in src/main/java/org/apache/sling/installer/factory/model/impl/RepositoryAccess.java [102:145]
private void downloadArtifact(final Artifact artifact) throws IOException {
// create fake pom
final Path dir = Files.createTempDirectory(null);
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>" + artifact.getGroupId() + "</groupId>");
lines.add(" <artifactId>" + artifact.getArtifactId() + "</artifactId>");
lines.add(" <version>" + artifact.getVersion() + "</version>");
if ( artifact.getClassifier() != null ) {
lines.add(" <classifier>" + artifact.getClassifier() + "</classifier>");
}
if ( !"bundle".equals(artifact.getType()) && !"jar".equals(artifact.getType()) ) {
lines.add(" <type>" + artifact.getType() + "</type>");
}
lines.add(" <scope>provided</scope>");
lines.add(" </dependency>");
lines.add(" </dependencies>");
lines.add("</project>");
logger.info("Writing pom to {}", dir);
Files.write(dir.resolve("pom.xml"), lines, Charset.forName("UTF-8"));
final File output = dir.resolve("output.txt").toFile();
final File error = dir.resolve("error.txt").toFile();
// invoke maven
logger.info("Invoking maven...");
final ProcessBuilder pb = new ProcessBuilder("mvn", "verify");
pb.directory(dir.toFile());
pb.redirectOutput(Redirect.to(output));
pb.redirectError(Redirect.to(error));
final Process p = pb.start();
try {
p.waitFor();
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
}