Introduce Gerrit gwtui common project
The new project hosts code that is reused between Gerrit core and GWT based plugins. Change-Id: I1a6e4352f681266c2ce664881a64d35bd2639299
This commit is contained in:
parent
ac2086d183
commit
520f8a9e23
30
gerrit-gwtui-common/BUCK
Normal file
30
gerrit-gwtui-common/BUCK
Normal file
@ -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'],
|
||||||
|
)
|
@ -0,0 +1,18 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (C) 2014 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.
|
||||||
|
-->
|
||||||
|
<module>
|
||||||
|
<source path='client' />
|
||||||
|
</module>
|
@ -21,7 +21,14 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
|
|||||||
public final class NativeString extends JavaScriptObject {
|
public final class NativeString extends JavaScriptObject {
|
||||||
public static final JavaScriptObject TYPE = init();
|
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) {
|
static final NativeString wrap(String s) {
|
||||||
return wrap0(TYPE, s);
|
return wrap0(TYPE, s);
|
@ -61,6 +61,7 @@ gwt_module(
|
|||||||
'//gerrit-gwtexpui:Progress',
|
'//gerrit-gwtexpui:Progress',
|
||||||
'//gerrit-gwtexpui:SafeHtml',
|
'//gerrit-gwtexpui:SafeHtml',
|
||||||
'//gerrit-gwtexpui:UserAgent',
|
'//gerrit-gwtexpui:UserAgent',
|
||||||
|
'//gerrit-gwtui-common:client',
|
||||||
'//gerrit-common:client',
|
'//gerrit-common:client',
|
||||||
'//gerrit-extension-api:client',
|
'//gerrit-extension-api:client',
|
||||||
'//gerrit-patch-jgit:client',
|
'//gerrit-patch-jgit:client',
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
<inherits name='com.google.gerrit.extensions.Extensions'/>
|
<inherits name='com.google.gerrit.extensions.Extensions'/>
|
||||||
<inherits name='com.google.gerrit.prettify.PrettyFormatter'/>
|
<inherits name='com.google.gerrit.prettify.PrettyFormatter'/>
|
||||||
<inherits name='com.google.gerrit.Common'/>
|
<inherits name='com.google.gerrit.Common'/>
|
||||||
|
<inherits name='com.google.gerrit.GerritGwtUICommon'/>
|
||||||
<inherits name='com.google.gerrit.UserAgent'/>
|
<inherits name='com.google.gerrit.UserAgent'/>
|
||||||
<inherits name='org.eclipse.jgit.JGit'/>
|
<inherits name='org.eclipse.jgit.JGit'/>
|
||||||
<inherits name='net.codemirror.CodeMirror'/>
|
<inherits name='net.codemirror.CodeMirror'/>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
COMMON = ['gerrit-gwtui-common/src/main/java/']
|
||||||
SRC = 'src/main/java/com/google/gerrit/'
|
SRC = 'src/main/java/com/google/gerrit/'
|
||||||
SRCS = glob([SRC + '**/*.java'])
|
SRCS = glob([SRC + '**/*.java'])
|
||||||
|
|
||||||
@ -6,16 +7,41 @@ DEPS = [
|
|||||||
'//lib/gwt:dev',
|
'//lib/gwt:dev',
|
||||||
]
|
]
|
||||||
|
|
||||||
java_library2(
|
java_binary(
|
||||||
name = 'gwtui-api',
|
name = 'gwtui-api',
|
||||||
srcs = SRCS,
|
deps = [
|
||||||
resources = glob(['src/main/**/*']),
|
':gwtui-api-lib',
|
||||||
compile_deps = DEPS,
|
'//gerrit-gwtui-common:client-lib',
|
||||||
|
],
|
||||||
visibility = ['PUBLIC'],
|
visibility = ['PUBLIC'],
|
||||||
)
|
)
|
||||||
|
|
||||||
java_library(
|
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',
|
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 = [],
|
srcs = [],
|
||||||
resources = glob(['src/main/**/*']),
|
resources = glob(['src/main/**/*']),
|
||||||
visibility = ['PUBLIC'],
|
visibility = ['PUBLIC'],
|
||||||
@ -24,9 +50,9 @@ java_library(
|
|||||||
java_doc(
|
java_doc(
|
||||||
name = 'gwtui-api-javadoc',
|
name = 'gwtui-api-javadoc',
|
||||||
title = 'Gerrit Review GWT Extension API Documentation',
|
title = 'Gerrit Review GWT Extension API Documentation',
|
||||||
pkg = 'com.google.gerrit.plugin',
|
pkg = 'com.google.gerrit',
|
||||||
paths = ['$SRCDIR/src/main/java'],
|
paths = ['$SRCDIR/src/main/java'] + COMMON,
|
||||||
srcs = SRCS,
|
srcs = SRCS + glob(COMMON),
|
||||||
deps = DEPS,
|
deps = DEPS + ['//gerrit-gwtui-common:client-src-lib'],
|
||||||
visibility = ['PUBLIC'],
|
visibility = ['PUBLIC'],
|
||||||
)
|
)
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
-->
|
-->
|
||||||
<module>
|
<module>
|
||||||
<inherits name="com.google.gwt.json.JSON"/>
|
<inherits name="com.google.gwt.json.JSON"/>
|
||||||
|
<inherits name='com.google.gerrit.GerritGwtUICommon'/>
|
||||||
|
|
||||||
<define-linker name="gerrit_plugin" class="com.google.gerrit.plugin.linker.GerritPluginLinker"/>
|
<define-linker name="gerrit_plugin" class="com.google.gerrit.plugin.linker.GerritPluginLinker"/>
|
||||||
<add-linker name="gerrit_plugin"/>
|
<add-linker name="gerrit_plugin"/>
|
||||||
|
@ -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<NativeString> unwrap(final AsyncCallback<String> cb) {
|
|
||||||
return new AsyncCallback<NativeString>() {
|
|
||||||
@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() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<String> keys(JavaScriptObject obj) {
|
|
||||||
if (obj != null) {
|
|
||||||
return new JSONObject(obj).keySet();
|
|
||||||
}
|
|
||||||
return Collections.emptySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends JavaScriptObject> List<T> asList(
|
|
||||||
final JsArray<T> arr) {
|
|
||||||
if (arr == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new AbstractList<T>() {
|
|
||||||
@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 <T extends JavaScriptObject> JsArray<T> arrayOf(T element) {
|
|
||||||
JsArray<T> arr = JavaScriptObject.createArray().cast();
|
|
||||||
arr.push(element);
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Natives() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
package com.google.gerrit.plugin.client.rpc;
|
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.core.client.JavaScriptObject;
|
||||||
import com.google.gwt.http.client.URL;
|
import com.google.gwt.http.client.URL;
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
Loading…
Reference in New Issue
Block a user