Example usage for org.apache.maven.artifact.repository RepositoryRequest setLocalRepository

List of usage examples for org.apache.maven.artifact.repository RepositoryRequest setLocalRepository

Introduction

In this page you can find the example usage for org.apache.maven.artifact.repository RepositoryRequest setLocalRepository.

Prototype

RepositoryRequest setLocalRepository(ArtifactRepository localRepository);

Source Link

Document

Sets the local repository to use.

Usage

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 ava 2s .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.eclipse.ebr.maven.ModelUtil.java

License:Open Source License

void configureRepositoryRequest(final RepositoryRequest request) throws MojoExecutionException {
    request.setLocalRepository(getMavenSession().getLocalRepository());
    if (!getMavenSession().isOffline()) {
        try {//from w w  w.  j  a  v a  2 s  .c o m
            request.setRemoteRepositories(getRepositories(false));
        } catch (final InvalidRepositoryException e) {
            getLog().debug(e);
            throw new MojoExecutionException(format(
                    "Unable to create the default remote repository. Please verify the Maven configuration. %s",
                    e.getMessage()));
        }
    }
    request.setOffline(getMavenSession().isOffline());
    request.setForceUpdate(RepositoryPolicy.UPDATE_POLICY_ALWAYS
            .equals(getMavenSession().getRepositorySession().getUpdatePolicy()));
}