org.codehaus.groovy.tools.GroovyStarter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of groovy-all-minimal Show documentation
Show all versions of groovy-all-minimal Show documentation
Groovy: A powerful, dynamic language for the JVM
/*
* Copyright 2003-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.groovy.tools;
import java.lang.reflect .*;
import java.io.FileInputStream;
/**
* Helper class to help classworlds to load classes.
*/
public class GroovyStarter {
static void printUsage() {
System.out.println("possible programs are 'groovyc','groovy','console', and 'groovysh'");
System.exit(1);
}
public static void rootLoader(String args[]) {
String conf = System.getProperty("groovy.starter.conf",null);
LoaderConfiguration lc = new LoaderConfiguration();
// evaluate parameters
boolean hadMain=false, hadConf=false, hadCP=false;
int argsOffset = 0;
while (args.length-argsOffset>0 && !(hadMain && hadConf && hadCP)) {
if (args[argsOffset].equals("--classpath")) {
if (hadCP) break;
if (args.length==argsOffset+1) {
exit("classpath parameter needs argument");
}
lc.addClassPath(args[argsOffset+1]);
argsOffset+=2;
} else if (args[argsOffset].equals("--main")) {
if (hadMain) break;
if (args.length==argsOffset+1) {
exit("main parameter needs argument");
}
lc.setMainClass(args[argsOffset+1]);
argsOffset+=2;
} else if (args[argsOffset].equals("--conf")) {
if (hadConf) break;
if (args.length==argsOffset+1) {
exit("conf parameter needs argument");
}
conf=args[argsOffset+1];
argsOffset+=2;
} else {
break;
}
}
// we need to know the class we want to start
if (lc.getMainClass()==null && conf==null) {
exit("no configuration file or main class specified");
}
// copy arguments for main class
String[] newArgs = new String[args.length-argsOffset];
for (int i=0; i