use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class ListRepositoriesMojo method doExecute.
/**
* Displays a list of the repositories used by this build.
*
* @throws MojoExecutionException with a message if an error occurs.
*/
@Override
protected void doExecute() throws MojoExecutionException {
try {
CollectorResult collectResult = dependencyCollector.collectDependencies(session.getProjectBuildingRequest(), getProject().getModel());
this.getLog().info("Repositories used by this build:");
for (ArtifactRepository repo : collectResult.getRemoteRepositories()) {
this.getLog().info(repo.toString());
}
} catch (DependencyCollectorException e) {
throw new MojoExecutionException("Unable to resolve artifacts", e);
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class TestGetMojo method testParseRepository.
/**
* Test parsing of the remote repositories parameter
*
* @throws Exception in case of errors
*/
public void testParseRepository() throws Exception {
ArtifactRepository repo;
ArtifactRepositoryPolicy policy = null;
repo = mojo.parseRepository("central::default::http://repo1.maven.apache.org/maven2", policy);
assertEquals("central", repo.getId());
assertEquals(DefaultRepositoryLayout.class, repo.getLayout().getClass());
assertEquals("http://repo1.maven.apache.org/maven2", repo.getUrl());
try {
repo = mojo.parseRepository("central::legacy::http://repo1.maven.apache.org/maven2", policy);
fail("Exception expected: legacy repository not supported anymore");
} catch (MojoFailureException e) {
}
repo = mojo.parseRepository("central::::http://repo1.maven.apache.org/maven2", policy);
assertEquals("central", repo.getId());
assertEquals(DefaultRepositoryLayout.class, repo.getLayout().getClass());
assertEquals("http://repo1.maven.apache.org/maven2", repo.getUrl());
repo = mojo.parseRepository("http://repo1.maven.apache.org/maven2", policy);
assertEquals("temp", repo.getId());
assertEquals(DefaultRepositoryLayout.class, repo.getLayout().getClass());
assertEquals("http://repo1.maven.apache.org/maven2", repo.getUrl());
try {
mojo.parseRepository("::::http://repo1.maven.apache.org/maven2", policy);
fail("Exception expected");
} catch (MojoFailureException e) {
// expected
}
try {
mojo.parseRepository("central::http://repo1.maven.apache.org/maven2", policy);
fail("Exception expected");
} catch (MojoFailureException e) {
// expected
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class DependencyFilesetsTask method execute.
/**
* {@inheritDoc}
*/
public void execute() {
if (this.getProject().getReference(mavenProjectId) == null) {
throw new BuildException("Maven project reference not found: " + mavenProjectId);
}
MavenProject mavenProject = (MavenProject) this.getProject().getReference("maven.project");
// Add filesets for depenedency artifacts
Set<Artifact> depArtifacts = filterArtifacts(mavenProject.getArtifacts());
FileSet dependenciesFileSet = new FileSet();
dependenciesFileSet.setProject(getProject());
ArtifactRepository localRepository = (ArtifactRepository) getProject().getReference("maven.local.repository");
dependenciesFileSet.setDir(new File(localRepository.getBasedir()));
if (depArtifacts.isEmpty()) {
// For performance reasons in case of huge local repo, tell Ant to include a single thing, otherwise the
// whole directory is scanned (even though ** is excluded).
dependenciesFileSet.createInclude().setName(".");
dependenciesFileSet.createExclude().setName("**");
}
for (Artifact artifact : depArtifacts) {
String relativeArtifactPath = localRepository.pathOf(artifact);
dependenciesFileSet.createInclude().setName(relativeArtifactPath);
String fileSetName = getPrefix() + artifact.getDependencyConflictId();
FileSet singleArtifactFileSet = new FileSet();
singleArtifactFileSet.setProject(getProject());
singleArtifactFileSet.setFile(artifact.getFile());
getProject().addReference(fileSetName, singleArtifactFileSet);
}
getProject().addReference((getPrefix() + projectDependenciesId), dependenciesFileSet);
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class DefaultRepositoryCopier method scanForArtifactPaths.
protected List<String> scanForArtifactPaths(ArtifactRepository repository) {
List<String> collected;
try {
Wagon wagon = wagonManager.getWagon(repository.getProtocol());
Repository artifactRepository = new Repository(repository.getId(), repository.getUrl());
wagon.connect(artifactRepository);
collected = new ArrayList<String>();
scan(wagon, "/", collected);
wagon.disconnect();
return collected;
} catch (UnsupportedProtocolException e) {
throw new RuntimeException(e);
} catch (ConnectionException e) {
throw new RuntimeException(e);
} catch (AuthenticationException e) {
throw new RuntimeException(e);
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class DeployMojoTest method testAltSnapshotDeploymentRepository.
public void testAltSnapshotDeploymentRepository() throws Exception {
DeployMojo mojo = spy(new DeployMojo());
ArtifactRepository repository = mock(ArtifactRepository.class);
when(mojo.createDeploymentArtifactRepository("altSnapshotDeploymentRepository", "http://localhost")).thenReturn(repository);
project.setVersion("1.0-SNAPSHOT");
ProjectDeployerRequest pdr = new ProjectDeployerRequest().setProject(project).setAltDeploymentRepository("altSnapshotDeploymentRepository::http://localhost");
assertEquals(repository, mojo.getDeploymentRepository(pdr));
}
Aggregations