use of aQute.maven.api.Release in project bnd by bndtools.
the class MavenBndRepository method put.
@Override
public PutResult put(InputStream stream, PutOptions options) throws Exception {
init();
File binaryFile = File.createTempFile("put", ".jar");
File pomFile = File.createTempFile("pom", ".xml");
LocalPutResult result = new LocalPutResult();
try {
if (options == null)
options = new PutOptions();
else {
result.options = options;
}
IO.copy(stream, binaryFile);
if (options.digest != null) {
byte[] digest = SHA1.digest(binaryFile).digest();
if (!Arrays.equals(options.digest, digest))
throw new IllegalArgumentException("The given sha-1 does not match the contents sha-1");
}
if (options.context == null) {
options.context = registry.getPlugin(Workspace.class);
if (options.context == null)
options.context = new Processor();
}
ReleaseDTO instructions = getReleaseDTO(options.context);
try (Jar binary = new Jar(binaryFile)) {
Resource pomResource;
if (instructions.pom.path != null) {
File f = options.context.getFile(instructions.pom.path);
if (!f.isFile())
throw new IllegalArgumentException("-maven-release specifies " + f + " as pom file but this file is not found");
pomResource = new FileResource(f);
} else {
pomResource = getPomResource(binary);
if (pomResource == null) {
pomResource = createPomResource(binary, options.context);
if (pomResource == null)
throw new IllegalArgumentException("No POM resource in META-INF/maven/... The Maven Bnd Repository requires this pom.");
}
}
IO.copy(pomResource.openInputStream(), pomFile);
IPom pom;
try (InputStream fin = IO.stream(pomFile)) {
pom = storage.getPom(fin);
}
Archive binaryArchive = pom.binaryArchive();
checkRemotePossible(instructions, binaryArchive.isSnapshot());
if (!binaryArchive.isSnapshot()) {
releasePlugin.add(options.context, pom);
if (storage.exists(binaryArchive)) {
logger.debug("Already released {} to {}", pom.getRevision(), this);
result.alreadyReleased = true;
return result;
}
}
logger.debug("Put release {}", pom.getRevision());
try (Release releaser = storage.release(pom.getRevision(), options.context.getProperties())) {
if (releaser == null) {
logger.debug("Already released {}", pom.getRevision());
return result;
}
if (instructions.snapshot >= 0)
releaser.setBuild(instructions.snapshot, null);
if (isLocal(instructions))
releaser.setLocalOnly();
releaser.add(pom.getRevision().pomArchive(), pomFile);
releaser.add(binaryArchive, binaryFile);
result.binaryArchive = binaryArchive;
result.pomArchive = pom.getRevision().pomArchive();
if (!isLocal(instructions)) {
try (Tool tool = new Tool(options.context, binary)) {
if (instructions.javadoc != null) {
if (!NONE.equals(instructions.javadoc.path)) {
try (Jar jar = getJavadoc(tool, options.context, instructions.javadoc.path, instructions.javadoc.options, instructions.javadoc.packages == JavadocPackages.EXPORT)) {
save(releaser, pom.getRevision(), jar, "javadoc");
}
}
}
if (instructions.sources != null) {
if (!NONE.equals(instructions.sources.path)) {
try (Jar jar = getSource(tool, options.context, instructions.sources.path)) {
save(releaser, pom.getRevision(), jar, "sources");
}
}
}
}
}
}
if (configuration.noupdateOnRelease() == false && !binaryArchive.isSnapshot())
index.add(binaryArchive);
}
return result;
} catch (Exception e) {
result.failed = e.getMessage();
throw e;
} finally {
IO.delete(binaryFile);
IO.delete(pomFile);
}
}
use of aQute.maven.api.Release in project bnd by bndtools.
the class ReleasePluginImpl method saveToXml.
private void saveToXml(Project p, IMavenRepo storage, Archive index, ResourcesRepository repository) throws IOException, Exception {
XMLResourceGenerator rg = new XMLResourceGenerator();
File tmpFile = File.createTempFile("index", ".xml");
try {
rg.name(master.getRevision().toString());
rg.repository(repository);
rg.save(tmpFile);
try (Release release = storage.release(master.getRevision(), p.getFlattenedProperties())) {
release.force();
release.add(index, tmpFile);
}
} finally {
IO.delete(tmpFile);
}
}
use of aQute.maven.api.Release in project bnd by bndtools.
the class MavenRepoTest method testBasicSnapshotRelease.
public void testBasicSnapshotRelease() throws Exception {
File fpom = IO.getFile(local, "commons-cli/commons-cli/1.4-SNAPSHOT/commons-cli-1.4-SNAPSHOT.pom");
File rpom = IO.getFile(remote, "commons-cli/commons-cli/1.4-SNAPSHOT/commons-cli-1.4-19700101.000010-10.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());
Release r = storage.release(revision, new Properties());
r.setBuild(10000, null);
r.add("pom", null, new ByteArrayInputStream(new byte[0]));
r.close();
assertTrue(fpom.isFile());
assertTrue(rpom.isFile());
}
Aggregations