diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /container-dev-builder |
Publish
Diffstat (limited to 'container-dev-builder')
7 files changed, 316 insertions, 0 deletions
diff --git a/container-dev-builder/OWNERS b/container-dev-builder/OWNERS new file mode 100644 index 00000000000..3b2ba1ede81 --- /dev/null +++ b/container-dev-builder/OWNERS @@ -0,0 +1 @@ +gjoranv diff --git a/container-dev-builder/dependency_blacklist b/container-dev-builder/dependency_blacklist new file mode 100644 index 00000000000..7b0d647464d --- /dev/null +++ b/container-dev-builder/dependency_blacklist @@ -0,0 +1,2 @@ +antlr:antlr +junit:junit diff --git a/container-dev-builder/make.sh b/container-dev-builder/make.sh new file mode 100755 index 00000000000..ccecebdaed3 --- /dev/null +++ b/container-dev-builder/make.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +export VERSION=$1 +if [ -z "$VERSION" ] +then + echo "usage: $(basename $0) <version> [<builddir>]" + exit 1 +fi +echo VERSION=$VERSION + +export BASEDIR=$2 +if [ "$BASEDIR" ] +then + export POM_FORMAT="$BASEDIR/%s-HEAD/%s/pom.xml" +else + export POM_FORMAT="$(pwd)/../%s/pom.xml" +fi +echo POM_FORMAT=$POM_FORMAT +echo + +echo "-------------------------------------------------------------------------------" +echo "Compiling toolkit." +echo "-------------------------------------------------------------------------------" +cd tools +mvn -q clean install -DskipTests +JAVA_TOOLS="java -cp $(pwd)/target/tools-jar-with-dependencies.jar" +echo +cd .. + +DEPS_NEXT="com.yahoo.vespa:container-disc:jar:$VERSION:compile" +DEPS_PREV="" +BLACKLIST=$(cat dependency_blacklist) + +PASS=0 +rm -rf target +mkdir target +cd target +while [ "$DEPS_NEXT" ] +do + PASS=$((PASS+1)) + mkdir -p "pass$PASS" + cd "pass$PASS" + + DEPS_PREV=$DEPS_NEXT + DEPS_NEXT="" + + echo "-------------------------------------------------------------------------------" + echo "Deriving dependencies, pass $PASS." + echo "-------------------------------------------------------------------------------" + echo DEPENDENCIES=$DEPS_PREV + echo "Building dependency tree.." + $JAVA_TOOLS com.yahoo.container.dev.builder.PomFileGenerator $VERSION $DEPS_PREV > pom.xml + mvn -q dependency:tree -DoutputFile=dependencies + DEPS_NEXT="$($JAVA_TOOLS com.yahoo.container.dev.builder.DependencyResolver . $BLACKLIST)" + + echo "Resolving X-JDisc-Preinstall-Bundle instructions.." + mvn -q dependency:unpack-dependencies \ + -DexcludeTransitive=true \ + -Dmdep.unpack.includes="META-INF/MANIFEST.MF" \ + -Dmdep.useSubDirectoryPerArtifact=true \ + -DoutputDirectory=. + DEPS_NEXT="$DEPS_NEXT $($JAVA_TOOLS com.yahoo.container.dev.builder.PreinstalledBundleResolver . "$POM_FORMAT")" + + DEPS_NEXT=$(echo $DEPS_NEXT | sort | uniq) + [ "$DEPS_NEXT" == "$DEPS_PREV" ] && DEPS_NEXT="" + echo + cd .. +done + +echo "-------------------------------------------------------------------------------" +echo "Testing final pom.xml" +echo "-------------------------------------------------------------------------------" +cp pass$PASS/pom.xml . +mvn clean install -DskipTests || exit 1 +cd .. 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"); + } +} |