Skip to content

Commit edd24f7

Browse files
committed
Implementing distribution package building in platform independent manner. xargs has various set of command line options on linux/windows/macos. Windows has command line length restriction = 2048 symbols.
1 parent e649643 commit edd24f7

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

java/client/src/org/openqa/selenium/BUCK

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ java_binary(
226226
genrule(
227227
name = 'client-combined-sources',
228228
out = 'client-combined-' + SE_VERSION + '-sources.jar',
229-
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',
229+
cmd = 'mkdir temp && $(exe //java/client/src/org/openqa/selenium/tools:package) $OUT $(@query_paths "inputs(kind(java_library, deps(//java/client/src/org/openqa/selenium:client-combined)))")',
230230
)
231231

232232
# So we hide it in another zip file, which will be merged. Zip file merging isn't recursive.
@@ -243,6 +243,6 @@ zip_file(
243243
genrule(
244244
name = 'client-libs',
245245
out = 'libs-sources.jar',
246-
cmd = 'mkdir libs && echo $(classpath :client-combined) | tr : "\\n" | grep third_party/java | grep .jar | xargs -J % cp % libs && jar cMf $OUT libs/*',
246+
cmd = 'mkdir libs && python -c "import sys,shutil;map(lambda f:shutil.copy(f,\'libs\'),[l for l in open(sys.argv[1][1:]).read().split(\';\' if sys.platform.startswith(\'win\') else \':\') if l.endswith(\'.jar\') and \'third_party/java\' in l.replace(\'\\\\\',\'/\')])" $(@classpath :client-combined) && jar cMf $OUT libs/*',
247247
)
248248

java/client/src/org/openqa/selenium/tools/BUCK

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ java_library(
66
],
77
deps = [
88
"//third_party/java/javaparser:javaparser-core",
9+
"//third_party/java/guava:guava",
910
],
1011
)
1112

java/client/src/org/openqa/selenium/tools/PackageParser.java

+30-15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.openqa.selenium.tools;
1919

20+
import com.google.common.collect.ImmutableMap;
21+
2022
import com.github.javaparser.JavaParser;
2123
import com.github.javaparser.ParseProblemException;
2224
import com.github.javaparser.ast.CompilationUnit;
@@ -29,6 +31,8 @@
2931
import java.util.Calendar;
3032
import java.util.Map;
3133
import java.util.TreeMap;
34+
import java.util.stream.Collectors;
35+
import java.util.stream.Stream;
3236
import java.util.zip.ZipEntry;
3337
import java.util.zip.ZipOutputStream;
3438

@@ -40,32 +44,43 @@ public class PackageParser {
4044
TIME_STAMP = c.getTimeInMillis();
4145
}
4246

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

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

4952
for (int i = 1; i < args.length; i++) {
50-
Path source = Paths.get(args[i]);
51-
if (!source.getFileName().toString().endsWith(".java")) {
52-
continue;
53+
if (args[i].startsWith("@")) {
54+
Path macro = Paths.get(args[i].substring(1));
55+
Stream.of(Files.lines(macro).collect(Collectors.joining(" ")).split(" "))
56+
.forEach(line -> outToIn.putAll(processSingleSourceFile(Paths.get(line))));
57+
58+
} else {
59+
outToIn.putAll(processSingleSourceFile(Paths.get(args[i])));
5360
}
61+
}
5462

55-
try {
56-
CompilationUnit unit = JavaParser.parse(source);
57-
String packageName = unit.getPackageDeclaration()
58-
.map(decl -> decl.getName().asString())
59-
.orElse("");
60-
Path target = Paths.get(packageName.replace('.', File.separatorChar))
61-
.resolve(source.getFileName());
63+
zip(outToIn, out);
64+
}
6265

63-
outToIn.put(target.toString(), source);
64-
} catch (ParseProblemException ignored) {
65-
// carry on
66-
}
66+
private static Map<String, Path> processSingleSourceFile(Path source) {
67+
if (!source.getFileName().toString().endsWith(".java")) {
68+
return ImmutableMap.of();
6769
}
70+
try {
71+
CompilationUnit unit = JavaParser.parse(source);
72+
String packageName = unit.getPackageDeclaration()
73+
.map(decl -> decl.getName().asString())
74+
.orElse("");
75+
Path target = Paths.get(packageName.replace('.', File.separatorChar))
76+
.resolve(source.getFileName());
77+
return ImmutableMap.of(target.toString(), source);
78+
} catch (ParseProblemException|IOException ignored) {
79+
return ImmutableMap.of();
80+
}
81+
}
6882

83+
private static void zip(Map<String, Path> outToIn, Path out) throws IOException {
6984
try (ZipOutputStream zos = new ZipOutputStream(Files.newOutputStream(out))) {
7085
outToIn.forEach((target, source) -> {
7186
ZipEntry entry = new ZipEntry(target);

java/server/src/org/openqa/grid/selenium/BUCK

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ java_binary(
7474
genrule(
7575
name = 'selenium-server-sources',
7676
out = 'selenium-' + SE_VERSION + '-nodeps-sources.jar',
77-
cmd = 'mkdir temp && echo $(query_paths "inputs(kind(java_library, deps(:selenium)))") | xargs $(exe //java/client/src/org/openqa/selenium/tools:package) $OUT',
77+
cmd = 'mkdir temp && $(exe //java/client/src/org/openqa/selenium/tools:package) $OUT $(@query_paths "inputs(kind(java_library, deps(:selenium)))")',
7878
)
7979

8080
# So we hide it in another zip file, which will be merged. Zip file merging isn't recursive.
@@ -91,5 +91,5 @@ zip_file(
9191
genrule(
9292
name = 'server-libs',
9393
out = 'server-libs-sources.jar',
94-
cmd = 'mkdir libs && echo $(classpath :selenium) | tr : "\\n" | grep third_party/java | grep .jar | xargs -J % cp % libs && jar cMf $OUT libs/*',
94+
cmd = 'mkdir libs && python -c "import sys,shutil;map(lambda f:shutil.copy(f,\'libs\'),[l for l in open(sys.argv[1][1:]).read().split(\';\' if sys.platform.startswith(\'win\') else \':\') if l.endswith(\'.jar\') and \'third_party/java\' in l.replace(\'\\\\\',\'/\')])" $(@classpath :selenium) && jar cMf $OUT libs/*',
9595
)

0 commit comments

Comments
 (0)