use of org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException in project maven-plugins by apache.
the class DoapMojo method writeReleases.
/**
* Write all DOAP releases.
*
* @param writer not null
* @param project the Maven project, not null
* @throws MojoExecutionException if any
* @see <a href="http://usefulinc.com/ns/doap#release">http://usefulinc.com/ns/doap#release</a>
* @see <a href="http://usefulinc.com/ns/doap#Version">http://usefulinc.com/ns/doap#Version</a>
*/
private void writeReleases(XMLWriter writer, MavenProject project) throws MojoExecutionException {
Artifact artifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), null, project.getPackaging());
RepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact);
for (ArtifactRepository repo : remoteRepositories) {
if (repo.isBlacklisted()) {
continue;
}
if (repo.getSnapshots().isEnabled()) {
continue;
}
if (repo.getReleases().isEnabled()) {
try {
repositoryMetadataManager.resolveAlways(metadata, localRepository, repo);
break;
} catch (RepositoryMetadataResolutionException e) {
throw new MojoExecutionException(metadata.extendedToString() + " could not be retrieved from repositories due to an error: " + e.getMessage(), e);
}
}
}
if (metadata.getMetadata().getVersioning() == null) {
messages.getWarnMessages().add("No versioning was found for " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ". Ignored DOAP <release/> tag.");
return;
}
List<String> versions = metadata.getMetadata().getVersioning().getVersions();
// Recent releases in first
Collections.reverse(versions);
boolean addComment = false;
int i = 0;
for (String version : versions) {
if (!addComment) {
DoapUtil.writeComment(writer, "Project releases.");
addComment = true;
}
DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "release");
DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "Version");
DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "name");
if (version.equals(metadata.getMetadata().getVersioning().getRelease())) {
writer.writeText("Latest stable release");
} else {
writer.writeText(project.getName() + " - " + version);
}
// name
writer.endElement();
DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(), "revision", version);
// list all file release from all remote repos
for (ArtifactRepository repo : remoteRepositories) {
Artifact artifactRelease = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), version, null, project.getPackaging());
if (artifactRelease == null) {
continue;
}
String fileRelease = repo.getUrl() + "/" + repo.pathOf(artifactRelease);
try {
DoapUtil.fetchURL(settings, new URL(fileRelease));
} catch (IOException e) {
getLog().debug("IOException :" + e.getMessage());
continue;
}
DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(), "file-release", fileRelease);
Date releaseDate = null;
try {
releaseDate = REPOSITORY_DATE_FORMAT.parse(metadata.getMetadata().getVersioning().getLastUpdated());
} catch (ParseException e) {
getLog().error("Unable to parse date '" + metadata.getMetadata().getVersioning().getLastUpdated() + "'");
continue;
}
// See MDOAP-11
if (i == 0) {
DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(), "created", DOAP_DATE_FORMAT.format(releaseDate));
}
}
// Version
writer.endElement();
// release
writer.endElement();
i++;
}
}
Aggregations