Merge branch 'stable-2.15' into stable-2.16

* stable-2.15:
  Set version to 2.15.17-SNAPSHOT
  Set version to 2.15.16
  Revert "CreateAccount: Fail early when invalid SSH key is given"
  tools/eclipse/project.py: Fix typo of bazelisk
  Migrate from old-style legacy .java provider to the new JavaInfo.
  Support bazelisk or bazel in tools/eclipse/project.py
  Rework imports in project.py
  Update project.py to use argparse

Change-Id: If9388140c516f8ff2f5275eefe6cf65dad42449e
This commit is contained in:
David Pursehouse
2019-08-29 08:16:50 +09:00
4 changed files with 92 additions and 86 deletions

View File

@@ -131,16 +131,6 @@ public class CreateAccount
} }
extIds.add(ExternalId.createUsername(username, accountId, input.httpPassword)); extIds.add(ExternalId.createUsername(username, accountId, input.httpPassword));
if (input.sshKey != null) {
try {
authorizedKeys.addKey(accountId, input.sshKey);
sshKeyCache.evict(username);
} catch (InvalidSshKeyException e) {
throw new BadRequestException(e.getMessage());
}
}
for (AccountExternalIdCreator c : externalIdCreators) { for (AccountExternalIdCreator c : externalIdCreators) {
extIds.addAll(c.create(accountId, username, input.email)); extIds.addAll(c.create(accountId, username, input.email));
} }
@@ -173,6 +163,15 @@ public class CreateAccount
} }
} }
if (input.sshKey != null) {
try {
authorizedKeys.addKey(accountId, input.sshKey);
sshKeyCache.evict(username);
} catch (InvalidSshKeyException e) {
throw new BadRequestException(e.getMessage());
}
}
AccountLoader loader = infoLoader.create(true); AccountLoader loader = infoLoader.create(true);
AccountInfo info = loader.get(accountId); AccountInfo info = loader.get(accountId);
loader.fill(); loader.fill();

View File

