use of org.apache.maven.model.io.DefaultModelWriter in project syndesis by syndesisio.
the class RepackageExtensionMojo method obtainBomDependencies.
protected Set<MavenDependency> obtainBomDependencies(String urlLocation) throws IOException, MojoExecutionException {
Artifact artifact = downloadAndInstallArtifact(urlLocation).getArtifact();
File tempPom = new File(outputDirectory, ".syndesis-extension-plugin-temp-pom");
try (BufferedWriter out = Files.newBufferedWriter(tempPom.toPath(), StandardCharsets.UTF_8)) {
Dependency bom = new Dependency();
bom.setGroupId(artifact.getGroupId());
bom.setArtifactId(artifact.getArtifactId());
bom.setVersion(artifact.getVersion());
bom.setType(artifact.getExtension());
bom.setScope("import");
Model bomModel = new Model();
bomModel.setDependencyManagement(new DependencyManagement());
bomModel.getDependencyManagement().addDependency(bom);
bomModel.setRepositories(project.getRepositories());
MavenProject bomProject = new MavenProject();
bomProject.setModel(bomModel);
bomProject.setModelVersion(project.getModelVersion());
bomProject.setGroupId(project.getGroupId());
bomProject.setArtifactId(project.getArtifactId() + "-temp-bom");
bomProject.setVersion(project.getVersion());
ModelWriter modelWriter = new DefaultModelWriter();
modelWriter.write(out, Collections.emptyMap(), bomProject.getModel());
MavenResolverSystem resolver = Maven.resolver();
resolver.loadPomFromFile(tempPom).importCompileAndRuntimeDependencies();
MavenWorkingSession session = ((MavenWorkingSessionContainer) resolver).getMavenWorkingSession();
return session.getDependencyManagement();
} finally {
if (!tempPom.delete()) {
getLog().warn("Cannot delete file " + tempPom);
}
}
}
Aggregations