Skip to content

Commit

Permalink
[java] Extracting build tools into a separate source subtree and a se…
Browse files Browse the repository at this point in the history
…parate IDEA module to set different source levels for the build tools (11) and the main code (8)
  • Loading branch information
barancev committed Nov 16, 2020
1 parent 0eabe11 commit e22f55f
Show file tree
Hide file tree
Showing 26 changed files with 72 additions and 52 deletions.
1 change: 1 addition & 0 deletions .idea/modules.xml

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

13 changes: 13 additions & 0 deletions java/buildtools/buildtools.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="java" />
<orderEntry type="library" name="maven" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ java_binary(
"-target",
"11",
],
main_class = "dev.selenium.tools.jar.MergeJars",
visibility = [
"//visibility:public",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.tools.jar;
package dev.selenium.tools.jar;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ java_binary(
"-target",
"11",
],
main_class = "org.openqa.selenium.tools.javadoc.JavadocJarMaker",
main_class = "dev.selenium.tools.javadoc.JavadocJarMaker",
visibility = [
"//visibility:public",
],
deps = [
"//java/client/src/org/openqa/selenium/io",
"//java/client/src/org/openqa/selenium/tools/zip",
"//java/buildtools/src/dev/selenium/tools/zip",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.tools.javadoc;
package dev.selenium.tools.javadoc;

import org.openqa.selenium.io.TemporaryFilesystem;
import org.openqa.selenium.tools.zip.StableZipEntry;
import dev.selenium.tools.zip.StableZipEntry;

import javax.tools.DocumentationTool;
import javax.tools.JavaFileObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ java_binary(
"-target",
"11",
],
main_class = "org.openqa.selenium.tools.maven.MavenPublisher",
main_class = "dev.selenium.tools.maven.MavenPublisher",
visibility = ["//visibility:public"],
deps = [
"//java/client/src/org/openqa/selenium/remote",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.tools.maven;
package dev.selenium.tools.maven;

import com.google.common.base.Splitter;
import com.google.common.hash.Hashing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ java_binary(
"-target",
"11",
],
main_class = "org.openqa.selenium.tools.modules.ModuleGenerator",
main_class = "dev.selenium.tools.modules.ModuleGenerator",
visibility = ["//visibility:public"],
deps = [
"//java/client/src/org/openqa/selenium/io",
"//java/client/src/org/openqa/selenium/tools/zip",
"//java/buildtools/src/dev/selenium/tools/zip",
artifact("net.bytebuddy:byte-buddy"),
artifact("com.github.javaparser:javaparser-core"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.tools.modules;
package dev.selenium.tools.modules;

import com.github.javaparser.JavaParser;
import com.github.javaparser.ParseResult;
Expand All @@ -37,7 +37,7 @@
import net.bytebuddy.jar.asm.ModuleVisitor;

import org.openqa.selenium.io.TemporaryFilesystem;
import org.openqa.selenium.tools.zip.StableZipEntry;
import dev.selenium.tools.zip.StableZipEntry;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ java_library(
name = "zip",
srcs = glob(["*.java"]),
visibility = [
"//java/client/src/org/openqa/selenium/tools:__subpackages__",
"//java/buildtools/src/dev/selenium/tools:__subpackages__",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.tools.zip;
package dev.selenium.tools.zip;

import java.nio.file.attribute.FileTime;
import java.time.Instant;
Expand Down
6 changes: 3 additions & 3 deletions java/client/src/org/openqa/selenium/io/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ java_library(
visibility = [
"//java/client/src/org/openqa/selenium/os:__pkg__",
"//java/client/src/org/openqa/selenium/remote:__pkg__",
"//java/client/src/org/openqa/selenium/tools/jar:__pkg__",
"//java/client/src/org/openqa/selenium/tools/javadoc:__pkg__",
"//java/client/src/org/openqa/selenium/tools/modules:__pkg__",
"//java/buildtools/src/dev/selenium/tools/jar:__pkg__",
"//java/buildtools/src/dev/selenium/tools/javadoc:__pkg__",
"//java/buildtools/src/dev/selenium/tools/modules:__pkg__",
"//java/client/test/org/openqa/selenium/io:__pkg__",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public ByMagic(String magicWord) {

@Override
public List<WebElement> findElements(SearchContext context) {
return List.of(((FindByMagic) context).findByMagic(magicWord));
return Collections.singletonList(((FindByMagic) context).findByMagic(magicWord));
}
}

Expand Down
2 changes: 1 addition & 1 deletion java/client/test/org/openqa/selenium/testing/Safely.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void safelyCall(TearDownFixture... fixtures) {
}

try {
CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new));
CompletableFuture.allOf(futures.toArray(new CompletableFuture[]{}));
} finally {
executor.shutdownNow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ load("//java:defs.bzl", "java_test_suite")
# "9",
# ],
# deps = [
# "//java/client/src/org/openqa/selenium/tools/modules:ModuleGenerator",
# "//java/buildtools/src/dev/selenium/tools/modules:ModuleGenerator",
# "//third_party/java/assertj",
# "//third_party/java/bytebuddy:byte-buddy",
# "//third_party/java/guava",
Expand Down
2 changes: 1 addition & 1 deletion java/java.iml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/build/production" />
<output-test url="file://$MODULE_DIR$/build/test" />
<exclude-output />
Expand Down
2 changes: 1 addition & 1 deletion java/private/artifact.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ _maven_artifacts = rule(
"_singlejar": attr.label(
executable = True,
cfg = "host",
default = "//java/client/src/org/openqa/selenium/tools/jar:MergeJars",
default = "//java/buildtools/src/dev/selenium/tools/jar:MergeJars",
allow_files = True,
),
"binjar": attr.output(),
Expand Down
2 changes: 1 addition & 1 deletion java/private/javadoc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ javadoc = rule(
"transitive": attr.bool(),
"third_party_prefixes": attr.string_list(),
"_javadoc": attr.label(
default = "//java/client/src/org/openqa/selenium/tools/javadoc",
default = "//java/buildtools/src/dev/selenium/tools/javadoc",
cfg = "host",
executable = True,
),
Expand Down
6 changes: 3 additions & 3 deletions java/private/maven_artifacts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ maven_artifacts = rule(
],
),
"_javadoc": attr.label(
default = "//java/client/src/org/openqa/selenium/tools/javadoc",
default = "//java/buildtools/src/dev/selenium/tools/javadoc",
cfg = "host",
executable = True,
),
"_singlejar": attr.label(
executable = True,
cfg = "host",
default = "//java/client/src/org/openqa/selenium/tools/jar:MergeJars",
default = "//java/buildtools/src/dev/selenium/tools/jar:MergeJars",
allow_files = True,
),
"_uploader": attr.label(
executable = True,
cfg = "host",
default = "//java/client/src/org/openqa/selenium/tools/maven:MavenPublisher",
default = "//java/buildtools/src/dev/selenium/tools/maven:MavenPublisher",
allow_files = True,
),
},
Expand Down
4 changes: 2 additions & 2 deletions java/private/module.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ java_module = rule(
default = "@bazel_tools//tools/jdk:current_java_toolchain",
),
"_merge_jars": attr.label(
default = "//java/client/src/org/openqa/selenium/tools/jar:MergeJars",
default = "//java/buildtools/src/dev/selenium/tools/jar:MergeJars",
executable = True,
cfg = "host",
),
"_module_generator": attr.label(
default = "//java/client/src/org/openqa/selenium/tools/modules:ModuleGenerator",
default = "//java/buildtools/src/dev/selenium/tools/modules:ModuleGenerator",
executable = True,
cfg = "host",
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public SecretOptions(Config config) {

public Secret getRegistrationSecret() {
String secret = "";
if ((isSecure() || isSelfSigned()) && config.get(SERVER_SECTION, "registration-secret").isEmpty()) {
if ((isSecure() || isSelfSigned()) && !config.get(SERVER_SECTION, "registration-secret").isPresent()) {
try {
secret = getEncoder().encodeToString(Arrays.copyOfRange(Files.readAllBytes(getCertificate().toPath()), 0, 32));
return new Secret(secret);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.net.URISyntaxException;
import java.time.Instant;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -69,6 +70,8 @@
import static org.openqa.selenium.remote.http.HttpMethod.GET;
import static org.openqa.selenium.remote.http.HttpMethod.POST;

import com.google.common.collect.ImmutableMap;

public class GraphqlHandlerTest {

private final Secret registrationSecret = new Secret("stilton");
Expand Down Expand Up @@ -117,7 +120,7 @@ public void shouldBeAbleToGetGridUri() {

Map<String, Object> topLevel = executeQuery(handler, "{ grid { uri } }");

assertThat(topLevel).isEqualTo(Map.of("data", Map.of("grid", Map.of("uri", publicUri.toString()))));
assertThat(topLevel).isEqualTo(Collections.singletonMap("data", Collections.singletonMap("grid", Collections.singletonMap("uri", publicUri.toString()))));
}

@Test
Expand All @@ -128,7 +131,7 @@ public void shouldReturnAnEmptyListForNodesIfNoneAreRegistered() {

assertThat(topLevel)
.describedAs(topLevel.toString())
.isEqualTo(Map.of("data", Map.of("grid", Map.of("nodes", List.of()))));
.isEqualTo(Collections.singletonMap("data", Collections.singletonMap("grid", Collections.singletonMap("nodes", Collections.emptyMap()))));
}

@Test
Expand Down Expand Up @@ -156,7 +159,7 @@ public boolean test(Capabilities capabilities) {

assertThat(topLevel)
.describedAs(topLevel.toString())
.isEqualTo(Map.of("data", Map.of("grid", Map.of("nodes", List.of(Map.of("uri", nodeUri))))));
.isEqualTo(Collections.singletonMap("data", Collections.singletonMap("grid", Collections.singletonMap("nodes", Collections.singletonList(Collections.singletonMap("uri", nodeUri))))));
}

@Test
Expand Down Expand Up @@ -198,9 +201,9 @@ public void shouldBeAbleToGetSessionInfo() throws URISyntaxException {

assertThat(result)
.describedAs(result.toString())
.isEqualTo(Map.of(
"data", Map.of("session",
Map.of("id", sessionId,
.isEqualTo(Collections.singletonMap(
"data", Collections.singletonMap("session",
ImmutableMap.of("id", sessionId,
"capabilities", graphqlSession.getCapabilities(),
"startTime", graphqlSession.getStartTime(),
"uri", graphqlSession.getUri().toString()))));
Expand Down Expand Up @@ -245,9 +248,9 @@ public void shouldBeAbleToGetNodeInfoForSession() throws URISyntaxException {

assertThat(result)
.describedAs(result.toString())
.isEqualTo(Map.of(
"data", Map.of("session",
Map.of("nodeId", graphqlSession.getNodeId(),
.isEqualTo(Collections.singletonMap(
"data", Collections.singletonMap("session",
ImmutableMap.of("nodeId", graphqlSession.getNodeId(),
"nodeUri",
graphqlSession.getNodeUri().toString()))));
}
Expand Down Expand Up @@ -295,13 +298,13 @@ public void shouldBeAbleToGetSlotInfoForSession() throws URISyntaxException {

assertThat(result)
.describedAs(result.toString())
.isEqualTo(Map.of(
"data", Map.of("session",
Map.of("slot",
Map.of("id", graphqlSlot.getId(),
"stereotype", graphqlSlot.getStereotype(),
"lastStarted",
graphqlSlot.getLastStarted())))));
.isEqualTo(Collections.singletonMap(
"data", Collections.singletonMap("session",
Collections.singletonMap("slot",
ImmutableMap.of("id", graphqlSlot.getId(),
"stereotype", graphqlSlot.getStereotype(),
"lastStarted",
graphqlSlot.getLastStarted())))));
}

@Test
Expand Down Expand Up @@ -402,7 +405,7 @@ public void shouldThrowExceptionWhenSessionIsEmpty() throws URISyntaxException {
private Map<String, Object> executeQuery(HttpHandler handler, String query) {
HttpResponse res = handler.execute(
new HttpRequest(GET, "/graphql")
.setContent(Contents.asJson(Map.of("query", query))));
.setContent(Contents.asJson(Collections.singletonMap("query", query))));

return new Json().toType(Contents.string(res), MAP_TYPE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.openqa.selenium.testing.drivers.WebDriverBuilder;

import java.time.Duration;
import java.util.Collections;
import java.util.Map;

import static org.junit.Assert.assertEquals;
Expand All @@ -50,6 +51,8 @@
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
import static org.openqa.selenium.testing.Safely.safelyCall;

import com.google.common.collect.ImmutableMap;

public class ConsolePageTest {

private Server<?> server;
Expand Down Expand Up @@ -94,11 +97,9 @@ private Server<?> createStandalone() {
int port = PortProber.findFreePort();

Config config = new MemoizedConfig(
new MapConfig(Map.of(
"server", Map.of(
"port", port),
"node", Map.of(
"detect-drivers", true))));
new MapConfig(ImmutableMap.of(
"server", Collections.singletonMap("port", port),
"node", Collections.singletonMap("detect-drivers", true))));

Server<?> server = new Standalone().asServer(config).start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import java.net.URISyntaxException;
import java.time.Instant;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -58,7 +59,7 @@
public class ProxyCdpTest {

private final HttpHandler nullHandler = req -> new HttpResponse();
private final Config emptyConfig = new MapConfig(Map.of());
private final Config emptyConfig = new MapConfig(Collections.emptyMap());
private Server<?> proxyServer;
private SessionMap sessions;

Expand Down
Loading

0 comments on commit e22f55f

Please sign in to comment.