diff --git a/.gitignore b/.gitignore index 5769b6f..871d7dd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.ipr api/target/ dist/target/ +dist/lib/ dist/bin/jboss-modules.jar dist/bin/ceylon-runtime-bootstrap.jar dist/runtime-repo/ceylon/language/0.1/ceylon.language-0.1.car diff --git a/api/src/main/java/ceylon/modules/api/runtime/AbstractRuntime.java b/api/src/main/java/ceylon/modules/api/runtime/AbstractRuntime.java index dfa7a99..10ef916 100644 --- a/api/src/main/java/ceylon/modules/api/runtime/AbstractRuntime.java +++ b/api/src/main/java/ceylon/modules/api/runtime/AbstractRuntime.java @@ -22,15 +22,14 @@ package ceylon.modules.api.runtime; -import java.util.logging.Logger; - import ceylon.language.descriptor.Module; import ceylon.modules.Configuration; import ceylon.modules.api.util.CeylonToJava; import ceylon.modules.spi.Constants; - import com.redhat.ceylon.cmr.api.Repository; +import java.util.logging.Logger; + /** * Abstract Ceylon Modules runtime. * Useful for potential extension. @@ -91,18 +90,20 @@ public void execute(Configuration conf) throws Exception { ClassLoader cl = createClassLoader(name, mv, conf); Module runtimeModule = loadModule(cl, name); - if (runtimeModule == null) - throw new IllegalArgumentException("Something went very wrong, missing runtime module!"); // TODO -- dump some more useful msg - - String mn = CeylonToJava.toString(runtimeModule.getName()); - if (name.equals(mn) == false) - throw new IllegalArgumentException("Input module name doesn't match module's name: " + name + " != " + mn); - String version = CeylonToJava.toString(runtimeModule.getVersion()); - if (mv.equals(version) == false && Constants.DEFAULT.toString().equals(name) == false) - throw new IllegalArgumentException("Input module version doesn't match module's version: " + mv + " != " + version); + if (runtimeModule != null) { + final String mn = CeylonToJava.toString(runtimeModule.getName()); + if (name.equals(mn) == false) + throw new IllegalArgumentException("Input module name doesn't match module's name: " + name + " != " + mn); + + final String version = CeylonToJava.toString(runtimeModule.getVersion()); + if (mv.equals(version) == false && Constants.DEFAULT.toString().equals(name) == false) + throw new IllegalArgumentException("Input module version doesn't match module's version: " + mv + " != " + version); + } else if (Constants.DEFAULT.toString().equals(name) == false) { + throw new IllegalArgumentException("Missing module.class info: " + name); // TODO -- dump some more useful msg + } String runClassName = conf.run; - if(runClassName == null || runClassName.isEmpty()) + if (runClassName == null || runClassName.isEmpty()) runClassName = name + RUN_INFO_CLASS; invokeRun(cl, runClassName, conf.arguments); } diff --git a/impl/src/main/java/ceylon/modules/jboss/runtime/AbstractJBossRuntime.java b/impl/src/main/java/ceylon/modules/jboss/runtime/AbstractJBossRuntime.java index 76ecd9d..2ed28b5 100644 --- a/impl/src/main/java/ceylon/modules/jboss/runtime/AbstractJBossRuntime.java +++ b/impl/src/main/java/ceylon/modules/jboss/runtime/AbstractJBossRuntime.java @@ -55,7 +55,7 @@ public ClassLoader createClassLoader(String name, String version, Configuration /** * Get repository extension. * - * @param args the args + * @param conf the configuration * @return repository extension */ protected Repository createRepository(Configuration conf) { @@ -90,7 +90,7 @@ protected Repository createRepository(Configuration conf) { * Get repository service. * * @param serviceType the service type - * @param args the args + * @param conf the configuration * @return service instance or null */ protected T getService(Class serviceType, Configuration conf) { diff --git a/spi/src/main/java/ceylon/modules/Configuration.java b/spi/src/main/java/ceylon/modules/Configuration.java index 2f61d21..408b1bb 100644 --- a/spi/src/main/java/ceylon/modules/Configuration.java +++ b/spi/src/main/java/ceylon/modules/Configuration.java @@ -1,17 +1,17 @@ package ceylon.modules; +import ceylon.modules.spi.Argument; +import ceylon.modules.spi.ArgumentType; +import ceylon.modules.spi.Constants; + import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import ceylon.modules.spi.Argument; -import ceylon.modules.spi.ArgumentType; -import ceylon.modules.spi.Constants; - /** * Holds the configuration from the command-line arguments - * + * * @author Stephane Epardaud */ public class Configuration { @@ -44,68 +44,87 @@ public class Configuration { // Non-Ceylon public String executable; public boolean cacheContent; - /** names of implementation classes by interface name */ - public Map impl = new HashMap(); + /** + * names of implementation classes by interface name + */ + public Map impl = new HashMap(); /** * Sets an argument and checks its required number of parameters - * @param name argument name without the prefix -/+ - * @param type type of option + * + * @param name argument name without the prefix -/+ + * @param type type of option * @param values list of arguments - * @param i index of the argument name + * @param i index of the argument name * @return the index of the last argument required eaten by this argument */ public int setArgument(String name, ArgumentType type, String[] values, int i) { Argument argument = Argument.forArgumentName(name, type); - if(argument == null) - throw new IllegalArgumentException("Unknown argument: "+name); + if (argument == null) + throw new IllegalArgumentException("Unknown argument: " + name); if (i + argument.getRequiredValues() >= values.length) throw new IllegalArgumentException("Missing argument value: " + name); - int arg = i+1; - switch(argument){ - case EXECUTABLE: executable = values[arg]; break; - case CACHE_CONTENT: cacheContent = true; break; - case IMPLEMENTATION: impl.put(values[arg], values[arg+1]); break; - case SOURCE: src = values[arg]; break; - case RUN: run = values[arg]; break; - case REPOSITORY: repositories.add(values[arg]); break; - case HELP: printUsage(); break; - case VERSION: printVersion(); break; + int arg = i + 1; + switch (argument) { + case EXECUTABLE: + executable = values[arg]; + break; + case CACHE_CONTENT: + cacheContent = true; + break; + case IMPLEMENTATION: + impl.put(values[arg], values[arg + 1]); + break; + case SOURCE: + src = values[arg]; + break; + case RUN: + run = values[arg]; + break; + case REPOSITORY: + repositories.add(values[arg]); + break; + case HELP: + printUsage(); + break; + case VERSION: + printVersion(); + break; } - return i+argument.getRequiredValues(); + return i + argument.getRequiredValues(); } private void printVersion() { - System.out.println("Version: ceylon "+Constants.CEYLON_VERSION); + System.out.println("Version: ceylon " + Constants.CEYLON_VERSION); System.exit(0); } public void printUsage() { System.err.print("Usage: ceylon [options...] moduleName/version\n" - +"\n" - +" -run qualified-name: Name of a class or toplevel method to run\n" - +" (default: use the module descriptor)\n" - +" -rep path: Module repository path (can be specified more than once)\n" - +" (default: ...)\n" - +" -src path: Source path (default: source)\n" - +" -help: Prints help usage\n" - +" -version: Prints version number\n" - +" moduleName/version: Module name and version to run (required)\n" - ); + + "\n" + + " -run qualified-name: Name of a class or toplevel method to run\n" + + " (default: use the module descriptor)\n" + + " -rep path: Module repository path (can be specified more than once)\n" + + " (default: ...)\n" + + " -src path: Source path (default: source)\n" + + " -help: Prints help usage\n" + + " -version: Prints version number\n" + + " moduleName/version: Module name and version to run (required)\n" + ); System.exit(1); } public void check() { - if(executable == null - || executable.isEmpty()){ + if (executable == null + || executable.isEmpty()) { System.err.println("Missing +executable parameter\n"); printUsage(); } - if(module == null - || module.isEmpty()){ + if (module == null + || module.isEmpty()) { System.err.println("Missing module name\n"); printUsage(); } diff --git a/testsuite/src/test/java/org/jboss/ceylon/test/modules/ModulesTest.java b/testsuite/src/test/java/org/jboss/ceylon/test/modules/ModulesTest.java index 656295b..a150e6d 100644 --- a/testsuite/src/test/java/org/jboss/ceylon/test/modules/ModulesTest.java +++ b/testsuite/src/test/java/org/jboss/ceylon/test/modules/ModulesTest.java @@ -83,6 +83,10 @@ protected File createModuleFile(File tmpdir, Archive module) throws Exception { } protected void testArchive(Archive module, Archive... libs) throws Throwable { + testArchive(module, null, libs); + } + + protected void testArchive(Archive module, String run, Archive... libs) throws Throwable { File tmpdir = AccessController.doPrivileged(new PrivilegedAction() { public File run() { return new File(System.getProperty("ceylon.repo", System.getProperty("java.io.tmpdir"))); @@ -95,17 +99,28 @@ public File run() { for (Archive lib : libs) files.add(createModuleFile(tmpdir, lib)); - String fullName = module.getName(); - int p = fullName.indexOf("-"); - if (p < 0) - throw new IllegalArgumentException("No name and version split: " + fullName); + String name; + String version; - String name = fullName.substring(0, p); - String version = fullName.substring(p + 1, fullName.lastIndexOf(".")); + String fullName = module.getName(); + final boolean isDefault = (Constants.DEFAULT + ".car").equals(fullName); + if (isDefault) { + name = Constants.DEFAULT.toString(); + version = Repository.NO_VERSION; + } else { + int p = fullName.indexOf("-"); + if (p < 0) + throw new IllegalArgumentException("No name and version split: " + fullName); + + name = fullName.substring(0, p); + version = fullName.substring(p + 1, fullName.lastIndexOf(".")); + } Map args = new LinkedHashMap(); - args.put(Constants.IMPL_ARGUMENT_PREFIX+Argument.EXECUTABLE.toString(), RUNTIME_IMPL); - args.put(Constants.CEYLON_ARGUMENT_PREFIX+Argument.REPOSITORY.toString(), tmpdir.toString()); + args.put(Constants.IMPL_ARGUMENT_PREFIX + Argument.EXECUTABLE.toString(), RUNTIME_IMPL); + args.put(Constants.CEYLON_ARGUMENT_PREFIX + Argument.REPOSITORY.toString(), tmpdir.toString()); + if (run != null) + args.put(Constants.CEYLON_ARGUMENT_PREFIX + Argument.RUN.toString(), run); execute(name + "/" + version, args); } finally { @@ -129,8 +144,8 @@ protected void src(String module, String src) throws Throwable { protected void car(String module, Map extra) throws Throwable { Map args = new LinkedHashMap(); - args.put(Constants.IMPL_ARGUMENT_PREFIX+Argument.EXECUTABLE.toString(), RUNTIME_IMPL); - args.put(Constants.CEYLON_ARGUMENT_PREFIX+Argument.REPOSITORY.toString(), getRepo().getPath()); + args.put(Constants.IMPL_ARGUMENT_PREFIX + Argument.EXECUTABLE.toString(), RUNTIME_IMPL); + args.put(Constants.CEYLON_ARGUMENT_PREFIX + Argument.REPOSITORY.toString(), getRepo().getPath()); args.putAll(extra); execute(module, args); @@ -138,8 +153,8 @@ protected void car(String module, Map extra) throws Throwable { protected void src(String module, String src, Map extra) throws Throwable { Map args = new LinkedHashMap(); - args.put(Constants.IMPL_ARGUMENT_PREFIX+Argument.EXECUTABLE.toString(), RUNTIME_IMPL); - args.put(Constants.CEYLON_ARGUMENT_PREFIX+Argument.SOURCE.toString(), src); + args.put(Constants.IMPL_ARGUMENT_PREFIX + Argument.EXECUTABLE.toString(), RUNTIME_IMPL); + args.put(Constants.CEYLON_ARGUMENT_PREFIX + Argument.SOURCE.toString(), src); args.putAll(extra); execute(module, args); diff --git a/testsuite/src/test/java/org/jboss/ceylon/test/modules/defaultx/test/DefaultTestCase.java b/testsuite/src/test/java/org/jboss/ceylon/test/modules/defaultx/test/DefaultTestCase.java index 096521d..18d310c 100644 --- a/testsuite/src/test/java/org/jboss/ceylon/test/modules/defaultx/test/DefaultTestCase.java +++ b/testsuite/src/test/java/org/jboss/ceylon/test/modules/defaultx/test/DefaultTestCase.java @@ -53,4 +53,12 @@ public void testVisibility() throws Throwable { testArchive(module, lib); } + @Test + public void testDefaultRun() throws Throwable { + JavaArchive module = ShrinkWrap.create(JavaArchive.class, "default.car"); + module.addClasses(org.jboss.acme.run.class); + + testArchive(module, org.jboss.acme.run.class.getName()); + } + }