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"));
}
}
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());
}
}
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();
}
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));
}
}
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));
}
Aggregations