use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class GetMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (isSkip()) {
getLog().info("Skipping plugin execution");
return;
}
if (coordinate.getArtifactId() == null && artifact == null) {
throw new MojoFailureException("You must specify an artifact, " + "e.g. -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0");
}
if (artifact != null) {
String[] tokens = StringUtils.split(artifact, ":");
if (tokens.length < 3 || tokens.length > 5) {
throw new MojoFailureException("Invalid artifact, you must specify groupId:artifactId:version[:packaging[:classifier]] " + artifact);
}
coordinate.setGroupId(tokens[0]);
coordinate.setArtifactId(tokens[1]);
coordinate.setVersion(tokens[2]);
if (tokens.length >= 4) {
coordinate.setType(tokens[3]);
}
if (tokens.length == 5) {
coordinate.setClassifier(tokens[4]);
}
}
ArtifactRepositoryPolicy always = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
List<ArtifactRepository> repoList = new ArrayList<ArtifactRepository>();
if (pomRemoteRepositories != null) {
repoList.addAll(pomRemoteRepositories);
}
if (remoteRepositories != null) {
// Use the same format as in the deploy plugin id::layout::url
List<String> repos = Arrays.asList(StringUtils.split(remoteRepositories, ","));
for (String repo : repos) {
repoList.add(parseRepository(repo, always));
}
}
try {
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(repoList);
if (transitive) {
getLog().info("Resolving " + coordinate + " with transitive dependencies");
dependencyResolver.resolveDependencies(buildingRequest, coordinate, null);
} else {
getLog().info("Resolving " + coordinate);
artifactResolver.resolveArtifact(buildingRequest, toArtifactCoordinate(coordinate));
}
} catch (ArtifactResolverException e) {
throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
} catch (DependencyResolverException e) {
throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class TestCopyDependenciesMojo2 method testRepositoryLayout.
public void testRepositoryLayout() throws Exception {
String baseVersion = "2.0-SNAPSHOT";
String groupId = "testGroupId";
String artifactId = "expanded-snapshot";
Artifact expandedSnapshot = createExpandedVersionArtifact(baseVersion, groupId, artifactId, "compile", "jar", null);
mojo.getProject().getArtifacts().add(expandedSnapshot);
mojo.getProject().getDependencyArtifacts().add(expandedSnapshot);
Artifact pomExpandedSnapshot = createExpandedVersionArtifact(baseVersion, groupId, artifactId, "compile", "pom", null);
mojo.getProject().getArtifacts().add(pomExpandedSnapshot);
mojo.getProject().getDependencyArtifacts().add(pomExpandedSnapshot);
mojo.useRepositoryLayout = true;
mojo.execute();
ArtifactFactory artifactFactory = lookup(ArtifactFactory.class);
File outputDirectory = mojo.outputDirectory;
ArtifactRepository targetRepository = new MavenArtifactRepository("local", outputDirectory.toURL().toExternalForm(), new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy());
Set<Artifact> artifacts = mojo.getProject().getArtifacts();
for (Artifact artifact : artifacts) {
assertArtifactExists(artifact, targetRepository);
if (!artifact.getBaseVersion().equals(artifact.getVersion())) {
Artifact baseArtifact = artifactFactory.createArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact.getScope(), artifact.getType());
assertArtifactExists(baseArtifact, targetRepository);
}
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class DeployFileMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
if (uniqueVersion != null) {
throw new MojoExecutionException("You are using 'uniqueVersion' which has been removed" + " from the maven-deploy-plugin. " + "Please see the >>Major Version Upgrade to version 3.0.0<< on the plugin site.");
}
failIfOffline();
if (!file.exists()) {
throw new MojoExecutionException(file.getPath() + " not found.");
}
initProperties();
ArtifactRepository deploymentRepository = createDeploymentArtifactRepository(repositoryId, url);
String protocol = deploymentRepository.getProtocol();
if (StringUtils.isEmpty(protocol)) {
throw new MojoExecutionException("No transfer protocol found.");
}
MavenProject project = createMavenProject();
Artifact artifact = project.getArtifact();
if (file.equals(getLocalRepoFile())) {
throw new MojoFailureException("Cannot deploy artifact from the local repository: " + file);
}
List<Artifact> deployableArtifacts = new ArrayList<Artifact>();
if (classifier == null) {
artifact.setFile(file);
deployableArtifacts.add(artifact);
} else {
projectHelper.attachArtifact(project, packaging, classifier, file);
}
// Upload the POM if requested, generating one if need be
if (!"pom".equals(packaging)) {
File pom = pomFile;
if (pom == null && generatePom) {
pom = generatePomFile();
}
if (pom != null) {
if (classifier == null) {
ProjectArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, pom);
artifact.addMetadata(metadata);
} else {
artifact.setFile(pom);
deployableArtifacts.add(artifact);
}
}
}
if (updateReleaseInfo) {
artifact.setRelease(true);
}
artifact.setRepository(deploymentRepository);
if (sources != null) {
projectHelper.attachArtifact(project, "jar", "sources", sources);
}
if (javadoc != null) {
projectHelper.attachArtifact(project, "jar", "javadoc", javadoc);
}
if (files != null) {
if (types == null) {
throw new MojoExecutionException("You must specify 'types' if you specify 'files'");
}
if (classifiers == null) {
throw new MojoExecutionException("You must specify 'classifiers' if you specify 'files'");
}
int filesLength = StringUtils.countMatches(files, ",");
int typesLength = StringUtils.countMatches(types, ",");
int classifiersLength = StringUtils.countMatches(classifiers, ",");
if (typesLength != filesLength) {
throw new MojoExecutionException("You must specify the same number of entries in 'files' and " + "'types' (respectively " + filesLength + " and " + typesLength + " entries )");
}
if (classifiersLength != filesLength) {
throw new MojoExecutionException("You must specify the same number of entries in 'files' and " + "'classifiers' (respectively " + filesLength + " and " + classifiersLength + " entries )");
}
int fi = 0;
int ti = 0;
int ci = 0;
for (int i = 0; i <= filesLength; i++) {
int nfi = files.indexOf(',', fi);
if (nfi == -1) {
nfi = files.length();
}
int nti = types.indexOf(',', ti);
if (nti == -1) {
nti = types.length();
}
int nci = classifiers.indexOf(',', ci);
if (nci == -1) {
nci = classifiers.length();
}
File file = new File(files.substring(fi, nfi));
if (!file.isFile()) {
// try relative to the project basedir just in case
file = new File(project.getBasedir(), files.substring(fi, nfi));
}
if (file.isFile()) {
if (StringUtils.isWhitespace(classifiers.substring(ci, nci))) {
projectHelper.attachArtifact(project, types.substring(ti, nti).trim(), file);
} else {
projectHelper.attachArtifact(project, types.substring(ti, nti).trim(), classifiers.substring(ci, nci).trim(), file);
}
} else {
throw new MojoExecutionException("Specified side artifact " + file + " does not exist");
}
fi = nfi + 1;
ti = nti + 1;
ci = nci + 1;
}
} else {
if (types != null) {
throw new MojoExecutionException("You must specify 'files' if you specify 'types'");
}
if (classifiers != null) {
throw new MojoExecutionException("You must specify 'files' if you specify 'classifiers'");
}
}
List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
for (Artifact attached : attachedArtifacts) {
deployableArtifacts.add(attached);
}
try {
artifactDeployer.deploy(getSession().getProjectBuildingRequest(), deploymentRepository, deployableArtifacts);
} catch (ArtifactDeployerException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class DeployMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
boolean addedDeployRequest = false;
if (skip) {
getLog().info("Skipping artifact deployment");
} else {
failIfOffline();
// CHECKSTYLE_OFF: LineLength
// @formatter:off
ProjectDeployerRequest pdr = new ProjectDeployerRequest().setProject(project).setUpdateReleaseInfo(isUpdateReleaseInfo()).setRetryFailedDeploymentCount(getRetryFailedDeploymentCount()).setAltReleaseDeploymentRepository(altReleaseDeploymentRepository).setAltSnapshotDeploymentRepository(altSnapshotDeploymentRepository).setAltDeploymentRepository(altDeploymentRepository);
// @formatter:on
// CHECKSTYLE_ON: LineLength
ArtifactRepository repo = getDeploymentRepository(pdr);
if (!deployAtEnd) {
deployProject(getSession().getProjectBuildingRequest(), pdr, repo);
} else {
DEPLOYREQUESTS.add(pdr);
addedDeployRequest = true;
}
}
boolean projectsReady = READYPROJECTSCOUNTER.incrementAndGet() == reactorProjects.size();
if (projectsReady) {
synchronized (DEPLOYREQUESTS) {
while (!DEPLOYREQUESTS.isEmpty()) {
ArtifactRepository repo = getDeploymentRepository(DEPLOYREQUESTS.get(0));
deployProject(getSession().getProjectBuildingRequest(), DEPLOYREQUESTS.remove(0), repo);
}
}
} else if (addedDeployRequest) {
getLog().info("Deploying " + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion() + " at end");
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class DefaultDependencyResolverTest method test_aggregateRemoteArtifactRepositories.
public void test_aggregateRemoteArtifactRepositories() {
final List<ArtifactRepository> externalRepos = new ArrayList<ArtifactRepository>();
final ArtifactRepository er1 = repoFactory.createArtifactRepository("test.1", "http://test.com/path", layout, null, null);
externalRepos.add(er1);
final ArtifactRepository er2 = repoFactory.createArtifactRepository("test.2", "http://test2.com/path", layout, null, null);
externalRepos.add(er2);
final List<ArtifactRepository> projectRepos = new ArrayList<ArtifactRepository>();
final ArtifactRepository pr1 = repoFactory.createArtifactRepository("project.1", "http://test.com/project", layout, null, null);
projectRepos.add(pr1);
final ArtifactRepository pr2 = repoFactory.createArtifactRepository("project.2", "http://test2.com/path", layout, null, null);
projectRepos.add(pr2);
final MavenProject project = createMavenProject("group", "artifact", "1", new File("base"));
project.setRemoteArtifactRepositories(projectRepos);
final List<ArtifactRepository> aggregated = resolver.aggregateRemoteArtifactRepositories(externalRepos, Collections.singleton(project));
assertRepositoryWithId(er1.getId(), aggregated, true);
assertRepositoryWithId(er2.getId(), aggregated, true);
assertRepositoryWithId(pr1.getId(), aggregated, true);
assertRepositoryWithId(pr2.getId(), aggregated, false);
}
Aggregations