Skip to content

Commit

Permalink
Build selenium server dist jar using buck
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Sep 19, 2017
1 parent 043e445 commit 500f3e1
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 12 deletions.
6 changes: 2 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,12 @@ end

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

mkdir_p "build/dist"
cp Rake::Task['//java/server/src/org/openqa/grid/selenium:selenium'].out, "build/dist/selenium-server-standalone-#{version}.jar"
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/server/src/org/openqa/grid/selenium:selenium-zip'].out, "build/dist/selenium-server-#{version}.zip"
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/src/org/openqa/selenium/tools/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ java_binary(
],
visibility = [
"//java/client/src/org/openqa/selenium:client-combined-sources",
"//java/server/src/org/openqa/grid/selenium:selenium-server-sources",
],
)
25 changes: 17 additions & 8 deletions java/client/src/org/openqa/selenium/tools/PackageParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.openqa.selenium.tools;

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

import java.io.File;
Expand Down Expand Up @@ -30,14 +31,22 @@ public static void main(String[] args) throws IOException {

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);
if (!source.getFileName().toString().endsWith(".java")) {
continue;
}

try {
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);
} catch (ParseProblemException ignored) {
// carry on
}
}

try (ZipOutputStream zos = new ZipOutputStream(Files.newOutputStream(out))) {
Expand Down
49 changes: 49 additions & 0 deletions java/server/src/org/openqa/grid/selenium/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,52 @@ java_library(name = 'classes',
'//java/server/test/org/openqa/grid/e2e:tests',
],
)

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

# The jar file containing merged first party code
java_binary(
name = 'selenium-' + SE_VERSION + '-nodeps',
blacklist = [
'^(?!com.thoughtworks.selenium.*|org.openqa.selenium.*|org.openqa.grid.*)',
],
deps = [
':selenium',
],
)

# The first party source, as a source jar which we don't want merged
genrule(
name = 'selenium-server-sources',
out = 'selenium-' + SE_VERSION + '-nodeps-sources.jar',
cmd = 'mkdir temp && echo $(query_paths "inputs(kind(java_library, deps(:selenium)))") | 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 = 'selenium-server-source-zip',
out = 'selenium-server-sources.jar',
merge_source_zips = False,
srcs = [
':selenium-server-sources'
],
)

# The third party libraries we depend on, as a source jar for merging
genrule(
name = 'server-libs',
out = 'server-libs-sources.jar',
cmd = 'mkdir libs && echo $(classpath :selenium) | tr : "\\n" | grep third_party/java | grep .jar | xargs -J % cp % libs && jar cMf $OUT libs/*',
)

0 comments on commit 500f3e1

Please sign in to comment.