throw new RuntimeException("Artifacts not supplied");
}
if (targetDir == null) {
throw new RuntimeException("No target directory supplied");
}
ServiceDocument serviceDocument = ServiceDocument.Factory.newInstance();
ServiceType serviceType = serviceDocument.addNewService();
for (Iterator iterator = artifacts.iterator(); iterator.hasNext();) {
Artifact artifact = (Artifact) iterator.next();
Dependency dependency = artifact.getDependency();
if ("true".equals(dependency.getProperty(DEPENDENCY_PROPERTY))) {
String groupId = dependency.getGroupId();
String artifactId = dependency.getArtifactId();
String type = dependency.getType();
org.apache.geronimo.deployment.xbeans.ArtifactType dependencyType = serviceType.addNewDependency();
dependencyType.setGroupId(groupId);
dependencyType.setArtifactId(artifactId);
if ("true".equals(dependency.getProperty(KEEP_VERSION_PROPERTY))) {
String version = dependency.getVersion();
dependencyType.setVersion(version);
}
if (type != null && !"jar".equals(type)) {
dependencyType.setType(type);
}
}
}
if (serviceType.getDependencyArray().length > 0) {
File targetDir = new File(this.targetDir);
if (targetDir.exists()) {
if (!targetDir.isDirectory()) {
throw new RuntimeException("TargetDir: " + this.targetDir + " exists and is not a directory");
}
} else {
targetDir.mkdirs();
}
File output = new File(targetDir, "geronimo-dependency.xml");
XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setSavePrettyPrint();
serviceDocument.save(output, xmlOptions);
}
}