Search in sources :

Example 11 with MavenArtifact

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();
    }
}
Also used : MavenServerManager(org.eclipse.che.plugin.maven.server.MavenServerManager) MavenWrapperManager(org.eclipse.che.plugin.maven.server.MavenWrapperManager) Proxy(java.lang.reflect.Proxy) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Deque(java.util.Deque) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) Map(java.util.Map) LinkedList(java.util.LinkedList) Set(java.util.Set) MavenServerWrapper(org.eclipse.che.plugin.maven.server.MavenServerWrapper) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) MavenProjectModifications(org.eclipse.che.plugin.maven.server.core.project.MavenProjectModifications) Provider(com.google.inject.Provider) MavenKey(org.eclipse.che.maven.data.MavenKey) List(java.util.List) Lock(java.util.concurrent.locks.Lock) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) MavenWorkspaceCache(org.eclipse.che.maven.data.MavenWorkspaceCache) Collections(java.util.Collections) Singleton(com.google.inject.Singleton) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MavenKey(org.eclipse.che.maven.data.MavenKey) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact)

Example 12 with MavenArtifact

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;
}
Also used : MavenArtifactKey(org.eclipse.che.maven.data.MavenArtifactKey) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) MavenServerWrapper(org.eclipse.che.plugin.maven.server.MavenServerWrapper) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact)

Example 13 with MavenArtifact

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());
}
Also used : MavenArtifactKey(org.eclipse.che.maven.data.MavenArtifactKey) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Test(org.testng.annotations.Test)

Example 14 with MavenArtifact

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());
}
Also used : MavenArtifactKey(org.eclipse.che.maven.data.MavenArtifactKey) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Test(org.testng.annotations.Test)

Example 15 with MavenArtifact

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);
}
Also used : DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) DefaultRepositorySystem(org.eclipse.aether.internal.impl.DefaultRepositorySystem) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ArrayList(java.util.ArrayList) MavenRemoteRepository(org.eclipse.che.maven.data.MavenRemoteRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifactResolver(org.eclipse.aether.internal.impl.DefaultArtifactResolver) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ArtifactRepositoryFactory(org.apache.maven.artifact.repository.ArtifactRepositoryFactory) DefaultMaven(org.apache.maven.DefaultMaven) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Artifact(org.apache.maven.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) MavenRemoteRepository(org.eclipse.che.maven.data.MavenRemoteRepository)

Aggregations

MavenArtifact (org.eclipse.che.maven.data.MavenArtifact)15 Test (org.testng.annotations.Test)8 MavenArtifactKey (org.eclipse.che.maven.data.MavenArtifactKey)6 File (java.io.File)4 MavenModel (org.eclipse.che.maven.data.MavenModel)4 MavenKey (org.eclipse.che.maven.data.MavenKey)3 MavenProject (org.eclipse.che.plugin.maven.server.core.project.MavenProject)3 IProject (org.eclipse.core.resources.IProject)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Artifact (org.apache.maven.artifact.Artifact)2 MavenRemoteRepository (org.eclipse.che.maven.data.MavenRemoteRepository)2 MavenServerWrapper (org.eclipse.che.plugin.maven.server.MavenServerWrapper)2 MavenServerManagerTest (org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)2 Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1 Singleton (com.google.inject.Singleton)1 Proxy (java.lang.reflect.Proxy)1 Collections (java.util.Collections)1