Skip to content

Commit

Permalink
Build dist jars using buck
Browse files Browse the repository at this point in the history
At least for the client jar.
  • Loading branch information
shs96c committed Sep 19, 2017
1 parent 49305c8 commit 043e445
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 22 deletions.
11 changes: 11 additions & 0 deletions .idea/libraries/javaparser.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ end


task :'prep-release-zip' => [
'//java/client/src/org/openqa/selenium:client-combined:zip',
'//java/client/src/org/openqa/selenium:client-combined-zip',
'//java/server/src/org/openqa/grid/selenium:selenium:zip',
'//java/server/src/org/openqa/selenium/server/htmlrunner:selenium-runner'] do

Expand All @@ -451,9 +451,7 @@ task :'prep-release-zip' => [
cp Rake::Task['//java/server/src/org/openqa/grid/selenium:selenium:zip'].out, "build/dist/selenium-server-#{version}.zip"
`jar uf build/dist/selenium-server-#{version}.zip NOTICE LICENSE`
`cd java && jar uf ../build/dist/selenium-server-#{version}.zip CHANGELOG`
cp Rake::Task['//java/client/src/org/openqa/selenium:client-combined:zip'].out, "build/dist/selenium-java-#{version}.zip"
`jar uf build/dist/selenium-java-#{version}.zip NOTICE LICENSE`
`cd java && jar uf ../build/dist/selenium-server-#{version}.zip CHANGELOG`
cp Rake::Task['//java/client/src/org/openqa/selenium:client-combined-zip'].out, "build/dist/selenium-java-#{version}.zip"
cp Rake::Task['//java/server/src/org/openqa/selenium/server/htmlrunner:selenium-runner'].out, "build/dist/selenium-html-runner-#{version}.jar"
end

Expand Down
1 change: 1 addition & 0 deletions java/client/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@
<classpathentry kind="lib" path="/third-party/java/testng/testng-6.9.9.jar" sourcepath="/third-party/java/testng/testng-6.9.9-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/github/org.eclipse.egit.github.core-2.1.5.jar" sourcepath="/third-party/java/github/org.eclipse.egit.github.core-2.1.5.jar-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/bytebuddy/byte-buddy-1.7.5.jar" sourcepath="/third-party/java/bytebuddy/byte-buddy-1.7.5-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/javaparser/javaparser-core-3.4.0.jar" sourcepath="/third-party/java/javaparser/javaparser-core-3.4.0-sources.jar"/>
<classpathentry kind="output" path="build/production"/>
</classpath>
2 changes: 1 addition & 1 deletion java/client/client.iml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="byte-buddy" level="project" />
<orderEntry type="library" name="cglib" level="project" />
<orderEntry type="library" scope="RUNTIME" name="commons-codec" level="project" />
<orderEntry type="library" scope="RUNTIME" name="commons-collections" level="project" />
<orderEntry type="library" name="commons-exec" level="project" />
Expand Down Expand Up @@ -49,6 +48,7 @@
<orderEntry type="library" scope="TEST" name="websocket" level="project" />
<orderEntry type="library" scope="TEST" name="jetty-util" level="project" />
<orderEntry type="library" scope="TEST" name="github" level="project" />
<orderEntry type="library" name="javaparser" level="project" />
</component>
<component name="sonarModuleSettings">
<option name="alternativeWorkingDirPath" value="" />
Expand Down
55 changes: 38 additions & 17 deletions java/client/src/org/openqa/selenium/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ java_library(name = 'selenium',
visibility = ['PUBLIC'],
)

export_file(
name = 'template-pom',
src = 'pom.xml',
out = 'pom.xml',
visibility = ['PUBLIC'],
)

java_library(name = 'core',
maven_coords = 'org.seleniumhq.selenium:selenium-api:' + SE_VERSION,
maven_pom_template = ':template-pom',
Expand Down Expand Up @@ -186,6 +193,22 @@ java_library(
],
)


# This isn't very elegant, but we can build a dist zip like this:
zip_file(
name = 'client-combined-zip',
out = 'selenium-java-' + SE_VERSION + '.zip',
srcs = [
':client-combined-' + SE_VERSION,
':client-combined-source-zip',
':client-libs',
'//java:changelog',
'//:notice',
'//:license',
],
)

# The jar file containing merged first party code
java_binary(
name = 'client-combined-' + SE_VERSION,
blacklist = [
Expand All @@ -196,29 +219,27 @@ java_binary(
],
)

# Output of this rule is named a source jar so we can do merging later
# The first party source, as a source jar which we don't want merged
genrule(
name = 'client-libs',
out = 'libs-sources.jar',
cmd = 'mkdir libs && echo $(classpath :client-combined) | tr : "\\n" | grep third_party/java | grep .jar | xargs -J % cp % libs && jar cMf $OUT libs/*',
name = 'client-combined-sources',
out = 'client-combined-' + SE_VERSION + '-sources.jar',
cmd = 'mkdir temp && echo $(query_paths "inputs(kind(java_library, deps(//java/client/src/org/openqa/selenium:client-combined)))") | xargs $(exe //java/client/src/org/openqa/selenium/tools:package) $OUT',
)

# So we hide it in another zip file, which will be merged. Zip file merging isn't recursive.
zip_file(
name = 'client-combined-zip',
out = 'selenium-java-' + SE_VERSION + '.zip',
name = 'client-combined-source-zip',
out = 'selenium-java-sources.jar',
merge_source_zips = False,
srcs = [
':client-combined-' + SE_VERSION,
':client-libs',
'//java:changelog',
'//:notice',
'//:license',
':client-combined-sources'
],
)


export_file(
name = 'template-pom',
src = 'pom.xml',
out = 'pom.xml',
visibility = ['PUBLIC'],
# The third party libraries we depend on, as a source jar for merging
genrule(
name = 'client-libs',
out = 'libs-sources.jar',
cmd = 'mkdir libs && echo $(classpath :client-combined) | tr : "\\n" | grep third_party/java | grep .jar | xargs -J % cp % libs && jar cMf $OUT libs/*',
)

20 changes: 20 additions & 0 deletions java/client/src/org/openqa/selenium/tools/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
java_library(
name = "package-lib",
srcs = [
"PackageParser.java",
],
deps = [
"//third_party/java/javaparser:javaparser-core",
],
)

java_binary(
name = "package",
main_class = "org.openqa.selenium.tools.PackageParser",
deps = [
":package-lib",
],
visibility = [
"//java/client/src/org/openqa/selenium:client-combined-sources",
],
)
59 changes: 59 additions & 0 deletions java/client/src/org/openqa/selenium/tools/PackageParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.openqa.selenium.tools;

import com.github.javaparser.JavaParser;
import com.github.javaparser.ast.CompilationUnit;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Calendar;
import java.util.Map;
import java.util.TreeMap;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class PackageParser {
private final static long TIME_STAMP;
static {
Calendar c = Calendar.getInstance();
c.set(1985, 1, 1, 0, 0, 0);
TIME_STAMP = c.getTimeInMillis();
}


public static void main(String[] args) throws IOException {
Path out = Paths.get(args[0]);

Map<String, Path> outToIn = new TreeMap<>();

for (int i = 1; i < args.length; i++) {
Path source = Paths.get(args[i]);
CompilationUnit unit = JavaParser.parse(source);
String packageName = unit.getPackageDeclaration()
.map(decl -> decl.getName().asString())
.orElse("");
Path target = Paths.get(packageName.replace('.', File.separatorChar))
.resolve(source.getFileName());

outToIn.put(target.toString(), source);
}

try (ZipOutputStream zos = new ZipOutputStream(Files.newOutputStream(out))) {
outToIn.forEach((target, source) -> {
ZipEntry entry = new ZipEntry(target);
entry.setMethod(ZipEntry.DEFLATED);
entry.setTime(TIME_STAMP);
try {
zos.putNextEntry(entry);
Files.copy(source, zos);
zos.closeEntry();
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
}

}
10 changes: 10 additions & 0 deletions third_party/java/javaparser/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prebuilt_jar(
name = 'javaparser-core',
maven_coords = 'com.github.javaparser:javaparser-core:jar:3.4.0',
binary_jar = 'javaparser-core-3.4.0.jar',
source_jar = 'javaparser-core-3.4.0-sources.jar',
visibility = [
'//java/client/src/org/openqa/selenium/tools:',
],
)

Binary file not shown.
Binary file not shown.

0 comments on commit 043e445

Please sign in to comment.