# HG changeset patch # User Milos Kleint # Date 1225895295 -3600 # Node ID f84dd9421ee5a9733b03a2ee68088805962c2f5e # Parent 7fe5cbc7e421f9152732ea16ed9b5f2064088bfe #152392 add the LookupProvider.Register annotation api and implementation diff -r 7fe5cbc7e421 -r f84dd9421ee5 projectapi/apichanges.xml --- a/projectapi/apichanges.xml Wed Nov 05 11:07:58 2008 +0100 +++ b/projectapi/apichanges.xml Wed Nov 05 15:28:15 2008 +0100 @@ -104,6 +104,22 @@ + + + + Add annotation @LookupProvider.Register + + + + + +

+ Add annotation @LookupProvider.Register to replace registration in layer files. +

+
+ + +
diff -r 7fe5cbc7e421 -r f84dd9421ee5 projectapi/manifest.mf --- a/projectapi/manifest.mf Wed Nov 05 11:07:58 2008 +0100 +++ b/projectapi/manifest.mf Wed Nov 05 15:28:15 2008 +0100 @@ -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.20 +OpenIDE-Module-Specification-Version: 1.21 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/projectapi/layer.xml diff -r 7fe5cbc7e421 -r f84dd9421ee5 projectapi/nbproject/project.properties --- a/projectapi/nbproject/project.properties Wed Nov 05 11:07:58 2008 +0100 +++ b/projectapi/nbproject/project.properties Wed Nov 05 15:28:15 2008 +0100 @@ -43,6 +43,7 @@ javac.source=1.5 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml +cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar # masterfs needed for the usual reasons; core.jar needed for ArchiveURLMapper: test.unit.run.cp.extra=${core.startup.dir}/core/core.jar:${o.n.bootstrap.dir}/lib/boot.jar diff -r 7fe5cbc7e421 -r f84dd9421ee5 projectapi/src/org/netbeans/modules/projectapi/LookupProviderAnnotationProcessor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/projectapi/src/org/netbeans/modules/projectapi/LookupProviderAnnotationProcessor.java Wed Nov 05 15:28:15 2008 +0100 @@ -0,0 +1,78 @@ +/* + * 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.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.Element; +import javax.lang.model.element.TypeElement; +import org.netbeans.spi.project.LookupProvider; +import org.openide.filesystems.annotations.LayerGeneratingProcessor; +import org.openide.filesystems.annotations.LayerGenerationException; +import org.openide.util.lookup.ServiceProvider; + +/** + * processor for LookupProvider.Register annotation. + * @author mkleint + */ +@ServiceProvider(service=Processor.class) +@SupportedSourceVersion(SourceVersion.RELEASE_6) +@SupportedAnnotationTypes("org.netbeans.spi.project.LookupProvider.Register") +public class LookupProviderAnnotationProcessor extends LayerGeneratingProcessor { + + @Override + protected boolean handleProcess(Set annotations, RoundEnvironment roundEnv) throws LayerGenerationException { + if (roundEnv.processingOver()) { + return false; + } + for (Element e : roundEnv.getElementsAnnotatedWith(LookupProvider.Register.class)) { + LookupProvider.Register lpr = e.getAnnotation(LookupProvider.Register.class); + for (String type : lpr.projectType()) { + layer(e).instanceFile("Projects/" + type + "/Lookup", null, LookupProvider.class).write(); + } + } + return true; + } + +} diff -r 7fe5cbc7e421 -r f84dd9421ee5 projectapi/src/org/netbeans/spi/project/LookupProvider.java --- a/projectapi/src/org/netbeans/spi/project/LookupProvider.java Wed Nov 05 11:07:58 2008 +0100 +++ b/projectapi/src/org/netbeans/spi/project/LookupProvider.java Wed Nov 05 15:28:15 2008 +0100 @@ -64,4 +64,17 @@ * @return a {@link org.openide.util.Lookup} instance that is to be added to the project's lookup, never null. */ Lookup createAdditionalLookup(Lookup baseContext); + + /** + * annotation to register LookupProvider instances. + * @since org.netbeans.modules.projectapi 1.21 + */ + public @interface Register { + /** + * token(s) denoting one or more project types, eg. org-netbeans-modules-maven or org-netbeans-modules-java-j2seproject + * @return + */ + String[] projectType(); + } + }