From 520f8a9e23b36194192dc15a11d0138b00d787ba Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Thu, 6 Feb 2014 22:36:13 +0100 Subject: [PATCH] Introduce Gerrit gwtui common project The new project hosts code that is reused between Gerrit core and GWT based plugins. Change-Id: I1a6e4352f681266c2ce664881a64d35bd2639299 --- gerrit-gwtui-common/BUCK | 30 ++++++++ .../google/gerrit/GerritGwtUICommon.gwt.xml | 18 +++++ .../google/gerrit/client/rpc/NativeMap.java | 0 .../gerrit/client/rpc/NativeString.java | 9 ++- .../com/google/gerrit/client/rpc/Natives.java | 0 .../gerrit/client/rpc/TransformCallback.java | 0 gerrit-gwtui/BUCK | 1 + .../com/google/gerrit/GerritGwtUI.gwt.xml | 1 + gerrit-plugin-gwtui/BUCK | 42 ++++++++--- .../java/com/google/gerrit/Plugin.gwt.xml | 1 + .../plugin/client/rpc/NativeString.java | 54 -------------- .../gerrit/plugin/client/rpc/Natives.java | 71 ------------------- .../gerrit/plugin/client/rpc/RestApi.java | 1 + 13 files changed, 94 insertions(+), 134 deletions(-) create mode 100644 gerrit-gwtui-common/BUCK create mode 100644 gerrit-gwtui-common/src/main/java/com/google/gerrit/GerritGwtUICommon.gwt.xml rename {gerrit-gwtui => gerrit-gwtui-common}/src/main/java/com/google/gerrit/client/rpc/NativeMap.java (100%) rename {gerrit-gwtui => gerrit-gwtui-common}/src/main/java/com/google/gerrit/client/rpc/NativeString.java (87%) rename {gerrit-gwtui => gerrit-gwtui-common}/src/main/java/com/google/gerrit/client/rpc/Natives.java (100%) rename {gerrit-gwtui => gerrit-gwtui-common}/src/main/java/com/google/gerrit/client/rpc/TransformCallback.java (100%) delete mode 100644 gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/NativeString.java delete mode 100644 gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/Natives.java diff --git a/gerrit-gwtui-common/BUCK b/gerrit-gwtui-common/BUCK new file mode 100644 index 0000000000..76f2db8646 --- /dev/null +++ b/gerrit-gwtui-common/BUCK @@ -0,0 +1,30 @@ +SRC = 'src/main/java/com/google/gerrit/' + +gwt_module( + name = 'client', + srcs = glob([SRC + 'client/**/*.java']), + gwtxml = SRC + 'GerritGwtUICommon.gwt.xml', + compile_deps = ['//lib/gwt:user'], + visibility = ['PUBLIC'], +) + +java_library( + name = 'client-lib', + exported_deps = [':client-lib2'], + visibility = ['PUBLIC'], +) + +java_library2( + name = 'client-lib2', + srcs = glob(['src/main/**/*.java']), + resources = glob(['src/main/**/*']), + compile_deps = ['//lib/gwt:user'], + visibility = ['PUBLIC'], +) + +java_library( + name = 'client-src-lib', + srcs = [], + resources = glob(['src/main/**/*']), + visibility = ['PUBLIC'], +) diff --git a/gerrit-gwtui-common/src/main/java/com/google/gerrit/GerritGwtUICommon.gwt.xml b/gerrit-gwtui-common/src/main/java/com/google/gerrit/GerritGwtUICommon.gwt.xml new file mode 100644 index 0000000000..eb551c426c --- /dev/null +++ b/gerrit-gwtui-common/src/main/java/com/google/gerrit/GerritGwtUICommon.gwt.xml @@ -0,0 +1,18 @@ + + + + diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/rpc/NativeMap.java b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/rpc/NativeMap.java similarity index 100% rename from gerrit-gwtui/src/main/java/com/google/gerrit/client/rpc/NativeMap.java rename to gerrit-gwtui-common/src/main/java/com/google/gerrit/client/rpc/NativeMap.java diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/rpc/NativeString.java b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/rpc/NativeString.java similarity index 87% rename from gerrit-gwtui/src/main/java/com/google/gerrit/client/rpc/NativeString.java rename to gerrit-gwtui-common/src/main/java/com/google/gerrit/client/rpc/NativeString.java index 8cc5735889..0e16dc038c 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/rpc/NativeString.java +++ b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/rpc/NativeString.java @@ -21,7 +21,14 @@ import com.google.gwt.user.client.rpc.AsyncCallback; public final class NativeString extends JavaScriptObject { public static final JavaScriptObject TYPE = init(); - private static final native JavaScriptObject init() /*-{ return function(s){this.s=s}; }-*/; + // Used from core and plugins + private static final native JavaScriptObject init() /*-{ + if ($wnd.Gerrit === undefined || $wnd.Gerrit.JsonString === undefined) { + return function(s){this.s=s}; + } else { + return $wnd.Gerrit.JsonString; + } + }-*/; static final NativeString wrap(String s) { return wrap0(TYPE, s); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/rpc/Natives.java b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/rpc/Natives.java similarity index 100% rename from gerrit-gwtui/src/main/java/com/google/gerrit/client/rpc/Natives.java rename to gerrit-gwtui-common/src/main/java/com/google/gerrit/client/rpc/Natives.java diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/rpc/TransformCallback.java b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/rpc/TransformCallback.java similarity index 100% rename from gerrit-gwtui/src/main/java/com/google/gerrit/client/rpc/TransformCallback.java rename to gerrit-gwtui-common/src/main/java/com/google/gerrit/client/rpc/TransformCallback.java diff --git a/gerrit-gwtui/BUCK b/gerrit-gwtui/BUCK index b99bcfad8f..2e6510e064 100644 --- a/gerrit-gwtui/BUCK +++ b/gerrit-gwtui/BUCK @@ -61,6 +61,7 @@ gwt_module( '//gerrit-gwtexpui:Progress', '//gerrit-gwtexpui:SafeHtml', '//gerrit-gwtexpui:UserAgent', + '//gerrit-gwtui-common:client', '//gerrit-common:client', '//gerrit-extension-api:client', '//gerrit-patch-jgit:client', diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/GerritGwtUI.gwt.xml b/gerrit-gwtui/src/main/java/com/google/gerrit/GerritGwtUI.gwt.xml index 788f7cd1b8..76a5ca89d1 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/GerritGwtUI.gwt.xml +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/GerritGwtUI.gwt.xml @@ -27,6 +27,7 @@ + diff --git a/gerrit-plugin-gwtui/BUCK b/gerrit-plugin-gwtui/BUCK index b036d5ef7f..8022bd1362 100644 --- a/gerrit-plugin-gwtui/BUCK +++ b/gerrit-plugin-gwtui/BUCK @@ -1,3 +1,4 @@ +COMMON = ['gerrit-gwtui-common/src/main/java/'] SRC = 'src/main/java/com/google/gerrit/' SRCS = glob([SRC + '**/*.java']) @@ -6,16 +7,41 @@ DEPS = [ '//lib/gwt:dev', ] -java_library2( +java_binary( name = 'gwtui-api', - srcs = SRCS, - resources = glob(['src/main/**/*']), - compile_deps = DEPS, + deps = [ + ':gwtui-api-lib', + '//gerrit-gwtui-common:client-lib', + ], visibility = ['PUBLIC'], ) java_library( + name = 'gwtui-api-lib', + exported_deps = [':gwtui-api-lib2'], + visibility = ['PUBLIC'], +) + +java_library2( + name = 'gwtui-api-lib2', + srcs = SRCS, + resources = glob(['src/main/**/*']), + deps = ['//gerrit-gwtui-common:client-lib2'], + compile_deps = DEPS, + visibility = ['PUBLIC'], +) + +java_binary( name = 'gwtui-api-src', + deps = [ + ':gwtui-api-src-lib', + '//gerrit-gwtui-common:client-src-lib', + ], + visibility = ['PUBLIC'], +) + +java_library( + name = 'gwtui-api-src-lib', srcs = [], resources = glob(['src/main/**/*']), visibility = ['PUBLIC'], @@ -24,9 +50,9 @@ java_library( java_doc( name = 'gwtui-api-javadoc', title = 'Gerrit Review GWT Extension API Documentation', - pkg = 'com.google.gerrit.plugin', - paths = ['$SRCDIR/src/main/java'], - srcs = SRCS, - deps = DEPS, + pkg = 'com.google.gerrit', + paths = ['$SRCDIR/src/main/java'] + COMMON, + srcs = SRCS + glob(COMMON), + deps = DEPS + ['//gerrit-gwtui-common:client-src-lib'], visibility = ['PUBLIC'], ) diff --git a/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/Plugin.gwt.xml b/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/Plugin.gwt.xml index 81adcacf9f..e0b0833b76 100644 --- a/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/Plugin.gwt.xml +++ b/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/Plugin.gwt.xml @@ -15,6 +15,7 @@ --> + diff --git a/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/NativeString.java b/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/NativeString.java deleted file mode 100644 index 13c8b1d368..0000000000 --- a/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/NativeString.java +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2013 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.gerrit.plugin.client.rpc; - -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.user.client.rpc.AsyncCallback; - -/** Wraps a String that was returned from a JSON API. */ -public class NativeString extends JavaScriptObject { - private static final JavaScriptObject TYPE = init(); - - private static final native JavaScriptObject init() - /*-{ return $wnd.Gerrit.JsonString }-*/; - - public final native String asString() - /*-{ return this; }-*/; - - public static final - AsyncCallback unwrap(final AsyncCallback cb) { - return new AsyncCallback() { - @Override - public void onSuccess(NativeString result) { - cb.onSuccess(result != null ? result.asString() : null); - } - - @Override - public void onFailure(Throwable caught) { - cb.onFailure(caught); - } - }; - } - - public static final boolean is(JavaScriptObject o) { - return is(TYPE, o); - } - - private static final native boolean is(JavaScriptObject T, JavaScriptObject o) - /*-{ return o instanceof T }-*/; - - protected NativeString() { - } -} diff --git a/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/Natives.java b/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/Natives.java deleted file mode 100644 index 6f5b136abf..0000000000 --- a/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/Natives.java +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2012 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.gerrit.plugin.client.rpc; - -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.core.client.JsArray; -import com.google.gwt.json.client.JSONObject; - -import java.util.AbstractList; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -public class Natives { - /** - * Get the names of defined properties on the object. The returned set - * iterates in the native iteration order, which may match the source order. - */ - public static Set keys(JavaScriptObject obj) { - if (obj != null) { - return new JSONObject(obj).keySet(); - } - return Collections.emptySet(); - } - - public static List asList( - final JsArray arr) { - if (arr == null) { - return null; - } - return new AbstractList() { - @Override - public T set(int index, T element) { - T old = arr.get(index); - arr.set(index, element); - return old; - } - - @Override - public T get(int index) { - return arr.get(index); - } - - @Override - public int size() { - return arr.length(); - } - }; - } - - public static JsArray arrayOf(T element) { - JsArray arr = JavaScriptObject.createArray().cast(); - arr.push(element); - return arr; - } - - private Natives() { - } -} diff --git a/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/RestApi.java b/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/RestApi.java index 66f099fe1a..cfbc8a5f2e 100644 --- a/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/RestApi.java +++ b/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/RestApi.java @@ -14,6 +14,7 @@ package com.google.gerrit.plugin.client.rpc; +import com.google.gerrit.client.rpc.NativeString; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.http.client.URL; import com.google.gwt.user.client.rpc.AsyncCallback;