List of usage examples for org.apache.maven.artifact.repository DefaultRepositoryRequest DefaultRepositoryRequest
public DefaultRepositoryRequest()
From source file:org.apache.hyracks.maven.license.SourcePointerResolver.java
License:Apache License
private void collectSourcePointers() throws ProjectBuildingException, IOException { try (StubArtifactRepository stubRepo = new StubArtifactRepository()) { DefaultRepositoryRequest rr = new DefaultRepositoryRequest(); rr.setLocalRepository(stubRepo); ArtifactRepository central = getCentralRepository(); rr.setRemoteRepositories(Collections.singletonList(central)); ArtifactResolutionRequest request = new ArtifactResolutionRequest(rr); for (LicensedProjects lp : mojo.getLicenseMap().values()) { if (lp.getLicense().getDisplayName() != null && lp.getLicense().getDisplayName().toLowerCase().contains("cddl")) { ensureCDDLSourcesPointer(lp.getProjects(), central, request); }/* ww w . j av a 2s . c o m*/ } } }
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 {// w ww. jav a 2 s . com 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
public ArtifactVersion resolveArtifactVersion(final String groupId, final String artifactId, final String artifactVersion) throws MojoExecutionException { getLog().debug(format("Reading version metadata for artifact %s:%s.", groupId, artifactId)); final RepositoryRequest request = new DefaultRepositoryRequest(); configureRepositoryRequest(request); final Artifact artifact = repositorySystem.createArtifact(groupId, artifactId, "", null, "pom"); try {/*from w w w.j ava 2s . com*/ final RepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact); getRepositoryMetadataManager().resolve(metadata, request); final Metadata repositoryMetadata = checkNotNull(metadata.getMetadata(), "No repository metadata loaded."); if (StringUtils.equals("LATEST", artifactVersion)) { final Versioning metadataVersions = checkNotNull(repositoryMetadata.getVersioning(), "No versioning information available in repository metadata."); getLog().debug(format("Resolving '%s' to latest version.", artifactVersion)); return new DefaultArtifactVersion(metadataVersions.getLatest()); } else if (StringUtils.equals("RELEASE", artifactVersion)) { final Versioning metadataVersions = checkNotNull(repositoryMetadata.getVersioning(), "No versioning information available in repository metadata."); getLog().debug(format("Resolving '%s' to release version.", artifactVersion)); return new DefaultArtifactVersion(metadataVersions.getRelease()); } else { getLog().debug(format("Resolving '%s' to version.", artifactVersion)); return new DefaultArtifactVersion(artifactVersion); } } catch (final Exception e) { getLog().debug(e); throw new MojoExecutionException( format("Unable to retrieve available versions for artifact %s:%s:%s. %s", groupId, artifactId, artifactVersion, e.getMessage())); } }