Search in sources :

Example 76 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class CompilerMojoTestCase method getTestCompilerMojo.

private TestCompilerMojo getTestCompilerMojo(CompilerMojo compilerMojo, String pomXml) throws Exception {
    File testPom = new File(getBasedir(), pomXml);
    TestCompilerMojo mojo = (TestCompilerMojo) lookupMojo("testCompile", testPom);
    setVariableValueToObject(mojo, "log", new DebugEnabledLog());
    File buildDir = (File) getVariableValueFromObject(compilerMojo, "buildDirectory");
    File testClassesDir = new File(buildDir, "test-classes");
    setVariableValueToObject(mojo, "outputDirectory", testClassesDir);
    List<String> testClasspathList = new ArrayList<String>();
    Artifact junitArtifact = mock(Artifact.class);
    ArtifactHandler handler = mock(ArtifactHandler.class);
    when(handler.isAddedToClasspath()).thenReturn(true);
    when(junitArtifact.getArtifactHandler()).thenReturn(handler);
    File artifactFile;
    String localRepository = System.getProperty("localRepository");
    if (localRepository != null) {
        artifactFile = new File(localRepository, "junit/junit/3.8.1/junit-3.8.1.jar");
    } else {
        // for IDE
        String junitURI = org.junit.Test.class.getResource("Test.class").toURI().toString();
        junitURI = junitURI.substring("jar:".length(), junitURI.indexOf('!'));
        artifactFile = new File(URI.create(junitURI));
    }
    when(junitArtifact.getFile()).thenReturn(artifactFile);
    testClasspathList.add(artifactFile.getAbsolutePath());
    testClasspathList.add(compilerMojo.getOutputDirectory().getPath());
    String testSourceRoot = testPom.getParent() + "/src/test/java";
    setVariableValueToObject(mojo, "compileSourceRoots", Collections.singletonList(testSourceRoot));
    MavenProject project = getMockMavenProject();
    project.setArtifacts(Collections.singleton(junitArtifact));
    project.getBuild().setOutputDirectory(new File(buildDir, "classes").getAbsolutePath());
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "compilePath", Collections.EMPTY_LIST);
    setVariableValueToObject(mojo, "testPath", testClasspathList);
    setVariableValueToObject(mojo, "session", getMockMavenSession());
    setVariableValueToObject(mojo, "mojoExecution", getMockMojoExecution());
    setVariableValueToObject(mojo, "source", source);
    setVariableValueToObject(mojo, "target", target);
    return mojo;
}
Also used : DebugEnabledLog(org.apache.maven.plugin.compiler.stubs.DebugEnabledLog) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 77 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class AbstractEarTestBase method createArtifacts.

protected Set<Artifact> createArtifacts(String[] artifactsId, String[] types, String[] groupsId, String[] classifiers) {
    Set<Artifact> result = new TreeSet<Artifact>();
    if (artifactsId == null || artifactsId.length == 0) {
        return result;
    }
    for (int i = 0; i < artifactsId.length; i++) {
        String artifactId = artifactsId[i];
        String type = getData(types, i, DEFAULT_TYPE);
        String groupId = getData(groupsId, i, DEFAULT_GROUPID);
        String classifier = getData(classifiers, i, null);
        result.add(new ArtifactTestStub(groupId, artifactId, type, classifier));
    }
    return result;
}
Also used : ArtifactTestStub(org.apache.maven.plugins.ear.stub.ArtifactTestStub) TreeSet(java.util.TreeSet) Artifact(org.apache.maven.artifact.Artifact)

Example 78 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class ModuleIdentifierValidatorTest method createMockEarModule.

private EarModule createMockEarModule(String groupId, String artifactId, String classifier, String version) {
    EarModule earModule = mock(EarModule.class);
    Artifact artifact = mock(Artifact.class);
    when(earModule.getArtifact()).thenReturn(artifact);
    when(earModule.getArtifact().getGroupId()).thenReturn(groupId);
    when(earModule.getArtifact().getArtifactId()).thenReturn(artifactId);
    when(earModule.getArtifact().getClassifier()).thenReturn(classifier);
    when(earModule.getArtifact().getVersion()).thenReturn(version);
    when(earModule.getArtifact().getId()).thenReturn(groupId + ":" + artifactId + ":" + classifier + ":" + version);
    return earModule;
}
Also used : EarModule(org.apache.maven.plugins.ear.EarModule) Artifact(org.apache.maven.artifact.Artifact)

Example 79 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class TestAbstractFileNameMapping method test.

