import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.concurrent.CompletableFuture;
+import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
final Path buildBase;
/** The base of the a2 output for all layers. */
final Path a2Output;
+ /** The base of the a2 sources when packages separately. */
+ final Path a2srcOutput;
/** Whether sources should be packaged separately */
final boolean sourceBundles;
})).toAbsolutePath();
buildBase = sdkBuildBase.resolve(sdkSrcBase.getFileName());
a2Output = sdkBuildBase.resolve("a2");
+ a2srcOutput = sdkBuildBase.resolve("a2.src");
}
/*
throw new IllegalArgumentException("One and only one --category must be specified");
String category = categories.get(0);
+ final String branch;
Path branchMk = sdkSrcBase.resolve(BRANCH_MK);
- if (!Files.exists(branchMk))
- throw new IllegalStateException("No " + branchMk + " file available");
- Map<String, String> branchVariables = readeMakefileVariables(branchMk);
-
- String branch = branchVariables.get("BRANCH");
+ if (Files.exists(branchMk)) {
+ Map<String, String> branchVariables = readeMakefileVariables(branchMk);
+ branch = branchVariables.get("BRANCH");
+ } else {
+ branch = null;
+ }
long begin = System.currentTimeMillis();
// create jars in parallel
properties.load(in);
}
- Path branchBnd = sdkSrcBase.resolve("sdk/branches/" + branch + ".bnd");
- try (InputStream in = Files.newInputStream(branchBnd)) {
- properties.load(in);
+ if (branch != null) {
+ Path branchBnd = sdkSrcBase.resolve("sdk/branches/" + branch + ".bnd");
+ if (Files.exists(branchBnd))
+ try (InputStream in = Files.newInputStream(branchBnd)) {
+ properties.load(in);
+ }
}
Path bndBnd = source.resolve("bnd.bnd");
- try (InputStream in = Files.newInputStream(bndBnd)) {
- properties.load(in);
- }
+ if (Files.exists(bndBnd))
+ try (InputStream in = Files.newInputStream(bndBnd)) {
+ properties.load(in);
+ }
// Normalise
if (!properties.containsKey("Bundle-SymbolicName"))
// TODO add effective BND, Eclipse project file, etc., in order to be able to
// repackage
if (sourceBundles) {
- // TODO package sources separately
+ Path a2srcJarDirectory = bundleParent != null ? a2srcOutput.resolve(bundleParent).resolve(category)
+ : a2srcOutput.resolve(category);
+ Files.createDirectories(a2srcJarDirectory);
+ Path srcJarP = a2srcJarDirectory
+ .resolve(compiled.getFileName() + "." + major + "." + minor + ".src.jar");
+ Manifest srcManifest = new Manifest();
+ srcManifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
+ srcManifest.getMainAttributes().putValue("Bundle-SymbolicName", bundleSymbolicName + ".src");
+ srcManifest.getMainAttributes().putValue("Bundle-Version",
+ manifest.getMainAttributes().getValue("Bundle-Version").toString());
+ srcManifest.getMainAttributes().putValue("Eclipse-SourceBundle",
+ bundleSymbolicName + ";version=\"" + manifest.getMainAttributes().getValue("Bundle-Version"));
+
+ try (JarOutputStream srcJarOut = new JarOutputStream(Files.newOutputStream(srcJarP), srcManifest)) {
+ copySourcesToJar(srcP, srcJarOut, "");
+ }
} else {
- Files.walkFileTree(srcP, new SimpleFileVisitor<Path>() {
- @Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
- jarOut.putNextEntry(new JarEntry("OSGI-OPT/src/" + srcP.relativize(file).toString()));
- if (!Files.isDirectory(file))
- Files.copy(file, jarOut);
- return FileVisitResult.CONTINUE;
- }
- });
+ copySourcesToJar(srcP, jarOut, "OSGI-OPT/src/");
}
}
}
+ void copySourcesToJar(Path srcP, JarOutputStream srcJarOut, String prefix) throws IOException {
+ Files.walkFileTree(srcP, new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ srcJarOut.putNextEntry(new JarEntry(prefix + srcP.relativize(file).toString()));
+ if (!Files.isDirectory(file))
+ Files.copy(file, srcJarOut);
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ }
+
/**
* Recursively find the base source directory (which contains the
* <code>{@value #SDK_MK}</code> file).