diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEActionProvider.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEActionProvider.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEActionProvider.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEActionProvider.java @@ -76,11 +76,9 @@ import org.netbeans.api.java.project.JavaProjectConstants; import org.netbeans.api.java.project.runner.JavaRunner; import org.netbeans.api.java.queries.UnitTestForSourceQuery; -import org.netbeans.api.java.source.ClasspathInfo; import org.netbeans.api.java.source.CompilationController; import org.netbeans.api.java.source.ElementHandle; import org.netbeans.api.java.source.JavaSource; -import org.netbeans.api.java.source.SourceUtils; import org.netbeans.api.java.source.ui.ScanDialog; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; @@ -90,8 +88,9 @@ import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; import org.netbeans.modules.java.api.common.ant.UpdateHelper; +import org.netbeans.modules.java.api.common.classpath.ClassPathProviderImpl; +import org.netbeans.modules.java.api.common.project.ProjectProperties; import org.netbeans.modules.java.j2seproject.applet.AppletSupport; -import org.netbeans.modules.java.j2seproject.classpath.ClassPathProviderImpl; import org.netbeans.modules.java.j2seproject.ui.customizer.CustomizerProviderImpl; import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; import org.netbeans.modules.java.j2seproject.ui.customizer.MainClassChooser; @@ -742,7 +741,7 @@ } private void prepareDirtyList(Properties p, boolean isExplicitBuildTarget) { String doDepend = project.evaluator().getProperty(J2SEProjectProperties.DO_DEPEND); - String buildClassesDirValue = project.evaluator().getProperty(J2SEProjectProperties.BUILD_CLASSES_DIR); + String buildClassesDirValue = project.evaluator().getProperty(ProjectProperties.BUILD_CLASSES_DIR); File buildClassesDir = project.getAntProjectHelper().resolveFile(buildClassesDirValue); synchronized (this) { if (dirty == null) { @@ -772,7 +771,7 @@ } dirtyList.append(f); } - p.setProperty(J2SEProjectProperties.INCLUDES, dirtyList.toString()); + p.setProperty(ProjectProperties.INCLUDES, dirtyList.toString()); } dirty.clear(); } @@ -878,7 +877,7 @@ } private boolean allowAntBuild() { - String buildClasses = project.evaluator().getProperty(J2SEProjectProperties.BUILD_CLASSES_DIR); + String buildClasses = project.evaluator().getProperty(ProjectProperties.BUILD_CLASSES_DIR); File buildClassesFile = this.updateHelper.getAntProjectHelper().resolveFile(buildClasses); return !new File(buildClassesFile, AUTOMATIC_BUILD_TAG).exists(); diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEAntLogger.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEAntLogger.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEAntLogger.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEAntLogger.java @@ -41,99 +41,18 @@ package org.netbeans.modules.java.j2seproject; -import java.io.File; -import java.io.IOException; -import org.apache.tools.ant.module.spi.AntEvent; -import org.apache.tools.ant.module.spi.AntLogger; -import org.apache.tools.ant.module.spi.AntSession; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectManager; -import org.openide.ErrorManager; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; +import org.netbeans.modules.java.api.common.ProjectAntLogger; /** * Logger which should suppress or prettify typical Ant output from a * j2seproject's build-impl.xml. * @author Jesse Glick */ -public final class J2SEAntLogger extends AntLogger { +public final class J2SEAntLogger extends ProjectAntLogger { /** Default constructor for lookup. */ - public J2SEAntLogger() {} - - public boolean interestedInSession(AntSession session) { - // Even if the initiating project is not a J2SEProject, suppress these messages. - // However disable our tricks when running at VERBOSE or higher. - return session.getVerbosity() <= AntEvent.LOG_INFO; + public J2SEAntLogger() { + super(J2SEProject.class, new String[0]); } - private static boolean isJ2SEProject(final File dir) { - return getJ2SEProject(dir) != null; - } - - private static J2SEProject getJ2SEProject(File dir) { - FileObject projdir = FileUtil.toFileObject(FileUtil.normalizeFile(dir)); - try { - Project proj = ProjectManager.getDefault().findProject(projdir); - if (proj != null) { - // Check if it is a J2SEProject. - return proj.getLookup().lookup(J2SEProject.class); - } - } catch (IOException e) { - ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); - } - return null; - } - - public boolean interestedInScript(File script, AntSession session) { - if (script.getName().equals("build-impl.xml")) { // NOI18N - File parent = script.getParentFile(); - if (parent != null && parent.getName().equals("nbproject")) { // NOI18N - File parent2 = parent.getParentFile(); - if (parent2 != null && parent2.canRead()) { - return isJ2SEProject(parent2); - } - } - } - // Was not a J2SEProject's nbproject/build-impl.xml; ignore it. - return false; - } - - public String[] interestedInTargets(AntSession session) { - return AntLogger.ALL_TARGETS; - } - - public String[] interestedInTasks(AntSession session) { - // XXX will eventually need them all anyway; as is, could list just javac - return AntLogger.ALL_TASKS; - } - - public int[] interestedInLogLevels(AntSession session) { - return new int[] { - AntEvent.LOG_WARN, - }; - } - - public void taskFinished(AntEvent event) { - if ("javac".equals(event.getTaskName())) { // NOI18N - Throwable t = event.getException(); - AntSession session = event.getSession(); - if (t != null && !session.isExceptionConsumed(t)) { - // Some error was thrown from build-impl.xml#compile. Ignore it; generally - // it will have been a compilation error which we do not wish to show. - session.consumeException(t); - } - } - } - - public void messageLogged(AntEvent event) { - // #43968 - filter out following message - if (!event.isConsumed() && event.getLogLevel() == AntEvent.LOG_WARN && - event.getMessage().startsWith("Trying to override old definition of " + // NOI18N - "task http://www.netbeans.org/ns/j2se-project/")) { // NOI18N - event.consume(); - } - } - } diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEPersistenceProvider.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEPersistenceProvider.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEPersistenceProvider.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEPersistenceProvider.java @@ -67,7 +67,7 @@ import org.netbeans.modules.j2ee.persistence.spi.PersistenceScopesProvider; import org.netbeans.modules.j2ee.persistence.spi.support.EntityMappingsMetadataModelHelper; import org.netbeans.modules.j2ee.persistence.spi.support.PersistenceScopesHelper; -import org.netbeans.modules.java.j2seproject.classpath.ClassPathProviderImpl; +import org.netbeans.modules.java.api.common.classpath.ClassPathProviderImpl; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java @@ -65,19 +65,21 @@ import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectInformation; import org.netbeans.api.project.ProjectManager; +import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.ant.AntArtifact; import org.netbeans.api.project.ant.AntBuildExtender; import org.netbeans.modules.java.api.common.SourceRoots; import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.java.api.common.ant.UpdateImplementation; +import org.netbeans.modules.java.api.common.classpath.ClassPathExtender; +import org.netbeans.modules.java.api.common.classpath.ClassPathModifier; +import org.netbeans.modules.java.api.common.classpath.ClassPathProviderImpl; +import org.netbeans.modules.java.api.common.project.ProjectProperties; import org.netbeans.modules.java.api.common.queries.QuerySupport; import org.netbeans.modules.java.j2seproject.api.J2SEPropertyEvaluator; -import org.netbeans.modules.java.j2seproject.classpath.ClassPathProviderImpl; -import org.netbeans.modules.java.j2seproject.classpath.J2SEProjectClassPathModifier; import org.netbeans.modules.java.j2seproject.ui.J2SELogicalViewProvider; import org.netbeans.modules.java.j2seproject.ui.customizer.CustomizerProviderImpl; import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; -import org.netbeans.modules.java.j2seproject.queries.BinaryForSourceQueryImpl; import org.netbeans.spi.java.project.support.ExtraSourceJavadocSupport; import org.netbeans.spi.java.project.support.LookupMergerSupport; import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport; @@ -115,7 +117,6 @@ import org.openide.util.Lookup; import org.openide.util.Mutex; import org.openide.util.NbBundle; -import org.openide.util.Utilities; import org.openide.util.lookup.Lookups; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -143,7 +144,7 @@ private SourceRoots sourceRoots; private SourceRoots testRoots; private final ClassPathProviderImpl cpProvider; - private final J2SEProjectClassPathModifier cpMod; + private final ClassPathModifier cpMod; private AntBuildExtender buildExtender; @@ -165,11 +166,29 @@ this.updateHelper = new UpdateHelper(updateProject, helper); this.cpProvider = new ClassPathProviderImpl(this.helper, evaluator(), getSourceRoots(),getTestSourceRoots()); //Does not use APH to get/put properties/cfgdata - this.cpMod = new J2SEProjectClassPathModifier(this, this.updateHelper, eval, refHelper); + this.cpMod = new ClassPathModifier(this, this.updateHelper, eval, refHelper, null, createClassPathModifierCallback(), null); final J2SEActionProvider actionProvider = new J2SEActionProvider( this, this.updateHelper ); lookup = createLookup(aux, actionProvider); actionProvider.startFSListener(); helper.addAntProjectListener(this); + } + + private ClassPathModifier.Callback createClassPathModifierCallback() { + return new ClassPathModifier.Callback() { + public String getClassPathProperty(SourceGroup sg, String type) { + assert sg != null : "SourceGroup cannot be null"; //NOI18N + assert type != null : "Type cannot be null"; //NOI18N + final String[] classPathProperty = getClassPathProvider().getPropertyName (sg, type); + if (classPathProperty == null || classPathProperty.length == 0) { + throw new UnsupportedOperationException ("Modification of [" + sg.getRootFolder().getPath() +", " + type + "] is not supported"); //NOI18N + } + return classPathProperty[0]; + } + + public String getElementName(String classpathProperty) { + return null; + } + }; } /** @@ -255,7 +274,7 @@ final J2SEActionProvider actionProvider) { final SubprojectProvider spp = refHelper.createSubprojectProvider(); FileEncodingQueryImplementation encodingQuery = QuerySupport.createFileEncodingQuery(evaluator(), J2SEProjectProperties.SOURCE_ENCODING); - @SuppressWarnings("deprecation") Object cpe = new org.netbeans.modules.java.j2seproject.classpath.J2SEProjectClassPathExtender(cpMod); + @SuppressWarnings("deprecation") Object cpe = new ClassPathExtender(cpMod, ProjectProperties.JAVAC_CLASSPATH, null); final Lookup base = Lookups.fixed( J2SEProject.this, new Info(), @@ -296,7 +315,7 @@ LookupMergerSupport.createSFBLookupMerger(), ExtraSourceJavadocSupport.createExtraJavadocQueryImplementation(this, helper, eval), LookupMergerSupport.createJFBLookupMerger(), - new BinaryForSourceQueryImpl(this.sourceRoots, this.testRoots, this.helper, this.eval) //Does not use APH to get/put properties/cfgdata + QuerySupport.createBinaryForSourceQueryImplementation(this.sourceRoots, this.testRoots, this.helper, this.eval) //Does not use APH to get/put properties/cfgdata ); return LookupProviderSupport.createCompositeLookup(base, "Projects/org-netbeans-modules-java-j2seproject/Lookup"); //NOI18N } @@ -305,7 +324,7 @@ return this.cpProvider; } - public J2SEProjectClassPathModifier getProjectClassPathModifier () { + public ClassPathModifier getProjectClassPathModifier () { return this.cpMod; } @@ -345,7 +364,7 @@ } File getTestClassesDirectory() { - String testClassesDir = evaluator().getProperty(J2SEProjectProperties.BUILD_TEST_CLASSES_DIR); + String testClassesDir = evaluator().getProperty(ProjectProperties.BUILD_TEST_CLASSES_DIR); if (testClassesDir == null) { return null; } @@ -549,11 +568,11 @@ updateHelper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep); ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - if (!ep.containsKey(J2SEProjectProperties.INCLUDES)) { - ep.setProperty(J2SEProjectProperties.INCLUDES, "**"); // NOI18N + if (!ep.containsKey(ProjectProperties.INCLUDES)) { + ep.setProperty(ProjectProperties.INCLUDES, "**"); // NOI18N } - if (!ep.containsKey(J2SEProjectProperties.EXCLUDES)) { - ep.setProperty(J2SEProjectProperties.EXCLUDES, ""); // NOI18N + if (!ep.containsKey(ProjectProperties.EXCLUDES)) { + ep.setProperty(ProjectProperties.EXCLUDES, ""); // NOI18N } helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); try { diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SESources.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SESources.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SESources.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SESources.java @@ -54,6 +54,7 @@ import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.java.project.JavaProjectConstants; import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.project.ProjectProperties; import org.netbeans.spi.project.support.GenericSources; import org.netbeans.spi.project.support.ant.SourcesHelper; import org.netbeans.spi.project.support.ant.AntProjectHelper; @@ -175,8 +176,8 @@ String prop = propNames[i]; String displayName = roots.getRootDisplayName(rootNames[i], prop); String loc = "${" + prop + "}"; // NOI18N - String includes = "${" + J2SEProjectProperties.INCLUDES + "}"; // NOI18N - String excludes = "${" + J2SEProjectProperties.EXCLUDES + "}"; // NOI18N + String includes = "${" + ProjectProperties.INCLUDES + "}"; // NOI18N + String excludes = "${" + ProjectProperties.EXCLUDES + "}"; // NOI18N sourcesHelper.addPrincipalSourceRoot(loc, includes, excludes, displayName, null, null); // NOI18N sourcesHelper.addTypedSourceRoot(loc, includes, excludes, JavaProjectConstants.SOURCES_TYPE_JAVA, displayName, null, null); // NOI18N } diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/BootClassPathImplementation.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/BootClassPathImplementation.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/BootClassPathImplementation.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.java.j2seproject.classpath; - -import java.beans.PropertyChangeEvent; -import org.netbeans.modules.java.j2seproject.J2SEProjectUtil; -import org.netbeans.spi.java.classpath.ClassPathImplementation; -import org.netbeans.spi.java.classpath.PathResourceImplementation; -import org.netbeans.spi.java.classpath.support.ClassPathSupport; -import org.netbeans.api.java.platform.JavaPlatform; -import org.netbeans.api.java.platform.JavaPlatformManager; -import org.netbeans.api.java.classpath.ClassPath; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.List; -import java.util.ArrayList; -import java.util.Collections; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.util.WeakListeners; - -final class BootClassPathImplementation implements ClassPathImplementation, PropertyChangeListener { - - private static final String PLATFORM_ACTIVE = "platform.active"; //NOI18N - private static final String ANT_NAME = "platform.ant.name"; //NOI18N - private static final String J2SE = "j2se"; //NOI18N - - private final PropertyEvaluator evaluator; - private JavaPlatformManager platformManager; - //name of project active platform - private String activePlatformName; - //active platform is valid (not broken reference) - private boolean isActivePlatformValid; - private List resourcesCache; - private PropertyChangeSupport support = new PropertyChangeSupport(this); - private long eventId; - - public BootClassPathImplementation(PropertyEvaluator evaluator) { - assert evaluator != null; - this.evaluator = evaluator; - evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, evaluator)); - } - - public List getResources() { - long currentId; - synchronized (this) { - if (this.resourcesCache != null) { - return this.resourcesCache; - } - currentId = eventId; - } - - JavaPlatform jp = findActivePlatform (); - final List result = new ArrayList(); - if (jp != null) { - //TODO: May also listen on CP, but from Platform it should be fixed. - final ClassPath cp = jp.getBootstrapLibraries(); - assert cp != null : jp; - for (ClassPath.Entry entry : cp.entries()) { - result.add(ClassPathSupport.createResource(entry.getURL())); - } - } - - synchronized (this) { - if (currentId == eventId) { - if (this.resourcesCache == null) { - this.resourcesCache = Collections.unmodifiableList(result); - } - return this.resourcesCache; - } - else { - return Collections.unmodifiableList (result); - } - } - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - this.support.addPropertyChangeListener (listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - this.support.removePropertyChangeListener (listener); - } - - private JavaPlatform findActivePlatform () { - if (this.platformManager == null) { - this.platformManager = JavaPlatformManager.getDefault(); - this.platformManager.addPropertyChangeListener(WeakListeners.propertyChange(this, this.platformManager)); - } - this.activePlatformName = evaluator.getProperty(PLATFORM_ACTIVE); - final JavaPlatform activePlatform = J2SEProjectUtil.getActivePlatform (this.activePlatformName); - this.isActivePlatformValid = activePlatform != null; - return activePlatform; - } - - public void propertyChange(PropertyChangeEvent evt) { - if (evt.getSource() == this.evaluator && evt.getPropertyName().equals(PLATFORM_ACTIVE)) { - //Active platform was changed - resetCache (); - } - else if (evt.getSource() == this.platformManager && JavaPlatformManager.PROP_INSTALLED_PLATFORMS.equals(evt.getPropertyName()) && activePlatformName != null) { - //Platform definitions were changed, check if the platform was not resolved or deleted - if (this.isActivePlatformValid) { - if (J2SEProjectUtil.getActivePlatform (this.activePlatformName) == null) { - //the platform was not removed - this.resetCache(); - } - } - else { - if (J2SEProjectUtil.getActivePlatform (this.activePlatformName) != null) { - this.resetCache(); - } - } - } - } - - /** - * Resets the cache and firesPropertyChange - */ - private void resetCache () { - synchronized (this) { - resourcesCache = null; - eventId++; - } - support.firePropertyChange(PROP_RESOURCES, null, null); - } - -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathProviderImpl.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathProviderImpl.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathProviderImpl.java +++ /dev/null @@ -1,397 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.java.j2seproject.classpath; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.util.Map; -import java.util.HashMap; -import org.netbeans.api.java.classpath.ClassPath; -import org.netbeans.api.project.ProjectManager; -import org.netbeans.api.project.SourceGroup; -import org.netbeans.modules.java.api.common.SourceRoots; -import org.netbeans.spi.java.classpath.ClassPathFactory; -import org.netbeans.spi.java.classpath.ClassPathProvider; -import org.netbeans.spi.java.project.classpath.support.ProjectClassPathSupport; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.util.Mutex; -import org.openide.util.WeakListeners; - -/** - * Defines the various class paths for a J2SE project. - */ -public final class ClassPathProviderImpl implements ClassPathProvider, PropertyChangeListener { - - private static final String BUILD_CLASSES_DIR = "build.classes.dir"; // NOI18N - private static final String DIST_JAR = "dist.jar"; // NOI18N - private static final String BUILD_TEST_CLASSES_DIR = "build.test.classes.dir"; // NOI18N - - private static final String JAVAC_CLASSPATH = "javac.classpath"; //NOI18N - private static final String JAVAC_TEST_CLASSPATH = "javac.test.classpath"; //NOI18N - private static final String RUN_CLASSPATH = "run.classpath"; //NOI18N - private static final String RUN_TEST_CLASSPATH = "run.test.classpath"; //NOI18N - - - private final AntProjectHelper helper; - private final File projectDirectory; - private final PropertyEvaluator evaluator; - private final SourceRoots sourceRoots; - private final SourceRoots testSourceRoots; - private final ClassPath[] cache = new ClassPath[8]; - - private final Map dirCache = new HashMap(); - - public ClassPathProviderImpl(AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots sourceRoots, - SourceRoots testSourceRoots) { - this.helper = helper; - this.projectDirectory = FileUtil.toFile(helper.getProjectDirectory()); - assert this.projectDirectory != null; - this.evaluator = evaluator; - this.sourceRoots = sourceRoots; - this.testSourceRoots = testSourceRoots; - evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, evaluator)); - } - - private FileObject getDir(final String propname) { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public FileObject run() { - synchronized (ClassPathProviderImpl.this) { - FileObject fo = (FileObject) ClassPathProviderImpl.this.dirCache.get (propname); - if (fo == null || !fo.isValid()) { - String prop = evaluator.getProperty(propname); - if (prop != null) { - fo = helper.resolveFileObject(prop); - ClassPathProviderImpl.this.dirCache.put (propname, fo); - } - } - return fo; - } - }}); - } - - private FileObject[] getPrimarySrcPath() { - return this.sourceRoots.getRoots(); - } - - private FileObject[] getTestSrcDir() { - return this.testSourceRoots.getRoots(); - } - - private FileObject getBuildClassesDir() { - return getDir(BUILD_CLASSES_DIR); - } - - private FileObject getDistJar() { - return getDir(DIST_JAR); - } - - private FileObject getBuildTestClassesDir() { - return getDir(BUILD_TEST_CLASSES_DIR); - } - - /** - * Find what a given file represents. - * @param file a file in the project - * @return one of:
- *
0
normal source
- *
1
test source
- *
2
built class (unpacked)
- *
3
built test class
- *
4
built class (in dist JAR)
- *
-1
something else
- *
- */ - private int getType(FileObject file) { - FileObject[] srcPath = getPrimarySrcPath(); - for (int i=0; i < srcPath.length; i++) { - FileObject root = srcPath[i]; - if (root.equals(file) || FileUtil.isParentOf(root, file)) { - return 0; - } - } - srcPath = getTestSrcDir(); - for (int i=0; i< srcPath.length; i++) { - FileObject root = srcPath[i]; - if (root.equals(file) || FileUtil.isParentOf(root, file)) { - return 1; - } - } - FileObject dir = getBuildClassesDir(); - if (dir != null && (dir.equals(file) || FileUtil.isParentOf(dir, file))) { - return 2; - } - dir = getDistJar(); // not really a dir at all, of course - if (dir != null && dir.equals(FileUtil.getArchiveFile(file))) { - // XXX check whether this is really the root - return 4; - } - dir = getBuildTestClassesDir(); - if (dir != null && (dir.equals(file) || FileUtil.isParentOf(dir,file))) { - return 3; - } - return -1; - } - - private ClassPath getCompileTimeClasspath(FileObject file) { - int type = getType(file); - return this.getCompileTimeClasspath(type); - } - - private synchronized ClassPath getCompileTimeClasspath(int type) { - if (type < 0 || type > 1) { - // Not a source file. - return null; - } - ClassPath cp = cache[2+type]; - if ( cp == null) { - if (type == 0) { - cp = ClassPathFactory.createClassPath( - ProjectClassPathSupport.createPropertyBasedClassPathImplementation( - projectDirectory, evaluator, new String[] {JAVAC_CLASSPATH})); // NOI18N - } - else { - cp = ClassPathFactory.createClassPath( - ProjectClassPathSupport.createPropertyBasedClassPathImplementation( - projectDirectory, evaluator, new String[] {JAVAC_TEST_CLASSPATH})); // NOI18N - } - cache[2+type] = cp; - } - return cp; - } - - private ClassPath getRunTimeClasspath(FileObject file) { - int type = getType(file); - if (type < 0 || type > 4) { - // Unregistered file, or in a JAR. - // For jar:file:$projdir/dist/*.jar!/**/*.class, it is misleading to use - // run.classpath since that does not actually contain the file! - // (It contains file:$projdir/build/classes/ instead.) - return null; - } else if (type > 1) { - type-=2; //Compiled source transform into source - } - return getRunTimeClasspath(type); - } - - private synchronized ClassPath getRunTimeClasspath(final int type) { - ClassPath cp = cache[4+type]; - if ( cp == null) { - if (type == 0) { - cp = ClassPathFactory.createClassPath( - ProjectClassPathSupport.createPropertyBasedClassPathImplementation( - projectDirectory, evaluator, new String[] {RUN_CLASSPATH})); // NOI18N - } - else if (type == 1) { - cp = ClassPathFactory.createClassPath( - ProjectClassPathSupport.createPropertyBasedClassPathImplementation( - projectDirectory, evaluator, new String[] {RUN_TEST_CLASSPATH})); // NOI18N - } - else if (type == 2) { - //Only to make the CompiledDataNode hapy - //Todo: Strictly it should return ${run.classpath} - ${build.classes.dir} + ${dist.jar} - cp = ClassPathFactory.createClassPath( - ProjectClassPathSupport.createPropertyBasedClassPathImplementation( - projectDirectory, evaluator, new String[] {DIST_JAR})); // NOI18N - } - cache[4+type] = cp; - } - return cp; - } - - private ClassPath getSourcepath(FileObject file) { - int type = getType(file); - return this.getSourcepath(type); - } - - private synchronized ClassPath getSourcepath(int type) { - if (type < 0 || type > 1) { - return null; - } - ClassPath cp = cache[type]; - if (cp == null) { - switch (type) { - case 0: - cp = ClassPathFactory.createClassPath(new SourcePathImplementation (this.sourceRoots, helper, evaluator)); - break; - case 1: - cp = ClassPathFactory.createClassPath(new SourcePathImplementation (this.testSourceRoots, helper, evaluator)); - break; - } - } - cache[type] = cp; - return cp; - } - - private synchronized ClassPath getBootClassPath() { - ClassPath cp = cache[7]; - if ( cp== null ) { - cp = ClassPathFactory.createClassPath(new BootClassPathImplementation(evaluator)); - cache[7] = cp; - } - return cp; - } - - public ClassPath findClassPath(FileObject file, String type) { - if (type.equals(ClassPath.COMPILE)) { - return getCompileTimeClasspath(file); - } else if (type.equals(ClassPath.EXECUTE)) { - return getRunTimeClasspath(file); - } else if (type.equals(ClassPath.SOURCE)) { - return getSourcepath(file); - } else if (type.equals(ClassPath.BOOT)) { - return getBootClassPath(); - } else { - return null; - } - } - - /** - * Returns array of all classpaths of the given type in the project. - * The result is used for example for GlobalPathRegistry registrations. - */ - public ClassPath[] getProjectClassPaths(String type) { - if (ClassPath.BOOT.equals(type)) { - return new ClassPath[]{getBootClassPath()}; - } - if (ClassPath.COMPILE.equals(type)) { - ClassPath[] l = new ClassPath[2]; - l[0] = getCompileTimeClasspath(0); - l[1] = getCompileTimeClasspath(1); - return l; - } - if (ClassPath.SOURCE.equals(type)) { - ClassPath[] l = new ClassPath[2]; - l[0] = getSourcepath(0); - l[1] = getSourcepath(1); - return l; - } - assert false; - return null; - } - - /** - * Returns the given type of the classpath for the project sources - * (i.e., excluding tests roots). - */ - public ClassPath getProjectSourcesClassPath(String type) { - if (ClassPath.BOOT.equals(type)) { - return getBootClassPath(); - } - if (ClassPath.COMPILE.equals(type)) { - return getCompileTimeClasspath(0); - } - if (ClassPath.SOURCE.equals(type)) { - return getSourcepath(0); - } - if (ClassPath.EXECUTE.equals(type)) { - return getRunTimeClasspath(0); - } - assert false : "Unknown classpath type: " + type; //NOI18N - return null; - } - - public synchronized void propertyChange(PropertyChangeEvent evt) { - dirCache.remove(evt.getPropertyName()); - } - - public String getPropertyName (final SourceRoots roots, final String type) { - if (roots.isTest()) { - if (ClassPath.COMPILE.equals(type)) { - return JAVAC_TEST_CLASSPATH; - } - else if (ClassPath.EXECUTE.equals(type)) { - return RUN_TEST_CLASSPATH; - } - else { - return null; - } - } - else { - if (ClassPath.COMPILE.equals(type)) { - return JAVAC_CLASSPATH; - } - else if (ClassPath.EXECUTE.equals(type)) { - return RUN_CLASSPATH; - } - else { - return null; - } - } - } - - public String getPropertyName (SourceGroup sg, String type) { - FileObject root = sg.getRootFolder(); - FileObject[] path = getPrimarySrcPath(); - for (int i=0; i wellKnownPaths; - private String antArtifactPrefix; - private UpdateHelper updateHelper; - - /** Creates a new instance of ClassPathSupport */ - public ClassPathSupport( PropertyEvaluator evaluator, - ReferenceHelper referenceHelper, - AntProjectHelper antProjectHelper, - UpdateHelper updateHelper, - String[] wellKnownPaths, - String antArtifactPrefix ) { - this.evaluator = evaluator; - this.referenceHelper = referenceHelper; - assert referenceHelper != null; - this.antProjectHelper = antProjectHelper; - this.wellKnownPaths = wellKnownPaths == null ? null : new HashSet(Arrays.asList(wellKnownPaths)); - this.antArtifactPrefix = antArtifactPrefix; - this.updateHelper = updateHelper; - } - - /** Creates list of Items from given property. - */ - public Iterator itemsIterator( String propertyValue ) { - // XXX More performance frendly impl. would retrun a lazzy iterator. - return itemsList( propertyValue ).iterator(); - } - - public List itemsList( String propertyValue ) { - - String pe[] = PropertyUtils.tokenizePath( propertyValue == null ? "": propertyValue ); // NOI18N - List items = new ArrayList( pe.length ); - for( int i = 0; i < pe.length; i++ ) { - Item item; - - // First try to find out whether the item is well known classpath - if ( isWellKnownPath( pe[i] ) ) { - // Some well know classpath - item = Item.create( pe[i] ); - } - else if ( isLibrary( pe[i] ) ) { - //Library from library manager - String libraryName = getLibraryNameFromReference(pe[i]); - assert libraryName != null : "Not a library reference: "+pe[i]; - Library library = referenceHelper.findLibrary(libraryName); - if ( library == null ) { - item = Item.createBroken( Item.TYPE_LIBRARY, pe[i] ); - } - else { - item = Item.create( library, pe[i] ); - } - } - else if ( isAntArtifact( pe[i] ) ) { - // Ant artifact from another project - Object[] ret = referenceHelper.findArtifactAndLocation(pe[i]); - if ( ret[0] == null || ret[1] == null ) { - item = Item.createBroken( Item.TYPE_ARTIFACT, pe[i] ); - } - else { - //fix of issue #55316 - AntArtifact artifact = (AntArtifact)ret[0]; - URI uri = (URI)ret[1]; - File usedFile = antProjectHelper.resolveFile(evaluator.evaluate(pe[i])); - File artifactFile = new File (artifact.getScriptLocation().toURI().resolve(uri).normalize()); - if (usedFile.equals(artifactFile)) { - item = Item.create( artifact, uri, pe[i] ); - } - else { - item = Item.createBroken( Item.TYPE_ARTIFACT, pe[i] ); - } - } - } else { - // Standalone jar or property - String eval = evaluator.evaluate( pe[i] ); - File f = null; - if (eval != null) { - f = antProjectHelper.resolveFile( eval ); - } - - String propertyName = CommonProjectUtils.getAntPropertyName(pe[i]); - String variableBaseProperty = antProjectHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(propertyName); - if (!isVariableBasedReference(variableBaseProperty)) { - variableBaseProperty = null; - } - - if ( f == null || !f.exists() ) { - item = Item.createBroken( eval, pe[i] ); - } - else { - item = Item.create( eval, pe[i], variableBaseProperty); - } - - item.initSourceAndJavadoc(antProjectHelper); - } - - items.add( item ); - - } - - return items; - - } - - /** Converts list of classpath items into array of Strings. - * !! This method creates references in the project !! - */ - public String[] encodeToStrings(Iterator classpath) { - - List result = new ArrayList(); - - while( classpath.hasNext() ) { - - Item item = classpath.next(); - String reference = null; - switch( item.getType() ) { - - case Item.TYPE_JAR: - reference = item.getReference(); - if ( item.isBroken() ) { - break; - } - if (reference == null) { - // New file - String file = item.getFilePath(); - // pass null as expected artifact type to always get file reference - reference = referenceHelper.createForeignFileReferenceAsIs(file, null); - if (item.getVariableBasedProperty() != null) { - // replace file reference with variable based reference: - EditableProperties ep = antProjectHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - ep.setProperty(CommonProjectUtils.getAntPropertyName(reference), item.getVariableBasedProperty()); - antProjectHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); - } - item.property = reference; - } - item.saveSourceAndJavadoc(referenceHelper, updateHelper); - break; - case Item.TYPE_LIBRARY: - reference = item.getReference(); - if ( item.isBroken() ) { - break; - } - Library library = item.getLibrary(); - if (reference == null) { - if ( library == null ) { - break; - } - reference = getLibraryReference( item ); - } - break; - case Item.TYPE_ARTIFACT: - reference = item.getReference(); - if ( item.isBroken() ) { - break; - } - AntArtifact artifact = item.getArtifact(); - if ( reference == null) { - if ( artifact == null ) { - break; - } - reference = referenceHelper.addReference( item.getArtifact(), item.getArtifactURI()); - } - break; - case Item.TYPE_CLASSPATH: - reference = item.getReference(); - break; - } - - if ( reference != null ) { - result.add( reference ); - } - - } - - String[] items = new String[ result.size() ]; - for( int i = 0; i < result.size(); i++) { - if ( i < result.size() - 1 ) { - items[i] = result.get( i ) + ":"; - } - else { - items[i] = result.get(i); - } - } - - return items; - } - - public String getLibraryReference( Item item ) { - if ( item.getType() != Item.TYPE_LIBRARY ) { - throw new IllegalArgumentException( "Item must be of type LIBRARY" ); - } - return referenceHelper.createLibraryReference(item.getLibrary(), "classpath"); // NOI18N - } - - // Private methods --------------------------------------------------------- - - private boolean isWellKnownPath( String property ) { - return wellKnownPaths == null ? false : wellKnownPaths.contains( property ); - } - - private boolean isAntArtifact( String property ) { - return antArtifactPrefix == null ? false : property.startsWith( antArtifactPrefix ); - } - - private static boolean isLibrary( String property ) { - return property.startsWith(LIBRARY_PREFIX) && property.endsWith(LIBRARY_SUFFIX); - } - - public static boolean isVariableBasedReference(String ref) { - return ref != null && ref.startsWith("${var."); // NOI18N - } - // Innerclasses ------------------------------------------------------------ - - /** Item of the classpath. - */ - public static class Item { - - // Types of the classpath elements - public static final int TYPE_JAR = 0; - public static final int TYPE_LIBRARY = 1; - public static final int TYPE_ARTIFACT = 2; - public static final int TYPE_CLASSPATH = 3; - - private static final String REF_START = "${file.reference."; //NOI18N - private static final int REF_START_INDEX = REF_START.length(); - private static final String JAVADOC_START = "${javadoc.reference."; //NOI18N - private static final String SOURCE_START = "${source.reference."; //NOI18N - - private Object object; - private URI artifactURI; - private int type; - private String property; - private boolean broken; - private String sourceFile; - private String javadocFile; - - private String initialSourceFile; - private String initialJavadocFile; - private String libraryName; - private String variableBasedProperty; - - private Item( int type, Object object, String property, boolean broken ) { - this.type = type; - this.object = object; - this.property = property; - this.broken = broken; - } - - private Item (int type, Object object, String property) { - this (type, object, property, false); - } - - private Item( int type, Object object, URI artifactURI, String property ) { - this( type, object, property, false); - this.artifactURI = artifactURI; - } - - - // Factory methods ----------------------------------------------------- - - - public static Item create( Library library, String property ) { - if ( library == null ) { - throw new IllegalArgumentException( "library must not be null" ); // NOI18N - } - Item itm = new Item( TYPE_LIBRARY, library, property); - itm.libraryName = library.getName(); - itm.reassignLibraryManager( library.getManager() ); - return itm; - } - - public static Item create( AntArtifact artifact, URI artifactURI, String property ) { - if ( artifactURI == null ) { - throw new IllegalArgumentException( "artifactURI must not be null" ); // NOI18N - } - if ( artifact == null ) { - throw new IllegalArgumentException( "artifact must not be null" ); // NOI18N - } - return new Item( TYPE_ARTIFACT, artifact, artifactURI, property ); - } - - public static Item create( String path, String property, String variableBasedProperty) { - if ( path == null ) { - throw new IllegalArgumentException( "path must not be null" ); // NOI18N - } - Item i = new Item( TYPE_JAR, path, property ); - i.variableBasedProperty = variableBasedProperty; - return i; - } - - public static Item create( String property ) { - if ( property == null ) { - throw new IllegalArgumentException( "property must not be null" ); // NOI18N - } - return new Item ( TYPE_CLASSPATH, null, property ); - } - - public static Item createBroken( int type, String property ) { - if ( property == null ) { - throw new IllegalArgumentException( "property must not be null in broken items" ); // NOI18N - } - Item itm = new Item( type, null, property, true); - if (type == TYPE_LIBRARY) { - Pattern LIBRARY_REFERENCE = Pattern.compile("\\$\\{libs\\.([^${}]+)\\.[^${}]+\\}"); // NOI18N - Matcher m = LIBRARY_REFERENCE.matcher(property); - if (m.matches()) { - itm.libraryName = m.group(1); - } else { - assert false : property; - } - } - return itm; - } - - public static Item createBroken( final String file, String property ) { - if ( property == null ) { - throw new IllegalArgumentException( "property must not be null in broken items" ); // NOI18N - } - return new Item( TYPE_JAR, file, property, true); - } - - // Instance methods ---------------------------------------------------- - - public int getType() { - return type; - } - - public Library getLibrary() { - if ( getType() != TYPE_LIBRARY ) { - throw new IllegalArgumentException( "Item is not of required type - LIBRARY" ); // NOI18N - } - assert object == null || object instanceof Library : - "Invalid object type: "+object.getClass().getName()+" instance: "+object.toString()+" expected type: Library"; //NOI18N - return (Library)object; - } - - public String getFilePath() { - if ( getType() != TYPE_JAR ) { - throw new IllegalArgumentException( "Item is not of required type - JAR" ); // NOI18N - } - return (String)object; - } - - public String getVariableBasedProperty() { - if ( getType() != TYPE_JAR ) { - throw new IllegalArgumentException( "Item is not of required type - JAR" ); // NOI18N - } - return variableBasedProperty; - } - - public AntArtifact getArtifact() { - if ( getType() != TYPE_ARTIFACT ) { - throw new IllegalArgumentException( "Item is not of required type - ARTIFACT" ); // NOI18N - } - return (AntArtifact)object; - } - - public URI getArtifactURI() { - if ( getType() != TYPE_ARTIFACT ) { - throw new IllegalArgumentException( "Item is not of required type - ARTIFACT" ); // NOI18N - } - return artifactURI; - } - - public void reassignLibraryManager(LibraryManager newManager) { - if (getType() != TYPE_LIBRARY) { - throw new IllegalArgumentException(" reassigning only works for type - LIBRARY"); - } - assert libraryName != null; - if (getLibrary() == null || newManager != getLibrary().getManager()) { - Library lib = newManager.getLibrary(libraryName); - if (lib == null) { - broken = true; - object = null; - } else { - object = lib; - broken = false; - } - } - } - - public String getReference() { - return property; - } - - /** - * only applicable to TYPE_JAR - * - * @return - */ - private String getSourceProperty() { - if (property == null || !property.startsWith(REF_START)) { - return null; - } - return CommonProjectUtils.getAntPropertyName(SOURCE_START + property.substring(REF_START_INDEX)); - } - - /** - * only applicable to TYPE_JAR - * - * @return - */ - private String getJavadocProperty() { - if (property == null || !property.startsWith(REF_START)) { - return null; - } - return CommonProjectUtils.getAntPropertyName(JAVADOC_START + property.substring(REF_START_INDEX)); - } - - public boolean canEdit () { - if (isBroken()) { - //Broken item cannot be edited - return false; - } - if (getType() == TYPE_JAR) { - //Jar can be edited only for ide created reference - if (property == null) { - //Just added item, allow editing - return true; - } - return getSourceProperty() != null && getJavadocProperty() != null; - } - else if (getType() == TYPE_LIBRARY) { - //Library can be edited - return true; - } - //Otherwise: project, classpath - cannot be edited - return false; - } - - /** - * only applicable to TYPE_JAR - * - * @return - */ - public String getSourceFilePath() { - return sourceFile; - } - - /** - * only applicable to TYPE_JAR - * - * @return - */ - public String getJavadocFilePath() { - return javadocFile; - } - - /** - * only applicable to TYPE_JAR - * - * @return - */ - public void setJavadocFilePath(String javadoc) { - javadocFile = javadoc; - } - - /** - * only applicable to TYPE_JAR - * - * @return - */ - public void setSourceFilePath(String source) { - sourceFile = source; - } - - private void setInitialSourceAndJavadoc(String source, String javadoc) { - initialSourceFile = source; - initialJavadocFile = javadoc; - sourceFile = source; - javadocFile = javadoc; - } - - private boolean hasChangedSource() { - if ((initialSourceFile == null) != (sourceFile == null)) { - return true; - } - if (initialSourceFile != null && sourceFile != null) { - - return ! initialSourceFile.equals(sourceFile); - } - return true; - } - - private boolean hasChangedJavadoc() { - if ((initialJavadocFile == null) != (javadocFile == null)) { - return true; - } - if (initialJavadocFile != null && javadocFile != null) { - return ! initialJavadocFile.equals(javadocFile); - } - return true; - } - - - public boolean isBroken() { - return this.broken; - } - - // TODO ideally this should be called from constructor but becaue of missing 'evaluator' - // I'm making it private method which needs to be called after construction of JAR Item - public void initSourceAndJavadoc(AntProjectHelper helper) { - assert getType() == Item.TYPE_JAR : getType(); - EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - String value; - String f = null; - String ref = getSourceProperty(); - if (ref != null) { - value = ep.getProperty(ref); - if (value != null) { - f = value; - } - } - String f2 = null; - ref = getJavadocProperty(); - if (ref != null) { - value = ep.getProperty(ref); - f2 = null; - if (value != null) { - f2 = value; - } - } - setInitialSourceAndJavadoc(f, f2); - } - - - public void saveSourceAndJavadoc(ReferenceHelper referenceHelper, UpdateHelper updateHelper) { - assert getType() == Item.TYPE_JAR : getType(); - if (hasChangedSource()) { - if (getSourceFilePath() != null) { - referenceHelper.createExtraForeignFileReferenceAsIs(getSourceFilePath(), getSourceProperty()); - } else { - removeSource(updateHelper); - } - } - if (hasChangedJavadoc()) { - if (getJavadocFilePath() != null) { - referenceHelper.createExtraForeignFileReferenceAsIs(getJavadocFilePath(), getJavadocProperty()); - } else { - removeJavadoc(updateHelper); - } - } - } - - public void removeSourceAndJavadoc(UpdateHelper updateHelper) { - assert getType() == Item.TYPE_JAR : getType(); - removeSource(updateHelper); - removeJavadoc(updateHelper); - } - - private void removeSource(UpdateHelper updateHelper) { - //oh well, how do I do this otherwise?? - EditableProperties ep = updateHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - if (getSourceProperty() != null) { - ep.remove(getSourceProperty()); - } - updateHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); - } - - private void removeJavadoc(UpdateHelper updateHelper) { - //oh well, how do I do this otherwise?? - EditableProperties ep = updateHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - if (getJavadocProperty() != null) { - ep.remove(getJavadocProperty()); - } - updateHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); - } - - public void updateJarReference(AntProjectHelper helper) { - assert getType() == Item.TYPE_JAR : getType(); - EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - String value = ep.getProperty(CommonProjectUtils.getAntPropertyName(getReference())); - object = value; - - String ref = getSourceProperty(); - if (ref != null) { - value = ep.getProperty(ref); - if (value != null) { - setSourceFilePath(value); - } - } - ref = getJavadocProperty(); - if (ref != null) { - value = ep.getProperty(ref); - if (value != null) { - setJavadocFilePath(value); - } - } - } - - @Override - public int hashCode() { - - int hash = getType(); - - if ( this.broken ) { - return 42; - } - - switch ( getType() ) { - case TYPE_ARTIFACT: - hash += getArtifact().getType().hashCode(); - hash += getArtifact().getScriptLocation().hashCode(); - hash += getArtifactURI().hashCode(); - break; - case TYPE_CLASSPATH: - hash += property.hashCode(); - break; - default: - hash += object.hashCode(); - } - - return hash; - } - - @Override - public boolean equals( Object itemObject ) { - - if ( !( itemObject instanceof Item ) ) { - return false; - } - - Item item = (Item)itemObject; - - if ( getType() != item.getType() ) { - return false; - } - - if ( isBroken() != item.isBroken() ) { - return false; - } - - if ( isBroken() ) { - return getReference().equals( item.getReference() ); - } - - switch ( getType() ) { - case TYPE_ARTIFACT: - if ( getArtifact().getType() != item.getArtifact().getType() ) { - return false; - } - - if ( !getArtifact().getScriptLocation().equals( item.getArtifact().getScriptLocation() ) ) { - return false; - } - - if ( !getArtifactURI().equals( item.getArtifactURI() ) ) { - return false; - } - return true; - case TYPE_CLASSPATH: - return property.equals( item.property ); - default: - return object.equals( item.object ); - } - - } - - } - - /** - * Converts the ant reference to the name of the referenced property - * @param ant reference - * @param the name of the referenced property - */ - public static String getAntPropertyName( String property ) { - if ( property != null && - property.startsWith( "${" ) && // NOI18N - property.endsWith( "}" ) ) { // NOI18N - return property.substring( 2, property.length() - 1 ); - } - else { - return property; - } - } - - /** - * Returns library name if given property represents library reference - * otherwise return null. - * - * @param property property to test - * @return library name or null - */ - public static String getLibraryNameFromReference(String property) { - if (!isLibrary(property)) { - return null; - } - return property.substring(LIBRARY_PREFIX.length(), property.lastIndexOf('.')); //NOI18N - } -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathExtender.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathExtender.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathExtender.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.java.j2seproject.classpath; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.netbeans.api.project.libraries.Library; -import org.netbeans.api.project.ant.AntArtifact; -import org.openide.util.Exceptions; - -@Deprecated -public class J2SEProjectClassPathExtender implements ProjectClassPathExtender { - - private static final String CP_CLASS_PATH = "javac.classpath"; //NOI18N - - private final J2SEProjectClassPathModifier delegate; - - public J2SEProjectClassPathExtender (final J2SEProjectClassPathModifier delegate) { - assert delegate != null; - this.delegate = delegate; - } - - public boolean addLibrary(final Library library) throws IOException { - return addLibrary(CP_CLASS_PATH, library); - } - - public boolean addLibrary(final String type, final Library library) throws IOException { - return this.delegate.handleLibraries (new Library[] {library},type, J2SEProjectClassPathModifier.ADD); - } - - public boolean addArchiveFile(final FileObject archiveFile) throws IOException { - return addArchiveFile(CP_CLASS_PATH,archiveFile); - } - - public boolean addArchiveFile(final String type, FileObject archiveFile) throws IOException { - if (FileUtil.isArchiveFile(archiveFile)) { - archiveFile = FileUtil.getArchiveRoot (archiveFile); - } - try { - return this.delegate.handleRoots(new URI[]{archiveFile.getURL().toURI()}, type, J2SEProjectClassPathModifier.ADD, true); - } catch (URISyntaxException ex) { - IOException ioe = new IOException(); - ioe.initCause(ex); - throw ioe; - } - } - - public boolean addAntArtifact(final AntArtifact artifact, final URI artifactElement) throws IOException { - return addAntArtifact(CP_CLASS_PATH,artifact, artifactElement); - } - - public boolean addAntArtifact(final String type, final AntArtifact artifact, final URI artifactElement) throws IOException { - return this.delegate.handleAntArtifacts(new AntArtifact[] {artifact}, new URI[] {artifactElement},type,J2SEProjectClassPathModifier.ADD); - } - -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifier.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifier.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifier.java +++ /dev/null @@ -1,340 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.classpath; - -import java.io.IOException; -import java.net.URI; -import java.net.URL; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.netbeans.api.java.classpath.ClassPath; -import org.netbeans.api.java.project.JavaProjectConstants; -import org.netbeans.api.project.ProjectManager; -import org.netbeans.api.project.SourceGroup; -import org.netbeans.api.project.Sources; -import org.netbeans.api.project.ant.AntArtifact; -import org.netbeans.api.project.libraries.Library; -import org.netbeans.modules.java.api.common.ant.UpdateHelper; -import org.netbeans.modules.java.j2seproject.J2SEProject; -import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; -import org.netbeans.spi.java.project.classpath.ProjectClassPathModifierImplementation; -import org.netbeans.spi.project.libraries.support.LibrariesSupport; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.spi.project.support.ant.ReferenceHelper; -import org.openide.ErrorManager; -import org.openide.filesystems.FileUtil; -import org.openide.util.Mutex; -import org.openide.util.MutexException; - -/** - *@author Tomas Zezula - * - */ -public class J2SEProjectClassPathModifier extends ProjectClassPathModifierImplementation { - - public static final int ADD = 1; - public static final int REMOVE = 2; - - private final J2SEProject project; - private final UpdateHelper helper; - private final ReferenceHelper refHelper; - private final PropertyEvaluator eval; - private final ClassPathSupport cs; - - private static final Logger LOG = Logger.getLogger(J2SEProjectClassPathModifier.class.getName()); - - /** Creates a new instance of J2SEProjectClassPathModifier */ - public J2SEProjectClassPathModifier(final J2SEProject project, final UpdateHelper helper, final PropertyEvaluator eval, final ReferenceHelper refHelper) { - assert project != null; - assert helper != null; - assert eval != null; - assert refHelper != null; - this.project = project; - this.helper = helper; - this.eval = eval; - this.refHelper = refHelper; - this.cs = new ClassPathSupport( eval, refHelper, helper.getAntProjectHelper(), helper, - J2SEProjectProperties.WELL_KNOWN_PATHS, - J2SEProjectProperties.ANT_ARTIFACT_PREFIX ); - } - - protected SourceGroup[] getExtensibleSourceGroups() { - Sources s = project.getLookup().lookup(Sources.class); - assert s != null; - return s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); - } - - protected String[] getExtensibleClassPathTypes (SourceGroup sg) { - return new String[] { - ClassPath.COMPILE, - ClassPath.EXECUTE - }; - } - - protected boolean removeRoots(final URL[] classPathRoots, final SourceGroup sourceGroup, final String type) throws IOException { - return handleRoots (convertURLsToURIs(classPathRoots), getClassPathProperty(sourceGroup, type), REMOVE, true); - } - - @Override - protected boolean removeRoots(final URI[] classPathRoots, final SourceGroup sourceGroup, final String type) throws IOException { - return handleRoots (classPathRoots, getClassPathProperty(sourceGroup, type), REMOVE, true); - } - - protected boolean addRoots (final URL[] classPathRoots, final SourceGroup sourceGroup, final String type) throws IOException { - return handleRoots (convertURLsToURIs(classPathRoots), getClassPathProperty(sourceGroup, type), ADD, true); - } - - @Override - protected boolean addRoots (final URI[] classPathRoots, final SourceGroup sourceGroup, final String type) throws IOException { - return handleRoots (classPathRoots, getClassPathProperty(sourceGroup, type), ADD, true); - } - - public boolean handleRoots (final URI[] classPathRoots, final String classPathProperty, final int operation, final boolean performHeuristics) throws IOException { - assert classPathRoots != null : "The classPathRoots cannot be null"; //NOI18N - assert classPathProperty != null; - try { - return ProjectManager.mutex().writeAccess( - new Mutex.ExceptionAction() { - public Boolean run() throws Exception { - EditableProperties props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH); - String raw = props.getProperty(classPathProperty); - List resources = cs.itemsList(raw); - boolean changed = false; - for (int i=0; i< classPathRoots.length; i++) { - String f; - if (performHeuristics && classPathRoots[i].isAbsolute()) { - f = J2SEProjectClassPathModifier.this.performSharabilityHeuristics(classPathRoots[i], project.getAntProjectHelper()); - } else { - URI toAdd = LibrariesSupport.getArchiveFile(classPathRoots[i]); - if (toAdd == null) { - toAdd = classPathRoots[i]; - } - f = LibrariesSupport.convertURIToFilePath(toAdd); - } - // LibrariesNode calls this method with variable based classpath items: - String filePath = f; - if (filePath.startsWith("${var.")) { // NOI18N - filePath = project.evaluator().evaluate(filePath); - } - ClassPathSupport.Item item = ClassPathSupport.Item.create( filePath, null, f.startsWith("${var.") ? f : null); // NOI18N - if (operation == ADD && !resources.contains(item)) { - resources.add (item); - changed = true; - } - else if (operation == REMOVE) { - if (resources.remove(item)) { - changed = true; - } - else { - for (Iterator it = resources.iterator(); it.hasNext();) { - ClassPathSupport.Item _r = it.next(); - if (_r.isBroken() && _r.getType() == ClassPathSupport.Item.TYPE_JAR && (f.equals(_r.getFilePath()) || f.equals(_r.getVariableBasedProperty()))) { - it.remove(); - changed = true; - } - } - } - } - } - if (changed) { - String itemRefs[] = cs.encodeToStrings( resources.iterator() ); - props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH); //PathParser may change the EditableProperties - props.setProperty(classPathProperty, itemRefs); - helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); - ProjectManager.getDefault().saveProject(project); - return true; - } - return false; - } - } - ); - } catch (Exception e) { - if (e instanceof IOException) { - throw (IOException) e; - } - else { - Exception t = new IOException (); - throw (IOException) ErrorManager.getDefault().annotate(t,e); - } - } - } - - protected boolean removeAntArtifacts(final AntArtifact[] artifacts, final URI[] artifactElements, final SourceGroup sourceGroup, final String type) throws IOException { - return handleAntArtifacts (artifacts, artifactElements, getClassPathProperty(sourceGroup, type), REMOVE); - } - - protected boolean addAntArtifacts(final AntArtifact[] artifacts, final URI[] artifactElements, final SourceGroup sourceGroup, final String type) throws IOException { - return handleAntArtifacts (artifacts, artifactElements, getClassPathProperty(sourceGroup, type), ADD); - } - - public boolean handleAntArtifacts (final AntArtifact[] artifacts, final URI[] artifactElements, final String classPathProperty, final int operation) throws IOException { - assert artifacts != null : "Artifacts cannot be null"; //NOI18N - assert artifactElements != null : "ArtifactElements cannot be null"; //NOI18N - assert artifacts.length == artifactElements.length : "Each artifact has to have corresponding artifactElement"; //NOI18N - assert classPathProperty != null; - try { - return ProjectManager.mutex().writeAccess( - new Mutex.ExceptionAction() { - public Boolean run() throws Exception { - EditableProperties props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH); - String raw = props.getProperty (classPathProperty); - List resources = cs.itemsList(raw); - boolean changed = false; - for (int i=0; i() { - public Boolean run() throws IOException { - EditableProperties props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH); - String raw = props.getProperty(classPathProperty); - List resources = cs.itemsList(raw); - List changed = new ArrayList(libraries.length); - for (int i=0; i< libraries.length; i++) { - assert libraries[i] != null; - Library lib = libraries[i]; - if (project.getAntProjectHelper().isSharableProject()) { - if (lib.getManager().getLocation() == null) { - - LOG.log(Level.FINE, "Client is adding global library ["+lib+ - "] to sharable project.", new Exception()); - // For backward compatibility just copy the library to shared one. - Library l = refHelper.getProjectLibraryManager().getLibrary(lib.getName()); - if (l != null) { - lib = l; - } else { - lib = refHelper.copyLibrary(lib); - } - } else if (!lib.getManager().getLocation().equals(refHelper.getProjectLibraryManager().getLocation())) { - throw new UnsupportedOperationException("Adding library '"+lib.getName()+ // NOI18N - "' from '"+lib.getManager().getLocation()+"' to project '"+project.getProjectDirectory()+ // NOI18N - "' is not supported because project libraries are defined in '"+refHelper.getProjectLibraryManager().getLocation()+"'"); // NOI18N - } - } - ClassPathSupport.Item item = ClassPathSupport.Item.create( lib, null ); - if (operation == ADD && !resources.contains(item)) { - resources.add (item); - changed.add(item); - } - else if (operation == REMOVE && resources.contains(item)) { - resources.remove(item); - changed.add(item); - } - } - if (!changed.isEmpty()) { - String itemRefs[] = cs.encodeToStrings( resources.iterator() ); - props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH); //PathParser may change the EditableProperties - props.setProperty(classPathProperty, itemRefs); - helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); - ProjectManager.getDefault().saveProject(project); - return true; - } - return false; - } - } - ); - } catch (MutexException e) { - throw (IOException) e.getException(); - } - } - - private String getClassPathProperty (final SourceGroup sg, final String type) { - assert sg != null : "SourceGroup cannot be null"; //NOI18N - assert type != null : "Type cannot be null"; //NOI18N - final String classPathProperty = project.getClassPathProvider().getPropertyName (sg, type); - if (classPathProperty == null) { - throw new UnsupportedOperationException ("Modification of [" + sg.getRootFolder().getPath() +", " + type + "] is not supported"); //NOI18N - } - return classPathProperty; - } -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/SourcePathImplementation.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/SourcePathImplementation.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/SourcePathImplementation.java +++ /dev/null @@ -1,414 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.java.j2seproject.classpath; - -import java.beans.PropertyChangeEvent; -import java.io.File; -import java.net.MalformedURLException; -import java.util.List; -import java.util.ArrayList; -import java.util.Collections; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.net.URI; -import java.net.URL; -import java.util.Iterator; -import java.util.StringTokenizer; -import org.netbeans.modules.java.api.common.SourceRoots; -import org.netbeans.spi.java.classpath.ClassPathImplementation; -import org.netbeans.spi.java.classpath.PathResourceImplementation; -import org.netbeans.spi.java.classpath.support.ClassPathSupport; -import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; -import org.netbeans.spi.java.classpath.FilteringPathResourceImplementation; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PathMatcher; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.filesystems.FileChangeAdapter; -import org.openide.filesystems.FileChangeListener; -import org.openide.filesystems.FileEvent; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.util.Exceptions; -import org.openide.util.RequestProcessor; -import org.openide.util.WeakListeners; - -/** - * Implementation of a single classpath that is derived from one Ant property. - */ -final class SourcePathImplementation implements ClassPathImplementation, PropertyChangeListener { - - private static final String PROP_BUILD_DIR = "build.dir"; //NOI18N - private static final String DIR_GEN_BINDINGS = "generated/addons"; // NOI18N - private static RequestProcessor REQ_PROCESSOR = new RequestProcessor(); // No I18N - private final PropertyChangeSupport support = new PropertyChangeSupport(this); - private List resources; - private final SourceRoots sourceRoots; - private final AntProjectHelper projectHelper; - private final PropertyEvaluator evaluator; - private FileChangeListener fcl = null; - - /** - * Construct the implementation. - * @param sourceRoots used to get the roots information and events - * @param projectHelper used to obtain the project root - */ - public SourcePathImplementation(SourceRoots sourceRoots, AntProjectHelper projectHelper, PropertyEvaluator evaluator) { - assert sourceRoots != null && projectHelper != null && evaluator != null; - this.sourceRoots = sourceRoots; - sourceRoots.addPropertyChangeListener(this); - this.projectHelper = projectHelper; - this.evaluator = evaluator; - evaluator.addPropertyChangeListener(this); - } - - private synchronized void createListener(String buildDir, String[] paths) { - if (this.fcl == null) { - // Need to keep reference to fcl. - // See JavaDoc for org.openide.util.WeakListeners - FileObject prjFo = this.projectHelper.getProjectDirectory(); - this.fcl = new AddOnGeneratedSourceRootListner(prjFo, buildDir, - paths); - ((AddOnGeneratedSourceRootListner) this.fcl).listenToProjRoot(); - } - } - - private List getGeneratedSrcRoots(String buildDir, String[] paths) { - List ret = - new ArrayList(); - - File buidDirFile = projectHelper.resolveFile(buildDir); - for (String path : paths) { - File genAddOns = new File(buidDirFile, path); - if (genAddOns.exists() && genAddOns.isDirectory()) { - File[] subDirs = genAddOns.listFiles(); - for (File subDir : subDirs) { - try { - URL url = subDir.toURI().toURL(); - if (!subDir.exists()) { - assert !url.toExternalForm().endsWith("/"); //NOI18N - url = new URL(url.toExternalForm() + '/'); //NOI18N - } - ret.add(ClassPathSupport.createResource(url)); - } catch (MalformedURLException ex) { - Exceptions.printStackTrace(ex); - } - } - } - } - return ret; - } - - private void invalidate() { - synchronized (this) { - this.resources = null; - } - this.support.firePropertyChange(PROP_RESOURCES, null, null); - } - - public List getResources() { - synchronized (this) { - if (this.resources != null) { - return this.resources; - } - } - URL[] roots = sourceRoots.getRootURLs(); - synchronized (this) { - if (this.resources == null) { - List result = new ArrayList(roots.length); - for (final URL root : roots) { - class PRI implements FilteringPathResourceImplementation, PropertyChangeListener { - - PropertyChangeSupport pcs = new PropertyChangeSupport(this); - PathMatcher matcher; - - PRI() { - evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, evaluator)); - } - - public URL[] getRoots() { - return new URL[]{root}; - } - - public boolean includes(URL root, String resource) { - if (matcher == null) { - matcher = new PathMatcher( - evaluator.getProperty(J2SEProjectProperties.INCLUDES), - evaluator.getProperty(J2SEProjectProperties.EXCLUDES), - new File(URI.create(root.toExternalForm()))); - } - return matcher.matches(resource, true); - } - - public ClassPathImplementation getContent() { - return null; - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - public void propertyChange(PropertyChangeEvent ev) { - String prop = ev.getPropertyName(); - if (prop == null || prop.equals(J2SEProjectProperties.INCLUDES) || prop.equals(J2SEProjectProperties.EXCLUDES)) { - matcher = null; - PropertyChangeEvent ev2 = new PropertyChangeEvent(this, FilteringPathResourceImplementation.PROP_INCLUDES, null, null); - ev2.setPropagationId(ev); - pcs.firePropertyChange(ev2); - } - } - } - result.add(new PRI()); - } - // adds java artifacts generated by wscompile and wsimport to resources to be available for code completion - try { - String buildDir = this.evaluator.getProperty(PROP_BUILD_DIR); - if (buildDir != null) { - // generated/wsclient - File f = new File(this.projectHelper.resolveFile(buildDir), "generated/wsclient"); //NOI18N - URL url = f.toURI().toURL(); - if (!f.exists()) { //NOI18N - assert !url.toExternalForm().endsWith("/"); //NOI18N - url = new URL(url.toExternalForm() + '/'); //NOI18N - } - result.add(ClassPathSupport.createResource(url)); - - // generated/wsimport/client - f = new File(this.projectHelper.resolveFile(buildDir), "generated/wsimport/client"); //NOI18N - url = f.toURI().toURL(); - if (!f.exists()) { //NOI18N - assert !url.toExternalForm().endsWith("/"); //NOI18N - url = new URL(url.toExternalForm() + '/'); //NOI18N - } - result.add(ClassPathSupport.createResource(url)); - - // generated/addons/ - result.addAll(getGeneratedSrcRoots(buildDir, - new String[]{DIR_GEN_BINDINGS})); - // Listen for any new Source root creation. - createListener(buildDir, - new String[]{DIR_GEN_BINDINGS}); - } - } catch (MalformedURLException ex) { - Exceptions.printStackTrace(ex); - } - this.resources = Collections.unmodifiableList(result); - } - return this.resources; - } - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - support.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - support.removePropertyChangeListener(listener); - } - - public void propertyChange(PropertyChangeEvent evt) { - if (SourceRoots.PROP_ROOTS.equals(evt.getPropertyName())) { - invalidate(); - } else if (this.evaluator != null && evt.getSource() == this.evaluator && - (evt.getPropertyName() == null || PROP_BUILD_DIR.equals(evt.getPropertyName()))) { - invalidate(); - } - } - - /** - * Thread to get newly created source root for each File/Folder create event. - **/ - private static class SourceRootScannerTask implements Runnable { - - SourcePathImplementation spi = null; - FileChangeListener fcl = null; - List> paths = null; - FileObject parent = null; - FileObject child = null; - List listnerAddedDirs = new ArrayList(); - - public SourceRootScannerTask(SourcePathImplementation s, - FileChangeListener origFcl, List> pths, - FileObject parent, FileObject child) { - this.spi = s; - this.fcl = origFcl; - this.paths = pths; - this.parent = parent; - this.child = child; - } - - private void firePropertyChange() { - this.spi.invalidate(); - } - - private void addListners(List path, int cIndx) { - int size = path.size(); - FileObject currParent = this.parent; - FileObject curr = this.child; - String relDir = null; - FileChangeListener weakFcl = null; - for (int i = cIndx; i < size; i++) { - curr = currParent.getFileObject(path.get(i)); - if ((curr != null) && (curr.isFolder())) { - relDir = FileUtil.getRelativePath(this.parent, curr); - if (!this.listnerAddedDirs.contains(relDir)) { - this.listnerAddedDirs.add(relDir); - weakFcl = FileUtil.weakFileChangeListener(this.fcl, - curr); - curr.addFileChangeListener(weakFcl); - } - - if (i == (size - 1)) { - if (curr.getChildren().length > 0) { - firePropertyChange(); - } - break; - } - - currParent = curr; - } else { - break; - } - } - } - - public void run() { - Iterator> itr = paths.iterator(); - List path = null; - int cIndx = -1; - int pIndx = -1; - boolean lastElem = false; - - while (itr.hasNext()) { - path = itr.next(); - cIndx = path.indexOf(child.getName()); - pIndx = path.indexOf(parent.getName()); - - lastElem = ((pIndx + 1) == path.size()) ? true : false; - - if (lastElem) { - if (cIndx == -1) { - firePropertyChange(); - } - } else { - if ((cIndx != -1) && (pIndx == (cIndx - 1))) { - // Add listner and fire change event if leaf directory - // is created. - addListners(path, cIndx); - } - } - } - } - } - - private class AddOnGeneratedSourceRootListner extends FileChangeAdapter { - // Path is relative to project root starting with project specific - // build directory. - private List> paths = Collections.synchronizedList( - new ArrayList>()); - private FileObject projRoot; - - AddOnGeneratedSourceRootListner(FileObject pr, String bd, String[] addOnPaths) { - this.projRoot = pr; - StringTokenizer stk = null; - List pathElems = null; - for (String path : addOnPaths) { - stk = new StringTokenizer(path, "/"); // No I18N - pathElems = new ArrayList(); - pathElems.add(bd); - while (stk.hasMoreTokens()) { - pathElems.add(stk.nextToken()); - } - this.paths.add(pathElems); - } - } - - /** - * Listen to all the folders from ProjectRoot, build upto any existing - * addons dirs. - **/ - public synchronized void listenToProjRoot() { - List dirsAdded = new ArrayList(); - String relativePath = null; - FileObject fo = this.projRoot; - FileChangeListener weakFcl = FileUtil.weakFileChangeListener(this, - fo); - fo.addFileChangeListener(weakFcl); - FileObject parent = null; - FileObject child = null; - for (List path : paths) { - parent = fo; - for (String pathElem : path) { - child = parent.getFileObject(pathElem); - if (child != null) { - relativePath = FileUtil.getRelativePath(fo, child); - if (!dirsAdded.contains(relativePath)) { - dirsAdded.add(relativePath); - weakFcl = FileUtil.weakFileChangeListener(this, - child); - child.addFileChangeListener(weakFcl); - parent = child; - } - } else { - // No need to check further down. - break; - } - } - } - } - - @Override - public void fileFolderCreated(FileEvent fe) { - synchronized (this) { - SourceRootScannerTask task = new SourceRootScannerTask( - SourcePathImplementation.this, - this, - this.paths, - (FileObject) fe.getSource(), - fe.getFile()); - SourcePathImplementation.REQ_PROCESSOR.post(task); - } - } - } -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/BinaryForSourceQueryImpl.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/BinaryForSourceQueryImpl.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/queries/BinaryForSourceQueryImpl.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.queries; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import javax.swing.event.ChangeListener; -import org.netbeans.api.java.queries.BinaryForSourceQuery; -import org.netbeans.api.java.queries.BinaryForSourceQuery.Result; -import org.netbeans.modules.java.api.common.SourceRoots; -import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; -import org.netbeans.spi.java.queries.BinaryForSourceQueryImplementation; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.util.ChangeSupport; -import org.openide.util.Exceptions; - -/** - * - * @author Tomas Zezula - */ -public class BinaryForSourceQueryImpl implements BinaryForSourceQueryImplementation { - - - private final Map cache = new HashMap(); - private final SourceRoots src; - private final SourceRoots test; - private final PropertyEvaluator eval; - private final AntProjectHelper helper; - - /** Creates a new instance of BinaryForSourceQueryImpl */ - public BinaryForSourceQueryImpl(SourceRoots src, SourceRoots test, AntProjectHelper helper, PropertyEvaluator eval) { - assert src != null; - assert test != null; - assert helper != null; - assert eval != null; - this.src = src; - this.test = test; - this.eval = eval; - this.helper = helper; - } - - public Result findBinaryRoots(URL sourceRoot) { - assert sourceRoot != null; - BinaryForSourceQuery.Result result = cache.get(sourceRoot); - if (result == null) { - for (URL root : this.src.getRootURLs()) { - if (root.equals(sourceRoot)) { - result = new R (J2SEProjectProperties.BUILD_CLASSES_DIR); - cache.put (sourceRoot,result); - break; - } - } - for (URL root : this.test.getRootURLs()) { - if (root.equals(sourceRoot)) { - result = new R (J2SEProjectProperties.BUILD_TEST_CLASSES_DIR); - cache.put (sourceRoot,result); - break; - } - } - } - return result; - } - - class R implements BinaryForSourceQuery.Result, PropertyChangeListener { - - private final String propName; - private final ChangeSupport changeSupport = new ChangeSupport(this); - - R (final String propName) { - assert propName != null; - this.propName = propName; - eval.addPropertyChangeListener(this); - } - - public URL[] getRoots() { - String val = eval.getProperty(propName); - if (val != null) { - File f = helper.resolveFile(val); - if (f != null) { - try { - return new URL[] {f.toURI().toURL()}; - } catch (MalformedURLException e) { - Exceptions.printStackTrace(e); - } - } - } - return new URL[0]; - } - - public void addChangeListener(ChangeListener l) { - assert l != null; - changeSupport.addChangeListener(l); - } - - public void removeChangeListener(ChangeListener l) { - assert l != null; - changeSupport.removeChangeListener(l); - } - - public void propertyChange(PropertyChangeEvent event) { - changeSupport.fireChange(); - } -} - -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ActionFilterNode.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ActionFilterNode.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ActionFilterNode.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.ui; - -import java.io.IOException; -import java.net.URL; -import java.util.List; -import java.util.ArrayList; -import javax.swing.Action; -import org.netbeans.api.project.FileOwnerQuery; -import org.netbeans.api.project.Project; -import org.netbeans.modules.java.j2seproject.classpath.ClassPathSupport; -import org.openide.ErrorManager; -import org.openide.actions.EditAction; -import org.openide.actions.FindAction; -import org.openide.loaders.DataObject; -import org.openide.actions.OpenAction; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileStateInvalidException; -import org.openide.filesystems.FileUtil; -import org.openide.nodes.FilterNode; -import org.openide.nodes.Node; -import org.openide.util.Lookup; -import org.openide.util.actions.SystemAction; -import org.openide.util.lookup.Lookups; -import org.openide.util.lookup.ProxyLookup; -import org.netbeans.api.java.queries.JavadocForBinaryQuery; -import org.netbeans.api.project.ProjectManager; -import org.netbeans.modules.java.api.common.ant.UpdateHelper; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.netbeans.spi.project.support.ant.PropertyUtils; -import org.netbeans.spi.project.support.ant.ReferenceHelper; - -/** - * This class decorates package nodes and file nodes under the Libraries Nodes. - * It removes all actions from these nodes except of file node's {@link OpenAction} - * and package node's {@link FindAction} It also adds the {@link ShowJavadocAction} - * to both file and package nodes. It also adds {@link RemoveClassPathRootAction} to - * class path roots. - */ -class ActionFilterNode extends FilterNode { - - private static final int MODE_ROOT = 1; - private static final int MODE_PACKAGE = 2; - private static final int MODE_FILE = 3; - private static final int MODE_FILE_CONTENT = 4; - - private final int mode; - private Action[] actionCache; - - /** - * Creates new ActionFilterNode for class path root - * @param original the original node - * @param helper used for implementing {@link RemoveClassPathRootAction.Removable} or null if - * the node should not have the {@link RemoveClassPathRootAction} - * @param classPathId ant property name of classpath to which these classpath root belongs or null if - * the node should not have the {@link RemoveClassPathRootAction} - * @param entryId ant property name of this classpath root or null if - * the node should not have the {@link RemoveClassPathRootAction} - * @return ActionFilterNode - */ - static ActionFilterNode create (Node original, UpdateHelper helper, ReferenceHelper refHelper, String classPathId, String entryId) { - DataObject dobj = original.getLookup().lookup(DataObject.class); - assert dobj != null; - FileObject root = dobj.getPrimaryFile(); - Lookup lkp = new ProxyLookup (new Lookup[] {original.getLookup(), helper == null ? - Lookups.singleton (new JavadocProvider(root,root)) : - Lookups.fixed(new Removable(helper, refHelper, classPathId, entryId), - new JavadocProvider(root,root))}); - return new ActionFilterNode (original, helper == null ? MODE_PACKAGE : MODE_ROOT, root, lkp); - } - - - - private ActionFilterNode (Node original, int mode, FileObject cpRoot, FileObject resource) { - this (original, mode, cpRoot, - new ProxyLookup(new Lookup[] {original.getLookup(),Lookups.singleton(new JavadocProvider(cpRoot,resource))})); - } - - private ActionFilterNode (Node original, int mode) { - super(original, original.isLeaf() ? Children.LEAF : new ActionFilterChildren(original, mode, null)); - this.mode = mode; - } - - private ActionFilterNode (Node original, int mode, FileObject root, Lookup lkp) { - super(original, original.isLeaf() ? Children.LEAF : new ActionFilterChildren(original, mode, root), lkp); - this.mode = mode; - } - - public Action[] getActions(boolean context) { - Action[] result = initActions(); - return result; - } - - - public Action getPreferredAction() { - if (mode == MODE_FILE) { - Action[] actions = initActions(); - if (actions.length > 0 && (actions[0] instanceof OpenAction || actions[0] instanceof EditAction )) { - return actions[0]; - } - } - return null; - } - - private Action[] initActions () { - if (actionCache == null) { - List result = new ArrayList(2); - if (mode == MODE_FILE) { - for (Action superAction : super.getActions(false)) { - if (superAction instanceof OpenAction || superAction instanceof EditAction) { - result.add(superAction); - } - } - result.add (SystemAction.get(ShowJavadocAction.class)); - } - else if (mode == MODE_PACKAGE || mode == MODE_ROOT) { - result.add (SystemAction.get(ShowJavadocAction.class)); - Action[] superActions = super.getActions(false); - for (int i=0; i0; - } catch (FileStateInvalidException fsi) { - return false; - } - } - - public void showJavadoc() { - try { - String relativeName = FileUtil.getRelativePath(cpRoot,resource); - URL[] urls = JavadocForBinaryQuery.findJavadoc(cpRoot.getURL()).getRoots(); - URL pageURL; - if (relativeName.length()==0) { - pageURL = ShowJavadocAction.findJavadoc ("overview-summary.html",urls); //NOI18N - if (pageURL == null) { - pageURL = ShowJavadocAction.findJavadoc ("index.html",urls); //NOI18N - } - } - else if (resource.isFolder()) { - //XXX Are the names the same also in the localized javadoc? - pageURL = ShowJavadocAction.findJavadoc (relativeName+"/package-summary.html",urls); //NOI18N - } - else { - String javadocFileName = relativeName.substring(0,relativeName.lastIndexOf('.'))+".html"; //NOI18Ns - pageURL = ShowJavadocAction.findJavadoc (javadocFileName,urls); - } - ShowJavadocAction.showJavaDoc(pageURL,relativeName.replace('/','.')); //NOI18N - } catch (FileStateInvalidException fsi) { - ErrorManager.getDefault().notify (fsi); - } - } - } - - private static class Removable implements RemoveClassPathRootAction.Removable { - - private final UpdateHelper helper; - private final ReferenceHelper refHelper; - private final String classPathId; - private final String entryId; - - Removable (UpdateHelper helper, ReferenceHelper refHelper, String classPathId, String entryId) { - this.helper = helper; - this.refHelper = refHelper; - this.classPathId = classPathId; - this.entryId = entryId; - } - - - public boolean canRemove () { - //Allow to remove only entries from PROJECT_PROPERTIES, same behaviour as the project customizer - EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - return props.getProperty (classPathId) != null; - } - - public void remove() { - ProjectManager.mutex().writeAccess ( new Runnable () { - public void run() { - EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - String cp = props.getProperty (classPathId); - if (cp != null) { - List result = new ArrayList(); - for (String entry : PropertyUtils.tokenizePath(cp)) { - if (!entryId.equals(ClassPathSupport.getAntPropertyName(entry))) { - int size = result.size(); - if (size>0) { - result.set(size - 1, result.get(size - 1) + ':'); //NOI18N - } - result.add(entry); - } - } - props.setProperty(classPathId, result.toArray(new String[result.size()])); - helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,props); - Project project = FileOwnerQuery.getOwner(helper.getAntProjectHelper().getProjectDirectory()); - assert project != null; - try { - ProjectManager.getDefault().saveProject(project); - } catch (IOException ioe) { - ErrorManager.getDefault().notify(ioe); - } - } - } - }); - } - } -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/J2SELogicalViewProvider.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/J2SELogicalViewProvider.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/J2SELogicalViewProvider.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/J2SELogicalViewProvider.java @@ -62,6 +62,8 @@ import org.netbeans.api.project.ProjectUtils; import org.netbeans.modules.java.api.common.SourceRoots; import org.netbeans.modules.java.api.common.ant.UpdateHelper; +import org.netbeans.modules.java.api.common.project.ProjectProperties; +import org.netbeans.modules.java.api.common.project.ui.LogicalViewProvider2; import org.netbeans.modules.java.j2seproject.J2SEProjectUtil; import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; import org.netbeans.modules.java.j2seproject.J2SEProject; @@ -71,7 +73,6 @@ import org.netbeans.spi.project.SubprojectProvider; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.ReferenceHelper; -import org.netbeans.spi.project.ui.LogicalViewProvider; import org.netbeans.spi.project.ui.support.CommonProjectActions; import org.netbeans.spi.project.ui.support.NodeFactorySupport; import org.netbeans.spi.project.ui.support.DefaultProjectOperations; @@ -98,7 +99,7 @@ * Support for creating logical views. * @author Petr Hrebejk */ -public class J2SELogicalViewProvider implements LogicalViewProvider { +public class J2SELogicalViewProvider implements LogicalViewProvider2 { private static final RequestProcessor RP = new RequestProcessor("J2SEPhysicalViewProvider.RP"); // NOI18N @@ -185,12 +186,12 @@ // Private innerclasses ---------------------------------------------------- private static final String[] BREAKABLE_PROPERTIES = { - J2SEProjectProperties.JAVAC_CLASSPATH, - J2SEProjectProperties.RUN_CLASSPATH, + ProjectProperties.JAVAC_CLASSPATH, + ProjectProperties.RUN_CLASSPATH, J2SEProjectProperties.DEBUG_CLASSPATH, - J2SEProjectProperties.RUN_TEST_CLASSPATH, + ProjectProperties.RUN_TEST_CLASSPATH, J2SEProjectProperties.DEBUG_TEST_CLASSPATH, - J2SEProjectProperties.JAVAC_TEST_CLASSPATH, + ProjectProperties.JAVAC_TEST_CLASSPATH, }; public boolean hasBrokenLinks () { diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNode.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNode.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNode.java +++ /dev/null @@ -1,826 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.ui; - -import java.awt.Image; -import java.awt.event.ActionEvent; -import java.beans.BeanInfo; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.IOException; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.Icon; -import javax.swing.ImageIcon; -import javax.swing.JFileChooser; -import javax.swing.UIManager; -import javax.swing.filechooser.FileFilter; -import org.openide.ErrorManager; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.filesystems.Repository; -import org.openide.filesystems.URLMapper; -import org.openide.loaders.DataFolder; -import org.openide.nodes.AbstractNode; -import org.openide.nodes.Children; -import org.openide.nodes.Node; -import org.openide.util.ImageUtilities; -import org.openide.util.NbBundle; -import org.openide.util.RequestProcessor; -import org.openide.util.Utilities; -import org.openide.util.lookup.Lookups; -import org.openide.windows.WindowManager; -import org.netbeans.api.project.SourceGroup; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ant.AntArtifact; -import org.netbeans.api.project.libraries.Library; -import org.netbeans.api.java.classpath.ClassPath; -import org.netbeans.api.java.project.JavaProjectConstants; -import org.netbeans.api.project.ant.FileChooser; -import org.netbeans.api.project.libraries.LibraryChooser; -import org.netbeans.api.project.libraries.LibraryManager; -import org.netbeans.modules.java.api.common.SourceRoots; -import org.netbeans.modules.java.api.common.ant.UpdateHelper; -import org.netbeans.modules.java.j2seproject.J2SEProject; -import org.netbeans.modules.java.j2seproject.classpath.ClassPathProviderImpl; -import org.netbeans.modules.java.j2seproject.classpath.J2SEProjectClassPathModifier; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.spi.project.support.ant.PropertyUtils; -import org.netbeans.spi.project.support.ant.ReferenceHelper; -import org.netbeans.spi.java.project.support.ui.PackageView; -import org.netbeans.spi.java.classpath.support.ClassPathSupport; -import org.netbeans.modules.java.j2seproject.ui.customizer.AntArtifactChooser; -import org.netbeans.spi.project.libraries.support.LibrariesSupport; -import org.openide.util.Exceptions; - -/** - * LibrariesNode displays the content of classpath and optionaly Java platform. - * @author Tomas Zezula - */ -final class LibrariesNode extends AbstractNode { - - private static final String ICON_KEY_UIMANAGER = "Tree.closedIcon"; // NOI18N - private static final String OPENED_ICON_KEY_UIMANAGER = "Tree.openIcon"; // NOI18N - private static final String ICON_KEY_UIMANAGER_NB = "Nb.Explorer.Folder.icon"; // NOI18N - private static final String OPENED_ICON_KEY_UIMANAGER_NB = "Nb.Explorer.Folder.openedIcon"; // NOI18N - - - private static final Image ICON_BADGE = ImageUtilities.loadImage("org/netbeans/modules/java/j2seproject/ui/resources/libraries-badge.png"); //NOI18N - static final RequestProcessor rp = new RequestProcessor (); - private static Image folderIconCache; - private static Image openedFolderIconCache; - - private final String displayName; - private final Action[] librariesNodeActions; - - /** - * Creates new LibrariesNode named displayName displaying classPathProperty classpath - * and optionaly Java platform. - * @param displayName the display name of the node - * @param project the project owning this node, the proejct is placed into LibrariesNode's lookup - * @param eval {@link PropertyEvaluator} used for listening - * @param helper {@link UpdateHelper} used for reading and updating project's metadata - * @param refHelper {@link ReferenceHelper} used for destroying unused references - * @param classPathProperty the ant property name of classpath which should be visualized - * @param classPathIgnoreRef the array of ant property names which should not be displayed, may be - * an empty array but not null - * @param platformProperty the ant name property holding the J2SE platform system name or null - * if the platform should not be displayed - * @param librariesNodeActions actions which should be available on the created node. - */ - LibrariesNode (String displayName, Project project, PropertyEvaluator eval, UpdateHelper helper, ReferenceHelper refHelper, - String classPathProperty, String[] classPathIgnoreRef, String platformProperty, - Action[] librariesNodeActions) { - super (new LibrariesChildren (project, eval, helper, refHelper, classPathProperty, classPathIgnoreRef, platformProperty), Lookups.singleton(project)); - this.displayName = displayName; - this.librariesNodeActions = librariesNodeActions; - } - - public String getDisplayName () { - return this.displayName; - } - - public String getName () { - return this.getDisplayName(); - } - - public Image getIcon( int type ) { - return computeIcon( false, type ); - } - - public Image getOpenedIcon( int type ) { - return computeIcon( true, type ); - } - - public Action[] getActions(boolean context) { - return this.librariesNodeActions; - } - - public boolean canCopy() { - return false; - } - - //Static Action Factory Methods - public static Action createAddProjectAction (J2SEProject p, boolean sources) { - if (sources) { - return new AddProjectAction(p, p.getSourceRoots()); - } else { - return new AddProjectAction(p, p.getTestSourceRoots()); - } - } - - public static Action createAddLibraryAction (J2SEProject p, boolean sources) { - if (sources) { - return new AddLibraryAction(p, p.getSourceRoots()); - } else { - return new AddLibraryAction(p, p.getTestSourceRoots()); - } - } - - public static Action createAddFolderAction (J2SEProject p, boolean sources) { - if (sources) { - return new AddFolderAction(p, p.getSourceRoots()); - } else { - return new AddFolderAction(p, p.getTestSourceRoots()); - } - } - - /** - * Returns Icon of folder on active platform - * @param opened should the icon represent opened folder - * @return the folder icon - */ - static synchronized Image getFolderIcon (boolean opened) { - if (opened) { - if (openedFolderIconCache == null) { - openedFolderIconCache = getTreeFolderIcon(opened); - } - return openedFolderIconCache; - } - else { - if (folderIconCache == null) { - folderIconCache = getTreeFolderIcon(opened); - } - return folderIconCache; - } - } - - private Image computeIcon( boolean opened, int type ) { - Image image = getFolderIcon(opened); - image = ImageUtilities.mergeImages(image, ICON_BADGE, 7, 7 ); - return image; - } - - //Static inner classes - private static class LibrariesChildren extends Children.Keys implements PropertyChangeListener { - - - /** - * Constant represneting a prefix of library reference generated by {@link org.netbeans.modules.java.j2seplatform.libraries.J2SELibraryTypeProvider} - */ - private static final String LIBRARY_PREFIX = "${libs."; // NOI18N - - /** - * Constant representing a prefix of artifact reference generated by {@link ReferenceHelper} - */ - private static final String ANT_ARTIFACT_PREFIX = "${reference."; // NOI18N - /** - * Constant representing a prefix of file reference generated by {@link ReferenceHelper} - */ - private static final String FILE_REF_PREFIX = "${file.reference."; //NOI18N - /** - * Constant representing a prefix of ant property reference - */ - private static final String REF_PREFIX = "${"; //NOI18N - - private static final String LIBRARIES_ICON = "org/netbeans/modules/java/j2seproject/ui/resources/libraries.gif"; //NOI18N - private static final String ARCHIVE_ICON = "org/netbeans/modules/java/j2seproject/ui/resources/jar.gif";//NOI18N - - private final Project project; - private final PropertyEvaluator eval; - private final UpdateHelper helper; - private final ReferenceHelper refHelper; - private final String classPathProperty; - private final String platformProperty; - private final Set classPathIgnoreRef; - - //XXX: Workaround: classpath is used only to listen on non existent files. - // This should be removed when there will be API for it - // See issue: http://www.netbeans.org/issues/show_bug.cgi?id=33162 - private ClassPath fsListener; - - - LibrariesChildren (Project project, PropertyEvaluator eval, UpdateHelper helper, ReferenceHelper refHelper, - String classPathProperty, String[] classPathIgnoreRef, String platformProperty) { - this.project = project; - this.eval = eval; - this.helper = helper; - this.refHelper = refHelper; - this.classPathProperty = classPathProperty; - this.classPathIgnoreRef = new HashSet(Arrays.asList(classPathIgnoreRef)); - this.platformProperty = platformProperty; - } - - public void propertyChange(PropertyChangeEvent evt) { - String propName = evt.getPropertyName(); - final boolean propRoots = ClassPath.PROP_ROOTS.equals(propName); - if (classPathProperty.equals(propName) || propRoots || LibraryManager.PROP_LIBRARIES.equals(propName)) { - synchronized (this) { - if (fsListener!=null) { - fsListener.removePropertyChangeListener (this); - } - } - rp.post (new Runnable () { - public void run () { - setKeys(getKeys()); - if (propRoots) { - J2SELogicalViewProvider lvp = project.getLookup().lookup(J2SELogicalViewProvider.class); - if (lvp != null) { - lvp.testBroken(); - } - } - } - }); - } - } - - protected void addNotify() { - this.eval.addPropertyChangeListener (this); - if (refHelper.getProjectLibraryManager() != null) { - refHelper.getProjectLibraryManager().addPropertyChangeListener(this); - } else { - LibraryManager.getDefault().addPropertyChangeListener(this); - } - this.setKeys(getKeys ()); - } - - protected void removeNotify() { - this.eval.removePropertyChangeListener(this); - if (refHelper.getProjectLibraryManager() != null) { - refHelper.getProjectLibraryManager().removePropertyChangeListener(this); - } else { - LibraryManager.getDefault().removePropertyChangeListener(this); - } - synchronized (this) { - if (fsListener!=null) { - fsListener.removePropertyChangeListener (this); - fsListener = null; - } - } - this.setKeys(Collections.EMPTY_SET); - } - - protected Node[] createNodes(Object obj) { - Node[] result = null; - if (obj instanceof Key) { - Key key = (Key) obj; - switch (key.getType()) { - case Key.TYPE_PLATFORM: - result = new Node[] {PlatformNode.create(eval, platformProperty)}; - break; - case Key.TYPE_PROJECT: - result = new Node[] {new ProjectNode(key.getProject(), key.getArtifactLocation(), helper, refHelper, key.getClassPathId(), - key.getEntryId())}; - break; - case Key.TYPE_LIBRARY: - result = new Node[] {ActionFilterNode.create(PackageView.createPackageView(key.getSourceGroup()), - helper, refHelper, key.getClassPathId(), key.getEntryId())}; - break; - } - } - if (result == null) { - assert false : "Unknown key type"; //NOI18N - result = new Node[0]; - } - return result; - } - - private List getKeys () { - EditableProperties projectSharedProps = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); - EditableProperties projectPrivateProps = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); - EditableProperties privateProps = PropertyUtils.getGlobalProperties(); - List/**/ rootsList = new ArrayList (); - List result = getKeys (projectSharedProps, projectPrivateProps, privateProps, classPathProperty, rootsList); - //Add PlatformNode if needed and project exists - FileObject projectDir = helper.getAntProjectHelper().getProjectDirectory(); - if (platformProperty!=null && projectDir !=null && projectDir.isValid() && !projectDir.isVirtual()) { - result.add (new Key()); - } - //XXX: Workaround: Remove this when there will be API for listening on nonexistent files - // See issue: http://www.netbeans.org/issues/show_bug.cgi?id=33162 - ClassPath cp = ClassPathSupport.createClassPath ((URL[])rootsList.toArray(new URL[rootsList.size()])); - cp.addPropertyChangeListener (this); - cp.getRoots(); - synchronized (this) { - fsListener = cp; - } - return result; - } - - private List getKeys (EditableProperties projectSharedProps, EditableProperties projectPrivateProps, - EditableProperties privateProps, String currentClassPath, List/**/ rootsList) { - List result = new ArrayList (); - String raw = projectSharedProps.getProperty (currentClassPath); - if (raw == null) { - raw = projectPrivateProps.getProperty(currentClassPath); - } - if (raw == null) { - raw = privateProps.getProperty(currentClassPath); - } - if (raw == null) { - return result; - } - List pe = new ArrayList(Arrays.asList(PropertyUtils.tokenizePath( raw ))); - while (pe.size()>0){ - String prop = (String) pe.remove(0); - String propName = org.netbeans.modules.java.j2seproject.classpath.ClassPathSupport.getAntPropertyName (prop); - if (classPathIgnoreRef.contains(propName)) { - continue; - } - else if (prop.startsWith( LIBRARY_PREFIX )) { - //Library reference - String val = prop.substring( LIBRARY_PREFIX.length(), prop.lastIndexOf('.') ); //NOI18N - Library lib = refHelper.findLibrary(val); - if (lib != null) { - List/**/ roots = lib.getContent("classpath"); //NOI18N - Icon libIcon = new ImageIcon (ImageUtilities.loadImage(LIBRARIES_ICON)); - for (Iterator it = roots.iterator(); it.hasNext();) { - URL rootUrl = (URL) it.next(); - rootsList.add (rootUrl); - FileObject root = URLMapper.findFileObject (rootUrl); - if (root != null) { - String displayName; - if ("jar".equals(rootUrl.getProtocol())) { //NOI18N - FileObject file = FileUtil.getArchiveFile (root); - displayName = file.getNameExt(); - } - else { - File file = FileUtil.toFile (root); - if (file != null) { - displayName = file.getAbsolutePath(); - } - else { - displayName = root.getNameExt(); - } - } - displayName = MessageFormat.format ( - NbBundle.getMessage (LibrariesNode.class,"TXT_LibraryPartFormat"), - new Object[] {lib.getDisplayName(), displayName}); - SourceGroup sg = new LibrariesSourceGroup (root, displayName, libIcon, libIcon); - result.add (new Key(sg,currentClassPath, propName)); - } - } - } - //Todo: May try to resolve even broken library - } - else if (prop.startsWith(ANT_ARTIFACT_PREFIX)) { - //Project reference - Object ret[] = refHelper.findArtifactAndLocation(prop); - if ( ret[0] != null && ret[1] != null) { - AntArtifact artifact = (AntArtifact)ret[0]; - URI uri = (URI) ret[1]; - result.add (new Key(artifact, uri, currentClassPath, propName)); - } - } - else if (prop.startsWith(FILE_REF_PREFIX)) { - //File reference - String evaluatedRef = eval.getProperty(propName); - if (evaluatedRef != null) { - File file = helper.getAntProjectHelper().resolveFile(evaluatedRef); - SourceGroup sg = createFileSourceGroup(file,rootsList); - if (sg !=null) { - result.add (new Key(sg,currentClassPath, propName)); - } - } - } - else if (prop.startsWith(REF_PREFIX)) { - //Path reference - result.addAll(getKeys(projectSharedProps, projectPrivateProps, privateProps,propName, rootsList)); - } - else { - //file - File file = helper.getAntProjectHelper().resolveFile(prop); - SourceGroup sg = createFileSourceGroup(file,rootsList); - if (sg !=null) { - result.add ( new Key(sg,currentClassPath, propName)); - } - } - } - return result; - } - - private static SourceGroup createFileSourceGroup (File file, List/**/ rootsList) { - Icon icon; - Icon openedIcon; - String displayName; - try { - URL url = file.toURI().toURL(); - if (FileUtil.isArchiveFile(url)) { - url = FileUtil.getArchiveRoot(url); - icon = openedIcon = new ImageIcon (ImageUtilities.loadImage(ARCHIVE_ICON)); - displayName = file.getName(); - } - else { - String sURL = url.toExternalForm(); - if (!sURL.endsWith("/")) { //NOI18N - url = new URL (sURL+"/"); //NOI18N - } - icon = new ImageIcon (getFolderIcon (false)); - openedIcon = new ImageIcon (getFolderIcon (true)); - displayName = file.getAbsolutePath(); - } - rootsList.add (url); - FileObject root = URLMapper.findFileObject (url); - if (root != null) { - return new LibrariesSourceGroup (root,displayName,icon,openedIcon); - } - } catch (MalformedURLException e) { - ErrorManager.getDefault().notify(e); - } - return null; - } - } - - private static class Key { - static final int TYPE_PLATFORM = 0; - static final int TYPE_LIBRARY = 1; - static final int TYPE_PROJECT = 2; - - private int type; - private String classPathId; - private String entryId; - private SourceGroup sg; - private AntArtifact antArtifact; - private URI uri; - - Key () { - this.type = TYPE_PLATFORM; - } - - Key (SourceGroup sg, String classPathId, String entryId) { - this.type = TYPE_LIBRARY; - this.sg = sg; - this.classPathId = classPathId; - this.entryId = entryId; - } - - Key (AntArtifact a, URI uri, String classPathId, String entryId) { - this.type = TYPE_PROJECT; - this.antArtifact = a; - this.uri = uri; - this.classPathId = classPathId; - this.entryId = entryId; - } - - public int getType () { - return this.type; - } - - public String getClassPathId () { - return this.classPathId; - } - - public String getEntryId () { - return this.entryId; - } - - public SourceGroup getSourceGroup () { - return this.sg; - } - - public AntArtifact getProject () { - return this.antArtifact; - } - - public URI getArtifactLocation () { - return this.uri; - } - - public int hashCode() { - int hashCode = this.type<<16; - switch (this.type) { - case TYPE_LIBRARY: - hashCode ^= this.sg == null ? 0 : this.sg.hashCode(); - break; - case TYPE_PROJECT: - hashCode ^= this.antArtifact == null ? 0 : this.antArtifact.hashCode(); - break; - } - return hashCode; - } - - public boolean equals(Object obj) { - if (!(obj instanceof Key)) { - return false; - } - Key other = (Key) obj; - if (other.type != type) { - return false; - } - switch (type) { - case TYPE_LIBRARY: - return (this.sg == null ? other.sg == null : this.sg.equals(other.sg)) && - (this.classPathId == null ? other.classPathId == null : this.classPathId.equals (other.classPathId)) && - (this.entryId == null ? other.entryId == null : this.entryId.equals (other.entryId)); - case TYPE_PROJECT: - return (this.antArtifact == null ? other.antArtifact == null : this.antArtifact.equals(other.antArtifact)) && - (this.classPathId == null ? other.classPathId == null : this.classPathId.equals (other.classPathId)) && - (this.entryId == null ? other.entryId == null : this.entryId.equals (other.entryId)); - case TYPE_PLATFORM: - return true; - default: - throw new IllegalStateException(); - } - } - } - - private static class AddProjectAction extends AbstractAction { - - private final J2SEProject project; - private final SourceRoots projectSourcesArtifact; - - public AddProjectAction (final J2SEProject project, final SourceRoots projectSourcesArtifact) { - super( NbBundle.getMessage( LibrariesNode.class, "LBL_AddProject_Action" ) ); - assert project != null; - assert projectSourcesArtifact != null; - this.project = project; - this.projectSourcesArtifact = projectSourcesArtifact; - } - - public void actionPerformed(ActionEvent e) { - final ClassPathProviderImpl cpProvider = project.getClassPathProvider(); - assert cpProvider != null; - final J2SEProjectClassPathModifier cpMod = this.project.getLookup().lookup(J2SEProjectClassPathModifier.class); - assert cpMod != null; - AntArtifactChooser.ArtifactItem ai[] = AntArtifactChooser.showDialog( - new String[] {JavaProjectConstants.ARTIFACT_TYPE_JAR, JavaProjectConstants.ARTIFACT_TYPE_FOLDER}, - project, null); - if ( ai != null ) { - final String propName = cpProvider.getPropertyName(projectSourcesArtifact, ClassPath.COMPILE); - addArtifacts(ai, cpMod, propName); - } - } - - private void addArtifacts (final AntArtifactChooser.ArtifactItem[] artifactItems, final J2SEProjectClassPathModifier cpMod, final String propName) { - assert artifactItems != null; - assert cpMod != null; - assert propName != null; - for (int i=0; i added = LibraryChooser.showDialog( - project.getReferenceHelper().getProjectLibraryManager(), - new LibraryChooser.Filter() { - public boolean accept(Library library) { - return "j2se".equals(library.getType()); //NOI18N - } - }, - project.getReferenceHelper().getLibraryChooserImportHandler()); - if (added != null) { - final String propName = cpProvider.getPropertyName(projectSourcesArtifact, ClassPath.COMPILE); - addLibraries(added.toArray(new Library[added.size()]),cpMod,propName); - } - } - - private void addLibraries (final Library[] libraries, final J2SEProjectClassPathModifier cpMod, final String propName) { - assert libraries != null; - assert cpMod != null; - assert propName != null; - for (int i=0; inull. - * - * @param opened wheter closed or opened icon should be returned. - */ - private static Image getTreeFolderIcon(boolean opened) { - final Node n = DataFolder.findFolder(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate(); - final Image base = opened ? n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16) : n.getIcon(BeanInfo.ICON_COLOR_16x16); - assert base != null; - return base; - } - - private static class AddFolderAction extends AbstractAction { - - private final J2SEProject project; - private final SourceRoots projectSourcesArtifact; - - public AddFolderAction (final J2SEProject project, final SourceRoots projectSourcesArtifact) { - super( NbBundle.getMessage( LibrariesNode.class, "LBL_AddFolder_Action" ) ); - assert project != null; - assert projectSourcesArtifact != null; - this.project = project; - this.projectSourcesArtifact = projectSourcesArtifact; - } - - public void actionPerformed(ActionEvent e) { - final ClassPathProviderImpl cpProvider = project.getClassPathProvider(); - assert cpProvider != null; - final J2SEProjectClassPathModifier cpMod = project.getProjectClassPathModifier(); - assert cpMod != null; - FileChooser chooser; - if (project.getAntProjectHelper().isSharableProject()) { - chooser = new FileChooser(project.getAntProjectHelper(), true); - } else { - chooser = new FileChooser(FileUtil.toFile(project.getProjectDirectory()), null); - } - chooser.enableVariableBasedSelection(true); - chooser.setFileHidingEnabled(false); - FileUtil.preventFileChooserSymlinkTraversal(chooser, null); - chooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES ); - chooser.setMultiSelectionEnabled( true ); - chooser.setDialogTitle( NbBundle.getMessage( LibrariesNode.class, "LBL_AddJar_DialogTitle" ) ); // NOI18N - FileFilter fileFilter = new SimpleFileFilter ( - NbBundle.getMessage( LibrariesNode.class, "LBL_ZipJarFolderFilter" ), // NOI18N - new String[] {"ZIP","JAR"} ); // NOI18N - //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order. - chooser.setAcceptAllFileFilterUsed( false ); - chooser.setFileFilter(fileFilter); - File curDir = FoldersListSettings.getDefault().getLastUsedClassPathFolder(); - chooser.setCurrentDirectory (curDir); - int option = chooser.showOpenDialog( WindowManager.getDefault().getMainWindow() ); - if ( option == JFileChooser.APPROVE_OPTION ) { - String files[]; - try { - files = chooser.getSelectedPaths(); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - return; - } - final String propName = cpProvider.getPropertyName(projectSourcesArtifact, ClassPath.COMPILE); - addJarFiles(files, chooser.getSelectedPathVariables(), fileFilter , FileUtil.toFile(project.getProjectDirectory()), - cpMod, propName); - curDir = FileUtil.normalizeFile(chooser.getCurrentDirectory()); - FoldersListSettings.getDefault().setLastUsedClassPathFolder(curDir); - } - } - - private void addJarFiles (final String[] files, final String[] pathBasedVariables, final FileFilter fileFilter, - final File base, final J2SEProjectClassPathModifier cpMod, final String propName) { - assert files != null; - assert fileFilter != null; - assert cpMod != null; - assert propName != null; - for (int i=0; i keys() { @@ -134,34 +139,40 @@ //Libraries Node return new LibrariesNode(NbBundle.getMessage(J2SELogicalViewProvider.class,"CTL_LibrariesNode"), - project, evaluator, helper, resolver, J2SEProjectProperties.RUN_CLASSPATH, - new String[] {J2SEProjectProperties.BUILD_CLASSES_DIR}, + project, evaluator, helper, resolver, ProjectProperties.RUN_CLASSPATH, + new String[] {ProjectProperties.BUILD_CLASSES_DIR}, "platform.active", // NOI18N new Action[] { - LibrariesNode.createAddProjectAction(project, true), - LibrariesNode.createAddLibraryAction(project, true), - LibrariesNode.createAddFolderAction(project, true), + LibrariesNode.createAddProjectAction(project, project.getSourceRoots()), + LibrariesNode.createAddLibraryAction(project.getReferenceHelper(), project.getSourceRoots(), null), + LibrariesNode.createAddFolderAction(project.getAntProjectHelper(), project.getSourceRoots()), null, - new SourceNodeFactory.PreselectPropertiesAction(project, "Libraries", CustomizerLibraries.COMPILE), // NOI18N - } + new JavaSourceNodeFactory.PreselectPropertiesAction(project, "Libraries", CustomizerLibraries.COMPILE), // NOI18N + }, + null, + cs, + null ); } else if (key == TEST_LIBRARIES) { return new LibrariesNode(NbBundle.getMessage(J2SELogicalViewProvider.class,"CTL_TestLibrariesNode"), - project, evaluator, helper, resolver, J2SEProjectProperties.RUN_TEST_CLASSPATH, + project, evaluator, helper, resolver, ProjectProperties.RUN_TEST_CLASSPATH, new String[] { - J2SEProjectProperties.BUILD_TEST_CLASSES_DIR, - J2SEProjectProperties.JAVAC_CLASSPATH, - J2SEProjectProperties.BUILD_CLASSES_DIR, + ProjectProperties.BUILD_TEST_CLASSES_DIR, + ProjectProperties.JAVAC_CLASSPATH, + ProjectProperties.BUILD_CLASSES_DIR, }, null, new Action[] { - LibrariesNode.createAddProjectAction(project, false), - LibrariesNode.createAddLibraryAction(project, false), - LibrariesNode.createAddFolderAction(project, false), + LibrariesNode.createAddProjectAction(project, project.getTestSourceRoots()), + LibrariesNode.createAddLibraryAction(project.getReferenceHelper(), project.getTestSourceRoots(), null), + LibrariesNode.createAddFolderAction(project.getAntProjectHelper(), project.getTestSourceRoots()), null, - new SourceNodeFactory.PreselectPropertiesAction(project, "Libraries", CustomizerLibraries.COMPILE_TESTS), // NOI18N - } + new JavaSourceNodeFactory.PreselectPropertiesAction(project, "Libraries", CustomizerLibraries.COMPILE_TESTS), // NOI18N + }, + null, + cs, + null ); } assert false: "No node for key: " + key; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesSourceGroup.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesSourceGroup.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesSourceGroup.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.ui; - -import java.beans.PropertyChangeListener; -import javax.swing.Icon; -import org.netbeans.api.project.SourceGroup; -import org.openide.ErrorManager; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileStateInvalidException; -import org.openide.filesystems.FileUtil; - -/** - * LibrariesSourceGroup - * {@link SourceGroup} implementation passed to - * {@link org.netbeans.spi.java.project.support.ui.PackageView#createPackageView(SourceGroup)} - * @author Tomas Zezula - */ -final class LibrariesSourceGroup implements SourceGroup { - - private final FileObject root; - private final String displayName; - private final Icon icon; - private final Icon openIcon; - - /** - * Creates new LibrariesSourceGroup - * @param root the classpath root - * @param displayName the display name presented to user - */ - LibrariesSourceGroup (FileObject root, String displayName ) { - this (root, displayName, null, null); - } - - /** - * Creates new LibrariesSourceGroup - * @param root the classpath root - * @param displayName the display name presented to user - * @param icon closed icon - * @param openIcon opened icon - */ - LibrariesSourceGroup (FileObject root, String displayName, Icon icon, Icon openIcon) { - assert root != null; - this.root = root; - this.displayName = displayName; - this.icon = icon; - this.openIcon = openIcon; - } - - - public FileObject getRootFolder() { - return this.root; - } - - public String getName() { - try { - return root.getURL().toExternalForm(); - } catch (FileStateInvalidException fsi) { - ErrorManager.getDefault().notify (fsi); - return root.toString(); - } - } - - public String getDisplayName() { - return this.displayName; - } - - public Icon getIcon(boolean opened) { - return opened ? openIcon : icon; - } - - public boolean contains(FileObject file) throws IllegalArgumentException { - return root.equals(file) || FileUtil.isParentOf(root,file); - } - - public boolean equals (Object other) { - if (!(other instanceof LibrariesSourceGroup)) { - return false; - } - LibrariesSourceGroup osg = (LibrariesSourceGroup) other; - return displayName == null ? osg.displayName == null : displayName.equals (osg.displayName) && - root == null ? osg.root == null : root.equals (osg.root); - } - - public int hashCode () { - return ((displayName == null ? 0 : displayName.hashCode())<<16) | ((root==null ? 0 : root.hashCode()) & 0xffff); - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - //Not needed - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - //Not needed - } -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/PlatformNode.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/PlatformNode.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/PlatformNode.java +++ /dev/null @@ -1,333 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.ui; - - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.CharConversionException; -import java.net.URL; -import java.text.MessageFormat; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.ArrayList; -import java.util.Set; -import javax.swing.Action; -import javax.swing.Icon; -import javax.swing.ImageIcon; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import org.netbeans.api.java.classpath.ClassPath; -import org.netbeans.api.java.queries.JavadocForBinaryQuery; -import org.netbeans.modules.java.j2seproject.J2SEProjectUtil; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileStateInvalidException; -import org.openide.filesystems.FileUtil; -import org.openide.nodes.Children; -import org.openide.nodes.AbstractNode; -import org.openide.nodes.Node; -import org.openide.util.ImageUtilities; -import org.openide.util.NbBundle; -import org.openide.util.Utilities; -import org.openide.util.WeakListeners; -import org.openide.ErrorManager; -import org.netbeans.api.java.platform.JavaPlatform; -import org.netbeans.api.java.platform.JavaPlatformManager; -import org.netbeans.api.project.SourceGroup; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.spi.java.project.support.ui.PackageView; -import org.openide.util.ChangeSupport; -import org.openide.util.actions.SystemAction; -import org.openide.util.lookup.Lookups; -import org.openide.xml.XMLUtil; - - - -/** - * PlatformNode represents Java platform in the logical view. - * Listens on the {@link PropertyEvaluator} for change of - * the ant property holding the platform name. - * It displays the content of boot classpath. - * @see JavaPlatform - * @author Tomas Zezula - */ -class PlatformNode extends AbstractNode implements ChangeListener { - - private static final String PLATFORM_ICON = "org/netbeans/modules/java/j2seproject/ui/resources/platform"; //NOI18N - private static final String ARCHIVE_ICON = "org/netbeans/modules/java/j2seproject/ui/resources/jar.gif"; //NOI18N - - private final PlatformProvider pp; - - private PlatformNode (PlatformProvider pp) { - super (new PlatformContentChildren (), Lookups.singleton (new JavadocProvider(pp))); - this.pp = pp; - this.pp.addChangeListener(this); - setIconBase(PLATFORM_ICON); - } - - public String getName () { - return this.getDisplayName(); - } - - public String getDisplayName () { - JavaPlatform plat = pp.getPlatform(); - String name; - if (plat != null) { - name = plat.getDisplayName(); - } - else { - String platformId = pp.getPlatformId (); - if (platformId == null) { - name = NbBundle.getMessage(PlatformNode.class,"TXT_BrokenPlatform"); - } - else { - name = MessageFormat.format(NbBundle.getMessage(PlatformNode.class,"FMT_BrokenPlatform"), new Object[] {platformId}); - } - } - return name; - } - - public String getHtmlDisplayName () { - if (pp.getPlatform() == null) { - String displayName = this.getDisplayName(); - try { - displayName = XMLUtil.toElementContent(displayName); - } catch (CharConversionException ex) { - // OK, no annotation in this case - return null; - } - return "" + displayName + ""; //NOI18N - } - else { - return null; - } - } - - public boolean canCopy() { - return false; - } - - public Action[] getActions(boolean context) { - return new Action[] { - SystemAction.get (ShowJavadocAction.class) - }; - } - - public void stateChanged(ChangeEvent e) { - this.fireNameChange(null,null); - this.fireDisplayNameChange(null,null); - //The caller holds ProjectManager.mutex() read lock - LibrariesNode.rp.post (new Runnable () { - public void run () { - ((PlatformContentChildren)getChildren()).addNotify (); - } - }); - } - - /** - * Creates new PlatformNode - * @param eval the PropertyEvaluator used for obtaining the active platform name - * and listening on the active platform change - * @param platformPropName the name of ant property holding the platform name - * - */ - static PlatformNode create (PropertyEvaluator eval, String platformPropName) { - PlatformProvider pp = new PlatformProvider (eval, platformPropName); - return new PlatformNode (pp); - } - - private static class PlatformContentChildren extends Children.Keys { - - PlatformContentChildren () { - } - - protected void addNotify() { - this.setKeys (this.getKeys()); - } - - protected void removeNotify() { - this.setKeys(Collections.EMPTY_SET); - } - - protected Node[] createNodes(Object key) { - SourceGroup sg = (SourceGroup) key; - return new Node[] {ActionFilterNode.create(PackageView.createPackageView(sg), null, null, null, null)}; - } - - private List getKeys () { - JavaPlatform platform = ((PlatformNode)this.getNode()).pp.getPlatform(); - if (platform == null) { - return Collections.EMPTY_LIST; - } - //Todo: Should listen on returned classpath, but now the bootstrap libraries are read only - FileObject[] roots = platform.getBootstrapLibraries().getRoots(); - List result = new ArrayList (roots.length); - for (int i=0; i 0; - } - - public void showJavadoc() { - JavaPlatform platform = platformProvider.getPlatform(); - if (platform != null) { - URL[] javadocRoots = getJavadocRoots(platform); - URL pageURL = ShowJavadocAction.findJavadoc("overview-summary.html",javadocRoots); - if (pageURL == null) { - pageURL = ShowJavadocAction.findJavadoc("index.html",javadocRoots); - } - ShowJavadocAction.showJavaDoc(pageURL, platform.getDisplayName()); - } - } - - - private static URL[] getJavadocRoots (JavaPlatform platform) { - Set result = new HashSet (); - List/**/ l = platform.getBootstrapLibraries().entries(); - for (Iterator it = l.iterator(); it.hasNext();) { - ClassPath.Entry e = (ClassPath.Entry) it.next (); - result.addAll(Arrays.asList(JavadocForBinaryQuery.findJavadoc (e.getURL()).getRoots())); - } - return (URL[]) result.toArray (new URL[result.size()]); - } - - - } - -} - - diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ProjectNode.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ProjectNode.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ProjectNode.java +++ /dev/null @@ -1,343 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.ui; - -import java.awt.Image; -import java.io.IOException; -import java.net.URI; -import java.net.URL; -import java.net.MalformedURLException; -import java.io.File; -import java.text.MessageFormat; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import java.util.ArrayList; -import java.util.List; -import javax.swing.Action; -import javax.swing.Icon; -import org.netbeans.api.project.FileOwnerQuery; -import org.netbeans.api.project.ProjectUtils; -import org.netbeans.modules.java.j2seproject.classpath.ClassPathSupport; -import org.openide.ErrorManager; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.nodes.AbstractNode; -import org.openide.nodes.Children; -import org.openide.nodes.Node; -import org.openide.util.ImageUtilities; -import org.openide.util.Lookup; -import org.openide.util.NbBundle; -import org.openide.util.Utilities; -import org.openide.util.HelpCtx; -import org.openide.util.lookup.Lookups; -import org.openide.util.actions.SystemAction; -import org.openide.util.actions.NodeAction; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectInformation; -import org.netbeans.api.project.ProjectManager; -import org.netbeans.api.project.ant.AntArtifact; -import org.netbeans.api.project.ui.OpenProjects; -import org.netbeans.api.java.queries.JavadocForBinaryQuery; -import org.netbeans.modules.java.api.common.ant.UpdateHelper; -import org.netbeans.spi.project.support.ant.EditableProperties; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyUtils; -import org.netbeans.spi.project.support.ant.ReferenceHelper; - - - -/** - * ProjectNode represents a dependent project under the Libraries Node. - * It is a leaf node with the following actions: {@link OpenProjectAction}, - * {@link ShowJavadocAction} and {@link RemoveClassPathRootAction} - * @author Tomas Zezula - */ -class ProjectNode extends AbstractNode { - - private static final String PROJECT_ICON = "org/netbeans/modules/java/j2seproject/ui/resources/projectDependencies.gif"; //NOI18N - - private final AntArtifact antArtifact; - private final URI artifactLocation; - private Image cachedIcon; - - ProjectNode (AntArtifact antArtifact, URI artifactLocation, UpdateHelper helper,ReferenceHelper refHelper, String classPathId, String entryId) { - super (Children.LEAF, createLookup (antArtifact, artifactLocation, helper, refHelper, classPathId, entryId)); - this.antArtifact = antArtifact; - this.artifactLocation = artifactLocation; - } - - public String getDisplayName () { - ProjectInformation info = getProjectInformation(); - if (info != null) { - return MessageFormat.format(NbBundle.getMessage(ProjectNode.class,"TXT_ProjectArtifactFormat"), - new Object[] {info.getDisplayName(), artifactLocation.toString()}); - } - else { - return NbBundle.getMessage (ProjectNode.class,"TXT_UnknownProjectName"); - } - } - - public String getName () { - return this.getDisplayName(); - } - - public Image getIcon(int type) { - if (cachedIcon == null) { - ProjectInformation info = getProjectInformation(); - if (info != null) { - Icon icon = info.getIcon(); - cachedIcon = ImageUtilities.icon2Image(icon); - } - else { - cachedIcon = ImageUtilities.loadImage(PROJECT_ICON); - } - } - return cachedIcon; - } - - public Image getOpenedIcon(int type) { - return this.getIcon(type); - } - - public boolean canCopy() { - return false; - } - - public Action[] getActions(boolean context) { - return new Action[] { - SystemAction.get (OpenProjectAction.class), - SystemAction.get (ShowJavadocAction.class), - SystemAction.get (RemoveClassPathRootAction.class), - }; - } - - public Action getPreferredAction () { - return getActions(false)[0]; - } - - private ProjectInformation getProjectInformation () { - Project p = this.antArtifact.getProject(); - if (p != null) { - return ProjectUtils.getInformation(p); - } - return null; - } - - private static Lookup createLookup (AntArtifact antArtifact, URI artifactLocation, - UpdateHelper helper, ReferenceHelper refHelper, String classPathId, String entryId) { - Project p = antArtifact.getProject(); - Object[] content; - if (p == null) { - content = new Object[1]; - } - else { - content = new Object[3]; - content[1] = new JavadocProvider(antArtifact, artifactLocation); - content[2] = p; - } - content[0] = new Removable(helper,refHelper, classPathId, entryId); - Lookup lkp = Lookups.fixed(content); - return lkp; - } - - private static class JavadocProvider implements ShowJavadocAction.JavadocProvider { - - private final AntArtifact antArtifact; - private final URI artifactLocation; - - JavadocProvider (AntArtifact antArtifact, URI artifactLocation) { - this.antArtifact = antArtifact; - this.artifactLocation = artifactLocation; - } - - - public boolean hasJavadoc() { - return findJavadoc().size() > 0; - } - - public void showJavadoc() { - Set us = findJavadoc(); - URL[] urls = (URL[])us.toArray(new URL[us.size()]); - URL pageURL = ShowJavadocAction.findJavadoc("overview-summary.html",urls); - if (pageURL == null) { - pageURL = ShowJavadocAction.findJavadoc("index.html",urls); - } - ProjectInformation info = null; - Project p = this.antArtifact.getProject (); - if (p != null) { - info = ProjectUtils.getInformation(p); - } - ShowJavadocAction.showJavaDoc (pageURL, info == null ? - NbBundle.getMessage (ProjectNode.class,"TXT_UnknownProjectName") : info.getDisplayName()); - } - - private Set findJavadoc() { - File scriptLocation = this.antArtifact.getScriptLocation(); - Set urls = new HashSet(); - try { - URL artifactURL = scriptLocation.toURI().resolve(this.artifactLocation).normalize().toURL(); - if (FileUtil.isArchiveFile(artifactURL)) { - artifactURL = FileUtil.getArchiveRoot(artifactURL); - } - urls.addAll(Arrays.asList(JavadocForBinaryQuery.findJavadoc(artifactURL).getRoots())); - } catch (MalformedURLException mue) { - ErrorManager.getDefault().notify (mue); - } - return urls; - } - - } - - private static class OpenProjectAction extends NodeAction { - - protected void performAction(Node[] activatedNodes) { - Project[] projects = new Project[activatedNodes.length]; - for (int i=0; i openedProjects =Arrays.asList(OpenProjects.getDefault().getOpenProjects()); - for (int i=0; i*/ result = new ArrayList (); - for (int i=0; i0) { - result.set (size-1,(String)result.get(size-1) + ':'); //NOI18N - } - result.add (entries[i]); - } - } - props.setProperty (classPathId, (String[])result.toArray(new String[result.size()])); - helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,props); - String ref = "${"+entryId+"}"; //NOI18N - if (!RemoveClassPathRootAction.isReferenced (new EditableProperties[] { - props, - helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH)}, ref)) { - refHelper.destroyReference(ref); - } - Project project = FileOwnerQuery.getOwner(helper.getAntProjectHelper().getProjectDirectory()); - assert project != null; - try { - ProjectManager.getDefault().saveProject(project); - } catch (IOException ioe) { - ErrorManager.getDefault().notify(ioe); - } - } - } - }); - } - } -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/RemoveClassPathRootAction.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/RemoveClassPathRootAction.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/RemoveClassPathRootAction.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.ui; - - -import org.openide.nodes.Node; -import org.openide.util.NbBundle; -import org.openide.util.HelpCtx; -import org.openide.util.actions.NodeAction; -import org.netbeans.spi.project.support.ant.EditableProperties; - -import java.util.Iterator; - -/** - * Action for removing an ClassPathRoot. The action looks up - * the {@link RemoveClassPathRootAction.Removable} in the - * activated node's Lookups and delegates to it. - * @author Tomas Zezula - */ -final class RemoveClassPathRootAction extends NodeAction { - - /** - * Implementation of this interfaces has to be placed - * into the node's Lookup to allow {@link RemoveClassPathRootAction} - * on the node. - */ - static interface Removable { - /** - * Checks if the classpath root can be removed - * @return returns true if the action should be enabled - */ - public boolean canRemove (); - - /** - * Removes the classpath root - */ - public abstract void remove (); - } - - protected void performAction(Node[] activatedNodes) { - for (int i=0; i=0) { - return true; - } - } - } - return false; - } -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ShowJavadocAction.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ShowJavadocAction.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ShowJavadocAction.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.ui; - -import java.net.URL; -import java.net.MalformedURLException; -import java.text.MessageFormat; -import org.openide.ErrorManager; -import org.openide.awt.HtmlBrowser; -import org.openide.awt.StatusDisplayer; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.URLMapper; -import org.openide.nodes.Node; -import org.openide.util.NbBundle; -import org.openide.util.HelpCtx; -import org.openide.util.actions.NodeAction; - - -/** - * Action for showing Javadoc. The action looks up - * the {@link ShowJavadocAction.JavadocProvider} in the - * activated node's Lookup and delegates to it. - * @author Tomas Zezula - */ -final class ShowJavadocAction extends NodeAction { - - /** - * Implementation of this interfaces has to be placed - * into the node's Lookup to allow {@link ShowJavadocAction} - * on the node. - */ - public static interface JavadocProvider { - - /** - * Checks if the node can provide Javaodc - * @return true if the action should be enabled - */ - public abstract boolean hasJavadoc (); - - /** - * Opens javadoc page in the browser - */ - public abstract void showJavadoc (); - } - - protected void performAction(Node[] activatedNodes) { - if (activatedNodes.length!=1) { - return; - } - JavadocProvider jd = (JavadocProvider) activatedNodes[0].getLookup().lookup(JavadocProvider.class); - if (jd == null) { - return; - } - jd.showJavadoc(); - } - - protected boolean enable(Node[] activatedNodes) { - if (activatedNodes.length!=1) { - return false; - } - JavadocProvider jd = (JavadocProvider) activatedNodes[0].getLookup().lookup(JavadocProvider.class); - if (jd == null) { - return false; - } - return jd.hasJavadoc(); - } - - public final String getName() { - return NbBundle.getMessage(ShowJavadocAction.class,"CTL_ShowJavadoc"); - } - - public final HelpCtx getHelpCtx() { - return new HelpCtx (ShowJavadocAction.class); - } - - public final boolean asynchronous () { - return false; - } - - /** - * Opens the IDE default browser with given URL - * @param javadoc URL of the javadoc page - * @param displayName the name of file to be displayed, typically the package name for class - * or project name for project. - */ - static void showJavaDoc (URL javadoc, String displayName) { - if (javadoc!=null) { - HtmlBrowser.URLDisplayer.getDefault().showURL(javadoc); - } - else { - StatusDisplayer.getDefault().setStatusText(MessageFormat.format(NbBundle.getMessage(ShowJavadocAction.class, - "TXT_NoJavadoc"), new Object[] {displayName})); //NOI18N - } - } - - /** - * Locates a javadoc page by a relative name and an array of javadoc roots - * @param resource the relative name of javadoc page - * @param urls the array of javadoc roots - * @return the URL of found javadoc page or null if there is no such a page. - */ - static URL findJavadoc (String resource, URL urls[]) { - for (int i=0; i, ChangeListener { - - private J2SEProject project; - - private final ChangeSupport changeSupport = new ChangeSupport(this); - - public SourcesNodeList(J2SEProject proj) { - project = proj; - } - - public List keys() { - if (this.project.getProjectDirectory() == null || !this.project.getProjectDirectory().isValid()) { - return Collections.EMPTY_LIST; - } - Sources sources = getSources(); - SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); - - List result = new ArrayList(groups.length); - for( int i = 0; i < groups.length; i++ ) { - result.add(new SourceGroupKey(groups[i])); - } - return result; - } - - public void addChangeListener(ChangeListener l) { - changeSupport.addChangeListener(l); - } - - public void removeChangeListener(ChangeListener l) { - changeSupport.removeChangeListener(l); - } - - public Node node(SourceGroupKey key) { - return new PackageViewFilterNode(key.group, project); - } - - public void addNotify() { - getSources().addChangeListener(this); - } - - public void removeNotify() { - getSources().removeChangeListener(this); - } - - public void stateChanged(ChangeEvent e) { - // setKeys(getKeys()); - // The caller holds ProjectManager.mutex() read lock - SwingUtilities.invokeLater(new Runnable() { - public void run() { - changeSupport.fireChange(); - } - }); - } - - private Sources getSources() { - return ProjectUtils.getSources(project); - } - - } - - private static class SourceGroupKey { - - public final SourceGroup group; - public final FileObject fileObject; - - SourceGroupKey(SourceGroup group) { - this.group = group; - this.fileObject = group.getRootFolder(); - } - - @Override - public int hashCode() { - int hash = 5; - String disp = this.group.getDisplayName(); - hash = 79 * hash + (fileObject != null ? fileObject.hashCode() : 0); - hash = 79 * hash + (disp != null ? disp.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof SourceGroupKey)) { - return false; - } else { - SourceGroupKey otherKey = (SourceGroupKey) obj; - - if (fileObject != otherKey.fileObject && (fileObject == null || !fileObject.equals(otherKey.fileObject))) { - return false; - } - String thisDisplayName = this.group.getDisplayName(); - String otherDisplayName = otherKey.group.getDisplayName(); - boolean oneNull = thisDisplayName == null; - boolean twoNull = otherDisplayName == null; - if (oneNull != twoNull || !thisDisplayName.equals(otherDisplayName)) { - return false; - } - return true; - } - } - - - } - - /** Yet another cool filter node just to add properties action - */ - private static class PackageViewFilterNode extends FilterNode { - - private String nodeName; - private Project project; - - Action[] actions; - - public PackageViewFilterNode(SourceGroup sourceGroup, Project project) { - super(PackageView.createPackageView(sourceGroup)); - this.project = project; - this.nodeName = "Sources"; - } - - - public Action[] getActions(boolean context) { - if (!context) { - if (actions == null) { - Action superActions[] = super.getActions(context); - actions = new Action[superActions.length + 2]; - System.arraycopy(superActions, 0, actions, 0, superActions.length); - actions[superActions.length] = null; - actions[superActions.length + 1] = new PreselectPropertiesAction(project, nodeName); - } - return actions; - } else { - return super.getActions(context); - } - } - - } - - - /** The special properties action - */ - static class PreselectPropertiesAction extends AbstractAction { - - private final Project project; - private final String nodeName; - private final String panelName; - - public PreselectPropertiesAction(Project project, String nodeName) { - this(project, nodeName, null); - } - - public PreselectPropertiesAction(Project project, String nodeName, String panelName) { - super(NbBundle.getMessage(J2SELogicalViewProvider.class, "LBL_Properties_Action")); - this.project = project; - this.nodeName = nodeName; - this.panelName = panelName; - } - - public void actionPerformed(ActionEvent e) { - // J2SECustomizerProvider cp = (J2SECustomizerProvider) project.getLookup().lookup(J2SECustomizerProvider.class); - CustomizerProviderImpl cp = (CustomizerProviderImpl) project.getLookup().lookup(CustomizerProviderImpl.class); - if (cp != null) { - cp.showCustomizer(nodeName, panelName); - } - - } - } - -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/AntArtifactChooser.form b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/AntArtifactChooser.form deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/AntArtifactChooser.form +++ /dev/null @@ -1,80 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/AntArtifactChooser.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/AntArtifactChooser.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/AntArtifactChooser.java +++ /dev/null @@ -1,309 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.ui.customizer; - -import java.awt.Component; -import java.awt.Dimension; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import javax.swing.DefaultListModel; -import javax.swing.JFileChooser; -import javax.swing.JPanel; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectManager; -import org.netbeans.api.project.ProjectUtils; -import org.netbeans.api.project.ant.AntArtifact; -import org.netbeans.api.project.ant.AntArtifactQuery; -import org.netbeans.spi.project.ui.support.ProjectChooser; -import org.netbeans.modules.java.j2seproject.ui.FoldersListSettings; -import org.openide.DialogDisplayer; -import org.openide.ErrorManager; -import org.openide.NotifyDescriptor; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.util.NbBundle; - -/** - * Accessory component used in the ProjectChooser for choosing project - * artifacts. - * @author Petr Hrebejk - */ -public class AntArtifactChooser extends JPanel implements PropertyChangeListener { - - - private String[] artifactTypes; - - /** Creates new form JarArtifactChooser */ - public AntArtifactChooser( String[] artifactTypes, JFileChooser chooser ) { - this.artifactTypes = artifactTypes; - - initComponents(); - jListArtifacts.setModel( new DefaultListModel() ); - chooser.addPropertyChangeListener( this ); - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - private void initComponents() {//GEN-BEGIN:initComponents - java.awt.GridBagConstraints gridBagConstraints; - - jLabelName = new javax.swing.JLabel(); - jTextFieldName = new javax.swing.JTextField(); - jLabelJarFiles = new javax.swing.JLabel(); - jScrollPane1 = new javax.swing.JScrollPane(); - jListArtifacts = new javax.swing.JList(); - - setLayout(new java.awt.GridBagLayout()); - - jLabelName.setLabelFor(jTextFieldName); - org.openide.awt.Mnemonics.setLocalizedText(jLabelName, org.openide.util.NbBundle.getMessage(AntArtifactChooser.class, "LBL_AACH_ProjectName_JLabel")); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 12, 2, 0); - add(jLabelName, gridBagConstraints); - - jTextFieldName.setEditable(false); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 12, 6, 0); - add(jTextFieldName, gridBagConstraints); - jTextFieldName.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AD_AACH_ProjectName_JLabel")); - - jLabelJarFiles.setLabelFor(jListArtifacts); - org.openide.awt.Mnemonics.setLocalizedText(jLabelJarFiles, org.openide.util.NbBundle.getMessage(AntArtifactChooser.class, "LBL_AACH_ProjectJarFiles_JLabel")); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 12, 2, 0); - add(jLabelJarFiles, gridBagConstraints); - - jScrollPane1.setViewportView(jListArtifacts); - jListArtifacts.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AD_AACH_ProjectJarFiles_JLabel")); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.weighty = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0); - add(jScrollPane1, gridBagConstraints); - - }//GEN-END:initComponents - - - public void propertyChange(PropertyChangeEvent e) { - if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(e.getPropertyName())) { - // We have to update the Accessory - JFileChooser chooser = (JFileChooser) e.getSource(); - File dir = chooser.getSelectedFile(); // may be null (#46744) - Project project = getProject(dir); // may be null - populateAccessory(project); - } - } - - private Project getProject( File projectDir ) { - - if (projectDir == null) { // #46744 - return null; - } - - try { - File normProjectDir = FileUtil.normalizeFile(projectDir); - FileObject fo = FileUtil.toFileObject(normProjectDir); - if (fo != null) { - return ProjectManager.getDefault().findProject(fo); - } - } catch (IOException e) { - ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); - // Return null - } - - return null; - } - - /** - * Set up GUI fields according to the requested project. - * @param project a subproject, or null - */ - private void populateAccessory( Project project ) { - - DefaultListModel model = (DefaultListModel)jListArtifacts.getModel(); - model.clear(); - jTextFieldName.setText(project == null ? "" : ProjectUtils.getInformation(project).getDisplayName()); //NOI18N - - if ( project != null ) { - - List artifacts = new ArrayList(); - for (int i=0; i getIterator( DefaultListModel model ) { - // XXX Better performing impl. would be nice - return getList( model ).iterator(); - } - - public static List getList( DefaultListModel model ) { - return Collections.list(NbCollections.checkedEnumerationByFilter(model.elements(), ClassPathSupport.Item.class, true)); - } - - - /** Moves items up in the list. The indices array will contain - * indices to be selected after the change was done. - */ - public static int[] moveUp( DefaultListModel listModel, int indices[]) { - - if( indices == null || indices.length == 0 ) { - assert false : "MoveUp button should be disabled"; // NOI18N - } - - // Move the items up - for( int i = 0; i < indices.length; i++ ) { - Object item = listModel.get( indices[i] ); - listModel.remove( indices[i] ); - listModel.add( indices[i] - 1, item ); - } - - // Keep the selection a before - for( int i = 0; i < indices.length; i++ ) { - indices[i] -= 1; - } - - return indices; - - } - - public static boolean canEdit( ListSelectionModel selectionModel, DefaultListModel listModel ) { - boolean can = selectionModel.getMinSelectionIndex() == selectionModel.getMaxSelectionIndex() - && selectionModel.getMinSelectionIndex() != -1; - if (can) { - ClassPathSupport.Item item = (ClassPathSupport.Item) listModel.get(selectionModel.getMinSelectionIndex()); - can = item.canEdit(); - } - return can; - } - - static void edit(DefaultListModel listModel, int[] selectedIndices, AntProjectHelper helper) { - ClassPathSupport.Item item = (ClassPathSupport.Item) listModel.getElementAt(selectedIndices[0]); - if (item.getType() == ClassPathSupport.Item.TYPE_JAR) { - EditJarSupport.Item eji = new EditJarSupport.Item(); - eji.setJarFile(item.getVariableBasedProperty() != null ? item.getVariableBasedProperty() : item.getFilePath()); - eji.setSourceFile(item.getSourceFilePath()); - eji.setJavadocFile(item.getJavadocFilePath()); - eji = EditJarSupport.showEditDialog(helper, eji); - if (eji != null) { - item.setJavadocFilePath(eji.getJavadocFile()); - item.setSourceFilePath(eji.getSourceFile()); - } - } - if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) { - if (item.getLibrary() != null) { - LibrariesCustomizer.showSingleLibraryCustomizer(item.getLibrary()); - } - } - } - - public static boolean canMoveUp( ListSelectionModel selectionModel ) { - return selectionModel.getMinSelectionIndex() > 0; - } - - /** Moves items down in the list. The indices array will contain - * indices to be selected after the change was done. - */ - public static int[] moveDown( DefaultListModel listModel, int indices[]) { - - if( indices == null || indices.length == 0 ) { - assert false : "MoveDown button should be disabled"; // NOI18N - } - - // Move the items up - for( int i = indices.length -1 ; i >= 0 ; i-- ) { - Object item = listModel.get( indices[i] ); - listModel.remove( indices[i] ); - listModel.add( indices[i] + 1, item ); - } - - // Keep the selection a before - for( int i = 0; i < indices.length; i++ ) { - indices[i] += 1; - } - - return indices; - - } - - public static boolean canMoveDown( ListSelectionModel selectionModel, int modelSize ) { - int iMax = selectionModel.getMaxSelectionIndex(); - return iMax != -1 && iMax < modelSize - 1; - } - - /** Removes selected indices from the model. Returns the index to be selected - */ - public static int[] remove( DefaultListModel listModel, int[] indices ) { - - if( indices == null || indices.length == 0 ) { - assert false : "Remove button should be disabled"; // NOI18N - } - - // Remove the items - for( int i = indices.length - 1 ; i >= 0 ; i-- ) { - listModel.remove( indices[i] ); - } - - if ( !listModel.isEmpty() ) { - // Select reasonable item - int selectedIndex = indices[indices.length - 1] - indices.length + 1; - if ( selectedIndex > listModel.size() - 1) { - selectedIndex = listModel.size() - 1; - } - return new int[] { selectedIndex }; - } - else { - return new int[] {}; - } - - } - - public static int[] addLibraries( DefaultListModel listModel, int[] indices, Library[] libraries, Set/**/ alreadyIncludedLibs ) { - - int lastIndex = indices == null || indices.length == 0 ? listModel.getSize() - 1 : indices[indices.length - 1]; - for (int i = 0, j=1; i < libraries.length; i++) { - if (!alreadyIncludedLibs.contains(libraries[i])) { - listModel.add( lastIndex + j++, ClassPathSupport.Item.create( libraries[i], null ) ); - } - } - Set addedLibs = new HashSet(Arrays.asList(libraries)); - int[] indexes = new int[libraries.length]; - for (int i=0, j=0; i 0) { - File fil = PropertyUtils.resolveFile(FileUtil.toFile(project.getProjectDirectory()), path); - URL url = FileUtil.normalizeFile(fil).toURI().toURL(); - manager = LibraryManager.forLocation(url); - } else { - empty = true; - } - } catch (BadLocationException ex) { - empty = true; - Exceptions.printStackTrace(ex); - } catch (MalformedURLException ex2) { - Exceptions.printStackTrace(ex2); - } - if (manager == null && empty) { - manager = LibraryManager.getDefault(); - } - if (manager == null) { - //TODO some error message - return; - } - - Set added = LibraryChooser.showDialog(manager, - new LibraryChooser.Filter() { - public boolean accept(Library library) { - return "j2se".equals(library.getType()); //NOI18N - } - }, - project.getReferenceHelper().getLibraryChooserImportHandler()); - if (added != null) { - Set includedLibraries = new HashSet(); - for (int i=0; i< listModel.getSize(); i++) { - ClassPathSupport.Item item = (ClassPathSupport.Item) listModel.get(i); - if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) { - if (item.isBroken()) { - //Try to refresh the broken item, it may be already valid or invalid - final String reference = item.getReference(); - final String libraryName = ClassPathSupport.getLibraryNameFromReference(reference); - assert libraryName != null : "Not a library reference: "+reference; - final Library library = manager.getLibrary( libraryName ); - if ( library != null ) { - listModel.remove(i); - item = ClassPathSupport.Item.create( library, reference ); - listModel.add(i, item); - } - } - else { - final Library origLibrary = item.getLibrary(); - final Library newLibrary = manager.getLibrary(origLibrary.getName()); - if (newLibrary == null) { - listModel.remove(i); - item = ClassPathSupport.Item.createBroken(ClassPathSupport.Item.TYPE_LIBRARY, item.getReference()); - listModel.add(i, item); - } - } - if (!item.isBroken()) { - includedLibraries.add( item.getLibrary() ); - } - } - } - int[] newSelection = ClassPathUiSupport.addLibraries(listModel, list.getSelectedIndices(), added.toArray(new Library[added.size()]), includedLibraries); - list.setSelectedIndices( newSelection ); - } - } - else if ( source == addAntArtifact ) { - AntArtifactChooser.ArtifactItem artifactItems[] = AntArtifactChooser.showDialog( - new String[] { JavaProjectConstants.ARTIFACT_TYPE_JAR, JavaProjectConstants.ARTIFACT_TYPE_FOLDER}, - project, list.getParent() ); - if (artifactItems != null) { - int[] newSelection = ClassPathUiSupport.addArtifacts( listModel, list.getSelectedIndices(), artifactItems); - list.setSelectedIndices( newSelection ); - } - } - else if ( source == remove ) { - int[] newSelection = ClassPathUiSupport.remove( listModel, list.getSelectedIndices() ); - list.setSelectedIndices( newSelection ); - } - else if ( source == edit ) { - ClassPathSupport.Item item = (Item) listModel.get(list.getSelectedIndices()[0]); - ClassPathUiSupport.edit( listModel, list.getSelectedIndices(), project.getAntProjectHelper()); - list.repaint(); //need to repaint to get the icon badges right.. - } - else if ( source == moveUp ) { - int[] newSelection = ClassPathUiSupport.moveUp( listModel, list.getSelectedIndices() ); - list.setSelectedIndices( newSelection ); - } - else if ( source == moveDown ) { - int[] newSelection = ClassPathUiSupport.moveDown( listModel, list.getSelectedIndices() ); - list.setSelectedIndices( newSelection ); - } - } - - - /** Handles changes in the selection - */ - public void valueChanged( ListSelectionEvent e ) { - - // remove enabled only if selection is not empty - boolean canRemove = false; - // and when the selection does not contain unremovable item - if ( selectionModel.getMinSelectionIndex() != -1 ) { - canRemove = true; - int iMin = selectionModel.getMinSelectionIndex(); - int iMax = selectionModel.getMinSelectionIndex(); - for ( int i = iMin; i <= iMax; i++ ) { - - if ( selectionModel.isSelectedIndex( i ) ) { - ClassPathSupport.Item item = (ClassPathSupport.Item)listModel.get( i ); - if ( item.getType() == ClassPathSupport.Item.TYPE_CLASSPATH ) { - canRemove = false; - break; - } - } - } - } - - // addJar allways enabled - // addLibrary allways enabled - // addArtifact allways enabled - edit.setEnabled( ClassPathUiSupport.canEdit (selectionModel, listModel )); - remove.setEnabled( canRemove ); - moveUp.setEnabled( ClassPathUiSupport.canMoveUp( selectionModel ) ); - moveDown.setEnabled( ClassPathUiSupport.canMoveDown( selectionModel, listModel.getSize() ) ); - - } - } - - private static class SimpleFileFilter extends FileFilter { - - private String description; - private Collection extensions; - - - public SimpleFileFilter (String description, String[] extensions) { - this.description = description; - this.extensions = Arrays.asList(extensions); - } - - public boolean accept(File f) { - if (f.isDirectory()) - return true; - String name = f.getName(); - int index = name.lastIndexOf('.'); //NOI18N - if (index <= 0 || index==name.length()-1) - return false; - String extension = name.substring (index+1).toUpperCase(); - return this.extensions.contains(extension); - } - - public String getDescription() { - return this.description; - } - } - -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java @@ -69,11 +69,16 @@ import org.netbeans.api.project.ProjectUtils; import org.netbeans.modules.java.api.common.SourceRoots; import org.netbeans.modules.java.api.common.ant.UpdateHelper; +import org.netbeans.modules.java.api.common.classpath.ClassPathSupport; +import org.netbeans.modules.java.api.common.project.ProjectProperties; +import org.netbeans.modules.java.api.common.project.ui.ClassPathUiSupport; +import org.netbeans.modules.java.api.common.project.ui.customizer.ClassPathListCellRenderer; +import org.netbeans.modules.java.api.common.project.ui.customizer.SourceRootsUi; import org.netbeans.modules.java.api.common.ui.PlatformUiSupport; +import org.netbeans.modules.java.api.common.util.CommonProjectUtils; import org.netbeans.modules.java.j2seproject.J2SEProject; import org.netbeans.modules.java.j2seproject.J2SEProjectType; import org.netbeans.modules.java.j2seproject.J2SEProjectUtil; -import org.netbeans.modules.java.j2seproject.classpath.ClassPathSupport; import org.netbeans.spi.java.project.support.ui.IncludeExcludeVisualizer; import org.netbeans.spi.project.ActionProvider; import org.netbeans.spi.project.support.ant.AntProjectHelper; @@ -112,12 +117,22 @@ // Special properties of the project public static final String J2SE_PROJECT_NAME = "j2se.project.name"; // NOI18N public static final String JAVA_PLATFORM = "platform.active"; // NOI18N + + // folowing properties have moved to ProjectProperties in java.api.common module: + //public static final String JAVAC_CLASSPATH = "javac.classpath"; // NOI18N + //public static final String RUN_CLASSPATH = "run.classpath"; // NOI18N + //public static final String JAVAC_TEST_CLASSPATH = "javac.test.classpath"; // NOI18N + //public static final String RUN_TEST_CLASSPATH = "run.test.classpath"; // NOI18N + //public static final String BUILD_CLASSES_DIR = "build.classes.dir"; // NOI18N + //public static final String BUILD_TEST_CLASSES_DIR = "build.test.classes.dir"; // NOI18N + //public static final String INCLUDES = "includes"; // NOI18N + //public static final String EXCLUDES = "excludes"; // NOI18N + //public static final String[] WELL_KNOWN_PATHS = new String[] { + //public static final String ANT_ARTIFACT_PREFIX = "${reference."; // NOI18N // Properties stored in the PROJECT.PROPERTIES public static final String DIST_DIR = "dist.dir"; // NOI18N public static final String DIST_JAR = "dist.jar"; // NOI18N - public static final String JAVAC_CLASSPATH = "javac.classpath"; // NOI18N - public static final String RUN_CLASSPATH = "run.classpath"; // NOI18N public static final String RUN_JVM_ARGS = "run.jvmargs"; // NOI18N public static final String RUN_WORK_DIR = "work.dir"; // NOI18N public static final String DEBUG_CLASSPATH = "debug.classpath"; // NOI18N @@ -125,24 +140,16 @@ public static final String MAIN_CLASS = "main.class"; // NOI18N public static final String JAVAC_SOURCE = "javac.source"; // NOI18N public static final String JAVAC_TARGET = "javac.target"; // NOI18N - public static final String JAVAC_TEST_CLASSPATH = "javac.test.classpath"; // NOI18N public static final String JAVAC_DEBUG = "javac.debug"; // NOI18N public static final String JAVAC_DEPRECATION = "javac.deprecation"; // NOI18N public static final String JAVAC_COMPILER_ARG = "javac.compilerargs"; //NOI18N - public static final String RUN_TEST_CLASSPATH = "run.test.classpath"; // NOI18N public static final String BUILD_DIR = "build.dir"; // NOI18N - public static final String BUILD_CLASSES_DIR = "build.classes.dir"; // NOI18N - public static final String BUILD_TEST_CLASSES_DIR = "build.test.classes.dir"; // NOI18N public static final String BUILD_TEST_RESULTS_DIR = "build.test.results.dir"; // NOI18N public static final String BUILD_CLASSES_EXCLUDES = "build.classes.excludes"; // NOI18N public static final String DIST_JAVADOC_DIR = "dist.javadoc.dir"; // NOI18N public static final String NO_DEPENDENCIES="no.dependencies"; // NOI18N public static final String DEBUG_TEST_CLASSPATH = "debug.test.classpath"; // NOI18N public static final String SOURCE_ENCODING="source.encoding"; // NOI18N - /** @since org.netbeans.modules.java.j2seproject/1 1.11 */ - public static final String INCLUDES = "includes"; // NOI18N - /** @since org.netbeans.modules.java.j2seproject/1 1.11 */ - public static final String EXCLUDES = "excludes"; // NOI18N /** @since org.netbeans.modules.java.j2seproject/1 1.12 */ public static final String DO_DEPEND = "do.depend"; // NOI18N /** @since org.netbeans.modules.java.j2seproject/1 1.12 */ @@ -181,20 +188,6 @@ //NB 6.1 tracking of files modifications public static final String TRACK_FILE_CHANGES="track.file.changes"; //NOI18N - - - // Well known paths - public static final String[] WELL_KNOWN_PATHS = new String[] { - "${" + JAVAC_CLASSPATH + "}", - "${" + JAVAC_TEST_CLASSPATH + "}", - "${" + RUN_CLASSPATH + "}", - "${" + RUN_TEST_CLASSPATH + "}", - "${" + BUILD_CLASSES_DIR + "}", - "${" + BUILD_TEST_CLASSES_DIR + "}", - }; - - // XXX looks like there is some kind of API missing in ReferenceHelper? - public static final String ANT_ARTIFACT_PREFIX = "${reference."; // NOI18N ClassPathSupport cs; @@ -288,7 +281,7 @@ this.evaluator = evaluator; this.refHelper = refHelper; this.genFileHelper = genFileHelper; - this.cs = new ClassPathSupport( evaluator, refHelper, updateHelper.getAntProjectHelper(), updateHelper, WELL_KNOWN_PATHS, ANT_ARTIFACT_PREFIX ); + this.cs = new ClassPathSupport(evaluator, refHelper, updateHelper.getAntProjectHelper(), updateHelper, null); privateGroup = new StoreGroup(); projectGroup = new StoreGroup(); @@ -302,16 +295,16 @@ */ private void init() { - CLASS_PATH_LIST_RENDERER = new J2SEClassPathUi.ClassPathListCellRenderer(evaluator, project.getProjectDirectory()); + CLASS_PATH_LIST_RENDERER = ClassPathListCellRenderer.createClassPathListRenderer(evaluator, project.getProjectDirectory()); // CustomizerSources - SOURCE_ROOTS_MODEL = J2SESourceRootsUi.createModel( project.getSourceRoots() ); - TEST_ROOTS_MODEL = J2SESourceRootsUi.createModel( project.getTestSourceRoots() ); - includes = evaluator.getProperty(INCLUDES); + SOURCE_ROOTS_MODEL = SourceRootsUi.createModel( project.getSourceRoots() ); + TEST_ROOTS_MODEL = SourceRootsUi.createModel( project.getTestSourceRoots() ); + includes = evaluator.getProperty(ProjectProperties.INCLUDES); if (includes == null) { includes = "**"; // NOI18N } - excludes = evaluator.getProperty(EXCLUDES); + excludes = evaluator.getProperty(ProjectProperties.EXCLUDES); if (excludes == null) { excludes = ""; // NOI18N } @@ -319,10 +312,10 @@ // CustomizerLibraries EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); - JAVAC_CLASSPATH_MODEL = ClassPathUiSupport.createListModel(cs.itemsIterator(projectProperties.get(JAVAC_CLASSPATH))); - JAVAC_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel(cs.itemsIterator(projectProperties.get(JAVAC_TEST_CLASSPATH))); - RUN_CLASSPATH_MODEL = ClassPathUiSupport.createListModel(cs.itemsIterator(projectProperties.get(RUN_CLASSPATH))); - RUN_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel(cs.itemsIterator(projectProperties.get(RUN_TEST_CLASSPATH))); + JAVAC_CLASSPATH_MODEL = ClassPathUiSupport.createListModel(cs.itemsIterator(projectProperties.get(ProjectProperties.JAVAC_CLASSPATH))); + JAVAC_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel(cs.itemsIterator(projectProperties.get(ProjectProperties.JAVAC_TEST_CLASSPATH))); + RUN_CLASSPATH_MODEL = ClassPathUiSupport.createListModel(cs.itemsIterator(projectProperties.get(ProjectProperties.RUN_CLASSPATH))); + RUN_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel(cs.itemsIterator(projectProperties.get(ProjectProperties.RUN_TEST_CLASSPATH))); PLATFORM_MODEL = PlatformUiSupport.createPlatformComboBoxModel (evaluator.getProperty(JAVA_PLATFORM)); PLATFORM_LIST_RENDERER = PlatformUiSupport.createPlatformListCellRenderer(); JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(JAVAC_TARGET)); @@ -413,7 +406,7 @@ storeProperties(); //Delete COS mark if (!COMPILE_ON_SAVE_MODEL.isSelected()) { - FileObject buildClasses = updateHelper.getAntProjectHelper().resolveFileObject(evaluator.getProperty(BUILD_CLASSES_DIR)); + FileObject buildClasses = updateHelper.getAntProjectHelper().resolveFileObject(evaluator.getProperty(ProjectProperties.BUILD_CLASSES_DIR)); if (buildClasses != null) { FileObject mark = buildClasses.getFileObject(COS_MARK); if (mark != null) { @@ -488,10 +481,10 @@ resolveProjectDependencies(); // Encode all paths (this may change the project properties) - String[] javac_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( JAVAC_CLASSPATH_MODEL ) ); - String[] javac_test_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( JAVAC_TEST_CLASSPATH_MODEL ) ); - String[] run_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( RUN_CLASSPATH_MODEL ) ); - String[] run_test_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( RUN_TEST_CLASSPATH_MODEL ) ); + String[] javac_cp = cs.encodeToStrings( ClassPathUiSupport.getList( JAVAC_CLASSPATH_MODEL ) ); + String[] javac_test_cp = cs.encodeToStrings( ClassPathUiSupport.getList( JAVAC_TEST_CLASSPATH_MODEL ) ); + String[] run_cp = cs.encodeToStrings( ClassPathUiSupport.getList( RUN_CLASSPATH_MODEL ) ); + String[] run_test_cp = cs.encodeToStrings( ClassPathUiSupport.getList( RUN_TEST_CLASSPATH_MODEL ) ); // Store source roots storeRoots( project.getSourceRoots(), SOURCE_ROOTS_MODEL ); @@ -531,10 +524,10 @@ privateProperties.setProperty(JAVADOC_PREVIEW, encodeBoolean (JAVADOC_PREVIEW_MODEL.isSelected(), javadocPreviewBooleanKind)); // Save all paths - projectProperties.setProperty( JAVAC_CLASSPATH, javac_cp ); - projectProperties.setProperty( JAVAC_TEST_CLASSPATH, javac_test_cp ); - projectProperties.setProperty( RUN_CLASSPATH, run_cp ); - projectProperties.setProperty( RUN_TEST_CLASSPATH, run_test_cp ); + projectProperties.setProperty( ProjectProperties.JAVAC_CLASSPATH, javac_cp ); + projectProperties.setProperty( ProjectProperties.JAVAC_TEST_CLASSPATH, javac_test_cp ); + projectProperties.setProperty( ProjectProperties.RUN_CLASSPATH, run_cp ); + projectProperties.setProperty( ProjectProperties.RUN_TEST_CLASSPATH, run_test_cp ); //Handle platform selection and javac.source javac.target properties PlatformUiSupport.storePlatform (projectProperties, updateHelper, J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, PLATFORM_MODEL.getSelectedItem(), JAVAC_SOURCE_MODEL.getSelectedItem()); @@ -546,8 +539,8 @@ projectProperties.putAll(additionalProperties); - projectProperties.put(INCLUDES, includes); - projectProperties.put(EXCLUDES, excludes); + projectProperties.put(ProjectProperties.INCLUDES, includes); + projectProperties.put(ProjectProperties.EXCLUDES, excludes); // Store the property changes into the project updateHelper.putProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties ); @@ -571,10 +564,10 @@ // Create a set of old and new artifacts. Set oldArtifacts = new HashSet(); EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); - oldArtifacts.addAll( cs.itemsList( projectProperties.get( JAVAC_CLASSPATH ) ) ); - oldArtifacts.addAll( cs.itemsList( projectProperties.get( JAVAC_TEST_CLASSPATH ) ) ); - oldArtifacts.addAll( cs.itemsList( projectProperties.get( RUN_CLASSPATH ) ) ); - oldArtifacts.addAll( cs.itemsList( projectProperties.get( RUN_TEST_CLASSPATH ) ) ); + oldArtifacts.addAll( cs.itemsList( projectProperties.get( ProjectProperties.JAVAC_CLASSPATH ) ) ); + oldArtifacts.addAll( cs.itemsList( projectProperties.get( ProjectProperties.JAVAC_TEST_CLASSPATH ) ) ); + oldArtifacts.addAll( cs.itemsList( projectProperties.get( ProjectProperties.RUN_CLASSPATH ) ) ); + oldArtifacts.addAll( cs.itemsList( projectProperties.get( ProjectProperties.RUN_TEST_CLASSPATH ) ) ); Set newArtifacts = new HashSet(); newArtifacts.addAll( ClassPathUiSupport.getList( JAVAC_CLASSPATH_MODEL ) ); @@ -609,7 +602,7 @@ if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) { // remove helper property pointing to library jar if there is any String prop = item.getReference(); - prop = ClassPathSupport.getAntPropertyName(prop); + prop = CommonProjectUtils.getAntPropertyName(prop); ep.remove(prop); changed = true; } diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SESourceRootsUi.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SESourceRootsUi.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SESourceRootsUi.java +++ /dev/null @@ -1,605 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.ui.customizer; - -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.net.URI; -import java.net.URL; -import java.util.Iterator; -import java.util.HashSet; -import java.util.Set; -import java.util.Vector; -import java.text.MessageFormat; -import javax.swing.*; -import javax.swing.JButton; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.event.CellEditorListener; -import javax.swing.event.ChangeEvent; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.DefaultTableModel; -import org.netbeans.api.java.project.JavaProjectConstants; -import org.netbeans.api.project.ProjectUtils; -import org.netbeans.api.project.SourceGroup; -import org.netbeans.api.project.Sources; -import org.netbeans.modules.java.j2seproject.J2SEProject; -import org.netbeans.api.project.FileOwnerQuery; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectInformation; -import org.netbeans.modules.java.api.common.SourceRoots; -import org.openide.DialogDisplayer; -import org.openide.DialogDescriptor; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.util.NbBundle; - -/** Handles adding, removing, reordering of source roots. - * - * @author Tomas Zezula - */ -public final class J2SESourceRootsUi { - - public static DefaultTableModel createModel( SourceRoots roots ) { - - String[] rootLabels = roots.getRootNames(); - String[] rootProps = roots.getRootProperties(); - URL[] rootURLs = roots.getRootURLs(); - Object[][] data = new Object[rootURLs.length] [2]; - for (int i=0; i< rootURLs.length; i++) { - data[i][0] = new File (URI.create (rootURLs[i].toExternalForm())); - data[i][1] = roots.getRootDisplayName(rootLabels[i], rootProps[i]); - } - return new SourceRootsModel(data); - - } - - public static EditMediator registerEditMediator( J2SEProject master, - SourceRoots sourceRoots, - JTable rootsList, - JButton addFolderButton, - JButton removeButton, - JButton upButton, - JButton downButton, - CellEditor rootsListEditor) { - - EditMediator em = new EditMediator( master, - sourceRoots, - rootsList, - addFolderButton, - removeButton, - upButton, - downButton); - - // Register the listeners - // On all buttons - addFolderButton.addActionListener( em ); - removeButton.addActionListener( em ); - upButton.addActionListener( em ); - downButton.addActionListener( em ); - // On list selection - rootsList.getSelectionModel().addListSelectionListener( em ); - DefaultCellEditor editor = (DefaultCellEditor) rootsListEditor; - if (editor == null) { - editor = new DefaultCellEditor(new JTextField()); - } - editor.addCellEditorListener (em); - rootsList.setDefaultRenderer( File.class, new FileRenderer (FileUtil.toFile(master.getProjectDirectory()))); - rootsList.setDefaultEditor(String.class, editor); - // Set the initial state of the buttons - em.valueChanged( null ); - - DefaultTableModel model = (DefaultTableModel)rootsList.getModel(); - String[] columnNames = new String[2]; - columnNames[0] = NbBundle.getMessage( J2SESourceRootsUi.class,"CTL_PackageFolders"); - columnNames[1] = NbBundle.getMessage( J2SESourceRootsUi.class,"CTL_PackageLabels"); - model.setColumnIdentifiers(columnNames); - rootsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - - return em; - } - - public static EditMediator registerEditMediator( J2SEProject master, - SourceRoots sourceRoots, - JTable rootsList, - JButton addFolderButton, - JButton removeButton, - JButton upButton, - JButton downButton ) { - return registerEditMediator(master, sourceRoots, rootsList, addFolderButton, - removeButton, upButton, downButton, null); - } - - /** - * Opens the standard dialog for warning an user about illegal source roots. - * @param roots the set of illegal source/test roots - */ - public static void showIllegalRootsDialog (Set/**/ roots) { - JButton closeOption = new JButton (NbBundle.getMessage(J2SESourceRootsUi.class,"CTL_J2SESourceRootsUi_Close")); - closeOption.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage(J2SESourceRootsUi.class,"AD_J2SESourceRootsUi_Close")); - JPanel warning = new WarningDlg (roots); - String message = NbBundle.getMessage(J2SESourceRootsUi.class,"MSG_InvalidRoot"); - JOptionPane optionPane = new JOptionPane (new Object[] {message, warning}, - JOptionPane.WARNING_MESSAGE, - 0, - null, - new Object[0], - null); - optionPane.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(J2SESourceRootsUi.class,"AD_InvalidRootDlg")); - DialogDescriptor dd = new DialogDescriptor (optionPane, - NbBundle.getMessage(J2SESourceRootsUi.class,"TITLE_InvalidRoot"), - true, - new Object[] { - closeOption, - }, - closeOption, - DialogDescriptor.DEFAULT_ALIGN, - null, - null); - DialogDisplayer.getDefault().notify(dd); - } - - // Private innerclasses ---------------------------------------------------- - - public static class EditMediator implements ActionListener, ListSelectionListener, CellEditorListener { - - - final JTable rootsList; - final JButton addFolderButton; - final JButton removeButton; - final JButton upButton; - final JButton downButton; - private final Project project; - private final SourceRoots sourceRoots; - private final Set ownedFolders; - private DefaultTableModel rootsModel; - private EditMediator relatedEditMediator; - private File lastUsedDir; //Last used current folder in JFileChooser - - - public EditMediator( J2SEProject master, - SourceRoots sourceRoots, - JTable rootsList, - JButton addFolderButton, - JButton removeButton, - JButton upButton, - JButton downButton) { - - if ( !( rootsList.getModel() instanceof DefaultTableModel ) ) { - throw new IllegalArgumentException( "Jtable's model has to be of class DefaultTableModel" ); // NOI18N - } - - this.rootsList = rootsList; - this.addFolderButton = addFolderButton; - this.removeButton = removeButton; - this.upButton = upButton; - this.downButton = downButton; - this.ownedFolders = new HashSet(); - - this.project = master; - this.sourceRoots = sourceRoots; - - this.ownedFolders.clear(); - this.rootsModel = (DefaultTableModel)rootsList.getModel(); - Vector data = rootsModel.getDataVector(); - for (Iterator it = data.iterator(); it.hasNext();) { - Vector row = (Vector) it.next (); - File f = (File) row.elementAt(0); - this.ownedFolders.add (f); - } - } - - public void setRelatedEditMediator(EditMediator rem) { - this.relatedEditMediator = rem; - } - - // Implementation of ActionListener ------------------------------------ - - /** Handles button events - */ - public void actionPerformed( ActionEvent e ) { - - Object source = e.getSource(); - - if ( source == addFolderButton ) { - - // Let user search for the Jar file - JFileChooser chooser = new JFileChooser(); - FileUtil.preventFileChooserSymlinkTraversal(chooser, null); - chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY ); - chooser.setMultiSelectionEnabled( true ); - if (this.sourceRoots.isTest()) { - chooser.setDialogTitle( NbBundle.getMessage( J2SESourceRootsUi.class, "LBL_TestFolder_DialogTitle" )); // NOI18N - } - else { - chooser.setDialogTitle( NbBundle.getMessage( J2SESourceRootsUi.class, "LBL_SourceFolder_DialogTitle" )); // NOI18N - } - File curDir = this.lastUsedDir; - if (curDir == null) { - curDir = FileUtil.toFile(this.project.getProjectDirectory()); - } - if (curDir != null) { - chooser.setCurrentDirectory (curDir); - } - int option = chooser.showOpenDialog( SwingUtilities.getWindowAncestor( addFolderButton ) ); // Sow the chooser - - if ( option == JFileChooser.APPROVE_OPTION ) { - curDir = chooser.getCurrentDirectory(); - if (curDir != null) { - this.lastUsedDir = curDir; - if (this.relatedEditMediator != null) { - this.relatedEditMediator.lastUsedDir = curDir; - } - } - File files[] = chooser.getSelectedFiles(); - addFolders( files ); - } - - } - else if ( source == removeButton ) { - removeElements(); - } - else if ( source == upButton ) { - moveUp(); - } - else if ( source == downButton ) { - moveDown(); - } - } - - // Selection listener implementation ---------------------------------- - - /** Handles changes in the selection - */ - public void valueChanged( ListSelectionEvent e ) { - - int[] si = rootsList.getSelectedRows(); - - // addJar allways enabled - - // addLibrary allways enabled - - // addArtifact allways enabled - - // edit enabled only if selection is not empty - boolean edit = si != null && si.length > 0; - - // remove enabled only if selection is not empty - boolean remove = si != null && si.length > 0; - // and when the selection does not contain unremovable item - - // up button enabled if selection is not empty - // and the first selected index is not the first row - boolean up = si != null && si.length > 0 && si[0] != 0; - - // up button enabled if selection is not empty - // and the laset selected index is not the last row - boolean down = si != null && si.length > 0 && si[si.length-1] !=rootsList.getRowCount() - 1; - - removeButton.setEnabled( remove ); - upButton.setEnabled( up ); - downButton.setEnabled( down ); - - //System.out.println("Selection changed " + edit + ", " + remove + ", " + + ", " + + ", "); - - } - - public void editingCanceled(ChangeEvent e) { - - } - - public void editingStopped(ChangeEvent e) { - // fireActionPerformed(); - } - - private void addFolders( File files[] ) { - int[] si = rootsList.getSelectedRows(); - int lastIndex = si == null || si.length == 0 ? -1 : si[si.length - 1]; - ListSelectionModel selectionModel = this.rootsList.getSelectionModel(); - selectionModel.clearSelection(); - Set rootsFromOtherProjects = new HashSet (); - Set rootsFromRelatedSourceRoots = new HashSet(); -out: for( int i = 0; i < files.length; i++ ) { - File normalizedFile = FileUtil.normalizeFile(files[i]); - Project p; - if (ownedFolders.contains(normalizedFile)) { - Vector dataVector = rootsModel.getDataVector(); - for (int j=0; j 0 || rootsFromRelatedSourceRoots.size() > 0) { - rootsFromOtherProjects.addAll(rootsFromRelatedSourceRoots); - showIllegalRootsDialog (rootsFromOtherProjects); - } - // fireActionPerformed(); - } - - private void removeElements() { - - int[] si = rootsList.getSelectedRows(); - - if( si == null || si.length == 0 ) { - assert false : "Remove button should be disabled"; // NOI18N - } - - // Remove the items - for( int i = si.length - 1 ; i >= 0 ; i-- ) { - this.ownedFolders.remove(((Vector)rootsModel.getDataVector().elementAt(si[i])).elementAt(0)); - rootsModel.removeRow( si[i] ); - } - - - if ( rootsModel.getRowCount() != 0) { - // Select reasonable item - int selectedIndex = si[si.length - 1] - si.length + 1; - if ( selectedIndex > rootsModel.getRowCount() - 1) { - selectedIndex = rootsModel.getRowCount() - 1; - } - rootsList.setRowSelectionInterval( selectedIndex, selectedIndex ); - } - - // fireActionPerformed(); - - } - - private void moveUp() { - - int[] si = rootsList.getSelectedRows(); - - if( si == null || si.length == 0 ) { - assert false : "MoveUp button should be disabled"; // NOI18N - } - - // Move the items up - ListSelectionModel selectionModel = this.rootsList.getSelectionModel(); - selectionModel.clearSelection(); - for( int i = 0; i < si.length; i++ ) { - Vector item = (Vector) rootsModel.getDataVector().elementAt(si[i]); - int newIndex = si[i]-1; - rootsModel.removeRow( si[i] ); - rootsModel.insertRow( newIndex, item ); - selectionModel.addSelectionInterval(newIndex,newIndex); - } - // fireActionPerformed(); - } - - private void moveDown() { - - int[] si = rootsList.getSelectedRows(); - - if( si == null || si.length == 0 ) { - assert false : "MoveDown button should be disabled"; // NOI18N - } - - // Move the items up - ListSelectionModel selectionModel = this.rootsList.getSelectionModel(); - selectionModel.clearSelection(); - for( int i = si.length -1 ; i >= 0 ; i-- ) { - Vector item = (Vector) rootsModel.getDataVector().elementAt(si[i]); - int newIndex = si[i] + 1; - rootsModel.removeRow( si[i] ); - rootsModel.insertRow( newIndex, item ); - selectionModel.addSelectionInterval(newIndex,newIndex); - } - // fireActionPerformed(); - } - - - } - - private static class SourceRootsModel extends DefaultTableModel { - - public SourceRootsModel (Object[][] data) { - super (data,new Object[]{"location","label"});//NOI18N - } - - public boolean isCellEditable(int row, int column) { - return column == 1; - } - - public Class getColumnClass(int columnIndex) { - switch (columnIndex) { - case 0: - return File.class; - case 1: - return String.class; - default: - return super.getColumnClass (columnIndex); - } - } - } - - private static class FileRenderer extends DefaultTableCellRenderer { - - private File projectFolder; - - public FileRenderer (File projectFolder) { - this.projectFolder = projectFolder; - } - - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,int row, int column) { - String displayName; - if (value instanceof File) { - File root = (File) value; - String pfPath = projectFolder.getAbsolutePath() + File.separatorChar; - String srPath = root.getAbsolutePath(); - if (srPath.startsWith(pfPath)) { - displayName = srPath.substring(pfPath.length()); - } - else { - displayName = srPath; - } - } - else { - displayName = null; - } - Component c = super.getTableCellRendererComponent(table, displayName, isSelected, hasFocus, row, column); - if (c instanceof JComponent) { - ((JComponent) c).setToolTipText (displayName); - } - return c; - } - - } - - private static class WarningDlg extends JPanel { - - public WarningDlg (Set invalidRoots) { - this.initGui (invalidRoots); - } - - private void initGui (Set invalidRoots) { - setLayout( new GridBagLayout ()); - JLabel label = new JLabel (); - label.setText (NbBundle.getMessage(J2SESourceRootsUi.class,"LBL_InvalidRoot")); - label.setDisplayedMnemonic(NbBundle.getMessage(J2SESourceRootsUi.class,"MNE_InvalidRoot").charAt(0)); - GridBagConstraints c = new GridBagConstraints(); - c.gridx = GridBagConstraints.RELATIVE; - c.gridy = GridBagConstraints.RELATIVE; - c.gridwidth = GridBagConstraints.REMAINDER; - c.fill = GridBagConstraints.HORIZONTAL; - c.anchor = GridBagConstraints.NORTHWEST; - c.weightx = 1.0; - c.insets = new Insets (12,0,6,0); - ((GridBagLayout)this.getLayout()).setConstraints(label,c); - this.add (label); - JList roots = new JList (invalidRoots.toArray()); - roots.setCellRenderer (new InvalidRootRenderer(true)); - JScrollPane p = new JScrollPane (roots); - c = new GridBagConstraints(); - c.gridx = GridBagConstraints.RELATIVE; - c.gridy = GridBagConstraints.RELATIVE; - c.gridwidth = GridBagConstraints.REMAINDER; - c.fill = GridBagConstraints.BOTH; - c.anchor = GridBagConstraints.NORTHWEST; - c.weightx = c.weighty = 1.0; - c.insets = new Insets (0,0,12,0); - ((GridBagLayout)this.getLayout()).setConstraints(p,c); - this.add (p); - label.setLabelFor(roots); - roots.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(J2SESourceRootsUi.class,"AD_InvalidRoot")); - JLabel label2 = new JLabel (); - label2.setText (NbBundle.getMessage(J2SESourceRootsUi.class,"MSG_InvalidRoot2")); - c = new GridBagConstraints(); - c.gridx = GridBagConstraints.RELATIVE; - c.gridy = GridBagConstraints.RELATIVE; - c.gridwidth = GridBagConstraints.REMAINDER; - c.fill = GridBagConstraints.HORIZONTAL; - c.anchor = GridBagConstraints.NORTHWEST; - c.weightx = 1.0; - c.insets = new Insets (0,0,0,0); - ((GridBagLayout)this.getLayout()).setConstraints(label2,c); - this.add (label2); - } - - private static class InvalidRootRenderer extends DefaultListCellRenderer { - - private boolean projectConflict; - - public InvalidRootRenderer (boolean projectConflict) { - this.projectConflict = projectConflict; - } - - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - File f = (File) value; - String message = f.getAbsolutePath(); - if (projectConflict) { - Project p = FileOwnerQuery.getOwner(f.toURI()); - if (p!=null) { - ProjectInformation pi = ProjectUtils.getInformation(p); - String projectName = pi.getDisplayName(); - message = MessageFormat.format (NbBundle.getMessage(J2SESourceRootsUi.class,"TXT_RootOwnedByProject"), new Object[] { - message, - projectName}); - } - } - return super.getListCellRendererComponent(list, message, index, isSelected, cellHasFocus); - } - } - } - -} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/resources/layer.xml b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/resources/layer.xml --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/resources/layer.xml +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/resources/layer.xml @@ -132,7 +132,7 @@ - + diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/FolderList.form b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/FolderList.form deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/FolderList.form +++ /dev/null @@ -1,70 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/FolderList.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/FolderList.java deleted file mode 100644 --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/FolderList.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.java.j2seproject.ui.wizards; - - -import java.awt.Color; -import java.awt.Component; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.text.MessageFormat; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import javax.swing.DefaultListModel; -import javax.swing.DefaultListCellRenderer; -import javax.swing.Icon; -import javax.swing.JFileChooser; -import javax.swing.JList; -import javax.swing.event.ListSelectionListener; -import javax.swing.event.ListSelectionEvent; -import org.netbeans.api.java.project.JavaProjectConstants; -import org.netbeans.api.project.SourceGroup; -import org.netbeans.api.project.Sources; -import org.netbeans.modules.java.j2seproject.ui.customizer.J2SESourceRootsUi; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.util.NbBundle; -import org.netbeans.api.project.FileOwnerQuery; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectInformation; -import org.netbeans.modules.java.j2seproject.ui.FoldersListSettings; - - -/** - * List of source/test roots - * @author tzezula - */ -public final class FolderList extends javax.swing.JPanel { - - public static final String PROP_FILES = "files"; //NOI18N - public static final String PROP_LAST_USED_DIR = "lastUsedDir"; //NOI18N - - private String fcMessage; - private File projectFolder; - private File lastUsedFolder; - private FolderList relatedFolderList; - - /** Creates new form FolderList */ - public FolderList (String label, char mnemonic, String accessibleDesc, String fcMessage, - char addButtonMnemonic, String addButtonAccessibleDesc, - char removeButtonMnemonic,String removeButtonAccessibleDesc) { - this.fcMessage = fcMessage; - initComponents(); - this.jLabel1.setText(label); - this.jLabel1.setDisplayedMnemonic(mnemonic); - this.roots.getAccessibleContext().setAccessibleDescription(accessibleDesc); - this.roots.setCellRenderer(new Renderer()); - this.roots.setModel (new DefaultListModel()); - this.roots.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent e) { - if (!e.getValueIsAdjusting()) { - removeButton.setEnabled(roots.getSelectedIndices().length != 0); - } - } - }); - this.addButton.getAccessibleContext().setAccessibleDescription(addButtonAccessibleDesc); - this.addButton.setMnemonic (addButtonMnemonic); - this.removeButton.getAccessibleContext().setAccessibleDescription(removeButtonAccessibleDesc); - this.removeButton.setMnemonic (removeButtonMnemonic); - this.removeButton.setEnabled(false); - } - - public void setProjectFolder (File projectFolder) { - this.projectFolder = projectFolder; - } - - public void setRelatedFolderList (FolderList relatedFolderList) { - this.relatedFolderList = relatedFolderList; - } - - public File[] getFiles () { - Object[] files = ((DefaultListModel)this.roots.getModel()).toArray(); - File[] result = new File[files.length]; - System.arraycopy(files, 0, result, 0, files.length); - return result; - } - - public void setFiles (File[] files) { - DefaultListModel model = ((DefaultListModel)this.roots.getModel()); - model.clear(); - for (int i=0; i0) { - this.roots.setSelectedIndex(0); - } - } - - public void setLastUsedDir (File lastUsedDir) { - if (this.lastUsedFolder == null ? lastUsedDir != null : !this.lastUsedFolder.equals(lastUsedDir)) { - File oldValue = this.lastUsedFolder; - this.lastUsedFolder = lastUsedDir; - this.firePropertyChange(PROP_LAST_USED_DIR, oldValue, this.lastUsedFolder); - } - } - - public File getLastUsedDir () { - return this.lastUsedFolder; - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - private void initComponents() {//GEN-BEGIN:initComponents - java.awt.GridBagConstraints gridBagConstraints; - - jLabel1 = new javax.swing.JLabel(); - jScrollPane1 = new javax.swing.JScrollPane(); - roots = new javax.swing.JList(); - addButton = new javax.swing.JButton(); - removeButton = new javax.swing.JButton(); - - setLayout(new java.awt.GridBagLayout()); - - jLabel1.setLabelFor(roots); - jLabel1.setText("jLabel1"); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0); - add(jLabel1, gridBagConstraints); - - jScrollPane1.setViewportView(roots); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.weighty = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12); - add(jScrollPane1, gridBagConstraints); - - addButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/wizards/Bundle").getString("CTL_AddFolder")); - addButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - addButtonActionPerformed(evt); - } - }); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - add(addButton, gridBagConstraints); - - removeButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/wizards/Bundle").getString("CTL_RemoveFolder")); - removeButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - removeButtonActionPerformed(evt); - } - }); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridy = 2; - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0); - add(removeButton, gridBagConstraints); - - }//GEN-END:initComponents - - private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed - Object[] selection = this.roots.getSelectedValues (); - for (int i=0; i0) { - J2SESourceRootsUi.showIllegalRootsDialog(invalidRoots); - } - } - }//GEN-LAST:event_addButtonActionPerformed - - - static boolean isValidRoot (File file, File[] relatedRoots, File projectFolder) { - Project p; - if ((p = FileOwnerQuery.getOwner(file.toURI()))!=null - && !file.getAbsolutePath().startsWith(projectFolder.getAbsolutePath()+File.separatorChar)) { - final Sources sources = (Sources) p.getLookup().lookup(Sources.class); - if (sources == null) { - return false; - } - final SourceGroup[] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC); - final SourceGroup[] javaGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); - final SourceGroup[] groups = new SourceGroup [sourceGroups.length + javaGroups.length]; - System.arraycopy(sourceGroups,0,groups,0,sourceGroups.length); - System.arraycopy(javaGroups,0,groups,sourceGroups.length,javaGroups.length); - final FileObject projectDirectory = p.getProjectDirectory(); - final FileObject fileObject = FileUtil.toFileObject(file); - if (projectDirectory == null || fileObject == null) { - return false; - } - for (int i = 0; i< groups.length; i++) { - final FileObject sgRoot = groups[i].getRootFolder(); - if (fileObject.equals(sgRoot)) { - return false; - } - if (!projectDirectory.equals(sgRoot) && FileUtil.isParentOf(sgRoot, fileObject)) { - return false; - } - } - return true; - } - else if (contains (file, relatedRoots)) { - return false; - } - return true; - } - - private static boolean contains (File folder, File[] roots) { - String path = folder.getAbsolutePath (); - for (int i=0; i