Search in sources :

Example 6 with ToolUsageError

use of com.redhat.ceylon.common.tool.ToolUsageError in project ceylon-compiler by ceylon.

the class ClasspathToolTests method testMissingModule.

@Test
public void testMissingModule() throws Exception {
    ToolModel<CeylonClasspathTool> model = pluginLoader.loadToolModel("classpath");
    Assert.assertNotNull(model);
    CeylonClasspathTool tool = pluginFactory.bindArguments(model, getMainTool(), Collections.<String>singletonList("naskduhqwedmansd"));
    try {
        tool.run();
        Assert.fail();
    } catch (ToolUsageError x) {
        Assert.assertTrue(x.getMessage().contains("Module naskduhqwedmansd not found"));
    }
}
Also used : ToolUsageError(com.redhat.ceylon.common.tool.ToolUsageError) CeylonClasspathTool(com.redhat.ceylon.tools.classpath.CeylonClasspathTool) Test(org.junit.Test)

Example 7 with ToolUsageError

use of com.redhat.ceylon.common.tool.ToolUsageError in project ceylon-compiler by ceylon.

the class CompilerToolTests method testDefaultModuleNoFiles.

@Test
public void testDefaultModuleNoFiles() 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", "default"));
        tool.run();
        Assert.fail("Tool should have thrown an exception");
    } catch (ToolUsageError e) {
        Assert.assertEquals("Module default does not contain any sources or resources", e.getMessage());
    }
}
Also used : CeylonCompileTool(com.redhat.ceylon.compiler.CeylonCompileTool) ToolUsageError(com.redhat.ceylon.common.tool.ToolUsageError) Test(org.junit.Test)

Example 8 with ToolUsageError

use of com.redhat.ceylon.common.tool.ToolUsageError in project ceylon-compiler by ceylon.

the class ImportJarToolTests method testBug1630.

