use of org.apache.maven.artifact.handler.manager.ArtifactHandlerManager in project maven-plugins by apache.
the class DependencyTestUtils method getArtifactFactory.
public static ArtifactFactory getArtifactFactory() throws IllegalAccessException {
ArtifactFactory artifactFactory;
ArtifactHandlerManager manager = new DefaultArtifactHandlerManager();
setVariableValueToObject(manager, "artifactHandlers", new HashMap());
artifactFactory = new DefaultArtifactFactory();
setVariableValueToObject(artifactFactory, "artifactHandlerManager", manager);
return artifactFactory;
}
use of org.apache.maven.artifact.handler.manager.ArtifactHandlerManager in project maven-plugins by apache.
the class TestCopyDependenciesMojo method setUp.
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("copy-dependencies", true, false);
File testPom = new File(getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml");
mojo = (CopyDependenciesMojo) lookupMojo("copy-dependencies", testPom);
mojo.outputDirectory = new File(this.testDir, "outputDirectory");
// mojo.silent = true;
assertNotNull(mojo);
assertNotNull(mojo.getProject());
MavenProject project = mojo.getProject();
MavenSession session = newMavenSession(project);
setVariableValueToObject(mojo, "session", session);
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
artifacts.addAll(directArtifacts);
project.setArtifacts(artifacts);
project.setDependencyArtifacts(directArtifacts);
mojo.markersDirectory = new File(this.testDir, "markers");
ArtifactHandlerManager manager = lookup(ArtifactHandlerManager.class);
setVariableValueToObject(mojo, "artifactHandlerManager", manager);
}
use of org.apache.maven.artifact.handler.manager.ArtifactHandlerManager in project maven-plugins by apache.
the class TestUnpackDependenciesMojo method setUp.
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("unpack-dependencies", true, false);
File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-dependencies-test/plugin-config.xml");
mojo = (UnpackDependenciesMojo) lookupMojo("unpack-dependencies", testPom);
mojo.outputDirectory = new File(this.testDir, "outputDirectory");
mojo.setUseJvmChmod(true);
// mojo.silent = true;
// it needs to get the archivermanager
stubFactory.setUnpackableFile(mojo.getArchiverManager());
// i'm using one file repeatedly to archive so I can test the name
// programmatically.
stubFactory.setSrcFile(new File(getBasedir() + File.separatorChar + UNPACKABLE_FILE_PATH));
assertNotNull(mojo);
assertNotNull(mojo.getProject());
MavenProject project = mojo.getProject();
MavenSession session = newMavenSession(project);
setVariableValueToObject(mojo, "session", session);
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
artifacts.addAll(directArtifacts);
project.setArtifacts(artifacts);
project.setDependencyArtifacts(directArtifacts);
mojo.markersDirectory = new File(this.testDir, "markers");
ArtifactHandlerManager manager = lookup(ArtifactHandlerManager.class);
setVariableValueToObject(mojo, "artifactHandlerManager", manager);
}
use of org.apache.maven.artifact.handler.manager.ArtifactHandlerManager in project sling by apache.
the class PreparePackageMojoTest method getMojoUnderTest.
private PreparePackageMojo getMojoUnderTest(String... knownArtifacts) throws Exception {
File mrr = getMavenRepoRoot();
ArtifactHandler ah = Mockito.mock(ArtifactHandler.class);
ArtifactHandlerManager ahm = Mockito.mock(ArtifactHandlerManager.class);
Mockito.when(ahm.getArtifactHandler(Mockito.anyString())).thenReturn(ah);
Set<org.apache.maven.artifact.Artifact> artifacts = new HashSet<>();
for (String s : knownArtifacts) {
String[] parts = s.split("[/]");
switch(parts.length) {
case 3:
artifacts.add(getMavenArtifact(mrr, ah, parts[0], parts[1], parts[2]));
break;
case 4:
artifacts.add(getMavenArtifact(mrr, ah, parts[0], parts[1], parts[2], parts[3]));
break;
default:
throw new IllegalStateException(s);
}
}
MavenProject mavenPrj = new MavenProject();
Build build = new Build();
Path tempDir = Files.createTempDirectory(getClass().getSimpleName());
build.setOutputDirectory(tempDir.toString());
build.setDirectory(tempDir.toString());
mavenPrj.setBuild(build);
mavenPrj.setDependencyArtifacts(artifacts);
PreparePackageMojo ppm = new PreparePackageMojo();
ppm.mavenSession = Mockito.mock(MavenSession.class);
ppm.project = mavenPrj;
ArchiverManager am = Mockito.mock(ArchiverManager.class);
UnArchiver ua = Mockito.mock(UnArchiver.class);
Mockito.when(am.getUnArchiver(Mockito.isA(File.class))).thenReturn(ua);
setPrivateField(ppm, "archiverManager", am);
setPrivateField(ppm, "artifactHandlerManager", ahm);
setPrivateField(ppm, "resolver", Mockito.mock(ArtifactResolver.class));
return ppm;
}
Aggregations