diff --git a/.gitignore b/.gitignore index 2951927..445b95a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,11 @@ /.classpath /.project -/.settings/org.maven.ide.eclipse.prefs -/.settings/org.eclipse.m2e.core.prefs +/.settings /bazel-bin /bazel-genfiles /bazel-gerrit-oauth-provider /bazel-out /bazel-testlogs +/eclipse-out /.idea *.swp diff --git a/.settings/org.eclipse.core.runtime.prefs b/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 0000000..8667cfd --- /dev/null +++ b/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,3 @@ +#Tue Sep 02 16:59:24 PDT 2008 +eclipse.preferences.version=1 +line.separator=\n diff --git a/BUILD b/BUILD index f9d021e..0944655 100644 --- a/BUILD +++ b/BUILD @@ -2,6 +2,7 @@ load("//tools/bzl:junit.bzl", "junit_tests") load( "//tools/bzl:plugin.bzl", "PLUGIN_DEPS", + "PLUGIN_TEST_DEPS", "gerrit_plugin", ) @@ -26,7 +27,16 @@ junit_tests( name = "gerrit-oauth-provider_tests", srcs = glob(["src/test/java/**/*.java"]), tags = ["oauth"], - deps = PLUGIN_DEPS + [ + deps = [ + ":gerrit-oauth-provider__plugin_test_deps", + ], +) + +java_library( + name = "gerrit-oauth-provider__plugin_test_deps", + testonly = 1, + visibility = ["//visibility:public"], + exports = PLUGIN_DEPS + PLUGIN_TEST_DEPS + [ ":gerrit-oauth-provider__plugin", "@scribe//jar", ], diff --git a/README.md b/README.md index b0a228b..414eef6 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ following: Install ------- -Copy the `bazel-genfiles/gerrit-oauth-provider.jar` to +Copy the `bazel-genfiles/oauth.jar` to `$gerrit_site/plugins` and re-run init to configure it: ``` diff --git a/WORKSPACE b/WORKSPACE index 189e820..2f9c20d 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,8 +3,8 @@ workspace(name = "com_github_davido_gerrit_oauth_provider") load("//:bazlets.bzl", "load_bazlets") load_bazlets( - commit = "5e0b58a466804eca41dd99df75bdf8575de0d167", - # local_path = "/home//projects/bazlets", + commit = "d025e909c2e8a369712165309f599a2765005f2d", + #local_path = "/home//projects/bazlets", ) # Snapshot Plugin API diff --git a/bazlets.bzl b/bazlets.bzl index de1b5d2..f089af4 100644 --- a/bazlets.bzl +++ b/bazlets.bzl @@ -1,10 +1,12 @@ +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + NAME = "com_googlesource_gerrit_bazlets" def load_bazlets( - commit = None, + commit, local_path = None): if not local_path: - native.git_repository( + git_repository( name = NAME, remote = "https://gerrit.googlesource.com/bazlets", commit = commit, diff --git a/src/main/java/com/googlesource/gerrit/plugins/oauth/BitbucketOAuthService.java b/src/main/java/com/googlesource/gerrit/plugins/oauth/BitbucketOAuthService.java index e600067..55680f2 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/oauth/BitbucketOAuthService.java +++ b/src/main/java/com/googlesource/gerrit/plugins/oauth/BitbucketOAuthService.java @@ -110,7 +110,7 @@ public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException { public OAuthToken getAccessToken(OAuthVerifier rv) { Verifier vi = new Verifier(rv.getValue()); Token to = service.getAccessToken(null, vi); - return new OAuthToken(to.getToken(), to.getSecret(), null); + return new OAuthToken(to.getToken(), to.getSecret(), to.getRawResponse()); } @Override diff --git a/src/main/java/com/googlesource/gerrit/plugins/oauth/GitLabOAuthService.java b/src/main/java/com/googlesource/gerrit/plugins/oauth/GitLabOAuthService.java index 2d6870a..792342e 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/oauth/GitLabOAuthService.java +++ b/src/main/java/com/googlesource/gerrit/plugins/oauth/GitLabOAuthService.java @@ -106,7 +106,7 @@ public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException { public OAuthToken getAccessToken(OAuthVerifier rv) { Verifier vi = new Verifier(rv.getValue()); Token to = service.getAccessToken(null, vi); - return new OAuthToken(to.getToken(), to.getSecret(), null); + return new OAuthToken(to.getToken(), to.getSecret(), to.getRawResponse()); } @Override diff --git a/tools/bzl/plugin.bzl b/tools/bzl/plugin.bzl index c157125..0b25d23 100644 --- a/tools/bzl/plugin.bzl +++ b/tools/bzl/plugin.bzl @@ -1,5 +1,6 @@ load( "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl", "PLUGIN_DEPS", + "PLUGIN_TEST_DEPS", "gerrit_plugin", ) diff --git a/tools/eclipse/BUILD b/tools/eclipse/BUILD index 9adce20..252c327 100644 --- a/tools/eclipse/BUILD +++ b/tools/eclipse/BUILD @@ -1,14 +1,9 @@ -load("//tools/bzl:plugin.bzl", "PLUGIN_DEPS", "gerrit_plugin") load("//tools/bzl:classpath.bzl", "classpath_collector") -java_library( - name = "classpath", - runtime_deps = PLUGIN_DEPS + [ - "//:gerrit-oauth-provider__plugin", - ], -) - classpath_collector( name = "main_classpath_collect", - deps = PLUGIN_DEPS + ["//:gerrit-oauth-provider__plugin"], + testonly = 1, + deps = [ + "//:gerrit-oauth-provider__plugin_test_deps", + ], ) diff --git a/tools/eclipse/project.py b/tools/eclipse/project.py deleted file mode 100755 index a98c35a..0000000 --- a/tools/eclipse/project.py +++ /dev/null @@ -1,179 +0,0 @@ -#!/usr/bin/env python -# 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. -# - -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 re -import sys - -MAIN = '//tools/eclipse:classpath' -JRE = '/'.join([ - 'org.eclipse.jdt.launching.JRE_CONTAINER', - 'org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType', - 'JavaSE-1.8', -]) -# Map of targets to corresponding classpath collector rules -cp_targets = { - MAIN: '//tools/eclipse:main_classpath_collect', -} - -ROOT = path.abspath(__file__) -while not path.exists(path.join(ROOT, 'WORKSPACE')): - ROOT = path.dirname(ROOT) - -opts = OptionParser() -opts.add_option('--name', help='name of the generated project', - action='store', default='gerrit-oauth-provider', dest='project_name') -args, _ = opts.parse_args() - -def retrieve_ext_location(): - return check_output(['bazel', 'info', 'output_base']).strip() - -def gen_primary_build_tool(): - bazel = check_output(['which', 'bazel']).strip() - with open(path.join(ROOT, ".primary_build_tool"), 'w') as fd: - fd.write("bazel=%s\n" % bazel) - fd.write("PATH=%s\n" % environ["PATH"]) - -def _query_classpath(target): - deps = [] - t = cp_targets[target] - try: - check_call(['bazel', 'build', t]) - except CalledProcessError: - exit(1) - name = 'bazel-bin/tools/eclipse/' + t.split(':')[1] + '.runtime_classpath' - deps = [line.rstrip('\n') for line in open(name)] - return deps - -def gen_project(name='gerrit', root=ROOT): - p = path.join(root, '.project') - with open(p, 'w') as fd: - print("""\ - - - %(name)s - - - org.eclipse.jdt.core.javabuilder - - - - org.eclipse.jdt.core.javanature - -\ - """ % {"name": name}, file=fd) - -def gen_classpath(ext): - def make_classpath(): - impl = minidom.getDOMImplementation() - return impl.createDocument(None, 'classpath', None) - - def classpathentry(kind, path, src=None, out=None, exported=None): - e = doc.createElement('classpathentry') - e.setAttribute('kind', kind) - # TODO(davido): Remove this and other exclude BUILD files hack - # when this Bazel bug is fixed: - # https://github.com/bazelbuild/bazel/issues/1083 - if kind == 'src': - e.setAttribute('excluding', '**/BUILD') - e.setAttribute('path', path) - if src: - e.setAttribute('sourcepath', src) - if out: - e.setAttribute('output', out) - if exported: - e.setAttribute('exported', 'true') - doc.documentElement.appendChild(e) - - doc = make_classpath() - src = set() - lib = set() - - # Classpath entries are absolute for cross-cell support - java_library = re.compile('bazel-out/local-fastbuild/bin/lib[^/]+[.]jar$') - srcs = re.compile('(.*/external/[^/]+)/jar/(.*)[.]jar') - for p in _query_classpath(MAIN): - m = java_library.match(p) - if m: - src.add(".") - else: - if p.startswith("external"): - p = path.join(ext, p) - lib.add(p) - - for s in sorted(src): - out = None - - if s.startswith('lib/'): - out = 'eclipse-out/lib' - - p = path.join(s, 'java') - if path.exists(p): - classpathentry('src', p, out=out) - continue - - for env in ['main', 'test']: - o = None - if out: - o = out + '/' + env - elif env == 'test': - o = 'eclipse-out/test' - - for srctype in ['java', 'resources']: - p = path.join(s, 'src', env, srctype) - if path.exists(p): - classpathentry('src', p, out=o) - - for libs in [lib]: - for j in sorted(libs): - s = None - m = srcs.match(j) - if m: - prefix = m.group(1) - suffix = m.group(2) - p = path.join(prefix, "src", "%s-src.jar" % suffix) - if path.exists(p): - s = p - classpathentry('lib', j, s) - - classpathentry('con', JRE) - classpathentry('output', 'eclipse-out/classes') - - p = path.join(ROOT, '.classpath') - with open(p, 'w') as fd: - doc.writexml(fd, addindent='\t', newl='\n', encoding='UTF-8') - -try: - ext_location = retrieve_ext_location() - gen_project(args.project_name) - gen_classpath(ext_location) - gen_primary_build_tool() - - try: - check_call(['bazel', 'build', MAIN]) - except CalledProcessError: - exit(1) -except KeyboardInterrupt: - print('Interrupted by user', file=sys.stderr) - exit(1) diff --git a/tools/eclipse/project.sh b/tools/eclipse/project.sh new file mode 100755 index 0000000..8e4ed79 --- /dev/null +++ b/tools/eclipse/project.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# Copyright (C) 2017 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. +`bazel query @com_googlesource_gerrit_bazlets//tools/eclipse:project --output location | sed s/BUILD:.*//`project.py -n oauth -r .