Skip to content

Commit

Permalink
reduce usage of Guava (#5038)
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Nesen <[email protected]>
  • Loading branch information
senivam committed Apr 20, 2022
1 parent b0e7b1e commit b8e7c8b
Show file tree
Hide file tree
Showing 28 changed files with 89 additions and 211 deletions.
7 changes: 1 addition & 6 deletions connectors/apache-connector/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2011, 2022 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -55,11 +55,6 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
5 changes: 0 additions & 5 deletions connectors/apache5-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
7 changes: 1 addition & 6 deletions connectors/jetty-connector/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2011, 2022 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -66,11 +66,6 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
7 changes: 1 addition & 6 deletions connectors/netty-connector/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2016, 2022 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -49,11 +49,6 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
7 changes: 4 additions & 3 deletions containers/jdk-http/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -34,9 +34,10 @@

<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>test</scope>
<version>${commons.io.version}</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -30,15 +30,14 @@
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException;

import org.apache.commons.io.IOUtils;
import org.glassfish.jersey.SslConfigurator;
import org.glassfish.jersey.internal.util.JdkVersion;
import org.glassfish.jersey.server.ResourceConfig;

import org.junit.After;
import org.junit.Test;

import com.google.common.io.ByteStreams;

import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
Expand Down Expand Up @@ -188,9 +187,9 @@ private SSLContext getClientSslContext() throws IOException {


final SslConfigurator sslConfigClient = SslConfigurator.newInstance()
.trustStoreBytes(ByteStreams.toByteArray(trustStore))
.trustStoreBytes(IOUtils.toByteArray(trustStore))
.trustStorePassword(TRUSTSTORE_CLIENT_PWD)
.keyStoreBytes(ByteStreams.toByteArray(keyStore))
.keyStoreBytes(IOUtils.toByteArray(keyStore))
.keyPassword(KEYSTORE_CLIENT_PWD);

return sslConfigClient.createSSLContext();
Expand All @@ -201,9 +200,9 @@ private SSLContext getServerSslContext() throws IOException {
final InputStream keyStore = JdkHttpsServerTest.class.getResourceAsStream(KEYSTORE_SERVER_FILE);

final SslConfigurator sslConfigServer = SslConfigurator.newInstance()
.keyStoreBytes(ByteStreams.toByteArray(keyStore))
.keyStoreBytes(IOUtils.toByteArray(keyStore))
.keyPassword(KEYSTORE_SERVER_PWD)
.trustStoreBytes(ByteStreams.toByteArray(trustStore))
.trustStoreBytes(IOUtils.toByteArray(trustStore))
.trustStorePassword(TRUSTSTORE_SERVER_PWD);

return sslConfigServer.createSSLContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -12,6 +12,8 @@

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
Expand All @@ -31,8 +33,6 @@
import org.glassfish.jersey.server.ManagedAsync;
import org.glassfish.jersey.server.Uri;

import com.google.common.collect.Lists;
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
Expand Down Expand Up @@ -80,7 +80,7 @@ public void onSuccess(final List<AgentResponse> result) {
public void onFailure(final Throwable t) {
async.resume(t);
}
});
}, Executors.newSingleThreadExecutor());
}

private ListenableFuture<AgentResponse> visited(final AgentResponse response) {
Expand All @@ -97,11 +97,11 @@ private ListenableFuture<AgentResponse> visited(final AgentResponse response) {
});

// ... and set them to the final response.
return Futures.transform(visited, (AsyncFunction<List<Destination>, AgentResponse>) destinations -> {
return Futures.transform(visited, destinations -> {
response.setVisited(destinations);

return Futures.immediateFuture(response);
});
return response;
}, Executors.newSingleThreadExecutor());
}

