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) {
}
}
}
Aggregations