Search in sources :

Example 1 with XMLResourceGenerator

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

the class PomRepository method save.

void save(String name, Collection<? extends Resource> resources, File location) throws Exception, IOException {
    XMLResourceGenerator generator = new XMLResourceGenerator();
    generator.resources(resources);
    generator.name(name);
    generator.save(location);
}
Also used : XMLResourceGenerator(aQute.bnd.osgi.repository.XMLResourceGenerator)

Example 2 with XMLResourceGenerator

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

the class SearchRepository method save.

void save(String name, Collection<? extends Resource> resources, File location) throws Exception, IOException {
    XMLResourceGenerator generator = new XMLResourceGenerator();
    generator.resources(resources);
    generator.name(name);
    generator.save(location);
}
Also used : XMLResourceGenerator(aQute.bnd.osgi.repository.XMLResourceGenerator)

Example 3 with XMLResourceGenerator

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

the class P2Indexer method save.

private void save(Repository repository) throws IOException, Exception {
    XMLResourceGenerator xrg = new XMLResourceGenerator();
    xrg.repository(repository).name(name).save(indexFile);
}
Also used : XMLResourceGenerator(aQute.bnd.osgi.repository.XMLResourceGenerator)

Example 4 with XMLResourceGenerator

use of aQute.bnd.osgi.repository.XMLResourceGenerator 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 5 with XMLResourceGenerator

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

the class ReleasePluginImpl method saveToXml.

private void saveToXml(Project p, IMavenRepo storage, Archive index, ResourcesRepository repository) throws IOException, Exception {
    XMLResourceGenerator rg = new XMLResourceGenerator();
    File tmpFile = File.createTempFile("index", ".xml");
    try {
        rg.name(master.getRevision().toString());
        rg.repository(repository);
        rg.save(tmpFile);
        try (Release release = storage.release(master.getRevision(), p.getFlattenedProperties())) {
            release.force();
            release.add(index, tmpFile);
        }
    } finally {
        IO.delete(tmpFile);
    }
}
Also used : XMLResourceGenerator(aQute.bnd.osgi.repository.XMLResourceGenerator) File(java.io.File) Release(aQute.maven.api.Release)

Aggregations

XMLResourceGenerator (aQute.bnd.osgi.repository.XMLResourceGenerator)6 File (java.io.File)3 ResourcesRepository (aQute.bnd.osgi.repository.ResourcesRepository)2 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 DependencyResolver (aQute.bnd.maven.lib.resolve.DependencyResolver)1 RemotePostProcessor (aQute.bnd.maven.lib.resolve.RemotePostProcessor)1 CapabilityBuilder (aQute.bnd.osgi.resource.CapabilityBuilder)1 Release (aQute.maven.api.Release)1 FileNotFoundException (java.io.FileNotFoundException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)1