From 1e279c10fda443744f4baa710744c3dbb29a551d Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Sat, 18 May 2013 14:58:59 -0700 Subject: [PATCH] Include codemirror 3.13 Download and package codemirror 3.13 for inclusion in the UI. This may eventually replace the current side-by-side viewer, as well as offer rich online editing to make small fixes to existing changes. Change-Id: I483fb46d9e18164d189826eca5cb96f9a1471c7e --- gerrit-gwtui/BUCK | 1 + .../com/google/gerrit/GerritGwtUI.gwt.xml | 4 ++ .../java/com/google/gerrit/client/Gerrit.java | 3 + .../java/net/codemirror/CodeMirror.gwt.xml | 20 ++++++ .../java/net/codemirror/lib/CodeMirror.java | 68 +++++++++++++++++++ .../src/main/java/net/codemirror/lib/Lib.java | 32 +++++++++ lib/BUCK | 1 + lib/LICENSE-codemirror | 19 ++++++ lib/codemirror/BUCK | 35 ++++++++++ 9 files changed, 183 insertions(+) create mode 100644 gerrit-gwtui/src/main/java/net/codemirror/CodeMirror.gwt.xml create mode 100644 gerrit-gwtui/src/main/java/net/codemirror/lib/CodeMirror.java create mode 100644 gerrit-gwtui/src/main/java/net/codemirror/lib/Lib.java create mode 100644 lib/LICENSE-codemirror create mode 100644 lib/codemirror/BUCK diff --git a/gerrit-gwtui/BUCK b/gerrit-gwtui/BUCK index dc47d82430..cf3824840b 100644 --- a/gerrit-gwtui/BUCK +++ b/gerrit-gwtui/BUCK @@ -74,6 +74,7 @@ gwt_module( '//lib:gwtjsonrpc_src', '//lib:gwtorm', '//lib:jsr305', + '//lib/codemirror:codemirror', '//lib/gwt:user', '//lib/jgit:jgit', ], 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 5fdc5bb3bd..d33a525e3e 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 @@ -28,11 +28,15 @@ + + + + diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java index c8f40b26f6..14008e6cd4 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java @@ -85,6 +85,8 @@ import com.google.gwtjsonrpc.client.impl.ResultDeserializer; import com.google.gwtjsonrpc.common.AsyncCallback; import com.google.gwtorm.client.KeyUtil; +import net.codemirror.lib.CodeMirror; + import java.util.ArrayList; public class Gerrit implements EntryPoint { @@ -366,6 +368,7 @@ public class Gerrit implements EntryPoint { initHostname(); Window.setTitle(M.windowTitle1(myHost)); + CodeMirror.install(); final HostPageDataService hpd = GWT.create(HostPageDataService.class); hpd.load(new GerritCallback() { diff --git a/gerrit-gwtui/src/main/java/net/codemirror/CodeMirror.gwt.xml b/gerrit-gwtui/src/main/java/net/codemirror/CodeMirror.gwt.xml new file mode 100644 index 0000000000..20e413c97a --- /dev/null +++ b/gerrit-gwtui/src/main/java/net/codemirror/CodeMirror.gwt.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/gerrit-gwtui/src/main/java/net/codemirror/lib/CodeMirror.java b/gerrit-gwtui/src/main/java/net/codemirror/lib/CodeMirror.java new file mode 100644 index 0000000000..0f08943eff --- /dev/null +++ b/gerrit-gwtui/src/main/java/net/codemirror/lib/CodeMirror.java @@ -0,0 +1,68 @@ +// 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 net.codemirror.lib; + +import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.ScriptElement; +import com.google.gwt.dom.client.StyleInjector; +import com.google.gwt.resources.client.ExternalTextResource; +import com.google.gwt.resources.client.ResourceCallback; +import com.google.gwt.resources.client.ResourceException; +import com.google.gwt.resources.client.TextResource; +import com.google.gwt.safehtml.shared.SafeUri; + +import java.util.logging.Level; +import java.util.logging.Logger; + +public class CodeMirror { + public static void install() { + asyncInjectCss(Lib.I.css()); + asyncInjectScript(Lib.I.js().getSafeUri()); + } + + private static void asyncInjectCss(ExternalTextResource css) { + try { + css.getText(new ResourceCallback() { + @Override + public void onSuccess(TextResource resource) { + StyleInjector.inject(resource.getText()); + } + + @Override + public void onError(ResourceException e) { + error(e); + } + }); + } catch (ResourceException e) { + error(e); + } + } + + private static void asyncInjectScript(SafeUri uri) { + ScriptElement script = Document.get().createScriptElement(); + script.setSrc(uri.asString()); + script.setLang("javascript"); + script.setType("text/javascript"); + Document.get().getBody().appendChild(script); + } + + private static void error(ResourceException e) { + Logger log = Logger.getLogger("net.codemirror"); + log.log(Level.SEVERE, "Cannot fetch CSS", e); + } + + private CodeMirror() { + } +} diff --git a/gerrit-gwtui/src/main/java/net/codemirror/lib/Lib.java b/gerrit-gwtui/src/main/java/net/codemirror/lib/Lib.java new file mode 100644 index 0000000000..242fd54d65 --- /dev/null +++ b/gerrit-gwtui/src/main/java/net/codemirror/lib/Lib.java @@ -0,0 +1,32 @@ +// 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 net.codemirror.lib; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.resources.client.DataResource; +import com.google.gwt.resources.client.DataResource.DoNotEmbed; +import com.google.gwt.resources.client.ExternalTextResource; + +interface Lib extends ClientBundle { + static final Lib I = GWT.create(Lib.class); + + @Source("codemirror.css") + ExternalTextResource css(); + + @Source("codemirror.js") + @DoNotEmbed + DataResource js(); +} diff --git a/lib/BUCK b/lib/BUCK index 9f24e6fe2e..a9d0bf6c3f 100644 --- a/lib/BUCK +++ b/lib/BUCK @@ -9,6 +9,7 @@ define_license(name = 'args4j') define_license(name = 'automaton') define_license(name = 'bouncycastle') define_license(name = 'clippy') +define_license(name = 'codemirror') define_license(name = 'h2') define_license(name = 'jgit') define_license(name = 'jsch') diff --git a/lib/LICENSE-codemirror b/lib/LICENSE-codemirror new file mode 100644 index 0000000000..cdb16cde3d --- /dev/null +++ b/lib/LICENSE-codemirror @@ -0,0 +1,19 @@ +Copyright (C) 2013 by Marijn Haverbeke + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/lib/codemirror/BUCK b/lib/codemirror/BUCK new file mode 100644 index 0000000000..5d5aaed758 --- /dev/null +++ b/lib/codemirror/BUCK @@ -0,0 +1,35 @@ +VERSION = '3.13' +SHA1 = '7a83ae686d75afd30bb152d7683f2dc27e59ea82' +URL = 'http://codemirror.net/codemirror-%s.zip' % VERSION + +# TODO(sop) Repackage by license boundaries. +# TODO(sop) Minify with Closure JS compiler. +genrule( + name = 'codemirror', + cmd = ';'.join([ + 'cd $TMP', + 'mkdir net META-INF', + 'unzip -d net $SRCS', + 'mv net/codemirror-%s net/codemirror' % VERSION, + 'echo "Manifest-Version: 1.0" >META-INF/MANIFEST.MF', + 'zip -r $OUT *' + ]), + srcs = [genfile('dist.zip')], + deps = [ + ':download', + '//lib:LICENSE-codemirror', + ], + out = 'codemirror.jar', + visibility = ['PUBLIC'], +) + +genrule( + name = 'download', + cmd = '${//tools:download_file}' + + ' -o $OUT' + + ' -u ' + URL + + ' -v ' + SHA1, + srcs = [], + deps = ['//tools:download_file'], + out = 'dist.zip', +)