Issue #150194: add @ProjectServiceProvider and @LookupMerger.Registration as alternatives to @LookupProvider.Registration. These are potentially easier to use and more efficient than the older annotation. However, they do not apply to cases where the choice of lookup items must be determined dynamically. diff --git a/groovy.support/nbproject/project.xml b/groovy.support/nbproject/project.xml --- a/groovy.support/nbproject/project.xml +++ b/groovy.support/nbproject/project.xml @@ -119,7 +119,7 @@ 1 - 1.13 + 1.23 diff --git a/groovy.support/src/org/netbeans/modules/groovy/support/GroovyActionProvider.java b/groovy.support/src/org/netbeans/modules/groovy/support/GroovyActionProvider.java --- a/groovy.support/src/org/netbeans/modules/groovy/support/GroovyActionProvider.java +++ b/groovy.support/src/org/netbeans/modules/groovy/support/GroovyActionProvider.java @@ -62,6 +62,7 @@ import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; import org.netbeans.spi.project.ActionProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; import org.netbeans.spi.project.support.ant.PropertyUtils; import org.openide.DialogDisplayer; @@ -87,6 +88,7 @@ * * @author Martin Adamek */ +@ProjectServiceProvider(service=ActionProvider.class, projectType="org-netbeans-modules-java-j2seproject") public class GroovyActionProvider implements ActionProvider { // from J2SEProjectProperties diff --git a/groovy.support/src/org/netbeans/modules/groovy/support/GroovyLookupProvider.java b/groovy.support/src/org/netbeans/modules/groovy/support/GroovyLookupProvider.java deleted file mode 100644 --- a/groovy.support/src/org/netbeans/modules/groovy/support/GroovyLookupProvider.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.groovy.support; - -import java.util.ArrayList; -import java.util.List; -import org.netbeans.api.project.Project; -import org.netbeans.spi.project.LookupProvider; -import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; - -/** - * - * @author Martin Adamek - */ -public class GroovyLookupProvider implements LookupProvider { - @LookupProvider.Registration(projectType="org-netbeans-modules-java-j2seproject") - public static GroovyLookupProvider createJavaSE() { - return new GroovyLookupProvider(); - } - - private GroovyLookupProvider() {} - - public Lookup createAdditionalLookup(Lookup baseContext) { - Project project = baseContext.lookup(Project.class); - if (project == null) { - throw new IllegalStateException("Lookup " + baseContext + " does not contain a Project"); - } - List instances = new ArrayList(3); - instances.add(new GroovyProjectExtender(project)); - instances.add(LookupMergerSupport.createActionProviderLookupMerger()); - instances.add(new GroovyActionProvider(project)); - instances.add(new GsfClasspathHook(project, baseContext)); - return Lookups.fixed(instances.toArray(new Object[instances.size()])); - } - -} diff --git a/groovy.support/src/org/netbeans/modules/groovy/support/GroovyProjectExtender.java b/groovy.support/src/org/netbeans/modules/groovy/support/GroovyProjectExtender.java --- a/groovy.support/src/org/netbeans/modules/groovy/support/GroovyProjectExtender.java +++ b/groovy.support/src/org/netbeans/modules/groovy/support/GroovyProjectExtender.java @@ -62,6 +62,7 @@ import org.netbeans.modules.groovy.support.spi.GroovyFeature; import org.netbeans.modules.gsfpath.api.classpath.GlobalPathRegistry; import org.netbeans.modules.gsfpath.spi.classpath.support.ClassPathSupport; +import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.support.ant.EditableProperties; import org.openide.filesystems.FileLock; import org.openide.filesystems.FileObject; @@ -77,6 +78,8 @@ * * @author Martin Adamek */ +@ProjectServiceProvider(service={GroovyFeature.class, GroovyProjectExtender.class}, +projectType="org-netbeans-modules-java-j2seproject") public class GroovyProjectExtender implements GroovyFeature { private static final String EXTENSIBLE_TARGET_NAME = "-pre-pre-compile"; // NOI18N @@ -91,7 +94,7 @@ private org.netbeans.modules.gsfpath.api.classpath.ClassPath gsfClassPath; private GroovyCustomizerPanel panel; - GroovyProjectExtender(Project project) { + public GroovyProjectExtender(Project project) { this.project = project; } diff --git a/groovy.support/src/org/netbeans/modules/groovy/support/GsfClasspathHook.java b/groovy.support/src/org/netbeans/modules/groovy/support/GsfClasspathHook.java --- a/groovy.support/src/org/netbeans/modules/groovy/support/GsfClasspathHook.java +++ b/groovy.support/src/org/netbeans/modules/groovy/support/GsfClasspathHook.java @@ -41,8 +41,8 @@ import org.netbeans.api.project.Project; import org.netbeans.modules.groovy.support.spi.GroovyFeature; +import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.ui.ProjectOpenedHook; -import org.openide.util.Lookup; /** * Temporary solution to have GSF indexing enabled on projects with only @@ -52,11 +52,12 @@ * * @author Martin Adamek */ +@ProjectServiceProvider(service=ProjectOpenedHook.class, projectType="org-netbeans-modules-java-j2seproject") public class GsfClasspathHook extends ProjectOpenedHook { private final Project project; - public GsfClasspathHook(Project project, Lookup baseContext) { + public GsfClasspathHook(Project project) { this.project = project; } diff --git a/groovy.support/src/org/netbeans/modules/groovy/support/LookupMergerSupport.java b/groovy.support/src/org/netbeans/modules/groovy/support/LookupMergerSupport.java --- a/groovy.support/src/org/netbeans/modules/groovy/support/LookupMergerSupport.java +++ b/groovy.support/src/org/netbeans/modules/groovy/support/LookupMergerSupport.java @@ -62,6 +62,7 @@ * is found. * @return */ + @LookupMerger.Registration(projectType="org-netbeans-modules-java-j2seproject") public static LookupMerger createActionProviderLookupMerger() { return new ActionProviderMerger(); } diff --git a/hibernate/nbproject/project.xml b/hibernate/nbproject/project.xml --- a/hibernate/nbproject/project.xml +++ b/hibernate/nbproject/project.xml @@ -247,7 +247,7 @@ 1 - 1.14 + 1.23 diff --git a/hibernate/src/org/netbeans/modules/hibernate/service/HibernateProjectLookupExtender.java b/hibernate/src/org/netbeans/modules/hibernate/service/HibernateProjectLookupExtender.java deleted file mode 100644 --- a/hibernate/src/org/netbeans/modules/hibernate/service/HibernateProjectLookupExtender.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * 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.hibernate.service; - -import org.netbeans.modules.hibernate.service.spi.HibernateEnvironmentImpl; -import org.netbeans.api.project.Project; -import org.netbeans.modules.hibernate.service.api.HibernateEnvironment; -import org.netbeans.modules.hibernate.service.spi.HibernateVerificationWarningOverrider; -import org.netbeans.spi.project.LookupProvider; -import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; - - -/** - * The class extends project lookup to include additional instances of - * Hibernate artifacts. This class is registered in the project's lookup. - * - * @author Vadiraj Deshpande (Vadiraj.Deshpande@Sun.COM) - */ -@LookupProvider.Registration(projectType={ - "org-netbeans-modules-maven", - "org-netbeans-modules-java-j2seproject", - "org-netbeans-modules-web-project" -}, projectTypes=@LookupProvider.Registration.ProjectType(id="org-netbeans-modules-ant-freeform", position=700)) -public class HibernateProjectLookupExtender implements LookupProvider { - - public Lookup createAdditionalLookup(Lookup baseContext) { - Project project = baseContext.lookup(Project.class); - HibernateEnvironment hibernateEnvironment = new HibernateEnvironmentImpl(project); - HibernateVerificationWarningOverrider warningOverrider = new HibernateVerificationWarningOverrider(project); - return Lookups.fixed(new Object[]{hibernateEnvironment, warningOverrider}); - } - -} diff --git a/hibernate/src/org/netbeans/modules/hibernate/service/spi/HibernateEnvironmentImpl.java b/hibernate/src/org/netbeans/modules/hibernate/service/spi/HibernateEnvironmentImpl.java --- a/hibernate/src/org/netbeans/modules/hibernate/service/spi/HibernateEnvironmentImpl.java +++ b/hibernate/src/org/netbeans/modules/hibernate/service/spi/HibernateEnvironmentImpl.java @@ -67,6 +67,8 @@ import org.netbeans.modules.hibernate.mapping.model.MyClass; import org.netbeans.modules.hibernate.util.CustomClassLoader; import org.netbeans.modules.hibernate.util.HibernateUtil; +import org.netbeans.spi.project.LookupProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.loaders.DataObject; @@ -81,6 +83,11 @@ * * @author Vadiraj Deshpande (Vadiraj.Deshpande@Sun.COM) */ +@ProjectServiceProvider(service=HibernateEnvironment.class, projectType={ + "org-netbeans-modules-maven", + "org-netbeans-modules-java-j2seproject", + "org-netbeans-modules-web-project" +}, projectTypes=@LookupProvider.Registration.ProjectType(id="org-netbeans-modules-ant-freeform", position=700)) public class HibernateEnvironmentImpl implements HibernateEnvironment { /** Handle to the current project to which this HibernateEnvironment is bound*/ diff --git a/hibernate/src/org/netbeans/modules/hibernate/service/spi/HibernateVerificationWarningOverrider.java b/hibernate/src/org/netbeans/modules/hibernate/service/spi/HibernateVerificationWarningOverrider.java --- a/hibernate/src/org/netbeans/modules/hibernate/service/spi/HibernateVerificationWarningOverrider.java +++ b/hibernate/src/org/netbeans/modules/hibernate/service/spi/HibernateVerificationWarningOverrider.java @@ -43,12 +43,19 @@ import org.netbeans.modules.hibernate.service.api.HibernateEnvironment; import org.netbeans.modules.j2ee.jpa.verification.api.JPAVerificationWarningIds; import org.netbeans.modules.j2ee.jpa.verification.api.VerificationWarningOverrider; +import org.netbeans.spi.project.LookupProvider; +import org.netbeans.spi.project.ProjectServiceProvider; /** * To override specific verification warning * * @author Dongmei Cao */ +@ProjectServiceProvider(service=VerificationWarningOverrider.class, projectType={ + "org-netbeans-modules-maven", + "org-netbeans-modules-java-j2seproject", + "org-netbeans-modules-web-project" +}, projectTypes=@LookupProvider.Registration.ProjectType(id="org-netbeans-modules-ant-freeform", position=701)) public class HibernateVerificationWarningOverrider implements VerificationWarningOverrider { private Project project; 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 @@ -133,7 +133,7 @@ 1 - 1.18 + 1.23 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 @@ -42,7 +42,6 @@ import java.io.IOException; import java.net.URI; import java.net.URL; -import org.netbeans.modules.maven.api.PluginPropertyUtils; import org.netbeans.modules.maven.api.customizer.ModelHandle; import org.netbeans.modules.maven.spi.customizer.ModelHandleUtils; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -53,6 +52,7 @@ 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; @@ -60,6 +60,8 @@ * * @author mkleint */ +@ProjectServiceProvider(service={ProjectClassPathModifierImplementation.class, ProjectClassPathExtender.class}, +projectType="org-netbeans-modules-maven") public class CPExtender extends ProjectClassPathModifierImplementation implements ProjectClassPathExtender { private static final String SL_15 = "1.5"; //NOI18N private Project project; diff --git a/maven.persistence/src/org/netbeans/modules/maven/persistence/EntityClassScopeProviderImpl.java b/maven.persistence/src/org/netbeans/modules/maven/persistence/EntityClassScopeProviderImpl.java --- a/maven.persistence/src/org/netbeans/modules/maven/persistence/EntityClassScopeProviderImpl.java +++ b/maven.persistence/src/org/netbeans/modules/maven/persistence/EntityClassScopeProviderImpl.java @@ -49,19 +49,21 @@ import org.netbeans.modules.j2ee.persistence.spi.EntityClassScopeProvider; import org.netbeans.modules.j2ee.persistence.spi.support.EntityMappingsMetadataModelHelper; import org.netbeans.modules.maven.api.classpath.ProjectSourcesClassPathProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileObject; /** * * @author mkleint */ +@ProjectServiceProvider(service=EntityClassScopeProvider.class, projectType="org-netbeans-modules-maven") public class EntityClassScopeProviderImpl implements EntityClassScopeProvider { Project project; EntityMappingsMetadataModelHelper helper; EntityClassScope scope; - EntityClassScopeProviderImpl(Project prj) { + public EntityClassScopeProviderImpl(Project prj) { project = prj; } diff --git a/maven.persistence/src/org/netbeans/modules/maven/persistence/MavenPersistenceProvider.java b/maven.persistence/src/org/netbeans/modules/maven/persistence/MavenPersistenceProvider.java --- a/maven.persistence/src/org/netbeans/modules/maven/persistence/MavenPersistenceProvider.java +++ b/maven.persistence/src/org/netbeans/modules/maven/persistence/MavenPersistenceProvider.java @@ -50,6 +50,7 @@ import org.netbeans.modules.j2ee.persistence.spi.PersistenceLocationProvider; import org.netbeans.modules.j2ee.persistence.spi.PersistenceScopeProvider; import org.netbeans.modules.j2ee.persistence.spi.PersistenceScopesProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileObject; import org.openide.util.WeakListeners; @@ -57,6 +58,8 @@ * * @author Daniel Mohni */ +@ProjectServiceProvider(service={PersistenceLocationProvider.class, PersistenceScopeProvider.class, PersistenceScopesProvider.class}, +projectType="org-netbeans-modules-maven") public class MavenPersistenceProvider implements PersistenceLocationProvider, PersistenceScopeProvider, PersistenceScopesProvider { diff --git a/maven.persistence/src/org/netbeans/modules/maven/persistence/PersistenceLookupProvider.java b/maven.persistence/src/org/netbeans/modules/maven/persistence/PersistenceLookupProvider.java deleted file mode 100644 --- a/maven.persistence/src/org/netbeans/modules/maven/persistence/PersistenceLookupProvider.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2008 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 2008 Sun Microsystems, Inc. - */ -package org.netbeans.modules.maven.persistence; - -import org.netbeans.api.project.Project; -import org.netbeans.spi.project.LookupProvider; -import org.netbeans.spi.project.ui.RecommendedTemplates; -import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; - -/** - * extending the default maven project lookup. - * @author Milos Kleint - */ -@LookupProvider.Registration(projectType="org-netbeans-modules-maven") -public class PersistenceLookupProvider implements LookupProvider { - - /** Creates a new instance of J2eeLookupProvider */ - public PersistenceLookupProvider() { - } - - /** - * - * @param context - * @return - */ - public Lookup createAdditionalLookup(Lookup context) { -// // if there's more items later, just do a proxy.. - Project prj = context.lookup(Project.class); - assert prj != null; - return Lookups.fixed(new Object[] { - new MavenPersistenceProvider(prj), - new EntityClassScopeProviderImpl(prj), - new RecoTemp(), - new CPExtender(prj) - }); - } - - private static class RecoTemp implements RecommendedTemplates { - public String[] getRecommendedTypes() { - return new String[] { - "persistence" //NOI18N - }; - } - } - -} diff --git a/maven.persistence/src/org/netbeans/modules/maven/persistence/RecommendedTemplatesImpl.java b/maven.persistence/src/org/netbeans/modules/maven/persistence/RecommendedTemplatesImpl.java new file mode 100644 --- /dev/null +++ b/maven.persistence/src/org/netbeans/modules/maven/persistence/RecommendedTemplatesImpl.java @@ -0,0 +1,50 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 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 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.maven.persistence; + +import org.netbeans.spi.project.ProjectServiceProvider; +import org.netbeans.spi.project.ui.RecommendedTemplates; + +@ProjectServiceProvider(service=RecommendedTemplates.class, projectType="org-netbeans-modules-maven") +public class RecommendedTemplatesImpl implements RecommendedTemplates { + public String[] getRecommendedTypes() { + return new String[] {"persistence"}; + } +} diff --git a/maven.profiler/nbproject/project.xml b/maven.profiler/nbproject/project.xml --- a/maven.profiler/nbproject/project.xml +++ b/maven.profiler/nbproject/project.xml @@ -97,7 +97,7 @@ 1 - 1.18 + 1.23 diff --git a/maven.profiler/src/org/netbeans/modules/maven/profiler/LookupProviderImpl.java b/maven.profiler/src/org/netbeans/modules/maven/profiler/LookupProviderImpl.java deleted file mode 100644 --- a/maven.profiler/src/org/netbeans/modules/maven/profiler/LookupProviderImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2008 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 2008 Sun Microsystems, Inc. - */ - -package org.netbeans.modules.maven.profiler; - -import org.netbeans.modules.maven.api.NbMavenProject; -import org.netbeans.api.project.Project; -import org.netbeans.spi.project.LookupProvider; -import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; - -/** - * - * @author mkleint - */ -@LookupProvider.Registration(projectType="org-netbeans-modules-maven") -public class LookupProviderImpl implements LookupProvider { - - public Lookup createAdditionalLookup(Lookup baseContext) { - - NbMavenProject nbprj = baseContext.lookup(NbMavenProject.class); - Project prj = baseContext.lookup(Project.class); - assert prj != null; - assert nbprj != null; - - return Lookups.fixed(new RunCheckerImpl(prj)); - } - -} diff --git a/maven.profiler/src/org/netbeans/modules/maven/profiler/RunCheckerImpl.java b/maven.profiler/src/org/netbeans/modules/maven/profiler/RunCheckerImpl.java --- a/maven.profiler/src/org/netbeans/modules/maven/profiler/RunCheckerImpl.java +++ b/maven.profiler/src/org/netbeans/modules/maven/profiler/RunCheckerImpl.java @@ -47,6 +47,7 @@ import org.netbeans.modules.maven.api.execute.ExecutionContext; import org.netbeans.modules.maven.api.execute.LateBoundPrerequisitesChecker; import org.netbeans.modules.profiler.utils.ProjectUtilities; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.util.RequestProcessor; /** @@ -54,6 +55,7 @@ * @author mkleint * @author Jiri Sedlacek */ +@ProjectServiceProvider(service=LateBoundPrerequisitesChecker.class, projectType="org-netbeans-modules-maven") public class RunCheckerImpl implements LateBoundPrerequisitesChecker { private static final String ACTION_PROFILE = "profile"; // NOI18N diff --git a/maven.spring/nbproject/project.xml b/maven.spring/nbproject/project.xml --- a/maven.spring/nbproject/project.xml +++ b/maven.spring/nbproject/project.xml @@ -61,7 +61,7 @@ 1 - 1.19 + 1.23 diff --git a/maven.spring/src/org/netbeans/modules/maven/spring/MavenSpringConfigProviderImpl.java b/maven.spring/src/org/netbeans/modules/maven/spring/MavenSpringConfigProviderImpl.java --- a/maven.spring/src/org/netbeans/modules/maven/spring/MavenSpringConfigProviderImpl.java +++ b/maven.spring/src/org/netbeans/modules/maven/spring/MavenSpringConfigProviderImpl.java @@ -50,6 +50,7 @@ import org.netbeans.modules.spring.api.beans.SpringConstants; import org.netbeans.modules.spring.spi.beans.SpringConfigFileLocationProvider; import org.netbeans.modules.spring.spi.beans.SpringConfigFileProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.NbCollections; @@ -58,10 +59,11 @@ * * @author mkleint */ +@ProjectServiceProvider(service={SpringConfigFileProvider.class, SpringConfigFileLocationProvider.class}, projectType="org-netbeans-modules-maven") public class MavenSpringConfigProviderImpl implements SpringConfigFileLocationProvider, SpringConfigFileProvider { private Project prj; - MavenSpringConfigProviderImpl(Project project) { + public MavenSpringConfigProviderImpl(Project project) { prj = project; } diff --git a/maven.spring/src/org/netbeans/modules/maven/spring/MavenSpringLookupProvider.java b/maven.spring/src/org/netbeans/modules/maven/spring/MavenSpringLookupProvider.java deleted file mode 100644 --- a/maven.spring/src/org/netbeans/modules/maven/spring/MavenSpringLookupProvider.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2008 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 2008 Sun Microsystems, Inc. - */ - - -package org.netbeans.modules.maven.spring; - -import org.netbeans.api.project.Project; -import org.netbeans.spi.project.LookupProvider; -import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; - -/** - * - * @author mkleint - */ -@LookupProvider.Registration(projectType="org-netbeans-modules-maven") -public class MavenSpringLookupProvider implements LookupProvider { - - public Lookup createAdditionalLookup(Lookup baseContext) { - Project project = baseContext.lookup(Project.class); - if (project == null) { - throw new IllegalStateException("Lookup " + baseContext + " does not contain a Project"); - } - return Lookups.fixed( - new MavenSpringConfigProviderImpl(project), - new RecommendedTemplatesImpl(project)); - } - - - -} diff --git a/maven.spring/src/org/netbeans/modules/maven/spring/RecommendedTemplatesImpl.java b/maven.spring/src/org/netbeans/modules/maven/spring/RecommendedTemplatesImpl.java --- a/maven.spring/src/org/netbeans/modules/maven/spring/RecommendedTemplatesImpl.java +++ b/maven.spring/src/org/netbeans/modules/maven/spring/RecommendedTemplatesImpl.java @@ -41,12 +41,14 @@ import org.netbeans.api.project.Project; import org.netbeans.modules.maven.api.NbMavenProject; +import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.ui.RecommendedTemplates; /** * * @author Milos Kleint */ +@ProjectServiceProvider(service=RecommendedTemplates.class, projectType="org-netbeans-modules-maven") public class RecommendedTemplatesImpl implements RecommendedTemplates { private static final String[] SPRING_TYPES = new String[] { diff --git a/openide.filesystems/src/org/openide/filesystems/annotations/LayerBuilder.java b/openide.filesystems/src/org/openide/filesystems/annotations/LayerBuilder.java --- a/openide.filesystems/src/org/openide/filesystems/annotations/LayerBuilder.java +++ b/openide.filesystems/src/org/openide/filesystems/annotations/LayerBuilder.java @@ -41,7 +41,6 @@ import java.io.IOException; import java.io.InputStream; -import java.io.ObjectOutputStream; import java.net.URI; import java.util.Arrays; import java.util.LinkedHashMap; @@ -142,7 +141,10 @@ if (originatingElement == null) { throw new IllegalArgumentException("Only applicable to builders with exactly one associated element"); } - TypeMirror typeMirror = type != null ? processingEnv.getElementUtils().getTypeElement(type.getName().replace('$', '.')).asType() : null; + TypeMirror typeMirror = type != null ? + processingEnv.getTypeUtils().getDeclaredType( + processingEnv.getElementUtils().getTypeElement(type.getName().replace('$', '.'))) : + null; switch (originatingElement.getKind()) { case CLASS: { String clazz = processingEnv.getElementUtils().getBinaryName((TypeElement) originatingElement).toString(); diff --git a/openide.util/src/org/openide/util/lookup/ExcludingLookup.java b/openide.util/src/org/openide/util/lookup/ExcludingLookup.java --- a/openide.util/src/org/openide/util/lookup/ExcludingLookup.java +++ b/openide.util/src/org/openide/util/lookup/ExcludingLookup.java @@ -47,6 +47,7 @@ import java.util.*; import org.openide.util.LookupEvent; +import org.openide.util.Parameters; /** Allows exclusion of certain instances from lookup. @@ -67,6 +68,9 @@ ExcludingLookup(Lookup delegate, Class[] classes) { this.delegate = delegate; + for (Class c : classes) { + Parameters.notNull("classes[x]", c); + } if (classes.length == 1) { this.classes = classes[0]; } else { diff --git a/projectapi/apichanges.xml b/projectapi/apichanges.xml --- a/projectapi/apichanges.xml +++ b/projectapi/apichanges.xml @@ -125,6 +125,28 @@ + + + Add annotations @ProjectServiceProvider and @LookupMerger.Registration + + + + +

