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 @@ -105,6 +105,22 @@ + + + Extended BootClassPathImplementation and ClassPathProviderImpl to support non j2se platforms + + + + + +

+ Extended BootClassPathImplementation and ClassPathProviderImpl to support non j2se platforms. +

+
+ + + +
Added BaseActionProvider.Callback3 with a method providing additional build properties. 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.58 +OpenIDE-Module-Specification-Version: 1.59 diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/classpath/BootClassPathImplementation.java b/java.api.common/src/org/netbeans/modules/java/api/common/classpath/BootClassPathImplementation.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/classpath/BootClassPathImplementation.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/classpath/BootClassPathImplementation.java @@ -54,6 +54,8 @@ import java.util.List; import java.util.ArrayList; import java.util.Collections; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.annotations.common.NullAllowed; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.modules.java.api.common.util.CommonProjectUtils; import org.netbeans.spi.project.support.ant.PropertyEvaluator; @@ -70,6 +72,7 @@ private static final String PLATFORM_ACTIVE = "platform.active"; // NOI18N private final PropertyEvaluator evaluator; + private final String platformType; private JavaPlatformManager platformManager; // name of project active platform private String activePlatformName; @@ -80,10 +83,14 @@ private PropertyChangeSupport support = new PropertyChangeSupport(this); private ClassPath endorsedClassPath; - BootClassPathImplementation(PropertyEvaluator evaluator, ClassPath endorsedClassPath) { + BootClassPathImplementation( + @NonNull final PropertyEvaluator evaluator, + @NullAllowed final ClassPath endorsedClassPath, + @NullAllowed final String platformType) { assert evaluator != null; this.endorsedClassPath = endorsedClassPath; this.evaluator = evaluator; + this.platformType = platformType; evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, evaluator)); if (endorsedClassPath != null) { endorsedClassPath.addPropertyChangeListener(this); 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 @@ -43,15 +43,16 @@ */ package org.netbeans.modules.java.api.common.classpath; -import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; +import java.util.Arrays; import java.util.Map; import java.util.HashMap; 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.api.java.platform.JavaPlatform; import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.SourceGroup; import org.netbeans.modules.java.api.common.SourceRoots; @@ -64,7 +65,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.Mutex; -import org.openide.util.WeakListeners; +import org.openide.util.Parameters; /** * Defines the various class paths for a J2SE project. @@ -72,23 +73,24 @@ */ public final class ClassPathProviderImpl implements ClassPathProvider { - private String buildClassesDir = "build.classes.dir"; // NOI18N private static final String buildGeneratedDir = "build.generated.sources.dir"; // NOI18N - 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[] processorTestClasspath = new String[]{"javac.test.processorpath"}; //NOI18N - private String[] runClasspath = new String[]{"run.classpath"}; //NOI18N - private String[] runTestClasspath = new String[]{"run.test.classpath"}; //NOI18N - private String[] endorsedClasspath = new String[]{ProjectProperties.ENDORSED_CLASSPATH}; //NOI18N + private static final String[] processorTestClasspath = new String[]{"javac.test.processorpath"}; //NOI18N private final AntProjectHelper helper; private final File projectDirectory; private final PropertyEvaluator evaluator; private final SourceRoots sourceRoots; private final SourceRoots testSourceRoots; + private final String buildClassesDir; + private final String distJar; + private final String buildTestClassesDir; + private final String[] javacClasspath; + private final String[] processorClasspath; + private final String[] javacTestClasspath; + private final String[] runClasspath; + private final String[] runTestClasspath; + private final String[] endorsedClasspath; + private final String platformType; /** * ClassPaths cache * Index -> CP mapping @@ -112,18 +114,18 @@ public ClassPathProviderImpl(AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots sourceRoots, SourceRoots testSourceRoots) { - this.helper = helper; - this.projectDirectory = FileUtil.toFile(helper.getProjectDirectory()); - assert this.projectDirectory != null; - this.evaluator = evaluator; - this.sourceRoots = sourceRoots; - this.testSourceRoots = testSourceRoots; - listener = new PropertyChangeListener() { - public synchronized void propertyChange(PropertyChangeEvent evt) { - dirCache.remove(evt.getPropertyName()); - } - }; - evaluator.addPropertyChangeListener(WeakListeners.propertyChange(listener, evaluator)); + this( + helper, + evaluator, + sourceRoots, + testSourceRoots, + Builder.DEFAULT_BUILD_CLASSES_DIR, + Builder.DEFAULT_DIST_JAR, + Builder.DEFAULT_BUILD_TEST_CLASSES_DIR, + Builder.DEFAULT_JAVAC_CLASS_PATH, + Builder.DEFAULT_JAVAC_TEST_CLASS_PATH, + Builder.DEFAULT_RUN_CLASS_PATH, + Builder.DEFAULT_RUN_TEST_CLASS_PATH); } public ClassPathProviderImpl(AntProjectHelper helper, PropertyEvaluator evaluator, @@ -131,7 +133,8 @@ String buildClassesDir, String distJar, String buildTestClassesDir, String[] javacClasspath, String[] javacTestClasspath, String[] runClasspath, String[] runTestClasspath) { - this(helper, + this( + helper, evaluator, sourceRoots, testSourceRoots, @@ -142,7 +145,7 @@ javacTestClasspath, runClasspath, runTestClasspath, - new String[]{ProjectProperties.ENDORSED_CLASSPATH}); + Builder.DEFAULT_ENDORSED_CLASSPATH); } /** * Constructor allowing customization of endorsedClasspath property names. @@ -153,7 +156,8 @@ String buildClassesDir, String distJar, String buildTestClassesDir, String[] javacClasspath, String[] javacTestClasspath, String[] runClasspath, String[] runTestClasspath, String[] endorsedClasspath) { - this(helper, + this( + helper, evaluator, sourceRoots, testSourceRoots, @@ -161,11 +165,11 @@ distJar, buildTestClassesDir, javacClasspath, - javacClasspath, + Builder.DEFAULT_PROCESSOR_PATH, javacTestClasspath, runClasspath, runTestClasspath, - new String[]{ProjectProperties.ENDORSED_CLASSPATH}); + endorsedClasspath); } /** @@ -177,7 +181,59 @@ String buildClassesDir, String distJar, String buildTestClassesDir, String[] javacClasspath, String[] processorPath, String[] javacTestClasspath, String[] runClasspath, String[] runTestClasspath, String[] endorsedClasspath) { - this(helper, evaluator, sourceRoots, testSourceRoots); + this( + helper, + evaluator, + sourceRoots, + testSourceRoots, + buildClassesDir, + distJar, + buildTestClassesDir, + javacClasspath, + processorPath, + javacTestClasspath, + runClasspath, + runTestClasspath, + endorsedClasspath, + Builder.DEFAULT_PLATFORM_TYPE + ); + } + + private ClassPathProviderImpl( + @NonNull final AntProjectHelper helper, + @NonNull final PropertyEvaluator evaluator, + @NonNull final SourceRoots sourceRoots, + @NonNull final SourceRoots testSourceRoots, + @NonNull final String buildClassesDir, + @NonNull final String distJar, + @NonNull final String buildTestClassesDir, + @NonNull final String[] javacClasspath, + @NonNull final String[] processorPath, + @NonNull final String[] javacTestClasspath, + @NonNull final String[] runClasspath, + @NonNull final String[] runTestClasspath, + @NonNull final String[] endorsedClasspath, + @NonNull final String platformType) { + Parameters.notNull("helper", helper); //NOI18N + Parameters.notNull("evaluator", evaluator); //NOI18N + Parameters.notNull("sourceRoots", sourceRoots); //NOI18N + Parameters.notNull("testSourceRoots", testSourceRoots); //NOI18N + Parameters.notNull("buildClassesDir", buildClassesDir); //NOI18N + Parameters.notNull("distJar", distJar); //NOI18N + Parameters.notNull("buildTestClassesDir", buildTestClassesDir); //NOI18N + Parameters.notNull("javacClasspath", javacClasspath); //NOI18N + Parameters.notNull("processorPath", processorPath); //NOI18N + Parameters.notNull("javacTestClasspath", javacTestClasspath); //NOI18N + Parameters.notNull("runClasspath", runClasspath); //NOI18N + Parameters.notNull("runTestClasspath", runTestClasspath); //NOI18N + Parameters.notNull("endorsedClasspath", endorsedClasspath); //NOI18N + Parameters.notNull("platformType", platformType); //NOI18N + this.helper = helper; + this.projectDirectory = FileUtil.toFile(helper.getProjectDirectory()); + assert this.projectDirectory != null; + this.evaluator = evaluator; + this.sourceRoots = sourceRoots; + this.testSourceRoots = testSourceRoots; this.buildClassesDir = buildClassesDir; this.distJar = distJar; this.buildTestClassesDir = buildTestClassesDir; @@ -187,6 +243,211 @@ this.runClasspath = runClasspath; this.runTestClasspath = runTestClasspath; this.endorsedClasspath = endorsedClasspath; + this.platformType = platformType; + + } + + /** + * Builder to create ClassPathProviderImpl. + * @since 1.59 + */ + public static final class Builder { + + private static final String DEFAULT_PLATFORM_TYPE = "j2se"; //NOI18N + private static final String DEFAULT_BUILD_CLASSES_DIR = "build.classes.dir"; //NOI18N + private static final String DEFAULT_BUILD_TEST_CLASSES_DIR = "build.test.classes.dir"; // NOI18N + private static final String DEFAULT_DIST_JAR = "dist.jar"; // NOI18N + private static final String[] DEFAULT_JAVAC_CLASS_PATH = new String[]{"javac.classpath"}; //NOI18N + private static final String[] DEFAULT_PROCESSOR_PATH = new String[]{ProjectProperties.JAVAC_PROCESSORPATH}; //NOI18N + private static final String[] DEFAULT_JAVAC_TEST_CLASS_PATH = new String[]{"javac.test.classpath"}; //NOI18N + private static final String[] DEFAULT_RUN_CLASS_PATH = new String[]{"run.classpath"}; //NOI18N + private static final String[] DEFAULT_RUN_TEST_CLASS_PATH = new String[]{"run.test.classpath"}; //NOI18N + private static final String[] DEFAULT_ENDORSED_CLASSPATH = new String[]{ProjectProperties.ENDORSED_CLASSPATH}; //NOI18N + + private final AntProjectHelper helper; + private final PropertyEvaluator evaluator; + private final SourceRoots sourceRoots; + private final SourceRoots testSourceRoots; + + private String platformType = DEFAULT_PLATFORM_TYPE; + private String buildClassesDir = DEFAULT_BUILD_CLASSES_DIR; + private String buildTestClassesDir = DEFAULT_BUILD_TEST_CLASSES_DIR; + private String distJar = DEFAULT_DIST_JAR; + private String[] javacClasspath = DEFAULT_JAVAC_CLASS_PATH; + private String[] processorPath = DEFAULT_PROCESSOR_PATH; + private String[] javacTestClasspath = DEFAULT_JAVAC_TEST_CLASS_PATH; + private String[] runClasspath = DEFAULT_RUN_CLASS_PATH; + private String[] runTestClasspath = DEFAULT_RUN_TEST_CLASS_PATH; + private String[] endorsedClasspath = DEFAULT_ENDORSED_CLASSPATH; + + private Builder( + @NonNull final AntProjectHelper helper, + @NonNull final PropertyEvaluator evaluator, + @NonNull final SourceRoots sourceRoots, + @NonNull final SourceRoots testSourceRoots) { + Parameters.notNull("helper", helper); //NOI18N + Parameters.notNull("evaluator", evaluator); //NOI18N + Parameters.notNull("sourceRoots", sourceRoots); //NOI18N + Parameters.notNull("testSourceRoots", testSourceRoots); //NOI18N + this.helper = helper; + this.evaluator = evaluator; + this.sourceRoots = sourceRoots; + this.testSourceRoots = testSourceRoots; + } + + /** + * Sets a {@link JavaPlatform} type for boot classpath lookup. + * @param platformType the type of {@link JavaPlatform}, by default "j2se" + * @return {@link Builder} + */ + @NonNull + public Builder setPlatformType(@NonNull final String platformType) { + Parameters.notNull("platformType", platformType); //NOI18N + this.platformType = platformType; + return this; + } + + /** + * Sets a property name containing build classes directory. + * @param buildClassesDirProperty the name of property containing the build classes directory, by default "build.classes.dir" + * @return {@link Builder} + */ + @NonNull + public Builder setBuildClassesDirProperty(@NonNull final String buildClassesDirProperty) { + Parameters.notNull("buildClassesDirProperty", buildClassesDirProperty); //NOI18N + this.buildClassesDir = buildClassesDirProperty; + return this; + } + + /** + * Sets a property name containing build test classes directory. + * @param buildTestClassesDirProperty the name of property containing the build test classes directory, by default "build.test.classes.dir" + * @return {@link Builder} + */ + @NonNull + public Builder setBuildTestClassesDirProperty(@NonNull final String buildTestClassesDirProperty) { + Parameters.notNull("buildTestClassesDirProperty", buildTestClassesDirProperty); //NOI18N + this.buildTestClassesDir = buildTestClassesDirProperty; + return this; + } + + /** + * Sets a property name containing the distribution jar. + * @param distJarProperty the name of property containing the distribution jar reference, by default "dist.jar" + * @return {@link Builder} + */ + @NonNull + public Builder setDistJarProperty(@NonNull final String distJarProperty) { + Parameters.notNull("distJarProperty", distJarProperty); //NOI18N + this.distJar = distJarProperty; + return this; + } + + /** + * Sets javac classpath properties for source roots. + * @param javacClassPathProperties the names of properties containing the compiler classpath for sources, by default "javac.classpath" + * @return {@link Builder} + */ + @NonNull + public Builder setJavacClassPathProperties(@NonNull final String[] javacClassPathProperties) { + Parameters.notNull("javacClassPathProperties", javacClassPathProperties); //NOI18N + this.javacClasspath = Arrays.copyOf(javacClassPathProperties, javacClassPathProperties.length); + return this; + } + + /** + * Sets javac processor path properties for source roots. + * @param processorPathProperties the names of properties containing the compiler processor path for sources, by default "javac.processorpath" + * @return {@link Builder} + */ + @NonNull + public Builder setProcessorPathProperties(@NonNull final String[] processorPathProperties) { + Parameters.notNull("processorPathProperties", processorPathProperties); + this.processorPath = Arrays.copyOf(processorPathProperties, processorPathProperties.length); + return this; + } + + /** + * Sets javac classpath properties for test roots. + * @param javacTestClasspathProperties the names of properties containing the compiler classpath for tests, by default "javac.test.classpath" + * @return {@link Builder} + */ + @NonNull + public Builder setJavacTestClasspathProperties(@NonNull final String[] javacTestClasspathProperties) { + Parameters.notNull("javacTestClasspathProperties", javacTestClasspathProperties); //NOI18N + this.javacTestClasspath = Arrays.copyOf(javacTestClasspathProperties, javacTestClasspathProperties.length); + return this; + } + + /** + * Sets runtime classpath properties for source roots. + * @param runClasspathProperties the names of properties containing the runtime classpath for sources, by default "run.classpath" + * @return {@link Builder} + */ + @NonNull + public Builder setRunClasspathProperties(@NonNull final String[] runClasspathProperties) { + Parameters.notNull("runClasspathProperties", runClasspathProperties); //NOI18N + this.runClasspath = Arrays.copyOf(runClasspathProperties, runClasspathProperties.length); + return this; + } + + /** + * Sets runtime classpath properties for test roots. + * @param runTestClasspathProperties the names of properties containing the runtime classpath for tests, by default "run.test.classpath" + * @return {@link Builder} + */ + @NonNull + public Builder setRunTestClasspathProperties(@NonNull final String[] runTestClasspathProperties) { + Parameters.notNull("runTestClasspathProperties", runTestClasspathProperties); //NOI18N + this.runTestClasspath = Arrays.copyOf(runTestClasspathProperties, runTestClasspathProperties.length); + return this; + } + + /** + * Sets endorsed classpath properties. + * @param endorsedClasspathProperties the names of properties containing the endorsed classpath, by default "endorsed.classpath" + * @return {@link Builder} + */ + @NonNull + public Builder setEndorsedClasspathProperties(@NonNull final String[] endorsedClasspathProperties) { + Parameters.notNull("endorsedClasspathProperties", endorsedClasspathProperties); //NOI18N + this.endorsedClasspath = Arrays.copyOf(endorsedClasspathProperties, endorsedClasspathProperties.length); + return this; + } + + + /** + * Creates a configured {@link ClassPathProviderImpl}. + * @return the {@link ClassPathProviderImpl} + */ + @NonNull + public ClassPathProviderImpl build() { + return new ClassPathProviderImpl ( + helper, + evaluator, + sourceRoots, + testSourceRoots, + buildClassesDir, + distJar, + buildTestClassesDir, + javacClasspath, + processorPath, + javacTestClasspath, + runClasspath, + runTestClasspath, + endorsedClasspath, + platformType); + } + + @NonNull + public static Builder create( + @NonNull final AntProjectHelper helper, + @NonNull final PropertyEvaluator evaluator, + @NonNull final SourceRoots sourceRoots, + @NonNull final SourceRoots testSourceRoots) { + return new Builder(helper, evaluator, sourceRoots, testSourceRoots); + } + } diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/classpath/ClassPathSupportFactory.java b/java.api.common/src/org/netbeans/modules/java/api/common/classpath/ClassPathSupportFactory.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/classpath/ClassPathSupportFactory.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/classpath/ClassPathSupportFactory.java @@ -42,7 +42,10 @@ package org.netbeans.modules.java.api.common.classpath; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.annotations.common.NullAllowed; import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.api.java.platform.JavaPlatform; import org.netbeans.modules.java.api.common.SourceRoots; import org.netbeans.spi.java.classpath.ClassPathImplementation; import org.netbeans.spi.project.support.ant.AntProjectHelper; @@ -64,7 +67,7 @@ * @return classpath implementation */ public static ClassPathImplementation createBootClassPathImplementation(PropertyEvaluator evaluator) { - return new BootClassPathImplementation(evaluator, null); + return createBootClassPathImplementation(evaluator, null, null); } /** @@ -76,7 +79,23 @@ * @since org.netbeans.modules.java.api.common/0 1.11 */ public static ClassPathImplementation createBootClassPathImplementation(PropertyEvaluator evaluator, ClassPath endorsedClassPath) { - return new BootClassPathImplementation(evaluator, endorsedClassPath); + return createBootClassPathImplementation(evaluator, endorsedClassPath, null); + } + + /** + * Creates implementation of BOOT classpath based on project's platform.active + * property and given endorsed classpath which will have precedence of platform classpath. + * @param evaluator project's property evaluator + * @param endorsedClassPath endorsed classpath to prepend to boot classpath + * @param platformType the type of {@link JavaPlatform} + * @return classpath implementation + * @since 1.59 + */ + public static ClassPathImplementation createBootClassPathImplementation( + @NonNull final PropertyEvaluator evaluator, + @NullAllowed final ClassPath endorsedClassPath, + @NullAllowed final String platformType) { + return new BootClassPathImplementation(evaluator, endorsedClassPath, platformType); } /** diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/util/CommonProjectUtils.java b/java.api.common/src/org/netbeans/modules/java/api/common/util/CommonProjectUtils.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/util/CommonProjectUtils.java +++ b/java.api.common/src/org/netbeans/modules/java/api/common/util/CommonProjectUtils.java @@ -49,7 +49,9 @@ import java.util.HashMap; import java.util.Map; import javax.lang.model.element.TypeElement; +import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.annotations.common.NullAllowed; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.platform.JavaPlatform; import org.netbeans.api.java.platform.JavaPlatformManager; @@ -81,13 +83,36 @@ * @return active {@link JavaPlatform} or null if the project's platform * is broken */ + @CheckForNull public static JavaPlatform getActivePlatform(final String activePlatformId) { + return getActivePlatform(activePlatformId, null); + } + + /** + * Returns the active platform used by the project or null if the active + * project platform is broken. + * @param activePlatformId the name of platform used by Ant script or null + * for default platform. + * @param platformType the type of {@link JavaPlatform} + * @return active {@link JavaPlatform} or null if the project's platform + * is broken + * @since 1.59 + */ + @CheckForNull + public static JavaPlatform getActivePlatform( + @NullAllowed final String activePlatformId, + @NullAllowed String platformType) { + if (platformType == null) { + platformType = "j2se"; //NOI18N + } final JavaPlatformManager pm = JavaPlatformManager.getDefault(); if (activePlatformId == null) { - return pm.getDefaultPlatform(); + final JavaPlatform candidate = pm.getDefaultPlatform(); + return candidate == null || !platformType.equals(candidate.getSpecification().getName()) ? + null : + candidate; } - - JavaPlatform[] installedPlatforms = pm.getPlatforms(null, new Specification("j2se", null)); //NOI18N + JavaPlatform[] installedPlatforms = pm.getPlatforms(null, new Specification(platformType, null)); //NOI18N for (JavaPlatform javaPlatform : installedPlatforms) { String antName = javaPlatform.getProperties().get("platform.ant.name"); //NOI18N if (antName != null && antName.equals(activePlatformId)) {