Skip to content

Commit ea9194e

Browse files
committed
CLI: compile preloader against JDK 1.6
To be able to detect the Java runtime version at startup to report an error if it's < 1.8
1 parent a236400 commit ea9194e

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@
283283
<target name="preloader">
284284
<cleandir dir="${output}/classes/preloader"/>
285285
<javac destdir="${output}/classes/preloader" debug="true" debuglevel="lines,vars,source" includeAntRuntime="false"
286-
source="${java.target}" target="${java.target}">
286+
source="1.6" target="1.6">
287287
<src location="${basedir}/compiler/preloader/src"/>
288288
</javac>
289289

compiler/preloader/preloader.iml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module type="JAVA_MODULE" version="4">
3-
<component name="NewModuleRootManager" inherit-compiler-output="true">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="true">
44
<exclude-output />
55
<content url="file://$MODULE_DIR$">
66
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
77
</content>
8-
<orderEntry type="inheritedJdk" />
8+
<orderEntry type="jdk" jdkName="1.6" jdkType="JavaSDK" />
99
<orderEntry type="sourceFolder" forTests="false" />
1010
</component>
11-
</module>
12-
11+
</module>

compiler/preloader/src/org/jetbrains/kotlin/preloading/ClassPreloadingUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static ClassLoader preloadClasses(
5757
}
5858