@Test
public void testBug1630() throws Exception {
    FileUtil.delete(destFile("importtest"));
    ToolModel<CeylonImportJarTool> model = pluginLoader.loadToolModel("import-jar");
    Assert.assertNotNull(model);
    try {
        CeylonImportJarTool tool = pluginFactory.bindArguments(model, getMainTool(), options("--dry-run", "--descriptor", "test/src/com/redhat/ceylon/tools/test/test-descriptor.properties", "importtest/1.0", "test/src/com/redhat/ceylon/tools/test/test2.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 9 with ToolUsageError

use of com.redhat.ceylon.common.tool.ToolUsageError in project ceylon-compiler by ceylon.

the class CeylonCompileTool method initialize.

@Override
public void initialize(CeylonTool mainTool) throws IOException {
    compiler = new Main("ceylon compile");
    Options options = Options.instance(new Context());
    if (modulesOrFiles.isEmpty() && !javac.contains("-help") && !javac.contains("-X") && !javac.contains("-version")) {
        throw new IllegalStateException("Argument moduleOrFile should appear at least 1 time(s)");
    }
    arguments = new ArrayList<>();
    if (cwd != null) {
        arguments.add("-cwd");
        arguments.add(cwd.getPath());
    }
    for (File source : applyCwd(this.sources)) {
        arguments.add("-src");
        arguments.add(source.getPath());
        options.addMulti(OptionName.SOURCEPATH, source.getPath());
    }
    for (File resource : applyCwd(this.resources)) {
        arguments.add("-res");
        arguments.add(resource.getPath());
    //options.addMulti(OptionName.RESOURCEPATH, resource.getPath());
    }
    if (resourceRoot != null) {
        arguments.add("-resroot");
        arguments.add(resourceRoot);
    }
    if (continueOnErrors) {
        arguments.add("-continue");
    }
    if (progress) {
        arguments.add("-progress");
    }
    if (offline) {
        arguments.add("-offline");
    }
    if (timeout != -1) {
        arguments.add("-timeout");
        arguments.add(String.valueOf(timeout));
    }
    if (flatClasspath) {
        arguments.add("-flat-classpath");
    }
    if (autoExportMavenDependencies) {
        arguments.add("-auto-export-maven-dependencies");
    }
    if (overrides != null) {
        arguments.add("-overrides");
        if (overrides.startsWith("classpath:")) {
            arguments.add(overrides);
        } else {
            arguments.add(applyCwd(new File(overrides)).getPath());
        }
    }
    if (noOsgi) {
        arguments.add("-noosgi");
    }
    if (osgiProvidedBundles != null && !osgiProvidedBundles.isEmpty()) {
        arguments.add("-osgi-provided-bundles");
        arguments.add(osgiProvidedBundles);
    }
    if (noPom) {
        arguments.add("-nopom");
    }
    if (pack200) {
        arguments.add("-pack200");
    }
    if (verbose != null) {
        if (verbose.isEmpty()) {
            arguments.add("-verbose");
        } else {
            arguments.add("-verbose:" + verbose);
        }
    }
    if (out != null) {
        arguments.add("-out");
        arguments.add(out);
    }
    if (user != null) {
        arguments.add("-user");
        arguments.add(user);
    }
    if (pass != null) {
        arguments.add("-pass");
        arguments.add(pass);
    }
    String fileEncoding = encoding;
    if (fileEncoding == null) {
        fileEncoding = DefaultToolOptions.getDefaultEncoding();
    }
    if (fileEncoding != null) {
        JavacOption encodingOpt = getJavacOpt(OptionName.ENCODING.toString());
        validateWithJavac(options, encodingOpt, OptionName.ENCODING.toString(), fileEncoding, "option.error.syntax.encoding");
        arguments.add(OptionName.ENCODING.toString());
        arguments.add(fileEncoding);
    }
    if (systemRepo != null) {
        arguments.add("-sysrep");
        arguments.add(systemRepo);
    }
    if (cacheRepo != null) {
        arguments.add("-cacherep");
        arguments.add(cacheRepo);
    }
    if (noDefRepos) {
        arguments.add("-nodefreps");
    }
    if (repo != null) {
        for (URI uri : this.repo) {
            arguments.add("-rep");
            arguments.add(uri.toString());
        }
    }
    if (suppressWarnings != null) {
        arguments.add("-suppress-warnings");
        arguments.add(EnumUtil.enumsToString(suppressWarnings));
    }
    addJavacArguments(arguments);
    List<File> srcs = applyCwd(this.sources);
    List<String> expandedModulesOrFiles = ModuleWildcardsHelper.expandWildcards(srcs, this.modulesOrFiles, Backend.Java);
    if (expandedModulesOrFiles.isEmpty()) {
        throw new ToolUsageError("No modules or source files to compile");
    }
    JavacOption sourceFileOpt = getJavacOpt(OptionName.SOURCEFILE.toString());
    if (sourceFileOpt != null) {
        for (String moduleOrFile : expandedModulesOrFiles) {
            validateWithJavac(options, sourceFileOpt, moduleOrFile, moduleOrFile, "argument.error");
        }
    }
    validateSourceArguments(expandedModulesOrFiles);
    arguments.addAll(expandedModulesOrFiles);
    if (verbose != null) {
        System.out.println(arguments);
        System.out.flush();
    }
}
Also used : Context(com.sun.tools.javac.util.Context) DefaultToolOptions(com.redhat.ceylon.common.config.DefaultToolOptions) RecognizedOptions(com.sun.tools.javac.main.RecognizedOptions) Options(com.sun.tools.javac.util.Options) JavacOption(com.sun.tools.javac.main.JavacOption) ToolUsageError(com.redhat.ceylon.common.tool.ToolUsageError) Main(com.redhat.ceylon.compiler.java.launcher.Main) File(java.io.File) URI(java.net.URI)

Example 10 with ToolUsageError

use of com.redhat.ceylon.common.tool.ToolUsageError in project ceylon-compiler by ceylon.

the class ClasspathToolTests method testModuleNameWithBadVersion.

@Test
public void testModuleNameWithBadVersion() throws Exception {
    ToolModel<CeylonClasspathTool> model = pluginLoader.loadToolModel("classpath");
    Assert.assertNotNull(model);
    CeylonClasspathTool tool = pluginFactory.bindArguments(model, getMainTool(), Collections.<String>singletonList("ceylon.language/666"));
    try {
        tool.run();
    } catch (ToolUsageError x) {
        Assert.assertTrue(x.getMessage().contains("Version 666 not found for module ceylon.language"));
    }
}
Also used : ToolUsageError(com.redhat.ceylon.common.tool.ToolUsageError) CeylonClasspathTool(com.redhat.ceylon.tools.classpath.CeylonClasspathTool) 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