# HG changeset patch # User Jesse Glick # Date 1313443416 14400 #196455: provide better deprecation path for ProjectClassPathExtender. diff --git a/j2ee.api.ejbmodule/nbproject/project.xml b/j2ee.api.ejbmodule/nbproject/project.xml --- a/j2ee.api.ejbmodule/nbproject/project.xml +++ b/j2ee.api.ejbmodule/nbproject/project.xml @@ -116,6 +116,7 @@ 1 + 1.10 diff --git a/j2ee.api.ejbmodule/src/org/netbeans/modules/j2ee/spi/ejbjar/support/EjbEnterpriseReferenceContainerSupport.java b/j2ee.api.ejbmodule/src/org/netbeans/modules/j2ee/spi/ejbjar/support/EjbEnterpriseReferenceContainerSupport.java --- a/j2ee.api.ejbmodule/src/org/netbeans/modules/j2ee/spi/ejbjar/support/EjbEnterpriseReferenceContainerSupport.java +++ b/j2ee.api.ejbmodule/src/org/netbeans/modules/j2ee/spi/ejbjar/support/EjbEnterpriseReferenceContainerSupport.java @@ -45,12 +45,15 @@ package org.netbeans.modules.j2ee.spi.ejbjar.support; import java.io.IOException; +import java.net.URI; import java.util.HashSet; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.api.j2ee.core.Profile; +import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.project.JavaProjectConstants; +import org.netbeans.api.java.project.classpath.ProjectClassPathModifier; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; @@ -71,7 +74,6 @@ import org.netbeans.modules.j2ee.dd.api.ejb.EjbJarMetadata; import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel; import org.netbeans.modules.j2ee.metadata.model.api.MetadataModelAction; -import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; import org.openide.filesystems.FileObject; @@ -113,7 +115,7 @@ return addReference(ref, refType, ejbRefName, true, referencingFile, referencingClass); } - private String addReference(final EjbReference ejbReference, final EjbReference.EjbRefIType refType, final String ejbRefName, final boolean local, FileObject referencingFile, + private String addReference(final EjbReference ejbReference, final EjbReference.EjbRefIType refType, final String ejbRefName, final boolean local, final FileObject referencingFile, final String referencingClass) throws IOException { final org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbModule = findEjbModule(referencingFile); @@ -181,9 +183,7 @@ if(!fromSameProject) { try { - ProjectClassPathExtender pcpe = ejbProject.getLookup().lookup(ProjectClassPathExtender.class); - assert pcpe != null; - pcpe.addAntArtifact(moduleJarTarget, moduleJarTarget.getArtifactLocations()[0]); + ProjectClassPathModifier.addAntArtifacts(new AntArtifact[] {moduleJarTarget}, new URI[] {moduleJarTarget.getArtifactLocations()[0]}, referencingFile, ClassPath.COMPILE); } catch (IOException ioe) { Exceptions.printStackTrace(ioe); } 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 @@ -226,7 +226,7 @@ 1 - 1.37 + 1.41 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 @@ -49,6 +49,7 @@ import java.io.File; import java.io.IOException; import java.net.URI; +import java.net.URL; import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -56,11 +57,11 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.Icon; -import javax.swing.JButton; import org.netbeans.api.j2ee.core.Profile; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.classpath.GlobalPathRegistry; import org.netbeans.api.java.project.JavaProjectConstants; +import org.netbeans.api.java.project.classpath.ProjectClassPathModifier; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.ProjectUtils; @@ -77,7 +78,6 @@ import org.netbeans.modules.j2ee.clientproject.wsclient.AppClientProjectWebServicesSupportProvider; import org.netbeans.modules.j2ee.common.SharabilityUtility; import org.netbeans.modules.j2ee.common.Util; -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.ClassPathSupport; import org.netbeans.modules.java.api.common.classpath.ClassPathProviderImpl; @@ -122,8 +122,6 @@ import org.netbeans.spi.project.ui.RecommendedTemplates; import org.netbeans.spi.project.ui.support.UILookupMergerSupport; import org.netbeans.spi.queries.FileEncodingQueryImplementation; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; import org.openide.filesystems.FileAttributeEvent; import org.openide.filesystems.FileChangeListener; import org.openide.filesystems.FileEvent; @@ -137,7 +135,6 @@ import org.openide.util.ImageUtilities; import org.openide.util.Lookup; 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.NodeList; @@ -178,7 +175,6 @@ private final Car apiJar; private JarContainerImpl enterpriseResourceSupport; private FileObject libFolder; - private final ClassPathExtender classPathExtender; private final ClassPathModifier cpMod; private final ClassPathProviderImpl cpProvider; private ClassPathUiSupport.Callback classPathUiSupportCallback; @@ -224,7 +220,6 @@ cpMod = new ClassPathModifier(this, this.updateHelper, eval, refHelper, new ClassPathSupportCallbackImpl(helper), createClassPathModifierCallback(), getClassPathUiSupportCallback()); - classPathExtender = new ClassPathExtender(cpMod, ProjectProperties.JAVAC_CLASSPATH, ClassPathSupportCallbackImpl.ELEMENT_INCLUDED_LIBRARIES); lookup = createLookup(aux, cpProvider); } @@ -339,7 +334,7 @@ encodingQuery, QuerySupport.createTemplateAttributesProvider(helper, encodingQuery), new RecommendedTemplatesImpl(this.updateHelper), - classPathExtender, + ProjectClassPathModifier.extenderForModifier(cpMod), cpMod, libMod, buildExtender, @@ -457,7 +452,7 @@ if (fo.getParent ().equals (libFolder)) { try { - classPathExtender.addArchiveFile(fo); + cpMod.addRoots(new URL[] {FileUtil.getArchiveRoot(fo.getURL())}, ProjectProperties.JAVAC_CLASSPATH); } catch (IOException e) { Exceptions.printStackTrace(e); } @@ -585,15 +580,13 @@ if (libFolderName != null && helper.resolveFile (libFolderName).isDirectory ()) { libFolder = helper.resolveFileObject(libFolderName); FileObject children [] = libFolder.getChildren (); - List libs = new LinkedList(); + List libs = new LinkedList(); for (int i = 0; i < children.length; i++) { if (FileUtil.isArchiveFile(children[i])) { - libs.add(children[i]); + libs.add(FileUtil.getArchiveRoot(children[i].getURL())); } } - FileObject[] libsArray = new FileObject[libs.size()]; - libs.toArray(libsArray); - classPathExtender.addArchiveFiles(ProjectProperties.JAVAC_CLASSPATH, libsArray, ClassPathSupportCallbackImpl.ELEMENT_INCLUDED_LIBRARIES); + cpMod.addRoots(libs.toArray(new URL[libs.size()]), ProjectProperties.JAVAC_CLASSPATH); libFolder.addFileChangeListener (AppClientProject.this); } diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/JarContainerImpl.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/JarContainerImpl.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/JarContainerImpl.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/JarContainerImpl.java @@ -46,11 +46,12 @@ import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.net.URI; import javax.lang.model.element.TypeElement; import org.netbeans.api.j2ee.core.Profile; +import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.project.JavaProjectConstants; +import org.netbeans.api.java.project.classpath.ProjectClassPathModifier; import org.netbeans.api.java.source.CompilationController; import org.netbeans.api.java.source.JavaSource; import org.netbeans.api.project.FileOwnerQuery; @@ -72,7 +73,6 @@ import org.netbeans.modules.j2ee.dd.api.common.MessageDestinationRef; import org.netbeans.modules.j2ee.dd.api.common.ResourceRef; import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException; -import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; import org.netbeans.spi.project.support.ant.ReferenceHelper; @@ -255,16 +255,11 @@ getAppClient().addEjbRef(newRef); } catch (ClassNotFoundException ex){} - ProjectClassPathExtender cpExtender = webProject.getLookup().lookup(ProjectClassPathExtender.class); - if (cpExtender != null) { - try { - AntArtifact target = getAntArtifact(ejbReference, refType); - cpExtender.addAntArtifact(target, target.getArtifactLocations()[0].normalize()); - } catch (IOException ioe) { - Exceptions.printStackTrace(ioe); - } - } else { - Logger.getLogger("global").log(Level.INFO, "WebProjectClassPathExtender not found in the project lookup of project: " + webProject.getProjectDirectory().getPath()); //NOI18N + try { + AntArtifact target = getAntArtifact(ejbReference, refType); + ProjectClassPathModifier.addAntArtifacts(new AntArtifact[] {target}, new URI[] {target.getArtifactLocations()[0].normalize()}, referencingFile, ClassPath.COMPILE); + } catch (IOException ioe) { + Exceptions.printStackTrace(ioe); } writeDD(referencingFile, referencingClass); 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 @@ -263,7 +263,7 @@ 1 - 1.37 + 1.41 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 @@ -52,6 +52,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -86,7 +87,6 @@ import org.netbeans.modules.j2ee.common.SharabilityUtility; import org.netbeans.modules.j2ee.common.Util; import org.netbeans.modules.j2ee.common.project.ArtifactCopyOnSaveSupport; -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.ClassPathSupport; import org.netbeans.modules.java.api.common.classpath.ClassPathProviderImpl; @@ -127,6 +127,7 @@ 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.java.project.classpath.ProjectClassPathModifier; import org.netbeans.api.project.ProjectUtils; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule.Type; import org.netbeans.modules.j2ee.deployment.devmodules.spi.ArtifactListener; @@ -205,7 +206,6 @@ private EjbProjectJAXWSClientSupport jaxWsClientSupport; private SourceRoots sourceRoots; private SourceRoots testRoots; - private final ClassPathExtender classPathExtender; private final ClassPathModifier classPathModifier; private PropertyChangeListener j2eePlatformListener; private AntBuildExtender buildExtender; @@ -308,7 +308,6 @@ classPathModifier = new ClassPathModifier(this, this.updateHelper, eval, refHelper, new ClassPathSupportCallbackImpl(helper), createClassPathModifierCallback(), getClassPathUiSupportCallback()); - classPathExtender = new ClassPathExtender(classPathModifier, ProjectProperties.JAVAC_CLASSPATH, ClassPathSupportCallbackImpl.ELEMENT_INCLUDED_LIBRARIES); lookup = createLookup(aux, cpProvider); css = new CopyOnSaveSupport(); artifactSupport = new ArtifactCopySupport(); @@ -448,7 +447,7 @@ encodingQuery, new RecommendedTemplatesImpl(updateHelper), refHelper, - classPathExtender, + ProjectClassPathModifier.extenderForModifier(classPathModifier), classPathModifier, new EjbJarProjectOperations(this), new EjbJarPersistenceProvider(this, evaluator(), cpProvider), @@ -691,7 +690,7 @@ if (fo.getParent ().equals (libFolder)) { try { - classPathExtender.addArchiveFile(fo); + classPathModifier.addRoots(new URL[] {FileUtil.getArchiveRoot(fo.getURL())}, ProjectProperties.JAVAC_CLASSPATH); } catch (IOException e) { Exceptions.printStackTrace(e); @@ -770,15 +769,15 @@ if (libFolderName != null && helper.resolveFile (libFolderName).isDirectory ()) { libFolder = helper.resolveFileObject(libFolderName); FileObject[] children = libFolder.getChildren (); - List libs = new LinkedList(); + List libs = new LinkedList(); for (int i = 0; i < children.length; i++) { if (FileUtil.isArchiveFile(children[i])) { - libs.add(children[i]); + libs.add(FileUtil.getArchiveRoot(children[i].getURL())); } } FileObject[] libsArray = new FileObject[libs.size()]; libs.toArray(libsArray); - classPathExtender.addArchiveFiles(ProjectProperties.JAVAC_CLASSPATH, libsArray, ClassPathSupportCallbackImpl.ELEMENT_INCLUDED_LIBRARIES); + classPathModifier.addRoots(libs.toArray(new URL[libs.size()]), ProjectProperties.JAVAC_CLASSPATH); libFolder.addFileChangeListener (EjbJarProject.this); } 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 @@ -159,7 +159,7 @@ 1 - 1.37 + 1.41 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 @@ -75,6 +75,7 @@ import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.classpath.GlobalPathRegistry; import org.netbeans.api.java.project.JavaProjectConstants; +import org.netbeans.api.java.project.classpath.ProjectClassPathModifier; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.SourceGroup; @@ -341,8 +342,6 @@ private Lookup createLookup(final AuxiliaryConfiguration aux, final J2SEActionProvider actionProvider) { FileEncodingQueryImplementation encodingQuery = QuerySupport.createFileEncodingQuery(evaluator(), J2SEProjectProperties.SOURCE_ENCODING); - @SuppressWarnings("deprecation") Object cpe = new org.netbeans.modules.java.api.common.classpath.ClassPathExtender( - cpMod, ProjectProperties.JAVAC_CLASSPATH, null); final Lookup base = Lookups.fixed( J2SEProject.this, QuerySupport.createProjectInformation(updateHelper, this, J2SE_PROJECT_ICON), @@ -366,7 +365,7 @@ QuerySupport.createSharabilityQuery(helper, evaluator(), getSourceRoots(), getTestSourceRoots()), new CoSAwareFileBuiltQueryImpl(QuerySupport.createFileBuiltQuery(helper, evaluator(), getSourceRoots(), getTestSourceRoots()), this), new RecommendedTemplatesImpl (this.updateHelper), - cpe, + ProjectClassPathModifier.extenderForModifier(cpMod), buildExtender, cpMod, new J2SEProjectOperations(this, actionProvider), diff --git a/java.project/apichanges.xml b/java.project/apichanges.xml --- a/java.project/apichanges.xml +++ b/java.project/apichanges.xml @@ -109,6 +109,27 @@ + + + Added ProjectClassPathModifier.extenderForModifier + + + + +

