Copy gwtorm dependencies into core repo

This is the minimal set of files from gwtorm that are still needed by
Gerrit core. The long term plan is to migrate away from these, for
example by revamping our exception hierarchy (I9c8fac5f) and converting
the legacy mutable gwtorm-based types to immutable AutoValues.

In the short term, copying these files into core allows us to remove a
bunch of unused class files from the war, and prevents new dependencies
from creeping in. This change should be viewed as a starting point of
the larger project to eliminate gwtorm, not an end in itself.

Files copied from:
https://gerrit.googlesource.com/gwtorm/+/de62a8902ade3239e4a2db105bb24e4561e34df3

The whole gwtorm repo is under the same AOSP umbrella as Gerrit core, so
it's all under the same CLA and can be copied between repos on the
Gerrit hosts without any change to the license.

Change-Id: I0f09ed399180bc132fb0a28be07944b4aa9fe4a0
This commit is contained in:
Dave Borowitz
2019-04-08 14:46:16 -07:00
committed by David Pursehouse
parent bdeca27b67
commit c58702ac79
51 changed files with 669 additions and 75 deletions

View File

@@ -94,7 +94,6 @@ Apache2.0
* guava
* guava-failureaccess
* guava-retrying
* gwtorm-client
* html-types
* j2objc
* jsr305

View File