private ListenableFuture<AgentResponse> recommended(final AgentResponse response) {
Expand All @@ -120,15 +120,14 @@ private ListenableFuture<AgentResponse> recommended(final AgentResponse response

// ... transform them to Recommendation instances ...
final ListenableFuture<List<Recommendation>> recommendations = Futures.transform(
destinations,
(AsyncFunction<List<Destination>, List<Recommendation>>) destinationList -> {
destinations, destinationList -> {
// Create new array list to avoid multiple remote calls.
final List<Recommendation> recommendationList = Lists.newArrayList(Lists.transform(
destinationList,
destination -> new Recommendation(destination.getDestination(), null, 0)));
final List<Recommendation> recommendationList = destinationList.stream().map(
destination -> new Recommendation(destination.getDestination(), null, 0))
.collect(Collectors.toList());

return Futures.immediateFuture(recommendationList);
});
return recommendationList;
}, Executors.newSingleThreadExecutor());

// ... add forecasts and calculations ...
final ListenableFuture<List<List<Recommendation>>> filledRecommendations = Futures
Expand All @@ -140,47 +139,51 @@ private ListenableFuture<AgentResponse> recommended(final AgentResponse response

// ... and transform the list into agent response with filled recommendations.
return Futures
.transform(filledRecommendations, (AsyncFunction<List<List<Recommendation>>, AgentResponse>) input -> {
.transform(filledRecommendations, input -> {
response.setRecommended(input.get(0));

return Futures.immediateFuture(response);
});
return response;
}, Executors.newSingleThreadExecutor());
}

private ListenableFuture<List<Recommendation>> forecasts(final ListenableFuture<List<Recommendation>> recommendations) {
forecast.register(RxListenableFutureInvokerProvider.class);

// Fill the list with weather forecast.
return Futures.transform(recommendations, (AsyncFunction<List<Recommendation>, List<Recommendation>>) list ->
return Futures.transform(recommendations, list ->
// For each recommendation ...
Futures.successfulAsList(Lists.transform(list, recommendation -> Futures.transform(
(List<Recommendation>) Futures.successfulAsList(list.stream().map(recommendation -> Futures.transform(
// ... get the weather forecast ...
forecast.resolveTemplate("destination", recommendation.getDestination()).request()
.rx(RxListenableFutureInvoker.class)
.get(Forecast.class),
// ... and set it to the recommendation.
(AsyncFunction<Forecast, Recommendation>) forecast -> {
forecast -> {
recommendation.setForecast(forecast.getForecast());
return Futures.immediateFuture(recommendation);
}))));
return recommendation;
},
Executors.newSingleThreadExecutor())).collect(Collectors.toList())),
Executors.newSingleThreadExecutor());
}

private ListenableFuture<List<Recommendation>> calculations(final ListenableFuture<List<Recommendation>> recommendations) {
calculation.register(RxListenableFutureInvokerProvider.class);

// Fill the list with price calculations.
return Futures.transform(recommendations, (AsyncFunction<List<Recommendation>, List<Recommendation>>) list ->
return Futures.transform(recommendations, list ->
// For each recommendation ...
Futures.successfulAsList(Lists.transform(list, recommendation -> Futures.transform(
(List<Recommendation>) Futures.successfulAsList(list.stream().map(recommendation -> Futures.transform(
// ... get the price calculation ...
calculation.resolveTemplate("from", "Moon")
.resolveTemplate("to", recommendation.getDestination())
.request().rx(RxListenableFutureInvoker.class).get(Calculation.class),
// ... and set it to the recommendation.
(AsyncFunction<Calculation, Recommendation>) calculation -> {
calculation -> {
recommendation.setPrice(calculation.getPrice());
return Futures.immediateFuture(recommendation);
})))
return recommendation;
},
Executors.newSingleThreadExecutor())).collect(Collectors.toList())),
Executors.newSingleThreadExecutor()
);
}
}
3 changes: 2 additions & 1 deletion ext/rx/rx-client-guava/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
Copyright (c) 2014, 2021 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014, 2022 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -41,6 +41,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
</project>
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1528,11 +1528,11 @@
<version>${jta.api.version}</version>
</dependency>

<dependency>
<!--<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependency>--> <!-- The latest repackaged guava version is 18.0 -->

<dependency>
<groupId>org.glassfish.hk2</groupId>
Expand Down Expand Up @@ -2108,6 +2108,7 @@
<bnd.plugin.version>2.3.6</bnd.plugin.version>
<cdi.api.version>1.1</cdi.api.version>
<cdi2.api.version>2.0.2</cdi2.api.version>
<commons.io.version>2.11.0</commons.io.version>
<commons-lang3.version>3.3.2</commons-lang3.version>
<microprofile.config.version>2.0</microprofile.config.version>
<checkstyle.mvn.plugin.version>3.1.0</checkstyle.mvn.plugin.version>
Expand All @@ -2121,7 +2122,7 @@
<gae.version>1.9.59</gae.version>
<grizzly.client.version>1.16</grizzly.client.version>
<grizzly2.version>2.4.4</grizzly2.version>
<guava.version>18.0</guava.version>
<guava.version>31.1-jre</guava.version>
<hamcrest.version>1.3</hamcrest.version>
<helidon.version>1.0.3</helidon.version>
<xmlunit.version>1.6</xmlunit.version>
Expand Down
8 changes: 1 addition & 7 deletions test-framework/maven/container-runner-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2015, 2022 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -119,12 +119,6 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.0.1-jre</version>
</dependency>

</dependencies>

<build>
Expand Down
9 changes: 2 additions & 7 deletions test-framework/maven/custom-enforcer-rules/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2015, 2022 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -46,12 +46,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${commons.io.version}</version>
</dependency>

<dependency>
Expand Down
Loading

0 comments on commit b8e7c8b

Please sign in to comment.