Remove Mozilla Rhino from our build
Since we don't render the syntax highlighting on the server, because its just too damn slow, we don't need a full JavaScript language implementation in our runtime directory. Drop that dependency to save WAR file size and reduce the amount of code we have to keep track of. Change-Id: I937871a8053995f36b92a99b41bb5f6e97f0d1ed Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -49,7 +49,6 @@ ANTLR <<antlr,New-Style BSD>>
|
|||||||
args4j <<args4j,MIT License>>
|
args4j <<args4j,MIT License>>
|
||||||
SLF4J <<slf4j,MIT License>>
|
SLF4J <<slf4j,MIT License>>
|
||||||
Clippy <<clippy,MIT License>>
|
Clippy <<clippy,MIT License>>
|
||||||
Mozilla Rhino <<mpl1_1,MPL 1.1>>
|
|
||||||
juniversalchardet <<mpl1_1,MPL 1.1>>
|
juniversalchardet <<mpl1_1,MPL 1.1>>
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import com.google.gerrit.httpd.auth.ldap.LdapAuthModule;
|
|||||||
import com.google.gerrit.httpd.auth.openid.OpenIdModule;
|
import com.google.gerrit.httpd.auth.openid.OpenIdModule;
|
||||||
import com.google.gerrit.httpd.gitweb.GitWebModule;
|
import com.google.gerrit.httpd.gitweb.GitWebModule;
|
||||||
import com.google.gerrit.httpd.rpc.UiRpcModule;
|
import com.google.gerrit.httpd.rpc.UiRpcModule;
|
||||||
import com.google.gerrit.prettify.server.PrettifyModule;
|
|
||||||
import com.google.gerrit.reviewdb.AuthType;
|
import com.google.gerrit.reviewdb.AuthType;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
@@ -122,7 +121,6 @@ public class WebModule extends FactoryModule {
|
|||||||
install(new UiRpcModule());
|
install(new UiRpcModule());
|
||||||
install(new GerritRequestModule());
|
install(new GerritRequestModule());
|
||||||
install(new ProjectServlet.Module());
|
install(new ProjectServlet.Module());
|
||||||
install(new PrettifyModule());
|
|
||||||
|
|
||||||
bind(SshInfo.class).toProvider(sshInfoProvider);
|
bind(SshInfo.class).toProvider(sshInfoProvider);
|
||||||
bind(SshKeyCache.class).toProvider(sshKeyCacheProvider);
|
bind(SshKeyCache.class).toProvider(sshKeyCacheProvider);
|
||||||
|
|||||||
@@ -38,16 +38,6 @@ limitations under the License.
|
|||||||
<artifactId>gwtexpui</artifactId>
|
<artifactId>gwtexpui</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.code.guice</groupId>
|
|
||||||
<artifactId>guice</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>rhino</groupId>
|
|
||||||
<artifactId>js</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.gerrit</groupId>
|
<groupId>com.google.gerrit</groupId>
|
||||||
<artifactId>gerrit-patch-jgit</artifactId>
|
<artifactId>gerrit-patch-jgit</artifactId>
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
// 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 com.google.gerrit.prettify.server;
|
|
||||||
|
|
||||||
import com.google.gerrit.prettify.common.PrettyFactory;
|
|
||||||
import com.google.gerrit.prettify.common.PrettyFormatter;
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
|
|
||||||
public class PrettifyModule extends AbstractModule {
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
bind(ServerPrettyFactory.class);
|
|
||||||
bind(PrettyFactory.class).to(ServerPrettyFactory.class);
|
|
||||||
bind(PrettyFormatter.class).toProvider(ServerPrettyFactory.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
// 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 com.google.gerrit.prettify.server;
|
|
||||||
|
|
||||||
import com.google.gerrit.prettify.common.PrettyFactory;
|
|
||||||
import com.google.gerrit.prettify.common.PrettyFormatter;
|
|
||||||
import com.google.gerrit.prettify.common.PrettySettings;
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.google.inject.Provider;
|
|
||||||
import com.google.inject.Singleton;
|
|
||||||
|
|
||||||
import org.mozilla.javascript.Context;
|
|
||||||
import org.mozilla.javascript.ContextFactory;
|
|
||||||
import org.mozilla.javascript.Scriptable;
|
|
||||||
import org.mozilla.javascript.ScriptableObject;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
|
|
||||||
/** Runs prettify via Mozilla Rhino JavaScript engine. */
|
|
||||||
@Singleton
|
|
||||||
class ServerPrettyFactory implements PrettyFactory, Provider<PrettyFormatter> {
|
|
||||||
private final ContextFactory contextFactory;
|
|
||||||
private final ScriptableObject sharedScope;
|
|
||||||
private final Scriptable sharedWindow;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
ServerPrettyFactory() {
|
|
||||||
contextFactory = new ContextFactory() {
|
|
||||||
@Override
|
|
||||||
protected boolean hasFeature(Context cx, int featureIndex) {
|
|
||||||
if (featureIndex == Context.FEATURE_DYNAMIC_SCOPE) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.hasFeature(cx, featureIndex);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Context cx = contextFactory.enterContext();
|
|
||||||
try {
|
|
||||||
cx.setOptimizationLevel(9);
|
|
||||||
|
|
||||||
sharedScope = cx.initStandardObjects(null, true);
|
|
||||||
sharedWindow = cx.newObject(sharedScope);
|
|
||||||
sharedScope.put("window", sharedScope, sharedWindow);
|
|
||||||
|
|
||||||
compile(cx, "prettify.js");
|
|
||||||
compile(cx, "server-env.js");
|
|
||||||
|
|
||||||
compile(cx, "lang-apollo.js");
|
|
||||||
compile(cx, "lang-css.js");
|
|
||||||
compile(cx, "lang-hs.js");
|
|
||||||
compile(cx, "lang-lisp.js");
|
|
||||||
compile(cx, "lang-lua.js");
|
|
||||||
compile(cx, "lang-ml.js");
|
|
||||||
compile(cx, "lang-proto.js");
|
|
||||||
compile(cx, "lang-sql.js");
|
|
||||||
compile(cx, "lang-vb.js");
|
|
||||||
compile(cx, "lang-wiki.js");
|
|
||||||
} finally {
|
|
||||||
Context.exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PrettyFormatter get() {
|
|
||||||
return new PrettyFormatter() {
|
|
||||||
@Override
|
|
||||||
protected String prettify(String html, String type) {
|
|
||||||
return prettyPrintOne(html, type, settings);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private String prettyPrintOne(String srcText, String type, PrettySettings how) {
|
|
||||||
Context cx = contextFactory.enterContext();
|
|
||||||
try {
|
|
||||||
Scriptable callScope = cx.newObject(sharedScope);
|
|
||||||
callScope.setPrototype(sharedScope);
|
|
||||||
callScope.setParentScope(null);
|
|
||||||
|
|
||||||
// We have to clone and shadow the window object, so we can
|
|
||||||
// set a per-call window.PR_TAB_WIDTH value. Above we ensured
|
|
||||||
// we compiled our code in a dynamic scope so the window object
|
|
||||||
// resolution will happen to our shadowed value.
|
|
||||||
//
|
|
||||||
Scriptable callWindow = cx.newObject(callScope);
|
|
||||||
callWindow.setPrototype(sharedWindow);
|
|
||||||
callWindow.put("PR_TAB_WIDTH", callWindow, how.getTabSize());
|
|
||||||
|
|
||||||
callScope.put("window", callScope, callWindow);
|
|
||||||
callScope.put("srcText", callScope, srcText);
|
|
||||||
callScope.put("srcType", callScope, type);
|
|
||||||
String call = "prettyPrintOne(srcText, srcType)";
|
|
||||||
|
|
||||||
return cx.evaluateString(callScope, call, "<call>", 1, null).toString();
|
|
||||||
} finally {
|
|
||||||
Context.exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void compile(Context cx, String name) {
|
|
||||||
name = "com/google/gerrit/prettify/client/" + name;
|
|
||||||
|
|
||||||
InputStream in = getClass().getClassLoader().getResourceAsStream(name);
|
|
||||||
if (in == null) {
|
|
||||||
throw new RuntimeException("Cannot find " + name);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
final InputStreamReader r = new InputStreamReader(in, "UTF-8");
|
|
||||||
try {
|
|
||||||
cx.compileReader(r, name, 1, null).exec(cx, sharedScope);
|
|
||||||
} finally {
|
|
||||||
r.close();
|
|
||||||
}
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new RuntimeException("Cannot compile " + name, e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("Cannot compile " + name, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
6
pom.xml
6
pom.xml
@@ -704,12 +704,6 @@ limitations under the License.
|
|||||||
<version>1.3.9</version>
|
<version>1.3.9</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>rhino</groupId>
|
|
||||||
<artifactId>js</artifactId>
|
|
||||||
<version>1.7R2</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.gerrit</groupId>
|
<groupId>com.google.gerrit</groupId>
|
||||||
<artifactId>juniversalchardet</artifactId>
|
<artifactId>juniversalchardet</artifactId>
|
||||||
|
|||||||
Reference in New Issue
Block a user