-
Notifications
You must be signed in to change notification settings - Fork 193
/
DefaultJavaRuntimeEnvironment.java
66 lines (56 loc) · 2.35 KB
/
DefaultJavaRuntimeEnvironment.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*******************************************************************************
* Copyright (c) 2012 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
import java.util.Iterator;
import java.util.Map.Entry;
import org.eclipse.jdt.core.tests.util.Util;
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
public class DefaultJavaRuntimeEnvironment extends FileSystem {
private DefaultJavaRuntimeEnvironment(String[] jreClasspaths) {
super(jreClasspaths, new String[] {} /* ignore initial file names */, null);
}
private static INameEnvironment[] defaultJreClassLibs;
public static INameEnvironment[] create(String[] jreClasspaths) {
if (defaultJreClassLibs == null) {
defaultJreClassLibs = new INameEnvironment[1];
defaultJreClassLibs[0] = new DefaultJavaRuntimeEnvironment(jreClasspaths);
}
return defaultJreClassLibs;
}
public void cleanup() {
// reset output folder only, which is the last entry on the classpath list
// see #getDefaultClassPaths()
Classpath outputFolder = this.classpaths[this.classpaths.length - 1];
// and remove the path from cached module locations:
for (Iterator<Entry<String, Classpath>> iterator = this.moduleLocations.entrySet().iterator(); iterator.hasNext();) {
Entry<String, Classpath> entry = iterator.next();
if (entry.getValue().equals(outputFolder))
iterator.remove();
}
outputFolder.reset();
}
public static void cleanUpDefaultJreClassLibs() {
if (defaultJreClassLibs != null && defaultJreClassLibs.length > 0) {
if (defaultJreClassLibs[0] instanceof DefaultJavaRuntimeEnvironment)
defaultJreClassLibs[0].cleanup();
}
}
private static String[] javaLibsAndOutputDir;
static String[] getDefaultClassPaths() {
if (javaLibsAndOutputDir == null)
javaLibsAndOutputDir = Util.concatWithClassLibs(AbstractRegressionTest.OUTPUT_DIR, false);
return javaLibsAndOutputDir;
}
}