use of org.eclipse.che.maven.data.MavenArtifact in project che by eclipse.
the class MavenProjectManager method findDependentProjects.
public List<MavenProject> findDependentProjects(List<MavenProject> projects) {
readLock.lock();
try {
List<MavenProject> result = new ArrayList<>();
Set<MavenKey> mavenKeys = projects.stream().map(MavenProject::getMavenKey).collect(Collectors.toSet());
Set<String> paths = projects.stream().map(project -> project.getProject().getFullPath().toOSString()).collect(Collectors.toSet());
for (MavenProject project : projectToMavenProjectMap.values()) {
boolean isAdd = false;
for (String path : project.getModulesPath()) {
if (paths.contains(path)) {
isAdd = true;
break;
}
}
if (!isAdd) {
for (MavenArtifact artifact : project.getDependencies()) {
if (contains(mavenKeys, artifact.getArtifactId(), artifact.getGroupId(), artifact.getVersion())) {
isAdd = true;
break;
}
}
}
if (isAdd) {
result.add(project);
}
}
return result;
} finally {
readLock.unlock();
}
}
use of org.eclipse.che.maven.data.MavenArtifact in project che by eclipse.
the class ClasspathManager method downloadSources.
private boolean downloadSources(IPackageFragmentRoot fragmentRoot) throws JavaModelException {
fragmentRoot.getAdapter(MavenArtifactKey.class);
IClasspathEntry classpathEntry = fragmentRoot.getResolvedClasspathEntry();
MavenArtifactKey artifactKey = getArtifactKey(classpathEntry);
if (artifactKey != null) {
MavenServerWrapper mavenServer = wrapperManager.getMavenServer(MavenWrapperManager.ServerType.DOWNLOAD);
try {
mavenServer.customize(projectManager.copyWorkspaceCache(), terminal, notifier, false, false);
MavenArtifactKey sourceKey = new MavenArtifactKey(artifactKey.getGroupId(), artifactKey.getArtifactId(), artifactKey.getVersion(), artifactKey.getPackaging(), SOURCES);
MavenArtifact mavenArtifact = mavenServer.resolveArtifact(sourceKey, Collections.emptyList());
if (mavenArtifact.isResolved()) {
updateClasspath(projectManager.findMavenProject(fragmentRoot.getJavaProject().getProject()));
}
return mavenArtifact.isResolved();
} finally {
wrapperManager.release(mavenServer);
}
}
return false;
}
use of org.eclipse.che.maven.data.MavenArtifact in project che by eclipse.
the class ProjectResolverTest method testResolveNotExistingArtifactSource.
@Test
public void testResolveNotExistingArtifactSource() throws Exception {
MavenArtifactKey artifactKey = new MavenArtifactKey("junit", "junit", "3.56", "jar", "sources");
MavenArtifact artifact = mavenServer.resolveArtifact(artifactKey, Collections.emptyList());
assertNotNull(artifact);
assertFalse(artifact.isResolved());
}
use of org.eclipse.che.maven.data.MavenArtifact in project che by eclipse.
the class ProjectResolverTest method testResolveArtifactSource.
@Test
public void testResolveArtifactSource() throws Exception {
MavenArtifactKey artifactKey = new MavenArtifactKey("junit", "junit", "4.11", "jar", "sources");
MavenArtifact artifact = mavenServer.resolveArtifact(artifactKey, Collections.emptyList());
assertNotNull(artifact);
assertTrue(artifact.isResolved());
}
use of org.eclipse.che.maven.data.MavenArtifact in project che by eclipse.
the class MavenServerImpl method resolveArtifact.
@Override
public MavenArtifact resolveArtifact(MavenArtifactKey artifactKey, List<MavenRemoteRepository> repositories) throws RemoteException {
Artifact artifact = getMavenComponent(ArtifactFactory.class).createArtifactWithClassifier(artifactKey.getGroupId(), artifactKey.getArtifactId(), artifactKey.getVersion(), artifactKey.getPackaging(), artifactKey.getClassifier());
List<ArtifactRepository> repos = new ArrayList<>();
ArtifactRepositoryFactory factory = getMavenComponent(ArtifactRepositoryFactory.class);
for (MavenRemoteRepository repository : repositories) {
try {
ArtifactRepository artifactRepository = ProjectUtils.buildArtifactRepository(MavenModelUtil.convertToMavenRepository(repository), factory, container);
repos.add(artifactRepository);
} catch (InvalidRepositoryException e) {
MavenServerContext.getLogger().error(e);
}
}
MavenExecutionRequest request = newMavenRequest(null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
repos.forEach(request::addRemoteRepository);
DefaultMaven maven = (DefaultMaven) getMavenComponent(Maven.class);
RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
org.eclipse.aether.impl.ArtifactResolver artifactResolver = getMavenComponent(org.eclipse.aether.impl.ArtifactResolver.class);
InternalLoggerFactory loggerFactory = new InternalLoggerFactory();
if (artifactResolver instanceof DefaultArtifactResolver) {
((DefaultArtifactResolver) artifactResolver).setLoggerFactory(loggerFactory);
}
org.eclipse.aether.RepositorySystem repositorySystem = getMavenComponent(org.eclipse.aether.RepositorySystem.class);
if (repositorySystem instanceof DefaultRepositorySystem) {
((DefaultRepositorySystem) repositorySystem).setLoggerFactory(loggerFactory);
}
List<RemoteRepository> remoteRepositories = RepositoryUtils.toRepos(request.getRemoteRepositories());
remoteRepositories = repositorySystem.newResolutionRepositories(repositorySystemSession, remoteRepositories);
try {
ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, new ArtifactRequest(RepositoryUtils.toArtifact(artifact), remoteRepositories, null));
return MavenModelUtil.convertArtifact(RepositoryUtils.toArtifact(artifactResult.getArtifact()), localRepository);
} catch (ArtifactResolutionException e) {
MavenServerContext.getLogger().info(e);
}
return MavenModelUtil.convertArtifact(artifact, localRepository);
}
Aggregations