use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.
the class CeylonMavenExportTool method generatePomFromModule.
private void generatePomFromModule(File pomFile, ArtifactResult artifact, Set<String> directImports) {
try (OutputStream os = new FileOutputStream(pomFile)) {
XMLStreamWriter out = XMLOutputFactory.newInstance().createXMLStreamWriter(new OutputStreamWriter(os, "utf-8"));
// FIXME: what to do with the default module?
writePomHeader(out);
if (forImport || forSdkImport) {
writePomParent(out, artifact);
} else {
writeElement(out, "groupId", artifact.groupId());
}
writeElement(out, "artifactId", artifact.artifactId());
writeNewline(out);
writeElement(out, "name", artifact.name());
if (forImport || forSdkImport) {
writeElement(out, "packaging", "jar");
writeNewline(out);
writeOpen(out, "properties");
{
String root = forImport ? "${ceylon.home}/repo/" : "${ceylon.sdk}/";
writeElement(out, "jarFile", root + artifact.name().replace('.', '/') + "/${ceylon.version}/" + artifact.name() + "-${ceylon.version}." + (artifact.artifact().getName().endsWith(".jar") ? "jar" : "car"));
writeElement(out, "sourcesFile", root + artifact.name().replace('.', '/') + "/${ceylon.version}/" + artifact.name() + "-${ceylon.version}.src");
}
writeClose(out);
} else {
writeElement(out, "version", artifact.version());
}
List<ArtifactResult> imports = artifact.dependencies();
writePomDependencies(out, imports, directImports);
if (forImport || forSdkImport) {
writeNewline(out);
writeOpen(out, "build");
{
writeOpen(out, "plugins");
{
writeOpen(out, "plugin");
{
writeElement(out, "groupId", "com.coderplus.maven.plugins");
writeElement(out, "artifactId", "copy-rename-maven-plugin");
}
writeClose(out);
writeOpen(out, "plugin");
{
writeElement(out, "groupId", "org.codehaus.mojo");
writeElement(out, "artifactId", "build-helper-maven-plugin");
}
writeClose(out);
}
writeClose(out);
}
writeClose(out);
}
writePomFooter(out);
} catch (IOException | XMLStreamException e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.
the class CeylonMavenExportTool method generatePomForComplete.
private void generatePomForComplete(File pomFile, List<ArtifactResult> writtenModules, List<ArtifactResult> externalDependencies) {
try (OutputStream os = new FileOutputStream(pomFile)) {
XMLStreamWriter out = XMLOutputFactory.newInstance().createXMLStreamWriter(new OutputStreamWriter(os, "utf-8"));
// FIXME: what to do with the default module?
writePomHeader(out);
writePomParent(out, writtenModules.get(0));
writeElement(out, "artifactId", "ceylon-complete");
writeNewline(out);
writeElement(out, "name", "ceylon-complete");
writeNewline(out);
writeOpen(out, "dependencies");
{
writeOpen(out, "dependency");
{
writeElement(out, "groupId", "org.ceylon-lang");
writeElement(out, "artifactId", "ceylon-all");
}
writeClose(out);
}
writeClose(out);
writeNewline(out);
writeOpen(out, "build");
{
writeOpen(out, "plugins");
{
writeOpen(out, "plugin");
{
writeElement(out, "artifactId", "maven-shade-plugin");
writeElement(out, "version", "2.4.2");
writeOpen(out, "executions");
{
writeOpen(out, "execution");
{
writeOpen(out, "goals");
{
writeElement(out, "goal", "shade");
}
writeClose(out);
writeOpen(out, "configuration");
{
writeElement(out, "createDependencyReducedPom", "true");
writeElement(out, "createSourcesJar", "true");
writeOpen(out, "artifactSet");
{
writeOpen(out, "includes");
{
writeElement(out, "include", "org.ceylon-lang:*");
List<ArtifactResult> sortedImports = new ArrayList<>(externalDependencies);
Collections.sort(sortedImports, ImportComparator);
for (ArtifactResult dep : sortedImports) {
String dependencyName = dep.name();
// skip jdk
if (jdkProvider.isJDKModule(dependencyName))
continue;
writeElement(out, "include", dep.groupId() + ":" + dep.artifactId());
}
}
writeClose(out);
}
writeClose(out);
}
writeClose(out);
}
writeClose(out);
}
writeClose(out);
}
writeClose(out);
}
writeClose(out);
}
writeClose(out);
writePomFooter(out);
} catch (IOException | XMLStreamException e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.
the class CeylonMavenExportTool method generatePomParts.
private void generatePomParts(File pomFile, List<ArtifactResult> writtenModules, List<ArtifactResult> externalDependencies, Set<String> directImports) {
try (OutputStream os = new FileOutputStream(pomFile)) {
XMLStreamWriter out = XMLOutputFactory.newInstance().createXMLStreamWriter(new OutputStreamWriter(os, "utf-8"));
// FIXME: what to do with the default module?
writePomHeader(out);
writePomParent(out, writtenModules.get(0));
writeElement(out, "artifactId", "ceylon-parts");
writeNewline(out);
writeElement(out, "name", "ceylon-parts");
writeNewline(out);
writeOpen(out, "properties");
{
SortedMap<String, String> props = new TreeMap<>();
for (ArtifactResult dep : externalDependencies) {
String name = getDependencyPropertyName(dep.name());
if (directImports.contains(name))
props.put(name, dep.version());
}
for (Entry<String, String> entry : props.entrySet()) {
writeElement(out, entry.getKey(), entry.getValue());
}
}
writeClose(out);
writeNewline(out);
writeOpen(out, "modules");
{
List<ArtifactResult> sortedImports = new ArrayList<>(writtenModules);
Collections.sort(sortedImports, ImportComparator);
for (ArtifactResult dep : sortedImports) {
String dependencyName = dep.name();
writeElement(out, "module", dependencyName);
}
if (forImport) {
writeElement(out, "module", "ceylon-all");
writeElement(out, "module", "ceylon-complete");
writeElement(out, "module", "ceylon-system");
} else {
writeElement(out, "module", "ceylon-sdk");
}
}
writeClose(out);
writeNewline(out);
writeOpen(out, "dependencyManagement");
{
writePomDependencies(out, writtenModules, directImports, true);
}
writeClose(out);
writeNewline(out);
writePomFooter(out);
} catch (IOException | XMLStreamException e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.ceylon.model.cmr.ArtifactResult 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