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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations