diff --git a/api.java/apichanges.xml b/api.java/apichanges.xml --- a/api.java/apichanges.xml +++ b/api.java/apichanges.xml @@ -2,7 +2,7 @@ + + + Introducing AptQuery + + + + + +

Adding AptQuery return annotation processing options for a given file/folder. +

+
+ + + +
Introducing JavaClassPathConstants.PROCESSOR_PATH diff --git a/api.java/manifest.mf b/api.java/manifest.mf --- a/api.java/manifest.mf +++ b/api.java/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.api.java/1 -OpenIDE-Module-Specification-Version: 1.24 +OpenIDE-Module-Specification-Version: 1.25 OpenIDE-Module-Localizing-Bundle: org/netbeans/api/java/queries/Bundle.properties AutoUpdate-Show-In-Client: false diff --git a/api.java/nbproject/project.xml b/api.java/nbproject/project.xml --- a/api.java/nbproject/project.xml +++ b/api.java/nbproject/project.xml @@ -47,6 +47,15 @@ org.netbeans.api.java + org.netbeans.api.annotations.common + + + + 1 + 1.4 + + + org.netbeans.api.java.classpath diff --git a/api.java/src/org/netbeans/api/java/queries/AptQuery.java b/api.java/src/org/netbeans/api/java/queries/AptQuery.java new file mode 100644 --- /dev/null +++ b/api.java/src/org/netbeans/api/java/queries/AptQuery.java @@ -0,0 +1,127 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ + +package org.netbeans.api.java.queries; + +import javax.swing.event.ChangeListener; +import org.netbeans.api.annotations.common.CheckForNull; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.api.java.classpath.JavaClassPathConstants; +import org.netbeans.spi.java.queries.AptQueryImplementation; +import org.openide.filesystems.FileObject; +import org.openide.util.Lookup; +import org.openide.util.Parameters; + +/**Return annotation processing configuration for given Java file, package or source folder. + * + * @author Jan Lahoda + * @since org.netbeans.api.java/1 1.25 + */ +public class AptQuery { + + /** + * Returns annotation processing configuration for Java file, Java package or source folder. + * @param file Java source file, Java package or source folder in question + * @return annotation processing configuration. Never null. + */ + public static @NonNull Result getAptOptions(@NonNull FileObject file) { + Parameters.notNull("file", file); + + for (AptQueryImplementation i : Lookup.getDefault().lookupAll(AptQueryImplementation.class)) { + Result r = i.getAptOptions(file); + + if (r != null) { + return r; + } + } + + return EMPTY; + } + + /**Annotation processing configuration. The processor path is returned from + * {@link ClassPath#getClassPath(org.openide.filesystems.FileObject, java.lang.String)} + * for {@link JavaClassPathConstants#PROCESSOR_PATH}. + * + */ + public static interface Result { + + /**Whether the annotation processors should be run inside Java editor. + * + * @return true if and only if the annotation processors should be run inside the Java editor + */ + public boolean annotationProcessingEnabled(); + + /**Which annotation processors should be run. + * + * @return if null, run all annotation processors found on the {@link JavaClassPathConstants#PROCESSOR_PATH}, + * otherwise only the selected processors will be run. The values should be binary names of the + * annotation processors. + */ + public @CheckForNull Iterable annotationProcessorsToRun(); + + /**Add a {@link ChangeListener}. + * + * @param l the listener + */ + public void addChangeListener(@NonNull ChangeListener l); + + /**Remove a {@link ChangeListener}. + * + * @param l the listener + */ + public void removeChangeListener(@NonNull ChangeListener l); + } + + private static final Result EMPTY = new Result() { + public boolean annotationProcessingEnabled() { + return true; + } + + public Iterable annotationProcessorsToRun() { + return null; + } + + public void addChangeListener(ChangeListener l) {} + public void removeChangeListener(ChangeListener l) {} + + }; + + private AptQuery() {} +} diff --git a/api.java/src/org/netbeans/spi/java/queries/AptQueryImplementation.java b/api.java/src/org/netbeans/spi/java/queries/AptQueryImplementation.java new file mode 100644 --- /dev/null +++ b/api.java/src/org/netbeans/spi/java/queries/AptQueryImplementation.java @@ -0,0 +1,61 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ + +package org.netbeans.spi.java.queries; + +import org.netbeans.api.java.queries.AptQuery; +import org.netbeans.api.java.queries.AptQuery.Result; +import org.openide.filesystems.FileObject; + +/**SPI for the {@link AptQuery}. + * + * @author Jan Lahoda + * @since org.netbeans.api.java/1 1.25 + */ +public interface AptQueryImplementation { + + /**Return the annotation processing configuration, or null if the current + * provider cannot provide configuration for the given file/folder. + * + * @param file Java source file, Java package or source folder in question + * @return non-null Result if this provider can provide annotation processing configuration for the given file/folder. + */ + public Result getAptOptions(FileObject file); + +} diff --git a/java.api.common/apichanges.xml b/java.api.common/apichanges.xml --- a/java.api.common/apichanges.xml +++ b/java.api.common/apichanges.xml @@ -103,6 +103,25 @@ + + + Support for AptQuery + + + + + +

