Skip to content

Commit 129776d

Browse files
authored
Merge pull request #1307 from tzezula/tzezula/mx_java_platform
Added support for per-project platform for mx projects.
2 parents 5f7082f + e59aa11 commit 129776d

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

java/java.project/apichanges.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ is the proper place.
8585
<!-- ACTUAL CHANGES BEGIN HERE: -->
8686

8787
<changes>
88+
<change id="ProjectPlatformNoPE">
89+
<api name="java_project"/>
90+
<summary>Added support for per-project platform for projects which don't use PropertyEvaluator.</summary>
91+
<version major="1" minor="77"/>
92+
<date day="19" month="6" year="2019"/>
93+
<author login="tzezula"/>
94+
<compatibility addition="yes"/>
95+
<description>
96+
Added support for per-project platform for projects which don't use <code>PropertyEvaluator</code>.
97+
</description>
98+
<class package="org.netbeans.spi.java.project.support" name="ProjectPlatform"/>
99+
</change>
88100
<change id="ProjectModulesModifier">
89101
<api name="java_project"/>
90102
<summary>Added a SPI to manipulate with project's <code>module-info.java</code> declarations</summary>

java/java.project/manifest.mf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ Manifest-Version: 1.0
22
OpenIDE-Module: org.netbeans.modules.java.project/1
33
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/project/Bundle.properties
44
OpenIDE-Module-Needs: javax.script.ScriptEngine.freemarker
5-
OpenIDE-Module-Specification-Version: 1.76
5+
OpenIDE-Module-Specification-Version: 1.77
66
AutoUpdate-Show-In-Client: false
77

java/java.project/src/org/netbeans/spi/java/project/support/ProjectPlatform.java

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public final class ProjectPlatform {
6060
private ProjectPlatform() {
6161
throw new IllegalStateException("No instance allowed"); //NOI18N
6262
}
63-
6463
/**
6564
* Creates a transient {@link JavaPlatform} defined in given {@link Project}.
6665
* @param owner the project to return the {@link JavaPlatform} for
@@ -76,28 +75,53 @@ public static JavaPlatform forProject(
7675
@NonNull final String platformType) {
7776
Parameters.notNull("owner", owner); //NOI18N
7877
Parameters.notNull("eval", eval); //NOI18N
79-
Parameters.notNull("platformType", platformType); //NOI18N
80-
final String platformName = eval.getProperty(PLATFORM_ACTIVE);
78+
Parameters.notNull("platformType", platformType); //NOI18N
79+
final String platformName = eval.getProperty(PLATFORM_ACTIVE);
8180
final FileObject jdkHome = resolvePlatformHome(
8281
platformName,
8382
owner.getProjectDirectory(),
8483
eval);
8584
if (jdkHome == null) {
8685
return null;
8786
}
87+
return forProject(owner, jdkHome, platformName, platformType);
88+
}
89+
90+
/**
91+
* Creates a transient {@link JavaPlatform} defined in given {@link Project}.
92+
* @param owner the project to return the {@link JavaPlatform} for
93+
* @param platformHome the {@link JavaPlatform} install folder
94+
* @param platformName the {@link JavaPlatform} system name uniquely identifying the platform.
95+
* The name has to be valid property name, use the {@link PropertyUtils#getUsablePropertyName(java.lang.String)} to create the name.
96+
* For the Ant based project the platform name is a value of {@code platform.active} property.
97+
* @param platformType the type of the platform, eg. "j2se"
98+
* @return a {@link JavaPlatform} for given project or null when platform cannot
99+
* be created
100+
* @since 1.77
101+
*/
102+
@CheckForNull
103+
public static JavaPlatform forProject(
104+
@NonNull final Project owner,
105+
@NonNull final FileObject platformHome,
106+
@NonNull final String platformName,
107+
@NonNull final String platformType) {
108+
Parameters.notNull("owner", owner); //NOI18N
109+
Parameters.notNull("platformHome", platformHome); //NOI18N
110+
Parameters.notNull("platformName", platformName); //NOI18N
111+
Parameters.notNull("platformType", platformType); //NOI18N
88112
JavaPlatform res;
89-
JavaPlatform delegate;
113+
JavaPlatform delegate;
90114
synchronized (platformsByProject) {
91-
res = platformsByProject.get(jdkHome);
115+
res = platformsByProject.get(platformHome);
92116
delegate = res == null ?
93-
platformsByHome.get(jdkHome) :
117+
platformsByHome.get(platformHome) :
94118
null;
95119
}
96120
if (res == null) {
97121
boolean newDelegate = false;
98122
if (delegate == null) {
99-
delegate = Optional.ofNullable(findJavaPlatform(jdkHome, platformType))
100-
.orElseGet(() -> createJavaPlatform(jdkHome, platformType));
123+
delegate = Optional.ofNullable(findJavaPlatform(platformHome, platformType))
124+
.orElseGet(() -> createJavaPlatform(platformHome, platformType));
101125
newDelegate = true;
102126
}
103127
if (delegate != null) {
@@ -118,16 +142,16 @@ public Map<String, String> getProperties() {
118142
@Override
119143
public String getDisplayName() {
120144
return platformName;
121-
}
122-
};
145+
}
146+
};
123147
}
124148
if (res != null) {
125149
synchronized (platformsByProject) {
126150
platformsByProject.put(owner, res);
127151
assert delegate != null;
128152
if (newDelegate) {
129-
homesByProject.put(owner, jdkHome);
130-
platformsByHome.put(jdkHome, delegate);
153+
homesByProject.put(owner, platformHome);
154+
platformsByHome.put(platformHome, delegate);
131155
}
132156
}
133157
}

0 commit comments

Comments
 (0)