Search in sources :

Example 1 with ToolUsageError

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);
}
Also used : ToolUsageError(com.redhat.ceylon.common.tool.ToolUsageError) File(java.io.File)

Example 2 with ToolUsageError

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();
}
Also used : ToolUsageError(com.redhat.ceylon.common.tool.ToolUsageError) Properties(java.util.Properties) File(java.io.File)

Example 3 with ToolUsageError

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"));
}
Also used : ArrayList(java.util.ArrayList) ToolUsageError(com.redhat.ceylon.common.tool.ToolUsageError) Map(java.util.Map) File(java.io.File) ArtifactResult(com.redhat.ceylon.model.cmr.ArtifactResult)

Example 4 with ToolUsageError

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());
    }
}
Also used : CeylonImportJarTool(com.redhat.ceylon.tools.importjar.CeylonImportJarTool) ToolUsageError(com.redhat.ceylon.common.tool.ToolUsageError) Test(org.junit.Test)

Example 5 with ToolUsageError

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());
    }
}
Also used : CeylonCompileTool(com.redhat.ceylon.compiler.CeylonCompileTool) ToolUsageError(com.redhat.ceylon.common.tool.ToolUsageError) Test(org.junit.Test)

Aggregations

ToolUsageError (com.redhat.ceylon.common.tool.ToolUsageError)12 Test (org.junit.Test)6 File (java.io.File)4 CeylonCompileTool (com.redhat.ceylon.compiler.CeylonCompileTool)2 CeylonClasspathTool (com.redhat.ceylon.tools.classpath.CeylonClasspathTool)2 CeylonImportJarTool (com.redhat.ceylon.tools.importjar.CeylonImportJarTool)2 Map (java.util.Map)2 LegacyImporter (com.redhat.ceylon.cmr.ceylon.LegacyImporter)1 DefaultToolOptions (com.redhat.ceylon.common.config.DefaultToolOptions)1 Main (com.redhat.ceylon.compiler.java.launcher.Main)1 ArtifactResult (com.redhat.ceylon.model.cmr.ArtifactResult)1 RepositoryException (com.redhat.ceylon.model.cmr.RepositoryException)1 JavacOption (com.sun.tools.javac.main.JavacOption)1 RecognizedOptions (com.sun.tools.javac.main.RecognizedOptions)1 Context (com.sun.tools.javac.util.Context)1 Options (com.sun.tools.javac.util.Options)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1