+ Implementations of LookupProvider should be converted wherever possible. +

+
+ +

+ Added annotations to register entries to project lookup individually. + These can be used instead of implementing a LookupProvider. + Since the entries are loaded on demand, this can help avoid needless class loading. +

+
+ + + +
Add annotation @LookupProvider.Registration diff --git a/projectapi/manifest.mf b/projectapi/manifest.mf --- a/projectapi/manifest.mf +++ b/projectapi/manifest.mf @@ -1,7 +1,7 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.projectapi/1 OpenIDE-Module-Install: org/netbeans/modules/projectapi/Installer.class -OpenIDE-Module-Specification-Version: 1.22 +OpenIDE-Module-Specification-Version: 1.23 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/projectapi/layer.xml diff --git a/projectapi/src/org/netbeans/modules/projectapi/LazyLookupProviders.java b/projectapi/src/org/netbeans/modules/projectapi/LazyLookupProviders.java new file mode 100644 --- /dev/null +++ b/projectapi/src/org/netbeans/modules/projectapi/LazyLookupProviders.java @@ -0,0 +1,158 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 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 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.projectapi; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import org.netbeans.api.project.Project; +import org.netbeans.spi.project.LookupMerger; +import org.netbeans.spi.project.LookupProvider; +import org.netbeans.spi.project.ProjectServiceProvider; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; +import org.openide.util.Lookup.Template; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; + +/** + * Factory methods for lazy {@link LookupProvider} registration. + */ +public class LazyLookupProviders { + + private LazyLookupProviders() {} + + /** + * @see ProjectServiceProvider + */ + public static LookupProvider forProjectServiceProvider(final Map attrs) throws ClassNotFoundException { + return new LookupProvider() { + public Lookup createAdditionalLookup(final Lookup lkp) { + return new ProxyLookup() { + final Collection serviceNames = Arrays.asList(((String) attrs.get("service")).split(",")); // NOI18N + Class service; + protected @Override void beforeLookup(Template template) { + if (service == null && serviceNames.contains(template.getType().getName())) { // NOI18N + service = template.getType(); + try { + Object instance = loadPSPInstance((String) attrs.get("class"), (String) attrs.get("method"), lkp); // NOI18N + service.cast(instance); + setLookups(Lookups.singleton(instance)); + } catch (Exception x) { + Exceptions.printStackTrace(x); + } + } + } + }; + } + }; + } + private static Object loadPSPInstance(String implName, String methodName, Lookup lkp) throws Exception { + Class clazz = Thread.currentThread().getContextClassLoader().loadClass(implName); + if (methodName == null) { + for (Constructor c : clazz.getConstructors()) { + Object[] vals = valuesFor(c.getParameterTypes(), lkp); + if (vals != null) { + return c.newInstance(vals); + } + } + } else { + for (Method m : clazz.getMethods()) { + Object[] vals = valuesFor(m.getParameterTypes(), lkp); + if (vals != null) { + return m.invoke(null, vals); + } + } + } + throw new RuntimeException(implName + "." + methodName); // NOI18N + } + private static Object[] valuesFor(Class[] params, Lookup lkp) { + if (params.length > 2) { + return null; + } + List values = new ArrayList(); + for (Class param : params) { + if (param == Lookup.class) { + values.add(lkp); + } else if (param == Project.class) { + Project project = lkp.lookup(Project.class); + if (project == null) { + throw new IllegalArgumentException("Lookup " + lkp + " did not contain any Project instance"); + } + values.add(project); + } else { + return null; + } + } + return values.toArray(); + } + + /** + * @see org.netbeans.spi.project.LookupMerger.Registration + */ + public static MetaLookupMerger forLookupMerger(final Map attrs) throws ClassNotFoundException { + return new MetaLookupMerger() { + private LookupMerger delegate; + public boolean canNowMerge(Class service) { + if (delegate == null && service.getName().equals((String) attrs.get("service"))) { // NOI18N + try { + LookupMerger m = (LookupMerger) attrs.get("lookupMergerInstance"); // NOI18N + if (service != m.getMergeableClass()) { + throw new ClassCastException(service + " vs. " + m.getMergeableClass()); // NOI18N + } + delegate = m; + return true; + } catch (Exception x) { + Exceptions.printStackTrace(x); + } + } + return false; + } + public LookupMerger merger() { + return delegate; + } + }; + } + +} diff --git a/projectapi/src/org/netbeans/modules/projectapi/LookupProviderAnnotationProcessor.java b/projectapi/src/org/netbeans/modules/projectapi/LookupProviderAnnotationProcessor.java --- a/projectapi/src/org/netbeans/modules/projectapi/LookupProviderAnnotationProcessor.java +++ b/projectapi/src/org/netbeans/modules/projectapi/LookupProviderAnnotationProcessor.java @@ -39,17 +39,34 @@ package org.netbeans.modules.projectapi; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import java.util.Set; import javax.annotation.processing.Processor; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.annotation.processing.SupportedSourceVersion; import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; +import org.netbeans.api.project.Project; +import org.netbeans.spi.project.LookupMerger; import org.netbeans.spi.project.LookupProvider; +import org.netbeans.spi.project.ProjectServiceProvider; +import org.openide.filesystems.annotations.LayerBuilder; import org.openide.filesystems.annotations.LayerGeneratingProcessor; import org.openide.filesystems.annotations.LayerGenerationException; +import org.openide.util.Lookup; import org.openide.util.lookup.ServiceProvider; /** @@ -58,7 +75,11 @@ */ @ServiceProvider(service=Processor.class) @SupportedSourceVersion(SourceVersion.RELEASE_6) -@SupportedAnnotationTypes("org.netbeans.spi.project.LookupProvider.Registration") +@SupportedAnnotationTypes({ + "org.netbeans.spi.project.LookupProvider.Registration", + "org.netbeans.spi.project.ProjectServiceProvider", + "org.netbeans.spi.project.LookupMerger.Registration" +}) public class LookupProviderAnnotationProcessor extends LayerGeneratingProcessor { protected boolean handleProcess(Set annotations, RoundEnvironment roundEnv) throws LayerGenerationException { @@ -77,7 +98,184 @@ layer(e).instanceFile("Projects/" + type.id() + "/Lookup", null, LookupProvider.class).position(type.position()).write(); } } + for (Element e : roundEnv.getElementsAnnotatedWith(ProjectServiceProvider.class)) { + List services = findServiceAnnotation(e); + if (services.isEmpty()) { + throw new LayerGenerationException("Must specify at least one service", e); + } + String servicesBinName = null; + for (TypeMirror service : services) { + String n = processingEnv.getElementUtils().getBinaryName((TypeElement) processingEnv.getTypeUtils().asElement(service)).toString(); + if (n.equals(LookupMerger.class.getName())) { + throw new LayerGenerationException("@ProjectServiceProvider should not be used on LookupMerger; use @LookupMerger.Registration instead", e); + } + servicesBinName = servicesBinName == null ? n : servicesBinName + "," + n; + } + String[] binAndMethodNames = findPSPDefinition(e, services); + ProjectServiceProvider psp = e.getAnnotation(ProjectServiceProvider.class); + if (psp.projectType().length == 0 && psp.projectTypes().length == 0) { + throw new LayerGenerationException("You must specify either projectType or projectTypes", e); + } + String fileBaseName = binAndMethodNames[0].replace('.', '-'); + if (binAndMethodNames[1] != null) { + fileBaseName += "-" + binAndMethodNames[1]; + } + for (String type : psp.projectType()) { + LayerBuilder.File f = layer(e).file("Projects/" + type + "/Lookup/" + fileBaseName + ".instance"). + methodvalue("instanceCreate", LazyLookupProviders.class.getName(), "forProjectServiceProvider"). + stringvalue("class", binAndMethodNames[0]). + stringvalue("service", servicesBinName); + if (binAndMethodNames[1] != null) { + f.stringvalue("method", binAndMethodNames[1]); + } + f.write(); + } + for (LookupProvider.Registration.ProjectType type : psp.projectTypes()) { + LayerBuilder.File f = layer(e).file("Projects/" + type.id() + "/Lookup/" + fileBaseName + ".instance"). + methodvalue("instanceCreate", LazyLookupProviders.class.getName(), "forProjectServiceProvider"). + stringvalue("class", binAndMethodNames[0]). + stringvalue("service", servicesBinName). + position(type.position()); + if (binAndMethodNames[1] != null) { + f.stringvalue("method", binAndMethodNames[1]); + } + f.write(); + } + } + for (Element e : roundEnv.getElementsAnnotatedWith(LookupMerger.Registration.class)) { + LookupMerger.Registration lmr = e.getAnnotation(LookupMerger.Registration.class); + String fileBaseName; + DeclaredType impl; + if (e.getKind() == ElementKind.CLASS) { + fileBaseName = processingEnv.getElementUtils().getBinaryName((TypeElement) e).toString().replace('.', '-'); + impl = (DeclaredType) e.asType(); + } else { + fileBaseName = processingEnv.getElementUtils().getBinaryName((TypeElement) e.getEnclosingElement()).toString().replace('.', '-') + + "-" + e.getSimpleName().toString(); + impl = (DeclaredType) ((ExecutableElement) e).getReturnType(); + } + DeclaredType service = findLookupMergerType(impl); + if (service == null) { + throw new LayerGenerationException("Not assignable to LookupMerger for some T", e); + } + String serviceBinName = processingEnv.getElementUtils().getBinaryName((TypeElement) service.asElement()).toString(); + if (lmr.projectType().length == 0 && lmr.projectTypes().length == 0) { + throw new LayerGenerationException("You must specify either projectType or projectTypes", e); + } + for (String type : lmr.projectType()) { + layer(e).file("Projects/" + type + "/Lookup/" + fileBaseName + ".instance"). + methodvalue("instanceCreate", LazyLookupProviders.class.getName(), "forLookupMerger"). + instanceAttribute("lookupMergerInstance", LookupMerger.class). + stringvalue("service", serviceBinName). + write(); + } + for (LookupProvider.Registration.ProjectType type : lmr.projectTypes()) { + layer(e).file("Projects/" + type.id() + "/Lookup/" + fileBaseName + ".instance"). + methodvalue("instanceCreate", LazyLookupProviders.class.getName(), "forLookupMerger"). + instanceAttribute("lookupMergerInstance", LookupMerger.class). + stringvalue("service", serviceBinName). + position(type.position()). + write(); + } + } return true; } + private List findServiceAnnotation(Element e) throws LayerGenerationException { + for (AnnotationMirror ann : e.getAnnotationMirrors()) { + if (!ProjectServiceProvider.class.getName().equals(ann.getAnnotationType().toString())) { + continue; + } + for (Map.Entry attr : ann.getElementValues().entrySet()) { + if (!attr.getKey().getSimpleName().contentEquals("service")) { + continue; + } + List r = new ArrayList(); + for (Object item : (List) attr.getValue().getValue()) { + r.add((TypeMirror) ((AnnotationValue) item).getValue()); + } + return r; + } + throw new LayerGenerationException("No service attr found", e); + } + throw new LayerGenerationException("No @ProjectServiceProvider found", e); + } + + private String[] findPSPDefinition(Element e, List services) throws LayerGenerationException { + if (e.getKind() == ElementKind.CLASS) { + TypeElement clazz = (TypeElement) e; + for (TypeMirror service : services) { + if (!processingEnv.getTypeUtils().isAssignable(clazz.asType(), service)) { + throw new LayerGenerationException("Not assignable to " + service, e); + } + } + int constructorCount = 0; + CONSTRUCTOR: for (ExecutableElement constructor : ElementFilter.constructorsIn(clazz.getEnclosedElements())) { + if (!constructor.getModifiers().contains(Modifier.PUBLIC)) { + continue; + } + List params = constructor.getParameters(); + if (params.size() > 2) { + continue; + } + for (VariableElement param : params) { + if (!param.asType().equals(processingEnv.getElementUtils().getTypeElement(Project.class.getCanonicalName()).asType()) && + !param.asType().equals(processingEnv.getElementUtils().getTypeElement(Lookup.class.getCanonicalName()).asType())) { + continue CONSTRUCTOR; + } + } + constructorCount++; + } + if (constructorCount != 1) { + throw new LayerGenerationException("Must have exactly one public constructor optionally taking Project and/or Lookup", e); + } + return new String[] {processingEnv.getElementUtils().getBinaryName(clazz).toString(), null}; + } else { + ExecutableElement meth = (ExecutableElement) e; + for (TypeMirror service : services) { + if (!processingEnv.getTypeUtils().isAssignable(meth.getReturnType(), service)) { + throw new LayerGenerationException("Not assignable to " + service, e); + } + } + if (!meth.getModifiers().contains(Modifier.PUBLIC)) { + throw new LayerGenerationException("Method must be public", e); + } + if (!meth.getModifiers().contains(Modifier.STATIC)) { + throw new LayerGenerationException("Method must be static", e); + } + List params = meth.getParameters(); + if (params.size() > 2) { + throw new LayerGenerationException("Method must take at most two parameters", e); + } + for (VariableElement param : params) { + if (!param.asType().equals(processingEnv.getElementUtils().getTypeElement(Project.class.getCanonicalName()).asType()) && + !param.asType().equals(processingEnv.getElementUtils().getTypeElement(Lookup.class.getCanonicalName()).asType())) { + throw new LayerGenerationException("Method parameters may be either Lookup or Project", e); + } + } + return new String[] { + processingEnv.getElementUtils().getBinaryName((TypeElement) meth.getEnclosingElement()).toString(), + meth.getSimpleName().toString()}; + } + } + + private DeclaredType findLookupMergerType(DeclaredType t) { + String rawName = processingEnv.getTypeUtils().erasure(t).toString(); + if (rawName.equals(LookupMerger.class.getName())) { + List args = t.getTypeArguments(); + if (args.size() == 1) { + return (DeclaredType) args.get(0); + } else { + return null; + } + } + for (TypeMirror supe : processingEnv.getTypeUtils().directSupertypes(t)) { + DeclaredType result = findLookupMergerType((DeclaredType) supe); + if (result != null) { + return result; + } + } + return null; + } + } diff --git a/projectapi/src/org/netbeans/modules/projectapi/MetaLookupMerger.java b/projectapi/src/org/netbeans/modules/projectapi/MetaLookupMerger.java new file mode 100644 --- /dev/null +++ b/projectapi/src/org/netbeans/modules/projectapi/MetaLookupMerger.java @@ -0,0 +1,54 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 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 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.projectapi; + +import org.netbeans.spi.project.LookupMerger; +import org.openide.util.Lookup; + +/** + * @see LazyLookupProviders#forLookupMerger + */ +public interface MetaLookupMerger { + + boolean canNowMerge(Class service); + + LookupMerger/*|null*/ merger(); + +} diff --git a/projectapi/src/org/netbeans/spi/project/LookupMerger.java b/projectapi/src/org/netbeans/spi/project/LookupMerger.java --- a/projectapi/src/org/netbeans/spi/project/LookupMerger.java +++ b/projectapi/src/org/netbeans/spi/project/LookupMerger.java @@ -41,6 +41,11 @@ package org.netbeans.spi.project; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.netbeans.spi.project.LookupProvider.Registration.ProjectType; import org.openide.util.Lookup; /** @@ -72,4 +77,26 @@ */ T merge(Lookup lookup); + /** + * Registers a lookup merger for some project types. + * The annotated class must be assignable to {@link LookupMerger} with a type parameter. + * @since org.netbeans.modules.projectapi/1 1.23 + */ + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE, ElementType.METHOD}) + @interface Registration { + + /** + * Token(s) denoting one or more project types, e.g. {@code "org-netbeans-modules-java-j2seproject"} + */ + String[] projectType() default {}; + + /** + * Alternate registration of project types with positions. + * You must specify either this or {@link #projectType} (or both). + */ + ProjectType[] projectTypes() default {}; + + } + } diff --git a/projectapi/src/org/netbeans/spi/project/LookupProvider.java b/projectapi/src/org/netbeans/spi/project/LookupProvider.java --- a/projectapi/src/org/netbeans/spi/project/LookupProvider.java +++ b/projectapi/src/org/netbeans/spi/project/LookupProvider.java @@ -70,7 +70,10 @@ Lookup createAdditionalLookup(Lookup baseContext); /** - * Annotation to register LookupProvider instances. + * Annotation to register {@link LookupProvider} instances. + *

If you wish to unconditionally register one or more objects, + * it will be more efficient and may be easier to use + * {@link ProjectServiceProvider} (and/or {@link LookupMerger.Registration}). * @since org.netbeans.modules.projectapi 1.21 */ @Retention(RetentionPolicy.SOURCE) @@ -83,12 +86,14 @@ /** * Alternate registration of project types with positions. * You must specify either this or {@link #projectType} (or both). + * @since org.netbeans.modules.projectapi/1 1.22 */ ProjectType[] projectTypes() default {}; @Retention(RetentionPolicy.SOURCE) @Target({}) /** * Alternate individual registration for one project type. + * @since org.netbeans.modules.projectapi/1 1.22 */ @interface ProjectType { /** diff --git a/projectapi/src/org/netbeans/spi/project/ProjectServiceProvider.java b/projectapi/src/org/netbeans/spi/project/ProjectServiceProvider.java new file mode 100644 --- /dev/null +++ b/projectapi/src/org/netbeans/spi/project/ProjectServiceProvider.java @@ -0,0 +1,77 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 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 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.spi.project; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.netbeans.api.project.Project; +import org.netbeans.spi.project.LookupProvider.Registration.ProjectType; +import org.openide.util.Lookup; + +/** + * Like {@link LookupProvider} but registers a single object into a project's lookup. + * An annotated class must have one public constructor, which may take {@link Project} and/or {@link Lookup} parameters. + * An annotated factory method must have similar parameters. + * @since org.netbeans.modules.projectapi/1 1.23 + */ +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.TYPE, ElementType.METHOD}) +public @interface ProjectServiceProvider { + + /** + * Service class(es) to be registered. + * The annotated class must be assignable to the service class(es). + */ + Class[] service(); + + /** + * Token(s) denoting one or more project types, e.g. {@code "org-netbeans-modules-java-j2seproject"} + */ + String[] projectType() default {}; + + /** + * Alternate registration of project types with positions. + * You must specify either this or {@link #projectType} (or both). + */ + ProjectType[] projectTypes() default {}; + +} diff --git a/projectapi/src/org/netbeans/spi/project/support/LookupProviderSupport.java b/projectapi/src/org/netbeans/spi/project/support/LookupProviderSupport.java --- a/projectapi/src/org/netbeans/spi/project/support/LookupProviderSupport.java +++ b/projectapi/src/org/netbeans/spi/project/support/LookupProviderSupport.java @@ -54,6 +54,7 @@ import javax.swing.event.ChangeListener; import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; +import org.netbeans.modules.projectapi.MetaLookupMerger; import org.netbeans.spi.project.LookupMerger; import org.netbeans.spi.project.LookupProvider; import org.openide.ErrorManager; @@ -108,6 +109,7 @@ private List currentLookups; private Lookup.Result mergers; + private final Lookup.Result metaMergers; private Reference listenerRef; //#68623: the proxy lookup fires changes only if someone listens on a particular template: private final List> results = new ArrayList>(); @@ -121,17 +123,20 @@ assert base != null; baseLookup = base; providerResult = providerLookup.lookup(new Lookup.Template(LookupProvider.class)); + metaMergers = providerLookup.lookupResult(MetaLookupMerger.class); assert isAllJustLookupProviders(providerLookup) : "Layer content at " + path + " contains other than LookupProvider instances! See messages.log file for more details."; //NOI18N - doDelegate(providerResult.allInstances()); + doDelegate(); providerListener = new LookupListener() { public void resultChanged(LookupEvent ev) { // XXX this may need to be run asynchronously; deadlock-prone - doDelegate(providerResult.allInstances()); + doDelegate(); } }; providerResult.addLookupListener( WeakListeners.create(LookupListener.class, providerListener, providerResult)); + metaMergers.addLookupListener( + WeakListeners.create(LookupListener.class, providerListener, metaMergers)); } //just for assertion evaluation. @@ -139,7 +144,7 @@ Lookup.Result res = lkp.lookupResult(Object.class); Set> set = res.allClasses(); for (Class clzz : set) { - if (!LookupProvider.class.isAssignableFrom(clzz)) { + if (!LookupProvider.class.isAssignableFrom(clzz) && !MetaLookupMerger.class.isAssignableFrom(clzz)) { Logger.getLogger(LookupProviderSupport.class.getName()).warning("" + clzz.getName() + " is not instance of LookupProvider."); //NOI18N return false; } @@ -149,16 +154,25 @@ public void resultChanged(LookupEvent ev) { - doDelegate(providerResult.allInstances()); + doDelegate(); + } + + protected @Override void beforeLookup(Lookup.Template template) { + for (MetaLookupMerger metaMerger : metaMergers.allInstances()) { + if (metaMerger.canNowMerge(template.getType())) { + doDelegate(); + } + } } - private synchronized void doDelegate(Collection providers) { + private synchronized void doDelegate() { //unregister listeners from the old results: for (Lookup.Result r : results) { r.removeLookupListener(this); } + Collection providers = providerResult.allInstances(); List newLookups = new ArrayList(); for (LookupProvider elem : providers) { if (old.contains(elem)) { @@ -186,7 +200,14 @@ l = WeakListeners.create(LookupListener.class, this, mergers); listenerRef = new WeakReference(l); mergers.addLookupListener(l); - for (LookupMerger lm : mergers.allInstances()) { + Collection allMergers = new ArrayList(mergers.allInstances()); + for (MetaLookupMerger metaMerger : metaMergers.allInstances()) { + LookupMerger merger = metaMerger.merger(); + if (merger != null) { + allMergers.add(merger); + } + } + for (LookupMerger lm : allMergers) { Class c = lm.getMergeableClass(); if (filteredClasses.contains(c)) { ErrorManager.getDefault().log(ErrorManager.WARNING, diff --git a/projectapi/test/unit/src/org/netbeans/spi/project/support/LookupProviderSupportTest.java b/projectapi/test/unit/src/org/netbeans/spi/project/support/LookupProviderSupportTest.java --- a/projectapi/test/unit/src/org/netbeans/spi/project/support/LookupProviderSupportTest.java +++ b/projectapi/test/unit/src/org/netbeans/spi/project/support/LookupProviderSupportTest.java @@ -42,9 +42,16 @@ package org.netbeans.spi.project.support; import java.beans.PropertyChangeListener; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -58,12 +65,14 @@ import org.netbeans.junit.NbTestCase; import org.netbeans.spi.project.LookupMerger; import org.netbeans.spi.project.LookupProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileObject; import org.openide.util.Lookup; import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.InstanceContent; import org.openide.util.lookup.Lookups; import org.openide.util.test.MockChangeListener; +import org.openide.util.test.MockLookup; /** * @author mkleint @@ -285,5 +294,88 @@ public void removePropertyChangeListener(PropertyChangeListener listener) { } } + + public void testLazyProviders() throws Exception { + // Cannot simply use static initializers to tell when classes are loaded; + // these will not be run in case a service is loaded but not yet initialized. + ClassLoader l = new URLClassLoader(new URL[] { + LookupProviderSupportTest.class.getProtectionDomain().getCodeSource().getLocation()}, + LookupProviderSupportTest.class.getClassLoader()) { + protected @Override synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + if (name.startsWith(LookupProviderSupportTest.class.getName() + "$")) { + Class c = findLoadedClass(name); + if (c == null) { + // do not delegate to parent, i.e. be sure we have loaded it + c = findClass(name); + if (resolve) { + resolveClass(c); + } + loadedClasses.add(c); + } + return c; + } else { + return super.loadClass(name, resolve); + } + } + }; + Thread.currentThread().setContextClassLoader(l); + MockLookup.setInstances(l); + assertLoadedClasses(); + Lookup all = LookupProviderSupport.createCompositeLookup(Lookups.fixed("hello"), "Projects/x/Lookup"); + assertLoadedClasses(); + assertEquals("hello", all.lookup(String.class)); + assertLoadedClasses(); + Collection svcs2 = all.lookupAll(l.loadClass(Service2.class.getName())); + assertEquals(1, svcs2.size()); + assertEquals(ServiceImpl2.class.getName(), svcs2.iterator().next().getClass().getName()); + assertLoadedClasses("Service2", "ServiceImpl2"); + Collection svcs1 = all.lookupAll(l.loadClass(Service1.class.getName())); + assertLoadedClasses("MergedServiceImpl1", "Merger", "Service1", "Service2", "ServiceImpl1a", "ServiceImpl1b", "ServiceImpl2"); + assertEquals(svcs1.toString(), 1, svcs1.size()); + assertTrue(svcs1.toString(), svcs1.toString().contains("ServiceImpl1a@")); + assertTrue(svcs1.toString(), svcs1.toString().contains("ServiceImpl1b@")); + assertTrue(svcs1.toString(), svcs1.toString().contains("Merge[")); + } + private static final Set> loadedClasses = new HashSet>(); + private static void assertLoadedClasses(String... names) { + SortedSet actual = new TreeSet(); + for (Class clazz : loadedClasses) { + actual.add(clazz.getName().replaceFirst("^\\Q" + LookupProviderSupportTest.class.getName() + "$\\E", "")); + } + assertEquals(Arrays.toString(names), actual.toString()); + } + public interface Service1 {} + public interface Service2 {} + @ProjectServiceProvider(projectType="x", service=Service1.class) + public static class ServiceImpl1a implements Service1 {} + public static class ServiceImpl1b implements Service1 { + private ServiceImpl1b(boolean x) {assert x;} + @ProjectServiceProvider(projectType="x", service=Service1.class) + public static Service1 create() {return new ServiceImpl1b(true);} + } + @ProjectServiceProvider(projectType="x", service=Service2.class) + public static class ServiceImpl2 implements Service2 { + public ServiceImpl2(Lookup base) { + assertNotNull(base.lookup(String.class)); + } + } + @LookupMerger.Registration(projectType="x") + public static class Merger implements LookupMerger { + public Class getMergeableClass() { + return Service1.class; + } + public Service1 merge(final Lookup lkp) { + return new MergedServiceImpl1(lkp.lookupAll(Service1.class)); + } + } + private static class MergedServiceImpl1 implements Service1 { + private final Collection delegates; + MergedServiceImpl1(Collection delegates) { + this.delegates = delegates; + } + public @Override String toString() { + return "Merge" + delegates; + } + } } diff --git a/spring.beans/nbproject/project.xml b/spring.beans/nbproject/project.xml --- a/spring.beans/nbproject/project.xml +++ b/spring.beans/nbproject/project.xml @@ -227,7 +227,7 @@ 1 - 1.17 + 1.23 diff --git a/spring.beans/src/org/netbeans/modules/spring/beans/ProjectLookupProvider.java b/spring.beans/src/org/netbeans/modules/spring/beans/ProjectLookupProvider.java deleted file mode 100644 --- a/spring.beans/src/org/netbeans/modules/spring/beans/ProjectLookupProvider.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.spring.beans; - -import java.util.ArrayList; -import java.util.List; -import org.netbeans.api.project.Project; -import org.netbeans.spi.project.LookupProvider; -import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; - -/** - * - * @author Andrei Badea - */ -public class ProjectLookupProvider implements LookupProvider { - - private final Kind kind; - - @LookupProvider.Registration(projectType={ - "org-netbeans-modules-java-j2seproject", - "org-netbeans-modules-j2ee-ejbjarproject" - }) - public static ProjectLookupProvider standard() { - return new ProjectLookupProvider(Kind.NON_WEB); - } - - @LookupProvider.Registration(projectType="org-netbeans-modules-web-project") - public static ProjectLookupProvider web() { - return new ProjectLookupProvider(Kind.WEB); - } - - @LookupProvider.Registration(projectType="org-netbeans-modules-maven") - public static ProjectLookupProvider simple() { - return new ProjectLookupProvider(Kind.SIMPLE); - } - - private ProjectLookupProvider(Kind kind) { - this.kind = kind; - } - - public Lookup createAdditionalLookup(Lookup baseContext) { - Project project = baseContext.lookup(Project.class); - if (project == null) { - throw new IllegalStateException("Lookup " + baseContext + " does not contain a Project"); - } - List instances = new ArrayList(3); - instances.add(new ProjectSpringScopeProvider(project)); - if (kind != Kind.SIMPLE) { - instances.add(new RecommendedTemplatesImpl(kind == Kind.WEB)); - instances.add(new SpringConfigFileLocationProviderImpl(project)); - } - return Lookups.fixed(instances.toArray(new Object[instances.size()])); - } - - enum Kind { - - // For most projects. - NON_WEB, - - // For web projects, whose config file providers are provided by the Web MVC support - // (since it needs to use the WebModule API). - WEB, - - // For Maven projects, which implement everything. - SIMPLE - } -} diff --git a/spring.beans/src/org/netbeans/modules/spring/beans/ProjectSpringScopeProvider.java b/spring.beans/src/org/netbeans/modules/spring/beans/ProjectSpringScopeProvider.java --- a/spring.beans/src/org/netbeans/modules/spring/beans/ProjectSpringScopeProvider.java +++ b/spring.beans/src/org/netbeans/modules/spring/beans/ProjectSpringScopeProvider.java @@ -44,11 +44,18 @@ import org.netbeans.api.project.Project; import org.netbeans.modules.spring.api.beans.ConfigFileManager; import org.netbeans.modules.spring.api.beans.SpringScope; +import org.netbeans.spi.project.ProjectServiceProvider; /** * * @author Andrei Badea */ +@ProjectServiceProvider(service=ProjectSpringScopeProvider.class, projectType={ + "org-netbeans-modules-java-j2seproject", + "org-netbeans-modules-j2ee-ejbjarproject", + "org-netbeans-modules-web-project", + "org-netbeans-modules-maven" +}) public class ProjectSpringScopeProvider { private final Project project; diff --git a/spring.beans/src/org/netbeans/modules/spring/beans/RecommendedTemplatesImpl.java b/spring.beans/src/org/netbeans/modules/spring/beans/RecommendedTemplatesImpl.java --- a/spring.beans/src/org/netbeans/modules/spring/beans/RecommendedTemplatesImpl.java +++ b/spring.beans/src/org/netbeans/modules/spring/beans/RecommendedTemplatesImpl.java @@ -39,6 +39,7 @@ package org.netbeans.modules.spring.beans; +import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.ui.RecommendedTemplates; /** @@ -57,10 +58,23 @@ private final boolean web; - public RecommendedTemplatesImpl(boolean web) { + private RecommendedTemplatesImpl(boolean web) { this.web = web; } + @ProjectServiceProvider(service=RecommendedTemplates.class, projectType="org-netbeans-modules-web-project") + public static RecommendedTemplates forWeb() { + return new RecommendedTemplatesImpl(true); + } + + @ProjectServiceProvider(service=RecommendedTemplates.class, projectType={ + "org-netbeans-modules-java-j2seproject", + "org-netbeans-modules-j2ee-ejbjarproject" + }) + public static RecommendedTemplates forNonWeb() { + return new RecommendedTemplatesImpl(true); + } + public String[] getRecommendedTypes() { return web ? SPRING_WEB_TYPES : SPRING_TYPES; } diff --git a/spring.beans/src/org/netbeans/modules/spring/beans/SpringConfigFileLocationProviderImpl.java b/spring.beans/src/org/netbeans/modules/spring/beans/SpringConfigFileLocationProviderImpl.java --- a/spring.beans/src/org/netbeans/modules/spring/beans/SpringConfigFileLocationProviderImpl.java +++ b/spring.beans/src/org/netbeans/modules/spring/beans/SpringConfigFileLocationProviderImpl.java @@ -43,12 +43,18 @@ import org.netbeans.api.project.SourceGroup; import org.netbeans.modules.j2ee.core.api.support.SourceGroups; import org.netbeans.modules.spring.spi.beans.SpringConfigFileLocationProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileObject; /** * * @author Andrei Badea */ +@ProjectServiceProvider(service=SpringConfigFileLocationProvider.class, projectType={ + "org-netbeans-modules-java-j2seproject", + "org-netbeans-modules-j2ee-ejbjarproject", + "org-netbeans-modules-web-project" +}) public class SpringConfigFileLocationProviderImpl implements SpringConfigFileLocationProvider { private final Project project; diff --git a/spring.webmvc/nbproject/project.xml b/spring.webmvc/nbproject/project.xml --- a/spring.webmvc/nbproject/project.xml +++ b/spring.webmvc/nbproject/project.xml @@ -123,7 +123,7 @@ 1 - 1.13 + 1.23 diff --git a/spring.webmvc/src/org/netbeans/modules/spring/webmvc/ProjectLookupProvider.java b/spring.webmvc/src/org/netbeans/modules/spring/webmvc/ProjectLookupProvider.java deleted file mode 100644 --- a/spring.webmvc/src/org/netbeans/modules/spring/webmvc/ProjectLookupProvider.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.spring.webmvc; - -import org.netbeans.api.project.Project; -import org.netbeans.spi.project.LookupProvider; -import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; - -/** - * - * @author Andrei Badea - */ -@LookupProvider.Registration(projectType="org-netbeans-modules-web-project") -public class ProjectLookupProvider implements LookupProvider { - - public Lookup createAdditionalLookup(Lookup baseContext) { - Project project = baseContext.lookup(Project.class); - if (project == null) { - throw new IllegalStateException("Lookup " + baseContext + " does not contain a Project"); - } - return Lookups.singleton(new WebProjectSpringConfigFileProvider(project)); - } -} diff --git a/spring.webmvc/src/org/netbeans/modules/spring/webmvc/WebProjectSpringConfigFileProvider.java b/spring.webmvc/src/org/netbeans/modules/spring/webmvc/WebProjectSpringConfigFileProvider.java --- a/spring.webmvc/src/org/netbeans/modules/spring/webmvc/WebProjectSpringConfigFileProvider.java +++ b/spring.webmvc/src/org/netbeans/modules/spring/webmvc/WebProjectSpringConfigFileProvider.java @@ -51,6 +51,7 @@ import org.netbeans.modules.spring.spi.beans.SpringConfigFileProvider; import org.netbeans.modules.web.api.webmodule.WebModule; import org.netbeans.modules.web.spi.webmodule.WebModuleProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.NbCollections; @@ -59,6 +60,8 @@ * * @author Andrei Badea */ +@ProjectServiceProvider(service={SpringConfigFileProvider.class, SpringConfigFileLocationProvider.class}, +projectType="org-netbeans-modules-web-project") public class WebProjectSpringConfigFileProvider implements SpringConfigFileProvider, SpringConfigFileLocationProvider { private final Project project; diff --git a/visualweb.project.jsf/nbproject/project.xml b/visualweb.project.jsf/nbproject/project.xml --- a/visualweb.project.jsf/nbproject/project.xml +++ b/visualweb.project.jsf/nbproject/project.xml @@ -147,7 +147,7 @@ 1 - 1.17 + 1.23 diff --git a/visualweb.project.jsf/src/org/netbeans/modules/visualweb/project/jsf/libraries/ComplibLookupProvider.java b/visualweb.project.jsf/src/org/netbeans/modules/visualweb/project/jsf/libraries/ComplibProjectOpenedHook.java rename from visualweb.project.jsf/src/org/netbeans/modules/visualweb/project/jsf/libraries/ComplibLookupProvider.java rename to visualweb.project.jsf/src/org/netbeans/modules/visualweb/project/jsf/libraries/ComplibProjectOpenedHook.java --- a/visualweb.project.jsf/src/org/netbeans/modules/visualweb/project/jsf/libraries/ComplibLookupProvider.java +++ b/visualweb.project.jsf/src/org/netbeans/modules/visualweb/project/jsf/libraries/ComplibProjectOpenedHook.java @@ -9,24 +9,21 @@ import org.netbeans.api.project.Project; import org.netbeans.modules.visualweb.complib.api.ComplibService; -import org.netbeans.spi.project.LookupProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.ui.ProjectOpenedHook; import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; /** * Code used to initialize and clean up complibs associated with a project. * * @author Edwin Goei */ -@LookupProvider.Registration(projectType="org-netbeans-modules-web-project") -public class ComplibLookupProvider implements LookupProvider { - - public static class ComplibProjectOpenedHook extends ProjectOpenedHook { +@ProjectServiceProvider(service=ProjectOpenedHook.class, projectType="org-netbeans-modules-web-project") +public class ComplibProjectOpenedHook extends ProjectOpenedHook { private Project project; - private ComplibProjectOpenedHook(Project project) { + public ComplibProjectOpenedHook(Project project) { this.project = project; } @@ -46,16 +43,4 @@ } } - } - - public Lookup createAdditionalLookup(Lookup baseContext) { - Project project = baseContext.lookup(Project.class); - if (project == null) { - assert false : "Unable to derive Project"; - return Lookup.EMPTY; - } - - ComplibProjectOpenedHook projectOpenedHook = new ComplibProjectOpenedHook(project); - return Lookups.fixed(projectOpenedHook); - } } diff --git a/visualweb.project.jsfloader/nbproject/project.xml b/visualweb.project.jsfloader/nbproject/project.xml --- a/visualweb.project.jsfloader/nbproject/project.xml +++ b/visualweb.project.jsfloader/nbproject/project.xml @@ -78,7 +78,7 @@ 1 - 1.17 + 1.23 diff --git a/visualweb.project.jsfloader/src/org/netbeans/modules/visualweb/project/jsfloader/OpenEditOverride.java b/visualweb.project.jsfloader/src/org/netbeans/modules/visualweb/project/jsfloader/OpenEditOverride.java --- a/visualweb.project.jsfloader/src/org/netbeans/modules/visualweb/project/jsfloader/OpenEditOverride.java +++ b/visualweb.project.jsfloader/src/org/netbeans/modules/visualweb/project/jsfloader/OpenEditOverride.java @@ -42,14 +42,13 @@ import org.netbeans.core.spi.multiview.MultiViewElement; import org.netbeans.core.spi.multiview.MultiViewElementCallback; import org.netbeans.spi.project.AuxiliaryConfiguration; -import org.netbeans.spi.project.LookupProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.ui.ProjectOpenedHook; import org.openide.awt.UndoRedo; import org.openide.filesystems.FileObject; import org.openide.filesystems.URLMapper; import org.openide.loaders.DataObject; import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -59,8 +58,8 @@ * * @author quynguyen */ -@LookupProvider.Registration(projectType="org-netbeans-modules-web-project") -public final class OpenEditOverride implements LookupProvider { +@ProjectServiceProvider(service=ProjectOpenedHook.class, projectType="org-netbeans-modules-web-project") +public final class OpenEditOverride extends ProjectOpenedHook { // Taken from org.netbeans.modules.project.ui.ProjectUtilities private static final String OPEN_FILES_NS = "http://www.netbeans.org/ns/projectui-open-files/1"; // NOI18N private static final String OPEN_FILES_ELEMENT = "open-files"; // NOI18N @@ -70,11 +69,6 @@ private static WeakHashMap> multiViewsByProject = new WeakHashMap>(); - public Lookup createAdditionalLookup(Lookup baseContext) { - Project proj = baseContext.lookup(Project.class); - return Lookups.singleton(new ProjectOpenedHookImpl(proj)); - } - private static void multiViewChanged(Project fromProject, DataObject multiViewDO, String multiViewId) { HashMap projectMultiViews = multiViewsByProject.get(fromProject); @@ -89,10 +83,9 @@ multiViewsByProject.remove(proj); } - private static final class ProjectOpenedHookImpl extends ProjectOpenedHook { private WeakReference projectRef; - public ProjectOpenedHookImpl(Project project) { + public OpenEditOverride(Project project) { this.projectRef = new WeakReference(project); } @@ -149,7 +142,6 @@ unregisterProject(project); } } - } static final class MultiViewDelegate implements MultiViewElement { private final MultiViewElement originalElement; 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 @@ -275,7 +275,7 @@ 1 - 1.17 + 1.23 diff --git a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/J2SEJAXWSVersionProvider.java b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/J2SEJAXWSVersionProvider.java --- a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/J2SEJAXWSVersionProvider.java +++ b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/J2SEJAXWSVersionProvider.java @@ -63,12 +63,14 @@ import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.SourceGroup; import org.netbeans.modules.websvc.api.jaxws.project.JAXWSVersionProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileObject; /** * * @author mkuchtiak */ +@ProjectServiceProvider(service=JAXWSVersionProvider.class, projectType="org-netbeans-modules-java-j2seproject") public class J2SEJAXWSVersionProvider implements JAXWSVersionProvider{ private Project project; diff --git a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/J2SEProjectWSClientSupportProvider.java b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/J2SEProjectWSClientSupportProvider.java --- a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/J2SEProjectWSClientSupportProvider.java +++ b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/J2SEProjectWSClientSupportProvider.java @@ -48,12 +48,14 @@ import org.netbeans.modules.websvc.api.client.WebServicesClientSupport; import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportProvider; +import org.netbeans.spi.project.ProjectServiceProvider; /** Provider object to locate web service client support for j2se project. * * @author Milan Kuchtiak */ +@ProjectServiceProvider(service=WebServicesClientSupportProvider.class, projectType="org-netbeans-modules-java-j2seproject") public class J2SEProjectWSClientSupportProvider implements WebServicesClientSupportProvider { public J2SEProjectWSClientSupportProvider () { diff --git a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/J2SEWSSupportLookupProvider.java b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/J2SEWSSupportLookupProvider.java --- a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/J2SEWSSupportLookupProvider.java +++ b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/J2SEWSSupportLookupProvider.java @@ -57,6 +57,8 @@ * * @author mkuchtiak */ +// XXX could probably be converted to use @ProjectServiceProvider instead +// (would need to do some refactoring first) @LookupProvider.Registration(projectType="org-netbeans-modules-java-j2seproject") public class J2SEWSSupportLookupProvider implements LookupProvider { @@ -86,10 +88,6 @@ return Lookups.fixed(new Object[] { jaxWsClientSupportApi, jaxRpcClientSupportApi, - new J2SEProjectWSClientSupportProvider(), - new JaxWsArtifactsClassPathProvider(project), - new J2SEJAXWSVersionProvider(project), - new JaxWsSourceForBinaryQueryImpl(project, false), openHook}); } } \ No newline at end of file diff --git a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JavaEEJAXWSVersionProvider.java b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JavaEEJAXWSVersionProvider.java --- a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JavaEEJAXWSVersionProvider.java +++ b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JavaEEJAXWSVersionProvider.java @@ -56,11 +56,17 @@ import org.netbeans.modules.websvc.core.WSStackUtils; import org.netbeans.modules.websvc.wsstack.api.WSStack; import org.netbeans.modules.websvc.wsstack.jaxws.JaxWs; +import org.netbeans.spi.project.ProjectServiceProvider; /** * * @author rico */ +@ProjectServiceProvider(service=JAXWSVersionProvider.class, projectType={ + "org-netbeans-modules-web-project", + "org-netbeans-modules-j2ee-ejbjarproject", + "org-netbeans-modules-j2ee-clientproject" +}) public class JavaEEJAXWSVersionProvider implements JAXWSVersionProvider{ private Project project; diff --git a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JavaEEWSSupportLookupProvider.java b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JavaEEWSOpenHook.java rename from websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JavaEEWSSupportLookupProvider.java rename to websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JavaEEWSOpenHook.java --- a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JavaEEWSSupportLookupProvider.java +++ b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JavaEEWSOpenHook.java @@ -59,34 +59,26 @@ import org.netbeans.modules.websvc.api.jaxws.project.config.ServiceAlreadyExistsExeption; import org.netbeans.modules.websvc.core.JaxWsUtils; import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport; -import org.netbeans.spi.project.LookupProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.ui.ProjectOpenedHook; import org.openide.ErrorManager; -import org.openide.util.Lookup; import org.openide.util.RequestProcessor; -import org.openide.util.lookup.Lookups; /** - * Lookup Provider for WS Support in JavaEE project types - * * @author mkuchtiak */ - @LookupProvider.Registration(projectType={ - "org-netbeans-modules-web-project", - "org-netbeans-modules-j2ee-ejbjarproject", - "org-netbeans-modules-j2ee-clientproject" - }) -public class JavaEEWSSupportLookupProvider implements LookupProvider { +@ProjectServiceProvider(service=ProjectOpenedHook.class, projectType={ + "org-netbeans-modules-web-project", + "org-netbeans-modules-j2ee-ejbjarproject", + "org-netbeans-modules-j2ee-clientproject" +}) +public class JavaEEWSOpenHook extends ProjectOpenedHook { - /** Creates a new instance of JavaEEWSSupportLookupProvider */ - public JavaEEWSSupportLookupProvider() { + private final Project prj; + public JavaEEWSOpenHook(Project prj) { + this.prj = prj; } - public Lookup createAdditionalLookup(Lookup baseContext) { - final Project prj = baseContext.lookup(Project.class); - - ProjectOpenedHook openhook = new ProjectOpenedHook() { - PropertyChangeListener pcl; protected void projectOpened() { @@ -127,16 +119,6 @@ } } } - }; - - ProjectWebServiceNotifier servicesNotifier = new ProjectWebServiceNotifier(prj); - return Lookups.fixed( - openhook, - servicesNotifier, - new JaxWsArtifactsClassPathProvider(prj), - new JavaEEJAXWSVersionProvider(prj), - new JaxWsSourceForBinaryQueryImpl(prj, true)); - } private class WebservicesChangeListener implements PropertyChangeListener { diff --git a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JaxWsArtifactsClassPathProvider.java b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JaxWsArtifactsClassPathProvider.java --- a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JaxWsArtifactsClassPathProvider.java +++ b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JaxWsArtifactsClassPathProvider.java @@ -65,6 +65,7 @@ import org.netbeans.spi.java.classpath.ClassPathProvider; import org.netbeans.spi.java.classpath.PathResourceImplementation; import org.netbeans.spi.java.classpath.support.ClassPathSupport; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.modules.InstalledFileLocator; @@ -73,6 +74,12 @@ * * @author mkuchtiak */ +@ProjectServiceProvider(service=ClassPathProvider.class, projectType={ + "org-netbeans-modules-web-project", + "org-netbeans-modules-j2ee-ejbjarproject", + "org-netbeans-modules-j2ee-clientproject", + "org-netbeans-modules-java-j2seproject" +}) public class JaxWsArtifactsClassPathProvider implements ClassPathProvider { private Project project; private ClassPath sourceCP, compileCP, bootCP, executeCP; @@ -84,7 +91,7 @@ }; private static final Logger LOG = Logger.getLogger(JaxWsArtifactsClassPathProvider.class.getName()); - JaxWsArtifactsClassPathProvider(Project project) { + public JaxWsArtifactsClassPathProvider(Project project) { this.project = project; } diff --git a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JaxWsSourceForBinaryQueryImpl.java b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JaxWsSourceForBinaryQueryImpl.java --- a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JaxWsSourceForBinaryQueryImpl.java +++ b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/JaxWsSourceForBinaryQueryImpl.java @@ -63,6 +63,7 @@ import org.netbeans.api.project.ant.AntArtifact; import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport; import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; +import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.ant.AntArtifactProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileStateInvalidException; @@ -80,12 +81,26 @@ private boolean hasServiceArtifacts; private Set jarArtifacts = new HashSet(); + @ProjectServiceProvider(service=SourceForBinaryQueryImplementation.class, projectType="org-netbeans-modules-java-j2seproject") + public static SourceForBinaryQueryImplementation forJavaSE(Project project) { + return new JaxWsSourceForBinaryQueryImpl(project, false); + } + + @ProjectServiceProvider(service=SourceForBinaryQueryImplementation.class, projectType={ + "org-netbeans-modules-web-project", + "org-netbeans-modules-j2ee-ejbjarproject", + "org-netbeans-modules-j2ee-clientproject" + }) + public static SourceForBinaryQueryImplementation forJavaEE(Project project) { + return new JaxWsSourceForBinaryQueryImpl(project, true); + } + /** Constructor. * * @param project Project instance * @param hasServiceArtifacts true if project can contain services generated from WSDL */ - JaxWsSourceForBinaryQueryImpl(Project project, boolean hasServiceArtifacts) { + private JaxWsSourceForBinaryQueryImpl(Project project, boolean hasServiceArtifacts) { this.project = project; this.hasServiceArtifacts = hasServiceArtifacts; } diff --git a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/ProjectWebServiceNotifier.java b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/ProjectWebServiceNotifier.java --- a/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/ProjectWebServiceNotifier.java +++ b/websvc.core/src/org/netbeans/modules/websvc/core/jaxws/projects/ProjectWebServiceNotifier.java @@ -53,6 +53,7 @@ import org.netbeans.modules.websvc.wsstack.api.WSStack; import org.netbeans.modules.websvc.wsstack.jaxws.JaxWs; import org.netbeans.modules.websvc.wsstack.jaxws.JaxWsStackProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; @@ -60,6 +61,11 @@ * * @author mkuchtiak */ +@ProjectServiceProvider(service=WebServiceNotifier.class, projectType={ + "org-netbeans-modules-web-project", + "org-netbeans-modules-j2ee-ejbjarproject", + "org-netbeans-modules-j2ee-clientproject" +}) public class ProjectWebServiceNotifier implements WebServiceNotifier { private static final String J2EE_SERVER_INSTANCE = "j2ee.server.instance"; //NOI18N diff --git a/websvc.jaxrpc/nbproject/project.xml b/websvc.jaxrpc/nbproject/project.xml --- a/websvc.jaxrpc/nbproject/project.xml +++ b/websvc.jaxrpc/nbproject/project.xml @@ -190,7 +190,7 @@ 1 - 1.12 + 1.23 diff --git a/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/project/JaxRpcArtifactsClassPathProvider.java b/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/project/JaxRpcArtifactsClassPathProvider.java --- a/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/project/JaxRpcArtifactsClassPathProvider.java +++ b/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/project/JaxRpcArtifactsClassPathProvider.java @@ -57,6 +57,7 @@ import org.netbeans.spi.java.classpath.ClassPathProvider; import org.netbeans.spi.java.classpath.PathResourceImplementation; import org.netbeans.spi.java.classpath.support.ClassPathSupport; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.modules.InstalledFileLocator; @@ -65,13 +66,19 @@ * * @author mkuchtiak */ +@ProjectServiceProvider(service=ClassPathProvider.class, projectType={ + "org-netbeans-modules-java-j2seproject", + "org-netbeans-modules-web-project", + "org-netbeans-modules-j2ee-ejbjarproject", + "org-netbeans-modules-j2ee-clientproject" +}) public class JaxRpcArtifactsClassPathProvider implements ClassPathProvider { private Project project; private ClassPath sourceCP, compileCP, bootCP, executeCP; private static final Logger LOG = Logger.getLogger(JaxRpcArtifactsClassPathProvider.class.getName()); - JaxRpcArtifactsClassPathProvider(Project project) { + public JaxRpcArtifactsClassPathProvider(Project project) { this.project = project; } diff --git a/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/project/JaxRpcLookupProvider.java b/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/project/JaxRpcLookupProvider.java deleted file mode 100644 --- a/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/project/JaxRpcLookupProvider.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * 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 2007 Sun Microsystems, Inc. - */ -package org.netbeans.modules.websvc.jaxrpc.project; - -import org.netbeans.api.project.Project; - -import org.netbeans.spi.project.LookupProvider; -import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; - -/** - * Lookup Provider provided by JAX-RPC Support for all projects - * - * @author mkuchtiak - */ -@LookupProvider.Registration(projectType={ - "org-netbeans-modules-java-j2seproject", - "org-netbeans-modules-web-project", - "org-netbeans-modules-j2ee-ejbjarproject", - "org-netbeans-modules-j2ee-clientproject" -}) -public class JaxRpcLookupProvider implements LookupProvider { - - public Lookup createAdditionalLookup(Lookup baseContext) { - final Project prj = baseContext.lookup(Project.class); - - return Lookups.fixed(new Object[]{new JaxRpcArtifactsClassPathProvider(prj), new JaxRpcSourceForBinaryQuery()}); - } - -} diff --git a/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/project/JaxRpcSourceForBinaryQuery.java b/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/project/JaxRpcSourceForBinaryQuery.java --- a/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/project/JaxRpcSourceForBinaryQuery.java +++ b/websvc.jaxrpc/src/org/netbeans/modules/websvc/jaxrpc/project/JaxRpcSourceForBinaryQuery.java @@ -49,6 +49,7 @@ import org.netbeans.api.project.Project; import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport; import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -56,6 +57,12 @@ * * @author mkuchtiak */ +@ProjectServiceProvider(service=SourceForBinaryQueryImplementation.class, projectType={ + "org-netbeans-modules-java-j2seproject", + "org-netbeans-modules-web-project", + "org-netbeans-modules-j2ee-ejbjarproject", + "org-netbeans-modules-j2ee-clientproject" +}) public class JaxRpcSourceForBinaryQuery implements SourceForBinaryQueryImplementation { private final Map cache = new HashMap(); diff --git a/websvc.rest/nbproject/project.xml b/websvc.rest/nbproject/project.xml --- a/websvc.rest/nbproject/project.xml +++ b/websvc.rest/nbproject/project.xml @@ -209,7 +209,7 @@ 1 - 1.12 + 1.23 diff --git a/websvc.rest/src/org/netbeans/modules/websvc/rest/projects/WebProjectRestSupport.java b/websvc.rest/src/org/netbeans/modules/websvc/rest/projects/WebProjectRestSupport.java --- a/websvc.rest/src/org/netbeans/modules/websvc/rest/projects/WebProjectRestSupport.java +++ b/websvc.rest/src/org/netbeans/modules/websvc/rest/projects/WebProjectRestSupport.java @@ -71,6 +71,7 @@ import org.netbeans.modules.websvc.wsstack.api.WSTool; import org.netbeans.modules.websvc.wsstack.jaxrs.JaxRs; import org.netbeans.modules.websvc.wsstack.jaxrs.JaxRsStackProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.libraries.LibraryFactory; import org.netbeans.spi.project.libraries.LibraryImplementation; import org.netbeans.spi.project.libraries.support.LibrariesSupport; @@ -83,6 +84,7 @@ * * @author Nam Nguyen */ +@ProjectServiceProvider(service=RestSupport.class, projectType="org-netbeans-modules-web-project") public class WebProjectRestSupport extends RestSupport { public static final String J2EE_SERVER_INSTANCE = "j2ee.server.instance"; //NOI18N diff --git a/websvc.rest/src/org/netbeans/modules/websvc/rest/projects/WebRestSupportLookupProvider.java b/websvc.rest/src/org/netbeans/modules/websvc/rest/projects/WebRestSupportLookupProvider.java deleted file mode 100644 --- a/websvc.rest/src/org/netbeans/modules/websvc/rest/projects/WebRestSupportLookupProvider.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - -package org.netbeans.modules.websvc.rest.projects; - -import org.netbeans.api.project.Project; -import org.netbeans.modules.websvc.rest.spi.RestSupport; -import org.netbeans.spi.project.LookupProvider; -import org.netbeans.spi.project.ui.PrivilegedTemplates; -import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; - -/** Lookup Provider for WS Support - * - * @author mkuchtiak - */ -@LookupProvider.Registration(projectType="org-netbeans-modules-web-project") -public class WebRestSupportLookupProvider implements LookupProvider { - - /** Creates a new instance of JaxWSLookupProvider */ - public WebRestSupportLookupProvider() { - } - - public Lookup createAdditionalLookup(Lookup baseContext) { - final Project prj = baseContext.lookup(Project.class); - final RestSupport restSupport = new WebProjectRestSupport(prj); - -// PrivilegedTemplates templates = new PrivilegedTemplates() { -// public String[] getPrivilegedTemplates() { -// return new String[] { -// "Templates/WebServices/RestServicesFromEntities", // NOI18N -// "Templates/WebServices/RestServicesFromPatterns" //NOI18N -// //"Templates/WebServices/RestClientStubs" //NOI18N -// }; -// } -// }; - - //ProjectRestServiceNotifier servicesNotifier = new ProjectRestServiceNotifier(prj); - return Lookups.fixed(new Object[] {restSupport}); - } - -} diff --git a/xml.jaxb/nbproject/project.xml b/xml.jaxb/nbproject/project.xml --- a/xml.jaxb/nbproject/project.xml +++ b/xml.jaxb/nbproject/project.xml @@ -149,7 +149,7 @@ 1 - 1.9.12 + 1.23 @@ -348,7 +348,7 @@ org.netbeans.modules.jellytools - + org.netbeans.modules.jellytools.platform diff --git a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBGenSourceClassPathProvider.java b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBGenSourceClassPathProvider.java --- a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBGenSourceClassPathProvider.java +++ b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBGenSourceClassPathProvider.java @@ -34,6 +34,7 @@ import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; import org.netbeans.spi.java.classpath.ClassPathProvider; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -41,6 +42,11 @@ * * @author gpatil */ +@ProjectServiceProvider(service=ClassPathProvider.class, projectType={ + "org-netbeans-modules-java-j2seproject", + "org-netbeans-modules-web-project", + "org-netbeans-modules-j2ee-ejbjarproject" +}) public class JAXBGenSourceClassPathProvider implements ClassPathProvider { private static final String JAXB_GEN_SRC_ROOT = "/generated/addons/jaxb"; //NOI18N private static ThreadLocal inAPICall = new ThreadLocal() { @@ -54,7 +60,7 @@ private ClassPath sourceCP, compileCP, bootCP; private String buildDir = "build" ; //NOI18N private String jaxbSrcGenDir = buildDir + JAXB_GEN_SRC_ROOT; - JAXBGenSourceClassPathProvider(Project project) { + public JAXBGenSourceClassPathProvider(Project project) { this.project = project; //TODO get/update buildDir, JAXB_SRC_GEN_DIR } diff --git a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizLookupProvider.java b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizLookupProvider.java deleted file mode 100644 --- a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizLookupProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * Portions Copyrighted 2007 Sun Microsystems, Inc. - */ -package org.netbeans.modules.xml.jaxb.model; - -import org.netbeans.api.project.Project; -import org.netbeans.modules.xml.jaxb.api.model.JAXBWizModel; -import org.netbeans.spi.project.LookupProvider; -import org.netbeans.spi.project.ui.ProjectOpenedHook; -import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; - -/** - * - * @author gpatil - */ -@LookupProvider.Registration(projectType={ - "org-netbeans-modules-java-j2seproject", - "org-netbeans-modules-web-project", - "org-netbeans-modules-j2ee-ejbjarproject" -}) -public class JAXBWizLookupProvider implements LookupProvider { - - public Lookup createAdditionalLookup(Lookup baseContext) { - Project project = baseContext.lookup(Project.class); - JAXBWizModel model = new JAXBWizModelImpl(project); - JAXBGenSourceClassPathProvider cpProvider = - new JAXBGenSourceClassPathProvider(project); - JAXBWizSourceForBinaryQueryImpl sfbq = new JAXBWizSourceForBinaryQueryImpl(); - ProjectOpenedHook poh = new JAXBWizProjectOpenedHookImpl(project); - return Lookups.fixed(new Object[] {model, cpProvider, sfbq, poh}); - } -} diff --git a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizModelImpl.java b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizModelImpl.java --- a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizModelImpl.java +++ b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizModelImpl.java @@ -37,6 +37,7 @@ import org.netbeans.modules.xml.jaxb.cfg.schema.Schemas; import org.netbeans.modules.xml.jaxb.model.events.JAXBWizEventImpl; import org.netbeans.modules.xml.jaxb.util.ProjectHelper; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileChangeAdapter; import org.openide.filesystems.FileEvent; import org.openide.filesystems.FileObject; @@ -46,6 +47,11 @@ * * @author gpatil */ +@ProjectServiceProvider(service=JAXBWizModel.class, projectType={ + "org-netbeans-modules-java-j2seproject", + "org-netbeans-modules-web-project", + "org-netbeans-modules-j2ee-ejbjarproject" +}) public class JAXBWizModelImpl implements JAXBWizModel { private List listeners = null; private Project project; diff --git a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizProjectOpenedHookImpl.java b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizProjectOpenedHookImpl.java --- a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizProjectOpenedHookImpl.java +++ b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizProjectOpenedHookImpl.java @@ -44,12 +44,18 @@ import org.netbeans.modules.xml.jaxb.cfg.schema.Schemas; import org.netbeans.modules.xml.jaxb.util.JAXBWizModuleConstants; import org.netbeans.modules.xml.jaxb.util.ProjectHelper; +import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.ui.ProjectOpenedHook; /** * * @author gpatil */ +@ProjectServiceProvider(service=ProjectOpenedHook.class, projectType={ + "org-netbeans-modules-java-j2seproject", + "org-netbeans-modules-web-project", + "org-netbeans-modules-j2ee-ejbjarproject" +}) public class JAXBWizProjectOpenedHookImpl extends ProjectOpenedHook{ private Project prj; diff --git a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizSourceForBinaryQueryImpl.java b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizSourceForBinaryQueryImpl.java --- a/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizSourceForBinaryQueryImpl.java +++ b/xml.jaxb/src/org/netbeans/modules/xml/jaxb/model/JAXBWizSourceForBinaryQueryImpl.java @@ -49,6 +49,7 @@ import org.netbeans.modules.xml.jaxb.cfg.schema.Schemas; import org.netbeans.modules.xml.jaxb.util.ProjectHelper; import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; +import org.netbeans.spi.project.ProjectServiceProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -56,6 +57,11 @@ * * @author gpatil */ +@ProjectServiceProvider(service=SourceForBinaryQueryImplementation.class, projectType={ + "org-netbeans-modules-java-j2seproject", + "org-netbeans-modules-web-project", + "org-netbeans-modules-j2ee-ejbjarproject" +}) public class JAXBWizSourceForBinaryQueryImpl implements SourceForBinaryQueryImplementation { private final Map cache = new HashMap();