Search in sources :

Example 6 with ResourcesRepository

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

the class IndexerMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        logger.debug("skip project as configured");
        return;
    }
    if (scopes == null || scopes.isEmpty()) {
        scopes = Arrays.asList("compile", "runtime");
    }
    logger.debug("Indexing dependencies with scopes: {}", scopes);
    logger.debug("Including Transitive dependencies: {}", includeTransitive);
    logger.debug("Local file URLs permitted: {}", localURLs);
    logger.debug("Adding mvn: URLs as alternative content: {}", addMvnURLs);
    DependencyResolver dependencyResolver = new DependencyResolver(project, session, resolver, system, scopes, includeTransitive, new RemotePostProcessor(session, system, metadataReader, localURLs));
    Map<File, ArtifactResult> dependencies = dependencyResolver.resolve();
    Map<String, ArtifactRepository> repositories = new HashMap<>();
    for (ArtifactRepository artifactRepository : project.getRemoteArtifactRepositories()) {
        logger.debug("Located an artifact repository {}", artifactRepository.getId());
        repositories.put(artifactRepository.getId(), artifactRepository);
    }
    ArtifactRepository deploymentRepo = project.getDistributionManagementArtifactRepository();
    if (deploymentRepo != null) {
        logger.debug("Located a deployment repository {}", deploymentRepo.getId());
        if (repositories.get(deploymentRepo.getId()) == null) {
            repositories.put(deploymentRepo.getId(), deploymentRepo);
        } else {
            logger.info("The configured deployment repository {} has the same id as one of the remote artifact repositories. It is assumed that these repositories are the same.", deploymentRepo.getId());
        }
    }
    RepositoryURLResolver repositoryURLResolver = new RepositoryURLResolver(repositories);
    MavenURLResolver mavenURLResolver = new MavenURLResolver();
    ResourcesRepository resourcesRepository = new ResourcesRepository();
    XMLResourceGenerator xmlResourceGenerator = new XMLResourceGenerator();
    logger.debug("Indexing artifacts: {}", dependencies.keySet());
    try {
        IO.mkdirs(outputFile.getParentFile());
        for (Entry<File, ArtifactResult> entry : dependencies.entrySet()) {
            File file = entry.getKey();
            ResourceBuilder resourceBuilder = new ResourceBuilder();
            resourceBuilder.addFile(entry.getKey(), repositoryURLResolver.resolver(file, entry.getValue()));
            if (addMvnURLs) {
                CapabilityBuilder c = new CapabilityBuilder(ContentNamespace.CONTENT_NAMESPACE);
                c.addAttribute(ContentNamespace.CONTENT_NAMESPACE, SHA256.digest(file).asHex());
                c.addAttribute(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, mavenURLResolver.resolver(file, entry.getValue()));
                c.addAttribute(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE, file.length());
                c.addAttribute(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE, MavenURLResolver.MIME);
                resourceBuilder.addCapability(c);
            }
            resourcesRepository.add(resourceBuilder.build());
        }
        if (includeJar && project.getPackaging().equals("jar")) {
            File current = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".jar");
            if (current.exists()) {
                ResourceBuilder resourceBuilder = new ResourceBuilder();
                resourceBuilder.addFile(current, current.toURI());
                resourcesRepository.add(resourceBuilder.build());
            }
        }
        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");
    }
    attach(outputFile, "osgi-index", "xml");
    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");
        }
        attach(gzipOutputFile, "osgi-index", "xml.gz");
    }
}
Also used : RemotePostProcessor(aQute.bnd.maven.lib.resolve.RemotePostProcessor) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) CapabilityBuilder(aQute.bnd.osgi.resource.CapabilityBuilder) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileNotFoundException(java.io.FileNotFoundException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DependencyResolver(aQute.bnd.maven.lib.resolve.DependencyResolver) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) XMLResourceGenerator(aQute.bnd.osgi.repository.XMLResourceGenerator) File(java.io.File) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Example 7 with ResourcesRepository

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

the class ResolverValidator method resolve.

