use of org.apache.maven.artifact.metadata.ArtifactMetadata in project maven-plugins by apache.
the class SignAndDeployFileMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
AbstractGpgSigner signer = newSigner(null);
signer.setOutputDirectory(ascDirectory);
signer.setBaseDirectory(new File("").getAbsoluteFile());
if (offline) {
throw new MojoFailureException("Cannot deploy artifacts when Maven is in offline mode");
}
initProperties();
validateArtifactInformation();
if (!file.exists()) {
throw new MojoFailureException(file.getPath() + " not found.");
}
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get(repositoryLayout);
if (layout == null) {
throw new MojoFailureException("Invalid repository layout: " + repositoryLayout);
}
ArtifactRepository deploymentRepository = repositoryFactory.createDeploymentArtifactRepository(repositoryId, url, layout, uniqueVersion);
if (StringUtils.isEmpty(deploymentRepository.getProtocol())) {
throw new MojoFailureException("No transfer protocol found.");
}
Artifact artifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging, classifier);
if (file.equals(getLocalRepoFile(artifact))) {
throw new MojoFailureException("Cannot deploy artifact from the local repository: " + file);
}
File fileSig = signer.generateSignatureForArtifact(file);
ArtifactMetadata metadata = new AscArtifactMetadata(artifact, fileSig, false);
artifact.addMetadata(metadata);
if (!"pom".equals(packaging)) {
if (pomFile == null && generatePom) {
pomFile = generatePomFile();
}
if (pomFile != null) {
metadata = new ProjectArtifactMetadata(artifact, pomFile);
artifact.addMetadata(metadata);
fileSig = signer.generateSignatureForArtifact(pomFile);
metadata = new AscArtifactMetadata(artifact, fileSig, true);
artifact.addMetadata(metadata);
}
}
if (updateReleaseInfo) {
artifact.setRelease(true);
}
project.setArtifact(artifact);
try {
deploy(file, artifact, deploymentRepository, localRepository);
} catch (ArtifactDeploymentException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
if (sources != null) {
projectHelper.attachArtifact(project, "jar", "sources", sources);
}
if (javadoc != null) {
projectHelper.attachArtifact(project, "jar", "javadoc", javadoc);
}
if (files != null) {
if (types == null) {
throw new MojoExecutionException("You must specify 'types' if you specify 'files'");
}
if (classifiers == null) {
throw new MojoExecutionException("You must specify 'classifiers' if you specify 'files'");
}
int filesLength = StringUtils.countMatches(files, ",");
int typesLength = StringUtils.countMatches(types, ",");
int classifiersLength = StringUtils.countMatches(classifiers, ",");
if (typesLength != filesLength) {
throw new MojoExecutionException("You must specify the same number of entries in 'files' and " + "'types' (respectively " + filesLength + " and " + typesLength + " entries )");
}
if (classifiersLength != filesLength) {
throw new MojoExecutionException("You must specify the same number of entries in 'files' and " + "'classifiers' (respectively " + filesLength + " and " + classifiersLength + " entries )");
}
int fi = 0;
int ti = 0;
int ci = 0;
for (int i = 0; i <= filesLength; i++) {
int nfi = files.indexOf(',', fi);
if (nfi == -1) {
nfi = files.length();
}
int nti = types.indexOf(',', ti);
if (nti == -1) {
nti = types.length();
}
int nci = classifiers.indexOf(',', ci);
if (nci == -1) {
nci = classifiers.length();
}
File file = new File(files.substring(fi, nfi));
if (!file.isFile()) {
// try relative to the project basedir just in case
file = new File(project.getBasedir(), files.substring(fi, nfi));
}
if (file.isFile()) {
if (StringUtils.isWhitespace(classifiers.substring(ci, nci))) {
projectHelper.attachArtifact(project, types.substring(ti, nti).trim(), file);
} else {
projectHelper.attachArtifact(project, types.substring(ti, nti).trim(), classifiers.substring(ci, nci).trim(), file);
}
} else {
throw new MojoExecutionException("Specified side artifact " + file + " does not exist");
}
fi = nfi + 1;
ti = nti + 1;
ci = nci + 1;
}
} else {
if (types != null) {
throw new MojoExecutionException("You must specify 'files' if you specify 'types'");
}
if (classifiers != null) {
throw new MojoExecutionException("You must specify 'files' if you specify 'classifiers'");
}
}
List attachedArtifacts = project.getAttachedArtifacts();
for (Object attachedArtifact : attachedArtifacts) {
Artifact attached = (Artifact) attachedArtifact;
fileSig = signer.generateSignatureForArtifact(attached.getFile());
attached = new AttachedSignedArtifact(attached, new AscArtifactMetadata(attached, fileSig, false));
try {
deploy(attached.getFile(), attached, deploymentRepository, localRepository);
} catch (ArtifactDeploymentException e) {
throw new MojoExecutionException("Error deploying attached artifact " + attached.getFile() + ": " + e.getMessage(), e);
}
}
}
use of org.apache.maven.artifact.metadata.ArtifactMetadata in project maven-plugins by apache.
the class AttachedSignedArtifact method getMetadataList.
public Collection<ArtifactMetadata> getMetadataList() {
List<ArtifactMetadata> result = new ArrayList<ArtifactMetadata>(delegate.getMetadataList());
boolean alreadySigned = false;
for (Iterator i = result.iterator(); i.hasNext() && !alreadySigned; ) {
ArtifactMetadata metadata = (ArtifactMetadata) i.next();
alreadySigned = signature.getKey().equals(metadata.getKey());
}
if (!alreadySigned) {
result.add(signature);
}
return result;
}
Aggregations