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
This commit is contained in:
Shawn Pearce
2013-05-18 14:58:59 -07:00
parent 8713eb859e
commit 1e279c10fd
9 changed files with 183 additions and 0 deletions

View File

@@ -74,6 +74,7 @@ gwt_module(
'//lib:gwtjsonrpc_src',
'//lib:gwtorm',
'//lib:jsr305',
'//lib/codemirror:codemirror',
'//lib/gwt:user',
'//lib/jgit:jgit',
],

View File

@@ -28,11 +28,15 @@
<inherits name='com.google.gerrit.Common'/>
<inherits name='com.google.gerrit.UserAgent'/>
<inherits name='org.eclipse.jgit.JGit'/>
<inherits name='net.codemirror.CodeMirror'/>
<extend-property name='locale' values='en'/>
<set-property-fallback name='locale' value='en'/>
<set-property name='locale' value='en'/>
<set-configuration-property name='UiBinder.useSafeHtmlTemplates' value='true'/>
<set-property name='gwt.logging.logLevel' value='SEVERE'/>
<set-property name='gwt.logging.popupHandler' value='DISABLED'/>
<entry-point class='com.google.gerrit.client.Gerrit'/>
</module>

View File

@@ -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<HostPageData>() {

View File

@@ -0,0 +1,20 @@
<!--
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.
-->
<module>
<inherits name='com.google.gwt.logging.Logging'/>
<inherits name='com.google.gwt.resources.Resources'/>
<source path='lib'/>
</module>

View File

@@ -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<TextResource>() {
@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() {
}
}

View File

@@ -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();
}

View File

@@ -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')

19
lib/LICENSE-codemirror Normal file
View File

@@ -0,0 +1,19 @@
Copyright (C) 2013 by Marijn Haverbeke <marijnh@gmail.com>
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.

35
lib/codemirror/BUCK Normal file
View File

@@ -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',
)