Search in sources :

Example 76 with ArtifactResult

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);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 77 with ArtifactResult

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);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 78 with ArtifactResult

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);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) ZipEntry(java.util.zip.ZipEntry) Entry(java.util.Map.Entry) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) FileOutputStream(java.io.FileOutputStream) SortedMap(java.util.SortedMap) OutputStreamWriter(java.io.OutputStreamWriter) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 79 with ArtifactResult

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();
    }
}
Also used : Enumeration(java.util.Enumeration) ZipEntry(java.util.zip.ZipEntry) Attributes(java.util.jar.Attributes) ArrayList(java.util.ArrayList) JarOutputStream(java.util.jar.JarOutputStream) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ZipFile(java.util.zip.ZipFile) FileOutputStream(java.io.FileOutputStream) ModuleGraph(org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph) ZipFile(java.util.zip.ZipFile) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)79 File (java.io.File)40 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)32 SimpleRepositoryManager (org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager)28 Test (org.junit.Test)28 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)25 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)15 ModuleSpec (org.eclipse.ceylon.common.ModuleSpec)13 FileOutputStream (java.io.FileOutputStream)6 InputStream (java.io.InputStream)5 ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)5 Module (org.eclipse.ceylon.model.typechecker.model.Module)5 LinkedList (java.util.LinkedList)4 List (java.util.List)4 ZipEntry (java.util.zip.ZipEntry)4 FileInputStream (java.io.FileInputStream)3 OutputStream (java.io.OutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3