+ Any modules still implementing ProjectClassPathExtender should cease to do so. +

+
+ +

+ Added a bridge from an old SPI to the newer, preferred SPI. + Also added LookupMergerSupport.createClassPathModifierMerger. +

+
+ + + +
Added JavaTemplates.JAVA_ICON diff --git a/java.project/manifest.mf b/java.project/manifest.mf --- a/java.project/manifest.mf +++ b/java.project/manifest.mf @@ -3,7 +3,7 @@ OpenIDE-Module-Layer: org/netbeans/modules/java/project/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/project/Bundle.properties OpenIDE-Module-Needs: javax.script.ScriptEngine.freemarker -OpenIDE-Module-Specification-Version: 1.40 +OpenIDE-Module-Specification-Version: 1.41 OpenIDE-Module-Recommends: org.netbeans.spi.java.project.runner.JavaRunnerImplementation AutoUpdate-Show-In-Client: false diff --git a/java.project/src/org/netbeans/api/java/project/classpath/ProjectClassPathModifier.java b/java.project/src/org/netbeans/api/java/project/classpath/ProjectClassPathModifier.java --- a/java.project/src/org/netbeans/api/java/project/classpath/ProjectClassPathModifier.java +++ b/java.project/src/org/netbeans/api/java/project/classpath/ProjectClassPathModifier.java @@ -56,6 +56,7 @@ import org.netbeans.api.project.libraries.Library; import org.netbeans.modules.java.project.classpath.ProjectClassPathModifierAccessor; import org.netbeans.spi.java.project.classpath.ProjectClassPathModifierImplementation; +import org.netbeans.spi.java.project.support.LookupMergerSupport; import org.netbeans.spi.project.libraries.support.LibrariesSupport; import org.netbeans.spi.project.support.ant.PropertyUtils; import org.openide.filesystems.FileObject; @@ -455,4 +456,98 @@ } + /** + * Translates the new SPI into an instance of the old SPI. + * Useful to place in project lookup so that you need not bother implementing the old SPI. + * (Since there was not previously a matching API, old clients may directly look for the old SPI + * interface in a project's lookup.) + * Corresponding methods are called using the first reported source group (if any) and extensible classpath type (if any). + * @param pcpmi the new SPI + * @return a proxy fitting the old SPI + * @see #extenderForModifier(Project) + * @since 1.41 + */ + @SuppressWarnings("deprecation") // XXX seems ineffective against return type + public static org.netbeans.spi.java.project.classpath.ProjectClassPathExtender extenderForModifier(final ProjectClassPathModifierImplementation pcpmi) { + return new org.netbeans.spi.java.project.classpath.ProjectClassPathExtender() { + @Override public boolean addLibrary(Library library) throws IOException { + SourceGroup[] sgs = ProjectClassPathModifierAccessor.INSTANCE.getExtensibleSourceGroups(pcpmi); + if (sgs.length == 0) { + return false; + } + String[] types = ProjectClassPathModifierAccessor.INSTANCE.getExtensibleClassPathTypes(pcpmi, sgs[0]); + if (types.length == 0) { + return false; + } + try { + return ProjectClassPathModifierAccessor.INSTANCE.addLibraries(new Library[] {library}, pcpmi, sgs[0], types[0]); + } catch (UnsupportedOperationException x) { + return false; + } + } + @Override public boolean addArchiveFile(FileObject archiveFile) throws IOException { + SourceGroup[] sgs = ProjectClassPathModifierAccessor.INSTANCE.getExtensibleSourceGroups(pcpmi); + if (sgs.length == 0) { + return false; + } + String[] types = ProjectClassPathModifierAccessor.INSTANCE.getExtensibleClassPathTypes(pcpmi, sgs[0]); + if (types.length == 0) { + return false; + } + URL r = archiveFile.getURL(); + if (FileUtil.isArchiveFile(r)) { // ought to always be true, but Javadoc is vague + r = FileUtil.getArchiveRoot(r); + } + try { + return ProjectClassPathModifierAccessor.INSTANCE.addRoots(new URL[] {r}, pcpmi, sgs[0], types[0]); + } catch (UnsupportedOperationException x) { + return false; + } + } + @Override public boolean addAntArtifact(AntArtifact artifact, URI artifactElement) throws IOException { + SourceGroup[] sgs = ProjectClassPathModifierAccessor.INSTANCE.getExtensibleSourceGroups(pcpmi); + if (sgs.length == 0) { + return false; + } + String[] types = ProjectClassPathModifierAccessor.INSTANCE.getExtensibleClassPathTypes(pcpmi, sgs[0]); + if (types.length == 0) { + return false; + } + try { + return ProjectClassPathModifierAccessor.INSTANCE.addAntArtifacts(new AntArtifact[] {artifact}, new URI[] {artifactElement}, pcpmi, sgs[0], types[0]); + } catch (UnsupportedOperationException x) { + return false; + } + } + + }; + } + + /** + * Similar to {@link #extenderForModifier(ProjectClassPathModifierImplementation)} but permits the new SPI to be created lazily. + * This is useful if the project is using {@link LookupMergerSupport#createClassPathModifierMerger} and it is thus impossible to get the final SPI instance + * during construction of the project's lookup. + * The new SPI is located at runtime on each call; if not present, false is returned from all methods. + * @param p a project whose lookup may contain a {@link ProjectClassPathModifierImplementation} + * @return an SPI equivalent + * @since 1.41 + */ + @SuppressWarnings("deprecation") + public static org.netbeans.spi.java.project.classpath.ProjectClassPathExtender extenderForModifier(final Project p) { + return new org.netbeans.spi.java.project.classpath.ProjectClassPathExtender() { + @Override public boolean addLibrary(Library library) throws IOException { + ProjectClassPathModifierImplementation pcpmi = p.getLookup().lookup(ProjectClassPathModifierImplementation.class); + return pcpmi != null ? extenderForModifier(pcpmi).addLibrary(library) : false; + } + @Override public boolean addArchiveFile(FileObject archiveFile) throws IOException { + ProjectClassPathModifierImplementation pcpmi = p.getLookup().lookup(ProjectClassPathModifierImplementation.class); + return pcpmi != null ? extenderForModifier(pcpmi).addArchiveFile(archiveFile) : false; + } + @Override public boolean addAntArtifact(AntArtifact artifact, URI artifactElement) throws IOException { + ProjectClassPathModifierImplementation pcpmi = p.getLookup().lookup(ProjectClassPathModifierImplementation.class); + return pcpmi != null ? extenderForModifier(pcpmi).addAntArtifact(artifact, artifactElement) : false; + } + }; + } + } diff --git a/java.project/src/org/netbeans/modules/java/project/classpath/ClassPathModifierLookupMerger.java b/java.project/src/org/netbeans/modules/java/project/classpath/ClassPathModifierLookupMerger.java new file mode 100644 --- /dev/null +++ b/java.project/src/org/netbeans/modules/java/project/classpath/ClassPathModifierLookupMerger.java @@ -0,0 +1,194 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.project.classpath; + +import java.io.IOException; +import java.net.URI; +import java.net.URL; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.SourceGroup; +import org.netbeans.api.project.ant.AntArtifact; +import org.netbeans.api.project.libraries.Library; +import org.netbeans.spi.java.project.classpath.ProjectClassPathModifierImplementation; +import org.netbeans.spi.project.LookupMerger; +import org.openide.util.Lookup; + +public class ClassPathModifierLookupMerger implements LookupMerger{ + + @Override public Class getMergeableClass() { + return ProjectClassPathModifierImplementation.class; + } + + @Override public ProjectClassPathModifierImplementation merge(Lookup lookup) { + return new Modifier(lookup); + } + + private static class Modifier extends ProjectClassPathModifierImplementation { + + private final Lookup context; + + private Modifier(Lookup context) { + this.context = context; + } + + @Override protected SourceGroup[] getExtensibleSourceGroups() { + Collection sgs = new LinkedHashSet(); + for (ProjectClassPathModifierImplementation impl : context.lookupAll(ProjectClassPathModifierImplementation.class)) { + sgs.addAll(Arrays.asList(ProjectClassPathModifierAccessor.INSTANCE.getExtensibleSourceGroups(impl))); + } + return sgs.toArray(new SourceGroup[sgs.size()]); + } + + @Override protected String[] getExtensibleClassPathTypes(SourceGroup sourceGroup) { + Collection types = new LinkedHashSet(); + for (ProjectClassPathModifierImplementation impl : context.lookupAll(ProjectClassPathModifierImplementation.class)) { + types.addAll(Arrays.asList(ProjectClassPathModifierAccessor.INSTANCE.getExtensibleClassPathTypes(impl, sourceGroup))); + } + return types.toArray(new String[types.size()]); + } + + private interface Op { + boolean run(ProjectClassPathModifierImplementation impl) throws IOException, UnsupportedOperationException; + } + + private boolean run(Op op) throws IOException, UnsupportedOperationException { + boolean completedNormally = false; + UnsupportedOperationException uoe = null; + for (ProjectClassPathModifierImplementation impl : context.lookupAll(ProjectClassPathModifierImplementation.class)) { + try { + if (op.run(impl)) { + return true; + } else { + completedNormally = true; + } + } catch (UnsupportedOperationException x) { + uoe = x; + } + } + if (uoe != null && !completedNormally) { + throw uoe; + } else { + return false; + } + } + + // closures would be handy here... + + @Override protected boolean addLibraries(final Library[] libraries, final SourceGroup sourceGroup, final String type) throws IOException, UnsupportedOperationException { + return run(new Op() { + @Override public boolean run(ProjectClassPathModifierImplementation impl) throws IOException, UnsupportedOperationException { + return ProjectClassPathModifierAccessor.INSTANCE.addLibraries(libraries, impl, sourceGroup, type); + } + }); + } + + @Override protected boolean removeLibraries(final Library[] libraries, final SourceGroup sourceGroup, final String type) throws IOException, UnsupportedOperationException { + return run(new Op() { + @Override public boolean run(ProjectClassPathModifierImplementation impl) throws IOException, UnsupportedOperationException { + return ProjectClassPathModifierAccessor.INSTANCE.removeLibraries(libraries, impl, sourceGroup, type); + } + }); + } + + @Override protected boolean addRoots(final URL[] classPathRoots, final SourceGroup sourceGroup, final String type) throws IOException, UnsupportedOperationException { + return run(new Op() { + @Override public boolean run(ProjectClassPathModifierImplementation impl) throws IOException, UnsupportedOperationException { + return ProjectClassPathModifierAccessor.INSTANCE.addRoots(classPathRoots, impl, sourceGroup, type); + } + }); + } + + @Override protected boolean removeRoots(final URL[] classPathRoots, final SourceGroup sourceGroup, final String type) throws IOException, UnsupportedOperationException { + return run(new Op() { + @Override public boolean run(ProjectClassPathModifierImplementation impl) throws IOException, UnsupportedOperationException { + return ProjectClassPathModifierAccessor.INSTANCE.removeRoots(classPathRoots, impl, sourceGroup, type); + } + }); + } + + @Override protected boolean addRoots(final URI[] classPathRoots, final SourceGroup sourceGroup, final String type) throws IOException, UnsupportedOperationException { + return run(new Op() { + @Override public boolean run(ProjectClassPathModifierImplementation impl) throws IOException, UnsupportedOperationException { + return ProjectClassPathModifierAccessor.INSTANCE.addRoots(classPathRoots, impl, sourceGroup, type); + } + }); + } + + @Override protected boolean removeRoots(final URI[] classPathRoots, final SourceGroup sourceGroup, final String type) throws IOException, UnsupportedOperationException { + return run(new Op() { + @Override public boolean run(ProjectClassPathModifierImplementation impl) throws IOException, UnsupportedOperationException { + return ProjectClassPathModifierAccessor.INSTANCE.removeRoots(classPathRoots, impl, sourceGroup, type); + } + }); + } + + @Override protected boolean addAntArtifacts(final AntArtifact[] artifacts, final URI[] artifactElements, final SourceGroup sourceGroup, final String type) throws IOException, UnsupportedOperationException { + return run(new Op() { + @Override public boolean run(ProjectClassPathModifierImplementation impl) throws IOException, UnsupportedOperationException { + return ProjectClassPathModifierAccessor.INSTANCE.addAntArtifacts(artifacts, artifactElements, impl, sourceGroup, type); + } + }); + } + + @Override protected boolean removeAntArtifacts(final AntArtifact[] artifacts, final URI[] artifactElements, final SourceGroup sourceGroup, final String type) throws IOException, UnsupportedOperationException { + return run(new Op() { + @Override public boolean run(ProjectClassPathModifierImplementation impl) throws IOException, UnsupportedOperationException { + return ProjectClassPathModifierAccessor.INSTANCE.removeAntArtifacts(artifacts, artifactElements, impl, sourceGroup, type); + } + }); + } + + @Override protected boolean addProjects(final Project[] projects, final SourceGroup sourceGroup, final String type) throws IOException, UnsupportedOperationException { + return run(new Op() { + @Override public boolean run(ProjectClassPathModifierImplementation impl) throws IOException, UnsupportedOperationException { + return ProjectClassPathModifierAccessor.INSTANCE.addProjects(projects, impl, sourceGroup, type); + } + }); + } + + } + +} diff --git a/java.project/src/org/netbeans/spi/java/project/classpath/ProjectClassPathExtender.java b/java.project/src/org/netbeans/spi/java/project/classpath/ProjectClassPathExtender.java --- a/java.project/src/org/netbeans/spi/java/project/classpath/ProjectClassPathExtender.java +++ b/java.project/src/org/netbeans/spi/java/project/classpath/ProjectClassPathExtender.java @@ -46,6 +46,7 @@ import java.io.IOException; import java.net.URI; +import java.net.URL; import org.netbeans.api.java.project.classpath.ProjectClassPathModifier; import org.netbeans.api.project.ant.AntArtifact; import org.netbeans.api.project.libraries.Library; @@ -57,7 +58,8 @@ * allow clients to extend its compilation classpath * by a new classpath element (JAR, folder, dependent project, or library). * @since org.netbeans.modules.java.project/1 1.3 - * @deprecated Please use {@link ProjectClassPathModifier} instead. + * @deprecated As a caller, use {@link ProjectClassPathModifier} instead. + * As an implementor, use {@link ProjectClassPathModifier#extenderForModifier}. */ @Deprecated public interface ProjectClassPathExtender { @@ -68,7 +70,7 @@ * @param library to be added * @return true in case the classpath was changed * @exception IOException in case the project metadata cannot be changed - * @deprecated Please use {@link ProjectClassPathModifier#addLibrary} instead. + * @deprecated Please use {@link ProjectClassPathModifier#addLibraries} instead. */ @Deprecated boolean addLibrary(Library library) throws IOException; @@ -79,7 +81,7 @@ * @param archiveFile ZIP/JAR file to be added * @return true in case the classpath was changed * @exception IOException in case the project metadata cannot be changed - * @deprecated Please use {@link ProjectClassPathModifier#addArchive} instead. + * @deprecated Please use {@link ProjectClassPathModifier#addRoots(URL[], FileObject, String)} instead. */ @Deprecated boolean addArchiveFile(FileObject archiveFile) throws IOException; @@ -92,7 +94,7 @@ * (must be owned by the artifact and be relative to it) * @return true in case the classpath was changed * @exception IOException in case the project metadata cannot be changed - * @deprecated Please use {@link ProjectClassPathModifier#addAntArtifact} instead. + * @deprecated Please use {@link ProjectClassPathModifier#addAntArtifacts} instead. */ @Deprecated boolean addAntArtifact(AntArtifact artifact, URI artifactElement) throws IOException; diff --git a/java.project/src/org/netbeans/spi/java/project/classpath/ProjectClassPathModifierImplementation.java b/java.project/src/org/netbeans/spi/java/project/classpath/ProjectClassPathModifierImplementation.java --- a/java.project/src/org/netbeans/spi/java/project/classpath/ProjectClassPathModifierImplementation.java +++ b/java.project/src/org/netbeans/spi/java/project/classpath/ProjectClassPathModifierImplementation.java @@ -52,6 +52,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; +import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.project.JavaProjectConstants; import org.netbeans.api.project.Project; import org.netbeans.api.project.SourceGroup; @@ -69,7 +70,7 @@ /** * An SPI for project's classpaths modification. - * A project can provide subclass of this class in its {@link org.netbeans.api.project.Project#getLookup lookup} to + * A project can provide subclass of this class in its {@link Project#getLookup lookup} to * allow clients to add or remove new classpath elements (JAR, folder, dependent project, or library) to its * classpaths. * @since org.netbeans.modules.java.project/1 1.10 @@ -103,10 +104,10 @@ * Adds libraries into the project's classpath if the * libraries are not already included. * @param libraries to be added - * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA} + * @param sourceGroup of type {@link JavaProjectConstants#SOURCES_TYPE_JAVA} * identifying the compilation unit to change * @param type the type of the classpath the library should be added to, - * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE} + * e.g. {@link ClassPath#COMPILE} * @return true in case the classpath was changed (at least one library was added to the classpath), * the value false is returned when all the libraries are already included on the classpath. * @exception IOException in case the project metadata cannot be changed @@ -120,10 +121,10 @@ * Removes libraries from the project's classpath if the * libraries are included on it. * @param libraries to be removed - * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA} + * @param sourceGroup of type {@link JavaProjectConstants#SOURCES_TYPE_JAVA} * identifying the compilation unit to change * @param type the type of the classpath the library should be removed from, - * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE} + * e.g. {@link ClassPath#COMPILE} * @return true in case the classpath was changed, (at least one library was removed from the classpath), * the value false is returned when none of the libraries was included on the classpath. * @exception IOException in case the project metadata cannot be changed @@ -136,10 +137,10 @@ * Adds archive files or folders into the project's classpath if the * entries are not already there. * @param classPathRoots roots to be added, each root has to be either a root of an archive or a folder - * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA} + * @param sourceGroup of type {@link JavaProjectConstants#SOURCES_TYPE_JAVA} * identifying the compilation unit to change * @param type the type of the classpath the root should be added to, - * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE} + * e.g. {@link ClassPath#COMPILE} * @return true in case the classpath was changed, (at least one classpath root was added to the classpath), * the value false is returned when all the classpath roots are already included on the classpath. * @exception IOException in case the project metadata cannot be changed @@ -156,10 +157,10 @@ * {@link #addRoots(URL[], SourceGroup, String)}. It throws UnsupportedOperationException * if URIs are not absolute. * @param classPathRoots roots to be added, each root has to be either a root of an archive or a folder; URI can be relative - * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA} + * @param sourceGroup of type {@link JavaProjectConstants#SOURCES_TYPE_JAVA} * identifying the compilation unit to change * @param type the type of the classpath the root should be added to, - * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE} + * e.g. {@link ClassPath#COMPILE} * @return true in case the classpath was changed, (at least one classpath root was added to the classpath), * the value false is returned when all the classpath roots are already included on the classpath. * @exception IOException in case the project metadata cannot be changed @@ -206,10 +207,10 @@ * Removes archive files or folders from the project's classpath if the * entries are included on it. * @param classPathRoots roots to be removed, each root has to be either a root of an archive or a folder - * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA} + * @param sourceGroup of type {@link JavaProjectConstants#SOURCES_TYPE_JAVA} * identifying the compilation unit to change * @param type the type of the classpath the root should be removed from, - * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE} + * e.g. {@link ClassPath#COMPILE} * @return true in case the classpath was changed, (at least one classpath root was removed from the classpath), * the value false is returned when none of the classpath roots was included on the classpath. * @exception IOException in case the project metadata cannot be changed @@ -226,10 +227,10 @@ * {@link #removeRoots(URL[], SourceGroup, String)}. It throws UnsupportedOperationException * if URIs are not absolute. * @param classPathRoots roots to be removed, each root has to be either a root of an archive or a folder; URI can be relative - * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA} + * @param sourceGroup of type {@link JavaProjectConstants#SOURCES_TYPE_JAVA} * identifying the compilation unit to change * @param type the type of the classpath the root should be removed from, - * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE} + * e.g. {@link ClassPath#COMPILE} * @return true in case the classpath was changed, (at least one classpath root was removed from the classpath), * the value false is returned when none of the classpath roots was included on the classpath. * @exception IOException in case the project metadata cannot be changed @@ -247,10 +248,10 @@ * @param artifactElements the URIs of the build output, the artifactElements has to have the same length * as artifacts. * (must be owned by the artifact and be relative to it) - * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA} + * @param sourceGroup of type {@link JavaProjectConstants#SOURCES_TYPE_JAVA} * identifying the compilation unit to change * @param type the type of the classpath the artifact should be added to, - * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE} + * e.g. {@link ClassPath#COMPILE} * @return true in case the classpath was changed, (at least one artifact was added to the classpath), * the value false is returned when all the artifacts are already included on the classpath. * @exception IOException in case the project metadata cannot be changed @@ -266,10 +267,10 @@ * @param artifactElements the URIs of the build output, the artifactElements has to have the same length * as artifacts. * (must be owned by the artifact and be relative to it) - * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA} + * @param sourceGroup of type {@link JavaProjectConstants#SOURCES_TYPE_JAVA} * identifying the compilation unit to change * @param type the type of the classpath the artifact should be removed from, - * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE} + * e.g. {@link ClassPath#COMPILE} * @return true in case the classpath was changed, (at least one artifact was removed from the classpath), * the value false is returned when none of the artifacts was included on the classpath. * @exception IOException in case the project metadata cannot be changed @@ -285,10 +286,10 @@ * Other project types can override the behaviour. * @param projects to be added * (must be owned by the artifact and be relative to it) - * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA} + * @param sourceGroup of type {@link JavaProjectConstants#SOURCES_TYPE_JAVA} * identifying the compilation unit to change * @param type the type of the classpath the artifact should be added to, - * eg {@link org.netbeans.api.java.classpath.ClassPath#COMPILE} + * e.g. {@link ClassPath#COMPILE} * @return true in case the classpath was changed, (at least one artifact was added to the classpath), * the value false is returned when all the artifacts are already included on the classpath. * @exception IOException in case the project metadata cannot be changed @@ -296,7 +297,7 @@ * adding of an artifact to the classpath of the given type. * @since org.netbeans.modules.java.project/1 1.24 */ - protected boolean addProjects(Project[] projects, SourceGroup sg, String classPathType) throws IOException, UnsupportedOperationException { + protected boolean addProjects(Project[] projects, SourceGroup sourceGroup, String type) throws IOException, UnsupportedOperationException { List ants = new ArrayList(); List antUris = new ArrayList(); for (Project prj : projects) { @@ -306,7 +307,7 @@ antUris.add(aa.getArtifactLocations()[0]); } } - return addAntArtifacts(ants.toArray(new AntArtifact[0]), antUris.toArray(new URI[0]), sg, classPathType); + return addAntArtifacts(ants.toArray(new AntArtifact[0]), antUris.toArray(new URI[0]), sourceGroup, type); } /** diff --git a/java.project/src/org/netbeans/spi/java/project/support/LookupMergerSupport.java b/java.project/src/org/netbeans/spi/java/project/support/LookupMergerSupport.java --- a/java.project/src/org/netbeans/spi/java/project/support/LookupMergerSupport.java +++ b/java.project/src/org/netbeans/spi/java/project/support/LookupMergerSupport.java @@ -42,6 +42,7 @@ package org.netbeans.spi.java.project.support; +import java.io.IOException; import java.net.URL; import java.util.Arrays; import java.util.Collection; @@ -54,7 +55,9 @@ import org.netbeans.api.java.queries.JavadocForBinaryQuery; import org.netbeans.api.java.queries.SourceForBinaryQuery; import org.netbeans.api.project.ProjectManager; +import org.netbeans.modules.java.project.classpath.ClassPathModifierLookupMerger; import org.netbeans.spi.java.classpath.ClassPathProvider; +import org.netbeans.spi.java.project.classpath.ProjectClassPathModifierImplementation; import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2; @@ -106,7 +109,20 @@ public static LookupMerger createClassPathProviderMerger(ClassPathProvider defaultProvider) { return new ClassPathProviderMerger(defaultProvider); } - + + /** + * Creates a merger of class path modifiers. + * All supported source groups and classpath types are unified. + * The first modifier implementation to return true (or throw {@link IOException}) is accepted. + * False is returned if all of the implementations do so. + * {@link UnsupportedOperationException} is thrown only if all of the implementations do so. + * @return a merger + * @since 1.41 + */ + public static LookupMerger createClassPathModifierMerger() { + return new ClassPathModifierLookupMerger(); + } + private static class SFBLookupMerger implements LookupMerger { public Class getMergeableClass() { diff --git a/maven.persistence/manifest.mf b/maven.persistence/manifest.mf --- a/maven.persistence/manifest.mf +++ b/maven.persistence/manifest.mf @@ -3,5 +3,5 @@ OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/maven/persistence/Bundle.properties OpenIDE-Module-Public-Packages: - AutoUpdate-Show-In-Client: false -OpenIDE-Module-Specification-Version: 1.12 +OpenIDE-Module-Specification-Version: 1.13 diff --git a/maven.persistence/nbproject/project.xml b/maven.persistence/nbproject/project.xml --- a/maven.persistence/nbproject/project.xml +++ b/maven.persistence/nbproject/project.xml @@ -91,7 +91,7 @@ 1 - 1.18 + 1.41
@@ -100,7 +100,7 @@ 2 - 2.0 + 2.19 diff --git a/maven.persistence/src/org/netbeans/modules/maven/persistence/CPExtender.java b/maven.persistence/src/org/netbeans/modules/maven/persistence/CPExtender.java --- a/maven.persistence/src/org/netbeans/modules/maven/persistence/CPExtender.java +++ b/maven.persistence/src/org/netbeans/modules/maven/persistence/CPExtender.java @@ -53,19 +53,17 @@ import org.netbeans.api.project.ant.AntArtifact; import org.netbeans.api.project.libraries.Library; import org.netbeans.modules.maven.api.ModelUtils; -import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender; import org.netbeans.spi.java.project.classpath.ProjectClassPathModifierImplementation; import org.netbeans.spi.project.ProjectServiceProvider; -import org.openide.filesystems.FileObject; import org.openide.util.Exceptions; /** * * @author mkleint */ -@ProjectServiceProvider(service={ProjectClassPathModifierImplementation.class, ProjectClassPathExtender.class}, +@ProjectServiceProvider(service=ProjectClassPathModifierImplementation.class, projectType="org-netbeans-modules-maven") -public class CPExtender extends ProjectClassPathModifierImplementation implements ProjectClassPathExtender { +public class CPExtender extends ProjectClassPathModifierImplementation { private static final String SL_15 = "1.5"; //NOI18N private Project project; /** Creates a new instance of CPExtender */ @@ -119,7 +117,7 @@ return false; } - public boolean addLibrary(Library library) throws IOException { + private boolean addLibrary(Library library) throws IOException { if ("toplink".equals(library.getName())) { //NOI18N //TODO would be nice if the toplink lib shipping with netbeans be the same binary // then we could just copy the pieces to local repo. @@ -130,6 +128,7 @@ ModelHandle handle = ModelHandleUtils.createModelHandle(project); // checking source doesn't work anymore, the wizard requires the level to be 1.5 up front. + // XXX this seems wrong; what if the source level is already 1.6 or higher? (or "5" or "6"?) ModelUtils.checkSourceLevel(handle, SL_15); ModelHandleUtils.writeModelHandle(handle, project); @@ -142,12 +141,16 @@ } return false; } - - public boolean addArchiveFile(FileObject arg0) throws IOException { + + @Override protected boolean addRoots(URI[] classPathRoots, SourceGroup sourceGroup, String type) throws IOException, UnsupportedOperationException { return false; } - - public boolean addAntArtifact(AntArtifact arg0, URI arg1) throws IOException { + + @Override protected boolean removeRoots(URI[] classPathRoots, SourceGroup sourceGroup, String type) throws IOException, UnsupportedOperationException { + return false; + } + + @Override protected boolean addProjects(Project[] projects, SourceGroup sourceGroup, String type) throws IOException, UnsupportedOperationException { return false; } diff --git a/maven/manifest.mf b/maven/manifest.mf --- a/maven/manifest.mf +++ b/maven/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.maven/2 -OpenIDE-Module-Specification-Version: 2.18 +OpenIDE-Module-Specification-Version: 2.19 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/maven/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/maven/layer.xml AutoUpdate-Show-In-Client: false diff --git a/maven/nbproject/project.xml b/maven/nbproject/project.xml --- a/maven/nbproject/project.xml +++ b/maven/nbproject/project.xml @@ -153,7 +153,7 @@ 1 - 1.25 + 1.41 diff --git a/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java b/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java --- a/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java +++ b/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java @@ -87,6 +87,7 @@ import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.java.project.JavaProjectConstants; +import org.netbeans.api.java.project.classpath.ProjectClassPathModifier; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectInformation; import org.netbeans.api.project.ProjectManager; @@ -99,8 +100,6 @@ import org.netbeans.modules.maven.api.PluginPropertyUtils; import org.netbeans.modules.maven.api.problem.ProblemReport; import org.netbeans.modules.maven.classpath.CPExtender; -import org.netbeans.modules.maven.classpath.CPExtenderLookupMerger; -import org.netbeans.modules.maven.classpath.CPModifierLookupMerger; import org.netbeans.modules.maven.classpath.ClassPathProviderImpl; import org.netbeans.modules.maven.classpath.MavenSourcesImpl; import org.netbeans.modules.maven.configurations.M2ConfigProvider; @@ -128,6 +127,7 @@ import org.netbeans.modules.maven.queries.MavenSharabilityQueryImpl; import org.netbeans.modules.maven.queries.MavenSourceLevelImpl; import org.netbeans.modules.maven.queries.MavenTestForSourceImpl; +import org.netbeans.spi.java.project.support.LookupMergerSupport; import org.netbeans.spi.project.LookupMerger; import org.netbeans.spi.project.ProjectState; import org.netbeans.spi.project.SubprojectProvider; @@ -909,8 +909,9 @@ UILookupMergerSupport.createPrivilegedTemplatesMerger(), UILookupMergerSupport.createRecommendedTemplatesMerger(), LookupProviderSupport.createSourcesMerger(), - new CPExtenderLookupMerger(extender), - new CPModifierLookupMerger(extender), + ProjectClassPathModifier.extenderForModifier(this), + extender, + LookupMergerSupport.createClassPathModifierMerger(), new BackwardCompatibilityWithMevenideChecker(), new DebuggerChecker(), new CosChecker(this), diff --git a/maven/src/org/netbeans/modules/maven/classpath/CPExtender.java b/maven/src/org/netbeans/modules/maven/classpath/CPExtender.java --- a/maven/src/org/netbeans/modules/maven/classpath/CPExtender.java +++ b/maven/src/org/netbeans/modules/maven/classpath/CPExtender.java @@ -85,8 +85,7 @@ * maven dependencies to the way classpath items are added through this api. * @author mkleint */ -@SuppressWarnings("deprecation") -public class CPExtender extends ProjectClassPathModifierImplementation implements org.netbeans.spi.java.project.classpath.ProjectClassPathExtender { +public class CPExtender extends ProjectClassPathModifierImplementation { private NbMavenProjectImpl project; private static final String POM_XML = "pom.xml"; //NOI18N @@ -105,52 +104,6 @@ this.project = project; } - public boolean addLibrary(final Library library) throws IOException { - final Boolean[] added = new Boolean[1]; - ModelOperation operation = new ModelOperation() { - public void performOperation(POMModel model) { - try { - added[0] = addRemoveLibrary(library, model, null, true); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - added[0] = Boolean.FALSE; - } - } - }; - FileObject pom = project.getProjectDirectory().getFileObject(POM_XML);//NOI18N - org.netbeans.modules.maven.model.Utilities.performPOMModelOperations(pom, Collections.singletonList(operation)); - //TODO is the manual reload necessary if pom.xml file is being saved? -// NbMavenProject.fireMavenProjectReload(project); - if (added[0]) { - project.getLookup().lookup(NbMavenProject.class).triggerDependencyDownload(); - } - - return added[0]; - } - - public boolean addArchiveFile(FileObject arch) throws IOException { - final File jar = FileUtil.archiveOrDirForURL(arch.getURL()); - if (jar == null || jar.isDirectory()) { - throw new IOException("Cannot add folders to Maven projects as dependencies: " + arch); //NOI18N - } - final AtomicBoolean added = new AtomicBoolean(); - ModelOperation operation = new ModelOperation() { - public void performOperation(POMModel model) { - try { - added.compareAndSet(false, addRemoveJAR(jar, model, null, true)); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } - } - }; - FileObject pom = project.getProjectDirectory().getFileObject(POM_XML);//NOI18N - org.netbeans.modules.maven.model.Utilities.performPOMModelOperations(pom, Collections.singletonList(operation)); - if (added.get()) { - project.getLookup().lookup(NbMavenProject.class).triggerDependencyDownload(); - } - return added.get(); - } - private boolean addRemoveLibrary(Library library, POMModel model, String scope, boolean add) throws IOException { Boolean modified = checkLibraryForPoms(library, model, scope, add); if (modified == null) { @@ -260,10 +213,6 @@ return modified; } - public boolean addAntArtifact(AntArtifact arg0, URI arg1) throws IOException { - throw new IOException("Cannot add Ant based projects as subprojecs to Maven projects."); //NOI18N - } - public SourceGroup[] getExtensibleSourceGroups() { Sources s = this.project.getLookup().lookup(Sources.class); assert s != null; diff --git a/maven/src/org/netbeans/modules/maven/classpath/CPExtenderLookupMerger.java b/maven/src/org/netbeans/modules/maven/classpath/CPExtenderLookupMerger.java deleted file mode 100644 --- a/maven/src/org/netbeans/modules/maven/classpath/CPExtenderLookupMerger.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2010 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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 2008 Sun Microsystems, Inc. - */ - -package org.netbeans.modules.maven.classpath; - -import java.io.IOException; -import java.net.URI; -import java.util.Collection; -import org.netbeans.api.project.ant.AntArtifact; -import org.netbeans.api.project.libraries.Library; -import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender; -import org.netbeans.spi.project.LookupMerger; -import org.openide.filesystems.FileObject; -import org.openide.util.Lookup; - -/** - * - * @author mkleint - */ -@SuppressWarnings("deprecation") -public class CPExtenderLookupMerger implements LookupMerger { - - private CPExtender fallback; - - /** Creates a new instance of CPExtenderLookupMerger */ - public CPExtenderLookupMerger(CPExtender fallbck) { - fallback = fallbck; - assert fallback != null; - } - - public Class getMergeableClass() { - return ProjectClassPathExtender.class; - } - - public synchronized ProjectClassPathExtender merge(Lookup lookup) { - return new Extender(lookup); - } - - @SuppressWarnings("deprecation") - private class Extender implements ProjectClassPathExtender { - - private final Lookup context; - - private Extender(Lookup context) { - this.context = context; - } - - public boolean addLibrary(Library arg0) throws IOException { - Collection list = context.lookupAll(ProjectClassPathExtender.class); - for (ProjectClassPathExtender ext : list) { - boolean added = ext.addLibrary(arg0); - if (added) { - return added; - } - } - return fallback.addLibrary(arg0); - } - - public boolean addArchiveFile(FileObject arg0) throws IOException { - Collection list = context.lookupAll(ProjectClassPathExtender.class); - for (ProjectClassPathExtender ext : list) { - boolean added = ext.addArchiveFile(arg0); - if (added) { - return added; - } - } - return fallback.addArchiveFile(arg0); - } - - public boolean addAntArtifact(AntArtifact arg0, URI arg1) throws IOException { - Collection list = context.lookupAll(ProjectClassPathExtender.class); - for (ProjectClassPathExtender ext : list) { - boolean added = ext.addAntArtifact(arg0, arg1); - if (added) { - return added; - } - } - return fallback.addAntArtifact(arg0, arg1); - } - - } -} diff --git a/maven/src/org/netbeans/modules/maven/classpath/CPModifierLookupMerger.java b/maven/src/org/netbeans/modules/maven/classpath/CPModifierLookupMerger.java deleted file mode 100644 --- a/maven/src/org/netbeans/modules/maven/classpath/CPModifierLookupMerger.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2010 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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 2008 Sun Microsystems, Inc. - */ - - -package org.netbeans.modules.maven.classpath; - -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URI; -import java.net.URL; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.SourceGroup; -import org.netbeans.api.project.ant.AntArtifact; -import org.netbeans.api.project.libraries.Library; -import org.netbeans.spi.java.project.classpath.ProjectClassPathModifierImplementation; -import org.netbeans.spi.project.LookupMerger; -import org.openide.util.Lookup; - -/** - * TODO: The idea of having a LookupMerger for this class is not 100% semantically correct. - * The original add/remove methods return values have different meaning than here. - * if true is returned from impls means everything is done no further processing necessary, - * false means not relevant, try another impl or fallback to default. - * a proper solution would be to create our own api that would reflect this difference. - * @author mkleint - */ -public class CPModifierLookupMerger implements LookupMerger{ - - private CPExtender fallback; - - /** Creates a new instance of CPExtenderLookupMerger */ - public CPModifierLookupMerger(CPExtender fallbck) { - fallback = fallbck; - assert fallback != null; - } - - public Class getMergeableClass() { - return ProjectClassPathModifierImplementation.class; - } - - public synchronized ProjectClassPathModifierImplementation merge(Lookup lookup) { - return new Extender(lookup); - } - - private class Extender extends ProjectClassPathModifierImplementation { - - private final Lookup context; - - private Extender(Lookup context) { - this.context = context; - } - - private Object retVal(String methodName, ProjectClassPathModifierImplementation impl, - Class[] paramTypes, - Object... params) throws IOException { - try { - Method meth = impl.getClass().getDeclaredMethod(methodName, paramTypes); - meth.setAccessible(true); - return meth.invoke(impl, params); - } catch (InvocationTargetException x) { - if (x.getCause() instanceof IOException) { - throw (IOException)x.getCause(); - } - //JDK16 can replace with new IOException(x.getCause()); - IOException ex = new IOException(x.getCause().getMessage()); - ex.initCause(x.getCause()); - throw ex; - } catch (Exception e) { - e.printStackTrace(); - throw new AssertionError("Cannot use reflection on " + impl + " method:" + methodName); - } - } - - protected SourceGroup[] getExtensibleSourceGroups() { - Collection list = context.lookupAll(ProjectClassPathModifierImplementation.class); - Collection sg = new HashSet(); - for (ProjectClassPathModifierImplementation ext : list) { - try { - SourceGroup[] sgs = (SourceGroup[])retVal("getExtensibleSourceGroups", ext, null);//NOI18N - sg.addAll(Arrays.asList(sgs)); - } catch (IOException e) { - //should not happen at all. - } - } - sg.addAll(Arrays.asList(fallback.getExtensibleSourceGroups())); - return sg.toArray(new SourceGroup[sg.size()]); - } - - protected String[] getExtensibleClassPathTypes(SourceGroup arg0) { - Collection list = context.lookupAll(ProjectClassPathModifierImplementation.class); - Collection retVal = new HashSet(); - for (ProjectClassPathModifierImplementation ext : list) { - try { - String[] ret = (String[])retVal("getExtensibleClassPathTypes", ext, //NOI18N - new Class[] {SourceGroup.class}, arg0 ); - retVal.addAll(Arrays.asList(ret)); - } catch (IOException e) { - //should not happen at all. - } - } - retVal.addAll(Arrays.asList(fallback.getExtensibleClassPathTypes(arg0))); - return retVal.toArray(new String[retVal.size()]); - } - - protected boolean addLibraries(Library[] arg0, SourceGroup arg1, - String arg2) throws IOException, - UnsupportedOperationException { - Collection list = context.lookupAll(ProjectClassPathModifierImplementation.class); - for (ProjectClassPathModifierImplementation ext : list) { - Boolean ret = (Boolean)retVal("addLibraries", ext, //NOI18N - new Class[] { new Library[0].getClass(), SourceGroup.class, String.class}, arg0, arg1, arg2); - if (ret.booleanValue()) { - return ret.booleanValue(); - } - } - return fallback.addLibraries(arg0, arg1, arg2); - } - - protected boolean removeLibraries(Library[] arg0, SourceGroup arg1, - String arg2) throws IOException, - UnsupportedOperationException { - Collection list = context.lookupAll(ProjectClassPathModifierImplementation.class); - for (ProjectClassPathModifierImplementation ext : list) { - Boolean ret = (Boolean)retVal("removeLibraries", ext, //NOI18N - new Class[] { new Library[0].getClass(), SourceGroup.class, String.class}, arg0, arg1, arg2); - if (ret.booleanValue()) { - return ret.booleanValue(); - } - } - return fallback.removeLibraries(arg0, arg1, arg2); - } - - protected boolean addRoots(URL[] arg0, SourceGroup arg1, String arg2) throws IOException, - UnsupportedOperationException { - Collection list = context.lookupAll(ProjectClassPathModifierImplementation.class); - for (ProjectClassPathModifierImplementation ext : list) { - Boolean ret = (Boolean)retVal("addRoots", ext, //NOI18N - new Class[] { new URL[0].getClass(), SourceGroup.class, String.class}, arg0, arg1, arg2); - if (ret.booleanValue()) { - return ret.booleanValue(); - } - } - return fallback.addRoots(arg0, arg1, arg2); - } - - protected boolean removeRoots(URL[] arg0, SourceGroup arg1, String arg2) throws IOException, - UnsupportedOperationException { - Collection list = context.lookupAll(ProjectClassPathModifierImplementation.class); - for (ProjectClassPathModifierImplementation ext : list) { - Boolean ret = (Boolean)retVal("removeRoots", ext, //NOI18N - new Class[] { new URL[0].getClass(), SourceGroup.class, String.class}, arg0, arg1, arg2); - if (ret.booleanValue()) { - return ret.booleanValue(); - } - } - return fallback.removeRoots(arg0, arg1, arg2); - } - - protected boolean addAntArtifacts(AntArtifact[] arg0, URI[] arg1, - SourceGroup arg2, String arg3) throws IOException, - UnsupportedOperationException { - Collection list = context.lookupAll(ProjectClassPathModifierImplementation.class); - for (ProjectClassPathModifierImplementation ext : list) { - Boolean ret = (Boolean)retVal("addAntArtifacts", ext, //NOI18N - new Class[] { new AntArtifact[0].getClass(), new URI[0].getClass(), SourceGroup.class, String.class}, arg0, arg1, arg2, arg3); - if (ret.booleanValue()) { - return ret.booleanValue(); - } - } - return fallback.addAntArtifacts(arg0, arg1, arg2, arg3); - } - - protected boolean removeAntArtifacts(AntArtifact[] arg0, URI[] arg1, - SourceGroup arg2, String arg3) throws IOException, - UnsupportedOperationException { - Collection list = context.lookupAll(ProjectClassPathModifierImplementation.class); - for (ProjectClassPathModifierImplementation ext : list) { - Boolean ret = (Boolean)retVal("addAntArtifacts", ext, //NOI18N - new Class[] { new AntArtifact[0].getClass(), new URI[0].getClass(), SourceGroup.class, String.class}, arg0, arg1, arg2, arg3); - if (ret.booleanValue()) { - return ret.booleanValue(); - } - } - return fallback.addAntArtifacts(arg0, arg1, arg2, arg3); - } - - @Override - protected boolean addProjects(Project[] projects, SourceGroup sg, String classPathType) throws IOException, UnsupportedOperationException { -// Collection list = context.lookupAll(ProjectClassPathModifierImplementation.class); -// for (ProjectClassPathModifierImplementation ext : list) { -// Boolean ret = (Boolean)retVal("addProjects", ext, //NOI18N -// new Class[] { new Project[0].getClass(), SourceGroup.class, String.class}, projects, sg, classPathType); -// if (ret.booleanValue()) { -// return ret.booleanValue(); -// } -// } - //use only the fallback, as that's the man with correct impl. others might have the ant based default method implementation preserved.. - return fallback.addProjects(projects, sg, classPathType); - } - - - } - -} diff --git a/projectimport.jbuilder/nbproject/project.xml b/projectimport.jbuilder/nbproject/project.xml --- a/projectimport.jbuilder/nbproject/project.xml +++ b/projectimport.jbuilder/nbproject/project.xml @@ -116,6 +116,7 @@ 1 + 1.10 diff --git a/projectimport.jbuilder/src/org/netbeans/modules/projectimport/j2seimport/ImportUtils.java b/projectimport.jbuilder/src/org/netbeans/modules/projectimport/j2seimport/ImportUtils.java --- a/projectimport.jbuilder/src/org/netbeans/modules/projectimport/j2seimport/ImportUtils.java +++ b/projectimport.jbuilder/src/org/netbeans/modules/projectimport/j2seimport/ImportUtils.java @@ -46,6 +46,7 @@ import java.io.File; import java.io.IOException; +import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.Collection; @@ -54,9 +55,11 @@ import java.util.List; import java.util.Map; import java.util.logging.Logger; +import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.platform.JavaPlatform; import org.netbeans.api.java.platform.JavaPlatformManager; import org.netbeans.api.java.project.JavaProjectConstants; +import org.netbeans.api.java.project.classpath.ProjectClassPathModifier; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; import org.netbeans.api.project.Project; @@ -68,7 +71,6 @@ import org.netbeans.modules.java.j2seproject.J2SEProject; import org.netbeans.modules.java.j2seproject.J2SEProjectGenerator; import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; -import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; import org.openide.filesystems.FileObject; @@ -317,13 +319,12 @@ public void addDependency(final J2SEProject nbProject, final J2SEProject nbSubProject) throws IOException { - ProjectClassPathExtender nbClsPath = (ProjectClassPathExtender) - nbProject.getLookup().lookup(ProjectClassPathExtender.class); - AntArtifact[] artifact = AntArtifactQuery.findArtifactsByType(nbSubProject, JavaProjectConstants.ARTIFACT_TYPE_JAR); - - nbClsPath.addAntArtifact(artifact[0], artifact[0].getArtifactLocations()[0]); + FileObject[] roots = nbProject.getSourceRoots().getRoots(); + if (roots.length > 0) { + ProjectClassPathModifier.addAntArtifacts(artifact, new URI[] {artifact[0].getArtifactLocations()[0]}, roots[0], ClassPath.COMPILE); + } } private WarningContainer/* warnings*/ addSourceRoots(final ProjectModel projectDefinition, @@ -361,14 +362,12 @@ for (Iterator it = projectDefinition.getUserLibraries().iterator(); it.hasNext();) { ProjectModel.UserLibrary userLibrary = (ProjectModel.UserLibrary)it.next(); - ProjectClassPathExtender nbClsPath = (ProjectClassPathExtender) nbProject.getLookup().lookup(ProjectClassPathExtender.class); - assert nbClsPath != null; List allLibs = getAllLibraries(null, userLibrary); for (Iterator itUL = allLibs.iterator(); itUL.hasNext();) { ProjectModel.Library lEntry = (ProjectModel.Library)itUL.next(); try { - warnings.addAll(addLibrary(nbClsPath, lEntry, projectDefinition)); + warnings.addAll(addLibrary(nbProject, lEntry, projectDefinition)); } catch(IOException iex) { ImportUtils.addWarning(warnings,iex.getLocalizedMessage()); } @@ -394,13 +393,10 @@ final J2SEProject nbProject) throws IOException { WarningContainer warnings = new WarningContainer(); - ProjectClassPathExtender nbClsPath = (ProjectClassPathExtender) nbProject.getLookup().lookup(ProjectClassPathExtender.class); - assert nbClsPath != null; - for (Iterator it = projectDefinition.getLibraries().iterator(); it.hasNext();) { ProjectModel.Library lEntry = (ProjectModel.Library)it.next(); try { - warnings.addAll(addLibrary(nbClsPath, lEntry, projectDefinition)); + warnings.addAll(addLibrary(nbProject, lEntry, projectDefinition)); } catch(IOException iex) { ImportUtils.addWarning(warnings,iex.getLocalizedMessage()); } @@ -410,12 +406,14 @@ } - private WarningContainer addLibrary(final ProjectClassPathExtender nbClsPath, + private WarningContainer addLibrary(final J2SEProject nbProject, final ProjectModel.Library lEntry, final ProjectModel projectDefinition) throws IOException { WarningContainer warnings = new WarningContainer(); FileObject archiv = FileUtil.toFileObject(lEntry.getArchiv()); - - nbClsPath.addArchiveFile(archiv); + FileObject[] roots = nbProject.getSourceRoots().getRoots(); + if (roots.length == 0 || !ProjectClassPathModifier.addRoots(new URL[] {FileUtil.getArchiveRoot(archiv.getURL())}, roots[0], ClassPath.COMPILE)) { + addWarning(warnings, "No Java source roots in: " + FileUtil.getFileDisplayName(nbProject.getProjectDirectory())); // XXX I18N + } return warnings; } diff --git a/web.project/nbproject/project.xml b/web.project/nbproject/project.xml --- a/web.project/nbproject/project.xml +++ b/web.project/nbproject/project.xml @@ -216,15 +216,6 @@ - org.netbeans.modules.javaee.specs.support - - - - 0 - 1.0 - - - org.netbeans.modules.j2eeserver @@ -256,7 +247,7 @@ 1 - 1.37 + 1.41 @@ -268,6 +259,15 @@ + org.netbeans.modules.javaee.specs.support + + + + 0 + 1.0 + + + org.netbeans.modules.junit 2 diff --git a/web.project/src/org/netbeans/modules/web/project/WebProject.java b/web.project/src/org/netbeans/modules/web/project/WebProject.java --- a/web.project/src/org/netbeans/modules/web/project/WebProject.java +++ b/web.project/src/org/netbeans/modules/web/project/WebProject.java @@ -59,7 +59,6 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import javax.swing.Icon; -import javax.swing.JButton; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.netbeans.api.java.classpath.ClassPath; @@ -68,10 +67,10 @@ import org.netbeans.api.project.ant.AntBuildExtender; import org.netbeans.api.queries.FileBuiltQuery.Status; import org.netbeans.api.j2ee.core.Profile; +import org.netbeans.api.java.project.classpath.ProjectClassPathModifier; import org.netbeans.modules.j2ee.dd.api.ejb.EjbJarMetadata; import org.netbeans.modules.j2ee.metadata.model.api.MetadataModelAction; import org.netbeans.modules.java.api.common.Roots; -import org.netbeans.modules.java.api.common.classpath.ClassPathSupport.Item; import org.netbeans.modules.j2ee.deployment.devmodules.spi.ArtifactListener.Artifact; import org.netbeans.modules.web.common.spi.ProjectWebRootProvider; import org.netbeans.modules.web.jsfapi.spi.JsfSupportHandle; @@ -118,7 +117,6 @@ import org.netbeans.modules.j2ee.common.Util; import org.netbeans.modules.j2ee.common.dd.DDHelper; import org.netbeans.modules.j2ee.common.project.ArtifactCopyOnSaveSupport; -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.ClassPathModifierSupport; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; @@ -176,8 +174,6 @@ import org.netbeans.spi.project.support.ant.PropertyProvider; import org.netbeans.spi.project.support.ant.PropertyUtils; import org.netbeans.spi.queries.FileEncodingQueryImplementation; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; import org.openide.filesystems.FileLock; import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileSystem.AtomicAction; @@ -226,7 +222,6 @@ private final UpdateHelper updateHelper; private final UpdateProjectImpl updateProject; private final AuxiliaryConfiguration aux; - private final ClassPathExtender classPathExtender; private final ClassPathModifier cpMod; private final WebProjectLibrariesModifierImpl libMod; private final ClassPathProviderImpl cpProvider; @@ -392,7 +387,6 @@ cpMod = new ClassPathModifier(this, this.updateHelper, eval, refHelper, new ClassPathSupportCallbackImpl(helper), createClassPathModifierCallback(), getClassPathUiSupportCallback()); libMod = new WebProjectLibrariesModifierImpl(this, this.updateHelper, eval, refHelper); - classPathExtender = new ClassPathExtender(cpMod, ProjectProperties.JAVAC_CLASSPATH, ClassPathSupportCallbackImpl.TAG_WEB_MODULE_LIBRARIES); lookup = createLookup(aux, cpProvider); css = new CopyOnSaveSupport(); artifactSupport = new ArtifactCopySupport(); @@ -569,7 +563,7 @@ getTestSourceRoots(), WebProjectProperties.WEB_DOCBASE_DIR), new RecommendedTemplatesImpl(this), new CoSAwareFileBuiltQueryImpl(QuerySupport.createFileBuiltQuery(helper, evaluator(), getSourceRoots(), getTestSourceRoots()), this), - classPathExtender, + ProjectClassPathModifier.extenderForModifier(cpMod), buildExtender, cpMod, new WebProjectOperations(this), diff --git a/web.struts/nbproject/project.xml b/web.struts/nbproject/project.xml --- a/web.struts/nbproject/project.xml +++ b/web.struts/nbproject/project.xml @@ -183,6 +183,7 @@ 1 + 1.10 diff --git a/web.struts/src/org/netbeans/modules/web/struts/StrutsFrameworkProvider.java b/web.struts/src/org/netbeans/modules/web/struts/StrutsFrameworkProvider.java --- a/web.struts/src/org/netbeans/modules/web/struts/StrutsFrameworkProvider.java +++ b/web.struts/src/org/netbeans/modules/web/struts/StrutsFrameworkProvider.java @@ -60,7 +60,9 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.SwingUtilities; +import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.project.JavaProjectConstants; +import org.netbeans.api.java.project.classpath.ProjectClassPathModifier; import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.SourceGroup; import org.netbeans.modules.j2ee.dd.api.common.CreateCapability; @@ -94,7 +96,6 @@ import org.netbeans.modules.web.struts.ui.StrutsConfigurationPanel; -import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; @@ -129,16 +130,13 @@ Library lib = LibraryManager.getDefault().getLibrary("struts"); //NOI18N if (lib != null) { - ProjectClassPathExtender cpExtender = (ProjectClassPathExtender) project.getLookup().lookup(ProjectClassPathExtender.class); - if (cpExtender != null) { + SourceGroup[] sgs = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); + if (sgs.length > 0) { try { - cpExtender.addLibrary(lib); + ProjectClassPathModifier.addLibraries(new Library[] {lib}, sgs[0].getRootFolder(), ClassPath.COMPILE); } catch (IOException ioe) { Exceptions.printStackTrace(ioe); } - } else { - Logger.getLogger("global").log(Level.INFO, - "WebProjectClassPathExtender not found in the project lookup of project: " + project.getProjectDirectory().getPath()); //NOI18N } try { diff --git a/websvc.core/nbproject/project.xml b/websvc.core/nbproject/project.xml --- a/websvc.core/nbproject/project.xml +++ b/websvc.core/nbproject/project.xml @@ -228,6 +228,7 @@ 1 + 1.10 diff --git a/websvc.core/src/org/netbeans/modules/websvc/core/dev/wizard/JaxWsServiceCreator.java b/websvc.core/src/org/netbeans/modules/websvc/core/dev/wizard/JaxWsServiceCreator.java --- a/websvc.core/src/org/netbeans/modules/websvc/core/dev/wizard/JaxWsServiceCreator.java +++ b/websvc.core/src/org/netbeans/modules/websvc/core/dev/wizard/JaxWsServiceCreator.java @@ -81,6 +81,7 @@ import javax.lang.model.type.TypeKind; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.project.JavaProjectConstants; +import org.netbeans.api.java.project.classpath.ProjectClassPathModifier; import org.netbeans.api.java.source.CancellableTask; import org.netbeans.api.java.source.Comment; import org.netbeans.api.java.source.GeneratorUtilities; @@ -108,7 +109,6 @@ import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlService; import org.netbeans.modules.websvc.core.JaxWsUtils; import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport; -import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender; import org.netbeans.spi.project.ui.templates.support.Templates; import org.openide.DialogDisplayer; import org.openide.ErrorManager; @@ -308,17 +308,17 @@ // check if the wsimport class is already present - this means we don't need to add the library SourceGroup[] sgs = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); + if (sgs.length > 0) { ClassPath classPath = ClassPath.getClassPath(sgs[0].getRootFolder(), ClassPath.COMPILE); FileObject wsimportFO = classPath.findResource("com/sun/tools/ws/ant/WsImport.class"); // NOI18N if (wsimportFO != null) { return; } - ProjectClassPathExtender pce = (ProjectClassPathExtender) project.getLookup().lookup(ProjectClassPathExtender.class); Library jaxws21_ext = LibraryManager.getDefault().getLibrary("jaxws21"); //NOI18N - if (pce != null && jaxws21_ext != null) { + if (jaxws21_ext != null) { try { - pce.addLibrary(jaxws21_ext); + ProjectClassPathModifier.addLibraries(new Library[] {jaxws21_ext}, sgs[0].getRootFolder(), ClassPath.COMPILE); } catch (IOException e) { throw new Exception("Unable to add JAXWS 21 Library. " + e.getMessage()); } @@ -327,7 +327,6 @@ "ProjectClassPathExtender or library not found"); } - if (sgs.length > 0) { try { FileObject srcRoot = sgs[0].getRootFolder(); WSUtils.addJaxWsApiEndorsed(project, srcRoot); diff --git a/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/client/wizard/JaxRpcClientCreator.java b/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/client/wizard/JaxRpcClientCreator.java --- a/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/client/wizard/JaxRpcClientCreator.java +++ b/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/client/wizard/JaxRpcClientCreator.java @@ -58,6 +58,7 @@ import java.util.Set; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.project.JavaProjectConstants; +import org.netbeans.api.java.project.classpath.ProjectClassPathModifier; import org.netbeans.api.java.queries.UnitTestForSourceQuery; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; @@ -74,8 +75,6 @@ import org.netbeans.modules.websvc.api.support.ClientCreator; import org.netbeans.modules.websvc.core.ClientWizardProperties; import org.netbeans.modules.websvc.core.WsdlRetriever; -import org.netbeans.modules.websvc.core.WsdlRetriever; -import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender; import org.openide.DialogDisplayer; import org.openide.ErrorManager; import org.openide.NotifyDescriptor; @@ -301,10 +300,9 @@ FileObject wscompileFO = classPath.findResource("com/sun/xml/rpc/tools/ant/Wscompile.class"); if (wscompileFO==null) { // add jax-rpc16 if webservice is not on classpath - ProjectClassPathExtender pce = (ProjectClassPathExtender)project.getLookup().lookup(ProjectClassPathExtender.class); Library jaxrpclib = LibraryManager.getDefault().getLibrary("jaxrpc16"); //NOI18N - if ((pce!=null) && (jaxrpclib != null)) { - pce.addLibrary(jaxrpclib); + if (jaxrpclib != null) { + ProjectClassPathModifier.addLibraries(new Library[] {jaxrpclib}, sgs[0].getRootFolder(), ClassPath.COMPILE); } }