use of java.net.URLClassLoader in project groovy by apache.
the class ScriptCompilationExecuter method execute.
public long execute() throws Exception {
ClassLoader cl = new URLClassLoader(classpath, ClassLoader.getSystemClassLoader().getParent());
GroovyClassLoader gcl = new GroovyClassLoader(cl);
CompilationUnit cu = new CompilationUnit(new CompilerConfiguration(), null, gcl, new GroovyClassLoader(this.getClass().getClassLoader()));
for (File source : sources) {
cu.addSource(source);
}
long sd = System.nanoTime();
cu.compile(CompilePhase.CLASS_GENERATION.getPhaseNumber());
long dur = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - sd);
return dur;
}
use of java.net.URLClassLoader in project sonarqube by SonarSource.
the class ManifestUtilsTest method emptyManifest.
@Test
public void emptyManifest() throws Exception {
Manifest mf = new Manifest();
File jar = createJar(mf, "emptyManifest.jar");
URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[] { jar }));
assertThat(ManifestUtils.getPropertyValues(classloader, "foo")).isEmpty();
}
use of java.net.URLClassLoader in project sonarqube by SonarSource.
the class ManifestUtilsTest method manyManifests.
@Test
public void manyManifests() throws Exception {
Manifest mf1 = new Manifest();
mf1.getMainAttributes().putValue("foo", "bar");
File jar1 = createJar(mf1, "manyManifests-one.jar");
Manifest mf2 = new Manifest();
mf2.getMainAttributes().putValue("foo", "otherbar");
File jar2 = createJar(mf2, "manyManifests-two.jar");
URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[] { jar1, jar2 }));
List<String> values = ManifestUtils.getPropertyValues(classloader, "foo");
assertThat(values).containsOnly("bar", "otherbar");
}
use of java.net.URLClassLoader in project che by eclipse.
the class JUnitTestRunner method execute.
/**
* {@inheritDoc}
*/
@Override
public TestResult execute(Map<String, String> testParameters) throws Exception {
String projectAbsolutePath = testParameters.get("absoluteProjectPath");
boolean updateClasspath = Boolean.valueOf(testParameters.get("updateClasspath"));
boolean runClass = Boolean.valueOf(testParameters.get("runClass"));
String projectPath = testParameters.get("projectPath");
String projectType = "";
if (projectManager != null) {
projectType = projectManager.getProject(projectPath).getType();
}
ClassLoader currentClassLoader = this.getClass().getClassLoader();
TestClasspathProvider classpathProvider = classpathRegistry.getTestClasspathProvider(projectType);
URLClassLoader providedClassLoader = (URLClassLoader) classpathProvider.getClassLoader(projectAbsolutePath, projectPath, updateClasspath);
projectClassLoader = new URLClassLoader(providedClassLoader.getURLs(), null) {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
if (name.startsWith("javassist.")) {
return currentClassLoader.loadClass(name);
}
return super.findClass(name);
}
};
boolean isJUnit4Compatible = false;
boolean isJUnit3Compatible = false;
try {
Class.forName(JUNIT4X_RUNNER_CLASS, true, projectClassLoader);
isJUnit4Compatible = true;
} catch (Exception ignored) {
}
try {
Class.forName(JUNIT3X_RUNNER_CLASS, true, projectClassLoader);
isJUnit3Compatible = true;
} catch (Exception ignored) {
}
boolean useJUnitV3API = false;
if (!isJUnit4Compatible) {
if (!isJUnit3Compatible) {
throw new ClassNotFoundException("JUnit classes not found in the following project classpath: " + Arrays.asList(providedClassLoader.getURLs()));
} else {
useJUnitV3API = true;
}
}
String currentWorkingDir = System.getProperty("user.dir");
try {
System.setProperty("user.dir", projectAbsolutePath);
TestResult testResult;
if (runClass) {
String fqn = testParameters.get("fqn");
testResult = useJUnitV3API ? run3x(fqn) : run4x(fqn);
} else {
testResult = useJUnitV3API ? runAll3x(projectAbsolutePath) : runAll4x(projectAbsolutePath);
}
return testResult;
} finally {
System.setProperty("user.dir", currentWorkingDir);
}
}
use of java.net.URLClassLoader in project pinpoint by naver.
the class PinpointClassFilterTest method testDoFilter_Package.
@Test
public void testDoFilter_Package() throws Exception {
final URLClassLoader agentClassLoader = new URLClassLoader(new URL[0]);
ClassFileFilter filter = new PinpointClassFilter(agentClassLoader);
final ClassLoader defaultClassLoader = ClassLoaderUtils.getDefaultClassLoader();
Assert.assertSame("pinpoint", filter.accept(defaultClassLoader, "com/navercorp/pinpoint/", null, null, null), ClassFileFilter.SKIP);
Assert.assertSame(filter.accept(defaultClassLoader, "java/test", null, null, null), ClassFileFilter.CONTINUE);
Assert.assertSame(filter.accept(defaultClassLoader, "javax/test", null, null, null), ClassFileFilter.CONTINUE);
Assert.assertSame(filter.accept(defaultClassLoader, "test", null, null, null), ClassFileFilter.CONTINUE);
}
Aggregations