Get rid of dependency on Guava
Since I789f9aa589 removed usage of Guava's Optional, we only have
the dependency on Guava for the following simple utility methods:
Strings.isNullOrEmpty
MoreObjects.firstNonNull
Remove the dependency and instead provide own implementations
of those methods.
Change-Id: Iddcc20005004d37dae703fc0522c546a5212575c
diff --git a/lib/BUCK b/lib/BUCK
index 9c596fa..d333cba 100644
--- a/lib/BUCK
+++ b/lib/BUCK
@@ -1,13 +1,6 @@
include_defs('//bucklets/maven_jar.bucklet')
maven_jar(
- name = 'guava',
- id = 'com.google.guava:guava:19.0-rc2',
- sha1 = '93e17f60bc524c2610b41c494bb829c11ca89436',
- license = 'Apache2.0',
-)
-
-maven_jar(
name = 'junit',
id = 'junit:junit:4.11',
sha1 = '4e031bb61df09069aeb2bffb4019e7a5034a4ee0',
@@ -20,7 +13,6 @@
sha1 = 'bd17774d2dc0fffa884d42c07d2537e86c67acd6',
license = 'DO_NOT_DISTRIBUTE',
exported_deps = [
- ':guava',
':junit',
],
)
diff --git a/src/main/java/com/googlesource/gerrit/plugins/cookbook/HelloProjectAction.java b/src/main/java/com/googlesource/gerrit/plugins/cookbook/HelloProjectAction.java
index 8057bb7..0e5f6f0 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/cookbook/HelloProjectAction.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/cookbook/HelloProjectAction.java
@@ -14,8 +14,6 @@
package com.googlesource.gerrit.plugins.cookbook;
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Strings;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.server.CurrentUser;
@@ -39,6 +37,20 @@
this.user = user;
}
+ private boolean isNullOrEmpty(String s) {
+ return s == null || s.isEmpty();
+ }
+
+ private Object firstNonNull(String first, String second) {
+ if (first != null) {
+ return first;
+ }
+ if (second != null) {
+ return second;
+ }
+ throw new NullPointerException();
+ }
+
@Override
public String apply(ProjectResource rsrc, Input input) {
final String greeting = input.french
@@ -46,8 +58,8 @@
: "Hello";
return String.format("%s %s from project %s!",
greeting,
- Strings.isNullOrEmpty(input.message)
- ? MoreObjects.firstNonNull(user.get().getUserName(), "world")
+ isNullOrEmpty(input.message)
+ ? firstNonNull(user.get().getUserName(), "world")
: input.message,
rsrc.getName());
}