use of org.apache.maven.archetype.catalog.ArchetypeCatalog in project maven-archetype by apache.
the class LocalCatalogArchetypeDataSource method getArchetypeCatalog.
public ArchetypeCatalog getArchetypeCatalog(ProjectBuildingRequest buildingRequest) throws ArchetypeDataSourceException {
File localRepo = repositoryManager.getLocalRepositoryBasedir(buildingRequest);
File catalogFile = new File(localRepo, ARCHETYPE_CATALOG_FILENAME);
if (catalogFile.exists() && catalogFile.isDirectory()) {
catalogFile = new File(catalogFile, ARCHETYPE_CATALOG_FILENAME);
}
getLogger().debug("Using catalog " + catalogFile);
if (catalogFile.exists()) {
try {
return readCatalog(ReaderFactory.newXmlReader(catalogFile));
} catch (FileNotFoundException e) {
throw new ArchetypeDataSourceException("The specific archetype catalog does not exist.", e);
} catch (IOException e) {
throw new ArchetypeDataSourceException("Error reading archetype catalog.", e);
}
} else {
return new ArchetypeCatalog();
}
}
use of org.apache.maven.archetype.catalog.ArchetypeCatalog in project indy by Commonjava.
the class ArchetypeCatalogMerger method merge.
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;
boolean merged = false;
final Set<String> seen = new HashSet<String>();
for (final Transfer src : sources) {
try (InputStream 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