use of org.apache.maven.artifact.repository.ArtifactRepository in project asterixdb by apache.
the class SourcePointerResolver method ensureCDDLSourcesPointer.
private void ensureCDDLSourcesPointer(Collection<Project> projects, ArtifactRepository central, ArtifactResolutionRequest request) throws ProjectBuildingException, IOException {
for (Project p : projects) {
if (p.getSourcePointer() != null) {
continue;
}
mojo.getLog().debug("finding sources for artifact: " + p);
Artifact sourcesArtifact = new DefaultArtifact(p.getGroupId(), p.getArtifactId(), p.getVersion(), Artifact.SCOPE_COMPILE, "jar", "sources", null);
MavenProject mavenProject = mojo.resolveDependency(sourcesArtifact);
sourcesArtifact.setArtifactHandler(mavenProject.getArtifact().getArtifactHandler());
final ArtifactRepository localRepo = mojo.getSession().getLocalRepository();
final File marker = new File(localRepo.getBasedir(), localRepo.pathOf(sourcesArtifact) + ".oncentral");
final File antimarker = new File(localRepo.getBasedir(), localRepo.pathOf(sourcesArtifact) + ".nocentral");
boolean onCentral;
if (marker.exists() || antimarker.exists()) {
onCentral = marker.exists();
} else {
request.setArtifact(sourcesArtifact);
ArtifactResolutionResult result = mojo.getArtifactResolver().resolve(request);
mojo.getLog().debug("result: " + result);
onCentral = result.isSuccess();
if (onCentral) {
FileUtils.touch(marker);
} else {
FileUtils.touch(antimarker);
}
}
StringBuilder noticeBuilder = new StringBuilder("You may obtain ");
noticeBuilder.append(p.getName()).append(" in Source Code form code here:\n");
if (onCentral) {
noticeBuilder.append(central.getUrl()).append("/").append(central.pathOf(sourcesArtifact));
} else {
mojo.getLog().warn("Unable to find sources in 'central' for " + p + ", falling back to project url: " + p.getUrl());
noticeBuilder.append(p.getUrl() != null ? p.getUrl() : "MISSING SOURCE POINTER");
}
p.setSourcePointer(noticeBuilder.toString());
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project sling by apache.
the class BundleInstallFileMojo method resolveBundleFileFromArtifact.
@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
private String resolveBundleFileFromArtifact() throws MojoExecutionException {
if (artifactId == null && artifact == null) {
return null;
}
if (artifactId == null) {
String[] tokens = StringUtils.split(artifact, ":");
if (tokens.length != 3 && tokens.length != 4 && tokens.length != 5) {
throw new MojoExecutionException("Invalid artifact, you must specify " + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
}
groupId = tokens[0];
artifactId = tokens[1];
version = tokens[2];
if (tokens.length >= 4)
packaging = tokens[3];
if (tokens.length == 5)
classifier = tokens[4];
}
Artifact packageArtifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging, classifier);
if (pomRemoteRepositories == null) {
pomRemoteRepositories = new ArrayList();
}
List repoList = new ArrayList(pomRemoteRepositories);
if (repositoryUrl != null) {
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
ArtifactRepository remoteRepo = artifactRepositoryFactory.createArtifactRepository(repositoryId, repositoryUrl, repositoryLayout, policy, policy);
repoList.add(remoteRepo);
}
try {
artifactResolver.resolve(packageArtifact, repoList, localRepository);
getLog().info("Resolved artifact to " + packageArtifact.getFile().getAbsolutePath());
} catch (AbstractArtifactResolutionException e) {
throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
}
return packageArtifact.getFile().getAbsolutePath();
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project bnd by bndtools.
the class DependencyResolver method resolve.
public Map<File, ArtifactResult> resolve() throws MojoExecutionException {
if (resolvedDependencies != null) {
return resolvedDependencies;
}
DependencyResolutionRequest request = new DefaultDependencyResolutionRequest(project, session);
request.setResolutionFilter(new DependencyFilter() {
@Override
public boolean accept(DependencyNode node, List<DependencyNode> parents) {
if (node.getDependency() != null) {
return scopes.contains(node.getDependency().getScope());
}
return false;
}
});
DependencyResolutionResult result;
try {
result = resolver.resolve(request);
} catch (DependencyResolutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
Map<File, ArtifactResult> dependencies = new HashMap<>();
DependencyNode dependencyGraph = result.getDependencyGraph();
if (dependencyGraph != null && !dependencyGraph.getChildren().isEmpty()) {
List<RemoteRepository> remoteRepositories = new ArrayList<>(project.getRemoteProjectRepositories());
ArtifactRepository deployRepo = project.getDistributionManagementArtifactRepository();
if (deployRepo != null) {
remoteRepositories.add(RepositoryUtils.toRepo(deployRepo));
}
discoverArtifacts(dependencies, dependencyGraph.getChildren(), project.getArtifact().getId(), remoteRepositories);
}
return resolvedDependencies = dependencies;
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project sling by apache.
the class MavenSourceReferenceResolver method resolve.
@Override
public IRuntimeClasspathEntry resolve(SourceReference reference) throws CoreException {
if (reference == null || reference.getType() != SourceReference.Type.MAVEN) {
return null;
}
MavenSourceReference sr = (MavenSourceReference) reference;
List<ArtifactRepository> repos = MavenPlugin.getMaven().getArtifactRepositories();
Artifact jarArtifact = MavenPlugin.getMaven().resolve(sr.getGroupId(), sr.getArtifactId(), sr.getVersion(), "jar", "", repos, new NullProgressMonitor());
Artifact sourcesArtifact = MavenPlugin.getMaven().resolve(sr.getGroupId(), sr.getArtifactId(), sr.getVersion(), "jar", "sources", repos, new NullProgressMonitor());
IPath jarPath = Path.fromOSString(jarArtifact.getFile().getAbsolutePath());
IPath sourcePath = Path.fromOSString(sourcesArtifact.getFile().getAbsolutePath());
IRuntimeClasspathEntry mavenEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(jarPath);
mavenEntry.setSourceAttachmentPath(sourcePath);
return mavenEntry;
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project felix by apache.
the class AbstractBundlePluginTest method getMavenProjectStub.
protected MavenProjectStub getMavenProjectStub() {
MavenProjectStub project = new MavenProjectStub();
project.setGroupId("group");
project.setArtifactId("project");
project.setVersion("1.2.3.4");
VersionRange versionRange = VersionRange.createFromVersion(project.getVersion());
ArtifactHandler artifactHandler = new DefaultArtifactHandler("pom");
Artifact artifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), versionRange, null, "pom", null, artifactHandler);
artifact.setResolved(true);
project.setArtifact(artifact);
ProjectBuilderConfiguration projectBuilderConfiguration = new DefaultProjectBuilderConfiguration();
ArtifactRepositoryLayout layout = new LegacyRepositoryLayout();
ArtifactRepository artifactRepository = new DefaultArtifactRepository("scratch", new File(getBasedir(), "target" + File.separatorChar + "scratch").toURI().toString(), layout);
projectBuilderConfiguration.setLocalRepository(artifactRepository);
project.setProjectBuilderConfiguration(projectBuilderConfiguration);
return project;
}
Aggregations