use of ceylon.modules.CeylonRuntimeException in project ceylon by eclipse.
the class AbstractRuntime method execute.
public void execute(Configuration conf) throws Exception {
String exe = conf.module;
// FIXME: argument checks could be done earlier
if (exe == null) {
throw new CeylonRuntimeException("No initial module defined");
}
int p = exe.indexOf("/");
if (p == 0) {
throw new CeylonRuntimeException("Missing runnable info: " + exe);
}
if (p == exe.length() - 1) {
throw new CeylonRuntimeException("Missing version info: " + exe);
}
String name = exe.substring(0, p > 0 ? p : exe.length());
String mv = (p > 0 ? exe.substring(p + 1) : null);
final ClassLoaderHolder clh = createClassLoader(name, mv, conf);
execute(conf, name, clh);
}
use of ceylon.modules.CeylonRuntimeException in project ceylon by eclipse.
the class AbstractRuntime method invokeRun.
protected static void invokeRun(ClassLoaderHolder clh, String moduleName, String ceylonRunnableName, final String[] args) throws Exception {
final Class<?> runClass;
ClassLoader cl = clh.getClassLoader();
ClassLoader oldClassLoader = SecurityActions.setContextClassLoader(cl);
try {
try {
String javaClassName = JVMModuleUtil.javaClassNameFromCeylon(moduleName, ceylonRunnableName);
if (ceylonRunnableName == null) {
ceylonRunnableName = moduleName + "::" + JVMModuleUtil.RUN_INFO_CLASS;
}
runClass = cl.loadClass(javaClassName);
} catch (ClassNotFoundException cnfe) {
String type = Character.isUpperCase(ceylonRunnableName.charAt(0)) ? "class" : "function";
String msg = String.format("Could not find toplevel %s '%s'.", type, ceylonRunnableName);
if (!moduleName.equals(Constants.DEFAULT.toString()) && !ceylonRunnableName.contains(".") && !ceylonRunnableName.contains("::")) {
msg += String.format(" Class and method names need to be fully qualified, maybe you meant '%s'?", moduleName + "::" + ceylonRunnableName);
}
// msg += " [" + clh + "]";
throw new CeylonRuntimeException(msg);
}
if ((runClass.getModifiers() & Modifier.PUBLIC) == 0) {
String type = Character.isUpperCase(ceylonRunnableName.charAt(0)) ? "class" : "function";
String msg = String.format("Cannot run toplevel %s '%s': it should be shared.", type, ceylonRunnableName);
throw new CeylonRuntimeException(msg);
}
try {
SecurityActions.invokeRun(runClass, args);
} catch (NoSuchMethodException ex) {
String type = Character.isUpperCase(ceylonRunnableName.charAt(0)) ? "class" : "function";
String msg = String.format("Cannot run toplevel %s '%s': it should have no parameters or they should all have default values.", type, ceylonRunnableName);
throw new CeylonRuntimeException(msg);
}
} finally {
SecurityActions.setContextClassLoader(oldClassLoader);
}
}
use of ceylon.modules.CeylonRuntimeException in project ceylon by eclipse.
the class CeylonRunTool method startInFlatClasspath.
private void startInFlatClasspath(String module, String version) {
JavaRunnerOptions options = new JavaRunnerOptions();
if (repos != null) {
for (URI userRepository : repos) {
options.addUserRepository(userRepository.toASCIIString());
}
}
if (getCwd() != null) {
options.setWorkingDirectory(getCwd().getAbsolutePath());
}
options.setOffline(offline);
options.setSystemRepository(systemRepo);
options.setVerboseCategory(verbose);
options.setRun(prependModuleName(module, run));
options.setOverrides(overrides);
options.setDowngradeDist(!upgradeDist);
options.setExtraModules(extraModules);
try {
Runner runner = CeylonToolProvider.getRunner(Backend.Java, options, module, version);
runner.run(args.toArray(new String[args.size()]));
} catch (ModuleNotFoundException e) {
throw new CeylonRuntimeException(e.getMessage());
}
}
use of ceylon.modules.CeylonRuntimeException in project ceylon by eclipse.
the class CeylonRunTool method run.
@Override
public void run() throws IOException {
compileFlags = processCompileFlags(compileFlags, DefaultToolOptions.getRunToolCompileFlags(org.eclipse.ceylon.common.Backend.Java));
String module = ModuleUtil.moduleName(moduleNameOptVersion);
String version = checkModuleVersionsOrShowSuggestions(module, ModuleUtil.moduleVersion(moduleNameOptVersion), ModuleQuery.Type.JVM, Versions.JVM_BINARY_MAJOR_VERSION, Versions.JVM_BINARY_MINOR_VERSION, // JS binary but don't care since JVM
null, null, compileFlags);
if (version == null) {
return;
}
if (!version.isEmpty()) {
moduleNameOptVersion = ModuleUtil.makeModuleName(module, version);
}
if (flatClasspath) {
startInFlatClasspath(module, version);
return;
}
// else go on with JBoss modules
ArrayList<String> argList = new ArrayList<String>();
String ceylonVersion = System.getProperty(Constants.PROP_CEYLON_SYSTEM_VERSION);
if (ceylonVersion == null) {
ceylonVersion = Versions.CEYLON_VERSION_NUMBER;
}
String sysRep;
if (systemRepo != null) {
sysRep = systemRepo;
} else {
sysRep = System.getProperty(Constants.PROP_CEYLON_SYSTEM_REPO);
}
if (run != null) {
argList.add("-run");
argList.add(prependModuleName(module, run));
}
if (offline) {
argList.add("-offline");
}
if (verbose != null) {
argList.add("-verbose");
if (verbose.isEmpty()) {
argList.add("all");
} else {
argList.add(verbose);
}
}
argList.add("-sysrep");
argList.add(sysRep);
if (!upgradeDist) {
argList.add("-downgrade-dist");
}
if (cacheRepo != null) {
argList.add("-cacherep");
argList.add(cacheRepo);
}
if (overrides != null) {
argList.add("-overrides");
argList.add(overrides);
}
if (noDefRepos) {
argList.add("-nodefreps");
}
if (autoExportMavenDependencies) {
argList.add("-auto-export-maven-dependencies");
}
if (repos != null) {
for (URI repo : this.repos) {
argList.add("-rep");
argList.add(repo.toString());
}
}
argList.add(moduleNameOptVersion);
argList.addAll(args);
try {
if (runtimeModule == null) {
synchronized (ModuleLoader.class) {
if (runtimeModule == null) {
org.jboss.modules.Module.setModuleLogger(new NoGreetingJDKModuleLogger());
System.setProperty("boot.module.loader", InitialModuleLoader.class.getName());
org.jboss.modules.Main.main(moduleArguments(argList, sysRep, ceylonVersion));
// set runtime module
ModuleLoader ml = Module.getBootModuleLoader();
runtimeModule = ml.loadModule(ModuleIdentifier.create(CEYLON_RUNTIME, ceylonVersion));
} else {
runtimeModule.run(moduleArguments(argList, null, null));
}
}
} else {
runtimeModule.run(moduleArguments(argList, null, null));
}
} catch (Error err) {
throw err;
} catch (RuntimeException e) {
// get around a class loader issue
if (e instanceof CeylonRuntimeException == false && e.getClass().getName().equals("ceylon.modules.CeylonRuntimeException"))
throw new CeylonRuntimeException(e.getMessage());
throw e;
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
use of ceylon.modules.CeylonRuntimeException in project ceylon by eclipse.
the class AbstractJBossRuntime method createClassLoader.
public ClassLoaderHolder createClassLoader(String name, String version, Configuration conf) throws Exception {
if (RepositoryManager.DEFAULT_MODULE.equals(name)) {
if (version != null) {
throw new CeylonRuntimeException("Invalid module identifier: default module should not have any version");
}
} else {
if (version == null) {
StringBuilder sb = new StringBuilder("Invalid module identifier: missing required version");
sb.append(" (should be of the form ");
sb.append(name);
sb.append("/version)");
throw new CeylonRuntimeException(sb.toString());
}
}
ModuleIdentifier moduleIdentifier;
try {
moduleIdentifier = ModuleIdentifier.fromString(name + ":" + version);
} catch (IllegalArgumentException x) {
CeylonRuntimeException cre = new CeylonRuntimeException("Invalid module name or version: contains invalid characters");
cre.initCause(x);
throw cre;
}
try {
ModuleLoader moduleLoader = createModuleLoader(conf);
Module module = moduleLoader.loadModule(moduleIdentifier);
return new ClassLoaderHolderImpl(module);
} catch (ModuleNotFoundException e) {
String spec = e.getMessage();
int p = spec.lastIndexOf(':');
if (p >= 0) {
spec = spec.substring(0, p) + "/" + spec.substring(p + 1);
}
// ModuleIdentifier escapes :
spec = spec.replace("\\:", ":");
String msg = "Could not find module: " + spec + " (invalid version?";
if (name.equals("ceylon.language")) {
msg += " try running with '--link-with-current-distribution'";
}
msg += ")";
final CeylonRuntimeException cre = new CeylonRuntimeException(msg);
cre.initCause(e);
// e.printStackTrace();
throw cre;
}
}
Aggregations