@@ -176,13 +176,6 @@ maven_jar(
sha1 = "f645ed69d595b24d4cf8b3fbb64cc505bede8829",
)
maven_jar(
name = "gwtorm-client",
artifact = "com.google.gerrit:gwtorm:1.20",
sha1 = "a4809769b710bc8ce3f203125630b8419f0e58b0",
src_sha1 = "cb63296276ce3228b2d83a37017a99e38ad8ed42",
)
maven_jar(
name = "protobuf",
artifact = "com.google.protobuf:protobuf-java:3.6.1",

View File

@@ -34,10 +34,10 @@ java_library(
"//java/com/google/gerrit/server/restapi",
"//java/com/google/gerrit/sshd",
"//java/com/google/gerrit/testing:gerrit-test-util",
"//java/com/google/gwtorm",
"//lib:args4j",
"//lib:gson",
"//lib:guava-retrying",
"//lib:gwtorm",
"//lib:h2",
"//lib:jimfs",
"//lib:jsch",
@@ -116,10 +116,10 @@ java_library2(
"//java/com/google/gerrit/server/schema",
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gerrit/sshd",
"//java/com/google/gwtorm",
"//lib:args4j",
"//lib:gson",
"//lib:guava-retrying",
"//lib:gwtorm",
"//lib:jsch",
"//lib:servlet-api-3_1",
"//lib/commons:lang",

View File

@@ -22,9 +22,9 @@ java_library(
"//java/com/google/gerrit/extensions:api",
"//java/com/google/gerrit/prettify:server",
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gwtorm",
"//java/org/eclipse/jgit:server",
"//lib:guava",
"//lib:gwtorm",
"//lib:servlet-api-3_1",
"//lib/auto:auto-value",
"//lib/auto:auto-value-annotations",

View File

@@ -12,9 +12,9 @@ java_library(
"//java/com/google/gerrit/proto",
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gerrit/server",
"//java/com/google/gwtorm",
"//lib:gson",
"//lib:guava",
"//lib:gwtorm",
"//lib:protobuf",
"//lib/commons:codec",
"//lib/commons:lang",

View File

@@ -7,8 +7,8 @@ java_library(
"//java/com/google/gerrit/extensions:api",
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gerrit/server",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib/bouncycastle:bcpg-neverlink",
"//lib/bouncycastle:bcprov-neverlink",
"//lib/flogger:api",

View File

@@ -26,11 +26,11 @@ java_library(
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gerrit/util/cli",
"//java/com/google/gerrit/util/http",
"//java/com/google/gwtorm",
"//java/org/eclipse/jgit:server",
"//lib:args4j",
"//lib:gson",
"//lib:guava",
"//lib:gwtorm",
"//lib:jsch",
"//lib:servlet-api-3_1",
"//lib:soy",

View File

@@ -11,9 +11,9 @@ java_library(
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gerrit/server",
"//java/com/google/gerrit/server/audit",
"//java/com/google/gwtorm",
"//lib:gson",
"//lib:guava",
"//lib:gwtorm",
"//lib:servlet-api-3_1",
"//lib/commons:codec",
"//lib/flogger:api",

View File

@@ -15,7 +15,7 @@ java_library(
"//java/com/google/gerrit/server",
"//java/com/google/gerrit/server/audit",
"//lib:guava",
"//lib:gwtorm",
"//java/com/google/gwtorm",
"//lib:servlet-api-3_1",
"//lib/commons:codec",
"//lib/flogger:api",

View File

@@ -25,8 +25,8 @@ java_library(
"//java/com/google/gerrit/server/restapi",
"//java/com/google/gerrit/server/schema",
"//java/com/google/gerrit/sshd",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib:servlet-api-3_1",
"//lib/flogger:api",
"//lib/guice",

View File

@@ -25,8 +25,8 @@ java_library(
"//java/com/google/gerrit/metrics",
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gerrit/server/logging",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib/antlr:java-runtime",
"//lib/auto:auto-value",
"//lib/auto:auto-value-annotations",

View File

@@ -9,8 +9,8 @@ java_library(
"//java/com/google/gerrit/index:query_exception",
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gerrit/server",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib/lucene:lucene-core-and-backward-codecs",
],
)
@@ -35,8 +35,8 @@ java_library(
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gerrit/server",
"//java/com/google/gerrit/server/logging",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib:protobuf",
"//lib/flogger:api",
"//lib/guice",

View File

@@ -47,9 +47,9 @@ java_library(
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gerrit/sshd",
"//java/com/google/gerrit/util/http",
"//java/com/google/gwtorm",
"//lib:args4j",
"//lib:guava",
"//lib:gwtorm",
"//lib:protobuf",
"//lib:servlet-api-3_1-without-neverlink",
"//lib/auto:auto-value",

View File

@@ -20,8 +20,8 @@ java_library(
"//java/com/google/gerrit/server/ioutil",
"//java/com/google/gerrit/server/schema",
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib:h2",
"//lib/commons:validator",
"//lib/flogger:api",

View File

@@ -7,8 +7,8 @@ java_library(
"//java/com/google/gerrit/common:server",
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gerrit/server",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib/flogger:api",
"//lib/guice",
"//lib/guice:guice-assistedinject",

View File

@@ -17,9 +17,9 @@ java_library(
"//java/com/google/gerrit/server/restapi",
"//java/com/google/gerrit/server/schema",
"//java/com/google/gerrit/util/cli",
"//java/com/google/gwtorm",
"//lib:args4j",
"//lib:guava",
"//lib:gwtorm",
"//lib/flogger:api",
"//lib/guice",
"//lib/jgit/org.eclipse.jgit:jgit",

View File

@@ -8,8 +8,8 @@ java_library(
deps = [
"//java/com/google/gerrit/common:annotations",
"//java/com/google/gerrit/extensions:api",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib:protobuf",
"//proto:entities_java_proto",
],

View File

@@ -52,6 +52,7 @@ java_library(
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gerrit/util/cli",
"//java/com/google/gerrit/util/ssl",
"//java/com/google/gwtorm",
"//java/org/apache/commons/net",
"//java/org/eclipse/jgit:server",
"//lib:args4j",
@@ -86,7 +87,6 @@ java_library(
"//lib:gson",
"//lib:guava",
"//lib:guava-retrying",
"//lib:gwtorm",
"//lib:jsch",
"//lib:juniversalchardet",
"//lib:mime-util",

View File

@@ -13,9 +13,9 @@ java_library(
"//java/com/google/gerrit/server",
"//java/com/google/gerrit/server/restapi",
"//java/com/google/gerrit/util/cli",
"//java/com/google/gwtorm",
"//lib:args4j",
"//lib:guava",
"//lib:gwtorm",
"//lib:servlet-api-3_1",
"//lib/guice",
"//lib/guice:guice-assistedinject",

View File

@@ -21,6 +21,7 @@ java_library(
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gerrit/util/cli",
"//java/com/google/gerrit/util/ssl",
"//java/com/google/gwtorm",
"//java/org/apache/commons/net",
"//java/org/eclipse/jgit:server",
"//lib:args4j",
@@ -55,7 +56,6 @@ java_library(
"//lib:gson",
"//lib:guava",
"//lib:guava-retrying",
"//lib:gwtorm",
"//lib:jsch",
"//lib:juniversalchardet",
"//lib:mime-util",

View File

@@ -5,8 +5,8 @@ java_library(
deps = [
"//java/com/google/gerrit/common:annotations",
"//java/com/google/gerrit/proto",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib:protobuf",
"//lib/jgit/org.eclipse.jgit:jgit",
],

View File

@@ -12,9 +12,9 @@ java_library(
"//java/com/google/gerrit/server/logging",
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gerrit/util/cli",
"//java/com/google/gwtorm",
"//lib:args4j",
"//lib:guava",
"//lib:gwtorm",
"//lib/auto:auto-value",
"//lib/auto:auto-value-annotations",
"//lib/flogger:api",

View File

@@ -22,12 +22,12 @@ java_library(
"//java/com/google/gerrit/server/logging",
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gerrit/util/cli",
"//java/com/google/gwtorm",
"//java/org/eclipse/jgit:server",
"//lib:args4j",
"//lib:blame-cache",
"//lib:gson",
"//lib:guava",
"//lib:gwtorm",
"//lib:servlet-api-3_1",
"//lib/auto:auto-value",
"//lib/auto:auto-value-annotations",

View File

@@ -14,9 +14,9 @@ java_library(
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gerrit/server",
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gwtorm",
"//java/org/eclipse/jgit:server",
"//lib:guava",
"//lib:gwtorm",
"//lib/auto:auto-value",
"//lib/auto:auto-value-annotations",
"//lib/commons:dbcp",

View File

@@ -21,10 +21,10 @@ java_library(
"//java/com/google/gerrit/server/schema",
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gerrit/util/cli",
"//java/com/google/gwtorm",
"//lib:args4j",
"//lib:gson",
"//lib:guava",
"//lib:gwtorm",
"//lib:jsch",
"//lib:servlet-api-3_1",
"//lib/auto:auto-value",

View File

@@ -33,8 +33,8 @@ java_library(
"//java/com/google/gerrit/server/restapi",
"//java/com/google/gerrit/server/schema",
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib:h2",
"//lib:junit",
"//lib/auto:auto-value",

View File

@@ -0,0 +1,5 @@
java_library(
name = "gwtorm",
srcs = glob(["**/*.java"]),
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,108 @@
// Copyright 2008 Google Inc.
//
// 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.gwtorm.client;
import java.io.Serializable;
/**
* Abstract key type composed of other keys.
*
* <p>Applications should subclass this type to create their own entity-specific key classes.
*
* @param <P> the parent key type. Use {@link Key} if no parent key is needed.
*/
@SuppressWarnings("serial")
public abstract class CompoundKey<P extends Key<?>> implements Key<P>, Serializable {
/** @return the member key components, minus the parent key. */
public abstract Key<?>[] members();
/** @return the parent key instance; null if this is a root level key. */
@Override
public P getParentKey() {
return null;
}
@Override
public int hashCode() {
int hc = 0;
if (getParentKey() != null) {
hc = getParentKey().hashCode();
}
for (final Key<?> k : members()) {
hc *= 31;
hc += k.hashCode();
}
return hc;
}
@Override
public boolean equals(final Object b) {
if (b == null || b.getClass() != getClass()) {
return false;
}
final CompoundKey<P> q = cast(b);
if (getParentKey() != null && !getParentKey().equals(q.getParentKey())) {
return false;
}
final Key<?>[] aMembers = members();
final Key<?>[] bMembers = q.members();
if (aMembers.length != bMembers.length) {
return false;
}
for (int i = 0; i < aMembers.length; i++) {
if (!aMembers[i].equals(bMembers[i])) {
return false;
}
}
return true;
}
@Override
public String toString() {
final StringBuffer r = new StringBuffer();
boolean first = true;
if (getParentKey() != null) {
r.append(KeyUtil.encode(getParentKey().toString()));
first = false;
}
for (final Key<?> k : members()) {
if (!first) {
r.append(',');
}
r.append(KeyUtil.encode(k.toString()));
first = false;
}
return r.toString();
}
@Override
public void fromString(final String in) {
final String[] parts = in.split(",");
int p = 0;
if (getParentKey() != null) {
getParentKey().fromString(KeyUtil.decode(parts[p++]));
}
for (final Key<?> k : members()) {
k.fromString(KeyUtil.decode(parts[p++]));
}
}
@SuppressWarnings("unchecked")
private static <A extends Key<?>> CompoundKey<A> cast(final Object b) {
return (CompoundKey<A>) b;
}
}

View File

@@ -0,0 +1,80 @@
// Copyright 2008 Google Inc.
//
// 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.gwtorm.client;
import java.io.Serializable;
/**
* Abstract key type using a single integer value.
*
* <p>Applications should subclass this type to create their own entity-specific key classes.
*
* @param <P> the parent key type. Use {@link Key} if no parent key is needed.
*/
@SuppressWarnings("serial")
public abstract class IntKey<P extends Key<?>> implements Key<P>, Serializable {
/** @return id of the entity instance. */
public abstract int get();
/** @param newValue the new value of this key. */
protected abstract void set(int newValue);
/** @return the parent key instance; null if this is a root level key. */
@Override
public P getParentKey() {
return null;
}
@Override
public int hashCode() {
int hc = get();
if (getParentKey() != null) {
hc *= 31;
hc += getParentKey().hashCode();
}
return hc;
}
@Override
public boolean equals(final Object b) {
if (b == null || b.getClass() != getClass()) {
return false;
}
final IntKey<P> q = cast(b);
return get() == q.get() && KeyUtil.eq(getParentKey(), q.getParentKey());
}
@Override
public String toString() {
final StringBuffer r = new StringBuffer();
if (getParentKey() != null) {
r.append(getParentKey().toString());
r.append(',');
}
r.append(get());
return r.toString();
}
@Override
public void fromString(final String in) {
set(Integer.parseInt(KeyUtil.parseFromString(getParentKey(), in)));
}
@SuppressWarnings("unchecked")
private static <A extends Key<?>> IntKey<A> cast(final Object b) {
return (IntKey<A>) b;
}
}

View File

@@ -0,0 +1,45 @@
// Copyright 2008 Google Inc.
//
// 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.gwtorm.client;
/**
* Generic type for an entity key.
*
* <p>Although not required, entities should make their primary key type implement this interface,
* permitting traversal up through the containment hierarchy of the entity keys.
*
* @param <P> type of the parent key. If no parent, use {@link Key} itself.
*/
public interface Key<P extends Key<?>> {
/**
* Get the parent key instance.
*
* @return the parent key; null if this entity key is a root-level key.
*/
public P getParentKey();
@Override
public int hashCode();
@Override
public boolean equals(Object o);
/** @return the key, encoded in a string format . */
@Override
public String toString();
/** Reset this key instance to represent the data in the supplied string. */
public void fromString(String in);
}

View File

@@ -0,0 +1,103 @@
// Copyright 2008 Google Inc.
//
// 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.gwtorm.client;
/** Common utility functions for {@link Key} implementors. */
public class KeyUtil {
private static Encoder ENCODER_IMPL = new StandardKeyEncoder();
/**
* Set the encoder implementation to a valid implementation.
*
* <p>Server-side code needs to set the encoder to a {@link
* com.google.gwtorm.server.StandardKeyEncoder} instance prior to invoking any methods in this
* class. Typically this is done by the {@link com.google.gwtorm.server.SchemaFactory}
* implementation's static initializer.
*/
public static void setEncoderImpl(final Encoder e) {
ENCODER_IMPL = e;
}
/**
* Determine if two keys are equal, supporting null references.
*
* @param <T> type of the key entity.
* @param a first key to test; may be null.
* @param b second key to test; may be null.
* @return true if both <code>a</code> and <code>b</code> are null, or if both are not-null and
* <code>a.equals(b)</code> is true. Otherwise false.
*/
public static <T extends Key<?>> boolean eq(final T a, final T b) {
if (a == b) {
return true;
}
if (a == null || b == null) {
return false;
}
return a.equals(b);
}
/**
* Encode a string to be safe for use within a URL like string.
*
* <p>The returned encoded string has URL component characters escaped with hex escapes (e.g. ' '
* is '+' and '%' is '%25'). The special character '/' is left literal. The comma character (',')
* is always encoded, permitting multiple encoded string values to be joined together safely.
*
* @param e the string to encode, must not be null.
* @return the encoded string.
*/
public static String encode(final String e) {
return ENCODER_IMPL.encode(e);
}
/**
* Decode a string previously encoded by {@link #encode(String)}.
*
* @param e the string to decode, must not be null.
* @return the decoded string.
*/
public static String decode(final String e) {
return ENCODER_IMPL.decode(e);
}
/**
* Split a string along the last comma and parse into the parent.
*
* @param parent parent key; <code>parent.fromString(in[0..comma])</code>.
* @param in the input string.
* @return text (if any) after the last comma in the input.
*/
public static String parseFromString(final Key<?> parent, final String in) {
final int comma = in.lastIndexOf(',');
if (comma < 0 && parent == null) {
return decode(in);
}
if (comma < 0 && parent != null) {
throw new IllegalArgumentException("Not enough components: " + in);
}
assert (parent != null);
parent.fromString(in.substring(0, comma));
return decode(in.substring(comma + 1));
}
public abstract static class Encoder {
public abstract String encode(String e);
public abstract String decode(String e);
}
private KeyUtil() {}
}

View File

@@ -0,0 +1,111 @@
// Copyright 2008 Google Inc.
//
// 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.gwtorm.client;
import com.google.gwtorm.client.KeyUtil.Encoder;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
public class StandardKeyEncoder extends Encoder {
private static final char[] hexc = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
private static final char safe[];
private static final byte hexb[];
static {
safe = new char[256];
safe['-'] = '-';
safe['_'] = '_';
safe['.'] = '.';
safe['!'] = '!';
safe['~'] = '~';
safe['*'] = '*';
safe['\''] = '\'';
safe['('] = '(';
safe[')'] = ')';
safe['/'] = '/';
safe[' '] = '+';
for (char c = '0'; c <= '9'; c++) safe[c] = c;
for (char c = 'A'; c <= 'Z'; c++) safe[c] = c;
for (char c = 'a'; c <= 'z'; c++) safe[c] = c;
hexb = new byte['f' + 1];
Arrays.fill(hexb, (byte) -1);
for (char i = '0'; i <= '9'; i++) hexb[i] = (byte) (i - '0');
for (char i = 'A'; i <= 'F'; i++) hexb[i] = (byte) ((i - 'A') + 10);
for (char i = 'a'; i <= 'f'; i++) hexb[i] = (byte) ((i - 'a') + 10);
}
@Override
public String encode(final String e) {
final byte[] b;
try {
b = e.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
throw new RuntimeException("No UTF-8 support", e1);
}
final StringBuilder r = new StringBuilder(b.length);
for (int i = 0; i < b.length; i++) {
final int c = b[i] & 0xff;
final char s = safe[c];
if (s == 0) {
r.append('%');
r.append(hexc[c >> 4]);
r.append(hexc[c & 15]);
} else {
r.append(s);
}
}
return r.toString();
}
@Override
public String decode(final String e) {
if (e.indexOf('%') < 0) {
return e.replace('+', ' ');
}
final byte[] b = new byte[e.length()];
int bPtr = 0;
try {
for (int i = 0; i < e.length(); ) {
final char c = e.charAt(i);
if (c == '%' && i + 2 < e.length()) {
final int v = (hexb[e.charAt(i + 1)] << 4) | hexb[e.charAt(i + 2)];
if (v < 0) {
throw new IllegalArgumentException(e.substring(i, i + 3));
}
b[bPtr++] = (byte) v;
i += 3;
} else if (c == '+') {
b[bPtr++] = ' ';
i++;
} else {
b[bPtr++] = (byte) c;
i++;
}
}
} catch (ArrayIndexOutOfBoundsException err) {
throw new IllegalArgumentException("Bad encoding: " + e);
}
try {
return new String(b, 0, bPtr, "UTF-8");
} catch (UnsupportedEncodingException e1) {
throw new RuntimeException("No UTF-8 support", e1);
}
}
}

View File

@@ -0,0 +1,86 @@
// Copyright 2008 Google Inc.
//
// 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.gwtorm.client;
import java.io.Serializable;
/**
* Abstract key type using a single string value.
*
* <p>Applications should subclass this type to create their own entity-specific key classes.
*
* @param <P> the parent key type. Use {@link Key} if no parent key is needed.
*/
@SuppressWarnings("serial")
public abstract class StringKey<P extends Key<?>>
implements Key<P>, Serializable, Comparable<StringKey<?>> {
/** @return name of the entity instance. */
public abstract String get();
/** @param newValue the new value of this key. */
protected abstract void set(String newValue);
/** @return the parent key instance; null if this is a root level key. */
@Override
public P getParentKey() {
return null;
}
@Override
public int hashCode() {
int hc = get() != null ? get().hashCode() : 0;
if (getParentKey() != null) {
hc *= 31;
hc += getParentKey().hashCode();
}
return hc;
}
@Override
public boolean equals(final Object b) {
if (b == null || get() == null || b.getClass() != getClass()) {
return false;
}
final StringKey<P> q = cast(b);
return get().equals(q.get()) && KeyUtil.eq(getParentKey(), q.getParentKey());
}
@Override
public int compareTo(final StringKey<?> other) {
return get().compareTo(other.get());
}
@Override
public String toString() {
final StringBuffer r = new StringBuffer();
if (getParentKey() != null) {
r.append(getParentKey().toString());
r.append(',');
}
r.append(KeyUtil.encode(get()));
return r.toString();
}
@Override
public void fromString(final String in) {
set(KeyUtil.parseFromString(getParentKey(), in));
}
@SuppressWarnings("unchecked")
private static <A extends Key<?>> StringKey<A> cast(final Object b) {
return (StringKey<A>) b;
}
}

View File

@@ -0,0 +1,27 @@
// Copyright 2009 Google Inc.
//
// 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.gwtorm.server;
/** Indicates one or more entities were concurrently inserted with the same key. */
@SuppressWarnings("serial")
public class OrmDuplicateKeyException extends OrmException {
public OrmDuplicateKeyException(final String msg) {
super(msg);
}
public OrmDuplicateKeyException(final String msg, final Throwable why) {
super(msg, why);
}
}

View File

@@ -0,0 +1,31 @@
// Copyright 2008 Google Inc.
//
// 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.gwtorm.server;
/** Any data store read or write error. */
@SuppressWarnings("serial")
public class OrmException extends Exception {
public OrmException(final String message) {
super(message);
}
public OrmException(final String message, final Throwable why) {
super(message, why);
}
public OrmException(final Throwable why) {
super(why);
}
}

View File

@@ -0,0 +1,31 @@
// Copyright 2008 Google Inc.
//
// 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.gwtorm.server;
/** Any data store read or write error. */
@SuppressWarnings("serial")
public class OrmRuntimeException extends RuntimeException {
public OrmRuntimeException(final String message) {
super(message);
}
public OrmRuntimeException(final String message, final Throwable why) {
super(message, why);
}
public OrmRuntimeException(final Throwable why) {
super(why);
}
}

View File

@@ -7,7 +7,7 @@ java_library(
"//java/com/google/gerrit/extensions:api",
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gerrit/server",
"//lib:gwtorm",
"//java/com/google/gwtorm",
"//lib/flogger:api",
"//lib/jgit/org.eclipse.jgit:jgit",
"//lib/prolog:runtime",

View File

@@ -21,7 +21,7 @@ java_library(
"//java/com/google/gerrit/extensions:api",
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gerrit/server",
"//lib:gwtorm",
"//java/com/google/gwtorm",
"//lib/truth",
],
)

View File

@@ -18,7 +18,7 @@ java_library(
deps = [
"//java/com/google/gerrit/acceptance:lib",
"//java/com/google/gerrit/reviewdb:server",
"//lib:gwtorm",
"//java/com/google/gwtorm",
"//lib:junit",
],
)

View File

@@ -33,8 +33,8 @@ java_library(
"//java/com/google/gerrit/extensions:api",
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gerrit/server",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib/truth",
],
)

View File

@@ -18,8 +18,8 @@ junit_tests(
"//java/com/google/gerrit/server/project/testing:project-test-util",
"//java/com/google/gerrit/server/schema",
"//java/com/google/gerrit/testing:gerrit-test-util",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib/bouncycastle:bcpg",
"//lib/bouncycastle:bcpg-neverlink",
"//lib/bouncycastle:bcprov",

View File

@@ -12,10 +12,10 @@ junit_tests(
"//java/com/google/gerrit/server",
"//java/com/google/gerrit/testing:gerrit-test-util",
"//java/com/google/gerrit/util/http",
"//java/com/google/gwtorm",
"//javatests/com/google/gerrit/util/http/testutil",
"//lib:gson",
"//lib:guava",
"//lib:gwtorm",
"//lib:jimfs",
"//lib:junit",
"//lib:servlet-api-3_1-without-neverlink",

View File

@@ -21,10 +21,10 @@ junit_tests(
"//java/com/google/gerrit/server",
"//java/com/google/gerrit/server/project/testing:project-test-util",
"//java/com/google/gerrit/testing:gerrit-test-util",
"//java/com/google/gwtorm",
"//java/org/eclipse/jgit:server",
"//lib:gson",
"//lib:guava-retrying",
"//lib:gwtorm",
"//lib/commons:codec",
"//lib/guice",
"//lib/jgit/org.eclipse.jgit:jgit",

View File

@@ -60,11 +60,11 @@ junit_tests(
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gerrit/testing:gerrit-test-util",
"//java/com/google/gerrit/truth",
"//java/com/google/gwtorm",
"//java/org/eclipse/jgit:server",
"//lib:gson",
"//lib:guava",
"//lib:guava-retrying",
"//lib:gwtorm",
"//lib:protobuf",
"//lib/auto:auto-value",
"//lib/auto:auto-value-annotations",

View File

@@ -7,8 +7,8 @@ junit_tests(
"//java/com/google/gerrit/server/cache/serialize",
"//java/com/google/gerrit/server/cache/testing",
"//java/com/google/gerrit/testing:gerrit-test-util",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib:junit",
"//lib:protobuf",
"//lib/auto:auto-value",

View File

@@ -18,8 +18,8 @@ junit_tests(
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gerrit/testing:gerrit-test-util",
"//java/com/google/gerrit/truth",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib/jgit/org.eclipse.jgit:jgit",
"//lib/jgit/org.eclipse.jgit.junit:junit",
"//lib/truth",

View File

@@ -20,8 +20,8 @@ java_library(
"//java/com/google/gerrit/server/schema",
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gerrit/testing:gerrit-test-util",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib/guice",
"//lib/jgit/org.eclipse.jgit:jgit",
"//lib/jgit/org.eclipse.jgit.junit:junit",
@@ -42,8 +42,8 @@ junit_tests(
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gerrit/server",
"//java/com/google/gerrit/testing:gerrit-test-util",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib/guice",
"//lib/jgit/org.eclipse.jgit:jgit",
"//lib/jgit/org.eclipse.jgit.junit:junit",
@@ -66,8 +66,8 @@ junit_tests(
"//java/com/google/gerrit/server",
"//java/com/google/gerrit/server/cache/testing",
"//java/com/google/gerrit/testing:gerrit-test-util",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib/jgit/org.eclipse.jgit:jgit",
"//lib/truth",
"//lib/truth:truth-proto-extension",

View File

@@ -12,8 +12,8 @@ junit_tests(
"//java/com/google/gerrit/server/schema",
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gerrit/testing:gerrit-test-util",
"//java/com/google/gwtorm",
"//lib:guava",
"//lib:gwtorm",
"//lib/guice",
"//lib/jgit/org.eclipse.jgit:jgit",
"//lib/jgit/org.eclipse.jgit.junit:junit",

View File

@@ -12,11 +12,11 @@ junit_tests(
"//java/com/google/gerrit/server/util/git",
"//java/com/google/gerrit/testing:gerrit-test-util",
"//java/com/google/gerrit/truth",
"//java/com/google/gwtorm",
"//java/org/eclipse/jgit:server",
"//lib:gson",
"//lib:guava",
"//lib:guava-retrying",
"//lib:gwtorm",
"//lib:protobuf",
"//lib/auto:auto-value",
"//lib/auto:auto-value-annotations",

View File

@@ -33,20 +33,6 @@ java_library(
exports = ["@gson//jar"],
)
java_library(
name = "gwtorm-client",
data = ["//lib:LICENSE-Apache2.0"],
visibility = ["//visibility:public"],
exports = ["@gwtorm-client//jar"],
)
java_library(
name = "gwtorm-client_src",
data = ["//lib:LICENSE-Apache2.0"],
visibility = ["//visibility:public"],
exports = ["@gwtorm-client//jar:src"],
)
java_library(
name = "protobuf",
data = ["//lib:LICENSE-protobuf"],
@@ -54,17 +40,6 @@ java_library(
exports = ["@protobuf//jar"],
)
java_library(
name = "gwtorm",
visibility = ["//visibility:public"],
exports = [":gwtorm-client"],
runtime_deps = [
":protobuf",
"//lib/antlr:java-runtime",
"//lib/ow2:ow2-asm",
],
)
java_library(
name = "guava-failureaccess",
data = ["//lib:LICENSE-Apache2.0"],

View File

@@ -49,6 +49,7 @@ EXPORTS = [
"//java/com/google/gerrit/server/util/time",
"//java/com/google/gerrit/util/cli",
"//java/com/google/gerrit/util/http",
"//java/com/google/gwtorm",
"//lib/commons:compress",
"//lib/commons:dbcp",
"//lib/commons:lang",
@@ -75,7 +76,6 @@ EXPORTS = [
"//lib:guava",
"//lib:guava-retrying",
"//lib:gson",
"//lib:gwtorm",
"//lib:icu4j",
"//lib:jsch",
"//lib:mime-util",