Skip to content
Snippets Groups Projects
Commit 8c40ecd9 authored by Pekka Enberg's avatar Pekka Enberg
Browse files

Merge branch 'java'

parents 831b017e b16df0f9
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
<module>runjava</module> <module>runjava</module>
<module>tests</module> <module>tests</module>
<module>tests-isolates</module> <module>tests-isolates</module>
<module>tests-jre-extension</module>
</modules> </modules>
<dependencies> <dependencies>
...@@ -56,6 +57,11 @@ ...@@ -56,6 +57,11 @@
<artifactId>tests-isolates</artifactId> <artifactId>tests-isolates</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>io.osv</groupId>
<artifactId>tests-jre-extension</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
......
...@@ -43,6 +43,31 @@ ...@@ -43,6 +43,31 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>net.sf.cglib</pattern>
<shadedPattern>io.osv.shade.net.sf.cglib</shadedPattern>
</relocation>
<relocation>
<pattern>org.objectweb.asm</pattern>
<shadedPattern>io.osv.shade.org.objectweb.asm</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>
...@@ -60,8 +60,7 @@ public class ContextIsolator { ...@@ -60,8 +60,7 @@ public class ContextIsolator {
ClassLoader originalSystemClassLoader = getOsvClassLoader().getParent(); ClassLoader originalSystemClassLoader = getOsvClassLoader().getParent();
masterContext = new Context(originalSystemClassLoader, System.getProperties()); masterContext = new Context(originalSystemClassLoader, System.getProperties());
parentClassLoaderForIsolates = new TeeClassLoader( parentClassLoaderForIsolates = originalSystemClassLoader;
new FilteringClassLoader(originalSystemClassLoader, "io.osv."));
installSystemPropertiesProxy(); installSystemPropertiesProxy();
} }
......
package io.osv;
class FilteringClassLoader extends ClassLoader {
private final String allowedPrefix;
public FilteringClassLoader(ClassLoader parent, String allowedPrefix) {
super(parent);
this.allowedPrefix = allowedPrefix;
}
private boolean isClassAllowed(String name) {
return name.startsWith(allowedPrefix);
}
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
if (!isClassAllowed(name)) {
throw new ClassNotFoundException(name);
}
return super.loadClass(name, resolve);
}
}
package io.osv;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
class TeeClassLoader extends ClassLoader {
private ClassLoader delegate;
public TeeClassLoader(ClassLoader delegate) {
super(null);
this.delegate = delegate;
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
return delegate.loadClass(name);
}
@Override
protected URL findResource(String name) {
return delegate.getResource(name);
}
@Override
protected Enumeration<URL> findResources(String name) throws IOException {
return delegate.getResources(name);
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.osv</groupId>
<artifactId>java-parent</artifactId>
<version>${version}</version>
</parent>
<artifactId>tests-jre-extension</artifactId>
<packaging>jar</packaging>
<build>
<finalName>tests-jre-extension</finalName>
</build>
</project>
package tests;
/*
* Copyright (C) 2014 Cloudius Systems, Ltd.
*
* This work is open source software, licensed under the terms of the
* BSD license as described in the LICENSE file in the top-level directory.
*/
public class SomeExtensionClass {
}
...@@ -31,6 +31,11 @@ ...@@ -31,6 +31,11 @@
<artifactId>runjava</artifactId> <artifactId>runjava</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>io.osv</groupId>
<artifactId>tests-jre-extension</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>io.osv</groupId> <groupId>io.osv</groupId>
<artifactId>tests-isolates</artifactId> <artifactId>tests-isolates</artifactId>
...@@ -81,23 +86,6 @@ ...@@ -81,23 +86,6 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testSourceDirectory>${basedir}/src/main/java/</testSourceDirectory>
<testClassesDirectory>target/classes</testClassesDirectory>
<argLine>-ea -Djava.system.class.loader=io.osv.OsvSystemClassLoader
-Djava.util.logging.manager=io.osv.jul.IsolatingLogManager
</argLine>
<systemProperties>
<property>
<name>isolates.jar</name>
<value>${io.osv:tests-isolates:jar:jar-with-dependencies}</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>
...@@ -7,6 +7,7 @@ import java.util.concurrent.CyclicBarrier; ...@@ -7,6 +7,7 @@ import java.util.concurrent.CyclicBarrier;
import static io.osv.TestIsolateLaunching.runIsolate; import static io.osv.TestIsolateLaunching.runIsolate;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/* /*
* Copyright (C) 2014 Cloudius Systems, Ltd. * Copyright (C) 2014 Cloudius Systems, Ltd.
...@@ -66,4 +67,9 @@ public class ClassLoaderIsolationTest { ...@@ -66,4 +67,9 @@ public class ClassLoaderIsolationTest {
} }
} }
} }
@Test
public void testClassesFromExtensionDirectoryCanBeLoaded() throws Exception {
assertNotNull(SomeExtensionClass.class);
}
} }
...@@ -10,5 +10,8 @@ usr_files = FileMap() ...@@ -10,5 +10,8 @@ usr_files = FileMap()
usr_files.add('${OSV_BASE}/java/tests/target/runjava-tests.jar').to(_jar) usr_files.add('${OSV_BASE}/java/tests/target/runjava-tests.jar').to(_jar)
usr_files.add('${OSV_BASE}/java/tests-isolates/target/tests-isolates-jar-with-dependencies.jar').to(_isolates_jar) usr_files.add('${OSV_BASE}/java/tests-isolates/target/tests-isolates-jar-with-dependencies.jar').to(_isolates_jar)
usr_files.add('${OSV_BASE}/java/tests-jre-extension/target/tests-jre-extension.jar') \
.to('/usr/lib/jvm/jre/lib/ext/tests-jre-extension.jar')
run_tests = api.run_java(classpath=[_jar, _isolates_jar], run_tests = api.run_java(classpath=[_jar, _isolates_jar],
args=['-Disolates.jar=' + _isolates_jar, 'org.junit.runner.JUnitCore', 'io.osv.AllTests']) args=['-Disolates.jar=' + _isolates_jar, 'org.junit.runner.JUnitCore', 'io.osv.AllTests'])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment