From: Mathieu Baudier Date: Tue, 23 May 2023 09:11:39 +0000 (+0200) Subject: Introduce osgi-install target. A2_OUTPUT not configurable. X-Git-Tag: v2.3.6~12 X-Git-Url: https://git.argeo.org/?a=commitdiff_plain;h=ed86c203d9fcb9113431795edf3e7712b81e2c65;p=cc0%2Fargeo-build.git Introduce osgi-install target. A2_OUTPUT not configurable. --- diff --git a/common.mk b/common.mk index d4f3cdf..2ef8063 100644 --- a/common.mk +++ b/common.mk @@ -5,3 +5,9 @@ build-minor=3 ECJ_BRANCH=3.32 BNDLIB_BRANCH=5.3 SYSLOGGER_BRANCH=$(build-major).$(build-minor) + +# GNU defaults +prefix ?= /usr/local +datarootdir ?= $(prefix)/share + +A2_INSTALL_TARGET ?= $(datarootdir)/a2 \ No newline at end of file diff --git a/osgi.mk b/osgi.mk index 5e426a6..40946d5 100644 --- a/osgi.mk +++ b/osgi.mk @@ -7,7 +7,7 @@ include $(ARGEO_BUILD_BASE)common.mk # SDK_SRC_BASE the base of the source code, typically the root of the cloned git repository # SDK_BUILD_BASE the base of the output # JAVA_HOME the base of the JDK used to build -A2_OUTPUT ?= $(SDK_BUILD_BASE)/a2 +A2_OUTPUT = $(SDK_BUILD_BASE)/a2 JVM ?= $(JAVA_HOME)/bin/java JAVADOC ?= $(JAVA_HOME)/bin/javadoc @@ -76,6 +76,11 @@ endif clean-manifests : @rm -rf $(foreach bundle, $(BUNDLES), $(bundle)/META-INF/MANIFEST.MF); +osgi-install: + $(ARGEO_MAKE) \ + install --category $(A2_CATEGORY) --bundles $(subst $(A2_CATEGORY)/,,$*) \ + --target $(DESTDIR)$(A2_INSTALL_TARGET) + # Javadoc generation javadoc: $(BUILD_BASE)/built $(JAVADOC) -noindex -quiet -Xmaxwarns 1 -d $(BUILD_BASE)/api --source-path $(subst $(space),$(pathsep),$(strip $(JAVADOC_SRCS))) -subpackages $(JAVADOC_PACKAGES) diff --git a/repackage.mk b/repackage.mk index e1846b7..80ee925 100644 --- a/repackage.mk +++ b/repackage.mk @@ -7,7 +7,7 @@ include $(ARGEO_BUILD_BASE)common.mk # SDK_SRC_BASE the base of the source code, typically the root of the cloned git repository # SDK_BUILD_BASE the base of the output # JAVA_HOME the base of the JDK used to build -A2_OUTPUT ?= $(SDK_BUILD_BASE)/a2 +A2_OUTPUT = $(SDK_BUILD_BASE)/a2 JVM ?= $(JAVA_HOME)/bin/java # The following variables should be declared in the including Makefile: diff --git a/src/org/argeo/build/Make.java b/src/org/argeo/build/Make.java index e557111..2347738 100644 --- a/src/org/argeo/build/Make.java +++ b/src/org/argeo/build/Make.java @@ -84,6 +84,10 @@ public class Make { * Make file variable (in {@link #SDK_MK}) with a path to the build output base. */ private final static String VAR_SDK_BUILD_BASE = "SDK_BUILD_BASE"; + /** + * Make file variable (in {@link #BRANCH_MK}) with the branch. + */ + private final static String VAR_BRANCH = "BRANCH"; /** Name of the local-specific Makefile (sdk.mk). */ final static String SDK_MK = "sdk.mk"; @@ -266,7 +270,7 @@ public class Make { return; List categories = options.get("--category"); - Objects.requireNonNull(bundles, "--category argument must be set"); + Objects.requireNonNull(categories, "--category argument must be set"); if (categories.size() != 1) throw new IllegalArgumentException("One and only one --category must be specified"); String category = categories.get(0); @@ -275,7 +279,7 @@ public class Make { Path branchMk = sdkSrcBase.resolve(BRANCH_MK); if (Files.exists(branchMk)) { Map branchVariables = readMakefileVariables(branchMk); - branch = branchVariables.get("BRANCH"); + branch = branchVariables.get(VAR_BRANCH); } else { branch = null; } @@ -296,7 +300,60 @@ public class Make { long duration = System.currentTimeMillis() - begin; logger.log(INFO, "Packaging took " + duration + " ms"); } - + + /** Install the bundles. */ + void install(Map> options) throws IOException { + // check arguments + List bundles = options.get("--bundles"); + Objects.requireNonNull(bundles, "--bundles argument must be set"); + if (bundles.isEmpty()) + return; + + List categories = options.get("--category"); + Objects.requireNonNull(categories, "--category argument must be set"); + if (categories.size() != 1) + throw new IllegalArgumentException("One and only one --category must be specified"); + String category = categories.get(0); + + List targetDirs = options.get("--target"); + Objects.requireNonNull(targetDirs, "--target argument must be set"); + if (targetDirs.size() != 1) + throw new IllegalArgumentException("One and only one --target must be specified"); + Path targetA2 = Paths.get(targetDirs.get(0)); + + final String branch; + Path branchMk = sdkSrcBase.resolve(BRANCH_MK); + if (Files.exists(branchMk)) { + Map branchVariables = readMakefileVariables(branchMk); + branch = branchVariables.get(VAR_BRANCH); + } else { + throw new IllegalArgumentException(VAR_BRANCH + " variable must be set."); + } + + Properties properties = new Properties(); + Path branchBnd = sdkSrcBase.resolve("sdk/branches/" + branch + ".bnd"); + if (Files.exists(branchBnd)) + try (InputStream in = Files.newInputStream(branchBnd)) { + properties.load(in); + } + String major = properties.getProperty("major"); + Objects.requireNonNull(major, "'major' must be set"); + String minor = properties.getProperty("minor"); + Objects.requireNonNull(minor, "'minor' must be set"); + + for (String bundle : bundles) { + Path bundlePath = Paths.get(bundle); + Path bundleParent = bundlePath.getParent(); + Path a2JarDirectory = bundleParent != null ? a2Output.resolve(bundleParent).resolve(category) + : a2Output.resolve(category); + Path jarP = a2JarDirectory.resolve(bundlePath.getFileName() + "." + major + "." + minor + ".jar"); + + Path targetJarP = targetA2.resolve(a2JarDirectory.relativize(jarP)); + Files.createDirectories(targetJarP.getParent()); + Files.copy(jarP, targetJarP); + } + } + /** Package a single bundle. */ void createBundle(String branch, String bundle, String category) throws IOException { final Path source; @@ -583,6 +640,7 @@ public class Make { case "compile" -> argeoMake.compile(options); case "bundle" -> argeoMake.bundle(options); case "all" -> argeoMake.all(options); + case "install" -> argeoMake.install(options); default -> throw new IllegalArgumentException("Unkown action: " + action); }