use of aQute.bnd.service.RepositoryPlugin.PutResult in project bnd by bndtools.
the class MavenBndRepoTest method testPutDefaultLocalSnapshot.
public void testPutDefaultLocalSnapshot() throws Exception {
Map<String, String> map = new HashMap<>();
map.put("releaseUrl", null);
map.put("snapshotUrl", null);
config(map);
File jar = IO.getFile("testresources/snapshot.jar");
PutResult put = repo.put(new FileInputStream(jar), null);
assertIsFile(local, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-SNAPSHOT.jar");
assertIsFile(local, "biz/aQute/bnd/biz.aQute.bnd.maven/3.2.0-SNAPSHOT/biz.aQute.bnd.maven-3.2.0-SNAPSHOT.pom");
String s = IO.collect(index);
assertFalse(s.contains("biz.aQute.bnd.maven"));
}
use of aQute.bnd.service.RepositoryPlugin.PutResult in project bnd by bndtools.
the class RepoCommand method _copy.
public void _copy(CopyOptions options) throws Exception {
List<String> args = options._arguments();
String srcName = args.remove(0);
String dstName = args.remove(0);
RepositoryPlugin source = workspace.getRepository(srcName);
RepositoryPlugin dest = workspace.getRepository(dstName);
if (source == null) {
bnd.error("No such source repository: %s, available repos %s", srcName, workspace.getRepositories());
}
if (dest == null) {
bnd.error("No such destination repository: %s, available repos %s", dstName, workspace.getRepositories());
} else if (!dest.canWrite())
bnd.error("Destination repository cannot write: %s", dest);
if (!bnd.isOk() || source == null || dest == null) {
return;
}
logger.debug("src = {} -> {}", srcName, source);
logger.debug("dst = {} -> {}", dstName, dest);
@SuppressWarnings("unused")
class Spec {
DownloadBlocker src;
DownloadBlocker dst;
String bsn;
Version version;
public byte[] digest;
}
List<Spec> sources = new ArrayList<Spec>();
for (String bsn : source.list(null)) {
for (Version version : source.versions(bsn)) {
logger.debug("src: {} {}", bsn, version);
Spec spec = new Spec();
spec.bsn = bsn;
spec.version = version;
spec.src = new DownloadBlocker(bnd);
File src = source.get(bsn, version, null, spec.src);
if (src == null) {
bnd.error("No such entry: %s-%s", bsn, version);
} else {
spec.dst = findMatchingVersion(dest, bsn, version);
sources.add(spec);
}
}
}
for (Spec spec : sources) {
String reason = spec.src.getReason();
if (reason != null) {
bnd.error("Failed to find %s because: %s", spec.src.getFile(), reason);
}
File src = spec.src.getFile();
if (!src.isFile()) {
bnd.error("Not a valid file %s", spec.src.getFile());
}
spec.digest = SHA1.digest(src).digest();
}
//
// See if we can prune the list by diffing
//
ResourceRepository resources = null;
if (dest instanceof ResourceRepository)
resources = (ResourceRepository) dest;
nextFile: for (Iterator<Spec> i = sources.iterator(); i.hasNext(); ) {
Spec spec = i.next();
if (resources != null) {
ResourceDescriptor rd = resources.getResourceDescriptor(spec.digest);
if (rd != null)
// Already exists
continue nextFile;
}
// TODO Diff
}
if (!bnd.isOk())
return;
for (Spec spec : sources) {
File src = spec.src.getFile();
if (!options.dry()) {
try (InputStream fin = IO.stream(src)) {
PutResult put = dest.put(fin, null);
if (put.digest != null) {
if (!Arrays.equals(spec.digest, put.digest)) {
bnd.error("Digest error in upload %s", src);
}
}
} catch (Exception e) {
bnd.exception(e, "Exception %s in upload %s", e, src);
}
}
}
for (String bsn : source.list(null)) {
for (Version version : source.versions(bsn)) {
System.out.println(bsn + ";version=" + version);
}
}
}
use of aQute.bnd.service.RepositoryPlugin.PutResult in project bnd by bndtools.
the class TestLocalIndexGeneration method testOverwrite.
public void testOverwrite() throws Exception {
config.put("overwrite", "false");
repo.setProperties(config);
PutResult r = repo.put(new BufferedInputStream(new FileInputStream("testdata/bundles/name.njbartlett.osgi.emf.minimal-2.6.1.jar")), new RepositoryPlugin.PutOptions());
File originalFile = new File(r.artifact);
assertEquals(IO.getFile(outputDir, "name.njbartlett.osgi.emf.minimal/name.njbartlett.osgi.emf.minimal-2.6.1.jar").getAbsolutePath(), originalFile.getAbsolutePath());
Jar newJar = new Jar(IO.getFile("testdata/bundles/name.njbartlett.osgi.emf.minimal-2.6.1.jar"));
Jar dummyJar = new Jar(IO.getFile("testdata/bundles/dummybundle.jar"));
newJar.putResource("testOverwrite/dummybundle.jar", new JarResource(dummyJar));
newJar.write("testdata/bundles/name.njbartlett.osgi.emf.minimal-2.6.1-testOverwrite.jar");
r = repo.put(new BufferedInputStream(new FileInputStream("testdata/bundles/name.njbartlett.osgi.emf.minimal-2.6.1-testOverwrite.jar")), new RepositoryPlugin.PutOptions());
IO.delete(IO.getFile("testdata/bundles/name.njbartlett.osgi.emf.minimal-2.6.1-testOverwrite.jar"));
assertNull(r.artifact);
}
use of aQute.bnd.service.RepositoryPlugin.PutResult in project bnd by bndtools.
the class FileRepoTest method testIndex.
/**
* Test a repo with an index
*/
public void testIndex() throws Exception {
//
// Check if the index property works
// by verifying the diff between the
// testRepo and the indexed Repo
//
assertNull(testRepo.getResources());
assertNotNull(indexedRepo.getResources());
//
// Check that we can actually put a resource
//
PutResult put = indexedRepo.put(IO.getFile("jar/osgi.jar").toURI().toURL().openStream(), null);
assertNotNull(put);
// Can we get it?
ResourceDescriptor desc = indexedRepo.getDescriptor("osgi", new Version("4.0"));
assertNotNull(desc);
// Got the same file?
assertTrue(Arrays.equals(put.digest, desc.id));
//
// Check if the description was copied
//
assertEquals("OSGi Service Platform Release 4 Interfaces and Classes for use in compiling bundles.", desc.description);
//
// We must be able to access by its sha1
//
ResourceDescriptor resource = indexedRepo.getResource(put.digest);
assertTrue(Arrays.equals(resource.id, desc.id));
//
// Check if we now have a set of resources
//
SortedSet<ResourceDescriptor> resources = indexedRepo.getResources();
assertEquals(1, resources.size());
ResourceDescriptor rd = resources.iterator().next();
assertTrue(Arrays.equals(rd.id, put.digest));
//
// Check if the bsn brings us back
//
File file = indexedRepo.get(desc.bsn, desc.version, null);
assertNotNull(file);
assertTrue(Arrays.equals(put.digest, SHA1.digest(file).digest()));
byte[] digest = SHA256.digest(file).digest();
assertTrue(Arrays.equals(rd.sha256, digest));
//
// Delete and see if it is really gone
//
indexedRepo.delete(desc.bsn, desc.version);
resources = indexedRepo.getResources();
assertEquals(0, resources.size());
file = indexedRepo.get(desc.bsn, desc.version, null);
assertNull(file);
resource = indexedRepo.getResource(put.digest);
assertNull(resource);
}
use of aQute.bnd.service.RepositoryPlugin.PutResult in project bnd by bndtools.
the class TestLocalObrGeneration method testDeployBundle.
public void testDeployBundle() throws Exception {
PutResult r = repo.put(new BufferedInputStream(new FileInputStream("testdata/bundles/name.njbartlett.osgi.emf.minimal-2.6.1.jar")), new RepositoryPlugin.PutOptions());
File deployedFile = new File(r.artifact);
assertEquals(IO.getFile(outputDir, "name.njbartlett.osgi.emf.minimal/name.njbartlett.osgi.emf.minimal-2.6.1.jar").getAbsolutePath(), deployedFile.getAbsolutePath());
File indexFile = IO.getFile(outputDir, "repository.xml");
assertTrue(indexFile.exists());
assertTrue(IO.collect(indexFile).length() > 0);
AbstractIndexedRepo repo2 = createRepoForIndex(indexFile);
File[] files = repo2.get("name.njbartlett.osgi.emf.minimal", null);
assertNotNull(files);
assertEquals(1, files.length);
assertEquals(deployedFile.getAbsoluteFile(), files[0]);
}
Aggregations