diff --git a/BUILD b/BUILD new file mode 100644 index 0000000000..28dd0f50a0 --- /dev/null +++ b/BUILD @@ -0,0 +1,14 @@ +load('//tools/bzl:genrule2.bzl', 'genrule2') +load('//tools/bzl:pkg_war.bzl', 'pkg_war') + +genrule2( + name = 'version', + srcs = ['VERSION'], + cmd = "grep GERRIT_VERSION $< | cut -d \"'\" -f 2 >$@", + out = 'version.txt', + visibility = ['//visibility:public'], +) + +pkg_war(name = 'gerrit') +pkg_war(name = 'headless', ui = None) + diff --git a/WORKSPACE b/WORKSPACE index e93a911335..3cdc34ac27 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -118,6 +118,12 @@ maven_jar( sha1 = 'cdb2dcb4e22b83d6b32b93095f644c3462739e82', ) +http_jar( + name = "javax_validation_src", + url = "http://repo1.maven.org/maven2/javax/validation/validation-api/1.0.0.GA/validation-api-1.0.0.GA-sources.jar", + sha256 = 'a394d52a9b7fe2bb14f0718d2b3c8308ffe8f37e911956012398d55c9f9f9b54', +) + JGIT_VERS = '4.4.1.201607150455-r.118-g1096652' maven_jar( @@ -746,3 +752,29 @@ maven_jar( artifact = 'xerces:xercesImpl:2.8.1', sha1 = '25101e37ec0c907db6f0612cbf106ee519c1aef1', ) + +maven_jar( + name = 'postgresql', + artifact = 'postgresql:postgresql:9.1-901-1.jdbc4', + sha1 = '9bfabe48876ec38f6cbaa6931bad05c64a9ea942', +) + +CM_VERSION = '5.18.2' + +maven_jar( + name = 'codemirror_minified', + artifact = 'org.webjars.npm:codemirror-minified:' + CM_VERSION, + sha1 = '6755af157a7eaf2401468906bef67bbacc3c97f6', +) + +maven_jar( + name = 'codemirror_original', + artifact = 'org.webjars.npm:codemirror:' + CM_VERSION, + sha1 = '18c721ae88eed27cddb458c42f5d221fa3d9713e', +) + +maven_jar( + name = 'diff_match_patch', + artifact = 'org.webjars:google-diff-match-patch:20121119-1', + sha1 = '0cf1782dbcb8359d95070da9176059a5a9d37709', +) diff --git a/gerrit-acceptance-framework/BUILD b/gerrit-acceptance-framework/BUILD index 934e8d1968..58c13f5c9b 100644 --- a/gerrit-acceptance-framework/BUILD +++ b/gerrit-acceptance-framework/BUILD @@ -59,3 +59,12 @@ java_library2( ], visibility = ['//visibility:public'], ) + +load('//tools/bzl:javadoc.bzl', 'java_doc') + +java_doc( + name = 'acceptance-framework-javadoc', + title = 'Gerrit Acceptance Test Framework Documentation', + libs = [':lib'], + pkgs = ['com.google.gerrit.acceptance'], +) diff --git a/gerrit-extension-api/BUILD b/gerrit-extension-api/BUILD index 4a5cfe3858..b66617a4db 100644 --- a/gerrit-extension-api/BUILD +++ b/gerrit-extension-api/BUILD @@ -44,3 +44,12 @@ java_library( ], visibility = ['//visibility:public'], ) + +load('//tools/bzl:javadoc.bzl', 'java_doc') + +java_doc( + name = 'extension-api-javadoc', + title = 'Gerrit Review Extension API Documentation', + libs = [':api'], + pkgs = ['com.google.gerrit.extensions'], +) diff --git a/gerrit-gwtui-common/BUILD b/gerrit-gwtui-common/BUILD new file mode 100644 index 0000000000..01a82af859 --- /dev/null +++ b/gerrit-gwtui-common/BUILD @@ -0,0 +1,69 @@ +load('//tools/bzl:genrule2.bzl', 'genrule2') +load('//tools/bzl:java.bzl', 'java_library2') +load('//tools/bzl:junit.bzl', 'junit_tests') +load('//tools/bzl:gwt.bzl', 'gwt_module') + +EXPORTED_DEPS = [ + '//gerrit-common:client', + '//gerrit-gwtexpui:Clippy', + '//gerrit-gwtexpui:GlobalKey', + '//gerrit-gwtexpui:Progress', + '//gerrit-gwtexpui:SafeHtml', + '//gerrit-gwtexpui:UserAgent', +] +DEPS = ['//lib/gwt:user'] +SRC = 'src/main/java/com/google/gerrit/' +DIFFY = glob(['src/main/resources/com/google/gerrit/client/diffy*.png']) + +gwt_module( + name = 'client', + srcs = glob(['src/main/**/*.java']), + gwt_xml = SRC + 'GerritGwtUICommon.gwt.xml', + resources = glob( + ['src/main/**/*'], + exclude = [SRC + 'client/**/*.java'] + + [SRC + 'GerritGwtUICommon.gwt.xml'] + ), + exported_deps = EXPORTED_DEPS, + deps = DEPS, + visibility = ['//visibility:public'], +) + +java_library2( + name = 'client-lib', + srcs = glob(['src/main/**/*.java']), + resources = glob(['src/main/**/*']), + exported_deps = EXPORTED_DEPS, + deps = DEPS, + visibility = ['//visibility:public'], +) + +java_import( + name = 'diffy_logo', + jars = [':diffy_image_files_ln'], + visibility = ['//visibility:public'], +) + +genrule2( + name = 'diffy_image_files_ln', + srcs = [':diffy_image_files'], + cmd = 'ln -s $$ROOT/$(location :diffy_image_files) $@', + out = 'diffy_images.jar', +) + +java_library( + name = 'diffy_image_files', + resources = DIFFY, +) + +junit_tests( + name = 'client_tests', + srcs = glob(['src/test/java/**/*.java']), + deps = [ + ':client', + '//lib:junit', + '//lib/gwt:dev', + '//lib/jgit/org.eclipse.jgit:jgit', + ], + visibility = ['//visibility:public'], +) diff --git a/gerrit-gwtui/BUILD b/gerrit-gwtui/BUILD new file mode 100644 index 0000000000..dbf02e8a59 --- /dev/null +++ b/gerrit-gwtui/BUILD @@ -0,0 +1,89 @@ +load('//tools/bzl:gwt.bzl', 'gwt_module') +load('//tools/bzl:genrule2.bzl', 'genrule2') +load(':gwt.bzl', 'gwt_binary') + +MODULE = 'com.google.gerrit.GerritGwtUI' + +GWT_JVM_ARGS = ['-Xmx512m'] + +GWT_COMPILER_ARGS = [ + '-XdisableClassMetadata', +] + +GWT_COMPILER_ARGS_RELEASE_MODE = GWT_COMPILER_ARGS + [ + '-XdisableCastChecking', +] + +GWT_TRANSITIVE_DEPS = [ + '//lib/gwt:javax-validation', + '//lib/gwt:javax-validation_src', + '//lib/ow2:ow2-asm', + '//lib/ow2:ow2-asm-analysis', + '//lib/ow2:ow2-asm-commons', + '//lib/ow2:ow2-asm-tree', + '//lib/ow2:ow2-asm-util', +] + +DEPS = GWT_TRANSITIVE_DEPS + [ + '//gerrit-gwtexpui:CSS', + '//lib:gwtjsonrpc', + '//lib/gwt:dev', + '@jgit_src//file', +] + +gwt_module( + name = 'ui_module', + srcs = glob(['src/main/java/**/*.java']), + gwt_xml = 'src/main/java/%s.gwt.xml' % MODULE.replace('.', '/'), + resources = glob( + ['src/main/java/**/*'], + exclude = ['src/main/java/**/*.java'] + + ['src/main/java/%s.gwt.xml' % MODULE.replace('.', '/')] + ), + deps = [ + '//gerrit-gwtui-common:diffy_logo', + '//gerrit-gwtui-common:client', + '//gerrit-gwtexpui:CSS', + '//lib/codemirror:codemirror', + '//lib/gwt:user', + ], + visibility = ['//visibility:public'], +) + +genrule2( + name = 'ui_optdbg', + srcs = [ + ':ui_dbg', + ':ui_opt', + ], + cmd = 'cd $$TMP;' + + 'unzip -q $$ROOT/$(location :ui_dbg);' + + 'mv' + + ' gerrit_ui/gerrit_ui.nocache.js' + + ' gerrit_ui/dbg_gerrit_ui.nocache.js;' + + 'unzip -qo $$ROOT/$(location :ui_opt);' + + 'mkdir -p $$(dirname $@);' + + 'zip -qr $$ROOT/$@ .', + out = 'ui_optdbg.zip', + visibility = ['//visibility:public'], +) + +gwt_binary( + name = 'ui_opt', + modules = [MODULE], + module_deps = [':ui_module'], + deps = DEPS, + compiler_args = GWT_COMPILER_ARGS, + jvm_args = GWT_JVM_ARGS, +) + +gwt_binary( + name = 'ui_dbg', + modules = [MODULE], + style = 'PRETTY', + optimize = "0", + module_deps = [':ui_module'], + deps = DEPS, + compiler_args = GWT_COMPILER_ARGS, + jvm_args = GWT_JVM_ARGS, +) diff --git a/gerrit-gwtui/gwt.bzl b/gerrit-gwtui/gwt.bzl new file mode 100644 index 0000000000..91936ded91 --- /dev/null +++ b/gerrit-gwtui/gwt.bzl @@ -0,0 +1,95 @@ +# Copyright (C) 2016 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. + +# Port of Buck native gwt_binary() rule. See discussion in context of +# https://github.com/facebook/buck/issues/109 + +jar_filetype = FileType(['.jar']) +GWT_COMPILER = "com.google.gwt.dev.Compiler" + +def _impl(ctx): + output_zip = ctx.outputs.output + output_dir = output_zip.path + '.gwt_output' + deploy_dir = output_zip.path + '.gwt_deploy' + + deps = _get_transitive_closure(ctx) + + paths = [] + for dep in deps: + paths.append(dep.path) + + cmd = "external/local_jdk/bin/java %s -Dgwt.normalizeTimestamps=true -cp %s %s -war %s -deploy %s " % ( + " ".join(ctx.attr.jvm_args), + ":".join(paths), + GWT_COMPILER, + output_dir, + deploy_dir, + ) + cmd += " ".join([ + "-style %s" % ctx.attr.style, + "-optimize %s" % ctx.attr.optimize, + "-strict", + " ".join(ctx.attr.compiler_args), + " ".join(ctx.attr.modules) + "\n", + "rm -rf %s/gwt-unitCache\n" % output_dir, + "root=`pwd`\n", + "cd %s; $root/%s Cc ../%s $(find .)\n" % ( + output_dir, + ctx.executable._zip.path, + output_zip.basename, + ) + ]) + + ctx.action( + inputs = list(deps) + ctx.files._jdk + ctx.files._zip, + outputs = [output_zip], + mnemonic = "GwtBinary", + progress_message = "GWT compiling " + output_zip.short_path, + command = "set -e\n" + cmd, + ) + +def _get_transitive_closure(ctx): + deps = set() + for dep in ctx.attr.module_deps: + deps += dep.java.transitive_runtime_deps + deps += dep.java.transitive_source_jars + for dep in ctx.attr.deps: + if hasattr(dep, 'java'): + deps += dep.java.transitive_runtime_deps + elif hasattr(dep, 'files'): + deps += dep.files + + return deps + +gwt_binary = rule( + implementation = _impl, + attrs = { + "style": attr.string(default = "OBF"), + "optimize": attr.string(default = "9"), + "deps": attr.label_list(allow_files=jar_filetype), + "modules": attr.string_list(mandatory=True), + "module_deps": attr.label_list(allow_files=jar_filetype), + "compiler_args": attr.string_list(), + "jvm_args": attr.string_list(), + "_jdk": attr.label( + default=Label("//tools/defaults:jdk")), + "_zip": attr.label( + default=Label("@bazel_tools//tools/zip:zipper"), + executable=True, + single_file=True), + }, + outputs = { + "output": "%{name}.zip", + }, +) diff --git a/gerrit-main/BUILD b/gerrit-main/BUILD new file mode 100644 index 0000000000..67863c5626 --- /dev/null +++ b/gerrit-main/BUILD @@ -0,0 +1,13 @@ +java_binary( + name = 'main_bin', + main_class = 'Main', + runtime_deps = [':main_lib'], + visibility = ['//visibility:public'], +) + +java_library( + name = 'main_lib', + srcs = ['src/main/java/Main.java'], + deps = ['//gerrit-launcher:launcher'], + visibility = ['//visibility:public'], +) diff --git a/gerrit-plugin-api/BUILD b/gerrit-plugin-api/BUILD index c7617037b8..9404acc8b3 100644 --- a/gerrit-plugin-api/BUILD +++ b/gerrit-plugin-api/BUILD @@ -58,3 +58,38 @@ java_library( ], visibility = ['//visibility:public'], ) + +java_binary( + name = 'plugin-api-sources', + main_class = 'Dummy', + runtime_deps = [ + '//gerrit-antlr:libquery_exception-src.jar', + '//gerrit-antlr:libquery_parser-src.jar', + '//gerrit-common:libannotations-src.jar', + '//gerrit-extension-api:libapi-src.jar', + '//gerrit-gwtexpui:libserver-src.jar', + '//gerrit-httpd:libhttpd-src.jar', + '//gerrit-pgm:libinit-api-src.jar', + '//gerrit-reviewdb:libserver-src.jar', + '//gerrit-server:libserver-src.jar', + '//gerrit-sshd:libsshd-src.jar', + ], + visibility = ['//visibility:public'], +) + +load('//tools/bzl:javadoc.bzl', 'java_doc') + +java_doc( + name = 'plugin-api-javadoc', + title = 'Gerrit Review Plugin API Documentation', + pkgs = ['com.google.gerrit'], + libs = PLUGIN_API + [ + '//gerrit-antlr:query_exception', + '//gerrit-antlr:query_parser', + '//gerrit-common:annotations', + '//gerrit-common:server', + '//gerrit-extension-api:api', + '//gerrit-gwtexpui:server', + '//gerrit-reviewdb:server', + ], +) diff --git a/gerrit-server/BUILD b/gerrit-server/BUILD index a591fba2cd..6c7ab3e681 100644 --- a/gerrit-server/BUILD +++ b/gerrit-server/BUILD @@ -208,3 +208,12 @@ junit_tests( ], visibility = ['//visibility:public'], ) + +load('//tools/bzl:javadoc.bzl', 'java_doc') + +java_doc( + name = 'doc', + title = 'Gerrit Review Server Documentation', + libs = [':server'], + pkgs = ['com.google.gerrit'], +) diff --git a/gerrit-war/BUILD b/gerrit-war/BUILD new file mode 100644 index 0000000000..86c838f37e --- /dev/null +++ b/gerrit-war/BUILD @@ -0,0 +1,70 @@ +load('//tools/bzl:genrule2.bzl', 'genrule2') + +java_library( + name = 'init', + srcs = glob(['src/main/java/**/*.java']), + deps = [ + '//gerrit-cache-h2:cache-h2', + '//gerrit-extension-api:api', + '//gerrit-gpg:gpg', + '//gerrit-httpd:httpd', + '//gerrit-lucene:lucene', + '//gerrit-oauth:oauth', + '//gerrit-openid:openid', + '//gerrit-pgm:http', + '//gerrit-pgm:init', + '//gerrit-pgm:init-api', + '//gerrit-pgm:util', + '//gerrit-reviewdb:server', + '//gerrit-server:server', + '//gerrit-server/src/main/prolog:common', + '//gerrit-sshd:sshd', + '//lib:guava', + '//lib:gwtorm', + '//lib:servlet-api-3_1', + '//lib/guice:guice', + '//lib/guice:guice-servlet', + '//lib/jgit/org.eclipse.jgit:jgit', + '//lib/log:api', + ], + visibility = ['//visibility:public'], +) + +genrule2( + name = 'webapp_assets', + cmd = 'cd gerrit-war/src/main/webapp; zip -qr $$ROOT/$@ .', + srcs = glob(['src/main/webapp/**/*']), + out = 'webapp_assets.zip', + visibility = ['//visibility:public'], +) + +java_import( + name = 'log4j-config', + jars = [':log4j-config__jar'], + visibility = ['//visibility:public'], +) + +genrule2( + name = 'log4j-config__jar', + cmd = 'cd gerrit-war/src/main/resources && zip -9Dqr $$ROOT/$@ .', + srcs = ['src/main/resources/log4j.properties'], + out = 'log4j-config.jar', +) + +java_import( + name = 'version', + jars = [':gen_version'], + visibility = ['//visibility:public'], +) + +genrule2( + name = 'gen_version', + cmd = ' && '.join([ + 'cd $$TMP', + 'mkdir -p com/google/gerrit/common', + 'cat $$ROOT/$(location //:version) >com/google/gerrit/common/Version', + 'zip -9Dqr $$ROOT/$@ .', + ]), + tools = ['//:version'], + out = 'gen_version.jar', +) diff --git a/lib/BUILD b/lib/BUILD index a4900387b3..44c293d5d7 100644 --- a/lib/BUILD +++ b/lib/BUILD @@ -231,3 +231,9 @@ java_library( exports = [ '@icu4j//jar' ], visibility = ['//visibility:public'], ) + +java_library( + name = 'postgresql', + exports = ['@postgresql//jar'], + visibility = ['//visibility:public'], +) diff --git a/lib/codemirror/BUILD b/lib/codemirror/BUILD new file mode 100644 index 0000000000..0a62d413d9 --- /dev/null +++ b/lib/codemirror/BUILD @@ -0,0 +1,2 @@ +load('//lib/codemirror:cm.bzl', 'pkg_cm') +pkg_cm() diff --git a/lib/codemirror/cm.bzl b/lib/codemirror/cm.bzl new file mode 100644 index 0000000000..b4e55fe1fb --- /dev/null +++ b/lib/codemirror/cm.bzl @@ -0,0 +1,355 @@ +load('//tools/bzl:genrule2.bzl', 'genrule2') + +CM_CSS = [ + 'lib/codemirror.css', + 'addon/dialog/dialog.css', + 'addon/merge/merge.css', + 'addon/scroll/simplescrollbars.css', + 'addon/search/matchesonscrollbar.css', + 'addon/lint/lint.css', +] + +CM_JS = [ + 'lib/codemirror.js', + 'mode/meta.js', + 'keymap/emacs.js', + 'keymap/sublime.js', + 'keymap/vim.js', +] + +CM_ADDONS = [ + 'dialog/dialog.js', + 'edit/closebrackets.js', + 'edit/matchbrackets.js', + 'edit/trailingspace.js', + 'scroll/annotatescrollbar.js', + 'scroll/simplescrollbars.js', + 'search/jump-to-line.js', + 'search/matchesonscrollbar.js', + 'search/searchcursor.js', + 'search/search.js', + 'selection/mark-selection.js', + 'mode/multiplex.js', + 'mode/overlay.js', + 'mode/simple.js', + 'lint/lint.js', +] + +# Available themes must be enumerated here, +# in gerrit-extension-api/src/main/java/com/google/gerrit/extensions/common/Theme.java, +# in gerrit-gwtui/src/main/java/net/codemirror/theme/Themes.java +CM_THEMES = [ + '3024-day', + '3024-night', + 'abcdef', + 'ambiance', + 'base16-dark', + 'base16-light', + 'bespin', + 'blackboard', + 'cobalt', + 'colorforth', + 'dracula', + 'eclipse', + 'elegant', + 'erlang-dark', + 'hopscotch', + 'icecoder', + 'isotope', + 'lesser-dark', + 'liquibyte', + 'material', + 'mbo', + 'mdn-like', + 'midnight', + 'monokai', + 'neat', + 'neo', + 'night', + 'paraiso-dark', + 'paraiso-light', + 'pastel-on-dark', + 'railscasts', + 'rubyblue', + 'seti', + 'solarized', + 'the-matrix', + 'tomorrow-night-bright', + 'tomorrow-night-eighties', + 'ttcn', + 'twilight', + 'vibrant-ink', + 'xq-dark', + 'xq-light', + 'yeti', + 'zenburn', +] + +# Available modes must be enumerated here, +# in gerrit-gwtui/src/main/java/net/codemirror/mode/Modes.java, +# gerrit-gwtui/src/main/java/net/codemirror/mode/ModeInfo.java, +# and in CodeMirror's own mode/meta.js script. +CM_MODES = [ + 'apl', + 'asciiarmor', + 'asn.1', + 'asterisk', + 'brainfuck', + 'clike', + 'clojure', + 'cmake', + 'cobol', + 'coffeescript', + 'commonlisp', + 'crystal', + 'css', + 'cypher', + 'd', + 'dart', + 'diff', + 'django', + 'dockerfile', + 'dtd', + 'dylan', + 'ebnf', + 'ecl', + 'eiffel', + 'elm', + 'erlang', + 'factor', + 'fcl', + 'forth', + 'fortran', + 'gas', + 'gfm', + 'gherkin', + 'go', + 'groovy', + 'haml', + 'handlebars', + 'haskell-literate', + 'haskell', + 'haxe', + 'htmlembedded', + 'htmlmixed', + 'http', + 'idl', + 'javascript', + 'jinja2', + 'jsx', + 'julia', + 'livescript', + 'lua', + 'markdown', + 'mathematica', + 'mbox', + 'mirc', + 'mllike', + 'modelica', + 'mscgen', + 'mumps', + 'nginx', + 'nsis', + 'ntriples', + 'octave', + 'oz', + 'pascal', + 'pegjs', + 'perl', + 'php', + 'pig', + 'powershell', + 'properties', + 'protobuf', + 'pug', + 'puppet', + 'python', + 'q', + 'r', + 'rpm', + 'rst', + 'ruby', + 'rust', + 'sas', + 'sass', + 'scheme', + 'shell', + 'sieve', + 'slim', + 'smalltalk', + 'smarty', + 'solr', + 'soy', + 'sparql', + 'spreadsheet', + 'sql', + 'stex', + 'stylus', + 'swift', + 'tcl', + 'textile', + 'tiddlywiki', + 'tiki', + 'toml', + 'tornado', + 'troff', + 'ttcn-cfg', + 'ttcn', + 'turtle', + 'twig', + 'vb', + 'vbscript', + 'velocity', + 'verilog', + 'vhdl', + 'vue', + 'webidl', + 'xml', + 'xquery', + 'yacas', + 'yaml-frontmatter', + 'yaml', + 'z80', +] + +VERSION = '5.18.2' +TOP = 'META-INF/resources/webjars/codemirror/%s' % VERSION +TOP_MINIFIED = 'META-INF/resources/webjars/codemirror-minified/%s' % VERSION + +DIFF_MATCH_PATCH_VERSION = '20121119-1' +DIFF_MATCH_PATCH_TOP = ('META-INF/resources/webjars/google-diff-match-patch/%s' + % DIFF_MATCH_PATCH_VERSION) + +def pkg_cm(): + for archive, suffix, top in [ + ('@codemirror_original//jar', '', TOP), + ('@codemirror_minified//jar', '_r', TOP_MINIFIED) + ]: + # Main JavaScript and addons + genrule2( + name = 'cm' + suffix, + cmd = ' && '.join([ + "echo '/** @license' >$@", + 'unzip -p $(location %s) %s/LICENSE >>$@' % (archive, top), + "echo '*/' >>$@", + ] + + ['unzip -p $(location %s) %s/%s >>$@' % (archive, top, n) for n in CM_JS] + + ['unzip -p $(location %s) %s/addon/%s >>$@' % (archive, top, n) + for n in CM_ADDONS] + ), + tools = [ + '@codemirror_original//jar', + '@codemirror_minified//jar', + ], + out = 'cm%s.js' % suffix, + ) + + # Main CSS + genrule2( + name = 'css' + suffix, + cmd = ' && '.join([ + "echo '/** @license' >$@", + 'unzip -p $(location %s) %s/LICENSE >>$@' % (archive, top), + "echo '*/' >>$@", + ] + + ['unzip -p $(location %s) %s/%s >>$@' % (archive, top, n) + for n in CM_CSS] + ), + tools = [ + '@codemirror_original//jar', + '@codemirror_minified//jar', + ], + out = 'cm%s.css' % suffix, + ) + + # Modes + for n in CM_MODES: + genrule2( + name = 'mode_%s%s' % (n, suffix), + cmd = ' && '.join([ + "echo '/** @license' >$@", + 'unzip -p $(location %s) %s/LICENSE >>$@' % (archive, top), + "echo '*/' >>$@", + 'unzip -p $(location %s) %s/mode/%s/%s.js >>$@' % (archive, top, n, n), + ] + ), + tools = [ + '@codemirror_original//jar', + '@codemirror_minified//jar', + ], + out = 'mode_%s%s.js' % (n, suffix), + ) + + # Themes + for n in CM_THEMES: + genrule2( + name = 'theme_%s%s' % (n, suffix), + cmd = ' && '.join([ + "echo '/** @license' >$@", + 'unzip -p $(location %s) %s/LICENSE >>$@' % (archive, top), + "echo '*/' >>$@", + 'unzip -p $(location %s) %s/theme/%s.css >>$@' % (archive, top, n) + ] + ), + tools = [ + '@codemirror_original//jar', + '@codemirror_minified//jar', + ], + out = 'theme_%s%s.css' % (n, suffix), + ) + + # Merge Addon bundled with diff-match-patch + genrule2( + name = 'addon_merge%s' % suffix, + cmd = ' && '.join([ + "echo '/** @license' >$@", + 'unzip -p $(location %s) %s/LICENSE >>$@' % (archive, top), + "echo '*/\n' >>$@", + "echo '// The google-diff-match-patch library is from https://google-diff-match-patch.googlecode.com/svn-history/r106/trunk/javascript/diff_match_patch.js\n' >> $@", + "echo '/** @license' >>$@", + "echo 'LICENSE-Apache2.0' >>$@", + "echo '*/' >>$@", + 'unzip -p $(location @diff_match_patch//jar) %s/diff_match_patch.js >>$@' % DIFF_MATCH_PATCH_TOP, + "echo ';' >> $@", + 'unzip -p $(location %s) %s/addon/merge/merge.js >>$@' % (archive, top) + ] + ), + tools = [ + '@diff_match_patch//jar', + '@codemirror_original//jar', + '@codemirror_minified//jar', + ], + out = 'addon_merge%s.js' % suffix, + ) + + # Jar packaging + genrule2( + name = 'jar' + suffix, + cmd = ' && '.join([ + 'cd $$TMP', + 'mkdir -p net/codemirror/{addon,lib,mode,theme}', + 'cp $$ROOT/$(location :css%s) net/codemirror/lib/cm.css' % suffix, + 'cp $$ROOT/$(location :cm%s) net/codemirror/lib/cm.js' % suffix] + + ['cp $$ROOT/$(location :mode_%s%s) net/codemirror/mode/%s.js' % (n, suffix, n) + for n in CM_MODES] + + ['cp $$ROOT/$(location :theme_%s%s) net/codemirror/theme/%s.css' % (n, suffix, n) + for n in CM_THEMES] + + ['cp $$ROOT/$(location :addon_merge%s) net/codemirror/addon/merge_bundled.js' % suffix] + + ['zip -qr $$ROOT/$@ net/codemirror/{addon,lib,mode,theme}']), + tools = [ + ':addon_merge%s' % suffix, + ':cm%s' % suffix, + ':css%s' % suffix, + ] + [ + ':mode_%s%s' % (n, suffix) for n in CM_MODES + ] + [ + ':theme_%s%s' % (n, suffix) for n in CM_THEMES + ], + out = 'codemirror%s.jar' % suffix, + ) + + native.java_import( + name = 'codemirror' + suffix, + jars = [':jar%s' % suffix], + visibility = ['//visibility:public'], + ) diff --git a/lib/gwt/BUILD b/lib/gwt/BUILD index 2168bb4c3d..bf04c9503a 100644 --- a/lib/gwt/BUILD +++ b/lib/gwt/BUILD @@ -7,3 +7,9 @@ 'dev', 'user', ]] + +java_library( + name = 'javax-validation_src', + exports = ['@javax_validation_src//jar'], + visibility = ['//visibility:public'], +) diff --git a/tools/bzl/gwt.bzl b/tools/bzl/gwt.bzl index 29987ef284..c27e28f756 100644 --- a/tools/bzl/gwt.bzl +++ b/tools/bzl/gwt.bzl @@ -19,8 +19,6 @@ load('//tools/bzl:java.bzl', 'java_library2') def gwt_module(gwt_xml=None, resources=[], srcs=[], **kwargs): if gwt_xml: resources += [gwt_xml] - if srcs: - resources += srcs java_library2( srcs = srcs, diff --git a/tools/bzl/javadoc.bzl b/tools/bzl/javadoc.bzl new file mode 100644 index 0000000000..80771da7e0 --- /dev/null +++ b/tools/bzl/javadoc.bzl @@ -0,0 +1,71 @@ +# Copyright (C) 2016 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. + +# Javadoc rule. + +def _impl(ctx): + zip_output = ctx.outputs.zip + + transitive_jar_set = set() + source_jars = set() + for l in ctx.attr.libs: + source_jars += l.java.source_jars + transitive_jar_set += l.java.transitive_deps + + transitive_jar_paths = [j.path for j in transitive_jar_set] + dir = ctx.outputs.zip.path + ".dir" + source = ctx.outputs.zip.path + ".source" + cmd = [ + "mkdir %s" % source, + " && ".join(["unzip -qud %s %s" % (source, j.path) for j in source_jars]), + "mkdir %s" % dir, + " ".join([ + ctx.file._javadoc.path, + "-protected", + "-encoding UTF-8", + "-charset UTF-8", + "-notimestamp", + "-quiet", + "-windowtitle '%s'" % ctx.attr.title, + "-link", "http://docs.oracle.com/javase/7/docs/api", + "-sourcepath %s" % source, + "-subpackages ", + ":".join(ctx.attr.pkgs), + " -classpath ", + ":".join(transitive_jar_paths), + "-d %s" % dir]), + "find %s -exec touch -t 198001010000 '{}' ';'" % dir, + "(cd %s && zip -qr ../%s *)" % (dir, ctx.outputs.zip.basename), + ] + ctx.action( + inputs = list(transitive_jar_set) + list(source_jars) + ctx.files._jdk, + outputs = [zip_output], + command = " && ".join(cmd)) + +java_doc = rule( + attrs = { + "libs": attr.label_list(allow_files = False), + "pkgs": attr.string_list(), + "title": attr.string(), + "_javadoc": attr.label( + default = Label("@local_jdk//:bin/javadoc"), + single_file = True, + allow_files = True), + "_jdk": attr.label( + default = Label("@local_jdk//:jdk-default"), + allow_files = True), + }, + implementation = _impl, + outputs = {"zip" : "%{name}.zip"}, +) diff --git a/tools/bzl/pkg_war.bzl b/tools/bzl/pkg_war.bzl new file mode 100644 index 0000000000..8c3c6cba56 --- /dev/null +++ b/tools/bzl/pkg_war.bzl @@ -0,0 +1,139 @@ +# Copyright (C) 2016 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. + +# War packaging. + +jar_filetype = FileType(['.jar']) + +LIBS = [ + '//gerrit-war:init', + '//gerrit-war:log4j-config', + '//gerrit-war:version', + '//lib:postgresql', + '//lib/log:impl_log4j', +] + +PGMLIBS = [ + '//gerrit-pgm:pgm' +] + +def _add_context(in_file, output): + input_path = in_file.path + return [ + 'unzip -qd %s %s' % (output, input_path) + ] + +def _add_file(in_file, output): + output_path = output + input_path = in_file.path + short_path = in_file.short_path + n = in_file.basename + + # TODO(davido): Drop this when provided_deps added to java_library + if n.find('-jdk15on-') != -1: + return [] + + if short_path.startswith('gerrit-'): + n = short_path.split('/')[0] + '-' + n + + output_path += n + return [ + 'test -L %s || ln -s $(pwd)/%s %s' % (output_path, input_path, output_path) + ] + +def _make_war(input_dir, output): + return ''.join([ + '(root=$(pwd) && ', + 'cd %s && ' % input_dir, + 'zip -9qr ${root}/%s .)' % (output.path), + ]) + +def _war_impl(ctx): + war = ctx.outputs.war + build_output = war.path + '.build_output' + inputs = [] + + # Create war layout + cmd = [ + 'set -e;rm -rf ' + build_output, + 'mkdir -p ' + build_output, + 'mkdir -p %s/WEB-INF/lib' % build_output, + 'mkdir -p %s/WEB-INF/pgm-lib' % build_output, + ] + + # Add lib + transitive_lib_deps = set() + for l in ctx.attr.libs: + transitive_lib_deps += l.java.transitive_runtime_deps + + for dep in transitive_lib_deps: + cmd += _add_file(dep, build_output + '/WEB-INF/lib/') + inputs.append(dep) + + # Add pgm lib + transitive_pgmlib_deps = set() + for l in ctx.attr.pgmlibs: + transitive_pgmlib_deps += l.java.transitive_runtime_deps + + for dep in transitive_pgmlib_deps: + if dep not in inputs: + cmd += _add_file(dep, build_output + '/WEB-INF/pgm-lib/') + inputs.append(dep) + + # Add context + transitive_context_deps = set() + if ctx.attr.context: + for jar in ctx.attr.context: + if hasattr(jar, 'java'): + transitive_context_deps += jar.java.transitive_runtime_deps + elif hasattr(jar, 'files'): + transitive_context_deps += jar.files + for dep in transitive_context_deps: + cmd += _add_context(dep, build_output) + inputs.append(dep) + + # Add zip war + cmd.append(_make_war(build_output, war)) + + ctx.action( + inputs = inputs, + outputs = [war], + mnemonic = 'WAR', + command = '\n'.join(cmd), + use_default_shell_env = True, + ) + +_pkg_war = rule( + attrs = { + 'context': attr.label_list(allow_files = True), + 'libs': attr.label_list(allow_files = jar_filetype), + 'pgmlibs': attr.label_list(allow_files = False), + }, + implementation = _war_impl, + outputs = {'war' : '%{name}.war'}, +) + +def pkg_war(name, ui = 'ui_optdbg'): + ui_deps = [] + if ui: + ui_deps.append('//gerrit-gwtui:%s' % ui) + _pkg_war( + name = name, + libs = LIBS, + pgmlibs = PGMLIBS, + context = ui_deps + [ + '//gerrit-main:main_bin_deploy.jar', + '//gerrit-war:webapp_assets', + ], + )