Dissolve gerrit-patch-jgit top-level directory

Change-Id: If6f09473e9621912e7eb769a92c17545db2716f6
This commit is contained in:
David Ostrovsky
2017-08-20 21:23:57 +02:00
committed by Dave Borowitz
parent 898832619a
commit 729f68c812
17 changed files with 29 additions and 36 deletions

View File

@@ -0,0 +1,50 @@
load("//tools/bzl:genrule2.bzl", "genrule2")
load("//tools/bzl:gwt.bzl", "gwt_module")
gwt_module(
name = "client",
srcs = [
"diff/Edit_JsonSerializer.java",
"diff/ReplaceEdit.java",
],
gwt_xml = "JGit.gwt.xml",
visibility = ["//visibility:public"],
deps = [
":Edit",
"//lib:gwtjsonrpc",
"//lib/gwt:user",
],
)
gwt_module(
name = "Edit",
srcs = [":jgit_edit_src"],
visibility = ["//visibility:public"],
)
genrule2(
name = "jgit_edit_src",
outs = ["edit.srcjar"],
cmd = " && ".join([
"unzip -qd $$TMP $(location //lib/jgit/org.eclipse.jgit:jgit-source) " +
"org/eclipse/jgit/diff/Edit.java",
"cd $$TMP",
"zip -Dq $$ROOT/$@ org/eclipse/jgit/diff/Edit.java",
]),
tools = ["//lib/jgit/org.eclipse.jgit:jgit-source"],
)
java_library(
name = "server",
srcs = [
"diff/EditDeserializer.java",
"diff/ReplaceEdit.java",
"internal/storage/file/WindowCacheStatAccessor.java",
"lib/ObjectIdSerialization.java",
],
visibility = ["//visibility:public"],
deps = [
"//lib:gson",
"//lib/jgit/org.eclipse.jgit:jgit",
],
)

View File

@@ -0,0 +1,22 @@
<!--
Copyright (C) 2009 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='diff' includes='
Edit.java
Edit_JsonSerializer.java
ReplaceEdit.java
'/>
</module>

View File

@@ -0,0 +1,95 @@
// Copyright (C) 2009 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 org.eclipse.jgit.diff;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
public class EditDeserializer implements JsonDeserializer<Edit>, JsonSerializer<Edit> {
@Override
public Edit deserialize(final JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
if (json.isJsonNull()) {
return null;
}
if (!json.isJsonArray()) {
throw new JsonParseException("Expected array for Edit type");
}
final JsonArray o = (JsonArray) json;
final int cnt = o.size();
if (cnt < 4 || cnt % 4 != 0) {
throw new JsonParseException("Expected array of 4 for Edit type");
}
if (4 == cnt) {
return new Edit(get(o, 0), get(o, 1), get(o, 2), get(o, 3));
}
List<Edit> l = new ArrayList<>((cnt / 4) - 1);
for (int i = 4; i < cnt; ) {
int as = get(o, i++);
int ae = get(o, i++);
int bs = get(o, i++);
int be = get(o, i++);
l.add(new Edit(as, ae, bs, be));
}
return new ReplaceEdit(get(o, 0), get(o, 1), get(o, 2), get(o, 3), l);
}
private static int get(JsonArray a, int idx) throws JsonParseException {
final JsonElement v = a.get(idx);
if (!v.isJsonPrimitive()) {
throw new JsonParseException("Expected array of 4 for Edit type");
}
final JsonPrimitive p = (JsonPrimitive) v;
if (!p.isNumber()) {
throw new JsonParseException("Expected array of 4 for Edit type");
}
return p.getAsInt();
}
@Override
public JsonElement serialize(final Edit src, Type typeOfSrc, JsonSerializationContext context) {
if (src == null) {
return JsonNull.INSTANCE;
}
final JsonArray a = new JsonArray();
add(a, src);
if (src instanceof ReplaceEdit) {
for (Edit e : ((ReplaceEdit) src).getInternalEdits()) {
add(a, e);
}
}
return a;
}
private void add(JsonArray a, Edit src) {
a.add(new JsonPrimitive(src.getBeginA()));
a.add(new JsonPrimitive(src.getEndA()));
a.add(new JsonPrimitive(src.getBeginB()));
a.add(new JsonPrimitive(src.getEndB()));
}
}

