Search in sources :

Example 41 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project maven-plugins by apache.

the class AbstractGpgMojo method newSigner.

AbstractGpgSigner newSigner(MavenProject project) throws MojoExecutionException, MojoFailureException {
    AbstractGpgSigner signer = new GpgSigner(executable);
    signer.setLog(getLog());
    signer.setInteractive(interactive);
    signer.setKeyName(keyname);
    signer.setUseAgent(useAgent);
    signer.setHomeDirectory(homedir);
    signer.setDefaultKeyring(defaultKeyring);
    signer.setSecretKeyring(secretKeyring);
    signer.setPublicKeyring(publicKeyring);
    signer.setLockMode(lockMode);
    signer.setArgs(gpgArguments);
    loadGpgPassphrase();
    signer.setPassPhrase(passphrase);
    if (null == passphrase && !useAgent) {
        if (!interactive) {
            throw new MojoFailureException("Cannot obtain passphrase in batch mode");
        }
        try {
            signer.setPassPhrase(signer.getPassphrase(project));
        } catch (IOException e) {
            throw new MojoExecutionException("Exception reading passphrase", e);
        }
    }
    return signer;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException)

Example 42 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException 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)

Example 43 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project maven-plugins by apache.

the class TestGetMojo method testParseRepository.

/**
     * Test parsing of the remote repositories parameter
     * 
     * @throws Exception
     */
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
    }
}
Also used : ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 44 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project maven-plugins by apache.

the class DeployMojo method getDeploymentRepository.

ArtifactRepository getDeploymentRepository(ProjectDeployerRequest pdr) throws MojoExecutionException, MojoFailureException {
    MavenProject project = pdr.getProject();
    String altDeploymentRepository = pdr.getAltDeploymentRepository();
    String altReleaseDeploymentRepository = pdr.getAltReleaseDeploymentRepository();
    String altSnapshotDeploymentRepository = pdr.getAltSnapshotDeploymentRepository();
    ArtifactRepository repo = null;
    String altDeploymentRepo;
    if (ArtifactUtils.isSnapshot(project.getVersion()) && altSnapshotDeploymentRepository != null) {
        altDeploymentRepo = altSnapshotDeploymentRepository;
    } else if (!ArtifactUtils.isSnapshot(project.getVersion()) && altReleaseDeploymentRepository != null) {
        altDeploymentRepo = altReleaseDeploymentRepository;
    } else {
        altDeploymentRepo = altDeploymentRepository;
    }
    if (altDeploymentRepo != null) {
        getLog().info("Using alternate deployment repository " + altDeploymentRepo);
        Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher(altDeploymentRepo);
        if (!matcher.matches()) {
            throw new MojoFailureException(altDeploymentRepo, "Invalid syntax for repository.", "Invalid syntax for alternative repository. Use \"id::url\".");
        } else {
            String id = matcher.group(1).trim();
            String url = matcher.group(2).trim();
            repo = createDeploymentArtifactRepository(id, url);
        }
    }
    if (repo == null) {
        repo = project.getDistributionManagementArtifactRepository();
    }
    if (repo == null) {
        String msg = "Deployment failed: repository element was not specified in the POM inside" + " distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter";
        throw new MojoExecutionException(msg);
    }
    return repo;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Matcher(java.util.regex.Matcher) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 45 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project maven-plugins by apache.

the class VerifyMojo method execute.

/**
     * Invokes Maven on the configured test projects.
     *
     * @throws org.apache.maven.plugin.MojoExecutionException If the goal encountered severe errors.
     * @throws org.apache.maven.plugin.MojoFailureException If any of the Maven builds failed.
     */
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skipInvocation) {
        getLog().info("Skipping invocation per configuration." + " If this is incorrect, ensure the skipInvocation parameter is not set to true.");
        return;
    }
    File[] reportFiles = ReportUtils.getReportFiles(reportsDirectory);
    if (reportFiles.length <= 0) {
        if (Boolean.TRUE.equals(failIfNoProjects)) {
            throw new MojoFailureException("No projects to invoke!");
        }
        getLog().info("No invoker report files found, nothing to check.");
        return;
    }
    InvokerSession invokerSession = new InvokerSession();
    for (File reportFile : reportFiles) {
        try {
            BuildJobXpp3Reader reader = new BuildJobXpp3Reader();
            invokerSession.addJob(reader.read(ReaderFactory.newXmlReader(reportFile)));
        } catch (XmlPullParserException e) {
            throw new MojoExecutionException("Failed to parse report file: " + reportFile, e);
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to read report file: " + reportFile, e);
        }
    }
    if (!suppressSummaries) {
        invokerSession.logSummary(getLog(), ignoreFailures);
    }
    invokerSession.handleFailures(getLog(), ignoreFailures);
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) BuildJobXpp3Reader(org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File)

Aggregations

MojoFailureException (org.apache.maven.plugin.MojoFailureException)157 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)94 File (java.io.File)93 IOException (java.io.IOException)91 ArrayList (java.util.ArrayList)50 TreeSet (java.util.TreeSet)33 FileInputStream (java.io.FileInputStream)32 FileOutputStream (java.io.FileOutputStream)21 List (java.util.List)21 Map (java.util.Map)21 MavenProject (org.apache.maven.project.MavenProject)18 Set (java.util.Set)15 MalformedURLException (java.net.MalformedURLException)14 HashMap (java.util.HashMap)13 HashSet (java.util.HashSet)13 InputStream (java.io.InputStream)12 URLClassLoader (java.net.URLClassLoader)12 Matcher (java.util.regex.Matcher)12 Artifact (org.apache.maven.artifact.Artifact)12 AbstractMojo (org.apache.maven.plugin.AbstractMojo)12