Permalink
Browse files

nonlocking support - will build machine like it?

git-svn-id: https://svn.codehaus.org/groovy/eclipse/trunk@21689 a5544e8c-8a19-0410-ba12-f9af4593a198
  • Loading branch information...
1 parent 0b2a172 commit 44c7a6f3730080c7e3fe5ccea91dfd84609d1458 @aclement aclement committed Mar 1, 2011
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
@@ -17,3 +17,5 @@ Export-Package: org.codehaus.jdt.groovy.internal.compiler.ast,
org.eclipse.jdt.groovy.core,
org.eclipse.jdt.groovy.core.util,
org.eclipse.jdt.groovy.search
+Bundle-ClassPath: nlcl.jar,
+ .
@@ -13,7 +13,8 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
- plugin.xml
+ plugin.xml,\
+ nlcl.jar
src.includes = schema/,\
.settings/,\
JDTformatter.xml
Binary file not shown.
Binary file not shown.
@@ -15,12 +15,17 @@
import java.io.File;
import java.lang.reflect.Field;
+import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.jar.JarFile;
+import org.apache.xbean.classloader.NonLockingJarFileClassLoader;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.control.CompilationUnit;
import org.codehaus.groovy.control.CompilationUnit.ProgressListener;
@@ -85,8 +90,7 @@
PathLoaderPair(String classpath) {
this.classpath = classpath;
- this.groovyClassLoader = new GroovyClassLoader();
- configureClasspath(groovyClassLoader, classpath);
+ this.groovyClassLoader = new GroovyClassLoader(createConfigureLoader(classpath));
}
}
@@ -287,27 +291,87 @@ public void setCompilationUnit(CompilationUnit groovyCompilationUnit) {
}
- // FIXASC perf ok?
- private static void configureClasspath(GroovyClassLoader gcl, String path) {
- if (path != null) {
- if (path.indexOf(File.pathSeparator) != -1) {
- int pos = 0;
- while (pos != -1) {
- int nextSep = path.indexOf(File.pathSeparator, pos);
- if (nextSep == -1) {
- // last piece
- String p = path.substring(pos);
- gcl.addClasspath(p);
- pos = -1;
- } else {
- String p = path.substring(pos, nextSep);
- gcl.addClasspath(p);
- pos = nextSep + 1;
- }
+ // // FIXASC perf ok?
+ // private static void configureClasspath(URLClassLoader gcl, String path) {
+ // if (path != null) {
+ // if (path.indexOf(File.pathSeparator) != -1) {
+ // int pos = 0;
+ // while (pos != -1) {
+ // int nextSep = path.indexOf(File.pathSeparator, pos);
+ // if (nextSep == -1) {
+ // // last piece
+ // String p = path.substring(pos);
+ // gcl.addClasspath(p);
+ // pos = -1;
+ // } else {
+ // String p = path.substring(pos, nextSep);
+ // gcl.addClasspath(p);
+ // 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
}
}

0 comments on commit 44c7a6f

Please sign in to comment.