Search in sources :

Example 1 with KnownBundleAnalyzer

use of org.osgi.service.indexer.impl.KnownBundleAnalyzer in project bnd by bndtools.

the class R5RepoContentProvider method generateIndex.

public void generateIndex(Set<File> files, OutputStream output, String repoName, URI baseUri, boolean pretty, Registry registry, LogService log) throws Exception {
    RepoIndex indexer;
    if (log != null)
        indexer = new RepoIndex(log);
    else
        indexer = new RepoIndex();
    indexer.addAnalyzer(new KnownBundleAnalyzer(), FrameworkUtil.createFilter("(name=*)"));
    if (registry != null) {
        List<ResourceAnalyzer> analyzers = registry.getPlugins(ResourceAnalyzer.class);
        for (ResourceAnalyzer analyzer : analyzers) {
            // TODO: where to get the filter property??
            indexer.addAnalyzer(analyzer, null);
        }
    }
    long modified = 0;
    for (File file : files) modified = Math.max(modified, file.lastModified());
    Map<String, String> config = new HashMap<String, String>();
    config.put(ResourceIndexer.REPOSITORY_NAME, repoName);
    config.put(ResourceIndexer.ROOT_URL, baseUri.toString());
    config.put(ResourceIndexer.PRETTY, Boolean.toString(pretty));
    config.put(ResourceIndexer.COMPRESSED, Boolean.toString(!pretty));
    config.put(org.osgi.service.indexer.impl.RepoIndex.REPOSITORY_INCREMENT_OVERRIDE, Long.toString(modified));
    indexer.index(files, output, config);
}
Also used : ResourceAnalyzer(org.osgi.service.indexer.ResourceAnalyzer) HashMap(java.util.HashMap) KnownBundleAnalyzer(org.osgi.service.indexer.impl.KnownBundleAnalyzer) File(java.io.File) RepoIndex(org.osgi.service.indexer.impl.RepoIndex)

Example 2 with KnownBundleAnalyzer

use of org.osgi.service.indexer.impl.KnownBundleAnalyzer in project bnd by bndtools.

the class TestStandaloneLibrary method testKnownBundlesExtra.

public void testKnownBundlesExtra() throws Exception {
    Properties extras = new Properties();
    extras.setProperty("org.eclipse.equinox.ds;[1.4,1.5)", "cap=extra;extra=wibble");
    KnownBundleAnalyzer knownBundlesAnalyzer = new KnownBundleAnalyzer();
    knownBundlesAnalyzer.setKnownBundlesExtra(extras);
    RepoIndex indexer = new RepoIndex();
    indexer.addAnalyzer(knownBundlesAnalyzer, FrameworkUtil.createFilter("(name=*)"));
    StringWriter writer = new StringWriter();
    File tempDir = createTempDir();
    File tempFile = copyToTempFile(tempDir, "testdata/org.eclipse.equinox.ds-1.4.0.jar");
    Map<String, String> config = new HashMap<String, String>();
    config.put(ResourceIndexer.ROOT_URL, tempDir.getAbsoluteFile().toURI().toString());
    indexer.indexFragment(Collections.singleton(tempFile), writer, config);
    assertEquals(readStream(TestStandaloneLibrary.class.getResourceAsStream("/testdata/org.eclipse.equinox.ds-1.4.0.extra-fragment.txt")), writer.toString().trim());
    deleteWithException(tempDir);
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) Properties(java.util.Properties) KnownBundleAnalyzer(org.osgi.service.indexer.impl.KnownBundleAnalyzer) File(java.io.File) Utils.copyToTempFile(org.example.tests.utils.Utils.copyToTempFile) RepoIndex(org.osgi.service.indexer.impl.RepoIndex)

Example 3 with KnownBundleAnalyzer

use of org.osgi.service.indexer.impl.KnownBundleAnalyzer in project bnd by bndtools.

the class TestStandaloneLibrary method testKnownBundleRecognition.

public void testKnownBundleRecognition() throws Exception {
    RepoIndex indexer = new RepoIndex();
    indexer.addAnalyzer(new KnownBundleAnalyzer(), FrameworkUtil.createFilter("(name=*)"));
    StringWriter writer = new StringWriter();
    File tempDir = createTempDir();
    File tempFile = copyToTempFile(tempDir, "testdata/org.eclipse.equinox.ds-1.4.0.jar");
    Map<String, String> config = new HashMap<String, String>();
    config.put(ResourceIndexer.ROOT_URL, tempDir.getAbsoluteFile().toURI().toString());
    indexer.indexFragment(Collections.singleton(tempFile), writer, config);
    assertEquals(readStream(TestStandaloneLibrary.class.getResourceAsStream("/testdata/org.eclipse.equinox.ds-1.4.0.fragment.txt")), writer.toString().trim());
    deleteWithException(tempDir);
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) KnownBundleAnalyzer(org.osgi.service.indexer.impl.KnownBundleAnalyzer) File(java.io.File) Utils.copyToTempFile(org.example.tests.utils.Utils.copyToTempFile) RepoIndex(org.osgi.service.indexer.impl.RepoIndex)

Example 4 with KnownBundleAnalyzer

use of org.osgi.service.indexer.impl.KnownBundleAnalyzer in project bnd by bndtools.

the class RepoIndexTask method registerKnownBundles.

