Lines 55-64
Link Here
|
55 |
import java.util.concurrent.atomic.AtomicInteger; |
55 |
import java.util.concurrent.atomic.AtomicInteger; |
56 |
import javax.swing.event.ChangeEvent; |
56 |
import javax.swing.event.ChangeEvent; |
57 |
import javax.swing.event.ChangeListener; |
57 |
import javax.swing.event.ChangeListener; |
|
|
58 |
import org.netbeans.api.annotations.common.NonNull; |
59 |
import org.netbeans.api.annotations.common.NullAllowed; |
58 |
import org.netbeans.api.java.classpath.ClassPath; |
60 |
import org.netbeans.api.java.classpath.ClassPath; |
59 |
import org.netbeans.api.java.platform.JavaPlatform; |
61 |
import org.netbeans.api.java.platform.JavaPlatform; |
60 |
import org.netbeans.api.java.platform.Specification; |
62 |
import org.netbeans.api.java.platform.Specification; |
61 |
import org.netbeans.api.java.queries.SourceLevelQuery; |
|
|
62 |
import org.netbeans.api.project.Project; |
63 |
import org.netbeans.api.project.Project; |
63 |
import org.netbeans.api.project.ProjectManager; |
64 |
import org.netbeans.api.project.ProjectManager; |
64 |
import org.netbeans.junit.NbTestCase; |
65 |
import org.netbeans.junit.NbTestCase; |
Lines 76-81
Link Here
|
76 |
import org.netbeans.spi.project.support.ant.PropertyEvaluator; |
77 |
import org.netbeans.spi.project.support.ant.PropertyEvaluator; |
77 |
import org.openide.filesystems.FileUtil; |
78 |
import org.openide.filesystems.FileUtil; |
78 |
import org.openide.modules.SpecificationVersion; |
79 |
import org.openide.modules.SpecificationVersion; |
|
|
80 |
import org.openide.util.Mutex; |
79 |
import org.openide.util.test.MockLookup; |
81 |
import org.openide.util.test.MockLookup; |
80 |
|
82 |
|
81 |
/** |
83 |
/** |
Lines 100-105
Link Here
|
100 |
}); |
102 |
}); |
101 |
} |
103 |
} |
102 |
|
104 |
|
|
|
105 |
private static final String COMPACT1 = "compact1"; //NOI18N |
106 |
private static final String COMPACT2 = "compact2"; //NOI18N |
107 |
private static final String JDK_8 = "8"; //NOI18N |
108 |
private static final String JDK_8_ALIAS = "1.8"; //NOI18N |
103 |
private static final String JAVAC_SOURCE = "1.2"; |
109 |
private static final String JAVAC_SOURCE = "1.2"; |
104 |
private static final String DEFAULT_JAVAC_SOURCE = "17.2"; |
110 |
private static final String DEFAULT_JAVAC_SOURCE = "17.2"; |
105 |
|
111 |
|
Lines 136-142
Link Here
|
136 |
} |
142 |
} |
137 |
|
143 |
|
138 |
|
144 |
|
139 |
private void prepareProject(String platformName) throws IOException { |
145 |
private void prepareProject( |
|
|
146 |
@NonNull final String platformName) throws IOException { |
147 |
prepareProject(platformName, null, null); |
148 |
} |
149 |
private void prepareProject( |
150 |
@NonNull final String platformName, |
151 |
@NullAllowed final String sourceLevel, |
152 |
@NullAllowed final String profile) throws IOException { |
140 |
scratch = TestUtil.makeScratchDir(this); |
153 |
scratch = TestUtil.makeScratchDir(this); |
141 |
projdir = scratch.createFolder("proj"); |
154 |
projdir = scratch.createFolder("proj"); |
142 |
helper = ProjectGenerator.createProject(projdir, "test"); |
155 |
helper = ProjectGenerator.createProject(projdir, "test"); |
Lines 146-152
Link Here
|
146 |
EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); |
159 |
EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); |
147 |
props.setProperty("javac.source", "${def}"); |
160 |
props.setProperty("javac.source", "${def}"); |
148 |
props.setProperty("platform.active", platformName); |
161 |
props.setProperty("platform.active", platformName); |
149 |
props.setProperty("def", JAVAC_SOURCE); |
162 |
props.setProperty("def", |
|
|
163 |
sourceLevel != null ? |
164 |
sourceLevel : |
165 |
JAVAC_SOURCE); |
166 |
if (profile != null) { |
167 |
props.setProperty("javac.profile", profile); //NOI18N |
168 |
} |
150 |
helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); |
169 |
helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); |
151 |
props = PropertyUtils.getGlobalProperties(); |
170 |
props = PropertyUtils.getGlobalProperties(); |
152 |
props.put("default.javac.source", DEFAULT_JAVAC_SOURCE); |
171 |
props.put("default.javac.source", DEFAULT_JAVAC_SOURCE); |
Lines 207-212
Link Here
|
207 |
assertEquals("1.7", result.getSourceLevel().toString()); |
226 |
assertEquals("1.7", result.getSourceLevel().toString()); |
208 |
} |
227 |
} |
209 |
|
228 |
|
|
|
229 |
public void testProfilesJDK8ProfileGiven() throws IOException { |
230 |
this.prepareProject(TEST_PLATFORM, JDK_8, COMPACT2); |
231 |
final FileObject dummy = projdir.createData("Dummy.java"); //NOI18N |
232 |
final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval); |
233 |
final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy); |
234 |
assertTrue(result instanceof SourceLevelQueryImplementation2.Result2); |
235 |
assertEquals(COMPACT2, ((SourceLevelQueryImplementation2.Result2)result).getProfile()); |
236 |
} |
237 |
|
238 |
public void testProfilesJDK8AliasProfileGiven() throws IOException { |
239 |
this.prepareProject(TEST_PLATFORM, JDK_8_ALIAS, COMPACT2); |
240 |
final FileObject dummy = projdir.createData("Dummy.java"); //NOI18N |
241 |
final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval); |
242 |
final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy); |
243 |
assertTrue(result instanceof SourceLevelQueryImplementation2.Result2); |
244 |
assertEquals(COMPACT2, ((SourceLevelQueryImplementation2.Result2)result).getProfile()); |
245 |
} |
246 |
|
247 |
public void testProfilesJDK8AliasProfileNotGiven() throws IOException { |
248 |
this.prepareProject(TEST_PLATFORM, JDK_8, null); |
249 |
final FileObject dummy = projdir.createData("Dummy.java"); //NOI18N |
250 |
final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval); |
251 |
final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy); |
252 |
assertTrue(result instanceof SourceLevelQueryImplementation2.Result2); |
253 |
assertEquals(null, ((SourceLevelQueryImplementation2.Result2)result).getProfile()); |
254 |
} |
255 |
|
256 |
public void testProfilesOldJDKAliasProfileGiven() throws IOException { |
257 |
this.prepareProject(TEST_PLATFORM, JAVAC_SOURCE, COMPACT2); |
258 |
final FileObject dummy = projdir.createData("Dummy.java"); //NOI18N |
259 |
final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval); |
260 |
final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy); |
261 |
assertTrue(result instanceof SourceLevelQueryImplementation2.Result2); |
262 |
assertEquals(null, ((SourceLevelQueryImplementation2.Result2)result).getProfile()); |
263 |
} |
264 |
|
265 |
public void testProfileChanges() throws Exception { |
266 |
prepareProject(TEST_PLATFORM, JDK_8, COMPACT1); |
267 |
final FileObject dummy = projdir.createData("Dummy.java"); //NOI18N |
268 |
final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval); |
269 |
SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy); |
270 |
assertTrue(result instanceof SourceLevelQueryImplementation2.Result2); |
271 |
assertEquals(COMPACT1, ((SourceLevelQueryImplementation2.Result2)result).getProfile()); |
272 |
ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() { |
273 |
@Override |
274 |
public Void run() throws Exception { |
275 |
final EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); |
276 |
props.setProperty("javac.profile", COMPACT2); //NOI18N |
277 |
helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); |
278 |
ProjectManager.getDefault().saveProject(prj); |
279 |
return null; |
280 |
} |
281 |
}); |
282 |
result = sourceLevelQuery.getSourceLevel(dummy); |
283 |
assertTrue(result instanceof SourceLevelQueryImplementation2.Result2); |
284 |
assertEquals(COMPACT2, ((SourceLevelQueryImplementation2.Result2)result).getProfile()); |
285 |
|
286 |
} |
287 |
|
288 |
public void testProfileListening() throws Exception { |
289 |
prepareProject(TEST_PLATFORM, JDK_8, COMPACT1); |
290 |
final FileObject dummy = projdir.createData("Dummy.java"); //NOI18N |
291 |
final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval); |
292 |
final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy); |
293 |
assertTrue(result instanceof SourceLevelQueryImplementation2.Result2); |
294 |
assertEquals(COMPACT1, ((SourceLevelQueryImplementation2.Result2)result).getProfile()); |
295 |
final AtomicInteger eventCount = new AtomicInteger(); |
296 |
final ChangeListener listener = new ChangeListener() { |
297 |
@Override |
298 |
public void stateChanged(ChangeEvent e) { |
299 |
eventCount.getAndIncrement(); |
300 |
} |
301 |
}; |
302 |
result.addChangeListener(listener); |
303 |
ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() { |
304 |
@Override |
305 |
public Void run() throws Exception { |
306 |
final EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); |
307 |
props.setProperty("javac.profile", COMPACT2); //NOI18N |
308 |
helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); |
309 |
ProjectManager.getDefault().saveProject(prj); |
310 |
return null; |
311 |
} |
312 |
}); |
313 |
assertEquals(1, eventCount.get()); |
314 |
assertEquals(COMPACT2, ((SourceLevelQueryImplementation2.Result2)result).getProfile()); |
315 |
|
316 |
} |
317 |
|
210 |
private static class TestPlatformProvider implements JavaPlatformProvider { |
318 |
private static class TestPlatformProvider implements JavaPlatformProvider { |
211 |
|
319 |
|
212 |
private JavaPlatform platform; |
320 |
private JavaPlatform platform; |