Home » Language IDEs » Java Development Tools (JDT) » IClasspathContainer and JavaModel update problem
|
Re: IClasspathContainer and JavaModel update problem [message #46211 is a reply to message #45565] |
Sun, 01 June 2003 16:40 |
Wayne Parrott Messages: 84 Registered: July 2009 |
Member |
|
|
Hi Joss,
In MyEclipse we have a feature known as a LibrarySet.. These which are user
managed classpath-containers. Sounds like your efforts overlap with our
generalized LibrarySet direction. The J2EE librarysets provided by MyEclipse
are initially initialized from a folder's contents, i.e., a file-based
classpath-container and then users may edit them as they see fit. For EA2 I
have been adding more generalization that includes use of classpath
variables for relative library locations and the ability to add a libraryset
to any Java project.
I implemented a MyEclipse IClasspathContainerPage and integrated with none
of the problems you report. Upon closure of the property page the LibrarySet
appears in the Java navigator view along with all other libs. Is your
wizardPage constructing a proper IClasspathEntry that is returned with
#getSelection? I'm a little rusty on the internals but I believe that
org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathBloc k class handles
the update of your project's classpath which should cause the model to be
updated. Also I assume your classpath-container is registered through
JavaCore which gets passed into JavaModelManager?
Wayne
Genuitec
"Joss Wright" <joss.wright@talk21.com> wrote in message
news:bb8kdq$hvr$1@rogue.oti.com...
> I have created a LibFolderContainer plugin that mimics the behaviour of a
> java project 'lib' folder, i.e. it will automatically add jar files to the
> project that are placed in a folder referenced by my LibFolderContainer.
>
> I have also created a LibFolderContainerInitializer and a
> LibFolderContainerPage to select and configure the required 'lib' folder.
> However when I first configure my 'lib' folder via Project Properties >
> Java Build Path > Libraries (tab) > Add Library, the LibFolderContainer
> does not get initialised correctly, i.e. it does not show in the Package
> Explorer, unless I remove and then re-add the library container or close
> and then re-open the project.
>
> After a huge amount of debugging I think the problem is due to the
> JavaModel not being updated/refreshed after the LibFolderContainer is
> added to the project. As I don't make any changes to the Java Project
> other than create a reference to a folder then maybe this is correct
> behaviour, however does anyone know how to force a project JavaModel to be
> updated/refreshed.
>
> Thanks in advance,
>
> Joss
>
>
|
|
| |
Re: IClasspathContainer and JavaModel update problem [message #47200 is a reply to message #46654] |
Tue, 03 June 2003 10:06 |
Joss Wright Messages: 32 Registered: July 2009 |
Member |
|
|
Philippe/Wayne,
The following is a summary of what I do:
1. Register the container initialiser in plug-in.xml.
2. Register the container page in plug-in.xml.
3. In the container page I construct a container path and encode the
folder in the path, e.g. LIB_CONTAINER/lib where LIB_CONTAINER is the
container and lib is a folder in the root of the project.
4. In the container page I call newContainerEntry() in the finish() method.
5. In the initialiser I call setClasspathContainer() in the initialize()
method.
6. In the container class I add a resourceChangeListener during
construction.
7. In the resourceChangeListener I call setClasspathContainer() whenever
the selected folder resources change, i.e. by filtering in deltas based
upon the folder in the container path.
8. In the container class I generate an array of classpath entries in the
getClassPathEntries() method by building a list of jar files in the lib
folder and creating new library entries from them by calling
newLibraryEntry().
I have included the code for these methods below.
LibFolderContainerWizardPage:
public boolean finish() {
IPath containerPath = new Path(LibFolderContainer.LIB_CONTAINER);
containerPath = containerPath.append(directoryField.getText());
selection = JavaCore.newContainerEntry(containerPath);
return true;
}
Where directoryField contains the path of the folder selected in the
wizard page.
LibFolderContainerInitializer:
public void initialize(IPath containerPath, IJavaProject javaProject)
throws CoreException {
int size = containerPath.segmentCount();
if (size > 0) {
if (containerPath
.segment(0)
.equals(LibFolderContainer.LIB_CONTAINER)) {
IClasspathContainer container = null;
IFolder libFolder = getLibFolder(containerPath, javaProject);
if (libFolder != null) {
container = new LibFolderContainer(containerPath, javaProject,
libFolder);
}
JavaCore.setClasspathContainer(
containerPath,
new IJavaProject[] { javaProject },
new IClasspathContainer[] { container },
null);
}
}
}
Where getLibFolder() is a helper method for returning a folder object from
the container path.
LibFolderContainer:
public LibFolderContainer(
IPath containerPath,
IJavaProject javaProject,
IFolder libFolder) {
this.container = this;
this.containerPath = containerPath;
this.javaProject = javaProject;
this.libFolder = libFolder;
// create the resource change listener
IResourceChangeListener listener = new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
IResourceDelta libDelta =
event.getDelta().findMember(getLibFolder().getFullPath());
if (libDelta != null) {
try {
JavaCore.setClasspathContainer(
getPath(),
new IJavaProject[] { getJavaProject()},
new IClasspathContainer[] { container },
null);
} catch (JavaModelException e) {
// ignore
}
}
}
};
// add the resource change listener
ResourcesPlugin.getWorkspace().addResourceChangeListener(
listener,
IResourceChangeEvent.POST_CHANGE);
}
public IClasspathEntry[] getClasspathEntries() {
Vector classpathEntries = new Vector();
IResource[] members;
try {
members = getLibFolder().members();
for (int i = 0; i < members.length; i++) {
if (("jar").equalsIgnoreCase(members[i].getFileExtension())) {
//$NON-NLS-1$
classpathEntries.add(
JavaCore.newLibraryEntry(
members[i].getFullPath(),
Path.EMPTY,
Path.EMPTY));
}
}
} catch (CoreException e) {
// ignore
}
return (IClasspathEntry[]) classpathEntries.toArray(
new IClasspathEntry[classpathEntries.size()]);
}
As I said earlier this container works as expected, apart from when I add
the container to a project, the container does not appear in the Package
Explorer unless I open and close the project.
Any suggestions would be gratefully recieved.
Regards,
Joss
PS: I was not going to post this to the JDT project until I'd solved this
final problem but I'm starting to change my mind!!
Philippe Mulet wrote:
> Are you upgrading an existing container value, or creating a new one each
> time ? When setting an existing container using
> JavaCore.setClasspathContainer(...) it will ignore cases where the same
> instance of a container is being reused.
> "Joss Wright" <joss.wright@talk21.com> wrote in message
> news:bb8kdq$hvr$1@rogue.oti.com...
> > I have created a LibFolderContainer plugin that mimics the behaviour of a
> > java project 'lib' folder, i.e. it will automatically add jar files to the
> > project that are placed in a folder referenced by my LibFolderContainer.
> >
> > I have also created a LibFolderContainerInitializer and a
> > LibFolderContainerPage to select and configure the required 'lib' folder.
> > However when I first configure my 'lib' folder via Project Properties >
> > Java Build Path > Libraries (tab) > Add Library, the LibFolderContainer
> > does not get initialised correctly, i.e. it does not show in the Package
> > Explorer, unless I remove and then re-add the library container or close
> > and then re-open the project.
> >
> > After a huge amount of debugging I think the problem is due to the
> > JavaModel not being updated/refreshed after the LibFolderContainer is
> > added to the project. As I don't make any changes to the Java Project
> > other than create a reference to a folder then maybe this is correct
> > behaviour, however does anyone know how to force a project JavaModel to be
> > updated/refreshed.
> >
> > Thanks in advance,
> >
> > Joss
> >
> >
|
|
|
Re: IClasspathContainer and JavaModel update problem [message #50098 is a reply to message #47200] |
Thu, 05 June 2003 11:22 |
Philippe Mulet Messages: 229 Registered: July 2009 |
Senior Member |
|
|
Can you please enter a defect against JDT/Core. We seem to be missing a
change notification inside JDT which would cause to refresh the package
view.
Also, once having closed/reopened the project, do you get the container to
update properly when incrementally adding/deleting JARs inside the lib
folder ?
"Joss Wright" <joss.wright@talk21.com> wrote in message
news:bbhs03$9ru$1@rogue.oti.com...
> Philippe/Wayne,
>
> The following is a summary of what I do:
>
> 1. Register the container initialiser in plug-in.xml.
> 2. Register the container page in plug-in.xml.
> 3. In the container page I construct a container path and encode the
> folder in the path, e.g. LIB_CONTAINER/lib where LIB_CONTAINER is the
> container and lib is a folder in the root of the project.
> 4. In the container page I call newContainerEntry() in the finish()
method.
> 5. In the initialiser I call setClasspathContainer() in the initialize()
> method.
> 6. In the container class I add a resourceChangeListener during
> construction.
> 7. In the resourceChangeListener I call setClasspathContainer() whenever
> the selected folder resources change, i.e. by filtering in deltas based
> upon the folder in the container path.
> 8. In the container class I generate an array of classpath entries in the
> getClassPathEntries() method by building a list of jar files in the lib
> folder and creating new library entries from them by calling
> newLibraryEntry().
>
> I have included the code for these methods below.
>
> LibFolderContainerWizardPage:
>
> public boolean finish() {
> IPath containerPath = new Path(LibFolderContainer.LIB_CONTAINER);
> containerPath = containerPath.append(directoryField.getText());
> selection = JavaCore.newContainerEntry(containerPath);
> return true;
> }
>
> Where directoryField contains the path of the folder selected in the
> wizard page.
>
>
> LibFolderContainerInitializer:
>
> public void initialize(IPath containerPath, IJavaProject javaProject)
> throws CoreException {
> int size = containerPath.segmentCount();
> if (size > 0) {
> if (containerPath
> .segment(0)
> .equals(LibFolderContainer.LIB_CONTAINER)) {
> IClasspathContainer container = null;
> IFolder libFolder = getLibFolder(containerPath, javaProject);
> if (libFolder != null) {
> container = new LibFolderContainer(containerPath, javaProject,
> libFolder);
> }
> JavaCore.setClasspathContainer(
> containerPath,
> new IJavaProject[] { javaProject },
> new IClasspathContainer[] { container },
> null);
> }
> }
> }
>
> Where getLibFolder() is a helper method for returning a folder object from
> the container path.
>
>
> LibFolderContainer:
>
> public LibFolderContainer(
> IPath containerPath,
> IJavaProject javaProject,
> IFolder libFolder) {
>
> this.container = this;
> this.containerPath = containerPath;
> this.javaProject = javaProject;
> this.libFolder = libFolder;
>
> // create the resource change listener
> IResourceChangeListener listener = new IResourceChangeListener() {
> public void resourceChanged(IResourceChangeEvent event) {
> IResourceDelta libDelta =
> event.getDelta().findMember(getLibFolder().getFullPath());
> if (libDelta != null) {
> try {
> JavaCore.setClasspathContainer(
> getPath(),
> new IJavaProject[] { getJavaProject()},
> new IClasspathContainer[] { container },
> null);
> } catch (JavaModelException e) {
> // ignore
> }
> }
> }
> };
>
> // add the resource change listener
> ResourcesPlugin.getWorkspace().addResourceChangeListener(
> listener,
> IResourceChangeEvent.POST_CHANGE);
> }
>
> public IClasspathEntry[] getClasspathEntries() {
> Vector classpathEntries = new Vector();
> IResource[] members;
> try {
> members = getLibFolder().members();
> for (int i = 0; i < members.length; i++) {
> if (("jar").equalsIgnoreCase(members[i].getFileExtension())) {
> //$NON-NLS-1$
> classpathEntries.add(
> JavaCore.newLibraryEntry(
> members[i].getFullPath(),
> Path.EMPTY,
> Path.EMPTY));
> }
> }
> } catch (CoreException e) {
> // ignore
> }
> return (IClasspathEntry[]) classpathEntries.toArray(
> new IClasspathEntry[classpathEntries.size()]);
> }
>
>
> As I said earlier this container works as expected, apart from when I add
> the container to a project, the container does not appear in the Package
> Explorer unless I open and close the project.
>
> Any suggestions would be gratefully recieved.
>
> Regards,
>
> Joss
>
> PS: I was not going to post this to the JDT project until I'd solved this
> final problem but I'm starting to change my mind!!
>
>
> Philippe Mulet wrote:
>
> > Are you upgrading an existing container value, or creating a new one
each
> > time ? When setting an existing container using
> > JavaCore.setClasspathContainer(...) it will ignore cases where the same
> > instance of a container is being reused.
>
> > "Joss Wright" <joss.wright@talk21.com> wrote in message
> > news:bb8kdq$hvr$1@rogue.oti.com...
> > > I have created a LibFolderContainer plugin that mimics the behaviour
of a
> > > java project 'lib' folder, i.e. it will automatically add jar files to
the
> > > project that are placed in a folder referenced by my
LibFolderContainer.
> > >
> > > I have also created a LibFolderContainerInitializer and a
> > > LibFolderContainerPage to select and configure the required 'lib'
folder.
> > > However when I first configure my 'lib' folder via Project Properties
>
> > > Java Build Path > Libraries (tab) > Add Library, the
LibFolderContainer
> > > does not get initialised correctly, i.e. it does not show in the
Package
> > > Explorer, unless I remove and then re-add the library container or
close
> > > and then re-open the project.
> > >
> > > After a huge amount of debugging I think the problem is due to the
> > > JavaModel not being updated/refreshed after the LibFolderContainer is
> > > added to the project. As I don't make any changes to the Java Project
> > > other than create a reference to a folder then maybe this is correct
> > > behaviour, however does anyone know how to force a project JavaModel
to be
> > > updated/refreshed.
> > >
> > > Thanks in advance,
> > >
> > > Joss
> > >
> > >
>
>
>
>
>
|
|
|
Re: IClasspathContainer and JavaModel update problem [message #50129 is a reply to message #50098] |
Thu, 05 June 2003 12:19 |
Joss Wright Messages: 32 Registered: July 2009 |
Member |
|
|
Philippe,
> Can you please enter a defect against JDT/Core. We seem to be missing a
> change notification inside JDT which would cause to refresh the package
> view.
Yes.
In fact I have resolved the problem but not very nicely. My
LibFolderContainer refers to a folder that may be empty when first
created, JDT/Core will resolve the container to an empty classpath and
because the classpath has not changed, it will not refresh the
JavaModel/view, I believe the JavaModel should be refreshed when a
CPE_CONTAINER is added even if it returns an empty resolved classpath.
To get around this I added a ResourceChangeListener to my container, and
during PRE_AUTO_BUILD I set the classpath to empty and back again using
IJavaProject.setRawClasspath(), furthermore I only do this if the
classpath file is changed AND my LibFolderContainer variable is added to
the .classpath file. It's not nice but it works!!
> Also, once having closed/reopened the project, do you get the container to
> update properly when incrementally adding/deleting JARs inside the lib
> folder ?
If the 'lib' folder is empty, ie.e the folder referred to by my
LibFolderContainer, it shows up in the Package Explorer once the project
has been closed and reopened. The container works correctly, i.e. if there
are no jars in the folder nothing is seen in th container. Furthermore if
I then add jars to theunderlying folder they automatically appear in the
container and Package Explorer view as expected.
I am just getting the LibFolderContainerPage to work correctly then I will
post the code to the JDT/Core mailing list as a patchset. This should be
in the next couple of days.
I have one last question, I wanted to be able to import into the container
without opening the underlying folder (in the Resource view), so I tried
to implement IAdaptable in my LibFolderContainer class and return the
underlying folder via the getAdapter() method. I thought the ImportWizard
could use IAdaptable as well as IResource classes but this does not appear
to be the case.
If you have any quick ideas I'd be grateful otherwise I'll start looking
through the Platform code in more detail. However I believe this would be
a great addition to the LibFolderContainer, i.e. to right-click on it in
the Package Explorer and import directly into it via the standard Import
Wizard!!
Regards,
Joss
Philippe Mulet wrote:
> Can you please enter a defect against JDT/Core. We seem to be missing a
> change notification inside JDT which would cause to refresh the package
> view.
> Also, once having closed/reopened the project, do you get the container to
> update properly when incrementally adding/deleting JARs inside the lib
> folder ?
> "Joss Wright" <joss.wright@talk21.com> wrote in message
> news:bbhs03$9ru$1@rogue.oti.com...
> > Philippe/Wayne,
> >
> > The following is a summary of what I do:
> >
> > 1. Register the container initialiser in plug-in.xml.
> > 2. Register the container page in plug-in.xml.
> > 3. In the container page I construct a container path and encode the
> > folder in the path, e.g. LIB_CONTAINER/lib where LIB_CONTAINER is the
> > container and lib is a folder in the root of the project.
> > 4. In the container page I call newContainerEntry() in the finish()
> method.
> > 5. In the initialiser I call setClasspathContainer() in the initialize()
> > method.
> > 6. In the container class I add a resourceChangeListener during
> > construction.
> > 7. In the resourceChangeListener I call setClasspathContainer() whenever
> > the selected folder resources change, i.e. by filtering in deltas based
> > upon the folder in the container path.
> > 8. In the container class I generate an array of classpath entries in the
> > getClassPathEntries() method by building a list of jar files in the lib
> > folder and creating new library entries from them by calling
> > newLibraryEntry().
> >
> > I have included the code for these methods below.
> >
> > LibFolderContainerWizardPage:
> >
> > public boolean finish() {
> > IPath containerPath = new Path(LibFolderContainer.LIB_CONTAINER);
> > containerPath = containerPath.append(directoryField.getText());
> > selection = JavaCore.newContainerEntry(containerPath);
> > return true;
> > }
> >
> > Where directoryField contains the path of the folder selected in the
> > wizard page.
> >
> >
> > LibFolderContainerInitializer:
> >
> > public void initialize(IPath containerPath, IJavaProject javaProject)
> > throws CoreException {
> > int size = containerPath.segmentCount();
> > if (size > 0) {
> > if (containerPath
> > .segment(0)
> > .equals(LibFolderContainer.LIB_CONTAINER)) {
> > IClasspathContainer container = null;
> > IFolder libFolder = getLibFolder(containerPath, javaProject);
> > if (libFolder != null) {
> > container = new LibFolderContainer(containerPath, javaProject,
> > libFolder);
> > }
> > JavaCore.setClasspathContainer(
> > containerPath,
> > new IJavaProject[] { javaProject },
> > new IClasspathContainer[] { container },
> > null);
> > }
> > }
> > }
> >
> > Where getLibFolder() is a helper method for returning a folder object from
> > the container path.
> >
> >
> > LibFolderContainer:
> >
> > public LibFolderContainer(
> > IPath containerPath,
> > IJavaProject javaProject,
> > IFolder libFolder) {
> >
> > this.container = this;
> > this.containerPath = containerPath;
> > this.javaProject = javaProject;
> > this.libFolder = libFolder;
> >
> > // create the resource change listener
> > IResourceChangeListener listener = new IResourceChangeListener() {
> > public void resourceChanged(IResourceChangeEvent event) {
> > IResourceDelta libDelta =
> > event.getDelta().findMember(getLibFolder().getFullPath());
> > if (libDelta != null) {
> > try {
> > JavaCore.setClasspathContainer(
> > getPath(),
> > new IJavaProject[] { getJavaProject()},
> > new IClasspathContainer[] { container },
> > null);
> > } catch (JavaModelException e) {
> > // ignore
> > }
> > }
> > }
> > };
> >
> > // add the resource change listener
> > ResourcesPlugin.getWorkspace().addResourceChangeListener(
> > listener,
> > IResourceChangeEvent.POST_CHANGE);
> > }
> >
> > public IClasspathEntry[] getClasspathEntries() {
> > Vector classpathEntries = new Vector();
> > IResource[] members;
> > try {
> > members = getLibFolder().members();
> > for (int i = 0; i < members.length; i++) {
> > if (("jar").equalsIgnoreCase(members[i].getFileExtension())) {
> > //$NON-NLS-1$
> > classpathEntries.add(
> > JavaCore.newLibraryEntry(
> > members[i].getFullPath(),
> > Path.EMPTY,
> > Path.EMPTY));
> > }
> > }
> > } catch (CoreException e) {
> > // ignore
> > }
> > return (IClasspathEntry[]) classpathEntries.toArray(
> > new IClasspathEntry[classpathEntries.size()]);
> > }
> >
> >
> > As I said earlier this container works as expected, apart from when I add
> > the container to a project, the container does not appear in the Package
> > Explorer unless I open and close the project.
> >
> > Any suggestions would be gratefully recieved.
> >
> > Regards,
> >
> > Joss
> >
> > PS: I was not going to post this to the JDT project until I'd solved this
> > final problem but I'm starting to change my mind!!
> >
> >
> > Philippe Mulet wrote:
> >
> > > Are you upgrading an existing container value, or creating a new one
> each
> > > time ? When setting an existing container using
> > > JavaCore.setClasspathContainer(...) it will ignore cases where the same
> > > instance of a container is being reused.
> >
> > > "Joss Wright" <joss.wright@talk21.com> wrote in message
> > > news:bb8kdq$hvr$1@rogue.oti.com...
> > > > I have created a LibFolderContainer plugin that mimics the behaviour
> of a
> > > > java project 'lib' folder, i.e. it will automatically add jar files to
> the
> > > > project that are placed in a folder referenced by my
> LibFolderContainer.
> > > >
> > > > I have also created a LibFolderContainerInitializer and a
> > > > LibFolderContainerPage to select and configure the required 'lib'
> folder.
> > > > However when I first configure my 'lib' folder via Project Properties
> >
> > > > Java Build Path > Libraries (tab) > Add Library, the
> LibFolderContainer
> > > > does not get initialised correctly, i.e. it does not show in the
> Package
> > > > Explorer, unless I remove and then re-add the library container or
> close
> > > > and then re-open the project.
> > > >
> > > > After a huge amount of debugging I think the problem is due to the
> > > > JavaModel not being updated/refreshed after the LibFolderContainer is
> > > > added to the project. As I don't make any changes to the Java Project
> > > > other than create a reference to a folder then maybe this is correct
> > > > behaviour, however does anyone know how to force a project JavaModel
> to be
> > > > updated/refreshed.
> > > >
> > > > Thanks in advance,
> > > >
> > > > Joss
> > > >
> > > >
> >
> >
> >
> >
> >
|
|
|
Goto Forum:
Current Time: Sat Dec 21 14:32:23 GMT 2024
Powered by FUDForum. Page generated in 0.04216 seconds
|