public Resolution resolve(Repository repository, Resource resource) throws Exception {
    Resolution resolution = new Resolution();
    Requirement identity = getIdentity(resource);
    setProperty("-runrequires", ResourceUtils.toRequireCapability(identity));
    BndrunResolveContext context = getResolveContext();
    context.addRepository(repository);
    context.init();
    resolution.resource = resource;
    try {
        Map<Resource, List<Wire>> resolve2 = resolver.resolve(context);
        resolution.succeeded = true;
        resolution.resolved = resolve2.keySet();
        logger.debug("resolving {} succeeded", resource);
    } catch (ResolutionException e) {
        logger.debug("resolving {} failed", resource);
        resolution.succeeded = false;
        resolution.message = e.getMessage();
        for (Requirement req : e.getUnresolvedRequirements()) {
            logger.debug("    missing {}", req);
            resolution.unresolved.add(req);
        }
        ResourcesRepository systemRepository = new ResourcesRepository(system);
        for (Requirement r : resource.getRequirements(null)) {
            Collection<Capability> caps = systemRepository.findProvider(r);
            boolean missing = caps.isEmpty();
            if (missing) {
                Set<Requirement> requirements = singleton(r);
                caps = repository.findProviders(requirements).get(r);
                missing = caps.isEmpty();
                if (missing) {
                    if (ResourceUtils.getResolution(r) == ResolutionDirective.optional)
                        resolution.optionals.add(r);
                    else
                        resolution.missing.add(r);
                } else {
                    logger.debug("     found {} in repo", r);
                    resolution.repos.add(r);
                }
            } else {
                logger.debug("     found {} in system", r);
                resolution.system.add(r);
            }
        }
        error("resolving %s failed with %s", resource, resolution.message);
    } catch (Exception e) {
        e.printStackTrace();
        error("resolving %s failed with %s", context.getInputResource().getRequirements(null), e);
        resolution.message = e.getMessage();
    }
    return resolution;
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) Requirement(org.osgi.resource.Requirement) ResourceUtils.createWildcardRequirement(aQute.bnd.osgi.resource.ResourceUtils.createWildcardRequirement) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Resource(org.osgi.resource.Resource) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) ResolutionException(org.osgi.service.resolver.ResolutionException)

Example 8 with ResourcesRepository

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

the class ResolverValidator method validate.

public List<Resolution> validate(Collection<Resource> toBeChecked) throws Exception {
    Set<Resource> allResources = new LinkedHashSet<Resource>();
    for (URI uri : repositories) {
        allResources.addAll(XMLResourceParser.getResources(uri));
    }
    allResources.addAll(toBeChecked);
    ResourcesRepository repository = new ResourcesRepository(allResources);
    return validateResources(repository, toBeChecked);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Resource(org.osgi.resource.Resource) URI(java.net.URI) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Example 9 with ResourcesRepository

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

the class OSGiIndex method readIndexes.

private Promise<BridgeRepository> readIndexes(boolean refresh) throws Exception {
    List<Promise<List<Resource>>> promises = new ArrayList<>(getURIs().size());
    for (URI uri : getURIs()) {
        promises.add(download(uri, refresh));
    }
    Promise<List<List<Resource>>> all = Promises.all(promises);
    return all.map(new Function<List<List<Resource>>, BridgeRepository>() {

        @Override
        public BridgeRepository apply(List<List<Resource>> resources) {
            try {
                ResourcesRepository rr = new ResourcesRepository();
                for (List<Resource> p : resources) {
                    rr.addAll(p);
                }
                return new BridgeRepository(rr);
            } catch (Exception e) {
                throw Exceptions.duck(e);
            }
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) URI(java.net.URI) BridgeRepository(aQute.bnd.osgi.repository.BridgeRepository) Promise(org.osgi.util.promise.Promise) ArrayList(java.util.ArrayList) List(java.util.List) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Example 10 with ResourcesRepository

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

the class ReleasePluginImpl method end.

/*
	 * End the release cyle. This will index all artifacts released to the
	 * repository since the begin.
	 */
void end(Project p, IMavenRepo storage) throws Exception {
    if (releasedArtifacts.isEmpty())
        return;
    if (p != indexProject)
        throw new IllegalArgumentException("Different project that started the release plugin then that ended it " + indexProject + ":" + p);
    if (master == null)
        throw new IllegalArgumentException("The index project was never released so GAV is unknown for index");
    Archive index = master.getRevision().archive("xml", "index");
    String prefix = makeDots(index.remotePath);
    ResourcesRepository repository = createIndex(releasedArtifacts, storage, prefix);
    saveToXml(p, storage, index, repository);
}
Also used : Archive(aQute.maven.api.Archive) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

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