View File

@@ -0,0 +1,74 @@
// Copyright (C) 2009 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 org.eclipse.jgit.diff;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwtjsonrpc.client.impl.JsonSerializer;
import java.util.ArrayList;
import java.util.List;
public class Edit_JsonSerializer extends JsonSerializer<Edit> {
public static final Edit_JsonSerializer INSTANCE = new Edit_JsonSerializer();
@Override
public Edit fromJson(Object jso) {
if (jso == null) {
return null;
}
final JavaScriptObject o = (JavaScriptObject) jso;
final int cnt = length(o);
if (4 == cnt) {
return new Edit(get(o, 0), get(o, 1), get(o, 2), get(o, 3));
}
List<Edit> l = new ArrayList<>((cnt / 4) - 1);
for (int i = 4; i < cnt; ) {
int as = get(o, i++);
int ae = get(o, i++);
int bs = get(o, i++);
int be = get(o, i++);
l.add(new Edit(as, ae, bs, be));
}
return new ReplaceEdit(get(o, 0), get(o, 1), get(o, 2), get(o, 3), l);
}
@Override
public void printJson(StringBuilder sb, Edit o) {
sb.append('[');
append(sb, o);
if (o instanceof ReplaceEdit) {
for (Edit e : ((ReplaceEdit) o).getInternalEdits()) {
sb.append(',');
append(sb, e);
}
}
sb.append(']');
}
private void append(StringBuilder sb, Edit o) {
sb.append(o.getBeginA());
sb.append(',');
sb.append(o.getEndA());
sb.append(',');
sb.append(o.getBeginB());
sb.append(',');
sb.append(o.getEndB());
}
private static native int length(JavaScriptObject jso) /*-{ return jso.length; }-*/;
private static native int get(JavaScriptObject jso, int idx) /*-{ return jso[idx]; }-*/;
}

View File

@@ -0,0 +1,35 @@
// Copyright (C) 2010 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 org.eclipse.jgit.diff;
import java.util.List;
public class ReplaceEdit extends Edit {
private List<Edit> internalEdit;
public ReplaceEdit(int as, int ae, int bs, int be, List<Edit> internal) {
super(as, ae, bs, be);
internalEdit = internal;
}
public ReplaceEdit(Edit orig, List<Edit> internal) {
super(orig.getBeginA(), orig.getEndA(), orig.getBeginB(), orig.getEndB());
internalEdit = internal;
}
public List<Edit> getInternalEdits() {
return internalEdit;
}
}

View File

@@ -0,0 +1,30 @@
// Copyright (C) 2009 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 org.eclipse.jgit.internal.storage.file;
// Hack to obtain visibility to package level methods only.
// These aren't yet part of the public JGit API.
public class WindowCacheStatAccessor {
public static int getOpenFiles() {
return WindowCache.getInstance().getOpenFiles();
}
public static long getOpenBytes() {
return WindowCache.getInstance().getOpenBytes();
}
private WindowCacheStatAccessor() {}
}

View File

@@ -0,0 +1,54 @@
// Copyright (C) 2009 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 org.eclipse.jgit.lib;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.eclipse.jgit.util.IO;
public class ObjectIdSerialization {
public static void writeCanBeNull(OutputStream out, AnyObjectId id) throws IOException {
if (id != null) {
out.write((byte) 1);
writeNotNull(out, id);
} else {
out.write((byte) 0);
}
}
public static void writeNotNull(OutputStream out, AnyObjectId id) throws IOException {
id.copyRawTo(out);
}
public static ObjectId readCanBeNull(InputStream in) throws IOException {
switch (in.read()) {
case 0:
return null;
case 1:
return readNotNull(in);
default:
throw new IOException("Invalid flag before ObjectId");
}
}
public static ObjectId readNotNull(InputStream in) throws IOException {
final byte[] b = new byte[20];
IO.readFully(in, b, 0, 20);
return ObjectId.fromRaw(b);
}
private ObjectIdSerialization() {}
}