@@ -317,21 +317,6 @@ public class AccountIT extends AbstractDaemonTest {
RefUpdateCounter.projectRef(allUsers, RefNames.REFS_SEQUENCES + Sequences.NAME_ACCOUNTS)); RefUpdateCounter.projectRef(allUsers, RefNames.REFS_SEQUENCES + Sequences.NAME_ACCOUNTS));
} }
@Test
public void createWithInvalidSshKey() throws Exception {
AccountInput input = new AccountInput();
input.username = name("test");
input.sshKey = "invalid key";
// Invalid key should cause the creation to fail
BadRequestException thrown =
assertThrows(BadRequestException.class, () -> gApi.accounts().create(input));
assertThat(thrown).hasMessageThat().isEqualTo("Invalid SSH Key");
// The account should not have been created
assertThrows(ResourceNotFoundException.class, () -> gApi.accounts().id(input.username).get());
}
@Test @Test
public void createWithInvalidEmailAddress() throws Exception { public void createWithInvalidEmailAddress() throws Exception {
AccountInput input = new AccountInput(); AccountInput input = new AccountInput();

View File

@@ -78,8 +78,8 @@ def _war_impl(ctx):
# Add lib # Add lib
transitive_libs = [] transitive_libs = []
for j in ctx.attr.libs: for j in ctx.attr.libs:
if hasattr(j, "java"): if JavaInfo in j:
transitive_libs.append(j.java.transitive_runtime_deps) transitive_libs.append(j[JavaInfo].transitive_runtime_deps)
elif hasattr(j, "files"): elif hasattr(j, "files"):
transitive_libs.append(j.files) transitive_libs.append(j.files)
@@ -91,7 +91,7 @@ def _war_impl(ctx):
# Add pgm lib # Add pgm lib
transitive_pgmlibs = [] transitive_pgmlibs = []
for j in ctx.attr.pgmlibs: for j in ctx.attr.pgmlibs:
transitive_pgmlibs.append(j.java.transitive_runtime_deps) transitive_pgmlibs.append(j[JavaInfo].transitive_runtime_deps)
transitive_pgmlib_deps = depset(transitive = transitive_pgmlibs) transitive_pgmlib_deps = depset(transitive = transitive_pgmlibs)
for dep in transitive_pgmlib_deps.to_list(): for dep in transitive_pgmlib_deps.to_list():

View File

@@ -12,17 +12,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
#
from __future__ import print_function from __future__ import print_function
# TODO(davido): use Google style for importing instead: import argparse
# import optparse import os
# ... import subprocess
# optparse.OptionParser import xml.dom.minidom
from optparse import OptionParser
from os import environ, path, makedirs
from subprocess import CalledProcessError, check_call, check_output
from xml.dom import minidom
import re import re
import sys import sys
@@ -41,30 +36,57 @@ cp_targets = {
MAIN: '//tools/eclipse:main_classpath_collect', MAIN: '//tools/eclipse:main_classpath_collect',
} }
ROOT = path.abspath(__file__) ROOT = os.path.abspath(__file__)
while not path.exists(path.join(ROOT, 'WORKSPACE')): while not os.path.exists(os.path.join(ROOT, 'WORKSPACE')):
ROOT = path.dirname(ROOT) ROOT = os.path.dirname(ROOT)
opts = OptionParser() opts = argparse.ArgumentParser("Create Eclipse Project")
opts.add_option('--plugins', help='create eclipse projects for plugins', opts.add_argument('--plugins', help='create eclipse projects for plugins',
action='store_true') action='store_true')
opts.add_option('--name', help='name of the generated project', opts.add_argument('--name', help='name of the generated project',
action='store', default='gerrit', dest='project_name') action='store', default='gerrit', dest='project_name')
opts.add_option('-b', '--batch', action='store_true', opts.add_argument('-b', '--batch', action='store_true',
dest='batch', help='Bazel batch option') dest='batch', help='Bazel batch option')
opts.add_option('-j', '--java', action='store', opts.add_argument('-j', '--java', action='store',
dest='java', help='Post Java 8 support (9)') dest='java', help='Post Java 8 support (9)')
opts.add_option('-e', '--edge_java', action='store', opts.add_argument('-e', '--edge_java', action='store',
dest='edge_java', help='Post Java 9 support (10|11|...)') dest='edge_java', help='Post Java 9 support (10|11|...)')
opts.add_option('--bazel', help='name of the bazel executable', opts.add_argument('--bazel',
action='store', default='bazel', dest='bazel_exe') help=('name of the bazel executable. Defaults to using'
' bazelisk if found, or bazel if bazelisk is not'
' found.'),
action='store', default=None, dest='bazel_exe')
args = opts.parse_args()
def find_bazel():
if args.bazel_exe:
try:
return subprocess.check_output(
['which', args.bazel_exe]).strip().decode('UTF-8')
except subprocess.CalledProcessError:
print('Bazel command: %s not found' % args.bazel_exe, file=sys.stderr)
sys.exit(1)
try:
return subprocess.check_output(
['which', 'bazelisk']).strip().decode('UTF-8')
except subprocess.CalledProcessError:
try:
return subprocess.check_output(
['which', 'bazel']).strip().decode('UTF-8')
except subprocess.CalledProcessError:
print("Neither bazelisk nor bazel found. Please see"
" Documentation/dev-bazel for instructions on installing"
" one of them.")
sys.exit(1)
args, _ = opts.parse_args()
batch_option = '--batch' if args.batch else None batch_option = '--batch' if args.batch else None
custom_java = args.java custom_java = args.java
edge_java = args.edge_java edge_java = args.edge_java
bazel_exe = args.bazel_exe bazel_exe = find_bazel()
def _build_bazel_cmd(*args): def _build_bazel_cmd(*args):
build = False build = False
@@ -84,23 +106,23 @@ def _build_bazel_cmd(*args):
def retrieve_ext_location(): def retrieve_ext_location():
return check_output(_build_bazel_cmd('info', 'output_base')).strip() return subprocess.check_output(_build_bazel_cmd('info', 'output_base')).strip()
def gen_bazel_path(ext_location): def gen_bazel_path(ext_location):
bazel = check_output(['which', bazel_exe]).strip().decode('UTF-8') bazel = subprocess.check_output(['which', bazel_exe]).strip().decode('UTF-8')
with open(path.join(ROOT, ".bazel_path"), 'w') as fd: with open(os.path.join(ROOT, ".bazel_path"), 'w') as fd:
fd.write("output_base=%s\n" % ext_location) fd.write("output_base=%s\n" % ext_location)
fd.write("bazel=%s\n" % bazel) fd.write("bazel=%s\n" % bazel)
fd.write("PATH=%s\n" % environ["PATH"]) fd.write("PATH=%s\n" % os.environ["PATH"])
def _query_classpath(target): def _query_classpath(target):
deps = [] deps = []
t = cp_targets[target] t = cp_targets[target]
try: try:
check_call(_build_bazel_cmd('build', t)) subprocess.check_call(_build_bazel_cmd('build', t))
except CalledProcessError: except subprocess.CalledProcessError:
exit(1) exit(1)
name = 'bazel-bin/tools/eclipse/' + t.split(':')[1] + '.runtime_classpath' name = 'bazel-bin/tools/eclipse/' + t.split(':')[1] + '.runtime_classpath'
deps = [line.rstrip('\n') for line in open(name)] deps = [line.rstrip('\n') for line in open(name)]
@@ -108,7 +130,7 @@ def _query_classpath(target):
def gen_project(name='gerrit', root=ROOT): def gen_project(name='gerrit', root=ROOT):
p = path.join(root, '.project') p = os.path.join(root, '.project')
with open(p, 'w') as fd: with open(p, 'w') as fd:
print("""\ print("""\
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
@@ -127,9 +149,9 @@ def gen_project(name='gerrit', root=ROOT):
def gen_plugin_classpath(root): def gen_plugin_classpath(root):
p = path.join(root, '.classpath') p = os.path.join(root, '.classpath')
with open(p, 'w') as fd: with open(p, 'w') as fd:
if path.exists(path.join(root, 'src', 'test', 'java')): if os.path.exists(os.path.join(root, 'src', 'test', 'java')):
testpath = """ testpath = """
<classpathentry excluding="**/BUILD" kind="src" path="src/test/java"\ <classpathentry excluding="**/BUILD" kind="src" path="src/test/java"\
out="eclipse-out/test"> out="eclipse-out/test">
@@ -149,7 +171,7 @@ def gen_plugin_classpath(root):
def gen_classpath(ext): def gen_classpath(ext):
def make_classpath(): def make_classpath():
impl = minidom.getDOMImplementation() impl = xml.dom.minidom.getDOMImplementation()
return impl.createDocument(None, 'classpath', None) return impl.createDocument(None, 'classpath', None)
def classpathentry(kind, path, src=None, out=None, exported=None): def classpathentry(kind, path, src=None, out=None, exported=None):
@@ -191,7 +213,7 @@ def gen_classpath(ext):
if p.endswith('-src.jar'): if p.endswith('-src.jar'):
# gwt_module() depends on -src.jar for Java to JavaScript compiles. # gwt_module() depends on -src.jar for Java to JavaScript compiles.
if p.startswith("external"): if p.startswith("external"):
p = path.join(ext, p) p = os.path.join(ext, p)
gwt_lib.add(p) gwt_lib.add(p)
continue continue
@@ -217,7 +239,7 @@ def gen_classpath(ext):
"external/bazel_tools/tools/jdk/TestRunner_deploy.jar"): "external/bazel_tools/tools/jdk/TestRunner_deploy.jar"):
continue continue
if p.startswith("external"): if p.startswith("external"):
p = path.join(ext, p) p = os.path.join(ext, p)
lib.add(p) lib.add(p)
for p in _query_classpath(GWT): for p in _query_classpath(GWT):
@@ -239,8 +261,8 @@ def gen_classpath(ext):
continue continue
out = 'eclipse-out/' + s out = 'eclipse-out/' + s
p = path.join(s, 'java') p = os.path.join(s, 'java')
if path.exists(p): if os.path.exists(p):
classpathentry('src', p, out=out) classpathentry('src', p, out=out)
continue continue
@@ -252,8 +274,8 @@ def gen_classpath(ext):
o = 'eclipse-out/test' o = 'eclipse-out/test'
for srctype in ['java', 'resources']: for srctype in ['java', 'resources']:
p = path.join(s, 'src', env, srctype) p = os.path.join(s, 'src', env, srctype)
if path.exists(p): if os.path.exists(p):
classpathentry('src', p, out=o) classpathentry('src', p, out=o)
for libs in [lib, gwt_lib]: for libs in [lib, gwt_lib]:
@@ -263,8 +285,8 @@ def gen_classpath(ext):
if m: if m:
prefix = m.group(1) prefix = m.group(1)
suffix = m.group(2) suffix = m.group(2)
p = path.join(prefix, "jar", "%s-src.jar" % suffix) p = os.path.join(prefix, "jar", "%s-src.jar" % suffix)
if path.exists(p): if os.path.exists(p):
s = p s = p
if args.plugins: if args.plugins:
classpathentry('lib', j, s, exported=True) classpathentry('lib', j, s, exported=True)
@@ -287,20 +309,20 @@ def gen_classpath(ext):
classpathentry('lib', p, s) classpathentry('lib', p, s)
for s in sorted(gwt_src): for s in sorted(gwt_src):
p = path.join(ROOT, s, 'src', 'main', 'java') p = os.path.join(ROOT, s, 'src', 'main', 'java')
if path.exists(p): if os.path.exists(p):
classpathentry('lib', p, out='eclipse-out/gwtsrc') classpathentry('lib', p, out='eclipse-out/gwtsrc')
classpathentry('con', JRE) classpathentry('con', JRE)
classpathentry('output', 'eclipse-out/classes') classpathentry('output', 'eclipse-out/classes')
p = path.join(ROOT, '.classpath') p = os.path.join(ROOT, '.classpath')
with open(p, 'w') as fd: with open(p, 'w') as fd:
doc.writexml(fd, addindent='\t', newl='\n', encoding='UTF-8') doc.writexml(fd, addindent='\t', newl='\n', encoding='UTF-8')
if args.plugins: if args.plugins:
for plugin in plugins: for plugin in plugins:
plugindir = path.join(ROOT, plugin) plugindir = os.path.join(ROOT, plugin)
try: try:
gen_project(plugin.replace('plugins/', ""), plugindir) gen_project(plugin.replace('plugins/', ""), plugindir)
gen_plugin_classpath(plugindir) gen_plugin_classpath(plugindir)
@@ -310,17 +332,17 @@ def gen_classpath(ext):
def gen_factorypath(ext): def gen_factorypath(ext):
doc = minidom.getDOMImplementation().createDocument(None, 'factorypath', doc = xml.dom.minidom.getDOMImplementation().createDocument(
None) None, 'factorypath', None)
for jar in _query_classpath(AUTO): for jar in _query_classpath(AUTO):
e = doc.createElement('factorypathentry') e = doc.createElement('factorypathentry')
e.setAttribute('kind', 'EXTJAR') e.setAttribute('kind', 'EXTJAR')
e.setAttribute('id', path.join(ext, jar)) e.setAttribute('id', os.path.join(ext, jar))
e.setAttribute('enabled', 'true') e.setAttribute('enabled', 'true')
e.setAttribute('runInBatchMode', 'false') e.setAttribute('runInBatchMode', 'false')
doc.documentElement.appendChild(e) doc.documentElement.appendChild(e)
p = path.join(ROOT, '.factorypath') p = os.path.join(ROOT, '.factorypath')
with open(p, 'w') as fd: with open(p, 'w') as fd:
doc.writexml(fd, addindent='\t', newl='\n', encoding='UTF-8') doc.writexml(fd, addindent='\t', newl='\n', encoding='UTF-8')
@@ -334,13 +356,13 @@ try:
# TODO(davido): Remove this when GWT gone # TODO(davido): Remove this when GWT gone
gwt_working_dir = ".gwt_work_dir" gwt_working_dir = ".gwt_work_dir"
if not path.isdir(gwt_working_dir): if not os.path.isdir(gwt_working_dir):
makedirs(path.join(ROOT, gwt_working_dir)) os.makedirs(os.path.join(ROOT, gwt_working_dir))
try: try:
check_call(_build_bazel_cmd('build', MAIN, GWT, subprocess.check_call(_build_bazel_cmd('build', MAIN, GWT,
'//java/org/eclipse/jgit:libEdit-src.jar')) '//java/org/eclipse/jgit:libEdit-src.jar'))
except CalledProcessError: except subprocess.CalledProcessError:
exit(1) exit(1)
except KeyboardInterrupt: except KeyboardInterrupt:
print('Interrupted by user', file=sys.stderr) print('Interrupted by user', file=sys.stderr)