use of aQute.bnd.osgi.repository.XMLResourceGenerator in project bnd by bndtools.
the class LocalIndexerMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
logger.debug("skip project as configured");
return;
}
if (baseFile == null) {
baseFile = outputFile.getParentFile();
}
logger.debug("Indexing dependencies in folder: {}", inputDir.getAbsolutePath());
logger.debug("Outputting index to: {}", outputFile.getAbsolutePath());
logger.debug("Producing additional gzip index: {}", includeGzip);
logger.debug("URI paths will be relative to: {}", baseFile);
Set<File> toIndex = new HashSet<>();
toIndex.addAll(asList(inputDir.listFiles()));
BaseFileURLResolver baseFileURLResolver = new BaseFileURLResolver();
ResourcesRepository resourcesRepository = new ResourcesRepository();
XMLResourceGenerator xmlResourceGenerator = new XMLResourceGenerator();
for (File file : toIndex) {
ResourceBuilder resourceBuilder = new ResourceBuilder();
try {
resourceBuilder.addFile(file, baseFileURLResolver.resolver(file));
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
}
resourcesRepository.add(resourceBuilder.build());
}
try {
IO.mkdirs(outputFile.getParentFile());
xmlResourceGenerator.repository(resourcesRepository).save(outputFile);
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
}
if (fail) {
throw new MojoExecutionException("One or more URI lookups failed");
}
if (includeGzip) {
File gzipOutputFile = new File(outputFile.getPath() + ".gz");
try {
xmlResourceGenerator.save(gzipOutputFile);
} catch (Exception e) {
throw new MojoExecutionException("Unable to create the gzipped output file");
}
}
}
Aggregations