Author: max.andersen(a)jboss.com
Date: 2007-10-25 05:38:25 -0400 (Thu, 25 Oct 2007)
New Revision: 4502
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.core/src/org/jboss/ide/eclipse/as/classpath/core/DirectoryLibraryContainerInitializer.java
trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.ui/src/org/jboss/ide/eclipse/as/classpath/ui/DirectoryLibraryPage.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.core/plugin.xml
trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.ui/plugin.xml
Log:
Added preliminary work for the "automatic scan directory for lib/zip
files'-classpath container. Not done yet since it does not react to resource changes
(add/remove lib files)
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.core/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.core/plugin.xml 2007-10-25
09:27:07 UTC (rev 4501)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.core/plugin.xml 2007-10-25
09:38:25 UTC (rev 4502)
@@ -74,6 +74,17 @@
class="org.jboss.ide.eclipse.as.classpath.core.jee.J2EE50ClasspathContainerInitializer"
id="org.jboss.ide.eclipse.as.classpath.core.javaee-5.0">
</classpathContainerInitializer>
- </extension>
+ </extension>
+ <!--
+ Cannot be enabled before resource change listening is implemented.(max)
+ <extension
+ point="org.eclipse.jdt.core.classpathContainerInitializer">
+ <classpathContainerInitializer
+
class="org.jboss.ide.eclipse.as.classpath.core.DirectoryLibraryContainerInitializer"
+
id="org.jboss.ide.eclipse.as.classpath.core.DirectoryLibraryContainer">
+ </classpathContainerInitializer>
+ </extension>
+ -->
+
</plugin>
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.core/src/org/jboss/ide/eclipse/as/classpath/core/DirectoryLibraryContainerInitializer.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.core/src/org/jboss/ide/eclipse/as/classpath/core/DirectoryLibraryContainerInitializer.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.core/src/org/jboss/ide/eclipse/as/classpath/core/DirectoryLibraryContainerInitializer.java 2007-10-25
09:38:25 UTC (rev 4502)
@@ -0,0 +1,110 @@
+package org.jboss.ide.eclipse.as.classpath.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.ClasspathContainerInitializer;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+
+// Can't extend abstractclasspathcontainer since it assumes libraries are within our
plugins
+// TODO: need to implement resource change listeners like done in
FlexibleProjectContainer to be usefull.
+public class DirectoryLibraryContainerInitializer extends ClasspathContainerInitializer
{
+
+ public static final String CONTAINER_ID =
"org.jboss.ide.eclipse.as.classpath.core.DirectoryLibraryContainer";
+
+ @Override
+ public void initialize(IPath containerPath, IJavaProject project)
+ throws CoreException {
+ int size = containerPath.segmentCount();
+ if (size > 0)
+ {
+ if (containerPath.segment(0).equals(this.getClasspathContainerID()))
+ {
+ IClasspathContainer container = this.createClasspathContainer(project,
containerPath.removeFirstSegments(1));
+ JavaCore.setClasspathContainer(containerPath, new IJavaProject[]
+ {project}, new IClasspathContainer[]
+ {container}, null);
+ }
+ }
+ }
+
+ private IClasspathContainer createClasspathContainer(IJavaProject project, IPath
containerPath) {
+ return new DirectoryLibraryContainer(project, containerPath);
+ }
+
+ private String getClasspathContainerID() {
+ return CONTAINER_ID;
+ }
+
+ static class DirectoryLibraryContainer implements IClasspathContainer {
+
+ private final IResource file;
+
+ final IClasspathEntry[] entries;
+
+ private final IPath containerPath;
+
+ private final IJavaProject project;
+
+ public DirectoryLibraryContainer(IJavaProject project, IPath containerPath) {
+ this.project = project;
+ this.containerPath = containerPath;
+
+ this.file = project.getProject().getWorkspace().getRoot().getFolder(containerPath);
+
+
+ final List<IClasspathEntry> libraries = new ArrayList<IClasspathEntry>();
+
+ try {
+ if(file!=null && file.exists()) {
+ file.accept(new IResourceProxyVisitor() {
+ public boolean visit(IResourceProxy proxy) /* throws CoreException */{
+ switch(proxy.getType()) {
+ case IResource.FILE :
+ if (proxy.getName().endsWith(".jar") ||
proxy.getName().endsWith(".zip")) {
+ libraries.add(JavaCore.newLibraryEntry(proxy.requestFullPath(), null,
null));
+ }
+ return false;
+ case IResource.FOLDER :
+ //TODO: recursive by default or ?
+ return true;
+ }
+ return true;
+ }
+ }
+ , IResource.NONE);
+ }
+ } catch (CoreException e) {
+ // TODO: log
+ e.printStackTrace();
+ }
+
+ entries = libraries.toArray(new IClasspathEntry[0]);
+ }
+
+ public IClasspathEntry[] getClasspathEntries() {
+ return entries;
+ }
+
+ public String getDescription() {
+ return "Libraries found in " + ((file==null)?"[No directory
specified]":file.getProjectRelativePath().toString());
+ }
+
+ public int getKind() {
+ return K_APPLICATION;
+ }
+
+ public IPath getPath() {
+ return file.getProjectRelativePath();
+ }
+ }
+
+}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.ui/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.ui/plugin.xml 2007-10-25 09:27:07
UTC (rev 4501)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.ui/plugin.xml 2007-10-25 09:38:25
UTC (rev 4502)
@@ -7,6 +7,13 @@
class="org.jboss.ide.eclipse.as.classpath.ui.ejb3.JBossEJB3LibrariesPage"
id="org.jboss.ide.eclipse.as.classpath.ui.ejb3.containerPage"
name="JBoss EJB3 Libraries"/>
+ <!-- Cannot be enabled before resource change listening is implementd
(max)
+ <classpathContainerPage
+ class="org.jboss.ide.eclipse.as.classpath.ui.DirectoryLibraryPage"
+ id="org.jboss.ide.eclipse.as.classpath.ui.libraryDirectoryPage"
+ name="Directory with libraries">
+ </classpathContainerPage>
+ -->
</extension>
<extension
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.ui/src/org/jboss/ide/eclipse/as/classpath/ui/DirectoryLibraryPage.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.ui/src/org/jboss/ide/eclipse/as/classpath/ui/DirectoryLibraryPage.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.ui/src/org/jboss/ide/eclipse/as/classpath/ui/DirectoryLibraryPage.java 2007-10-25
09:38:25 UTC (rev 4502)
@@ -0,0 +1,119 @@
+package org.jboss.ide.eclipse.as.classpath.ui;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.ui.wizards.IClasspathContainerPage;
+import org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension;
+import org.eclipse.jdt.ui.wizards.NewElementWizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.jboss.ide.eclipse.as.classpath.core.DirectoryLibraryContainerInitializer;
+
+public class DirectoryLibraryPage extends NewElementWizardPage implements
+ IClasspathContainerPage, IClasspathContainerPageExtension {
+ private IProject ownerProject;
+ private String libsProjectName;
+ private Combo projectsCombo;
+
+ public DirectoryLibraryPage() {
+ super("DirectoryLibrariesContainerPage"); //$NON-NLS-1$
+
+ setTitle("Directory library");
+ setDescription("A classpath container that automatically adds all .jar and .zip
files found in a directory to the classpath.");
+ }
+
+ public IClasspathEntry getSelection() {
+ IPath path = new Path(DirectoryLibraryContainerInitializer.CONTAINER_ID);
+
+ final int index = this.projectsCombo.getSelectionIndex();
+ final String selectedProjectName = this.projectsCombo.getItem(index);
+
+ if (this.ownerProject == null
+ || !selectedProjectName.equals(this.ownerProject.getName())) {
+ path = path.append(selectedProjectName);
+ }
+
+ return JavaCore.newContainerEntry(path);
+ }
+
+ public void setSelection(final IClasspathEntry cpentry) {
+ final IPath path = cpentry == null ? null : cpentry.getPath();
+
+ if (path == null || path.segmentCount() == 1) {
+ if (this.ownerProject != null) {
+ this.libsProjectName = this.ownerProject.getName();
+ }
+ } else {
+ this.libsProjectName = path.segment(1);
+ }
+ }
+
+ public void createControl(final Composite parent) {
+ final Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(2, false));
+
+ final Label label = new Label(composite, SWT.NONE);
+ label.setText("Project:");
+
+ final String[] webProjects = getWebProjects();
+
+ this.projectsCombo = new Combo(composite, SWT.READ_ONLY);
+ this.projectsCombo.setItems(webProjects);
+
+ final int index;
+
+ if (this.ownerProject != null) {
+ index = indexOf(webProjects, this.libsProjectName);
+ } else {
+ if (this.projectsCombo.getItemCount() > 0) {
+ index = 0;
+ } else {
+ index = -1;
+ }
+ }
+
+ if (index != -1) {
+ this.projectsCombo.select(index);
+ }
+
+ final GridData gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.minimumWidth = 100;
+
+ this.projectsCombo.setLayoutData(gd);
+
+ setControl(composite);
+ }
+
+ public boolean finish() {
+ return true;
+ }
+
+ public void initialize(final IJavaProject project,
+ final IClasspathEntry[] currentEntries) {
+ this.ownerProject = (project == null ? null : project.getProject());
+ }
+
+ private static String[] getWebProjects() {
+ return new String[] { "test" };
+ }
+
+ private static int indexOf(final String[] array, final String str) {
+ for (int i = 0; i < array.length; i++) {
+ if (array[i].equals(str)) {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+}
\ No newline at end of file
Show replies by date