Search in sources :

Example 46 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project sts4 by spring-projects.

the class MavenBridge method compileAndGenerateJavadoc.

public MavenExecutionResult compileAndGenerateJavadoc(File pom) throws MavenException {
    try {
        MavenExecutionRequest request = createExecutionRequest();
        lookup(MavenExecutionRequestPopulator.class).populateDefaults(request);
        request.setPom(pom);
        ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
        configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
        configuration.setRepositorySession(createRepositorySession(request));
        configuration.setResolveDependencies(true);
        configuration.setResolveVersionRanges(true);
        request.setGoals(Arrays.asList(new String[] { "compile", "javadoc:javadoc" }));
        Properties userProperties = (Properties) request.getUserProperties().clone();
        userProperties.put("show", "private");
        request.setUserProperties(userProperties);
        return lookup(Maven.class).execute(request);
    } catch (MavenExecutionRequestPopulationException e) {
        throw new MavenException(e);
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) Properties(java.util.Properties) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Example 47 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project sts4 by spring-projects.

the class MavenBridge method getMirror.

public Mirror getMirror(ArtifactRepository repo) throws MavenException {
    MavenExecutionRequest request = createExecutionRequest();
    populateDefaults(request);
    return lookup(RepositorySystem.class).getMirror(repo, request.getMirrors());
}
Also used : RepositorySystem(org.apache.maven.repository.RepositorySystem) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest)

Example 48 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project sts4 by spring-projects.

the class MavenBridge method createExecutionRequest.

/* package */
@SuppressWarnings("deprecation")
MavenExecutionRequest createExecutionRequest() throws MavenException {
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    if (mavenConfiguration.getGlobalSettingsFile() != null) {
        request.setGlobalSettingsFile(new File(mavenConfiguration.getGlobalSettingsFile()));
    }
    File userSettingsFile = SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE;
    if (mavenConfiguration.getUserSettingsFile() != null) {
        userSettingsFile = new File(mavenConfiguration.getUserSettingsFile());
    }
    request.setUserSettingsFile(userSettingsFile);
    try {
        lookup(MavenExecutionRequestPopulator.class).populateFromSettings(request, getSettings());
    } catch (MavenExecutionRequestPopulationException ex) {
        throw new MavenException(ex);
    }
    ArtifactRepository localRepository = getLocalRepository();
    request.setLocalRepository(localRepository);
    request.setLocalRepositoryPath(localRepository.getBasedir());
    // request.setOffline(mavenConfiguration.isOffline());
    // request.getUserProperties().put("m2e.version",
    // MavenPluginActivator.getVersion()); //$NON-NLS-1$
    // request.getUserProperties().put(ConfigurationProperties.USER_AGENT,
    // MavenPluginActivator.getUserAgent());
    EnvironmentUtils.addEnvVars(request.getSystemProperties());
    copyProperties(request.getSystemProperties(), System.getProperties());
    request.setCacheNotFound(true);
    request.setCacheTransferError(true);
    // request.setUpdateSnapshots(false);
    return request;
}
Also used : MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) File(java.io.File) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Example 49 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project sts4 by spring-projects.

the class MavenCore method resolveDependencies.

/**
 * Calculates dependency graph for a Maven project provided the scope.
 *
 * @param project Maven Project descriptor
 * @param scope Dependency scope
 * @return Set of all dependencies including transient ones
 * @throws MavenException
 */
public Set<Artifact> resolveDependencies(MavenProject project, String scope) throws MavenException {
    MavenExecutionRequest request = maven.createExecutionRequest();
    DefaultRepositorySystemSession session = maven.createRepositorySession(request);
    DependencyNode graph = readDependencyTree(maven.lookupComponent(org.eclipse.aether.RepositorySystem.class), session, project, scope);
    if (graph != null) {
        ArrayList<DependencyNode> dependencyNodes = new ArrayList<>();
        graph.accept(new DependencyVisitor() {

            public boolean visitEnter(DependencyNode node) {
                if (node.getDependency() != null) {
                    dependencyNodes.add(node);
                }
                return true;
            }

            public boolean visitLeave(DependencyNode dependencynode) {
                return true;
            }
        });
        LinkedHashSet<Artifact> artifacts = new LinkedHashSet<>();
        RepositoryUtils.toArtifacts(artifacts, dependencyNodes, Collections.singletonList(project.getArtifact().getId()), null);
        return artifacts.parallelStream().map(artifact -> {
            if (!artifact.isResolved()) {
                try {
                    artifact = maven.resolve(artifact, project.getRemoteArtifactRepositories(), request);
                } catch (MavenException e) {
                    Log.log(e);
                    // Maven 2.x quirk: an artifact always points at the local repo,
                    // regardless whether resolved or not
                    LocalRepositoryManager lrm = session.getLocalRepositoryManager();
                    String path = lrm.getPathForLocalArtifact(RepositoryUtils.toArtifact(artifact));
                    artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
                }
            }
            return artifact;
        }).collect(Collectors.toSet());
    }
    return Collections.emptySet();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Arrays(java.util.Arrays) ArtifactTypeRegistry(org.eclipse.aether.artifact.ArtifactTypeRegistry) URL(java.net.URL) DependencyManagement(org.apache.maven.model.DependencyManagement) SimpleOptionalitySelector(org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector) MavenProject(org.apache.maven.project.MavenProject) ConflictResolver(org.eclipse.aether.util.graph.transformer.ConflictResolver) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) Artifact(org.apache.maven.artifact.Artifact) JandexIndex(org.springframework.ide.vscode.commons.jandex.JandexIndex) Path(java.nio.file.Path) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) FilteringDependencyVisitor(org.eclipse.aether.util.graph.visitor.FilteringDependencyVisitor) Collection(java.util.Collection) Set(java.util.Set) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) SourceUrlProviderFromSourceContainer(org.springframework.ide.vscode.commons.javadoc.SourceUrlProviderFromSourceContainer) Collectors(java.util.stream.Collectors) ScopeDependencyFilter(org.eclipse.aether.util.filter.ScopeDependencyFilter) List(java.util.List) Stream(java.util.stream.Stream) RepositoryUtils(org.apache.maven.RepositoryUtils) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) DependencyManagerUtils(org.eclipse.aether.util.graph.manager.DependencyManagerUtils) CloningDependencyVisitor(org.eclipse.aether.util.graph.visitor.CloningDependencyVisitor) HtmlJavadocProvider(org.springframework.ide.vscode.commons.javadoc.HtmlJavadocProvider) Supplier(com.google.common.base.Supplier) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) JavaScopeSelector(org.eclipse.aether.util.graph.transformer.JavaScopeSelector) Suppliers(com.google.common.base.Suppliers) NearestVersionSelector(org.eclipse.aether.util.graph.transformer.NearestVersionSelector) LinkedHashSet(java.util.LinkedHashSet) CollectRequest(org.eclipse.aether.collection.CollectRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) Log(org.springframework.ide.vscode.commons.util.Log) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) JavaScopeDeriver(org.eclipse.aether.util.graph.transformer.JavaScopeDeriver) IOException(java.io.IOException) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) InputStreamReader(java.io.InputStreamReader) File(java.io.File) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) Paths(java.nio.file.Paths) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) InputStream(java.io.InputStream) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) FilteringDependencyVisitor(org.eclipse.aether.util.graph.visitor.FilteringDependencyVisitor) CloningDependencyVisitor(org.eclipse.aether.util.graph.visitor.CloningDependencyVisitor) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) File(java.io.File)

Example 50 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project sts4 by spring-projects.

the class MavenCore method localRepositoryFolder.

public File localRepositoryFolder() throws MavenException {
    MavenExecutionRequest request = maven.createExecutionRequest();
    DefaultRepositorySystemSession session = maven.createRepositorySession(request);
    LocalRepositoryManager lrm = session.getLocalRepositoryManager();
    return lrm.getRepository().getBasedir();
}
Also used : DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager)

Aggregations

MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)56 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)40 File (java.io.File)24 MavenSession (org.apache.maven.execution.MavenSession)20 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)14 MavenProject (org.apache.maven.project.MavenProject)14 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)10 IOException (java.io.IOException)9 MavenExecutionRequestPopulationException (org.apache.maven.execution.MavenExecutionRequestPopulationException)9 MavenExecutionRequestPopulator (org.apache.maven.execution.MavenExecutionRequestPopulator)9 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)8 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)7 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)7 FileNotFoundException (java.io.FileNotFoundException)6 Path (java.nio.file.Path)6 Properties (java.util.Properties)6 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)6 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)6 LifecycleExecutionException (org.apache.maven.lifecycle.LifecycleExecutionException)5 ProjectBuilder (org.apache.maven.project.ProjectBuilder)5