Skip to content

Commit

Permalink
nonlocking support - will build machine like it?
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.codehaus.org/groovy/eclipse/trunk@21689 a5544e8c-8a19-0410-ba12-f9af4593a198
  • Loading branch information
aclement committed Mar 1, 2011
1 parent 0b2a172 commit 44c7a6f
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 22 deletions.
1 change: 1 addition & 0 deletions base/org.eclipse.jdt.groovy.core/.classpath
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry exported="true" kind="lib" path="nlcl.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
Expand Down
2 changes: 2 additions & 0 deletions base/org.eclipse.jdt.groovy.core/META-INF/MANIFEST.MF
Expand Up @@ -17,3 +17,5 @@ Export-Package: org.codehaus.jdt.groovy.internal.compiler.ast,
org.eclipse.jdt.groovy.core, org.eclipse.jdt.groovy.core,
org.eclipse.jdt.groovy.core.util, org.eclipse.jdt.groovy.core.util,
org.eclipse.jdt.groovy.search org.eclipse.jdt.groovy.search
Bundle-ClassPath: nlcl.jar,
.
3 changes: 2 additions & 1 deletion base/org.eclipse.jdt.groovy.core/build.properties
Expand Up @@ -13,7 +13,8 @@ source.. = src/
output.. = bin/ output.. = bin/
bin.includes = META-INF/,\ bin.includes = META-INF/,\
.,\ .,\
plugin.xml plugin.xml,\
nlcl.jar
src.includes = schema/,\ src.includes = schema/,\
.settings/,\ .settings/,\
JDTformatter.xml JDTformatter.xml
Binary file added base/org.eclipse.jdt.groovy.core/nlcl-src.jar
Binary file not shown.
Binary file added base/org.eclipse.jdt.groovy.core/nlcl.jar
Binary file not shown.
Expand Up @@ -15,12 +15,17 @@


import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.jar.JarFile; import java.util.jar.JarFile;


import org.apache.xbean.classloader.NonLockingJarFileClassLoader;
import org.codehaus.groovy.ast.ClassNode; import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.control.CompilationUnit; import org.codehaus.groovy.control.CompilationUnit;
import org.codehaus.groovy.control.CompilationUnit.ProgressListener; import org.codehaus.groovy.control.CompilationUnit.ProgressListener;
Expand Down Expand Up @@ -85,8 +90,7 @@ static class PathLoaderPair {


PathLoaderPair(String classpath) { PathLoaderPair(String classpath) {
this.classpath = classpath; this.classpath = classpath;
this.groovyClassLoader = new GroovyClassLoader(); this.groovyClassLoader = new GroovyClassLoader(createConfigureLoader(classpath));
configureClasspath(groovyClassLoader, classpath);
} }
} }


Expand Down Expand Up @@ -287,27 +291,87 @@ public void setCompilationUnit(CompilationUnit groovyCompilationUnit) {


} }


// FIXASC perf ok? // // FIXASC perf ok?
private static void configureClasspath(GroovyClassLoader gcl, String path) { // private static void configureClasspath(URLClassLoader gcl, String path) {
if (path != null) { // if (path != null) {
if (path.indexOf(File.pathSeparator) != -1) { // if (path.indexOf(File.pathSeparator) != -1) {
int pos = 0; // int pos = 0;
while (pos != -1) { // while (pos != -1) {
int nextSep = path.indexOf(File.pathSeparator, pos); // int nextSep = path.indexOf(File.pathSeparator, pos);
if (nextSep == -1) { // if (nextSep == -1) {
// last piece // // last piece
String p = path.substring(pos); // String p = path.substring(pos);
gcl.addClasspath(p); // gcl.addClasspath(p);
pos = -1; // pos = -1;
} else { // } else {
String p = path.substring(pos, nextSep); // String p = path.substring(pos, nextSep);
gcl.addClasspath(p); // gcl.addClasspath(p);
pos = nextSep + 1; // pos = nextSep + 1;
} // }
// }
// } else {
// gcl.addClasspath(path);
// }
// }
// }

private static boolean NONLOCKING = false;

static {
try {
boolean value = System.getProperty("greclipse.nonlocking", "false").equalsIgnoreCase("true");
NONLOCKING = value;
if (value) {
System.out.println("property set: greclipse.nonlocking: will try to avoid locking jars");
}
} catch (Throwable t) {
}
}

private static URLClassLoader createLoader(URL[] urls, ClassLoader parent) {
if (NONLOCKING) {
return new NonLockingJarFileClassLoader("AST Transform loader", urls, parent);
} else {
return new URLClassLoader(urls, parent);
}
}

private static URLClassLoader createConfigureLoader(String path) {
if (path == null) {
return createLoader(null, Thread.currentThread().getContextClassLoader());
}
List<URL> urls = new ArrayList<URL>();
if (path.indexOf(File.pathSeparator) != -1) {
int pos = 0;
while (pos != -1) {
int nextSep = path.indexOf(File.pathSeparator, pos);
if (nextSep == -1) {
// last piece
addNewURL(path.substring(pos), urls);
pos = -1;
} else {
addNewURL(path.substring(pos, nextSep), urls);
pos = nextSep + 1;
}
}
} else {
addNewURL(path, urls);
}
return createLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader());
}

private static void addNewURL(String path, List<URL> existingURLs) {
try {
File f = new File(path);
URL newURL = f.toURI().toURL();
for (URL url : existingURLs) {
if (url.equals(newURL)) {
return;
} }
} else {
gcl.addClasspath(path);
} }
existingURLs.add(newURL);
} catch (MalformedURLException e) {
// It was a busted URL anyway
} }
} }


Expand Down

0 comments on commit 44c7a6f

Please sign in to comment.