private void registerKnownBundles(BundleContext bundleContext) {
    KnownBundleAnalyzer kba = builtInknownBundles ? new KnownBundleAnalyzer() : new KnownBundleAnalyzer(new Properties());
    if (additionalKnownBundles != null) {
        File extras = new File(additionalKnownBundles);
        if (extras.exists()) {
            Properties props = new Properties();
            try (Reader r = new FileReader(extras)) {
                props.load(r);
                kba.setKnownBundlesExtra(props);
            } catch (IOException e) {
                throw new BuildException("Unable to load the additional known bundles " + additionalKnownBundles, e);
            }
        } else {
            throw new BuildException("The additional known bundles file " + additionalKnownBundles + " does not exist.");
        }
    }
    bundleContext.registerService(ResourceAnalyzer.class, kba, null);
}
Also used : Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) KnownBundleAnalyzer(org.osgi.service.indexer.impl.KnownBundleAnalyzer) Properties(java.util.Properties) File(java.io.File)

Example 5 with KnownBundleAnalyzer

use of org.osgi.service.indexer.impl.KnownBundleAnalyzer in project bnd by bndtools.

the class Index method processArgs.

private static File processArgs(String[] args, PrintStream err, Map<String, String> config, Collection<? super File> fileList, BundleContext context) throws Exception {
    /*
		 * Parse the command line
		 */
    CommandLineOptions commandLineOptions = new CommandLineOptions();
    CmdLineParser parser = new CmdLineParser(commandLineOptions);
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        err.printf("Error during command-line parsing: %s%n", e.getLocalizedMessage());
        commandLineOptions.help = true;
    }
    /* print usage when so requested and exit */
    if (commandLineOptions.help) {
        try {
            /* can't be covered by a test */
            //$NON-NLS-1$
            int cols = Integer.parseInt(System.getenv("COLUMNS"));
            if (cols > 80) {
                parser.setUsageWidth(cols);
            }
        } catch (NumberFormatException e) {
        /* swallow, can't be covered by a test */
        }
        CommandLineOptions.usage(err, PROGRAM_NAME, parser);
        return null;
    }
    KnownBundleAnalyzer knownBundleAnalyzer = null;
    config.put(ResourceIndexer.REPOSITORY_NAME, commandLineOptions.repositoryName);
    if (commandLineOptions.stylesheetURL != null) {
        config.put(ResourceIndexer.STYLESHEET, commandLineOptions.stylesheetURL.toString());
    }
    File output = commandLineOptions.outputFile;
    if (commandLineOptions.verbose) {
        config.put(ResourceIndexer.VERBOSE, Boolean.TRUE.toString());
    }
    if (commandLineOptions.rootURL != null) {
        config.put(ResourceIndexer.ROOT_URL, commandLineOptions.rootURL.toString());
    }
    config.put(ResourceIndexer.URL_TEMPLATE, commandLineOptions.resourceUrlTemplate);
    if (commandLineOptions.licenseURL != null) {
        config.put(ResourceIndexer.LICENSE_URL, commandLineOptions.licenseURL.toString());
    }
    if (commandLineOptions.pretty) {
        config.put(ResourceIndexer.PRETTY, Boolean.TRUE.toString());
    }
    if (commandLineOptions.overrideBuiltinKnownBundles) {
        knownBundleAnalyzer = new KnownBundleAnalyzer(new Properties());
    }
    File knownBundlesExtraFile = commandLineOptions.knownBundlePropertiesFile;
    if (commandLineOptions.incrementOverride) {
        config.put(RepoIndex.REPOSITORY_INCREMENT_OVERRIDE, "");
    }
    if (commandLineOptions.fileList.isEmpty()) {
        fileList.clear();
    } else {
        for (File file : commandLineOptions.fileList) {
            fileList.add(new File(file.toURI().normalize().getPath()));
        }
    }
    if (knownBundleAnalyzer == null)
        knownBundleAnalyzer = new KnownBundleAnalyzer();
    if (knownBundlesExtraFile != null) {
        Properties props = loadPropertiesFile(knownBundlesExtraFile);
        knownBundleAnalyzer.setKnownBundlesExtra(props);
    }
    context.registerService(ResourceAnalyzer.class.getName(), knownBundleAnalyzer, null);
    return output;
}
Also used : ResourceAnalyzer(org.osgi.service.indexer.ResourceAnalyzer) CmdLineParser(org.kohsuke.args4j.CmdLineParser) KnownBundleAnalyzer(org.osgi.service.indexer.impl.KnownBundleAnalyzer) Properties(java.util.Properties) File(java.io.File) CmdLineException(org.kohsuke.args4j.CmdLineException)

Aggregations

File (java.io.File)5 KnownBundleAnalyzer (org.osgi.service.indexer.impl.KnownBundleAnalyzer)5 HashMap (java.util.HashMap)3 Properties (java.util.Properties)3 RepoIndex (org.osgi.service.indexer.impl.RepoIndex)3 StringWriter (java.io.StringWriter)2 Utils.copyToTempFile (org.example.tests.utils.Utils.copyToTempFile)2 ResourceAnalyzer (org.osgi.service.indexer.ResourceAnalyzer)2 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 BuildException (org.apache.tools.ant.BuildException)1 CmdLineException (org.kohsuke.args4j.CmdLineException)1 CmdLineParser (org.kohsuke.args4j.CmdLineParser)1