Search in sources :

Example 1 with RepoIndex

use of org.osgi.service.indexer.impl.RepoIndex 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 RepoIndex

use of org.osgi.service.indexer.impl.RepoIndex 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 RepoIndex

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

the class Index method printCopyright.

public static void printCopyright(PrintStream out) throws IOException {
    String version = "";
    String copyright = "";
    Enumeration<URL> urls = Index.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
    while (urls.hasMoreElements()) {
        URL url = urls.nextElement();
        Manifest m = new Manifest(url.openStream());
        String bsn = m.getMainAttributes().getValue("Bundle-SymbolicName");
        if (bsn != null && bsn.equals("org.osgi.impl.bundle.repoindex.cli")) {
            version = m.getMainAttributes().getValue("Bundle-Version");
            copyright = m.getMainAttributes().getValue("Bundle-Copyright");
            break;
        }
    }
    out.println("RepoIndex | Resource Indexer v" + version);
    out.println(copyright);
}
Also used : RepoIndex(org.osgi.service.indexer.impl.RepoIndex) Manifest(java.util.jar.Manifest) URL(java.net.URL)

Example 4 with RepoIndex

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

the class TestStandaloneLibrary method testBasicServiceInvocation.

public void testBasicServiceInvocation() throws Exception {
    ResourceIndexer indexer = new RepoIndex();
    StringWriter writer = new StringWriter();
    File tempDir = createTempDir();
    File tempFile = copyToTempFile(tempDir, "testdata/01-bsn+version.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/fragment-basic.txt")), writer.toString().trim());
    deleteWithException(tempDir);
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) File(java.io.File) Utils.copyToTempFile(org.example.tests.utils.Utils.copyToTempFile) ResourceIndexer(org.osgi.service.indexer.ResourceIndexer) RepoIndex(org.osgi.service.indexer.impl.RepoIndex)

Example 5 with RepoIndex

use of org.osgi.service.indexer.impl.RepoIndex 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)

Aggregations

RepoIndex (org.osgi.service.indexer.impl.RepoIndex)9 File (java.io.File)7 HashMap (java.util.HashMap)7 StringWriter (java.io.StringWriter)5 Utils.copyToTempFile (org.example.tests.utils.Utils.copyToTempFile)5 ResourceIndexer (org.osgi.service.indexer.ResourceIndexer)3 KnownBundleAnalyzer (org.osgi.service.indexer.impl.KnownBundleAnalyzer)3 ResourceAnalyzer (org.osgi.service.indexer.ResourceAnalyzer)2 Project (aQute.bnd.build.Project)1 WorkspaceR5Repository (bndtools.central.WorkspaceR5Repository)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 Manifest (java.util.jar.Manifest)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1