@@ -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