import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
*/
void bundle(Map<String, List<String>> options) throws IOException {
- // generate manifests
- subDirs: for (Path subDir : Files.newDirectoryStream(buildBase, (p) -> Files.isDirectory(p))) {
- String bundleSymbolicName = subDir.getFileName().toString();
- if (!bundleSymbolicName.contains("."))
- continue subDirs;
- generateManifest(bundleSymbolicName, subDir);
- }
+// // generate manifests
+// subDirs: for (Path subDir : Files.newDirectoryStream(buildBase, (p) -> Files.isDirectory(p))) {
+// String bundleSymbolicName = subDir.getFileName().toString();
+// if (!bundleSymbolicName.contains("."))
+// continue subDirs;
+// generateManifest(bundleSymbolicName, subDir);
+// }
+
+ List<String> bundles = options.get("--bundles");
+ Objects.requireNonNull(bundles, "--bundles argument must be set");
// create jars
- subDirs: for (Path subDir : Files.newDirectoryStream(buildBase, (p) -> Files.isDirectory(p))) {
- String bundleSymbolicName = subDir.getFileName().toString();
- if (!bundleSymbolicName.contains("."))
- continue subDirs;
- Path source = sdkSrcBase.resolve(subDir.getFileName());
- if (!Files.exists(source))
- continue subDirs;
- Path jarP = buildBase.resolve(subDir.getFileName() + ".jar");
- createJar(source, subDir, jarP);
+ subDirs: for (String bundle : bundles) {
+ Path source = sdkSrcBase.resolve(bundle);
+// String bundleSymbolicName = source.getFileName().toString();
+ Path compiled = buildBase.resolve(bundle);
+// if (!bundleSymbolicName.contains("."))
+// continue subDirs;
+// if (!Files.exists(source))
+// continue subDirs;
+ Path jarP = buildBase.resolve(compiled.getFileName() + ".jar");
+ createBundle(source, compiled, jarP);
}
}
* BND
*/
- void generateManifest(String bundleSymbolicName, Path compiled) throws IOException {
+// void generateManifest(String bundleSymbolicName, Path compiled) throws IOException {
+// Properties properties = new Properties();
+// Path argeoBnd = argeoBuildBase.resolve("argeo.bnd");
+// try (InputStream in = Files.newInputStream(argeoBnd)) {
+// properties.load(in);
+// }
+// // FIXME make it configurable
+// Path branchBnd = sdkSrcBase.resolve("cnf/unstable.bnd");
+// try (InputStream in = Files.newInputStream(branchBnd)) {
+// properties.load(in);
+// }
+//
+// Path bndBnd = compiled.resolve("bnd.bnd");
+// try (InputStream in = Files.newInputStream(bndBnd)) {
+// properties.load(in);
+// }
+//
+// // Normalise
+// properties.put("Bundle-SymbolicName", bundleSymbolicName);
+//
+// // Calculate MANIFEST
+// Path binP = compiled.resolve("bin");
+// Manifest manifest;
+// try (Analyzer bndAnalyzer = new Analyzer()) {
+// bndAnalyzer.setProperties(properties);
+// Jar jar = new Jar(bundleSymbolicName, binP.toFile());
+// bndAnalyzer.setJar(jar);
+// manifest = bndAnalyzer.calcManifest();
+//
+//// keys: for (Object key : manifest.getMainAttributes().keySet()) {
+//// System.out.println(key + ": " + manifest.getMainAttributes().getValue(key.toString()));
+//// }
+// } catch (Exception e) {
+// throw new RuntimeException("Bnd analysis of " + compiled + " failed", e);
+// }
+//
+// // Write manifest
+// Path manifestP = compiled.resolve("META-INF/MANIFEST.MF");
+// Files.createDirectories(manifestP.getParent());
+// try (OutputStream out = Files.newOutputStream(manifestP)) {
+// manifest.write(out);
+// }
+// }
+
+ /*
+ * JAR PACKAGING
+ */
+ void createBundle(Path source, Path compiled, Path jarP) throws IOException {
+ String bundleSymbolicName = source.getFileName().toString();
+
+ // Metadata
Properties properties = new Properties();
Path argeoBnd = argeoBuildBase.resolve("argeo.bnd");
try (InputStream in = Files.newInputStream(argeoBnd)) {
properties.load(in);
}
- Path bndBnd = compiled.resolve("bnd.bnd");
+ Path bndBnd = source.resolve("bnd.bnd");
try (InputStream in = Files.newInputStream(bndBnd)) {
properties.load(in);
}
}
// Write manifest
- Path manifestP = compiled.resolve("META-INF/MANIFEST.MF");
- Files.createDirectories(manifestP.getParent());
- try (OutputStream out = Files.newOutputStream(manifestP)) {
- manifest.write(out);
- }
- }
-
- /*
- * JAR PACKAGING
- */
- void createJar(Path source, Path compiled, Path jarP) throws IOException {
- // Load manifest
- Path manifestP = compiled.resolve("META-INF/MANIFEST.MF");
- if (!Files.exists(manifestP))
- throw new IllegalStateException("Manifest " + manifestP + " not found");
- Manifest manifest;
- try (InputStream in = Files.newInputStream(manifestP)) {
- manifest = new Manifest(in);
- } catch (IOException e) {
- throw new IllegalStateException("Cannot read manifest " + manifestP, e);
- }
+// Path manifestP = compiled.resolve("META-INF/MANIFEST.MF");
+// Files.createDirectories(manifestP.getParent());
+// try (OutputStream out = Files.newOutputStream(manifestP)) {
+// manifest.write(out);
+// }
+//
+// // Load manifest
+// Path manifestP = compiled.resolve("META-INF/MANIFEST.MF");
+// if (!Files.exists(manifestP))
+// throw new IllegalStateException("Manifest " + manifestP + " not found");
+// Manifest manifest;
+// try (InputStream in = Files.newInputStream(manifestP)) {
+// manifest = new Manifest(in);
+// } catch (IOException e) {
+// throw new IllegalStateException("Cannot read manifest " + manifestP, e);
+// }
// Load excludes
List<PathMatcher> excludes = new ArrayList<>();
Files.createDirectories(jarP.getParent());
try (JarOutputStream jarOut = new JarOutputStream(Files.newOutputStream(jarP), manifest)) {
// add all classes first
- Path binP = compiled.resolve("bin");
+// Path binP = compiled.resolve("bin");
Files.walkFileTree(binP, new SimpleFileVisitor<Path>() {
@Override
throw new IllegalArgumentException("At least an action must be provided");
int actionIndex = 0;
String action = args[actionIndex];
- if (args.length > actionIndex + 1 && args[actionIndex + 1].startsWith("-"))
+ if (args.length > actionIndex + 1 && !args[actionIndex + 1].startsWith("-"))
throw new IllegalArgumentException(
"Action " + action + " must be followed by an option: " + Arrays.asList(args));
Map<String, List<String>> options = new HashMap<>();
String currentOption = null;
- List<String> currentOptionValues = null;
for (int i = actionIndex + 1; i < args.length; i++) {
if (args[i].startsWith("-")) {
- if (currentOption != null) {
- assert currentOptionValues != null;
- if (!options.containsKey(currentOption))
- options.put(currentOption, new ArrayList<>());
- options.get(currentOption).addAll(currentOptionValues);
- }
currentOption = args[i];
- currentOptionValues = new ArrayList<>();
+ if (!options.containsKey(currentOption))
+ options.put(currentOption, new ArrayList<>());
+
} else {
- currentOptionValues.add(args[i]);
+ options.get(currentOption).add(args[i]);
}
}
- Make argeoBuild = new Make();
+
+ Make argeoMake = new Make();
switch (action) {
- case "bundle" -> argeoBuild.bundle(options);
+ case "bundle" -> argeoMake.bundle(options);
default -> throw new IllegalArgumentException("Unkown action: " + action);
}
JVM := $(JAVA_HOME)/bin/java
JAVADOC := $(JAVA_HOME)/bin/javadoc
ECJ_JAR := $(A2_BASE)/org.argeo.tp.sdk/org.eclipse.jdt.core.compiler.batch.3.29.jar
-BND_TOOL := /usr/bin/bnd
+BNDLIB_JAR := $(A2_BASE)/org.argeo.tp.sdk/biz.aQute.bndlib.5.3.jar
+SLF4J_API_JAR := $(A2_BASE)/org.argeo.tp/org.slf4j.api.1.7.jar
-BUILD_BASE = $(SDK_BUILD_BASE)/$(A2_CATEGORY)
+ARGEO_MAKE := $(JVM) -cp $(ECJ_JAR):$(BNDLIB_JAR):$(SLF4J_API_JAR) $(SDK_SRC_BASE)/sdk/argeo-build/java/org/argeo/build/Make.java
+#BND_TOOL := /usr/bin/bnd
+
+BUILD_BASE = $(SDK_BUILD_BASE)/$(shell basename $(SDK_SRC_BASE))
WORKSPACE_BNDS := $(shell cd $(SDK_SRC_BASE) && find cnf -name '*.bnd') sdk/argeo-build/argeo.bnd
BUILD_WORKSPACE_BNDS := $(WORKSPACE_BNDS:%=$(BUILD_BASE)/%)
JAVA_SRCS = $(foreach bundle, $(BUNDLES), $(shell find $(bundle) -name '*.java'))
BNDS = $(foreach bundle, $(BUNDLES), $(BUILD_BASE)/$(shell basename $(bundle))/bnd.bnd)
-ECJ_SRCS = $(foreach bundle, $(BUNDLES), $(bundle)/src[-d $(BUILD_BASE)/$(shell basename $(bundle))/bin])
+ECJ_SRCS = $(foreach bundle, $(BUNDLES), $(bundle)/src[-d $(BUILD_BASE)/$(bundle)/bin])
JAVADOC_SRCS = $(foreach bundle, $(JAVADOC_BUNDLES),$(bundle)/src)
cp $< $@
$(BUILD_BASE)/%.jar: $(BUILD_BASE)/jars-built
- mv $(basename $@)/generated/*.jar $(basename $@).jar
+ #mv $(basename $@)/generated/*.jar $(basename $@).jar
# Build level
-$(BUILD_BASE)/jars-built: $(BNDS)
- cd $(BUILD_BASE) && $(BND_TOOL) build
- touch $@
-
-$(BUILD_BASE)/%/bnd.bnd : %/bnd.bnd $(BUILD_BASE)/java-compiled
- mkdir -p $(dir $@)bin
- #rsync -r --exclude "*.java" $(dir $<)src/ $(dir $@)bin
- #rsync -r --exclude-from $(SDK_SRC_BASE)/sdk/argeo-build/excludes.txt $(dir $<) $(dir $@)bin
- #if [ -d "$(dir $<)OSGI-INF" ]; then rsync -r $(dir $<)OSGI-INF/ $(dir $@)/OSGI-INF; fi
- cp $< $@
- #echo "\n-sourcepath:$(SDK_SRC_BASE)/$(dir $<)src\n" >> $@
+$(BUILD_BASE)/jars-built: $(BUILD_BASE)/java-compiled
+ $(ARGEO_MAKE) bundle --bundles $(BUNDLES)
$(BUILD_BASE)/java-compiled : $(JAVA_SRCS)
$(JVM) -jar $(ECJ_JAR) @$(SDK_SRC_BASE)/sdk/argeo-build/ecj.args -cp $(A2_CLASSPATH) $(ECJ_SRCS)