use of org.apache.maven.project.artifact.ProjectArtifact in project tycho by eclipse.
the class AbstractOsgiCompilerMojo method getClasspath.
@Override
public List<ClasspathEntry> getClasspath() throws MojoExecutionException {
TychoProject projectType = getBundleProject();
ArrayList<ClasspathEntry> classpath = new ArrayList<>(((BundleProject) projectType).getClasspath(project));
if (extraClasspathElements != null) {
ArtifactRepository localRepository = session.getLocalRepository();
List<ArtifactRepository> remoteRepositories = project.getRemoteArtifactRepositories();
for (Dependency extraDependency : extraClasspathElements) {
Artifact artifact = repositorySystem.createDependencyArtifact(extraDependency);
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
request.setLocalRepository(localRepository);
request.setRemoteRepositories(remoteRepositories);
request.setResolveRoot(true);
request.setResolveTransitively(true);
ArtifactResolutionResult result = repositorySystem.resolve(request);
if (result.hasExceptions()) {
throw new MojoExecutionException("Could not resolve extra classpath entry", result.getExceptions().get(0));
}
for (Artifact b : result.getArtifacts()) {
MavenProject bProject = null;
if (b instanceof ProjectArtifact) {
bProject = ((ProjectArtifact) b).getProject();
}
ArrayList<File> bLocations = new ArrayList<>();
// TODO properly handle multiple project locations maybe
bLocations.add(b.getFile());
classpath.add(new DefaultClasspathEntry(DefaultReactorProject.adapt(bProject), null, bLocations, null));
}
}
}
return classpath;
}
Aggregations