@Test
public void test() {
    ArtifactHandler handler = mock(ArtifactHandler.class);
    when(handler.getExtension()).thenReturn("jar");
    Artifact artifact = mock(Artifact.class);
    when(artifact.getArtifactHandler()).thenReturn(handler);
    when(artifact.getArtifactId()).thenReturn("mear149");
    when(artifact.getVersion()).thenReturn("1.0-SNAPSHOT");
    when(artifact.getBaseVersion()).thenReturn("1.0-20130423.042904");
    // default behavior: use -SNAPSHOT
    assertEquals("mear149-1.0-SNAPSHOT.jar", abstractFileNameMapping.generateFileName(artifact, true));
    abstractFileNameMapping.setUseBaseVersion(true);
    assertEquals("mear149-1.0-20130423.042904.jar", abstractFileNameMapping.generateFileName(artifact, true));
    abstractFileNameMapping.setUseBaseVersion(false);
    assertEquals("mear149-1.0-SNAPSHOT.jar", abstractFileNameMapping.generateFileName(artifact, true));
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) Artifact(org.apache.maven.artifact.Artifact) Test(org.junit.Test)

Example 80 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class GpgSignAttachedMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        // We're skipping the signing stuff
        return;
    }
    if (excludes == null || excludes.length == 0) {
        excludes = DEFAULT_EXCLUDES;
    }
    String[] newExcludes = new String[excludes.length];
    for (int i = 0; i < excludes.length; i++) {
        String pattern;
        pattern = excludes[i].trim().replace('/', File.separatorChar).replace('\\', File.separatorChar);
        if (pattern.endsWith(File.separator)) {
            pattern += "**";
        }
        newExcludes[i] = pattern;
    }
    excludes = newExcludes;
    AbstractGpgSigner signer = newSigner(project);
    // ----------------------------------------------------------------------------
    // What we need to generateSignatureForArtifact here
    // ----------------------------------------------------------------------------
    signer.setOutputDirectory(ascDirectory);
    signer.setBuildDirectory(new File(project.getBuild().getDirectory()));
    signer.setBaseDirectory(project.getBasedir());
    List signingBundles = new ArrayList();
    if (!"pom".equals(project.getPackaging())) {
        // ----------------------------------------------------------------------------
        // Project artifact
        // ----------------------------------------------------------------------------
        Artifact artifact = project.getArtifact();
        File file = artifact.getFile();
        if (file != null && file.isFile()) {
            getLog().debug("Generating signature for " + file);
            File projectArtifactSignature = signer.generateSignatureForArtifact(file);
            if (projectArtifactSignature != null) {
                signingBundles.add(new SigningBundle(artifact.getArtifactHandler().getExtension(), projectArtifactSignature));
            }
        } else if (project.getAttachedArtifacts().isEmpty()) {
            throw new MojoFailureException("The project artifact has not been assembled yet. " + "Please do not invoke this goal before the lifecycle phase \"package\".");
        } else {
            getLog().debug("Main artifact not assembled, skipping signature generation");
        }
    }
    // ----------------------------------------------------------------------------
    // POM
    // ----------------------------------------------------------------------------
    File pomToSign = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".pom");
    try {
        FileUtils.copyFile(project.getFile(), pomToSign);
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying POM for signing.", e);
    }
    getLog().debug("Generating signature for " + pomToSign);
    File pomSignature = signer.generateSignatureForArtifact(pomToSign);
    if (pomSignature != null) {
        signingBundles.add(new SigningBundle("pom", pomSignature));
    }
    for (Object o : project.getAttachedArtifacts()) {
        Artifact artifact = (Artifact) o;
        File file = artifact.getFile();
        getLog().debug("Generating signature for " + file);
        File signature = signer.generateSignatureForArtifact(file);
        if (signature != null) {
            signingBundles.add(new SigningBundle(artifact.getArtifactHandler().getExtension(), artifact.getClassifier(), signature));
        }
    }
    for (Object signingBundle : signingBundles) {
        SigningBundle bundle = (SigningBundle) signingBundle;
        projectHelper.attachArtifact(project, bundle.getExtension() + GpgSigner.SIGNATURE_EXTENSION, bundle.getClassifier(), bundle.getSignature());
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) Artifact(org.apache.maven.artifact.Artifact) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)450 File (java.io.File)175 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)92 ArrayList (java.util.ArrayList)91 MavenProject (org.apache.maven.project.MavenProject)63 IOException (java.io.IOException)50 HashSet (java.util.HashSet)42 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)32 LinkedHashSet (java.util.LinkedHashSet)29 MojoFailureException (org.apache.maven.plugin.MojoFailureException)24 HashMap (java.util.HashMap)22 Set (java.util.Set)22 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)22 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)21 URL (java.net.URL)20 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)20 Test (org.junit.Test)20 MalformedURLException (java.net.MalformedURLException)18 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)17 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)16