Search in sources :

Example 1 with FileRepo

use of aQute.lib.deployer.FileRepo in project bnd by bndtools.

the class FileRepoTest method createRepo.

private FileRepo createRepo(File root, Map<String, String> props) {
    FileRepo repo = new FileRepo();
    props.put("location", root.getAbsolutePath());
    repo.setProperties(props);
    return repo;
}
Also used : FileRepo(aQute.lib.deployer.FileRepo)

Example 2 with FileRepo

use of aQute.lib.deployer.FileRepo in project bnd by bndtools.

the class FileRepoTest method testCommands.

public void testCommands() throws Exception {
    FileRepo repo = new FileRepo();
    File root = tmp;
    delete(root);
    try {
        Map<String, String> props = new HashMap<String, String>();
        props.put(FileRepo.LOCATION, root.getAbsolutePath());
        props.put(FileRepo.CMD_INIT, "echo init $0 $1 $2 $3 >>report");
        props.put(FileRepo.CMD_OPEN, "echo open $0 $1 $2 $3 >>report");
        props.put(FileRepo.CMD_BEFORE_GET, "echo beforeGet $0 $1 $2 $3 >>report");
        props.put(FileRepo.CMD_BEFORE_PUT, "echo beforePut $0 $1 $2 $3 >>report");
        props.put(FileRepo.CMD_AFTER_PUT, "echo afterPut $0 $1 $2 $3 >>report");
        props.put(FileRepo.CMD_ABORT_PUT, "echo abortPut $0 $1 $2 $3 >>report");
        props.put(FileRepo.CMD_REFRESH, "echo refresh  $0 $1 $2 $3 >>report");
        props.put(FileRepo.CMD_CLOSE, "echo close  $0 $1 $2 $3 >>report");
        props.put(FileRepo.CMD_PATH, "/xxx,$@,/yyy");
        props.put(FileRepo.TRACE, true + "");
        repo.setProperties(props);
        repo.refresh();
        {
            InputStream in = stream(getFile("jar/osgi.jar"));
            try {
                repo.put(in, null);
            } finally {
                in.close();
            }
        }
        {
            InputStream in = stream("not a valid zip");
            try {
                repo.put(in, null);
                fail("expected failure");
            } catch (Exception e) {
            // ignore
            } finally {
                in.close();
            }
        }
        repo.close();
        String s = collect(new File(root, "report"));
        System.out.println(s);
        s = s.replaceAll("\\\\", "/");
        s = s.replaceAll(root.getAbsolutePath().replaceAll("\\\\", "/"), "@");
        String[] parts = s.split("\r?\n");
        assertEquals(8, parts.length);
        assertEquals(parts[0], "init @");
        assertEquals(parts[1], "open @");
        assertEquals(parts[2], "refresh @");
        assertTrue(parts[3].matches("beforePut @ @/.*"));
        assertEquals(parts[4], "afterPut @ @/osgi/osgi-4.0.0.jar D37A1C9D5A9D3774F057B5452B7E47B6D1BB12D0");
        assertTrue(parts[5].matches("beforePut @ @/.*"));
        assertTrue(parts[6].matches("abortPut @ @/.*"));
        assertEquals(parts[7], "close @");
    } finally {
        delete(root);
    }
}
Also used : HashMap(java.util.HashMap) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileRepo(aQute.lib.deployer.FileRepo) IO.getFile(aQute.lib.io.IO.getFile) File(java.io.File)

Example 3 with FileRepo

use of aQute.lib.deployer.FileRepo in project bnd by bndtools.

the class FileRepoTest method testDownloadListenerCallback.

public void testDownloadListenerCallback() throws Exception {
    try {
        FileRepo repo = new FileRepo("tmp", tmp, true);
        File srcBundle = IO.getFile("testresources/test.jar");
        PutResult r = repo.put(IO.stream(IO.getFile("testresources/test.jar")), null);
        assertNotNull(r);
        assertNotNull(r.artifact);
        // file repo, so should match
        File f = new File(r.artifact);
        SHA1 sha1 = SHA1.digest(srcBundle);
        sha1.equals(SHA1.digest(f));
        DownloadListener mock = Mockito.mock(DownloadListener.class);
        f = repo.get("test", new Version("0"), null, mock);
        Mockito.verify(mock).success(f);
        Mockito.verifyNoMoreInteractions(mock);
        Mockito.reset(mock);
        f = repo.get("XXXXXXXXXXXXXXXXX", new Version("0"), null, mock);
        assertNull(f);
        Mockito.verifyZeroInteractions(mock);
    } finally {
        IO.delete(tmp);
    }
}
Also used : SHA1(aQute.libg.cryptography.SHA1) DownloadListener(aQute.bnd.service.RepositoryPlugin.DownloadListener) Version(aQute.bnd.version.Version) FileRepo(aQute.lib.deployer.FileRepo) IO.getFile(aQute.lib.io.IO.getFile) File(java.io.File) PutResult(aQute.bnd.service.RepositoryPlugin.PutResult)

Aggregations

FileRepo (aQute.lib.deployer.FileRepo)3 IO.getFile (aQute.lib.io.IO.getFile)2 File (java.io.File)2 DownloadListener (aQute.bnd.service.RepositoryPlugin.DownloadListener)1 PutResult (aQute.bnd.service.RepositoryPlugin.PutResult)1 Version (aQute.bnd.version.Version)1 SHA1 (aQute.libg.cryptography.SHA1)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1