public static void rootLoader(String args[]) { String conf = System.getProperty("groovy.starter.conf",null); final LoaderConfiguration lc = new LoaderConfiguration(); exit("classpath parameter needs argument"); lc.addClassPath(args[argsOffset+1]); argsOffset+=2; hadCP=true; exit("main parameter needs argument"); lc.setMainClass(args[argsOffset+1]); argsOffset+=2; hadMain=true; if (lc.getMainClass()==null && conf==null) { exit("no configuration file or main class specified"); lc.configure(new FileInputStream(conf)); } catch (Exception e) { System.err.println("exception while configuring main class loader:"); Method m=null; try { Class c = loader.loadClass(lc.getMainClass()); m = c.getMethod("main", String[].class); } catch (ClassNotFoundException | NoSuchMethodException | SecurityException e1) {
private void findMatchingFiles(File[] files, Pattern pattern, boolean recursive) { for (File file : files) { String fileString = getSlashyPath(file.getPath()); Matcher m = pattern.matcher(fileString); if (m.matches() && file.isFile()) { addFile(file); } if (file.isDirectory() && recursive) { final File[] dirFiles = file.listFiles(); if (dirFiles != null) { findMatchingFiles(dirFiles, pattern, true); } } } }
loadPath = assignProperties(loadPath); loadFilteredPath(loadPath); } else if (line.startsWith(GRAB_PREFIX)) { String grabParams = line.substring(GRAB_PREFIX.length()).trim(); grabList.add(assignProperties(grabParams)); } else if (line.startsWith(MAIN_PREFIX)) { if (main != null) String params = line.substring(PROP_PREFIX.length()).trim(); String key = SystemUtil.setSystemPropertyFrom(params); System.setProperty(key, assignProperties(System.getProperty(key))); } else if (line.startsWith(CONFIGSCRIPT_PREFIX)) { String script = line.substring(CONFIGSCRIPT_PREFIX.length()).trim(); configScripts.add(assignProperties(script)); } else { throw new IOException("unexpected line in " + lineNumber + " : " + line);
private RootLoader makeRoot() { String[] list = taskClasspath.list(); LoaderConfiguration lc = new LoaderConfiguration(); for (int i=0; i<list.length; i++) { if (list[i].matches(".*ant-[^/]*jar$")) { continue; } if (list[i].matches(".*commons-logging-[^/]*jar$")) { continue; } if (list[i].matches(".*xerces-[^/]*jar$")) { continue; } lc.addFile(list[i]); } return new RootLoader(lc); }
propertyValue = getSlashyPath(propertyValue); propertyValue = correctDoubleSlash(propertyValue, propertyIndexEnd, str); result.append(propertyValue);
/** * Adds a file to the classpath if it exists. * * @param filename the name of the file to add */ public void addFile(String filename) { if (filename != null) addFile(new File(filename)); }
/** * constructs a new RootLoader with a @see LoaderConfiguration * object which holds the classpath */ public RootLoader(LoaderConfiguration lc) { this(chooseParent()); Thread.currentThread().setContextClassLoader(this); URL[] urls = lc.getClassPathUrls(); for (int i = 0; i < urls.length; i++) { addURL(urls[i]); } }
/** * constructs a new RootLoader with a {@link LoaderConfiguration} * object which holds the classpath */ public RootLoader(LoaderConfiguration lc) { this(chooseParent()); Thread.currentThread().setContextClassLoader(this); URL[] urls = lc.getClassPathUrls(); for (URL url : urls) { addURL(url); } // TODO M12N eventually defer this until later when we have a full Groovy // environment and use normal Grape.grab() String groovyHome = System.getProperty("groovy.home"); List<String> grabUrls = lc.getGrabUrls(); for (String grabUrl : grabUrls) { Map<String, Object> grabParts = GrapeUtil.getIvyParts(grabUrl); String group = grabParts.get("group").toString(); String module = grabParts.get("module").toString(); String name = grabParts.get("module").toString() + "-" + grabParts.get("version") + ".jar"; File jar = new File(groovyHome + "/repo/" + group + "/" + module + "/jars/" + name); try { addURL(jar.toURI().toURL()); } catch (MalformedURLException e) { // ignore } } }
propertyValue = getSlashyPath(propertyValue); result += propertyValue;
private RootLoader makeRoot() { String[] list = taskClasspath.list(); LoaderConfiguration lc = new LoaderConfiguration(); for (int i=0; i<list.length; i++) { if (list[i].matches(".*ant-[^/]*jar$")) { continue; } if (list[i].matches(".*commons-logging-[^/]*jar$")) { continue; } if (list[i].matches(".*xerces-[^/]*jar$")) { continue; } lc.addFile(list[i]); } return new RootLoader(lc); }
/** * Adds a classpath to this configuration. It expects a string with * multiple paths, separated by the system dependent path separator. * Expands wildcards, e.g. dir/* into all the jars in dir. * * @param path the path as a path separator delimited string * @see java.io.File#pathSeparator */ public void addClassPath(String path) { String[] paths = path.split(File.pathSeparator); for (String cpPath : paths) { // Check to support wild card classpath if (cpPath.endsWith("*")) { File dir = new File(cpPath.substring(0, cpPath.length() - 1)); File[] files = dir.listFiles(); if (files != null) { for (File file : files) { if (file.isFile() && file.getName().endsWith(".jar")) addFile(file); } } } else { addFile(new File(cpPath)); } } }
propertyValue = getSlashyPath(propertyValue); propertyValue = correctDoubleSlash(propertyValue,propertyIndexEnd,str); result += propertyValue;
/** * constructs a new RootLoader with a {@link LoaderConfiguration} * object which holds the classpath */ public RootLoader(LoaderConfiguration lc) { this(chooseParent()); Thread.currentThread().setContextClassLoader(this); URL[] urls = lc.getClassPathUrls(); for (URL url : urls) { addURL(url); } }
propertyValue = getSlashyPath(propertyValue); result += propertyValue;
public static void rootLoader(String args[]) { String conf = System.getProperty("groovy.starter.conf",null); LoaderConfiguration lc = new LoaderConfiguration(); exit("classpath parameter needs argument"); lc.addClassPath(args[argsOffset+1]); argsOffset+=2; hadCP=true; exit("main parameter needs argument"); lc.setMainClass(args[argsOffset+1]); argsOffset+=2; hadMain=true; if (lc.getMainClass()==null && conf==null) { exit("no configuration file or main class specified"); lc.configure(new FileInputStream(conf)); } catch (Exception e) { System.err.println("exception while configuring main class loader:"); Method m=null; try { Class c = loader.loadClass(lc.getMainClass()); m = c.getMethod("main", new Class[]{String[].class}); } catch (ClassNotFoundException e1) {
private void loadFilteredPath(String filter) { if (filter == null) return; filter = getSlashyPath(filter); int starIndex = filter.indexOf(WILDCARD); if (starIndex == -1) { addFile(new File(filter)); return; } boolean recursive = filter.contains(ALL_WILDCARD); if (filter.lastIndexOf('/') < starIndex) { starIndex = filter.lastIndexOf('/') + 1; } String startDir = filter.substring(0, starIndex - 1); File root = new File(startDir); filter = Pattern.quote(filter); filter = filter.replaceAll("\\" + WILDCARD + "\\" + WILDCARD, MATCH_ALL); filter = filter.replaceAll("\\" + WILDCARD, MATCH_FILE_NAME); Pattern pattern = Pattern.compile(filter); final File[] files = root.listFiles(); if (files != null) { findMatchingFiles(files, pattern, recursive); } }
private RootLoader makeRoot() { String[] list = taskClasspath.list(); LoaderConfiguration lc = new LoaderConfiguration(); for (int i=0; i<list.length; i++) { if (list[i].matches(".*ant-[^/]*jar$")) { continue; } if (list[i].matches(".*commons-logging-[^/]*jar$")) { continue; } if (list[i].matches(".*xerces-[^/]*jar$")) { continue; } lc.addFile(list[i]); } return new RootLoader(lc); }
/** * configures this loader with a stream * * @param is stream used to read the configuration * @throws IOException if reading or parsing the contents of the stream fails */ public void configure(InputStream is) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); int lineNumber = 0; while (true) { String line = reader.readLine(); if (line == null) break; line = line.trim(); lineNumber++; if (line.startsWith("#") || line.length() == 0) continue; if (line.startsWith(LOAD_PREFIX)) { String loadPath = line.substring(LOAD_PREFIX.length()).trim(); loadPath = assignProperties(loadPath); loadFilteredPath(loadPath); } else if (line.startsWith(MAIN_PREFIX)) { if (main != null) throw new IOException("duplicate definition of main in line " + lineNumber + " : " + line); main = line.substring(MAIN_PREFIX.length()).trim(); } else { throw new IOException("unexpected line in " + lineNumber + " : " + line); } } if (requireMain && main == null) throw new IOException("missing main class definition in config file"); }
/** * Adds a file to the classpath if it exists. * * @param filename the name of the file to add */ public void addFile(String filename) { if (filename != null) addFile(new File(filename)); }
propertyValue = getSlashyPath(propertyValue); propertyValue = correctDoubleSlash(propertyValue,propertyIndexEnd,str); result += propertyValue;