Merge branch 'stable-2.15'
* stable-2.15:
Upgrade bazlets to latest stable-2.15 to build with 2.15.5 API
bazlets: Replace native.git_repository with skylark rule
Upgrade bazlets to latest stable-2.14 to build with 2.14.15 API
Update bazlets to latest stable-2.15 and build with released 2.15.4 API
Format all build files with buildifier
Migrate (i.e. move) `tools/bazel.rc` to `.bazelrc`
Update bazlets to latest stable-2.14 to build with 2.14.14 API
Reduce cyclomatic complexity of some methods
Use logger built-in format
Format files with google-java-format 1.6
Upgrade bazlets to latest stable-2.15 revision
Change copyright to AOSP
Upgrade bazlets to latest stable-2.14 revision
Automate the SonarQube analysis with bazel
Change-Id: I3c82dd111bb33aed58ae5ee13fdbd4c56b2f5e2b
diff --git a/tools/bazel.rc b/.bazelrc
similarity index 100%
rename from tools/bazel.rc
rename to .bazelrc
diff --git a/BUILD b/BUILD
index 41af36e..a36b587 100644
--- a/BUILD
+++ b/BUILD
@@ -1,9 +1,9 @@
load("//tools/bzl:junit.bzl", "junit_tests")
load(
"//tools/bzl:plugin.bzl",
- "gerrit_plugin",
"PLUGIN_DEPS",
"PLUGIN_TEST_DEPS",
+ "gerrit_plugin",
)
gerrit_plugin(
diff --git a/WORKSPACE b/WORKSPACE
index 109865d..ee4d462 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
load("//:bazlets.bzl", "load_bazlets")
load_bazlets(
- commit = "60296e8f7162f279e3885a92014bc69252935612",
+ commit = "6d3fd710ea4ca44805bb8c858d72b53bd3a500f3",
# local_path = "/home/<user>/projects/bazlets",
)
diff --git a/bazlets.bzl b/bazlets.bzl
index e14e488..f089af4 100644
--- a/bazlets.bzl
+++ b/bazlets.bzl
@@ -1,17 +1,18 @@
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
+
NAME = "com_googlesource_gerrit_bazlets"
def load_bazlets(
- commit,
- local_path = None
- ):
- if not local_path:
- native.git_repository(
- name = NAME,
- remote = "https://gerrit.googlesource.com/bazlets",
- commit = commit,
- )
- else:
- native.local_repository(
- name = NAME,
- path = local_path,
- )
+ commit,
+ local_path = None):
+ if not local_path:
+ git_repository(
+ name = NAME,
+ remote = "https://gerrit.googlesource.com/bazlets",
+ commit = commit,
+ )
+ else:
+ native.local_repository(
+ name = NAME,
+ path = local_path,
+ )
diff --git a/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRights.java b/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRights.java
index c91c1e2..4df4f25 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRights.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRights.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2018 Ericsson
+// Copyright (C) 2018 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.
@@ -34,6 +34,7 @@
import com.google.inject.Singleton;
import java.io.IOException;
import java.nio.file.Path;
+import java.util.Arrays;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
@@ -114,29 +115,34 @@
for (String refName : defaultAccessRightsConfig.getSubsections(ProjectConfig.ACCESS)) {
if (RefConfigSection.isValid(refName) && isValidRegex(refName)) {
AccessSection as = config.getAccessSection(refName, true);
- for (String varName :
- defaultAccessRightsConfig.getStringList(
- ProjectConfig.ACCESS, refName, "exclusiveGroupPermissions")) {
- for (String n : varName.split("[, \t]{1,}")) {
- if (Permission.isPermission(n)) {
- as.getPermission(n, true).setExclusiveGroup(true);
- }
- }
- }
- String ownerGroupName = getOwerGroupName(project);
- for (String value : defaultAccessRightsConfig.getNames(ProjectConfig.ACCESS, refName)) {
- if (Permission.isPermission(value)) {
- Permission perm = as.getPermission(value, true);
- setPermissionRules(ownerGroupName, perm, refName, value);
- } else {
- log.error("Invalid permission {}", value);
- }
- }
+ getPermissions(refName, as);
+ setPermissions(refName, as, getOwnerGroupName(project));
}
}
}
- private String getOwerGroupName(ProjectState project) {
+ private void getPermissions(String refName, AccessSection as) {
+ for (String varName :
+ defaultAccessRightsConfig.getStringList(
+ ProjectConfig.ACCESS, refName, "exclusiveGroupPermissions")) {
+ Arrays.stream(varName.split("[, \t]{1,}"))
+ .filter(Permission::isPermission)
+ .forEach(n -> as.getPermission(n, true).setExclusiveGroup(true));
+ }
+ }
+
+ private void setPermissions(String refName, AccessSection as, String ownerGroupName) {
+ for (String value : defaultAccessRightsConfig.getNames(ProjectConfig.ACCESS, refName)) {
+ if (Permission.isPermission(value)) {
+ Permission perm = as.getPermission(value, true);
+ setPermissionRules(ownerGroupName, perm, refName, value);
+ } else {
+ log.error("Invalid permission {}", value);
+ }
+ }
+ }
+
+ private String getOwnerGroupName(ProjectState project) {
Set<AccountGroup.UUID> owners = project.getAllOwners();
if (!owners.isEmpty()) {
Optional<InternalGroup> owner = groupCache.get(owners.iterator().next());
@@ -151,7 +157,7 @@
try {
RefPattern.validateRegExp(refPattern);
} catch (InvalidNameException e) {
- log.error("Invalid ref name: " + e.getMessage());
+ log.error("Invalid ref name: {}", e.getMessage());
return false;
}
return true;
diff --git a/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidator.java b/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidator.java
index 3a6f2fa..a3fbef5 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidator.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidator.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2016 Ericsson
+// 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.
@@ -171,10 +171,9 @@
.getBoolean(DISABLE_GRANTING_PROJECT_OWNERSHIP, false);
} catch (NoSuchProjectException e) {
log.error(
- "Failed to check project config for "
- + parentCtrl.getProject().getName()
- + ": "
- + e.getMessage(),
+ "Failed to check project config for {}: {}",
+ parentCtrl.getProject().getName(),
+ e.getMessage(),
e);
throw new ValidationException(AN_ERROR_OCCURRED_MSG);
}
@@ -205,7 +204,7 @@
}
return AccountGroup.UUID.parse(groupInfo.id);
} catch (RestApiException | OrmException | IOException | ConfigInvalidException e) {
- log.error("Failed to create project " + name + ": " + e.getMessage(), e);
+ log.error("Failed to create project {}: {}", name, e.getMessage(), e);
throw new ValidationException(AN_ERROR_OCCURRED_MSG);
}
}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRightsIT.java b/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRightsIT.java
index 3c413a3..a0f9140 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRightsIT.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRightsIT.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2018 Ericsson
+// Copyright (C) 2018 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.
@@ -33,9 +33,8 @@
import org.junit.Test;
@TestPlugin(
- name = "project-group-structure",
- sysModule = "com.ericsson.gerrit.plugins.projectgroupstructure.Module"
-)
+ name = "project-group-structure",
+ sysModule = "com.ericsson.gerrit.plugins.projectgroupstructure.Module")
public class DefaultAccessRightsIT extends LightweightPluginDaemonTest {
@Override
diff --git a/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidatorIT.java b/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidatorIT.java
index 466af09..8006b23 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidatorIT.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidatorIT.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2016 Ericsson
+// 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.
@@ -36,9 +36,8 @@
import org.junit.Test;
@TestPlugin(
- name = "project-group-structure",
- sysModule = "com.ericsson.gerrit.plugins.projectgroupstructure.Module"
-)
+ name = "project-group-structure",
+ sysModule = "com.ericsson.gerrit.plugins.projectgroupstructure.Module")
public class ProjectCreationValidatorIT extends LightweightPluginDaemonTest {
private static final String PLUGIN_NAME = "project-group-structure";
diff --git a/tools/bzl/plugin.bzl b/tools/bzl/plugin.bzl
index a2e438f..0b25d23 100644
--- a/tools/bzl/plugin.bzl
+++ b/tools/bzl/plugin.bzl
@@ -1,6 +1,6 @@
load(
"@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl",
- "gerrit_plugin",
"PLUGIN_DEPS",
"PLUGIN_TEST_DEPS",
+ "gerrit_plugin",
)
diff --git a/tools/sonar/sonar.sh b/tools/sonar/sonar.sh
new file mode 100755
index 0000000..39df185
--- /dev/null
+++ b/tools/sonar/sonar.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+# Copyright (C) 2018 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/sonar:sonar --output location | sed s/BUILD:.*//`sonar.py