Unverified Commit 7575794c authored by Johan's avatar Johan
Browse files

Replace wouterd plugin with a more actively maintained plugin.

parent 668a3ada
......@@ -95,9 +95,8 @@
<version>2.19.1</version>
<configuration>
<systemProperties>
<sonarqube.host>http://${docker.containers.sonarqube.ports.9000/tcp.host}:${docker.containers.sonarqube.ports.9000/tcp.port}
</sonarqube.host>
<gitlab.host>http://${docker.containers.gitlab.ports.80/tcp.host}:${docker.containers.gitlab.ports.80/tcp.port}</gitlab.host>
<sonarqube.host>http://${sonar-plugin.host}:${sonar-plugin.port}</sonarqube.host>
<gitlab.host>http://${gitlab.host}:${gitlab.port}</gitlab.host>
<os.shell>${os.shell}</os.shell>
<os.command>${os.command}</os.command>
</systemProperties>
......@@ -114,64 +113,69 @@
<!-- Plugin to run Docker Container based ITs -->
<plugin>
<groupId>net.wouterdanes.docker</groupId>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>5.0.0</version>
<version>0.18.1</version>
<configuration>
<showLogs>true</showLogs>
<startParallel>true</startParallel>
<images>
<image>
<name>sonar-gitlab-plugin</name>
<alias>sonar-plugin</alias>
<build>
<dockerFileDir>${project.basedir}/src/test/resources/docker</dockerFileDir>
<!-- Add the build artifact to the build context. -->
<assembly>
<descriptorRef>artifact</descriptorRef>
</assembly>
</build>
<run>
<ports>
<port>+sonar-plugin.host:sonar-plugin.port:9000</port>
</ports>
<wait>
<log>Process\[web\] is up</log>
<time>30000</time>
</wait>
</run>
</image>
<image>
<name>gitlab/gitlab-ce</name>
<alias>gitlab</alias>
<run>
<ports>
<port>+gitlab.host:gitlab.port:80</port>
</ports>
<wait>
<log>master process ready</log>
<time>180000</time>
</wait>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>package</id>
<id>build-container</id>
<phase>package</phase>
<goals>
<goal>build-images</goal>
<goal>build</goal>
</goals>
<configuration>
<images>
<image>
<id>gitlab-plugin</id>
<dockerFile>${project.basedir}/src/test/resources/docker/Dockerfile</dockerFile>
<artifacts>
<artifact>
<file>${project.build.directory}/${project.build.finalName}.jar</file>
<dest>sonar-gitlab-plugin.jar</dest>
</artifact>
</artifacts>
</image>
</images>
</configuration>
</execution>
<execution>
<id>start</id>
<id>start-containers</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start-containers</goal>
<goal>start</goal>
</goals>
<configuration>
<!-- You can set forceCleanup to true to stop and remove started containers
at the end of the build even if the stop-containers goal is not executed
(useful for preventing Ctrl+C causing dangling containers) -->
<forceCleanup>false</forceCleanup>
<containers>
<container>
<id>sonarqube</id>
<image>gitlab-plugin</image>
<waitForStartup>Process\[web\] is up</waitForStartup>
</container>
<container>
<id>gitlab</id>
<image>gitlab/gitlab-ce</image>
<waitForStartup>master process ready</waitForStartup>
</container>
</containers>
</configuration>
</execution>
<execution>
<id>stop</id>
<id>cleanup-containers</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-containers</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
<goal>stop</goal>
<goal>remove</goal>
</goals>
</execution>
</executions>
......
package org.johnnei.sgp.it;
import java.io.File;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Created by Johnnei on 2016-12-20.
*/
public class CommandLine {
private static final Logger LOGGER = LoggerFactory.getLogger(CommandLine.class);
private final String shell;
private final String commandArgument;
private final File workingDirectory;
public CommandLine(String shell, String commandArgument, File workingDirectory) {
this.shell = shell;
this.commandArgument = commandArgument;
this.workingDirectory = workingDirectory;
}
public Process start(String command) throws IOException {
LOGGER.debug("Running: " + shell + " " + commandArgument + " " + command);
return new ProcessBuilder()
.directory(workingDirectory)
.command(shell, commandArgument, command)
.inheritIO()
.start();
}
public void startAndAwait(String command) throws IOException {
Process process = start(command);
try {
int returnCode = process.waitFor();
if (returnCode != 0) {
throw new RuntimeException("Process failed: " + returnCode);
}
} catch (InterruptedException e) {
process.destroy();
}
}
}
......@@ -2,6 +2,10 @@ package org.johnnei.sgp.it;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
......@@ -20,6 +24,8 @@ import org.gitlab.api.models.GitlabSession;
import org.hamcrest.collection.IsEmptyCollection;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -46,15 +52,21 @@ public abstract class IntegrationTest {
private static final String OS_SHELL = getProperty("os.shell", "/bin/bash");
private static final String OS_COMMAND = getProperty("os.command", "-c");
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
protected GitlabAPI gitlabApi;
protected GitlabProject project;
private CommandLine commandLine;
private String gitLabAuthToken;
private static String getProperty(String key, String defaultValue) {
String value = System.getProperty(key);
if (value == null || value.trim().isEmpty() || value.contains("$")) {
LOGGER.debug("Resolve failed: \"{}\" -> \"{}\"", key, value);
value = defaultValue;
}
......@@ -65,8 +77,29 @@ public abstract class IntegrationTest {
public void setUp() throws Exception {
LOGGER.debug("GitLab Host: {}", GITLAB_HOST);
LOGGER.debug("SonarQube Host: {}", SONARQUBE_HOST);
File repo = temporaryFolder.newFolder("repo");
prepareGitRepo(repo);
commandLine = new CommandLine(OS_SHELL, OS_COMMAND, repo);
ensureAdminCreated();
createProject();
initializeProject();
}
private void prepareGitRepo(File repo) throws IOException {
LOGGER.info("Preparing GIT repository in {}", repo.toPath().toString());
Path sourceFolder = new File("it-sources").toPath();
Files.walk(sourceFolder)
.forEach(file -> {
String destination = file.toString().replace(sourceFolder.toString(), repo.toPath().toString());
try {
Files.copy(file, Paths.get(destination), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new IllegalStateException("Failed to prepare git repository", e);
}
});
}
@After
......@@ -76,21 +109,14 @@ public abstract class IntegrationTest {
protected void checkout(String ref) throws IOException {
LOGGER.info("Checking out {}");
Process process = new ProcessBuilder()
.directory(new File("it-sources"))
.command("git", "checkout", ref)
.start();
try {
process.waitFor();
} catch (InterruptedException e) {
process.destroy();
}
commandLine.startAndAwait("git checkout " + ref);
}
protected void sonarAnalysis(String commitHash) throws IOException {
LOGGER.info("Starting SonarQube Analysis.");
String argument = "mvn" +
String argument = "mvn -B" +
" clean" +
" compile " +
" sonar:sonar" +
......@@ -100,26 +126,7 @@ public abstract class IntegrationTest {
" -Dsonar.gitlab.auth.token=" + gitLabAuthToken +
" -Dsonar.gitlab.analyse.project=root/sgp-it" +
" -Dsonar.gitlab.analyse.commit=" + commitHash;
LOGGER.debug("Running: " + OS_SHELL + " " + OS_COMMAND + " " + argument);
Process process = new ProcessBuilder()
.directory(new File("it-sources"))
.command(
OS_SHELL,
OS_COMMAND,
argument
)
.inheritIO()
.start();
try {
int returnCode = process.waitFor();
if (returnCode != 0) {
throw new RuntimeException("Process failed: " + returnCode);
}
} catch (InterruptedException e) {
process.destroy();
}
commandLine.startAndAwait(argument);
}
private void ensureAdminCreated() throws Exception {
......@@ -219,6 +226,10 @@ public abstract class IntegrationTest {
assertNotNull("Failed to create project in GitLab", project);
}
private void initializeProject() throws IOException {
}
private void deleteProject() throws IOException {
LOGGER.debug("Removing project from GitLab.");
if (project != null) {
......
FROM sonarqube:lts
MAINTAINER Johnnei
COPY sonar-gitlab-plugin.jar /opt/sonarqube/extensions/plugins/sonar-gitlab-plugin.jar
COPY maven/sonar-gitlab-plugin*.jar /opt/sonarqube/extensions/plugins/sonar-gitlab-plugin.jar
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment