Example usage for org.apache.maven.execution MavenSession getLocalRepository

List of usage examples for org.apache.maven.execution MavenSession getLocalRepository

Introduction

In this page you can find the example usage for org.apache.maven.execution MavenSession getLocalRepository.

Prototype

public ArtifactRepository getLocalRepository() 

Source Link

Usage

From source file:com.tenderowls.opensource.haxemojos.components.HaxeLifecycleParticipant.java

License:Apache License

@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
    super.afterProjectsRead(session);

    try {// w w  w. jav a 2  s.c  om
        MavenProject project = session.getCurrentProject();
        bootstrap.initialize(project, session.getLocalRepository());
    } catch (Exception e) {
        throw new MavenExecutionException(e.getMessage(), e);
    }
}

From source file:guru.nidi.maven.tools.MavenUtil.java

License:Apache License

public static ArtifactResolutionResult resolveArtifact(MavenSession session, RepositorySystem repository,
        Artifact artifact, boolean transitive, ArtifactFilter resolutionFilter) {
    artifact.setArtifactHandler(new DefaultArtifactHandler(artifact.getType()));
    ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(artifact)
            .setResolveRoot(true).setServers(session.getRequest().getServers())
            .setMirrors(session.getRequest().getMirrors()).setProxies(session.getRequest().getProxies())
            .setLocalRepository(session.getLocalRepository())
            .setRemoteRepositories(session.getRequest().getRemoteRepositories())
            .setResolveTransitively(transitive).setCollectionFilter(resolutionFilter)
            .setResolutionFilter(resolutionFilter);
    //.setListeners(Arrays.<ResolutionListener>asList(new DebugResolutionListener(new ConsoleLogger())));
    return repository.resolve(request);
}

From source file:guru.nidi.maven.tools.MavenUtil.java

License:Apache License

public static MavenProject projectFromArtifact(MavenSession session, ProjectBuilder projectBuilder,
        Artifact artifact, boolean resolveDependencies) throws ProjectBuildingException {
    final ProjectBuildingRequest request = new DefaultProjectBuildingRequest()
            .setLocalRepository(session.getLocalRepository())
            .setRepositorySession(session.getRepositorySession()).setSystemProperties(System.getProperties())
            .setResolveDependencies(resolveDependencies);
    return projectBuilder.build(artifact, request).getProject();
}

From source file:io.fabric8.maven.docker.assembly.MappingTrackArchiver.java

License:Apache License

private File getLocalMavenRepoFile(MavenSession session, File source) {
    ArtifactRepository localRepo = session.getLocalRepository();
    if (localRepo == null) {
        log.warn("No local repo found so not adding any extra watches in the local repository");
        return null;
    }//from   w  w  w.j a v  a  2  s. co m

    Artifact artifact = getArtifactFromJar(source);
    if (artifact != null) {
        try {
            return new File(localRepo.getBasedir(), localRepo.pathOf(artifact));
        } catch (InvalidArtifactRTException e) {
            log.warn("Cannot get the local repository path for %s in base dir %s : %s", artifact,
                    localRepo.getBasedir(), e.getMessage());
        }
    }
    return null;
}

From source file:io.treefarm.plugins.haxe.components.HaxeLifecycleParticipant.java

License:Apache License

@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
    try {//from   www .  jav a 2  s .  com
        MavenProject project = session.getCurrentProject();
        bootstrap.initialize(project, session.getLocalRepository());
    } catch (Exception e) {
        throw new MavenExecutionException(e.getMessage(), e);
    }
}

From source file:org.apache.sling.maven.slingstart.ModelUtils.java

License:Apache License

/**
 * Get a resolved Artifact from the coordinates provided
 *
 * @return the artifact, which has been resolved.
 * @throws MojoExecutionException/*w w w .  j  av  a 2s  .com*/
 */
public static Artifact getArtifact(final MavenProject project, final MavenSession session,
        final ArtifactHandlerManager artifactHandlerManager, final ArtifactResolver resolver,
        final String groupId, final String artifactId, final String version, final String type,
        final String classifier) throws MojoExecutionException {
    final Set<Artifact> artifacts = project.getDependencyArtifacts();
    for (final Artifact artifact : artifacts) {
        if (artifact.getGroupId().equals(groupId) && artifact.getArtifactId().equals(artifactId)
                && artifact.getVersion().equals(version) && artifact.getType().equals(type)
                && ((classifier == null && artifact.getClassifier() == null)
                        || (classifier != null && classifier.equals(artifact.getClassifier())))) {
            return artifact;
        }
    }
    final Artifact prjArtifact = new DefaultArtifact(groupId, artifactId,
            VersionRange.createFromVersion(version), Artifact.SCOPE_PROVIDED, type, classifier,
            artifactHandlerManager.getArtifactHandler(type));
    try {
        resolver.resolve(prjArtifact, project.getRemoteArtifactRepositories(), session.getLocalRepository());
    } catch (final ArtifactResolutionException e) {
        throw new MojoExecutionException(
                "Unable to get artifact for " + groupId + ":" + artifactId + ":" + version, e);
    } catch (final ArtifactNotFoundException e) {
        throw new MojoExecutionException(
                "Unable to get artifact for " + groupId + ":" + artifactId + ":" + version, e);
    }
    return prjArtifact;
}

From source file:org.arakhne.maven.AbstractArakhneMojo.java

License:Open Source License

/** Load the Maven project for the given artifact.
 * /*from   www  . ja  va  2s  .c  om*/
 * @param artifact
 * @return the maven project.
 */
public MavenProject getMavenProject(Artifact artifact) {
    try {
        MavenSession session = getMavenSession();
        MavenProject current = session.getCurrentProject();
        MavenProject prj = getMavenProjectBuilder().buildFromRepository(artifact,
                current.getRemoteArtifactRepositories(), session.getLocalRepository());
        return prj;
    } catch (ProjectBuildingException e) {
        getLog().warn(e);
    }
    return null;
}

From source file:org.codehaus.mojo.sonar.Bootstraper.java

License:Open Source License

private void executeMojo(MavenProject project, MavenSession session) throws MojoExecutionException {
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try {/*from w w w .j  av  a 2 s.c om*/

        RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
        repositoryRequest.setLocalRepository(session.getLocalRepository());
        repositoryRequest.setRemoteRepositories(project.getPluginArtifactRepositories());

        Plugin plugin = createSonarPlugin();

        List<RemoteRepository> remoteRepositories = session.getCurrentProject().getRemotePluginRepositories();

        PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor(plugin, remoteRepositories,
                session.getRepositorySession());

        String goal = "sonar";

        MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo(goal);
        if (mojoDescriptor == null) {
            throw new MojoExecutionException("Unknown mojo goal: " + goal);
        }
        MojoExecution mojoExecution = new MojoExecution(plugin, goal, "sonar" + goal);

        mojoExecution.setConfiguration(convert(mojoDescriptor));

        mojoExecution.setMojoDescriptor(mojoDescriptor);

        // olamy : we exclude nothing and import nothing regarding realm import and artifacts

        DependencyFilter artifactFilter = new DependencyFilter() {
            public boolean accept(DependencyNode arg0, List<DependencyNode> arg1) {
                return true;
            }
        };

        pluginManager.setupPluginRealm(pluginDescriptor, session,
                Thread.currentThread().getContextClassLoader(), Collections.<String>emptyList(),
                artifactFilter);

        Mojo mojo = pluginManager.getConfiguredMojo(Mojo.class, session, mojoExecution);
        Thread.currentThread().setContextClassLoader(pluginDescriptor.getClassRealm());
        mojo.execute();

    } catch (Exception e) {
        throw new MojoExecutionException("Can not execute Sonar", e);
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassLoader);
    }
}

From source file:org.debian.dependency.builders.DefaultSourceBuilderManager.java

License:Apache License

private Artifact resolveArtifact(final Artifact toResolve, final MavenSession session) {
    ArtifactResolutionRequest request = new ArtifactResolutionRequest()
            .setLocalRepository(session.getLocalRepository()).setOffline(true).setResolveRoot(true)
            .setArtifact(toResolve);//from  w w w.  j av  a  2  s. c  o  m

    ArtifactResolutionResult result = repositorySystem.resolve(request);
    return result.getArtifacts().iterator().next();
}

From source file:org.debian.dependency.DefaultDependencyCollection.java

License:Apache License

private Artifact resolveArtifact(final Artifact toResolve, final MavenSession session)
        throws DependencyResolutionException {
    // otherwise resolve through the normal means
    ArtifactResolutionRequest request = new ArtifactResolutionRequest()
            .setLocalRepository(session.getLocalRepository())
            .setRemoteRepositories(session.getRequest().getRemoteRepositories())
            .setMirrors(session.getSettings().getMirrors()).setServers(session.getRequest().getServers())
            .setProxies(session.getRequest().getProxies()).setOffline(session.isOffline())
            .setForceUpdate(session.getRequest().isUpdateSnapshots()).setResolveRoot(true)
            .setArtifact(toResolve);/*  w  w  w.  ja v  a  2  s  .c  om*/

    ArtifactResolutionResult result = repositorySystem.resolve(request);
    if (!result.isSuccess()) {
        if (result.getExceptions() != null) {
            for (Exception exception : result.getExceptions()) {
                getLogger().error("Error resolving artifact " + toResolve, exception);
            }
        }
        throw new DependencyResolutionException("Unable to resolve artifact " + toResolve);
    }

    return result.getArtifacts().iterator().next();
}