summaryrefslogtreecommitdiffstats
path: root/container-dev-builder/tools
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /container-dev-builder/tools
Publish
Diffstat (limited to 'container-dev-builder/tools')
-rw-r--r--container-dev-builder/tools/pom.xml51
-rw-r--r--container-dev-builder/tools/src/main/java/com/yahoo/container/dev/builder/DependencyResolver.java58
-rw-r--r--container-dev-builder/tools/src/main/java/com/yahoo/container/dev/builder/PomFileGenerator.java50
-rw-r--r--container-dev-builder/tools/src/main/java/com/yahoo/container/dev/builder/PreinstalledBundleResolver.java79
4 files changed, 238 insertions, 0 deletions
diff --git a/container-dev-builder/tools/pom.xml b/container-dev-builder/tools/pom.xml
new file mode 100644
index 00000000000..c892e80ec34
--- /dev/null
+++ b/container-dev-builder/tools/pom.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<!-- Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>tools</groupId>
+ <artifactId>tools</artifactId>
+ <version>1.0</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.1.1</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ <executions>
+ <execution>
+ <id>make-assembly</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+</project>
diff --git a/container-dev-builder/tools/src/main/java/com/yahoo/container/dev/builder/DependencyResolver.java b/container-dev-builder/tools/src/main/java/com/yahoo/container/dev/builder/DependencyResolver.java
new file mode 100644
index 00000000000..c8a0bcf5a8a
--- /dev/null
+++ b/container-dev-builder/tools/src/main/java/com/yahoo/container/dev/builder/DependencyResolver.java
@@ -0,0 +1,58 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.dev.builder;
+
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
+ */
+public class DependencyResolver {
+
+ private static final Path DEPENDENCIES = Paths.get("dependencies");
+
+ public static void main(String[] args) throws IOException, XmlPullParserException {
+ final Set<String> blacklist = new HashSet<>(Arrays.asList(args).subList(1, args.length));
+ final Set<String> dependencies = new TreeSet<>();
+ Files.walkFileTree(Paths.get(args[0]), new SimpleFileVisitor<Path>() {
+
+ @Override
+ public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
+ if (!attrs.isRegularFile()) {
+ return FileVisitResult.CONTINUE;
+ }
+ if (!file.getFileName().equals(DEPENDENCIES)) {
+ return FileVisitResult.CONTINUE;
+ }
+ for (final String line : Files.readAllLines(file, StandardCharsets.UTF_8)) {
+ for (final String dependency : line.split(" ")) {
+ if (dependency == null || dependency.isEmpty()) {
+ continue;
+ }
+ final String[] arr = dependency.split(":");
+ if (arr.length != 5 || blacklist.contains(arr[0] + ":" + arr[1])) {
+ continue;
+ }
+ dependencies.add(dependency);
+ }
+ }
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ for (final String dependency : dependencies) {
+ System.out.println(dependency);
+ }
+ }
+} \ No newline at end of file
diff --git a/container-dev-builder/tools/src/main/java/com/yahoo/container/dev/builder/PomFileGenerator.java b/container-dev-builder/tools/src/main/java/com/yahoo/container/dev/builder/PomFileGenerator.java
new file mode 100644
index 00000000000..f281bc4d7da
--- /dev/null
+++ b/container-dev-builder/tools/src/main/java/com/yahoo/container/dev/builder/PomFileGenerator.java
@@ -0,0 +1,50 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.dev.builder;
+
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.TreeSet;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
+ */
+public class PomFileGenerator {
+
+ public static void main(String[] args) throws IOException {
+ Model model = new Model();
+ model.setModelVersion("4.0.0");
+ model.setGroupId("com.yahoo.vespa");
+ model.setArtifactId("container-dev");
+ model.setVersion(args[0]);
+ model.getProperties().setProperty("project.build.sourceEncoding", StandardCharsets.UTF_8.name());
+ for (String str : new TreeSet<>(Arrays.asList(args).subList(1, args.length))) {
+ Dependency dependency = newDependency(str);
+ if (dependency == null) {
+ continue;
+ }
+ if (dependency.getGroupId().equals(model.getGroupId()) &&
+ dependency.getArtifactId().equals(model.getArtifactId())) {
+ continue;
+ }
+ model.addDependency(dependency);
+ }
+ new MavenXpp3Writer().write(System.out, model);
+ }
+
+ private static Dependency newDependency(String str) {
+ String[] arr = str.split(":");
+ if (arr.length != 5) {
+ return null;
+ }
+ Dependency out = new Dependency();
+ out.setGroupId(arr[0]);
+ out.setArtifactId(arr[1]);
+ out.setVersion(arr[3]);
+ return out;
+ }
+}
diff --git a/container-dev-builder/tools/src/main/java/com/yahoo/container/dev/builder/PreinstalledBundleResolver.java b/container-dev-builder/tools/src/main/java/com/yahoo/container/dev/builder/PreinstalledBundleResolver.java
new file mode 100644
index 00000000000..33717615d3a
--- /dev/null
+++ b/container-dev-builder/tools/src/main/java/com/yahoo/container/dev/builder/PreinstalledBundleResolver.java
@@ -0,0 +1,79 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.dev.builder;
+
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.jar.Manifest;
+
+public class PreinstalledBundleResolver {
+
+ private static final Path MANIFEST_MF = Paths.get("MANIFEST.MF");
+ private static final String X_JDISC_PREINSTALL_BUNDLE = "X-JDisc-Preinstall-Bundle";
+ private static final String REMOVABLE_SUFFIX = ".jar";
+ private static final String REMOVABLE_ASSEMBLY_ID = "-jar-with-dependencies";
+
+ public static void main(final String[] args) throws Throwable {
+ Files.walkFileTree(Paths.get(args[0]), new SimpleFileVisitor<Path>() {
+
+ @Override
+ public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
+ if (!attrs.isRegularFile()) {
+ return FileVisitResult.CONTINUE;
+ }
+ if (!file.getFileName().equals(MANIFEST_MF)) {
+ return FileVisitResult.CONTINUE;
+ }
+ final String preinstall = new Manifest(Files.newInputStream(file))
+ .getMainAttributes()
+ .getValue(X_JDISC_PREINSTALL_BUNDLE);
+ if (preinstall == null) {
+ return FileVisitResult.CONTINUE;
+ }
+ for (String bundle : preinstall.split(",")) {
+ printDependency(args[1], bundle);
+ }
+ return super.visitFile(file, attrs);
+ }
+ });
+ }
+
+ private static void printDependency(String pomFormat, String bundle) throws IOException {
+ bundle = bundle.trim();
+ if (bundle.isEmpty()) {
+ return;
+ }
+ if (bundle.endsWith(REMOVABLE_SUFFIX)) {
+ bundle = bundle.substring(0, bundle.length() - REMOVABLE_SUFFIX.length());
+ }
+ if (bundle.endsWith(REMOVABLE_ASSEMBLY_ID)) {
+ bundle = bundle.substring(0, bundle.length() - REMOVABLE_ASSEMBLY_ID.length());
+ }
+ Path pom = Paths.get(String.format(pomFormat, bundle));
+ if (!Files.exists(pom)) {
+ return;
+ }
+ Model model;
+ try {
+ model = new MavenXpp3Reader().read(Files.newBufferedReader(pom, StandardCharsets.UTF_8));
+ } catch (XmlPullParserException e) {
+ e.printStackTrace();
+ return;
+ }
+ model.setPomFile(pom.toFile());
+ final MavenProject project = new MavenProject(model);
+ System.out.println(project.getGroupId() + ":" +
+ project.getArtifactId() + ":jar:" +
+ project.getVersion() + ":compile");
+ }
+}