From f7c6213ee7cd4afb6f11b5ce14479aa68974b01c Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Fri, 9 Aug 2013 19:05:15 +0200 Subject: tests for fancy classloader configurations --- test/files/run/t6240a.check | 1 + test/files/run/t6240a/StepOne.java | 41 +++++++++++++++++++++++++++++++++++ test/files/run/t6240a/StepTwo.scala | 7 ++++++ test/files/run/t6240a/Test.scala | 16 ++++++++++++++ test/files/run/t6240b.check | 1 + test/files/run/t6240b/StepOne.java | 41 +++++++++++++++++++++++++++++++++++ test/files/run/t6240b/StepThree.scala | 4 ++++ test/files/run/t6240b/StepTwo.scala | 10 +++++++++ test/files/run/t6240b/Test.scala | 16 ++++++++++++++ 9 files changed, 137 insertions(+) create mode 100644 test/files/run/t6240a.check create mode 100644 test/files/run/t6240a/StepOne.java create mode 100644 test/files/run/t6240a/StepTwo.scala create mode 100644 test/files/run/t6240a/Test.scala create mode 100644 test/files/run/t6240b.check create mode 100644 test/files/run/t6240b/StepOne.java create mode 100644 test/files/run/t6240b/StepThree.scala create mode 100644 test/files/run/t6240b/StepTwo.scala create mode 100644 test/files/run/t6240b/Test.scala (limited to 'test') diff --git a/test/files/run/t6240a.check b/test/files/run/t6240a.check new file mode 100644 index 0000000000..29f695b6f4 --- /dev/null +++ b/test/files/run/t6240a.check @@ -0,0 +1 @@ +StepTwo.type diff --git a/test/files/run/t6240a/StepOne.java b/test/files/run/t6240a/StepOne.java new file mode 100644 index 0000000000..7abd148d69 --- /dev/null +++ b/test/files/run/t6240a/StepOne.java @@ -0,0 +1,41 @@ +import java.io.File; +import java.io.IOException; +import java.lang.ClassNotFoundException; +import java.lang.NoSuchMethodException; +import java.lang.IllegalAccessException; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.net.URLClassLoader; +import java.net.MalformedURLException; + +public class StepOne { + public static void main(String[] args) + throws MalformedURLException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException { + String[] launchPaths = System.getProperty("launch.classpath").split(":"); + + // move away StepThree + File tempDir = File.createTempFile("temp", Long.toString(System.nanoTime())); + System.setProperty("launch.step.three", tempDir.getAbsolutePath()); + tempDir.delete(); + tempDir.mkdir(); + File[] testClasses = new File(launchPaths[0]).listFiles(); + for (int i = 0; i < testClasses.length; i++) { + File testClass = testClasses[i]; + if (testClass.getPath().contains("StepThree")) { + File testClassMoved = new File(tempDir.getAbsolutePath() + "/" + testClass.getName()); + testClass.renameTo(testClassMoved); + } + } + + // launch StepTwo + URL[] launchURLs = new URL[launchPaths.length]; + for (int i = 0; i < launchPaths.length; i++) { + launchURLs[i] = new File(launchPaths[i]).toURL(); + } + URLClassLoader classLoader = new URLClassLoader(launchURLs, Object.class.getClassLoader()); + Class stepTwo = classLoader.loadClass("StepTwo"); + Method main = stepTwo.getDeclaredMethod("main", String[].class); + main.invoke(null, (Object)(new String[]{})); + } +} \ No newline at end of file diff --git a/test/files/run/t6240a/StepTwo.scala b/test/files/run/t6240a/StepTwo.scala new file mode 100644 index 0000000000..fc3221921d --- /dev/null +++ b/test/files/run/t6240a/StepTwo.scala @@ -0,0 +1,7 @@ +import java.io.File +import java.net.URLClassLoader + +object StepTwo extends App { + import scala.reflect.runtime.universe._ + println(typeOf[StepTwo.type]) +} \ No newline at end of file diff --git a/test/files/run/t6240a/Test.scala b/test/files/run/t6240a/Test.scala new file mode 100644 index 0000000000..6ae43c4809 --- /dev/null +++ b/test/files/run/t6240a/Test.scala @@ -0,0 +1,16 @@ +import java.io.File +import scala.sys.process._ + +object Test extends App { + def prop(key: String) = { + val value = System.getProperties.getProperty(key) + assert(value != null, key) + value + } + val testClassesDir = prop("partest.output") + assert(new File(testClassesDir).exists, testClassesDir) + val fullTestClassesClasspath = testClassesDir + prop("path.separator") + prop("java.class.path") + val javaBinary = if (new File(prop("javacmd")).isAbsolute) prop("javacmd") else prop("java.home") + "/bin/" + prop("javacmd") + assert(new File(javaBinary).exists, javaBinary) + List(javaBinary, "-cp", testClassesDir, "-Dlaunch.classpath=" + fullTestClassesClasspath, "StepOne").! +} \ No newline at end of file diff --git a/test/files/run/t6240b.check b/test/files/run/t6240b.check new file mode 100644 index 0000000000..255836105a --- /dev/null +++ b/test/files/run/t6240b.check @@ -0,0 +1 @@ +StepThree.type diff --git a/test/files/run/t6240b/StepOne.java b/test/files/run/t6240b/StepOne.java new file mode 100644 index 0000000000..7abd148d69 --- /dev/null +++ b/test/files/run/t6240b/StepOne.java @@ -0,0 +1,41 @@ +import java.io.File; +import java.io.IOException; +import java.lang.ClassNotFoundException; +import java.lang.NoSuchMethodException; +import java.lang.IllegalAccessException; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.net.URLClassLoader; +import java.net.MalformedURLException; + +public class StepOne { + public static void main(String[] args) + throws MalformedURLException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException { + String[] launchPaths = System.getProperty("launch.classpath").split(":"); + + // move away StepThree + File tempDir = File.createTempFile("temp", Long.toString(System.nanoTime())); + System.setProperty("launch.step.three", tempDir.getAbsolutePath()); + tempDir.delete(); + tempDir.mkdir(); + File[] testClasses = new File(launchPaths[0]).listFiles(); + for (int i = 0; i < testClasses.length; i++) { + File testClass = testClasses[i]; + if (testClass.getPath().contains("StepThree")) { + File testClassMoved = new File(tempDir.getAbsolutePath() + "/" + testClass.getName()); + testClass.renameTo(testClassMoved); + } + } + + // launch StepTwo + URL[] launchURLs = new URL[launchPaths.length]; + for (int i = 0; i < launchPaths.length; i++) { + launchURLs[i] = new File(launchPaths[i]).toURL(); + } + URLClassLoader classLoader = new URLClassLoader(launchURLs, Object.class.getClassLoader()); + Class stepTwo = classLoader.loadClass("StepTwo"); + Method main = stepTwo.getDeclaredMethod("main", String[].class); + main.invoke(null, (Object)(new String[]{})); + } +} \ No newline at end of file diff --git a/test/files/run/t6240b/StepThree.scala b/test/files/run/t6240b/StepThree.scala new file mode 100644 index 0000000000..210795d68f --- /dev/null +++ b/test/files/run/t6240b/StepThree.scala @@ -0,0 +1,4 @@ +object StepThree extends App { + import scala.reflect.runtime.universe._ + println(typeOf[StepThree.type]) +} \ No newline at end of file diff --git a/test/files/run/t6240b/StepTwo.scala b/test/files/run/t6240b/StepTwo.scala new file mode 100644 index 0000000000..88e46492e3 --- /dev/null +++ b/test/files/run/t6240b/StepTwo.scala @@ -0,0 +1,10 @@ +import java.io.File +import java.net.URLClassLoader + +object StepTwo extends App { + val classes = new File(System.getProperty("launch.step.three")) + val cl = new URLClassLoader(Array(classes.toURI.toURL), getClass.getClassLoader) + val stepThree = cl.loadClass("StepThree") + val main = stepThree.getDeclaredMethod("main", classOf[Array[String]]) + main.invoke(null, Array[String]()) +} \ No newline at end of file diff --git a/test/files/run/t6240b/Test.scala b/test/files/run/t6240b/Test.scala new file mode 100644 index 0000000000..6ae43c4809 --- /dev/null +++ b/test/files/run/t6240b/Test.scala @@ -0,0 +1,16 @@ +import java.io.File +import scala.sys.process._ + +object Test extends App { + def prop(key: String) = { + val value = System.getProperties.getProperty(key) + assert(value != null, key) + value + } + val testClassesDir = prop("partest.output") + assert(new File(testClassesDir).exists, testClassesDir) + val fullTestClassesClasspath = testClassesDir + prop("path.separator") + prop("java.class.path") + val javaBinary = if (new File(prop("javacmd")).isAbsolute) prop("javacmd") else prop("java.home") + "/bin/" + prop("javacmd") + assert(new File(javaBinary).exists, javaBinary) + List(javaBinary, "-cp", testClassesDir, "-Dlaunch.classpath=" + fullTestClassesClasspath, "StepOne").! +} \ No newline at end of file -- cgit v1.2.3