From 6b47596c47f5debb0a3690f2445c9a13697c940c Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Tue, 29 Apr 2014 16:30:36 -0700 Subject: [PATCH 1/3] Use properties file to map file extensions to CM3 mime types Use a properties file to map file extensions to the mime types used for syntax highlighting in codemirror. Using a properties file makes it easier to update the mapping and keep the lines sorted. Change-Id: Ic84c01b5fd783ffbc59873daa5e758317409f163 (cherry picked from commit bac7d1c053c8a5cdcf84c9628e29650df9fa5df2) --- .../server/DefaultFileExtensionRegistry.java | 75 +++++++++---------- .../gerrit/server/mime-types.properties | 19 +++++ 2 files changed, 55 insertions(+), 39 deletions(-) create mode 100644 gerrit-server/src/main/resources/com/google/gerrit/server/mime-types.properties diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/DefaultFileExtensionRegistry.java b/gerrit-server/src/main/java/com/google/gerrit/server/DefaultFileExtensionRegistry.java index 0416ba4ff9..61bd39ef4c 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/DefaultFileExtensionRegistry.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/DefaultFileExtensionRegistry.java @@ -16,60 +16,44 @@ package com.google.gerrit.server; import com.google.common.collect.ImmutableMap; +import eu.medsea.mimeutil.MimeException; import eu.medsea.mimeutil.MimeType; import eu.medsea.mimeutil.MimeUtil; import eu.medsea.mimeutil.detector.MimeDetector; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Collection; import java.util.Collections; +import java.util.Map; +import java.util.Properties; +/** Loads mime types from {@code mime-types.properties} at specificity of 2. */ public class DefaultFileExtensionRegistry extends MimeDetector { - private static final MimeType INI = newMimeType("text/x-ini", 2); - private static final MimeType PYTHON = newMimeType("text/x-python", 2); - private static final MimeType PERL = newMimeType("text/x-perl", 2); - private static final MimeType LISP = newMimeType("text/x-common-lisp", 2); - - private static final ImmutableMap TYPES = - ImmutableMap.builder() - .put(".gitmodules", INI) - .put("project.config", INI) - .put("BUCK", PYTHON) - .put("bucklet", newMimeType(PYTHON.toString(), 1)) - .put("defs", newMimeType(PYTHON.toString(), 1)) - .put("py", newMimeType(PYTHON.toString(), 1)) - .put("go", newMimeType("text/x-go", 1)) - .put("cxx", newMimeType("text/x-c++src", 1)) - .put("hxx", newMimeType("text/x-c++hdr", 1)) - .put("scala", newMimeType("text/x-scala", 1)) - .put("pl", PERL) - .put("pm", PERL) - .put("rb", newMimeType("text/x-ruby", 2)) - .put("cl", LISP) - .put("el", LISP) - .put("lisp", LISP) - .put("lsp", LISP) - .put("clj", newMimeType("text/x-clojure", 2)) - .put("groovy", newMimeType("text/x-groovy", 2)) - .build(); - - private static MimeType newMimeType(String type, final int specificity) { - return new MimeType(type) { - private static final long serialVersionUID = 1L; - - @Override - public int getSpecificity() { - return specificity; - } - }; - } + private static final Logger log = LoggerFactory.getLogger(DefaultFileExtensionRegistry.class); + private static final ImmutableMap TYPES; static { - for (MimeType type : TYPES.values()) { + Properties prop = new Properties(); + try (InputStream in = DefaultFileExtensionRegistry.class + .getResourceAsStream("mime-types.properties")) { + prop.load(in); + } catch (IOException e) { + log.warn("Cannot load mime-types.properties", e); + } + + ImmutableMap.Builder b = ImmutableMap.builder(); + for (Map.Entry e : prop.entrySet()) { + MimeType type = new FileExtensionMimeType((String) e.getValue()); + b.put((String) e.getKey(), type); MimeUtil.addKnownMimeType(type); } + TYPES = b.build(); } @Override @@ -119,4 +103,17 @@ public class DefaultFileExtensionRegistry extends MimeDetector { protected Collection getMimeTypesByteArray(byte[] arg0) { return Collections.emptyList(); } + + private static final class FileExtensionMimeType extends MimeType { + private static final long serialVersionUID = 1L; + + FileExtensionMimeType(String mimeType) throws MimeException { + super(mimeType); + } + + @Override + public int getSpecificity() { + return 2; + } + } } diff --git a/gerrit-server/src/main/resources/com/google/gerrit/server/mime-types.properties b/gerrit-server/src/main/resources/com/google/gerrit/server/mime-types.properties new file mode 100644 index 0000000000..baeb34d73f --- /dev/null +++ b/gerrit-server/src/main/resources/com/google/gerrit/server/mime-types.properties @@ -0,0 +1,19 @@ +bucklet = text/x-python +BUCK = text/x-python +clj = text/x-clojure +cl = text/x-common-lisp +cxx = text/x-c++src +defs = text/x-python +el = text/x-common-lisp +gitmodules = text/x-ini +go = text/x-go +groovy = text/x-groovy +hxx = text/x-c++hdr +lisp = text/x-common-lisp +lsp = text/x-common-lisp +pl = text/x-perl +pm = text/x-perl +project.config = text/x-ini +py = text/x-python +rb = text/x-ruby +scala = text/x-scala From 1065a871cc9f7122f315491bc32753bab9e8c91c Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Tue, 29 Apr 2014 16:50:30 -0700 Subject: [PATCH 2/3] SideBySide2: Add syntax highlighting for 18 more languages Include more languages into the CM3 mapping supported by Gerrit: * coffeescript * d * diff * dtd * erlang * gas * gfm (GitHub Flavored Markdown) * haskell * lua * markdown * php * pig * r * scheme * smalltalk * tcl * verilog * yaml Change-Id: Ie3cc3657183a475fb71a71e0fe35be848deb985f (cherry picked from commit 5478148f6f25db215424f51d6a5e88f7bf78f164) --- .../java/net/codemirror/lib/ModeInjector.java | 17 ++++++ .../main/java/net/codemirror/mode/Modes.java | 18 ++++++ .../main/java/net/codemirror/mode/mode_map | 58 +++++++++++++++++++ .../gerrit/server/mime-types.properties | 19 ++++++ lib/codemirror/cm3.defs | 18 ++++++ 5 files changed, 130 insertions(+) diff --git a/gerrit-gwtui/src/main/java/net/codemirror/lib/ModeInjector.java b/gerrit-gwtui/src/main/java/net/codemirror/lib/ModeInjector.java index 02faccbb50..5cd88b4d0b 100644 --- a/gerrit-gwtui/src/main/java/net/codemirror/lib/ModeInjector.java +++ b/gerrit-gwtui/src/main/java/net/codemirror/lib/ModeInjector.java @@ -43,19 +43,36 @@ public class ModeInjector { Modes.I.clike(), Modes.I.clojure(), Modes.I.commonlisp(), + Modes.I.coffeescript(), Modes.I.css(), + Modes.I.d(), + Modes.I.diff(), + Modes.I.dtd(), + Modes.I.erlang(), + Modes.I.gas(), + Modes.I.gfm(), Modes.I.go(), Modes.I.groovy(), + Modes.I.haskell(), Modes.I.htmlmixed(), Modes.I.javascript(), + Modes.I.lua(), + Modes.I.markdown(), Modes.I.perl(), + Modes.I.php(), + Modes.I.pig(), Modes.I.properties(), Modes.I.python(), + Modes.I.r(), Modes.I.ruby(), + Modes.I.scheme(), Modes.I.shell(), + Modes.I.smalltalk(), Modes.I.sql(), Modes.I.velocity(), + Modes.I.verilog(), Modes.I.xml(), + Modes.I.yaml(), }; mimeAlias = new HashMap<>(); diff --git a/gerrit-gwtui/src/main/java/net/codemirror/mode/Modes.java b/gerrit-gwtui/src/main/java/net/codemirror/mode/Modes.java index 307403a5bc..547c4a1a4d 100644 --- a/gerrit-gwtui/src/main/java/net/codemirror/mode/Modes.java +++ b/gerrit-gwtui/src/main/java/net/codemirror/mode/Modes.java @@ -27,19 +27,37 @@ public interface Modes extends ClientBundle { @Source("clike/clike.js") @DoNotEmbed DataResource clike(); @Source("clojure/clojure.js") @DoNotEmbed DataResource clojure(); @Source("commonlisp/commonlisp.js") @DoNotEmbed DataResource commonlisp(); + @Source("coffeescript/coffeescript.js") @DoNotEmbed DataResource coffeescript(); @Source("css/css.js") @DoNotEmbed DataResource css(); + @Source("d/d.js") @DoNotEmbed DataResource d(); + @Source("diff/diff.js") @DoNotEmbed DataResource diff(); + @Source("dtd/dtd.js") @DoNotEmbed DataResource dtd(); + @Source("erlang/erlang.js") @DoNotEmbed DataResource erlang(); + @Source("gas/gas.js") @DoNotEmbed DataResource gas(); + @Source("gfm/gfm.js") @DoNotEmbed DataResource gfm(); @Source("go/go.js") @DoNotEmbed DataResource go(); @Source("groovy/groovy.js") @DoNotEmbed DataResource groovy(); + @Source("haskell/haskell.js") @DoNotEmbed DataResource haskell(); @Source("htmlmixed/htmlmixed.js") @DoNotEmbed DataResource htmlmixed(); @Source("javascript/javascript.js") @DoNotEmbed DataResource javascript(); + @Source("lua/lua.js") @DoNotEmbed DataResource lua(); + @Source("markdown/markdown.js") @DoNotEmbed DataResource markdown(); @Source("perl/perl.js") @DoNotEmbed DataResource perl(); + @Source("php/php.js") @DoNotEmbed DataResource php(); + @Source("pig/pig.js") @DoNotEmbed DataResource pig(); @Source("properties/properties.js") @DoNotEmbed DataResource properties(); @Source("python/python.js") @DoNotEmbed DataResource python(); + @Source("r/r.js") @DoNotEmbed DataResource r(); @Source("ruby/ruby.js") @DoNotEmbed DataResource ruby(); + @Source("scheme/scheme.js") @DoNotEmbed DataResource scheme(); @Source("shell/shell.js") @DoNotEmbed DataResource shell(); + @Source("smalltalk/smalltalk.js") @DoNotEmbed DataResource smalltalk(); @Source("sql/sql.js") @DoNotEmbed DataResource sql(); + @Source("tcl/tcl.js") @DoNotEmbed DataResource tcl(); @Source("velocity/velocity.js") @DoNotEmbed DataResource velocity(); + @Source("verilog/verilog.js") @DoNotEmbed DataResource verilog(); @Source("xml/xml.js") @DoNotEmbed DataResource xml(); + @Source("yaml/yaml.js") @DoNotEmbed DataResource yaml(); // When adding a resource, update static initializer in ModeInjector. } diff --git a/gerrit-gwtui/src/main/java/net/codemirror/mode/mode_map b/gerrit-gwtui/src/main/java/net/codemirror/mode/mode_map index c62920d5ef..8c8a0cdeab 100644 --- a/gerrit-gwtui/src/main/java/net/codemirror/mode/mode_map +++ b/gerrit-gwtui/src/main/java/net/codemirror/mode/mode_map @@ -11,6 +11,9 @@ text/x-scala clojure: text/x-clojure +coffeescript: +text/x-coffeescript + commonlisp: text/x-common-lisp @@ -18,12 +21,33 @@ css: text/css text/x-scss +d: +text/x-d + +diff: +text/x-diff + +dtd: +application/xml-dtd + +erlang: +text/x-erlang + +gas: +text/x-gas + +gfm: +text/x-github-markdown + go: text/x-go groovy: text/x-groovy +haskell: +text/x-haskell + htmlmixed: text/html @@ -37,6 +61,12 @@ application/x-json text/typescript application/typescript +lua: +text/x-lua + +markdown: +text/x-markdown + perl: text/x-perl @@ -47,30 +77,58 @@ text/x-properties perl: text/x-perl +php: +application/x-httpd-php +application/x-httpd-php-open +text/x-php + +pig: +text/x-pig + python: text/x-python +r: +text/r-src + ruby: text/x-ruby +scheme: +text/x-scheme + shell: text/x-sh application/x-shellscript +smalltalk: +text/x-stsrc + sql: text/x-sql text/x-mariadb text/x-mysql text/x-plsql +tcl: +text/x-tcl + velocity: text/velocity +verilog: +text/x-verilog + xml: text/xml application/xml +yaml: +text/x-yaml + application/x-javascript = application/javascript application/x-shellscript = text/x-sh +application/x-tcl = text/x-tcl text/x-h = text/x-c++hdr text/x-java-source = text/x-java +text/x-scripttcl = text/x-tcl diff --git a/gerrit-server/src/main/resources/com/google/gerrit/server/mime-types.properties b/gerrit-server/src/main/resources/com/google/gerrit/server/mime-types.properties index baeb34d73f..aac1e5ade1 100644 --- a/gerrit-server/src/main/resources/com/google/gerrit/server/mime-types.properties +++ b/gerrit-server/src/main/resources/com/google/gerrit/server/mime-types.properties @@ -1,19 +1,38 @@ +as = text/x-gas bucklet = text/x-python BUCK = text/x-python clj = text/x-clojure cl = text/x-common-lisp +coffee = text/x-coffeescript cxx = text/x-c++src +d = text/x-d defs = text/x-python +diff = text/x-diff +dtd = application/xml-dtd el = text/x-common-lisp +erl = text/x-erlang gitmodules = text/x-ini go = text/x-go groovy = text/x-groovy +hs = text/x-haskell hxx = text/x-c++hdr lisp = text/x-common-lisp lsp = text/x-common-lisp +lua = text/x-lua +md = text/x-markdown +patch = text/x-diff +php = text/x-php +pig = text/x-pig pl = text/x-perl pm = text/x-perl project.config = text/x-ini +properties = text/x-ini py = text/x-python +r = text/r-src rb = text/x-ruby scala = text/x-scala +st = text/x-stsrc +v = text/x-verilog +vh = text/x-verilog +vm = text/velocity +yaml = text/x-yaml diff --git a/lib/codemirror/cm3.defs b/lib/codemirror/cm3.defs index 9679b1bef4..84f09c3e58 100644 --- a/lib/codemirror/cm3.defs +++ b/lib/codemirror/cm3.defs @@ -25,18 +25,36 @@ CM3_JS = [ CM3_MODES = [ 'clike/clike.js', 'clojure/clojure.js', + 'coffeescript/coffeescript.js', 'commonlisp/commonlisp.js', 'css/css.js', + 'd/d.js', + 'diff/diff.js', + 'dtd/dtd.js', + 'erlang/erlang.js', + 'gas/gas.js', + 'gfm/gfm.js', 'go/go.js', 'groovy/groovy.js', + 'haskell/haskell.js', 'htmlmixed/htmlmixed.js', 'javascript/javascript.js', + 'lua/lua.js', + 'markdown/markdown.js', 'perl/perl.js', + 'php/php.js', + 'pig/pig.js', 'properties/properties.js', 'python/python.js', + 'r/r.js', 'ruby/ruby.js', + 'scheme/scheme.js', 'shell/shell.js', + 'smalltalk/smalltalk.js', 'sql/sql.js', + 'tcl/tcl.js', 'velocity/velocity.js', + 'verilog/verilog.js', 'xml/xml.js', + 'yaml/yaml.js', ] From 8d5bbcd22171582c226e98bab7e02d3e5409f2b7 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Fri, 18 Jul 2014 10:12:09 +0200 Subject: [PATCH 3/3] 2.9 release notes: Add warning about download commands Add a warning that reminds administrators that the download-commands plugin must be installed for getting download-commands on the new change screen. This warning was already included in the 2.8 release notes but it makes sense to add this information to the 2.9 release notes as well. Some people may not have been interested in the beta version of the new change screen in 2.8 and hence they may have ignored the need for installing the download commands plugin. In addition provide more detailed instructions about how the download-commands plugin can be installed. Also add a warning about upgrading the plugin, since the 2.8 version of the download-commands plugin doesn't work with Gerrit 2.9. Explain that interactive init must be used to upgrade the plugin. Change-Id: I2101e0a3974ddb8d1fdf198941edc99305351650 Signed-off-by: Edwin Kempin --- ReleaseNotes/ReleaseNotes-2.9.txt | 50 ++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/ReleaseNotes/ReleaseNotes-2.9.txt b/ReleaseNotes/ReleaseNotes-2.9.txt index 64195a5178..9f2c9203ad 100644 --- a/ReleaseNotes/ReleaseNotes-2.9.txt +++ b/ReleaseNotes/ReleaseNotes-2.9.txt @@ -30,9 +30,57 @@ Schema Change java -jar gerrit.war reindex --recheck-mergeable -d site_path ---- -*WARNING* Support for query via the SQL index is removed. The usage of +*WARNING:* Support for query via the SQL index is removed. The usage of a secondary index is now mandatory. +*WARNING:* The new change screen only displays download commands if the +`download-commands` core plugin or any other plugin providing download +commands is installed. The `download-commands` plugin provides the +standard download schemes and commands. It is packaged together with +Gerrit and can be installed during the +link:https://gerrit-review.googlesource.com/Documentation/pgm-init.html[ +site initialization]: + +- Batch init: ++ +By default the batch init does *not* install any core plugin. To +install the `download-commands` plugin during batch init, specify the +'--install-plugin download-commands' option: ++ +---- + $ java -jar gerrit-2.9.war init -d site --batch --install-plugin download-commands +---- + +- Interactive init: ++ +There is a question whether the `download-commands` plugin should be +installed. To install the plugin the question must be answered with `y`: ++ +---- + Install plugin download-commands version v2.9 [y/N]? y +---- + +Pay attention that the 2.8 version of the `download-commands` plugin is +*not* compatible with Gerrit 2.9 and must be upgraded: + +- Batch init: ++ +With the batch init it is *not* possible to upgrade core plugins. + +- Interactive init: ++ +The interactive init asks whether the plugin should be upgraded: ++ +---- + Install plugin download-commands version v2.9 [y/N]? y + version v2.8.6.1 is already installed, overwrite it [y/N]? y +---- + +- Manual upgrade: ++ +The plugin can be upgraded manually by copying the new plugin jar into +the site's `plugins` folder. + *WARNING:* Upgrading to 2.9.x requires the server be first upgraded to 2.1.7 (or a later 2.1.x version), and then to 2.9.x. If you are upgrading from 2.2.x.x or later, you may ignore this warning and upgrade directly to 2.9.x.