diff --git a/j2ee.archive/nbproject/project.xml b/j2ee.archive/nbproject/project.xml --- a/j2ee.archive/nbproject/project.xml +++ b/j2ee.archive/nbproject/project.xml @@ -164,6 +164,15 @@ + org.netbeans.modules.java.api.common + + + + 0-1 + 1.18 + + + org.netbeans.modules.java.project @@ -314,6 +323,20 @@ + + + qa-functional + + org.netbeans.libs.junit4 + + + + org.netbeans.modules.nbjunit + + + + + diff --git a/j2ee.archive/src/org/netbeans/modules/j2ee/archive/project/ArchiveProject.java b/j2ee.archive/src/org/netbeans/modules/j2ee/archive/project/ArchiveProject.java --- a/j2ee.archive/src/org/netbeans/modules/j2ee/archive/project/ArchiveProject.java +++ b/j2ee.archive/src/org/netbeans/modules/j2ee/archive/project/ArchiveProject.java @@ -42,10 +42,8 @@ package org.netbeans.modules.j2ee.archive.project; import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; import java.io.File; import java.io.IOException; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -57,8 +55,8 @@ import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.classpath.GlobalPathRegistry; import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectInformation; import org.netbeans.api.project.ProjectManager; +import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.ant.AntArtifact; import org.netbeans.modules.j2ee.archive.Util; import org.netbeans.modules.j2ee.archive.customizer.ProvidesCustomizer; @@ -74,6 +72,7 @@ import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleImplementation2; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel; +import org.netbeans.modules.java.api.common.ant.ProjectInfoImpl; import org.netbeans.modules.web.api.webmodule.WebProjectConstants; import org.netbeans.spi.java.classpath.support.ClassPathSupport; import org.netbeans.spi.project.AuxiliaryConfiguration; @@ -83,7 +82,6 @@ import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.spi.project.support.ant.PropertyUtils; import org.netbeans.spi.project.ui.PrivilegedTemplates; import org.netbeans.spi.project.ui.RecommendedTemplates; import org.openide.ErrorManager; @@ -196,22 +194,7 @@ /** Return configured project name. */ public String getName() { - return (String) ProjectManager.mutex().readAccess(new Mutex.Action() { - @Override - public String run() { - Element data = updateHelper.getPrimaryConfigurationData(true); - // XXX replace by XMLUtil when that has findElement, findText, etc. - NodeList nl = data.getElementsByTagNameNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS, NAME_LIT); - if (nl.getLength() == 1) { - nl = nl.item(0).getChildNodes(); - if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) { - return ((Text) nl.item(0)).getNodeValue(); - } - } - return "BINARCHIVE???"; // NOI18N - } - }); - + return ProjectUtils.getInformation(this).getName(); } public ArchiveProjectProperties getArchiveProjectProperties() { @@ -226,9 +209,9 @@ private final class HelpfulLookup extends Lookup { private boolean verbose = Boolean.getBoolean("archiveproject.lookup.verbose"); - + Lookup inner = LookupProviderSupport.createCompositeLookup(Lookups.fixed(new Object[] { - new Info(), + new ProjectInfoImpl(ArchiveProject.this, helper, ARCHIVE_PROJECT_ICON), helper.createAuxiliaryConfiguration(), helper.createCacheDirectoryProvider(), helper.createGlobFileBuiltQuery(eval, new String[] {"${src.dir}/*.java"}, @@ -311,64 +294,7 @@ return ret; } } - //when #110886 gets implemented, this class is obsolete - private final class Info implements ProjectInformation { - - private PropertyChangeSupport pcs = new PropertyChangeSupport(this); - private WeakReference cachedName = null; - - Info() {} - - void firePropertyChange(String prop) { - pcs.firePropertyChange(prop, null, null); - synchronized (pcs) { - cachedName = null; - } - } - - @Override - public String getName() { - return PropertyUtils.getUsablePropertyName(getDisplayName()); - } - - @Override - public String getDisplayName() { - synchronized (pcs) { - if (cachedName != null) { - String dn = cachedName.get(); - if (dn != null) { - return dn; - } - } - } - String dn = ArchiveProject.this.getNamedProjectAttribute(NAME_LIT); - synchronized (pcs) { - cachedName = new WeakReference(dn); - } - return dn; - } - - @Override - public Icon getIcon() { - return ARCHIVE_PROJECT_ICON; - } - - @Override - public Project getProject() { - return ArchiveProject.this; - } - - @Override - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - @Override - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - } - + private final class MyAntProvider implements AntArtifactProvider { // TODO - Need to fix for ejb-jar/app-client/resource-adapter cases @Override diff --git a/j2ee.clientproject/nbproject/project.xml b/j2ee.clientproject/nbproject/project.xml --- a/j2ee.clientproject/nbproject/project.xml +++ b/j2ee.clientproject/nbproject/project.xml @@ -215,7 +215,7 @@ 0-1 - 1.15 + 1.18 diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientProject.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientProject.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientProject.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientProject.java @@ -43,10 +43,8 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; import java.io.File; import java.io.IOException; -import java.lang.ref.WeakReference; import java.net.URI; import java.util.Arrays; import java.util.LinkedList; @@ -60,8 +58,8 @@ import org.netbeans.api.java.classpath.GlobalPathRegistry; import org.netbeans.api.java.project.JavaProjectConstants; import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectInformation; import org.netbeans.api.project.ProjectManager; +import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.ant.AntArtifact; import org.netbeans.api.project.ant.AntBuildExtender; @@ -88,6 +86,7 @@ import org.netbeans.modules.j2ee.spi.ejbjar.CarImplementation; import org.netbeans.modules.j2ee.spi.ejbjar.CarImplementation2; import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.ant.ProjectInfoImpl; 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.project.ProjectProperties; @@ -106,14 +105,11 @@ import org.netbeans.spi.project.ant.AntBuildExtenderImplementation; import org.netbeans.spi.project.support.LookupProviderSupport; import org.netbeans.spi.project.support.ant.AntBasedProjectRegistration; -import org.netbeans.spi.project.support.ant.AntProjectEvent; import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.AntProjectListener; import org.netbeans.spi.project.support.ant.EditableProperties; import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; import org.netbeans.spi.project.support.ant.ProjectXmlSavedHook; 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.project.ui.PrivilegedTemplates; import org.netbeans.spi.project.ui.ProjectOpenedHook; @@ -134,14 +130,11 @@ import org.openide.util.Exceptions; import org.openide.util.ImageUtilities; import org.openide.util.Lookup; -import org.openide.util.Mutex; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; import org.openide.util.lookup.Lookups; import org.w3c.dom.Element; -import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.w3c.dom.Text; /** * Represents one plain Application Client project. @@ -153,7 +146,7 @@ sharedNamespace=AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, privateNamespace=AppClientProjectType.PRIVATE_CONFIGURATION_NAMESPACE ) -public final class AppClientProject implements Project, AntProjectListener, FileChangeListener { +public final class AppClientProject implements Project, FileChangeListener { private final Icon CAR_PROJECT_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/j2ee/clientproject/ui/resources/appclient.gif", false); // NOI18N @@ -216,7 +209,6 @@ getClassPathUiSupportCallback()); classPathExtender = new ClassPathExtender(cpMod, ProjectProperties.JAVAC_CLASSPATH, ClassPathSupportCallbackImpl.ELEMENT_INCLUDED_LIBRARIES); lookup = createLookup(aux, cpProvider); - helper.addAntProjectListener(this); } private ClassPathModifier.Callback createClassPathModifierCallback() { @@ -298,7 +290,7 @@ FileEncodingQueryImplementation encodingQuery = QuerySupport.createFileEncodingQuery(evaluator(), AppClientProjectProperties.SOURCE_ENCODING); AppClientSources sources = new AppClientSources(this, helper, evaluator(), getSourceRoots(), getTestSourceRoots()); Lookup base = Lookups.fixed(new Object[] { - new Info(), + new ProjectInfoImpl(this, helper, CAR_PROJECT_ICON), aux, helper.createCacheDirectoryProvider(), helper.createAuxiliaryProperties(), @@ -354,19 +346,6 @@ return this.cpProvider; } - public void configurationXmlChanged(AntProjectEvent ev) { - if (ev.getPath().equals(AntProjectHelper.PROJECT_XML_PATH)) { - // Could be various kinds of changes, but name & displayName might have changed. - Info info = (Info)getLookup().lookup(ProjectInformation.class); - info.firePropertyChange(ProjectInformation.PROP_NAME); - info.firePropertyChange(ProjectInformation.PROP_DISPLAY_NAME); - } - } - - public void propertiesChanged(AntProjectEvent ev) { - // currently ignored (probably better to listen to evaluator() if you need to) - } - // Package private methods ------------------------------------------------- /** @@ -422,20 +401,7 @@ /** Return configured project name. */ public String getName() { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public String run() { - Element data = updateHelper.getPrimaryConfigurationData(true); - // XXX replace by XMLUtil when that has findElement, findText, etc. - NodeList nl = data.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); // NOI18N - if (nl.getLength() == 1) { - nl = nl.item(0).getChildNodes(); - if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) { - return ((Text) nl.item(0)).getNodeValue(); - } - } - return "CAR???"; // NOI18N - } - }); + return ProjectUtils.getInformation(this).getName(); } public void fileAttributeChanged (FileAttributeEvent fe) { @@ -588,73 +554,6 @@ } // Private innerclasses ---------------------------------------------------- - //when #110886 gets implemented, this class is obsolete - private final class Info implements ProjectInformation { - - private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - - private WeakReference cachedName = null; - - Info() {} - - void firePropertyChange(String prop) { - pcs.firePropertyChange(prop, null, null); - synchronized (pcs) { - cachedName = null; - } - } - - public String getName() { - return PropertyUtils.getUsablePropertyName(getDisplayName()); - } - - public String getDisplayName() { - synchronized (pcs) { - if (cachedName != null) { - String dn = cachedName.get(); - if (dn != null) { - return dn; - } - } - } - String dn = ProjectManager.mutex().readAccess(new Mutex.Action() { - public String run() { - Element data = updateHelper.getPrimaryConfigurationData(true); - // XXX replace by XMLUtil when that has findElement, findText, etc. - NodeList nl = data.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); // NOI18N - if (nl.getLength() == 1) { - nl = nl.item(0).getChildNodes(); - if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) { - return ((Text) nl.item(0)).getNodeValue(); - } - } - return "???"; // NOI18N - } - }); - synchronized (pcs) { - cachedName = new WeakReference(dn); - } - return dn; - } - - public Icon getIcon() { - return CAR_PROJECT_ICON; - } - - public Project getProject() { - return AppClientProject.this; - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - } - private final class ProjectXmlSavedHookImpl extends ProjectXmlSavedHook { ProjectXmlSavedHookImpl() {} diff --git a/j2ee.earproject/nbproject/project.xml b/j2ee.earproject/nbproject/project.xml --- a/j2ee.earproject/nbproject/project.xml +++ b/j2ee.earproject/nbproject/project.xml @@ -188,7 +188,7 @@ 0-1 - 1.6 + 1.18 diff --git a/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/EarProject.java b/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/EarProject.java --- a/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/EarProject.java +++ b/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/EarProject.java @@ -43,10 +43,8 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; import java.io.File; import java.io.IOException; -import java.lang.ref.WeakReference; import java.util.Arrays; import java.util.List; import java.util.logging.Level; @@ -55,7 +53,6 @@ import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.classpath.GlobalPathRegistry; 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.ant.AntBuildExtender; @@ -81,6 +78,7 @@ import org.netbeans.modules.j2ee.spi.ejbjar.EarImplementation; import org.netbeans.modules.j2ee.spi.ejbjar.EarImplementation2; import org.netbeans.modules.j2ee.spi.ejbjar.EjbJarFactory; +import org.netbeans.modules.java.api.common.ant.ProjectInfoImpl; import org.netbeans.modules.java.api.common.ant.UpdateHelper; import org.netbeans.modules.web.api.webmodule.WebModule; import org.netbeans.spi.java.project.support.LookupMergerSupport; @@ -116,9 +114,7 @@ import org.openide.util.NbBundle; import org.openide.util.lookup.Lookups; import org.w3c.dom.Element; -import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.w3c.dom.Text; /** * Represents an Enterprise Application project. @@ -213,7 +209,7 @@ private Lookup createLookup(AuxiliaryConfiguration aux, ClassPathProviderImpl cpProvider) { SubprojectProvider spp = refHelper.createSubprojectProvider(); Lookup base = Lookups.fixed(new Object[] { - new Info(), + new ProjectInfoImpl(this, helper, EAR_PROJECT_ICON), aux, spp, helper.createAuxiliaryProperties(), @@ -272,24 +268,6 @@ return ear; } - /** Return configured project name. */ - public String getName() { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public String run() { - Element data = updateHelper.getPrimaryConfigurationData(true); - // XXX replace by XMLUtil when that has findElement, findText, etc. - NodeList nl = data.getElementsByTagNameNS(EarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); // NOI18N - if (nl.getLength() == 1) { - nl = nl.item(0).getChildNodes(); - if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) { - return ((Text) nl.item(0)).getNodeValue(); - } - } - return "EAR????"; // NOI18N - } - }); - } - /** Store configured project name. */ public void setName(final String name) { ProjectManager.mutex().writeAccess(new Mutex.Action() { @@ -351,61 +329,6 @@ } // Private innerclasses ---------------------------------------------------- - //when #110886 gets implemented, this class is obsolete - private final class Info implements ProjectInformation { - - private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - - - private WeakReference cachedName = null; - - Info() {} - - void firePropertyChange(String prop) { - pcs.firePropertyChange(prop, null, null); - synchronized (pcs) { - cachedName = null; - } - } - - public String getName() { - return PropertyUtils.getUsablePropertyName(getDisplayName()); - } - - public String getDisplayName() { - synchronized (pcs) { - if (cachedName != null) { - String dn = cachedName.get(); - if (dn != null) { - return dn; - } - } - } - String dn = EarProject.this.getName(); - synchronized (pcs) { - cachedName = new WeakReference(dn); - } - return dn; - } - - public Icon getIcon() { - return EAR_PROJECT_ICON; - } - - public Project getProject() { - return EarProject.this; - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - } - private final class ProjectXmlSavedHookImpl extends ProjectXmlSavedHook { ProjectXmlSavedHookImpl() {} diff --git a/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/EarProjectOperations.java b/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/EarProjectOperations.java --- a/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/EarProjectOperations.java +++ b/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/EarProjectOperations.java @@ -50,6 +50,7 @@ import org.apache.tools.ant.module.api.support.ActionUtils; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectInformation; import org.netbeans.api.project.ProjectManager; import org.netbeans.modules.j2ee.earproject.ui.customizer.EarProjectProperties; import org.netbeans.spi.project.ActionProvider; @@ -167,9 +168,9 @@ EarProjectOperations origOperations = original.getLookup().lookup(EarProjectOperations.class); fixLibraryLocation(origOperations); - - final String oldProjectName = project.getName(); - + + final String oldProjectName = project.getLookup().lookup(ProjectInformation.class).getName(); + project.setName(newName); ProjectManager.mutex().writeAccess(new Runnable() { diff --git a/j2ee.ejbjarproject/nbproject/project.xml b/j2ee.ejbjarproject/nbproject/project.xml --- a/j2ee.ejbjarproject/nbproject/project.xml +++ b/j2ee.ejbjarproject/nbproject/project.xml @@ -241,7 +241,7 @@ 0-1 - 1.15 + 1.18 diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/EjbJarProject.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/EjbJarProject.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/EjbJarProject.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/EjbJarProject.java @@ -45,12 +45,10 @@ import java.awt.Dialog; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.lang.ref.WeakReference; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -82,7 +80,6 @@ import org.netbeans.modules.j2ee.ejbjarproject.jaxws.EjbProjectJAXWSSupport; import org.netbeans.modules.j2ee.ejbjarproject.ui.EjbJarLogicalViewProvider; import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; -import org.netbeans.api.project.ProjectInformation; import org.netbeans.api.project.SourceGroup; import org.netbeans.modules.j2ee.common.SharabilityUtility; import org.netbeans.modules.j2ee.common.Util; @@ -106,9 +103,7 @@ import org.netbeans.spi.project.ant.AntArtifactProvider; import org.netbeans.spi.project.ant.AntBuildExtenderFactory; import org.netbeans.spi.project.ant.AntBuildExtenderImplementation; -import org.netbeans.spi.project.support.ant.AntProjectEvent; import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.AntProjectListener; import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; import org.netbeans.spi.project.support.ant.ProjectXmlSavedHook; import org.netbeans.spi.project.ui.PrivilegedTemplates; @@ -122,7 +117,6 @@ import org.openide.loaders.DataObject; import org.openide.util.ImageUtilities; import org.openide.util.Lookup; -import org.openide.util.Mutex; import org.openide.util.RequestProcessor; import org.openide.util.lookup.Lookups; import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; @@ -132,12 +126,14 @@ import org.netbeans.modules.j2ee.common.project.ui.UserProjectSettings; import org.netbeans.modules.j2ee.deployment.devmodules.api.InstanceRemovedException; import org.netbeans.api.j2ee.core.Profile; +import org.netbeans.api.project.ProjectUtils; import org.netbeans.modules.j2ee.deployment.devmodules.spi.ArtifactListener; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider.DeployOnSaveSupport; import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.CustomizerProviderImpl; import org.netbeans.modules.j2ee.spi.ejbjar.EjbJarImplementation; import org.netbeans.modules.j2ee.spi.ejbjar.EjbJarImplementation2; import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.ant.ProjectInfoImpl; 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.project.ProjectProperties; @@ -149,11 +145,8 @@ import org.openide.DialogDisplayer; import org.openide.util.NbBundle; import org.w3c.dom.Document; -import org.w3c.dom.Comment; import org.w3c.dom.Element; -import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.w3c.dom.Text; import org.netbeans.modules.websvc.api.webservices.WebServicesSupport; import org.netbeans.modules.websvc.api.client.WebServicesClientSupport; import org.netbeans.modules.websvc.spi.webservices.WebServicesSupportFactory; @@ -161,7 +154,6 @@ import org.netbeans.spi.java.project.support.LookupMergerSupport; import org.netbeans.spi.project.support.LookupProviderSupport; import org.netbeans.spi.project.support.ant.AntBasedProjectRegistration; -import org.netbeans.spi.project.support.ant.PropertyUtils; import org.netbeans.spi.project.ui.support.UILookupMergerSupport; import org.netbeans.spi.queries.FileEncodingQueryImplementation; import org.openide.NotifyDescriptor; @@ -184,7 +176,7 @@ sharedNamespace=EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, privateNamespace=EjbJarProjectType.PRIVATE_CONFIGURATION_NAMESPACE ) -public class EjbJarProject implements Project, AntProjectListener, FileChangeListener { +public class EjbJarProject implements Project, FileChangeListener { private final Icon PROJECT_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/j2ee/ejbjarproject/ui/resources/ejbjarProjectIcon.gif", false); // NOI18N @@ -312,7 +304,6 @@ css = new CopyOnSaveSupport(); artifactSupport = new ArtifactCopySupport(); deployOnSaveSupport = new DeployOnSaveSupportProxy(); - helper.addAntProjectListener(this); ProjectManager.mutex().postWriteRequest( new Runnable () { public void run() { @@ -409,7 +400,7 @@ Lookup base = Lookups.fixed(new Object[] { EjbJarProject.this, // never cast an externally obtained Project to EjbJarProject - use lookup instead buildExtender, - new Info(), + new ProjectInfoImpl(this, helper, PROJECT_ICON), aux, helper.createCacheDirectoryProvider(), helper.createAuxiliaryProperties(), @@ -468,20 +459,6 @@ return this.cpProvider; } - public void configurationXmlChanged(AntProjectEvent ev) { - if (ev.getPath().equals(AntProjectHelper.PROJECT_XML_PATH)) { - // Could be various kinds of changes, but name & displayName might have changed. - Info info = (Info)getLookup().lookup(ProjectInformation.class); - info.firePropertyChange(ProjectInformation.PROP_NAME); - info.firePropertyChange(ProjectInformation.PROP_DISPLAY_NAME); - } - } - - public void propertiesChanged(AntProjectEvent ev) { - // currently ignored - //TODO: should not be ignored! - } - String getBuildXmlName() { String storedName = helper.getStandardPropertyEvaluator().getProperty(EjbJarProjectProperties.BUILD_FILE); return storedName == null ? GeneratedFilesHelper.BUILD_XML_PATH : storedName; @@ -583,20 +560,7 @@ /** Return configured project name. */ public String getName() { - return ProjectManager.mutex().readAccess(new Mutex.Action() { - public String run() { - Element data = updateHelper.getPrimaryConfigurationData(true); - // XXX replace by XMLUtil when that has findElement, findText, etc. - NodeList nl = data.getElementsByTagNameNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); //NOI18N - if (nl.getLength() == 1) { - nl = nl.item(0).getChildNodes(); - if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) { - return ((Text) nl.item(0)).getNodeValue(); - } - } - return "A Broken EJB Project"; // NOI18N - } - }); + return ProjectUtils.getInformation(this).getName(); } /** Store configured project name. */ @@ -783,61 +747,6 @@ } // Private innerclasses ---------------------------------------------------- - - //when #110886 gets implemented, this class is obsolete - private final class Info implements ProjectInformation { - - private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - - private WeakReference cachedName = null; - - Info() {} - - void firePropertyChange(String prop) { - pcs.firePropertyChange(prop, null, null); - synchronized (pcs) { - cachedName = null; - } - } - - public String getName() { - return PropertyUtils.getUsablePropertyName(getDisplayName()); - } - - public String getDisplayName() { - synchronized (pcs) { - if (cachedName != null) { - String dn = cachedName.get(); - if (dn != null) { - return dn; - } - } - } - String dn = EjbJarProject.this.getName(); - synchronized (pcs) { - cachedName = new WeakReference(dn); - } - return dn; - } - - public Icon getIcon() { - return PROJECT_ICON; - } - - public Project getProject() { - return EjbJarProject.this; - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - } - private final class ProjectXmlSavedHookImpl extends ProjectXmlSavedHook { ProjectXmlSavedHookImpl() {} diff --git a/java.api.common/apichanges.xml b/java.api.common/apichanges.xml --- a/java.api.common/apichanges.xml +++ b/java.api.common/apichanges.xml @@ -175,6 +175,22 @@ + + + Create a reusable implementation for ProjectInformation. + + + + + +

+ Created a re-usable implementation of ProjectInformation that can be + used within the Java language projects. +

+
+ + +
diff --git a/java.api.common/manifest.mf b/java.api.common/manifest.mf --- a/java.api.common/manifest.mf +++ b/java.api.common/manifest.mf @@ -1,4 +1,4 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.java.api.common/0 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/api/common/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 1.17 +OpenIDE-Module-Specification-Version: 1.18 diff --git a/java.api.common/nbproject/project.xml b/java.api.common/nbproject/project.xml --- a/java.api.common/nbproject/project.xml +++ b/java.api.common/nbproject/project.xml @@ -233,6 +233,7 @@ org.netbeans.modules.apisupport.project org.netbeans.modules.groovy.grailsproject org.netbeans.modules.hudson.ant + org.netbeans.modules.j2ee.archive org.netbeans.modules.j2ee.clientproject org.netbeans.modules.j2ee.common org.netbeans.modules.j2ee.earproject diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/ant/ProjectInfoImpl.java b/java.api.common/src/org/netbeans/modules/java/api/common/ant/ProjectInfoImpl.java new file mode 100644 --- /dev/null +++ b/java.api.common/src/org/netbeans/modules/java/api/common/ant/ProjectInfoImpl.java @@ -0,0 +1,209 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 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]" + * + * 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. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ +package org.netbeans.modules.java.api.common.ant; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import javax.swing.Icon; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectInformation; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.spi.project.support.ant.AntProjectEvent; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.AntProjectListener; +import org.netbeans.spi.project.support.ant.PropertyUtils; +import org.openide.util.Mutex; +import org.openide.util.WeakListeners; +import org.openide.xml.XMLUtil; +import org.w3c.dom.Element; + +/** + * Default implementation for Java language based projects that use Ant as their + * build tool. + */ +public class ProjectInfoImpl implements ProjectInformation, AntProjectListener { + + private static final String ELEMENT_NAME = "name"; // NOI18N + private final Object guard = new Object(); // guard for property changes + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + private final Project project; + private final AntProjectHelper projectHelper; + private final String elementName; + private final Icon icon; + private String name; + private String displayName; + + /** + * Create an instance with all items that will not change during the lifetime + * of the project. + * + * @param project project that we hold information for + * @param projectHelper class to read/update the project configuration + * @param configurationNameSpace the specific name space that this project type uses + * @param icon project icon + * @param elementName configuration element name + */ + public ProjectInfoImpl(Project project, AntProjectHelper projectHelper, Icon icon, String elementName) { + this.project = project; + this.projectHelper = projectHelper; + this.icon = icon; + this.elementName = elementName; + + + projectHelper.addAntProjectListener((AntProjectListener) WeakListeners.create(AntProjectListener.class, this, projectHelper)); + } + + /** + * Create an instance with all items that will not change during the lifetime + * of the project. + * + * Uses the default configuration element name 'name'. + * + * @param project project that we hold information for + * @param projectHelper class to read/update the project configuration + * @param configurationNameSpace the specific name space that this project type uses + * @param icon project icon + */ + public ProjectInfoImpl(Project project, AntProjectHelper projectHelper, Icon icon) { + this(project, projectHelper, icon, ELEMENT_NAME); + } + + @Override + public String getName() { + synchronized (guard) { + if (name == null) { + name = PropertyUtils.getUsablePropertyName(getDisplayName()); + } + return name; + } + } + + @Override + public String getDisplayName() { + synchronized (guard) { + if (displayName == null) { + displayName = getElementTextFromConfiguration(elementName); + } + + return displayName; + } + } + + @Override + public Icon getIcon() { + return icon; + } + + @Override + public Project getProject() { + return project; + } + + /** + * Get the text from the named element of the primary configuration node. + * + * @param elementName name of the element that contains the property value + * @return the property value, or '???' if not found + */ + protected String getElementTextFromConfiguration(final String elementName) { + String elementText = ProjectManager.mutex().readAccess(new Mutex.Action() { + + @Override + public String run() { + Element data = projectHelper.getPrimaryConfigurationData(true, false); + Element element = XMLUtil.findElement(data, elementName, null); + + return (element != null) ? XMLUtil.findText(element) : "???"; // NOI18N + } + }); + + return elementText; + } + + /** + * Notify all listeners of the property change passing the old and new values. + * + * @param prop property name + * @param oldValue old value of the property + * @param newValue new value of the property + */ + protected void firePropertyChange(String prop, Object oldValue, Object newValue) { + pcs.firePropertyChange(prop, oldValue, newValue); + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + pcs.addPropertyChangeListener(listener); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + pcs.removePropertyChangeListener(listener); + } + + @Override + public void configurationXmlChanged(AntProjectEvent ev) { + // only interested in changes to nbproject/project.xml + if (AntProjectHelper.PROJECT_XML_PATH.equals(ev.getPath())) { + // Could be various kinds of changes, but name & displayName might have changed. + String oldName; + String oldDisplayName; + String newName; + String newDisplayName; + + synchronized (guard) { + oldName = name; + oldDisplayName = displayName; + // reset so they are re-read + name = null; + displayName = null; + newName = getName(); + newDisplayName = getDisplayName(); + } + + firePropertyChange(ProjectInformation.PROP_NAME, oldName, newName); + firePropertyChange(ProjectInformation.PROP_DISPLAY_NAME, oldDisplayName, newDisplayName); + } + } + + @Override + public void propertiesChanged(AntProjectEvent ev) { + // not interested in any properties + } +} diff --git a/java.j2seproject/nbproject/project.xml b/java.j2seproject/nbproject/project.xml --- a/java.j2seproject/nbproject/project.xml +++ b/java.j2seproject/nbproject/project.xml @@ -131,7 +131,7 @@ 0-1 - 1.15 + 1.18
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 @@ -43,7 +43,6 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; import java.io.File; import java.io.IOException; import java.lang.ref.Reference; @@ -71,13 +70,13 @@ import org.netbeans.api.java.classpath.GlobalPathRegistry; import org.netbeans.api.java.project.JavaProjectConstants; 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.api.queries.FileBuiltQuery.Status; import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.modules.java.api.common.ant.ProjectInfoImpl; 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.ClassPathModifier; @@ -97,9 +96,7 @@ import org.netbeans.spi.project.support.LookupProviderSupport; import org.netbeans.spi.project.ant.AntBuildExtenderImplementation; import org.netbeans.spi.project.support.ant.AntBasedProjectRegistration; -import org.netbeans.spi.project.support.ant.AntProjectEvent; import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.AntProjectListener; import org.netbeans.spi.project.support.ant.EditableProperties; import org.netbeans.spi.project.support.ant.FilterPropertyProvider; import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; @@ -130,7 +127,6 @@ import org.openide.util.lookup.Lookups; import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.w3c.dom.Text; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -146,7 +142,7 @@ privateName=J2SEProjectType.PRIVATE_CONFIGURATION_NAME, privateNamespace= J2SEProjectType.PRIVATE_CONFIGURATION_NAMESPACE ) -public final class J2SEProject implements Project, AntProjectListener { +public final class J2SEProject implements Project { private static final Icon J2SE_PROJECT_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/java/j2seproject/ui/resources/j2seProject.png", false); // NOI18N private static final Logger LOG = Logger.getLogger(J2SEProject.class.getName()); @@ -194,7 +190,6 @@ final J2SEActionProvider actionProvider = new J2SEActionProvider( this, this.updateHelper ); lookup = createLookup(aux, actionProvider); actionProvider.startFSListener(); - helper.addAntProjectListener(this); } private ClassPathModifier.Callback createClassPathModifierCallback() { @@ -319,7 +314,7 @@ J2SESources srcs = new J2SESources(this, helper, eval, getSourceRoots(), getTestSourceRoots()); final Lookup base = Lookups.fixed( J2SEProject.this, - new Info(), + new ProjectInfoImpl(this, helper, J2SE_PROJECT_ICON), aux, helper.createCacheDirectoryProvider(), helper.createAuxiliaryProperties(), @@ -372,19 +367,6 @@ return this.cpMod; } - public void configurationXmlChanged(AntProjectEvent ev) { - if (ev.getPath().equals(AntProjectHelper.PROJECT_XML_PATH)) { - // Could be various kinds of changes, but name & displayName might have changed. - Info info = (Info)getLookup().lookup(ProjectInformation.class); - info.firePropertyChange(ProjectInformation.PROP_NAME); - info.firePropertyChange(ProjectInformation.PROP_DISPLAY_NAME); - } - } - - public void propertiesChanged(AntProjectEvent ev) { - // currently ignored (probably better to listen to evaluator() if you need to) - } - // Package private methods ------------------------------------------------- /** @@ -452,73 +434,6 @@ } // Private innerclasses ---------------------------------------------------- - //when #110886 gets implemented, this class is obsolete - private final class Info implements ProjectInformation { - - private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - private WeakReference cachedName = null; - - Info() {} - - void firePropertyChange(String prop) { - pcs.firePropertyChange(prop, null, null); - synchronized (pcs) { - cachedName = null; - } - } - - public String getName() { - return PropertyUtils.getUsablePropertyName(getDisplayName()); - } - - public String getDisplayName() { - synchronized (pcs) { - if (cachedName != null) { - String dn = cachedName.get(); - if (dn != null) { - return dn; - } - } - } - String dn = ProjectManager.mutex().readAccess(new Mutex.Action() { - public String run() { - Element data = updateHelper.getPrimaryConfigurationData(true); - // XXX replace by XMLUtil when that has findElement, findText, etc. - NodeList nl = data.getElementsByTagNameNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); // NOI18N - if (nl.getLength() == 1) { - nl = nl.item(0).getChildNodes(); - if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) { - String val = ((Text) nl.item(0)).getNodeValue(); - return val != null ? val : "???"; //NOI18N - } - } - return "???"; // NOI18N - } - }); - synchronized (pcs) { - cachedName = new WeakReference(dn); - } - return dn; - } - - public Icon getIcon() { - return J2SE_PROJECT_ICON; - } - - public Project getProject() { - return J2SEProject.this; - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - } - private final class ProjectXmlSavedHookImpl extends ProjectXmlSavedHook { ProjectXmlSavedHookImpl() {} diff --git a/project.ant/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java b/project.ant/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java --- a/project.ant/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java +++ b/project.ant/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java @@ -772,10 +772,33 @@ * @return the configuration data that is available */ public Element getPrimaryConfigurationData(final boolean shared) { + return getPrimaryConfigurationData(shared, true); + } + + /** + * Get the primary configuration data for this project. + * The returned element will be named according to + * {@link AntBasedProjectType#getPrimaryConfigurationDataElementName} and + * {@link AntBasedProjectType#getPrimaryConfigurationDataElementNamespace}. + * The project may read this document fragment to get custom information + * from nbproject/project.xml and nbproject/private/private.xml. + * The fragment will have no parent node and while it may be modified, you must + * use {@link #putPrimaryConfigurationData} to store any changes. + * @param shared if true, refers to project.xml, else refers to + * private.xml + * @param useNamespace use the name space when looking for the node + * @return the configuration data that is available + */ + public Element getPrimaryConfigurationData(final boolean shared, final boolean useNamespace) { final String name = type.getPrimaryConfigurationDataElementName(shared); assert name.indexOf(':') == -1; - final String namespace = type.getPrimaryConfigurationDataElementNamespace(shared); - assert namespace != null && namespace.length() > 0; + final String namespace; + if (useNamespace) { + namespace = type.getPrimaryConfigurationDataElementNamespace(shared); + assert namespace != null && namespace.length() > 0; + } else { + namespace = null; + } return ProjectManager.mutex().readAccess(new Mutex.Action() { public Element run() { synchronized (modifiedMetadataPaths) { @@ -790,7 +813,7 @@ } }); } - + /** * Store the primary configuration data for this project. * The supplied element must be named according to