Search in sources :

Example 6 with ModuleImport

use of com.redhat.ceylon.model.typechecker.model.ModuleImport in project ceylon-compiler by ceylon.

the class MavenPomUtil method writePomXml.

private static void writePomXml(JarOutputStream jarOutputStream, String path, String groupId, String artifactId, Module module) {
    try {
        jarOutputStream.putNextEntry(new ZipEntry(path + "pom.xml"));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    try {
        XMLStreamWriter out = XMLOutputFactory.newInstance().createXMLStreamWriter(new OutputStreamWriter(jarOutputStream, "utf-8"));
        out.writeStartDocument();
        out.writeCharacters("\n");
        // FIXME: what to do with the default module?
        out.writeStartElement("project");
        out.writeAttribute("xmlns", "http://maven.apache.org/POM/4.0.0");
        out.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
        out.writeAttribute("xsi:schemaLocation", "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd");
        out.writeCharacters("\n ");
        out.writeStartElement("modelVersion");
        out.writeCharacters("4.0.0");
        out.writeEndElement();
        out.writeCharacters("\n ");
        out.writeStartElement("groupId");
        out.writeCharacters(groupId);
        out.writeEndElement();
        out.writeCharacters("\n ");
        out.writeStartElement("artifactId");
        out.writeCharacters(artifactId);
        out.writeEndElement();
        out.writeCharacters("\n ");
        out.writeStartElement("version");
        out.writeCharacters(module.getVersion());
        out.writeEndElement();
        out.writeCharacters("\n ");
        out.writeStartElement("name");
        out.writeCharacters(module.getNameAsString());
        out.writeEndElement();
        List<ModuleImport> imports = module.getImports();
        if (!imports.isEmpty()) {
            out.writeCharacters("\n ");
            out.writeStartElement("dependencies");
            for (ModuleImport dep : imports) {
                if (!ModelUtil.isForBackend(dep.getNativeBackends(), Backend.Java)) {
                    continue;
                }
                Module moduleDependency = dep.getModule();
                String dependencyName = moduleDependency.getNameAsString();
                // skip c.l and jdk
                if (dependencyName.equals(Module.LANGUAGE_MODULE_NAME) || JDKUtils.isJDKModule(dependencyName) || JDKUtils.isOracleJDKModule(dependencyName))
                    continue;
                String[] mavenCoordinates = getMavenCoordinates(moduleDependency.getNameAsString());
                out.writeCharacters("\n  ");
                out.writeStartElement("dependency");
                out.writeCharacters("\n    ");
                out.writeStartElement("groupId");
                out.writeCharacters(mavenCoordinates[0]);
                out.writeEndElement();
                out.writeCharacters("\n    ");
                out.writeStartElement("artifactId");
                out.writeCharacters(mavenCoordinates[1]);
                out.writeEndElement();
                out.writeCharacters("\n    ");
                out.writeStartElement("version");
                out.writeCharacters(moduleDependency.getVersion());
                out.writeEndElement();
                if (dep.isOptional()) {
                    out.writeCharacters("\n    ");
                    out.writeStartElement("optional");
                    out.writeCharacters("true");
                    out.writeEndElement();
                }
                out.writeCharacters("\n  ");
                out.writeEndElement();
            }
            out.writeCharacters("\n ");
            out.writeEndElement();
        }
        out.writeCharacters("\n");
        out.writeEndElement();
        out.writeEndDocument();
        out.flush();
    } catch (IOException | XMLStreamException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            jarOutputStream.closeEntry();
        } catch (IOException ignore) {
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ZipEntry(java.util.zip.ZipEntry) ModuleImport(com.redhat.ceylon.model.typechecker.model.ModuleImport) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) Module(com.redhat.ceylon.model.typechecker.model.Module)

Aggregations

ModuleImport (com.redhat.ceylon.model.typechecker.model.ModuleImport)6 Module (com.redhat.ceylon.model.typechecker.model.Module)5 ArrayList (java.util.ArrayList)3 ArtifactContext (com.redhat.ceylon.cmr.api.ArtifactContext)1 ModuleDependencyInfo (com.redhat.ceylon.cmr.api.ModuleDependencyInfo)1 ModuleInfo (com.redhat.ceylon.cmr.api.ModuleInfo)1 Overrides (com.redhat.ceylon.cmr.api.Overrides)1 Backends (com.redhat.ceylon.common.Backends)1 ErrorCollector (com.redhat.ceylon.compiler.java.test.ErrorCollector)1 CeyloncTaskImpl (com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl)1 ArtifactResult (com.redhat.ceylon.model.cmr.ArtifactResult)1 LazyModule (com.redhat.ceylon.model.loader.model.LazyModule)1 LazyModuleManager (com.redhat.ceylon.model.loader.model.LazyModuleManager)1 Annotation (com.redhat.ceylon.model.typechecker.model.Annotation)1 Class (com.redhat.ceylon.model.typechecker.model.Class)1 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)1 Constructor (com.redhat.ceylon.model.typechecker.model.Constructor)1 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)1 Interface (com.redhat.ceylon.model.typechecker.model.Interface)1 NothingType (com.redhat.ceylon.model.typechecker.model.NothingType)1