in src/main/java/org/apache/sling/feature/io/artifacts/ArtifactManager.java [475:524]
private void downloadArtifact(final ArtifactId artifactId) throws IOException {
// create fake pom
final Path dir = Files.createTempDirectory(null);
try {
final List<String> lines = new ArrayList<String>();
lines.add(
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">");
lines.add(" <modelVersion>4.0.0</modelVersion>");
lines.add(" <groupId>org.apache.sling</groupId>");
lines.add(" <artifactId>temp-artifact</artifactId>");
lines.add(" <version>1-SNAPSHOT</version>");
lines.add(" <dependencies>");
lines.add(" <dependency>");
lines.add(" <groupId>".concat(artifactId.getGroupId()).concat("</groupId>"));
lines.add(" <artifactId>".concat(artifactId.getArtifactId()).concat("</artifactId>"));
lines.add(" <version>".concat(artifactId.getVersion()).concat("</version>"));
if (artifactId.getClassifier() != null) {
lines.add(" <classifier>".concat(artifactId.getClassifier()).concat("</classifier>"));
}
if (!"bundle".equals(artifactId.getType()) && !"jar".equals(artifactId.getType())) {
lines.add(" <type>".concat(artifactId.getType()).concat("</type>"));
}
lines.add(" <scope>provided</scope>");
lines.add(" </dependency>");
lines.add(" </dependencies>");
lines.add("</project>");
logger.debug("Writing pom to {}", dir);
Files.write(dir.resolve("pom.xml"), lines, Charset.forName("UTF-8"));
final Path output = dir.resolve("output.txt");
final Path error = dir.resolve("error.txt");
// invoke maven
logger.debug("Invoking mvn...");
final ProcessBuilder pb = new ProcessBuilder("mvn", "verify");
pb.directory(dir.toFile());
pb.redirectOutput(Redirect.to(output.toFile()));
pb.redirectError(Redirect.to(error.toFile()));
final Process p = pb.start();
try {
p.waitFor();
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
} finally {
deleteDirectoryRecursively(dir);
}
}