use of com.redhat.ceylon.common.tool.ToolUsageError in project ceylon-compiler by ceylon.
the class CeylonWarTool method addResources.
/**
* Copies resources from the {@link #resourceRoot} to the WAR.
* @return true if a web.xml was added
*/
protected boolean addResources(List<EntrySpec> entries) throws MalformedURLException {
final File root;
if (this.resourceRoot == null) {
File defaultRoot = applyCwd(new File("web-content"));
if (!defaultRoot.exists()) {
return false;
}
root = defaultRoot;
} else {
root = applyCwd(new File(this.resourceRoot));
}
if (!root.exists()) {
throw new ToolUsageError(CeylonWarMessages.msg("resourceRoot.missing", root.getAbsolutePath()));
}
if (!root.isDirectory()) {
throw new ToolUsageError(CeylonWarMessages.msg("resourceRoot.nondir", root.getAbsolutePath()));
}
debug("adding.resources", root.getAbsolutePath());
return addResources(root, "", entries);
}
use of com.redhat.ceylon.common.tool.ToolUsageError in project ceylon-compiler by ceylon.
the class CeylonWarTool method run.
@Override
public void run() throws Exception {
final String moduleName = ModuleUtil.moduleName(this.moduleNameOptVersion);
final String moduleVersion = moduleVersion(this.moduleNameOptVersion);
final Properties properties = new Properties();
if (!loadModule(moduleName, moduleVersion) || !loadModule(WAR_MODULE, Versions.CEYLON_VERSION_NUMBER)) {
throw new ToolUsageError(CeylonWarMessages.msg("abort.missing.modules"));
}
addLibEntries();
properties.setProperty("moduleName", moduleName);
properties.setProperty("moduleVersion", moduleVersion);
addSpec(new PropertiesEntrySpec(properties, "META-INF/module.properties"));
if (!addResources(entrySpecs)) {
debug("adding.entry", "default web.xml");
addSpec(new URLEntrySpec(CeylonWarTool.class.getClassLoader().getResource("com/redhat/ceylon/tools/war/resources/default-web.xml"), "WEB-INF/web.xml"));
}
if (this.name == null) {
this.name = String.format("%s-%s.war", moduleName, moduleVersion);
debug("default.name", this.name);
}
final File jarFile = applyCwd(this.out == null ? new File(this.name) : new File(this.out, this.name));
writeJarFile(jarFile);
append(CeylonWarMessages.msg("archive.created", moduleName, moduleVersion, jarFile.getAbsolutePath()));
newline();
}
use of com.redhat.ceylon.common.tool.ToolUsageError in project ceylon-compiler by ceylon.
the class CeylonWarTool method addLibEntries.
protected void addLibEntries() throws MalformedURLException {
final List<String> libs = new ArrayList<>();
for (Map.Entry<String, ArtifactResult> entry : this.loadedModules.entrySet()) {
ArtifactResult module = entry.getValue();
if (module == null) {
// it's an optional, missing module (likely java.*)
continue;
}
final File artifact = module.artifact();
final String moduleName = entry.getKey();
// use "-" for the version separator
// use ".jar" so they'll get loaded by the container classloader
final String name = ModuleUtil.moduleName(moduleName) + "-" + ModuleUtil.moduleVersion(moduleName) + ".jar";
if (name.contains("/") || name.contains("\\") || name.length() == 0) {
throw new ToolUsageError(CeylonWarMessages.msg("module.name.illegal", name));
}
addSpec(new URLEntrySpec(artifact.toURI().toURL(), "WEB-INF/lib/" + name));
libs.add(name);
}
// store the list of added libs so the WarInitializer knows what to copy out
// to a repo if one has to be created
final StringBuffer libList = new StringBuffer();
for (String lib : libs) {
libList.append(lib).append("\n");
}
addSpec(new StringEntrySpec(libList.toString(), "META-INF/libs.txt"));
}
use of com.redhat.ceylon.common.tool.ToolUsageError in project ceylon-compiler by ceylon.
the class ImportJarToolTests method testWithUnknownModule.
@Test
public void testWithUnknownModule() throws Exception {
FileUtil.delete(destFile("importtest"));
ToolModel<CeylonImportJarTool> model = pluginLoader.loadToolModel("import-jar");
Assert.assertNotNull(model);
try {
CeylonImportJarTool tool = pluginFactory.bindArguments(model, getMainTool(), options("--descriptor", "test/src/com/redhat/ceylon/tools/test/test-descriptor-unknown.properties", "importtest/1.0", "test/src/com/redhat/ceylon/tools/test/test.jar"));
tool.run();
Assert.fail();
} catch (ToolUsageError e) {
Assert.assertEquals("Problems were found, aborting.", e.getMessage());
}
}
use of com.redhat.ceylon.common.tool.ToolUsageError in project ceylon-compiler by ceylon.
the class CompilerToolTests method testBug1623.
@Test
public void testBug1623() throws Exception {
ToolModel<CeylonCompileTool> model = pluginLoader.loadToolModel("compile");
Assert.assertNotNull(model);
try {
CeylonCompileTool tool = pluginFactory.bindArguments(model, getMainTool(), options("--src=test/src/com/redhat/ceylon/tools/test/empty"));
Assert.fail("Tool should have thrown an exception");
} catch (ToolUsageError e) {
Assert.assertEquals("No modules or source files to compile", e.getMessage());
}
}
Aggregations