Search in sources :

Example 6 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 7 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)

Example 8 with RepoIndex

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

the class TestStandaloneLibrary method assertIndexPath.

private void assertIndexPath(String root, String file, String dest) throws Exception {
    File tempDir = IO.getFile(root);
    tempDir.mkdirs();
    final List<String> errors = new ArrayList<>();
    final List<String> warnings = new ArrayList<>();
    File target = IO.getFile(tempDir, dest);
    target.getParentFile().mkdirs();
    try {
        IO.copy(IO.getFile("src/testdata/01-bsn+version.jar"), target);
        ResourceIndexer indexer = new RepoIndex(new LogService() {

            @Override
            public void log(ServiceReference sr, int level, String message, Throwable exception) {
                log(level, message + " " + exception);
            }

            @Override
            public void log(ServiceReference sr, int level, String message) {
                log(level, message);
            }

            @Override
            public void log(int level, String message, Throwable exception) {
                log(level, message + " " + exception);
            }

            @Override
            public void log(int level, String message) {
                switch(level) {
                    case LogService.LOG_ERROR:
                        errors.add(message);
                        break;
                    case LogService.LOG_WARNING:
                        warnings.add(message);
                        break;
                    default:
                        break;
                }
            }
        });
        StringWriter writer = new StringWriter();
        String osRootPath = root.replace('/', File.separatorChar);
        String rootURI = new File(osRootPath).toURI().toString();
        File osFile = new File(file.replace('/', File.separatorChar));
        assertTrue(osFile + " does not exist", osFile.isFile());
        Map<String, String> config = new HashMap<String, String>();
        config.put(ResourceIndexer.ROOT_URL, rootURI);
        indexer.indexFragment(Collections.singleton(osFile), writer, config);
        assertEquals(0, errors.size());
        assertEquals(0, warnings.size());
    } finally {
        deleteWithException(tempDir);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResourceIndexer(org.osgi.service.indexer.ResourceIndexer) ServiceReference(org.osgi.framework.ServiceReference) StringWriter(java.io.StringWriter) File(java.io.File) Utils.copyToTempFile(org.example.tests.utils.Utils.copyToTempFile) RepoIndex(org.osgi.service.indexer.impl.RepoIndex) LogService(org.osgi.service.log.LogService)

Example 9 with RepoIndex

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

the class TestStandaloneLibrary method testPlainJar.

public void testPlainJar() throws Exception {
    RepoIndex indexer = new RepoIndex();
    StringWriter writer = new StringWriter();
    File tempDir = createTempDir();
    File tempFile = copyToTempFile(tempDir, "testdata/jcip-annotations.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/plainjar.fragment.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) 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