diff --git a/java/com/google/gerrit/server/restapi/account/CreateAccount.java b/java/com/google/gerrit/server/restapi/account/CreateAccount.java index 15cae02704..4185f3602d 100644 --- a/java/com/google/gerrit/server/restapi/account/CreateAccount.java +++ b/java/com/google/gerrit/server/restapi/account/CreateAccount.java @@ -131,16 +131,6 @@ public class CreateAccount } 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) { 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); AccountInfo info = loader.get(accountId); loader.fill(); diff --git a/javatests/com/google/gerrit/acceptance/api/accounts/AccountIT.java b/javatests/com/google/gerrit/acceptance/api/accounts/AccountIT.java index 9c5b81d2e0..be30ab7390 100644 --- a/javatests/com/google/gerrit/acceptance/api/accounts/AccountIT.java +++ b/javatests/com/google/gerrit/acceptance/api/accounts/AccountIT.java @@ -317,21 +317,6 @@ public class AccountIT extends AbstractDaemonTest { 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 public void createWithInvalidEmailAddress() throws Exception { AccountInput input = new AccountInput(); diff --git a/tools/bzl/pkg_war.bzl b/tools/bzl/pkg_war.bzl index cb189db108..dd60079d3c 100644 --- a/tools/bzl/pkg_war.bzl +++ b/tools/bzl/pkg_war.bzl @@ -78,8 +78,8 @@ def _war_impl(ctx): # Add lib transitive_libs = [] for j in ctx.attr.libs: - if hasattr(j, "java"): - transitive_libs.append(j.java.transitive_runtime_deps) + if JavaInfo in j: + transitive_libs.append(j[JavaInfo].transitive_runtime_deps) elif hasattr(j, "files"): transitive_libs.append(j.files) @@ -91,7 +91,7 @@ def _war_impl(ctx): # Add pgm lib transitive_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) for dep in transitive_pgmlib_deps.to_list(): diff --git a/tools/eclipse/project.py b/tools/eclipse/project.py index 997ba5fdbf..979f3285d9 100755 --- a/tools/eclipse/project.py +++ b/tools/eclipse/project.py @@ -12,17 +12,12 @@ # 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. -# from __future__ import print_function -# TODO(davido): use Google style for importing instead: -# import optparse -# ... -# optparse.OptionParser -from optparse import OptionParser -from os import environ, path, makedirs -from subprocess import CalledProcessError, check_call, check_output -from xml.dom import minidom +import argparse +import os +import subprocess +import xml.dom.minidom import re import sys @@ -41,30 +36,57 @@ cp_targets = { MAIN: '//tools/eclipse:main_classpath_collect', } -ROOT = path.abspath(__file__) -while not path.exists(path.join(ROOT, 'WORKSPACE')): - ROOT = path.dirname(ROOT) +ROOT = os.path.abspath(__file__) +while not os.path.exists(os.path.join(ROOT, 'WORKSPACE')): + ROOT = os.path.dirname(ROOT) -opts = OptionParser() -opts.add_option('--plugins', help='create eclipse projects for plugins', - action='store_true') -opts.add_option('--name', help='name of the generated project', - action='store', default='gerrit', dest='project_name') -opts.add_option('-b', '--batch', action='store_true', - dest='batch', help='Bazel batch option') -opts.add_option('-j', '--java', action='store', - dest='java', help='Post Java 8 support (9)') -opts.add_option('-e', '--edge_java', action='store', - dest='edge_java', help='Post Java 9 support (10|11|...)') -opts.add_option('--bazel', help='name of the bazel executable', - action='store', default='bazel', dest='bazel_exe') +opts = argparse.ArgumentParser("Create Eclipse Project") +opts.add_argument('--plugins', help='create eclipse projects for plugins', + action='store_true') +opts.add_argument('--name', help='name of the generated project', + action='store', default='gerrit', dest='project_name') +opts.add_argument('-b', '--batch', action='store_true', + dest='batch', help='Bazel batch option') +opts.add_argument('-j', '--java', action='store', + dest='java', help='Post Java 8 support (9)') +opts.add_argument('-e', '--edge_java', action='store', + dest='edge_java', help='Post Java 9 support (10|11|...)') +opts.add_argument('--bazel', + 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 custom_java = args.java edge_java = args.edge_java -bazel_exe = args.bazel_exe +bazel_exe = find_bazel() + def _build_bazel_cmd(*args): build = False @@ -84,23 +106,23 @@ def _build_bazel_cmd(*args): 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): - bazel = check_output(['which', bazel_exe]).strip().decode('UTF-8') - with open(path.join(ROOT, ".bazel_path"), 'w') as fd: + bazel = subprocess.check_output(['which', bazel_exe]).strip().decode('UTF-8') + with open(os.path.join(ROOT, ".bazel_path"), 'w') as fd: fd.write("output_base=%s\n" % ext_location) 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): deps = [] t = cp_targets[target] try: - check_call(_build_bazel_cmd('build', t)) - except CalledProcessError: + subprocess.check_call(_build_bazel_cmd('build', t)) + except subprocess.CalledProcessError: exit(1) name = 'bazel-bin/tools/eclipse/' + t.split(':')[1] + '.runtime_classpath' deps = [line.rstrip('\n') for line in open(name)] @@ -108,7 +130,7 @@ def _query_classpath(target): def gen_project(name='gerrit', root=ROOT): - p = path.join(root, '.project') + p = os.path.join(root, '.project') with open(p, 'w') as fd: print("""\ @@ -127,9 +149,9 @@ def gen_project(name='gerrit', root=ROOT): def gen_plugin_classpath(root): - p = path.join(root, '.classpath') + p = os.path.join(root, '.classpath') 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 = """ @@ -149,7 +171,7 @@ def gen_plugin_classpath(root): def gen_classpath(ext): def make_classpath(): - impl = minidom.getDOMImplementation() + impl = xml.dom.minidom.getDOMImplementation() return impl.createDocument(None, 'classpath', None) def classpathentry(kind, path, src=None, out=None, exported=None): @@ -191,7 +213,7 @@ def gen_classpath(ext): if p.endswith('-src.jar'): # gwt_module() depends on -src.jar for Java to JavaScript compiles. if p.startswith("external"): - p = path.join(ext, p) + p = os.path.join(ext, p) gwt_lib.add(p) continue @@ -217,7 +239,7 @@ def gen_classpath(ext): "external/bazel_tools/tools/jdk/TestRunner_deploy.jar"): continue if p.startswith("external"): - p = path.join(ext, p) + p = os.path.join(ext, p) lib.add(p) for p in _query_classpath(GWT): @@ -239,8 +261,8 @@ def gen_classpath(ext): continue out = 'eclipse-out/' + s - p = path.join(s, 'java') - if path.exists(p): + p = os.path.join(s, 'java') + if os.path.exists(p): classpathentry('src', p, out=out) continue @@ -252,8 +274,8 @@ def gen_classpath(ext): o = 'eclipse-out/test' for srctype in ['java', 'resources']: - p = path.join(s, 'src', env, srctype) - if path.exists(p): + p = os.path.join(s, 'src', env, srctype) + if os.path.exists(p): classpathentry('src', p, out=o) for libs in [lib, gwt_lib]: @@ -263,8 +285,8 @@ def gen_classpath(ext): if m: prefix = m.group(1) suffix = m.group(2) - p = path.join(prefix, "jar", "%s-src.jar" % suffix) - if path.exists(p): + p = os.path.join(prefix, "jar", "%s-src.jar" % suffix) + if os.path.exists(p): s = p if args.plugins: classpathentry('lib', j, s, exported=True) @@ -287,20 +309,20 @@ def gen_classpath(ext): classpathentry('lib', p, s) for s in sorted(gwt_src): - p = path.join(ROOT, s, 'src', 'main', 'java') - if path.exists(p): + p = os.path.join(ROOT, s, 'src', 'main', 'java') + if os.path.exists(p): classpathentry('lib', p, out='eclipse-out/gwtsrc') classpathentry('con', JRE) classpathentry('output', 'eclipse-out/classes') - p = path.join(ROOT, '.classpath') + p = os.path.join(ROOT, '.classpath') with open(p, 'w') as fd: doc.writexml(fd, addindent='\t', newl='\n', encoding='UTF-8') if args.plugins: for plugin in plugins: - plugindir = path.join(ROOT, plugin) + plugindir = os.path.join(ROOT, plugin) try: gen_project(plugin.replace('plugins/', ""), plugindir) gen_plugin_classpath(plugindir) @@ -310,17 +332,17 @@ def gen_classpath(ext): def gen_factorypath(ext): - doc = minidom.getDOMImplementation().createDocument(None, 'factorypath', - None) + doc = xml.dom.minidom.getDOMImplementation().createDocument( + None, 'factorypath', None) for jar in _query_classpath(AUTO): e = doc.createElement('factorypathentry') 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('runInBatchMode', 'false') doc.documentElement.appendChild(e) - p = path.join(ROOT, '.factorypath') + p = os.path.join(ROOT, '.factorypath') with open(p, 'w') as fd: doc.writexml(fd, addindent='\t', newl='\n', encoding='UTF-8') @@ -334,13 +356,13 @@ try: # TODO(davido): Remove this when GWT gone gwt_working_dir = ".gwt_work_dir" - if not path.isdir(gwt_working_dir): - makedirs(path.join(ROOT, gwt_working_dir)) + if not os.path.isdir(gwt_working_dir): + os.makedirs(os.path.join(ROOT, gwt_working_dir)) try: - check_call(_build_bazel_cmd('build', MAIN, GWT, - '//java/org/eclipse/jgit:libEdit-src.jar')) - except CalledProcessError: + subprocess.check_call(_build_bazel_cmd('build', MAIN, GWT, + '//java/org/eclipse/jgit:libEdit-src.jar')) + except subprocess.CalledProcessError: exit(1) except KeyboardInterrupt: print('Interrupted by user', file=sys.stderr)