Introduce osgi-install target. A2_OUTPUT not configurable.
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 23 May 2023 09:11:39 +0000 (11:11 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 23 May 2023 09:11:39 +0000 (11:11 +0200)
common.mk
osgi.mk
repackage.mk
src/org/argeo/build/Make.java

index d4f3cdf2ee1f17832e389f9d36b843d38f5a4ac4..2ef806336bcc267ecfe299abf0c11b49bb817970 100644 (file)
--- 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 5e426a6d0fe0a35865c7b8f4f4fda563f3f315a9..40946d5d660ac3a34e4b0ad3aae03f95bafed7cd 100644 (file)
--- 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)
index e1846b72aee284473fa202087c5710e5f185dda7..80ee92564ba59b9c5806843a9f706a76c3aa11b9 100644 (file)
@@ -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:
index e5571119816be3c006c1b441aab01df5534ab671..23477388f1861b46428805759e20d0b56291ebf9 100644 (file)
@@ -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<String> 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<String, String> 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<String, List<String>> options) throws IOException {
+               // check arguments
+               List<String> bundles = options.get("--bundles");
+               Objects.requireNonNull(bundles, "--bundles argument must be set");
+               if (bundles.isEmpty())
+                       return;
+
+               List<String> 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<String> 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<String, String> 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);
                        }