+ Adding support for AptQuery, and related API changes. +

+
+ + + + + +
+ Add support for endorsed libraries diff --git a/java.api.common/manifest.mf b/java.api.common/manifest.mf --- a/java.api.common/manifest.mf +++ b/java.api.common/manifest.mf @@ -1,4 +1,4 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.java.api.common/0 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/api/common/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 1.13 +OpenIDE-Module-Specification-Version: 1.14 diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/classpath/ClassPathProviderImpl.java b/java.api.common/src/org/netbeans/modules/java/api/common/classpath/ClassPathProviderImpl.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/classpath/ClassPathProviderImpl.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/classpath/ClassPathProviderImpl.java @@ -46,6 +46,7 @@ import java.util.Map; import java.util.HashMap; import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.api.java.classpath.JavaClassPathConstants; import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.SourceGroup; import org.netbeans.modules.java.api.common.SourceRoots; @@ -71,6 +72,7 @@ private String distJar = "dist.jar"; // NOI18N private String buildTestClassesDir = "build.test.classes.dir"; // NOI18N private String[] javacClasspath = new String[]{"javac.classpath"}; //NOI18N + private String[] processorClasspath = new String[]{ProjectProperties.JAVAC_PROCESSORPATH}; //NOI18N private String[] javacTestClasspath = new String[]{"javac.test.classpath"}; //NOI18N private String[] runClasspath = new String[]{"run.classpath"}; //NOI18N private String[] runTestClasspath = new String[]{"run.test.classpath"}; //NOI18N @@ -93,8 +95,10 @@ * 6 - execute class path for dist.jar * 7 - boot class path * 8 - endorsed class path + * 9 - processor path + * 10 - test processor path */ - private final ClassPath[] cache = new ClassPath[9]; + private final ClassPath[] cache = new ClassPath[11]; private final Map dirCache = new HashMap(); @@ -143,11 +147,36 @@ String buildClassesDir, String distJar, String buildTestClassesDir, String[] javacClasspath, String[] javacTestClasspath, String[] runClasspath, String[] runTestClasspath, String[] endorsedClasspath) { + this(helper, + evaluator, + sourceRoots, + testSourceRoots, + buildClassesDir, + distJar, + buildTestClassesDir, + javacClasspath, + javacClasspath, + javacTestClasspath, + runClasspath, + runTestClasspath, + new String[]{ProjectProperties.ENDORSED_CLASSPATH}); + } + + /** + * Constructor allowing customization of processorPath. + * @since org.netbeans.modules.java.api.common/0 1.14 + */ + public ClassPathProviderImpl(AntProjectHelper helper, PropertyEvaluator evaluator, + SourceRoots sourceRoots, SourceRoots testSourceRoots, + String buildClassesDir, String distJar, String buildTestClassesDir, + String[] javacClasspath, String[] processorPath, String[] javacTestClasspath, String[] runClasspath, + String[] runTestClasspath, String[] endorsedClasspath) { this(helper, evaluator, sourceRoots, testSourceRoots); this.buildClassesDir = buildClassesDir; this.distJar = distJar; this.buildTestClassesDir = buildTestClassesDir; this.javacClasspath = javacClasspath; + this.processorClasspath = processorPath; this.javacTestClasspath = javacTestClasspath; this.runClasspath = runClasspath; this.runTestClasspath = runTestClasspath; @@ -270,6 +299,33 @@ return cp; } + private ClassPath getProcessorClasspath(FileObject file) { + int type = getType(file); + return this.getProcessorClasspath(type); + } + + private synchronized ClassPath getProcessorClasspath(int type) { + if (type < 0 || type > 1) { + // Not a source file. + return null; + } + ClassPath cp = cache[9+type]; + if ( cp == null) { + if (type == 0) { + cp = ClassPathFactory.createClassPath( + ProjectClassPathSupport.createPropertyBasedClassPathImplementation( + projectDirectory, evaluator, processorClasspath)); // NOI18N + } + else { + cp = ClassPathFactory.createClassPath( + ProjectClassPathSupport.createPropertyBasedClassPathImplementation( + projectDirectory, evaluator, /*XXX*/processorClasspath)); // NOI18N + } + cache[9+type] = cp; + } + return cp; + } + private ClassPath getRunTimeClasspath(FileObject file) { int type = getType(file); if (type < 0 || type > 4) { @@ -366,6 +422,8 @@ public ClassPath findClassPath(FileObject file, String type) { if (type.equals(ClassPath.COMPILE)) { return getCompileTimeClasspath(file); + } else if (type.equals(JavaClassPathConstants.PROCESSOR_PATH)) { + return getProcessorClasspath(file); } else if (type.equals(ClassPath.EXECUTE)) { return getRunTimeClasspath(file); } else if (type.equals(ClassPath.SOURCE)) { @@ -395,6 +453,12 @@ l[1] = getCompileTimeClasspath(1); return l; } + if (JavaClassPathConstants.PROCESSOR_PATH.equals(type)) { + ClassPath[] l = new ClassPath[2]; + l[0] = getProcessorClasspath(0); + l[1] = getProcessorClasspath(1); + return l; + } if (ClassPath.SOURCE.equals(type)) { ClassPath[] l = new ClassPath[2]; l[0] = getSourcepath(0); @@ -417,6 +481,9 @@ if (ClassPath.COMPILE.equals(type)) { return getCompileTimeClasspath(0); } + if (JavaClassPathConstants.PROCESSOR_PATH.equals(type)) { + return getProcessorClasspath(0); + } if (ClassPath.SOURCE.equals(type)) { return getSourcepath(0); } @@ -437,7 +504,7 @@ } else if (ClassPath.EXECUTE.equals(type)) { return runTestClasspath; - } + }//XXX: processor path else { return null; } @@ -449,6 +516,9 @@ else if (ClassPath.EXECUTE.equals(type)) { return runClasspath; } + else if (JavaClassPathConstants.PROCESSOR_PATH.equals(type)) { + return processorClasspath; + } else { return null; } @@ -469,6 +539,9 @@ else if (ClassPath.EXECUTE.equals(type)) { return runClasspath; } + else if (JavaClassPathConstants.PROCESSOR_PATH.equals(type)) { + return processorClasspath; + } else { return null; } diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/project/ProjectProperties.java b/java.api.common/src/org/netbeans/modules/java/api/common/project/ProjectProperties.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/project/ProjectProperties.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/project/ProjectProperties.java @@ -53,7 +53,27 @@ */ public final class ProjectProperties { + /** + * @since org.netbeans.modules.java.api.common/0 1.14 + */ + public static final String APT_ENABLED = "apt.enabled"; //NOI18N + /** + * @since org.netbeans.modules.java.api.common/0 1.14 + */ + public static final String APT_ENABLED_IN_EDITOR = "apt.enabled.in.editor"; //NOI18N + /** + * @since org.netbeans.modules.java.api.common/0 1.14 + */ + public static final String APT_RUN_ALL_PROCESSORS = "apt.run.all.processors"; //NOI18N + /** + * @since org.netbeans.modules.java.api.common/0 1.14 + */ + public static final String APT_PROCESSORS_LIST = "apt.processors.list"; //NOI18N public static final String JAVAC_CLASSPATH = "javac.classpath"; //NOI18N + /** + * @since org.netbeans.modules.java.api.common/0 1.14 + */ + public static final String JAVAC_PROCESSORPATH = "javac.processorpath"; //NOI18N public static final String JAVAC_TEST_CLASSPATH = "javac.test.classpath"; // NOI18N public static final String RUN_CLASSPATH = "run.classpath"; // NOI18N public static final String RUN_TEST_CLASSPATH = "run.test.classpath"; // NOI18N @@ -63,6 +83,7 @@ public static final String[] WELL_KNOWN_PATHS = new String[] { "${" + JAVAC_CLASSPATH + "}", // NOI18N + "${" + JAVAC_PROCESSORPATH + "}", // NOI18N "${" + JAVAC_TEST_CLASSPATH + "}", // NOI18N "${" + RUN_CLASSPATH + "}", // NOI18N "${" + RUN_TEST_CLASSPATH + "}", // NOI18N diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/EditMediator.java b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/EditMediator.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/EditMediator.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/EditMediator.java @@ -111,6 +111,7 @@ private final ButtonModel moveUp; private final ButtonModel moveDown; private final ButtonModel edit; + private final boolean allowRemoveClassPath; private Document libraryPath; private ClassPathUiSupport.Callback callback; private AntProjectHelper helper; @@ -131,6 +132,7 @@ ButtonModel moveUp, ButtonModel moveDown, ButtonModel edit, + boolean allowRemoveClassPath, Document libPath, ClassPathUiSupport.Callback callback, String[] antArtifactTypes, @@ -157,6 +159,7 @@ this.filter = filter; this.fileSelectionMode = fileSelectionMode; this.antArtifactTypes = antArtifactTypes; + this.allowRemoveClassPath = allowRemoveClassPath; } public static void register(Project project, @@ -173,11 +176,53 @@ Document libPath, ClassPathUiSupport.Callback callback) { register(project, helper, refHelper, list, addJar, addLibrary, - addAntArtifact, remove, moveUp, moveDown, edit, libPath, - callback, DEFAULT_ANT_ARTIFACT_TYPES, JAR_ZIP_FILTER, + addAntArtifact, remove, moveUp, moveDown, edit, false, libPath, + callback); + } + + public static void register(Project project, + AntProjectHelper helper, + ReferenceHelper refHelper, + ListComponent list, + ButtonModel addJar, + ButtonModel addLibrary, + ButtonModel addAntArtifact, + ButtonModel remove, + ButtonModel moveUp, + ButtonModel moveDown, + ButtonModel edit, + boolean allowRemoveClassPath, + Document libPath, + ClassPathUiSupport.Callback callback) { + register(project, helper, refHelper, list, addJar, addLibrary, + addAntArtifact, remove, moveUp, moveDown, edit, allowRemoveClassPath, libPath, + callback, DEFAULT_ANT_ARTIFACT_TYPES, JAR_ZIP_FILTER, JFileChooser.FILES_AND_DIRECTORIES); } - + + public static void register(Project project, + AntProjectHelper helper, + ReferenceHelper refHelper, + ListComponent list, + ButtonModel addJar, + ButtonModel addLibrary, + ButtonModel addAntArtifact, + ButtonModel remove, + ButtonModel moveUp, + ButtonModel moveDown, + ButtonModel edit, + Document libPath, + ClassPathUiSupport.Callback callback, + String[] antArtifactTypes, + FileFilter filter, + int fileSelectionMode) { + register(project, helper, refHelper, list, addJar, addLibrary, addAntArtifact, remove, moveUp, moveDown, edit, false, libPath, callback, antArtifactTypes, filter, fileSelectionMode); + } + + /**Added {@code allowRemoveClassPath} option that will allow the user to delete {@code ${javac.classpath}}. + * + * @since org.netbeans.modules.java.api.common/0 1.14 + */ public static void register(Project project, AntProjectHelper helper, ReferenceHelper refHelper, @@ -189,6 +234,7 @@ ButtonModel moveUp, ButtonModel moveDown, ButtonModel edit, + boolean allowRemoveClassPath, Document libPath, ClassPathUiSupport.Callback callback, String[] antArtifactTypes, @@ -206,6 +252,7 @@ moveUp, moveDown, edit, + allowRemoveClassPath, libPath, callback, antArtifactTypes, @@ -409,7 +456,7 @@ if ( selectionModel.isSelectedIndex( i ) ) { ClassPathSupport.Item item = (ClassPathSupport.Item)listModel.get( i ); if ( item.getType() == ClassPathSupport.Item.TYPE_CLASSPATH ) { - canRemove = false; + canRemove = allowRemoveClassPath; break; } } diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/queries/AptQueryImpl.java b/java.api.common/src/org/netbeans/modules/java/api/common/queries/AptQueryImpl.java new file mode 100644 --- /dev/null +++ b/java.api.common/src/org/netbeans/modules/java/api/common/queries/AptQueryImpl.java @@ -0,0 +1,133 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.api.common.queries; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.lang.ref.Reference; +import java.lang.ref.WeakReference; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import javax.swing.event.ChangeListener; +import org.netbeans.api.java.queries.AptQuery.Result; +import org.netbeans.spi.java.queries.AptQueryImplementation; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.openide.filesystems.FileObject; +import org.openide.util.ChangeSupport; +import org.openide.util.WeakListeners; + +/** + * + * @author lahvac + */ +final class AptQueryImpl implements AptQueryImplementation { + + private final PropertyEvaluator evaluator; + private final String annotationProcessingEnabledProperty; + private final String runAllAnnotationProcessorsProperty; + private final String annotationProcessorsProperty; + private final Set properties; + + public AptQueryImpl(PropertyEvaluator evaluator, String annotationProcessingEnabledProperty, String runAllAnnotationProcessorsProperty, String annotationProcessorsProperty) { + this.evaluator = evaluator; + this.annotationProcessingEnabledProperty = annotationProcessingEnabledProperty; + this.runAllAnnotationProcessorsProperty = runAllAnnotationProcessorsProperty; + this.annotationProcessorsProperty = annotationProcessorsProperty; + this.properties = new HashSet(Arrays.asList(annotationProcessingEnabledProperty, runAllAnnotationProcessorsProperty, annotationProcessorsProperty)); + } + + private Reference cache; + + public synchronized Result getAptOptions(FileObject file) { + Result current = cache != null ? cache.get() : null; + + if (current == null) { + cache = new WeakReference(current = new ResultImpl()); + } + + return current; + } + + private static final Set TRUE = new HashSet(Arrays.asList("true", "on", "1")); + + private final class ResultImpl implements Result, PropertyChangeListener { + + private final ChangeSupport cs = new ChangeSupport(this); + + public ResultImpl() { + evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, evaluator)); + } + + public boolean annotationProcessingEnabled() { + return TRUE.contains(evaluator.getProperty(annotationProcessingEnabledProperty)); + } + + public Iterable annotationProcessorsToRun() { + if (TRUE.contains(evaluator.getProperty(runAllAnnotationProcessorsProperty))) { + return null; + } + + String processors = evaluator.getProperty(annotationProcessorsProperty); + + if (processors == null) { + //TODO: what to do in this case? + processors = ""; + } + + return Arrays.asList(processors.split(",")); + } + + public void addChangeListener(ChangeListener l) { + cs.addChangeListener(l); + } + + public void removeChangeListener(ChangeListener l) { + cs.removeChangeListener(l); + } + + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName() == null || properties.contains(evt.getPropertyName())) { + cs.fireChange(); + } + } + + } +} diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/queries/QuerySupport.java b/java.api.common/src/org/netbeans/modules/java/api/common/queries/QuerySupport.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/queries/QuerySupport.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/queries/QuerySupport.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. + * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common @@ -34,12 +34,14 @@ * * Contributor(s): * - * Portions Copyrighted 2007 Sun Microsystems, Inc. + * Portions Copyrighted 2007-2010 Sun Microsystems, Inc. */ package org.netbeans.modules.java.api.common.queries; +import org.netbeans.api.java.queries.AptQuery.Result; import org.netbeans.modules.java.api.common.SourceRoots; +import org.netbeans.spi.java.queries.AptQueryImplementation; import org.netbeans.spi.java.queries.BinaryForSourceQueryImplementation; import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation; @@ -281,5 +283,18 @@ "build.classes.dir", "build.test.classes.dir"); // NOI18N } - + /**Create a new query to provide apt configuration data. + * + * @param helper project's AntProjectHelper + * @param evaluator project's evaluator + * @param annotationProcessingEnabledProperty property whose value will be returned from {@link Result#annotationProcessingEnabled()} + * @param runAllAnnotationProcessorsProperty when true, {@link Result#annotationProcessorsToRun()} will return null + * @param annotationProcessorsProperty should contain comma separated list of annotation processors to run (will be returned from {@link Result#annotationProcessorsToRun()}) + * @return a {@link AptQueryImplementation} to provide apt configuration data for this project. + * @since org.netbeans.modules.java.api.common/0 1.14 + */ + public static AptQueryImplementation createAptQuery(AntProjectHelper helper, PropertyEvaluator evaluator, + String annotationProcessingEnabledProperty, String runAllAnnotationProcessorsProperty, String annotationProcessorsProperty) { + return new AptQueryImpl(evaluator, annotationProcessingEnabledProperty, runAllAnnotationProcessorsProperty, annotationProcessorsProperty); + } } diff --git a/java.project/src/org/netbeans/modules/java/project/ProjectAptQueryImpl.java b/java.project/src/org/netbeans/modules/java/project/ProjectAptQueryImpl.java new file mode 100644 --- /dev/null +++ b/java.project/src/org/netbeans/modules/java/project/ProjectAptQueryImpl.java @@ -0,0 +1,67 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.project; + +import org.netbeans.api.java.queries.AptQuery.Result; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.spi.java.queries.AptQueryImplementation; +import org.openide.filesystems.FileObject; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author lahvac + */ +@ServiceProvider(service=AptQueryImplementation.class,position=100) +public class ProjectAptQueryImpl implements AptQueryImplementation { + + public Result getAptOptions(FileObject file) { + Project project = FileOwnerQuery.getOwner(file); + if (project != null) { + AptQueryImplementation slq = project.getLookup().lookup(AptQueryImplementation.class); + if (slq != null) { + return slq.getAptOptions(file); + } + } + return null; + } + +}