diff options
author | Eric Hartmann <hartmann.eric@gmail.com> | 2017-08-30 17:27:05 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-09-05 14:24:13 +0200 |
commit | 0f551cb0f2bbbdc9319b49fe495288eed8432fab (patch) | |
tree | 2643d483c6ff3ebe53c8b5ea05b3feb6a347fc85 /tests/plugins | |
parent | a228919e41902d87b3d4d73892ed8e849375fb85 (diff) | |
download | sonarqube-0f551cb0f2bbbdc9319b49fe495288eed8432fab.tar.gz sonarqube-0f551cb0f2bbbdc9319b49fe495288eed8432fab.zip |
SONAR-9715 Implement a delay for finishing task in Compute Engine
Diffstat (limited to 'tests/plugins')
3 files changed, 101 insertions, 1 deletions
diff --git a/tests/plugins/server-plugin/src/main/java/ServerPlugin.java b/tests/plugins/server-plugin/src/main/java/ServerPlugin.java index 07aa1f861a2..9ab0dd987de 100644 --- a/tests/plugins/server-plugin/src/main/java/ServerPlugin.java +++ b/tests/plugins/server-plugin/src/main/java/ServerPlugin.java @@ -38,6 +38,8 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +import ce.CePauseStep; +import ce.PauseMetric; import java.util.Arrays; import java.util.List; import org.sonar.api.Properties; @@ -86,6 +88,6 @@ import static org.sonar.api.PropertyType.USER_LOGIN; public class ServerPlugin extends SonarPlugin { public List getExtensions() { return Arrays.asList( - StartupCrash.class, TempFolderExtension.class); + StartupCrash.class, TempFolderExtension.class, PauseMetric.class, CePauseStep.class); } } diff --git a/tests/plugins/server-plugin/src/main/java/ce/CePauseStep.java b/tests/plugins/server-plugin/src/main/java/ce/CePauseStep.java new file mode 100644 index 00000000000..8214ac56d31 --- /dev/null +++ b/tests/plugins/server-plugin/src/main/java/ce/CePauseStep.java @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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 ce; + +import java.io.File; +import org.sonar.api.ce.measure.Component; +import org.sonar.api.ce.measure.MeasureComputer; +import org.sonar.api.utils.log.Logger; +import org.sonar.api.utils.log.Loggers; + +public class CePauseStep implements MeasureComputer { + + private static final Logger LOGGER = Loggers.get(CePauseStep.class); + + @Override + public MeasureComputerDefinition define(MeasureComputerDefinitionContext defContext) { + return defContext.newDefinitionBuilder() + .setInputMetrics("ncloc") + .setOutputMetrics(PauseMetric.KEY) + .build(); + } + + @Override + public void compute(MeasureComputerContext context) { + if (context.getComponent().getType() == Component.Type.PROJECT) { + String path = context.getSettings().getString("sonar.ce.pauseTask.path"); + if (path != null) { + waitForFileToBeDeleted(path); + } + } + } + + private static void waitForFileToBeDeleted(String path) { + LOGGER.info("CE analysis is paused. Waiting for file to be deleted: " + path); + File file = new File(path); + try { + while (file.exists()) { + Thread.sleep(500L); + } + LOGGER.info("CE analysis is resumed"); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new IllegalStateException("CE analysis has been interrupted"); + } + } +} diff --git a/tests/plugins/server-plugin/src/main/java/ce/PauseMetric.java b/tests/plugins/server-plugin/src/main/java/ce/PauseMetric.java new file mode 100644 index 00000000000..a16f821e4e4 --- /dev/null +++ b/tests/plugins/server-plugin/src/main/java/ce/PauseMetric.java @@ -0,0 +1,35 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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 ce; + +import java.util.Arrays; +import java.util.List; +import org.sonar.api.measures.Metric; +import org.sonar.api.measures.Metrics; + +public class PauseMetric implements Metrics { + + public static final String KEY = "pause"; + + @Override + public List<Metric> getMetrics() { + return Arrays.asList(new Metric.Builder(KEY, "Pause", Metric.ValueType.INT).create()); + } +} |