Search in sources :

Example 1 with ArtifactHandlerManager

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;
}
Also used : ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) DefaultArtifactFactory(org.apache.maven.artifact.factory.DefaultArtifactFactory) DefaultArtifactFactory(org.apache.maven.artifact.factory.DefaultArtifactFactory) HashMap(java.util.HashMap) ArtifactHandlerManager(org.apache.maven.artifact.handler.manager.ArtifactHandlerManager) DefaultArtifactHandlerManager(org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager) DefaultArtifactHandlerManager(org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager)

Example 2 with ArtifactHandlerManager

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);
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProject(org.apache.maven.project.MavenProject) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) ArtifactHandlerManager(org.apache.maven.artifact.handler.manager.ArtifactHandlerManager) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 3 with ArtifactHandlerManager

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);
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProject(org.apache.maven.project.MavenProject) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) ArtifactHandlerManager(org.apache.maven.artifact.handler.manager.ArtifactHandlerManager) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 4 with ArtifactHandlerManager

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;
}
Also used : Path(java.nio.file.Path) ArchiverManager(org.codehaus.plexus.archiver.manager.ArchiverManager) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) MavenSession(org.apache.maven.execution.MavenSession) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MavenProject(org.apache.maven.project.MavenProject) Build(org.apache.maven.model.Build) ArtifactHandlerManager(org.apache.maven.artifact.handler.manager.ArtifactHandlerManager) JarFile(java.util.jar.JarFile) File(java.io.File) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) HashSet(java.util.HashSet)

Aggregations

ArtifactHandlerManager (org.apache.maven.artifact.handler.manager.ArtifactHandlerManager)4 File (java.io.File)3 MavenSession (org.apache.maven.execution.MavenSession)3 MavenProject (org.apache.maven.project.MavenProject)3 Artifact (org.apache.maven.artifact.Artifact)2 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)2 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)2 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 JarFile (java.util.jar.JarFile)1 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)1 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)1 DefaultArtifactFactory (org.apache.maven.artifact.factory.DefaultArtifactFactory)1 ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)1 DefaultArtifactHandlerManager (org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager)1 ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)1 Build (org.apache.maven.model.Build)1 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)1 ArchiverManager (org.codehaus.plexus.archiver.manager.ArchiverManager)1