Search in sources :

Example 16 with ToolUsageError

use of org.eclipse.ceylon.common.tool.ToolUsageError in project ceylon by eclipse.

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(), toolOptions("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(org.eclipse.ceylon.common.tool.ToolUsageError) CeylonClasspathTool(org.eclipse.ceylon.tools.classpath.CeylonClasspathTool) Test(org.junit.Test)

Example 17 with ToolUsageError

use of org.eclipse.ceylon.common.tool.ToolUsageError in project ceylon by eclipse.

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(), toolOptions("--src=test/src/org/eclipse/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(org.eclipse.ceylon.compiler.CeylonCompileTool) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) Test(org.junit.Test)

Example 18 with ToolUsageError

use of org.eclipse.ceylon.common.tool.ToolUsageError in project ceylon by eclipse.

the class CeylonJigsawTool method run.

@Override
public void run() throws Exception {
    for (ModuleSpec module : modules) {
        String moduleName = module.getName();
        String version = checkModuleVersionsOrShowSuggestions(moduleName, module.isVersioned() ? module.getVersion() : null, ModuleQuery.Type.JVM, Versions.JVM_BINARY_MAJOR_VERSION, Versions.JVM_BINARY_MINOR_VERSION, // JS binary but don't care since JVM
        null, // JS binary but don't care since JVM
        null, null);
        if (version == null)
            return;
        loadModule(null, moduleName, version);
        if (!force)
            errorOnConflictingModule(moduleName, version);
    }
    // force loading the module which contains the main
    loadModule(null, "org.eclipse.ceylon.java.main", Versions.CEYLON_VERSION_NUMBER);
    loader.resolve();
    if (!out.exists()) {
        if (!out.mkdirs()) {
            throw new ToolUsageError(Messages.msg(bundle, "jigsaw.folder.error", out));
        }
    }
    final List<ArtifactResult> staticMetamodelEntries = new ArrayList<>();
    loader.visitModules(new ModuleGraph.Visitor() {

        @Override
        public void visit(Module module) {
            if (module.artifact != null) {
                File file = module.artifact.artifact();
                try {
                    if (file != null) {
                        append(file.getAbsolutePath());
                        newline();
                        staticMetamodelEntries.add(module.artifact);
                        String name = file.getName();
                        if (name.endsWith(".car"))
                            name = name.substring(0, name.length() - 4) + ".jar";
                        Files.copy(file.toPath(), new File(out, name).toPath(), StandardCopyOption.REPLACE_EXISTING);
                    }
                } catch (IOException x) {
                    // lame
                    throw new RuntimeException(x);
                }
            }
        }
    });
    if (staticMetamodel) {
        JvmBackendUtil.writeStaticMetamodel(out, staticMetamodelEntries, jdkProvider);
    }
    flush();
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) ModuleGraph(org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph) Module(org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph.Module) File(java.io.File)

Example 19 with ToolUsageError

use of org.eclipse.ceylon.common.tool.ToolUsageError in project ceylon by eclipse.

the class CeylonImportJarTool method run.

@Override
public void run() throws Exception {
    LegacyImporter importer = createImporter().moduleDescriptor(applyCwd(descriptor)).missingDependenciesPackages(parsedMissingDependenciesPackages);
    importer.setIgnoreAnnotations(ignoreAnnotations);
    if (!force || updateDescriptor) {
        try {
            importer.loadModuleDescriptor();
        } catch (ImportJarException x) {
            throw x;
        } catch (Exception x) {
            String key = "error.descriptorFile.invalid.";
            if (descriptor.getName().endsWith(".xml")) {
                key += "xml";
            } else {
                key += "properties";
            }
            throw new ImportJarException(key, new Object[] { descriptor.getPath(), x.getMessage() }, x);
        }
        if (!showClasses) {
            importer.listPackages(showSuggestions);
        } else {
            importer.listClasses();
        }
    }
    boolean hasErrors = importer.hasErrors();
    if (importer.hasProblems()) {
        if (updateDescriptor && descriptor != null) {
            if (!dryRun) {
                importer.updateModuleDescriptor();
            }
        } else {
            hasErrors = true;
        }
    }
    if (!hasErrors || force) {
        if (!hasErrors) {
            if (force && !updateDescriptor) {
                msg("info.forcedUpdate");
            } else {
                msg("info.noProblems");
            }
        } else {
            msg("error.problemsFoundForced");
        }
        if (!dryRun) {
            msg("info.noProblems.publishing").newline();
            try {
                importer.publish();
            } catch (RepositoryException x) {
                throw new ImportJarException("error.failedWriteArtifact", new Object[] { module, x.getLocalizedMessage() }, x);
            } catch (Exception x) {
                // FIXME: remove when the whole CMR is using RepositoryException
                throw new ImportJarException("error.failedWriteArtifact", new Object[] { module, x.getLocalizedMessage() }, x);
            }
            String repoString = this.getOutputRepositoryManager().getRepositoriesDisplayString().toString();
            msg("info.published", this.module.toString(), repoString.substring(1, repoString.length() - 1));
        }
        append(".").newline();
    } else {
        String msgKey;
        if (!updateDescriptor && descriptor == null) {
            msgKey = "error.problemsFoundSuggest";
        } else {
            msgKey = "error.problemsFound";
        }
        throw new ToolUsageError(Messages.msg(ImportJarMessages.RESOURCE_BUNDLE, msgKey));
    }
}
Also used : ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) LegacyImporter(org.eclipse.ceylon.cmr.ceylon.LegacyImporter) IOException(java.io.IOException) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException)

Example 20 with ToolUsageError

use of org.eclipse.ceylon.common.tool.ToolUsageError in project ceylon by eclipse.

the class ModuleLoadingTool method errorOnConflictingModule.

protected void errorOnConflictingModule(String module, String version) throws IOException {
    boolean duplicate = false;
    for (Map.Entry<String, SortedSet<String>> entry : loader.getDuplicateModules().entrySet()) {
        duplicate = true;
        printDuplicateModuleErrorMessage(entry.getKey(), entry.getValue());
    }
    if (duplicate)
        throw new ToolUsageError(Messages.msg(bundle, "module.conflict.error", module, version));
}
Also used : ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) Map(java.util.Map) SortedSet(java.util.SortedSet)

Aggregations

ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)20 File (java.io.File)9 IOException (java.io.IOException)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)5 ModuleSpec (org.eclipse.ceylon.common.ModuleSpec)4 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)3 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)3 CeylonImportJarTool (org.eclipse.ceylon.tools.importjar.CeylonImportJarTool)3 List (java.util.List)2 ModuleGraph (org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph)2 Module (org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph.Module)2 NonFatalToolMessage (org.eclipse.ceylon.common.tool.NonFatalToolMessage)2 SourceArgumentsResolver (org.eclipse.ceylon.common.tools.SourceArgumentsResolver)2 SourceDependencyResolver (org.eclipse.ceylon.common.tools.SourceDependencyResolver)2 CeylonClasspathTool (org.eclipse.ceylon.tools.classpath.CeylonClasspathTool)2 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)1