Search in sources :

Example 1 with Archive

use of aQute.maven.api.Archive in project bnd by bndtools.

the class MavenRepoTest method testBasic.

public void testBasic() throws Exception {
    Program program = Program.valueOf("commons-cli", "commons-cli");
    List<Revision> revisions = storage.getRevisions(program);
    assertNotNull(revisions);
    assertEquals(3, revisions.size());
    Revision revision = program.version(new MavenVersion("1.4-SNAPSHOT"));
    assertTrue(revisions.contains(revision));
    List<Archive> snapshotArchives = storage.getSnapshotArchives(revision);
    assertNotNull(snapshotArchives);
    assertEquals(10, snapshotArchives.size());
    Archive archive = storage.getResolvedArchive(revision, "pom", null);
    assertNotNull(archive);
    assertEquals("1.4-20160119.062305-9", archive.snapshot.toString());
    File file = storage.get(archive).getValue();
    assertNotNull(file);
    assertEquals(10373L, file.length());
}
Also used : MavenVersion(aQute.bnd.version.MavenVersion) Program(aQute.maven.api.Program) Archive(aQute.maven.api.Archive) Revision(aQute.maven.api.Revision) File(java.io.File)

Example 2 with Archive

use of aQute.maven.api.Archive in project bnd by bndtools.

the class MavenRepoTest method testSnapshotCaches.

public void testSnapshotCaches() throws Exception {
    File fpom = IO.getFile(local, "commons-cli/commons-cli/1.4-SNAPSHOT/commons-cli-1.4-SNAPSHOT.pom");
    Program program = Program.valueOf("commons-cli", "commons-cli");
    Revision revision = Program.valueOf("commons-cli", "commons-cli").version("1.4-SNAPSHOT");
    Archive apom = revision.archive("pom", null);
    assertFalse(fpom.exists());
    assertFalse(apom.isResolved());
    File f = storage.get(apom).getValue();
    assertEquals(fpom.getAbsolutePath(), f.getAbsolutePath());
    assertRecent(f);
    long flastModified = f.lastModified();
    Thread.sleep(1001);
    f = storage.get(apom).getValue();
    assertEquals(flastModified, f.lastModified());
    f.setLastModified(0);
    assertFalse(Math.abs(System.currentTimeMillis() - f.lastModified()) <= 2000);
    f = storage.get(apom).getValue();
    assertFalse(f.lastModified() != 0);
}
Also used : Program(aQute.maven.api.Program) Archive(aQute.maven.api.Archive) Revision(aQute.maven.api.Revision) File(java.io.File)

Example 3 with Archive

use of aQute.maven.api.Archive in project bnd by bndtools.

the class BndPomRepository method get.

@Override
public File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception {
    init();
    ResourceInfo resource = bridge.getInfo(bsn, version);
    if (resource == null)
        return null;
    String name = resource.getInfo().name();
    Archive archive = Archive.valueOf(name);
    Promise<File> p = repoImpl.getMavenRepository().get(archive);
    if (listeners.length == 0)
        return p.getValue();
    new DownloadListenerPromise(reporter, name + ": get " + bsn + ";" + version, p, listeners);
    return repoImpl.getMavenRepository().toLocalFile(archive);
}
Also used : ResourceInfo(aQute.bnd.osgi.repository.BridgeRepository.ResourceInfo) Archive(aQute.maven.api.Archive) DownloadListenerPromise(aQute.bnd.util.repository.DownloadListenerPromise) File(java.io.File)

Example 4 with Archive

use of aQute.maven.api.Archive in project bnd by bndtools.

the class IndexFile method sync.

private void sync() throws Exception {
    List<Promise<Void>> sync = new ArrayList<>(promises.size());
    for (Iterator<Entry<Archive, Promise<File>>> i = promises.entrySet().iterator(); i.hasNext(); ) {
        Entry<Archive, Promise<File>> entry = i.next();
        final Archive archive = entry.getKey();
        Promise<File> promise = entry.getValue();
        i.remove();
        sync.add(promise.<Void>then(null, new Failure() {

            @Override
            public void fail(Promise<?> resolved) throws Exception {
                reporter.exception(resolved.getFailure(), "Failed to sync %s", archive);
            }
        }));
    }
    // block until all promises resolved
    Promises.all(sync).getFailure();
}
Also used : Promise(org.osgi.util.promise.Promise) Entry(java.util.Map.Entry) Archive(aQute.maven.api.Archive) ArrayList(java.util.ArrayList) File(java.io.File) Failure(org.osgi.util.promise.Failure)

Example 5 with Archive

use of aQute.maven.api.Archive in project bnd by bndtools.

the class IndexFile method loadIndexFile.

private void loadIndexFile() throws Exception {
    lastModified = indexFile.lastModified();
    Set<Archive> toBeDeleted = new HashSet<>(descriptors.keySet());
    if (indexFile.isFile()) {
        lock.readLock().lock();
        try (BufferedReader rdr = IO.reader(indexFile)) {
            String line;
            while ((line = rdr.readLine()) != null) {
                line = Strings.trim(line);
                if (line.startsWith("#") || line.isEmpty())
                    continue;
                Archive a = Archive.valueOf(line);
                if (a == null) {
                    reporter.error("MavenBndRepository: invalid entry %s in file %s", line, indexFile);
                } else {
                    toBeDeleted.remove(a);
                    loadDescriptorAsync(a);
                }
            }
        } finally {
            lock.readLock().unlock();
        }
        this.descriptors.keySet().removeAll(toBeDeleted);
        this.promises.keySet().removeAll(toBeDeleted);
    }
}
Also used : Archive(aQute.maven.api.Archive) BufferedReader(java.io.BufferedReader) HashSet(java.util.HashSet)

Aggregations

Archive (aQute.maven.api.Archive)25 File (java.io.File)13 Revision (aQute.maven.api.Revision)6 Program (aQute.maven.api.Program)5 IOException (java.io.IOException)5 FileNotFoundException (java.io.FileNotFoundException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ArrayList (java.util.ArrayList)3 Resource (org.osgi.resource.Resource)3 HttpClient (aQute.bnd.http.HttpClient)2 Jar (aQute.bnd.osgi.Jar)2 IPom (aQute.maven.api.IPom)2 Release (aQute.maven.api.Release)2 MavenRepository (aQute.maven.provider.MavenRepository)2 SnapshotVersion (aQute.maven.provider.MetadataParser.SnapshotVersion)2 InputStream (java.io.InputStream)2 Failure (org.osgi.util.promise.Failure)2 Promise (org.osgi.util.promise.Promise)2 Workspace (aQute.bnd.build.Workspace)1 HttpRequestException (aQute.bnd.http.HttpRequestException)1