5959
private static URLClassLoader createFallbackClassLoader(Collection<File> files) throws IOException {
60-
List<URL> urls = new ArrayList<>(files.size());
60+
List<URL> urls = new ArrayList<URL>(files.size());
6161
for (File file : files) {
6262
urls.add(file.toURI().toURL());
6363
}
@@ -76,7 +76,7 @@ private static Collection<File> mergeClasspathFromManifests(Map<String, Object>
7676
return extractManifestClasspath((ResourceData) manifest);
7777
}
7878
else if (manifest instanceof ArrayList) {
79-
List<File> result = new ArrayList<>();
79+
List<File> result = new ArrayList<File>();
8080
for (ResourceData data : (ArrayList<ResourceData>) manifest) {
8181
result.addAll(extractManifestClasspath(data));
8282
}
@@ -93,7 +93,7 @@ private static Collection<File> extractManifestClasspath(ResourceData manifestDa
9393
String classpathSpaceSeparated = (String) manifest.getMainAttributes().get(Attributes.Name.CLASS_PATH);
9494
if (classpathSpaceSeparated == null) return Collections.emptyList();
9595

96-
Collection<File> classpath = new ArrayList<>(1);
96+
Collection<File> classpath = new ArrayList<File>(1);
9797
for (String jar : classpathSpaceSeparated.split(" ")) {
9898
if (".".equals(jar)) continue;
9999

@@ -117,7 +117,7 @@ private static Map<String, Object> loadAllClassesFromJars(
117117
ClassHandler handler
118118
) throws IOException {
119119
// 0.75 is HashMap.DEFAULT_LOAD_FACTOR
120-
Map<String, Object> resources = new HashMap<>((int) (classNumberEstimate / 0.75));
120+
Map<String, Object> resources = new HashMap<String, Object>((int) (classNumberEstimate / 0.75));
121121

122122
for (File jarFile : jarFiles) {
123123
if (handler != null) {
@@ -154,7 +154,7 @@ private static Map<String, Object> loadAllClassesFromJars(
154154
resources.put(name, resourceData);
155155
}
156156
else if (previous instanceof ResourceData) {
157-
List<ResourceData> list = new ArrayList<>();
157+
List<ResourceData> list = new ArrayList<ResourceData>();
158158
list.add((ResourceData) previous);
159159
list.add(resourceData);
160160
resources.put(name, list);

compiler/preloader/src/org/jetbrains/kotlin/preloading/MemoryBasedClassLoader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.net.URL;
2121
import java.util.*;
2222

23-
@SuppressWarnings("unchecked")
2423
/**
2524
* A class loader which loads classes and resources from the given map.
2625
*
@@ -29,6 +28,7 @@
2928
* Therefore if you need to be able to find classes via findResource(), you should pass a fallback
3029
* class loader which is able to do that at any point of time.
3130
*/
31+
@SuppressWarnings("unchecked")
3232
public class MemoryBasedClassLoader extends ClassLoader {
3333
private final ClassCondition classesToLoadByParent;
3434
private final ClassLoader parent;
@@ -140,7 +140,7 @@ public Enumeration<URL> getResources(String name) throws IOException {
140140
Enumeration<URL> fromParent = parent.getResources(name);
141141
if (!own.hasMoreElements()) return fromParent;
142142

143-
List<URL> result = new ArrayList<>();
143+
List<URL> result = new ArrayList<URL>();
144144
while (own.hasMoreElements()) {
145145
result.add(own.nextElement());
146146
}
@@ -163,7 +163,7 @@ else if (resources instanceof ResourceData) {
163163
else {
164164
assert resources instanceof ArrayList : "Resource map should contain ResourceData or ArrayList<ResourceData>: " + name;
165165
List<ResourceData> resourceDatas = (ArrayList<ResourceData>) resources;
166-
List<URL> urls = new ArrayList<>(resourceDatas.size());
166+
List<URL> urls = new ArrayList<URL>(resourceDatas.size());
167167
for (ResourceData data : resourceDatas) {
168168
urls.add(data.getURL());
169169
}

compiler/preloader/src/org/jetbrains/kotlin/preloading/Preloader.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,29 @@ public static void main(String[] args) throws Exception {
4444
}
4545

4646
private static void run(String[] args) throws Exception {
47-
long startTime = System.nanoTime();
47+
final long startTime = System.nanoTime();
4848

49-
Options options = parseOptions(args);
49+
final Options options = parseOptions(args);
5050

5151
ClassLoader classLoader = createClassLoader(options);
5252

53-
Handler handler = getHandler(options, classLoader);
53+
final Handler handler = getHandler(options, classLoader);
5454
ClassLoader preloaded = ClassPreloadingUtils.preloadClasses(options.classpath, options.estimate, classLoader, null, handler);
5555

5656
Class<?> mainClass = preloaded.loadClass(options.mainClass);
5757
Method mainMethod = mainClass.getMethod("main", String[].class);
5858

5959
Runtime.getRuntime().addShutdownHook(
60-
new Thread(() -> {
61-
if (options.measure) {
62-
System.out.println();
63-
System.out.println("=== Preloader's measurements: ");
64-
System.out.format("Total time: %.3fs\n", (System.nanoTime() - startTime) / 1e9);
60+
new Thread(new Runnable() {
61+
@Override
62+
public void run() {
63+
if (options.measure) {
64+
System.out.println();
65+
System.out.println("=== Preloader's measurements: ");
66+
System.out.format("Total time: %.3fs\n", (System.nanoTime() - startTime) / 1e9);
67+
}
68+
handler.done();
6569
}
66-
handler.done();
6770
})
6871
);
6972

@@ -120,10 +123,10 @@ private static File getJdkToolsJar() {
120123
private static Options parseOptions(String[] args) throws Exception {
121124
List<File> classpath = Collections.emptyList();
122125
boolean measure = false;
123-
List<File> instrumenters = new ArrayList<>();
126+
List<File> instrumenters = new ArrayList<File>();
124127
int estimate = DEFAULT_CLASS_NUMBER_ESTIMATE;
125128
String mainClass = null;
126-
List<String> arguments = new ArrayList<>();
129+
List<String> arguments = new ArrayList<String>();
127130

128131
for (int i = 0; i < args.length; i++) {
129132
String arg = args[i];
@@ -162,7 +165,7 @@ else if ("-measure".equals(arg)) {
162165

163166
private static List<File> parseClassPath(String classpath) {
164167
String[] paths = classpath.split(File.pathSeparator);
165-
List<File> files = new ArrayList<>(paths.length);
168+
List<File> files = new ArrayList<File>(paths.length);
166169
for (String path : paths) {
167170
File file = new File(path);
168171
if (!file.exists()) {
@@ -176,10 +179,10 @@ private static List<File> parseClassPath(String classpath) {
176179
private static Handler getHandler(Options options, ClassLoader withInstrumenter) {
177180
if (!options.measure) return new Handler();
178181

179-
Instrumenter instrumenter = options.instrumenters.isEmpty() ? Instrumenter.DO_NOTHING : loadInstrumenter(withInstrumenter);
182+
final Instrumenter instrumenter = options.instrumenters.isEmpty() ? Instrumenter.DO_NOTHING : loadInstrumenter(withInstrumenter);
180183

181-
int[] counter = new int[1];
182-
int[] size = new int[1];
184+
final int[] counter = new int[1];
185+
final int[] size = new int[1];
183186
return new Handler() {
184187
@Override
185188
public void beforeDefineClass(String name, int sizeInBytes) {

0 commit comments

Comments
 (0)