X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=src%2Forg%2Fargeo%2Fbuild%2FMake.java;h=97318ab610d5abc44caa4e7df77c9ad7d37d6b31;hb=af5b640e4fa16c3d5ed59a1fd3b1ffcdc37bf4fb;hp=b9fd48d3e96ca08539c74fd53c726b66fa1a0796;hpb=dd496fca245f053fc654f5fc66baf62460841fa5;p=cc0%2Fargeo-build.git diff --git a/src/org/argeo/build/Make.java b/src/org/argeo/build/Make.java index b9fd48d..97318ab 100644 --- a/src/org/argeo/build/Make.java +++ b/src/org/argeo/build/Make.java @@ -28,6 +28,7 @@ import java.util.Properties; 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; @@ -76,6 +77,8 @@ public class Make { 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; @@ -101,6 +104,7 @@ public class Make { })).toAbsolutePath(); buildBase = sdkBuildBase.resolve(sdkSrcBase.getFileName()); a2Output = sdkBuildBase.resolve("a2"); + a2srcOutput = sdkBuildBase.resolve("a2.src"); } /* @@ -195,12 +199,14 @@ public class Make { 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 branchVariables = readeMakefileVariables(branchMk); - - String branch = branchVariables.get("BRANCH"); + if (Files.exists(branchMk)) { + Map branchVariables = readeMakefileVariables(branchMk); + branch = branchVariables.get("BRANCH"); + } else { + branch = null; + } long begin = System.currentTimeMillis(); // create jars in parallel @@ -235,15 +241,19 @@ public class Make { 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")) @@ -345,21 +355,40 @@ public class Make { // 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() { - @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() { + @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 * {@value #SDK_MK} file).