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;
}
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());
}
}
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
}
}
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;
}
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);
}
Aggregations