use of org.eclipse.ceylon.common.ModuleSpec 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.ModuleSpec in project ceylon by eclipse.
the class CeylonMavenExportTool method run.
@Override
public void run() throws Exception {
String firstModuleName = null;
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;
if (firstModuleName == null) {
firstModuleName = moduleName;
}
System.err.println("Doing " + module);
loadModule(null, moduleName, version);
}
// FIXME: we probably want to allow exporting of multiple versions
loader.resolve();
final File outputFolder = applyCwd(out != null ? out : new File("maven-repository"));
if (!outputFolder.exists()) {
FileUtil.mkdirs(outputFolder);
} else {
// FIXME: error if regular file?
// FIXME: or add, don't delete?
FileUtil.delete(outputFolder);
}
final List<ArtifactResult> writtenModules = new LinkedList<>();
final List<ArtifactResult> externalDependencies = new LinkedList<>();
final Set<String> directImports = new HashSet<>();
loader.visitModules(new ModuleGraph.Visitor() {
@Override
public void visit(ModuleGraph.Module module) {
if (module.artifact == null || module.artifact.artifact() == null)
return;
// FIXME: skip Maven modules?
if (forImport || forSdkImport) {
if (forImport && !module.artifact.groupId().equals("org.ceylon-lang")) {
externalDependencies.add(module.artifact);
return;
}
if (forSdkImport && !directlyListed(module.artifact.name())) {
if (!module.artifact.groupId().equals("org.ceylon-lang")) {
externalDependencies.add(module.artifact);
}
return;
}
makeMavenImportFolder(module, outputFolder, directImports);
writtenModules.add(module.artifact);
} else
makeMavenModule(module, outputFolder, directImports);
}
});
if (forImport || forSdkImport) {
makeMavenImportSpecialFolders(writtenModules, externalDependencies, outputFolder, directImports);
}
flush();
}
use of org.eclipse.ceylon.common.ModuleSpec in project ceylon by eclipse.
the class CeylonBrowseTool method run.
@Override
public void run() throws Exception {
for (ModuleSpec module : modules) {
List<ModuleVersionDetails> versions = new ArrayList<ModuleVersionDetails>(getModuleVersions(getRepositoryManager(), module.getNamespace(), module.getName(), module.getVersion(), false, ModuleQuery.Type.ALL, null, null, null, null));
Collections.sort(versions);
if (versions.isEmpty()) {
String err = getModuleNotFoundErrorMessage(getRepositoryManager(), module.getName(), module.getVersion());
errorAppend(err);
errorNewline();
continue;
}
ModuleVersionDetails mvd = versions.get(versions.size() - 1);
browseDoc(mvd);
}
}
use of org.eclipse.ceylon.common.ModuleSpec in project ceylon by eclipse.
the class CeylonClasspathTool method run.
@Override
public void run() throws Exception {
// we do depend on having a Main
loadModule(null, "org.eclipse.ceylon.java.main", Versions.CEYLON_VERSION_NUMBER);
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)
continue;
loadModule(null, moduleName, version);
if (!force)
errorOnConflictingModule(moduleName, version);
}
loader.resolve();
loader.visitModules(new ModuleGraph.Visitor() {
boolean once = true;
@Override
public void visit(Module module) {
if (module.artifact != null) {
File file = module.artifact.artifact();
try {
if (file != null) {
if (once)
once = false;
else
append(File.pathSeparator);
append(file.getAbsolutePath());
}
} catch (IOException x) {
// lame
throw new RuntimeException(x);
}
}
}
});
flush();
}
use of org.eclipse.ceylon.common.ModuleSpec in project ceylon by eclipse.
the class CeylonFatJarTool method run.
@Override
public void run() throws Exception {
String firstModuleName = null, firstModuleVersion = null;
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;
if (firstModuleName == null) {
firstModuleName = moduleName;
firstModuleVersion = version;
}
loadModule(null, moduleName, version);
if (!force)
errorOnConflictingModule(moduleName, version);
}
loader.resolve();
String versionSuffix = firstModuleVersion != null && !firstModuleVersion.isEmpty() ? "-" + firstModuleVersion : "";
File outputJar = applyCwd(out != null ? out : new File(firstModuleName + versionSuffix + ".jar"));
if (outputJar.getParentFile() != null && !outputJar.getParentFile().exists()) {
FileUtil.mkdirs(outputJar.getParentFile());
}
if (outputJar.exists()) {
FileUtil.delete(outputJar);
}
final Set<String> added = new HashSet<>();
if (firstModuleName != null && run != null && !run.contains("::") && !run.contains(".")) {
run = firstModuleName + "::" + run;
}
Manifest manifest = new Manifest();
Attributes mainAttributes = manifest.getMainAttributes();
final String className = javaClassNameFromCeylon(firstModuleName, run);
mainAttributes.putValue("Main-Class", className);
mainAttributes.putValue("Manifest-Version", "1.0");
mainAttributes.putValue("Created-By", "Ceylon fat-jar for module " + firstModuleName + "/" + firstModuleVersion);
writeManifestEntries(mainAttributes);
added.add("META-INF/");
added.add("META-INF/MANIFEST.MF");
addResources();
try (JarOutputStream zipFile = new JarOutputStream(new FileOutputStream(outputJar), manifest)) {
writeResources(zipFile);
final List<ArtifactResult> staticMetamodelEntries = new ArrayList<>();
loader.visitModules(new ModuleGraph.Visitor() {
String runClassPath = className.replace('.', '/') + ".class";
@Override
public void visit(ModuleGraph.Module module) {
if (module.artifact != null) {
File file = module.artifact.artifact();
try {
if (file != null) {
if (isVerbose()) {
append(file.getAbsolutePath());
newline();
}
staticMetamodelEntries.add(module.artifact);
try (ZipFile src = new ZipFile(file)) {
Enumeration<? extends ZipEntry> entries = src.entries();
while (entries.hasMoreElements()) {
ZipEntry srcEntry = entries.nextElement();
if (srcEntry.getName().equals(runClassPath))
foundRun = true;
// skip manifests
if (skipEntry(srcEntry.getName()))
continue;
if (!added.add(srcEntry.getName())) {
// multiple folders is fine
if (!srcEntry.isDirectory()) {
append("Warning: skipping duplicate entry ").append(srcEntry.getName()).append(" from ").append(file).newline();
}
continue;
}
srcEntry.setCompressedSize(-1);
zipFile.putNextEntry(srcEntry);
if (!srcEntry.isDirectory())
IOUtils.copyStream(src.getInputStream(srcEntry), zipFile, true, false);
}
}
}
} catch (IOException x) {
// lame
throw new RuntimeException(x);
}
}
}
});
JvmBackendUtil.writeStaticMetamodel(zipFile, added, staticMetamodelEntries, jdkProvider, Collections.<String>emptySet());
zipFile.flush();
}
flush();
if (!foundRun) {
append("Warning: missing run class ").append(className).newline();
}
}
Aggregations