Search in sources :

Example 11 with ResourcesRepository

use of aQute.bnd.osgi.repository.ResourcesRepository in project bnd by bndtools.

the class ReleasePluginImpl method createIndex.

private ResourcesRepository createIndex(List<IPom> releasedArtifacts, IMavenRepo storage, String prefix) throws Exception {
    ResourcesRepository repo = new ResourcesRepository();
    for (IPom pom : releasedArtifacts) {
        try {
            System.out.println("Indexing " + pom);
            Promise<File> promise = storage.get(pom.binaryArchive());
            File file = promise.getValue();
            ResourceBuilder rb = new ResourceBuilder();
            String uri = prefix + pom.binaryArchive().remotePath;
            rb.addFile(file, new URI(uri));
            repo.add(rb.build());
        } catch (Exception e) {
            indexProject.exception(e, "Failed to index artifact %s", pom.binaryArchive());
        }
    }
    return repo;
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) IPom(aQute.maven.api.IPom) File(java.io.File) URI(java.net.URI) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository) IOException(java.io.IOException)

Example 12 with ResourcesRepository

use of aQute.bnd.osgi.repository.ResourcesRepository 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");
        }
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) XMLResourceGenerator(aQute.bnd.osgi.repository.XMLResourceGenerator) File(java.io.File) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) HashSet(java.util.HashSet)

Aggregations

ResourcesRepository (aQute.bnd.osgi.repository.ResourcesRepository)12 File (java.io.File)7 Resource (org.osgi.resource.Resource)7 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 URI (java.net.URI)4 HashMap (java.util.HashMap)3 Promise (org.osgi.util.promise.Promise)3 BridgeRepository (aQute.bnd.osgi.repository.BridgeRepository)2 XMLResourceGenerator (aQute.bnd.osgi.repository.XMLResourceGenerator)2 CapabilityBuilder (aQute.bnd.osgi.resource.CapabilityBuilder)2 DownloadListenerPromise (aQute.bnd.util.repository.DownloadListenerPromise)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Capability (org.osgi.resource.Capability)2 Requirement (org.osgi.resource.Requirement)2