X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fargeo%2Fbuild%2FMake.java;h=d94cb02069e42d166339fb700d1a482828e80e67;hb=e7090f399609f0c1c80729e426c2463efed7e9cc;hp=4fa8808697f54034307dea740ea25f0fee4d6a25;hpb=6953e7b0e4edc156941a94027b1eb9bc4e2a1e95;p=cc0%2Fargeo-build.git diff --git a/src/org/argeo/build/Make.java b/src/org/argeo/build/Make.java index 4fa8808..d94cb02 100644 --- a/src/org/argeo/build/Make.java +++ b/src/org/argeo/build/Make.java @@ -27,6 +27,7 @@ import java.util.Objects; import java.util.Properties; import java.util.StringJoiner; import java.util.StringTokenizer; +import java.util.concurrent.CompletableFuture; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; @@ -128,26 +129,34 @@ public class Make { // classpath if (!a2Categories.isEmpty()) { - compilerArgs.add("-cp"); StringJoiner classPath = new StringJoiner(File.pathSeparator); + StringJoiner modulePath = new StringJoiner(File.pathSeparator); for (String a2Base : a2Bases) { for (String a2Category : a2Categories) { Path a2Dir = Paths.get(a2Base).resolve(a2Category); if (!Files.exists(a2Dir)) Files.createDirectories(a2Dir); + modulePath.add(a2Dir.toString()); for (Path jarP : Files.newDirectoryStream(a2Dir, (p) -> p.getFileName().toString().endsWith(".jar"))) { classPath.add(jarP.toString()); + System.out.println(jarP); } } } + compilerArgs.add("-cp"); compilerArgs.add(classPath.toString()); +// compilerArgs.add("--module-path"); +// compilerArgs.add(modulePath.toString()); } // sources for (String bundle : bundles) { StringBuilder sb = new StringBuilder(); - sb.append(execDirectory.resolve(bundle).resolve("src")); + Path bundlePath = execDirectory.resolve(bundle); + if (!Files.exists(bundlePath)) + throw new IllegalArgumentException("Bundle " + bundle + " not found in " + execDirectory); + sb.append(bundlePath.resolve("src")); sb.append("[-d"); compilerArgs.add(sb.toString()); sb = new StringBuilder(); @@ -156,6 +165,12 @@ public class Make { compilerArgs.add(sb.toString()); } + if (logger.isLoggable(INFO)) + compilerArgs.add("-time"); + +// for (String arg : compilerArgs) +// System.out.println(arg); + boolean success = org.eclipse.jdt.core.compiler.batch.BatchCompiler.compile( compilerArgs.toArray(new String[compilerArgs.size()]), new PrintWriter(System.out), new PrintWriter(System.err), new MakeCompilationProgress()); @@ -164,7 +179,7 @@ public class Make { } /** Package the bundles. */ - void bundle(Map> options) throws IOException { + void bundle(Map> options) { // check arguments List bundles = options.get("--bundles"); Objects.requireNonNull(bundles, "--bundles argument must be set"); @@ -172,21 +187,38 @@ public class Make { return; List categories = options.get("--category"); - Objects.requireNonNull(bundles, "--bundles argument must be set"); + Objects.requireNonNull(bundles, "--category argument must be set"); if (categories.size() != 1) - throw new IllegalArgumentException("One and only one category must be specified"); + throw new IllegalArgumentException("One and only one --category must be specified"); String category = categories.get(0); - // create jars - for (String bundle : bundles) - createBundle(bundle, category); + List branches = options.get("--branch"); + if (branches.size() != 1) + throw new IllegalArgumentException("One and only one --branch must be specified"); + String branch = branches.get(0); + + long begin = System.currentTimeMillis(); + // create jars in parallel + List> toDos = new ArrayList<>(); + for (String bundle : bundles) { + toDos.add(CompletableFuture.runAsync(() -> { + try { + createBundle(branch, bundle, category); + } catch (IOException e) { + throw new RuntimeException("Packaging of " + bundle + " failed", e); + } + })); + } + CompletableFuture.allOf(toDos.toArray(new CompletableFuture[toDos.size()])).join(); + long duration = System.currentTimeMillis() - begin; + logger.log(INFO, "Packaging took " + duration + " ms"); } /* * UTILITIES */ /** Package a single bundle. */ - void createBundle(String bundle, String category) throws IOException { + void createBundle(String branch, String bundle, String category) throws IOException { Path source = execDirectory.resolve(bundle); Path compiled = buildBase.resolve(bundle); String bundleSymbolicName = source.getFileName().toString(); @@ -197,8 +229,8 @@ public class Make { try (InputStream in = Files.newInputStream(argeoBnd)) { properties.load(in); } - // FIXME make it configurable - Path branchBnd = sdkSrcBase.resolve("cnf/unstable.bnd"); + + Path branchBnd = sdkSrcBase.resolve("sdk/branches/" + branch + ".bnd"); try (InputStream in = Files.newInputStream(branchBnd)) { properties.load(in); } @@ -225,10 +257,10 @@ public class Make { throw new RuntimeException("Bnd analysis of " + compiled + " failed", e); } - String major = properties.getProperty("MAJOR"); - Objects.requireNonNull(major, "MAJOR must be set"); - String minor = properties.getProperty("MINOR"); - Objects.requireNonNull(minor, "MINOR must be set"); + String major = properties.getProperty("major"); + Objects.requireNonNull(major, "'major' must be set"); + String minor = properties.getProperty("minor"); + Objects.requireNonNull(minor, "'minor' must be set"); // Write manifest Path manifestP = compiled.resolve("META-INF/MANIFEST.MF"); @@ -295,7 +327,8 @@ public class Make { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { jarOut.putNextEntry(new JarEntry("OSGI-OPT/src/" + srcP.relativize(file).toString())); - Files.copy(file, jarOut); + if (!Files.isDirectory(file)) + Files.copy(file, jarOut); return FileVisitResult.CONTINUE; } }); @@ -350,13 +383,12 @@ public class Make { } long jvmUptime = ManagementFactory.getRuntimeMXBean().getUptime(); - logger.log(INFO, "Make action '" + action + "' succesfully completed after " + (jvmUptime / 1000) + "." + logger.log(INFO, "Make.java action '" + action + "' succesfully completed after " + (jvmUptime / 1000) + "." + (jvmUptime % 1000) + " s"); } catch (Exception e) { long jvmUptime = ManagementFactory.getRuntimeMXBean().getUptime(); - logger.log(ERROR, - "Make action '" + action + "' failed after " + (jvmUptime / 1000) + "." + (jvmUptime % 1000) + " s", - e); + logger.log(ERROR, "Make.java action '" + action + "' failed after " + (jvmUptime / 1000) + "." + + (jvmUptime % 1000) + " s", e); System.exit(1); } }