use of org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Reader 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;
}
Aggregations