aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2018-11-29 17:07:21 +0100
committersonartech <sonartech@sonarsource.com>2019-01-16 09:43:04 +0100
commita00e567bffae6300381d11989bfda011d2f85aba (patch)
treec35be0ea15bdde4b352c6eb452e3ffe4bfd2083a /sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob
parentb7d07953ea890469dca6f917399dba7edfd5f4ed (diff)
downloadsonarqube-a00e567bffae6300381d11989bfda011d2f85aba.tar.gz
sonarqube-a00e567bffae6300381d11989bfda011d2f85aba.zip
SONAR-11465 Move post-job at project level
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/PostJobWrapper.java3
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/PostJobsExecutor.java58
2 files changed, 61 insertions, 0 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/PostJobWrapper.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/PostJobWrapper.java
index 4b8e7b3772f..408ad6385c0 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/PostJobWrapper.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/PostJobWrapper.java
@@ -35,6 +35,9 @@ public class PostJobWrapper {
this.optimizer = optimizer;
this.descriptor = new DefaultPostJobDescriptor();
newPostJob.describe(descriptor);
+ if (descriptor.name() == null) {
+ descriptor.name(newPostJob.getClass().getName());
+ }
this.adaptor = adaptor;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/PostJobsExecutor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/PostJobsExecutor.java
new file mode 100644
index 00000000000..0b5a7608c75
--- /dev/null
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/PostJobsExecutor.java
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.postjob;
+
+import java.util.Collection;
+import java.util.stream.Collectors;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.bootstrap.PostJobExtensionDictionnary;
+
+public class PostJobsExecutor {
+ private static final Logger LOG = Loggers.get(PostJobsExecutor.class);
+
+ private final PostJobExtensionDictionnary selector;
+
+ public PostJobsExecutor(PostJobExtensionDictionnary selector) {
+ this.selector = selector;
+ }
+
+ public void execute() {
+ Collection<PostJobWrapper> postJobs = selector.selectPostJobs();
+ execute(postJobs);
+ }
+
+ private static void execute(Collection<PostJobWrapper> postJobs) {
+ logPostJobs(postJobs);
+
+ for (PostJobWrapper postJob : postJobs) {
+ if (postJob.shouldExecute()) {
+ LOG.info("Executing post-job '{}'", postJob);
+ postJob.execute();
+ }
+ }
+ }
+
+ private static void logPostJobs(Collection<PostJobWrapper> postJobs) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(() -> "Post-jobs : " + postJobs.stream().map(Object::toString).collect(Collectors.joining(" -> ")));
+ }
+ }
+}