use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project indy by Commonjava.
the class ArchetypeCatalogMerger method merge.
@Override
public byte[] merge(final Collection<Transfer> sources, final Group group, final String path) {
final ArchetypeCatalog master = new ArchetypeCatalog();
final ArchetypeCatalogXpp3Reader reader = new ArchetypeCatalogXpp3Reader();
final FileReader fr = null;
InputStream stream = null;
boolean merged = false;
final Set<String> seen = new HashSet<String>();
for (final Transfer src : sources) {
try {
stream = src.openInputStream();
final ArchetypeCatalog catalog = reader.read(stream, false);
for (final Archetype arch : catalog.getArchetypes()) {
final String key = arch.getGroupId() + ":" + arch.getArtifactId() + ":" + arch.getVersion();
if (seen.add(key)) {
master.addArchetype(arch);
}
}
merged = true;
} catch (final IOException e) {
final StoreKey key = getKey(src);
logger.error(String.format("Cannot read archetype catalog: %s from artifact-store: %s. Reason: %s", src.getPath(), key, e.getMessage()), e);
} catch (final XmlPullParserException e) {
final StoreKey key = getKey(src);
logger.error(String.format("Cannot parse archetype catalog: %s from artifact-store: %s. Reason: %s", src.getPath(), key, e.getMessage()), e);
} finally {
closeQuietly(fr);
}
}
if (merged) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
new ArchetypeCatalogXpp3Writer().write(baos, master);
return baos.toByteArray();
} catch (final IOException e) {
logger.error(String.format("Cannot write consolidated archetype catalog: %s to: %s. Reason: %s", path, group.getKey(), e.getMessage()), e);
}
}
return null;
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project indy by Commonjava.
the class MavenMetadataMerger method merge.
@Override
public byte[] merge(final Collection<Transfer> sources, final Group group, final String path) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Generating merged metadata in: {}:{}", group.getKey(), path);
final Metadata master = new Metadata();
master.setVersioning(new Versioning());
final MetadataXpp3Reader reader = new MetadataXpp3Reader();
final FileReader fr = null;
InputStream stream = null;
boolean merged = false;
Transfer snapshotProvider = null;
for (final Transfer src : sources) {
if (!src.exists()) {
continue;
}
try {
stream = src.openInputStream();
String content = IOUtils.toString(stream);
logger.debug("Adding in metadata content from: {}\n\n{}\n\n", src, content);
// there is a lot of junk in here to make up for Metadata's anemic merge() method.
final Metadata md = reader.read(new StringReader(content), false);
if (md.getGroupId() != null) {
master.setGroupId(md.getGroupId());
}
if (md.getArtifactId() != null) {
master.setArtifactId(md.getArtifactId());
}
if (md.getVersion() != null) {
master.setVersion(md.getVersion());
}
master.merge(md);
Versioning versioning = master.getVersioning();
Versioning mdVersioning = md.getVersioning();
// FIXME: Should we try to merge snapshot lists instead of using the first one we encounter??
if (versioning.getSnapshot() == null && mdVersioning != null) {
logger.info("INCLUDING snapshot information from: {} in: {}:{}", src, group.getKey(), path);
snapshotProvider = src;
versioning.setSnapshot(mdVersioning.getSnapshot());
final List<SnapshotVersion> snapshotVersions = versioning.getSnapshotVersions();
boolean added = false;
for (final SnapshotVersion snap : mdVersioning.getSnapshotVersions()) {
if (!snapshotVersions.contains(snap)) {
snapshotVersions.add(snap);
added = true;
}
}
if (added) {
Collections.sort(snapshotVersions, new SnapshotVersionComparator());
}
} else {
logger.warn("SKIPPING snapshot information from: {} in: {}:{} (obscured by: {})", src, group.getKey(), path, snapshotProvider);
}
merged = true;
} catch (final IOException e) {
final StoreKey key = getKey(src);
logger.error(String.format("Cannot read metadata: %s from artifact-store: %s. Reason: %s", src.getPath(), key, e.getMessage()), e);
} catch (final XmlPullParserException e) {
final StoreKey key = getKey(src);
logger.error(String.format("Cannot parse metadata: %s from artifact-store: %s. Reason: %s", src.getPath(), key, e.getMessage()), e);
} finally {
closeQuietly(fr);
closeQuietly(stream);
}
}
Versioning versioning = master.getVersioning();
if (versioning != null && versioning.getVersions() != null) {
if (metadataProviders != null) {
for (MavenMetadataProvider provider : metadataProviders) {
try {
Metadata toMerge = provider.getMetadata(group.getKey(), path);
if (toMerge != null) {
merged = master.merge(toMerge) || merged;
}
} catch (IndyWorkflowException e) {
logger.error(String.format("Cannot read metadata: %s from metadata provider: %s. Reason: %s", path, provider.getClass().getSimpleName(), e.getMessage()), e);
}
}
}
List<SingleVersion> versionObjects = versioning.getVersions().stream().map(VersionUtils::createSingleVersion).collect(Collectors.toList());
Collections.sort(versionObjects);
versioning.setVersions(versionObjects.stream().map(SingleVersion::renderStandard).collect(Collectors.toList()));
if (versionObjects.size() > 0) {
String latest = versionObjects.get(versionObjects.size() - 1).renderStandard();
versioning.setLatest(latest);
versioning.setRelease(latest);
}
}
if (merged) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
new MetadataXpp3Writer().write(baos, master);
return baos.toByteArray();
} catch (final IOException e) {
logger.error(String.format("Cannot write consolidated metadata: %s to: %s. Reason: %s", path, group.getKey(), e.getMessage()), e);
}
}
return null;
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project asterixdb by apache.
the class SupplementalModelHelper method getSupplement.
protected static Model getSupplement(Log log, Xpp3Dom supplementModelXml) throws MojoExecutionException {
MavenXpp3Reader modelReader = new MavenXpp3Reader();
Model model = null;
try {
model = modelReader.read(new StringReader(supplementModelXml.toString()));
String groupId = model.getGroupId();
String artifactId = model.getArtifactId();
if (groupId == null || "".equals(groupId.trim())) {
throw new MojoExecutionException("Supplemental project XML requires that a <groupId> element be present.");
}
if (artifactId == null || "".equals(artifactId.trim())) {
throw new MojoExecutionException("Supplemental project XML requires that a <artifactId> element be present.");
}
} catch (IOException e) {
log.warn("Unable to read supplemental XML: " + e.getMessage(), e);
} catch (XmlPullParserException e) {
log.warn("Unable to parse supplemental XML: " + e.getMessage(), e);
}
return model;
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project maven-plugins by apache.
the class ResourceResolver method resolveBundleFromProject.
private static List<JavadocBundle> resolveBundleFromProject(SourceResolverConfig config, MavenProject project, Artifact artifact) throws IOException {
List<JavadocBundle> bundles = new ArrayList<JavadocBundle>();
List<String> classifiers = new ArrayList<String>();
if (config.includeCompileSources()) {
classifiers.add(AbstractJavadocMojo.JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER);
}
if (config.includeTestSources()) {
classifiers.add(AbstractJavadocMojo.TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER);
}
for (String classifier : classifiers) {
File optionsFile = new File(project.getBuild().getDirectory(), "javadoc-bundle-options/javadoc-options-" + classifier + ".xml");
if (!optionsFile.exists()) {
continue;
}
FileInputStream stream = null;
try {
stream = new FileInputStream(optionsFile);
JavadocOptions options = new JavadocOptionsXpp3Reader().read(stream);
stream.close();
stream = null;
bundles.add(new JavadocBundle(options, new File(project.getBasedir(), options.getJavadocResourcesDirectory())));
} catch (XmlPullParserException e) {
IOException error = new IOException("Failed to read javadoc options from: " + optionsFile + "\nReason: " + e.getMessage());
error.initCause(e);
throw error;
} finally {
close(stream);
}
}
return bundles;
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project maven-plugins by apache.
the class InstallFileMojo method readModel.
/**
* Parses a POM.
*
* @param pomFile The path of the POM file to parse, must not be <code>null</code>.
* @return The model from the POM file, never <code>null</code>.
* @throws MojoExecutionException If the POM could not be parsed.
*/
private Model readModel(File pomFile) throws MojoExecutionException {
Reader reader = null;
try {
reader = ReaderFactory.newXmlReader(pomFile);
final Model model = new MavenXpp3Reader().read(reader);
reader.close();
reader = null;
return model;
} catch (FileNotFoundException e) {
throw new MojoExecutionException("File not found " + pomFile, e);
} catch (IOException e) {
throw new MojoExecutionException("Error reading POM " + pomFile, e);
} catch (XmlPullParserException e) {
throw new MojoExecutionException("Error parsing POM " + pomFile, e);
} finally {
IOUtil.close(reader);
}
}
Aggregations