Skip to content

Commit

Permalink
Merge branch 'master' into feature/JENKINS-48711
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-nenashev committed Jan 13, 2018
2 parents 7283ea4 + 3693244 commit f531b97
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 17 deletions.
56 changes: 56 additions & 0 deletions Jenkinsfile
@@ -0,0 +1,56 @@
/* Only keep the 10 most recent builds. */
properties([[$class: 'BuildDiscarderProperty',
strategy: [$class: 'LogRotator', numToKeepStr: '10']]])

// TODO: Move it to Jenkins Pipeline Library

/* These platforms correspond to labels in ci.jenkins.io, see:
* https://github.com/jenkins-infra/documentation/blob/master/ci.adoc
*/
List platforms = ['linux', 'windows']
Map branches = [:]

for (int i = 0; i < platforms.size(); ++i) {
String label = platforms[i]
branches[label] = {
node(label) {
timestamps {
stage('Checkout') {
checkout scm
}

stage('Build') {
withEnv([
"JAVA_HOME=${tool 'jdk8'}",
"PATH+MVN=${tool 'mvn'}/bin",
'PATH+JDK=$JAVA_HOME/bin',
]) {
timeout(30) {
String command = 'mvn --batch-mode clean install -Dmaven.test.failure.ignore=true'
if (isUnix()) {
sh command
}
else {
bat command
}
}
}
}

stage('Archive') {
/* Archive the test results */
junit '**/target/surefire-reports/TEST-*.xml'

if (label == 'linux') {
archiveArtifacts artifacts: 'target/**/*.jar'
// FindBugs is not enabled for this repo so far
// findbugs pattern: '**/target/findbugsXml.xml'
}
}
}
}
}
}

/* Execute our platforms in parallel */
parallel(branches)
Expand Up @@ -104,7 +104,7 @@ public class CliOptions {
@Parameter(names="-hookPrefixes", description = "Prefixes of the extra hooks' classes")
private String hookPrefixes;

@Parameter(names="-localCheckoutDir", description = "Folder containing a local (possibly modified) clone of a plugin repository")
@Parameter(names="-localCheckoutDir", description = "Folder containing either a local (possibly modified) clone of a plugin repository or a set of local clone of different plugins")
private String localCheckoutDir;

@Parameter(names="-help", description = "Print this help message")
Expand Down
Expand Up @@ -37,6 +37,7 @@
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmTag;
import org.apache.maven.scm.command.checkout.CheckOutScmResult;
Expand Down Expand Up @@ -248,8 +249,20 @@ public PluginCompatReport testPlugins()
MavenCoordinates actualCoreCoordinates = coreCoordinates;
PluginRemoting remote;
if (localCheckoutProvided() && onlyOnePluginIncluded()) {
// Only one plugin and checkout directory provided
remote = new PluginRemoting(new File(config.getLocalCheckoutDir(), "pom.xml"));
} else if(localCheckoutProvided()) {
// local directory provided for more than one plugin, so each plugin is allocated in localCheckoutDir/plugin-name
// If there is no subdirectory for the plugin, it will be cloned from scm
File pomFile = new File(new File(config.getLocalCheckoutDir(), plugin.name), "pom.xml");
if (pomFile.exists()) {
remote = new PluginRemoting(pomFile);
} else {
remote = new PluginRemoting(plugin.url);
}
} else {
// Only one plugin but checkout directory not provided or
// more than a plugin and no local checkout directory provided
remote = new PluginRemoting(plugin.url);
}
PomData pomData;
Expand Down Expand Up @@ -365,7 +378,7 @@ private static ClassPathResource getXslTransformerResource(){

private static File createBuildLogFile(File reportFile, String pluginName, String pluginVersion, MavenCoordinates coreCoords){
return new File(reportFile.getParentFile().getAbsolutePath()
+"/"+createBuildLogFilePathFor(pluginName, pluginVersion, coreCoords));
+ File.separator + createBuildLogFilePathFor(pluginName, pluginVersion, coreCoords));
}

private static String createBuildLogFilePathFor(String pluginName, String pluginVersion, MavenCoordinates coreCoords){
Expand All @@ -383,7 +396,7 @@ private TestExecutionResult testPluginAgainst(MavenCoordinates coreCoordinates,
System.out.println(String.format("#############################################"));
System.out.println(String.format("%n%n%n%n%n"));

File pluginCheckoutDir = new File(config.workDirectory.getAbsolutePath()+"/"+plugin.name+"/");
File pluginCheckoutDir = new File(config.workDirectory.getAbsolutePath() + File.separator + plugin.name + File.separator);

try {
// Run any precheckout hooks
Expand All @@ -405,27 +418,30 @@ private TestExecutionResult testPluginAgainst(MavenCoordinates coreCoordinates,
System.out.println("Deleting working directory "+pluginCheckoutDir.getAbsolutePath());
FileUtils.deleteDirectory(pluginCheckoutDir);
}

pluginCheckoutDir.mkdir();
System.out.println("Created plugin checkout dir : "+pluginCheckoutDir.getAbsolutePath());

if (localCheckoutProvided()) {
if (!onlyOnePluginIncluded()) {
throw new RuntimeException("You specified a local clone but did not choose only one plugin to execute PCT against it");
File localCheckoutPluginDir = new File(config.getLocalCheckoutDir(), plugin.name);
File pomLocalCheckoutPluginDir = new File(localCheckoutPluginDir, "pom.xml");
if(pomLocalCheckoutPluginDir.exists()) {
System.out.println("Copy plugin directory from : " + localCheckoutPluginDir.getAbsolutePath());
FileUtils.copyDirectoryStructure(localCheckoutPluginDir, pluginCheckoutDir);
} else {
cloneFromSCM(pomData.getConnectionUrl(), plugin.name, plugin.version, pluginCheckoutDir);
}
} else {
// TODO this fails when it encounters symlinks (e.g. work/jobs/…/builds/lastUnstableBuild),
// and even up-to-date versions of org.apache.commons.io.FileUtils seem to not handle links,
// so may need to use something like http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/essential/io/examples/Copy.java
System.out.println("Copy plugin directory from : " + config.getLocalCheckoutDir().getAbsolutePath());
FileUtils.copyDirectoryStructure(config.getLocalCheckoutDir(), pluginCheckoutDir);
}
// TODO this fails when it encounters symlinks (e.g. work/jobs/…/builds/lastUnstableBuild),
// and even up-to-date versions of org.apache.commons.io.FileUtils seem to not handle links,
// so may need to use something like http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/essential/io/examples/Copy.java
FileUtils.copyDirectoryStructure(config.getLocalCheckoutDir(), pluginCheckoutDir);
} else {
// These hooks could redirect the SCM, skip checkout (if multiple plugins use the same preloaded repo)
System.out.println("Checking out from SCM connection URL : " + pomData.getConnectionUrl() + " (" + plugin.name + "-" + plugin.version + ")");
ScmManager scmManager = SCMManagerFactory.getInstance().createScmManager();
ScmRepository repository = scmManager.makeScmRepository(pomData.getConnectionUrl());
CheckOutScmResult result = scmManager.checkOut(repository, new ScmFileSet(pluginCheckoutDir), new ScmTag(plugin.name + "-" + plugin.version));

if (!result.isSuccess()) {
throw new RuntimeException(result.getProviderMessage() + " || " + result.getCommandOutput());
}
cloneFromSCM(pomData.getConnectionUrl(), plugin.name, plugin.version, pluginCheckoutDir);
}
} else {
// If the plugin exists in a different directory (multimodule plugins)
Expand Down Expand Up @@ -512,6 +528,17 @@ private TestExecutionResult testPluginAgainst(MavenCoordinates coreCoordinates,
}
}

private void cloneFromSCM(String connectionUrl, String name, String version, File checkoutDirectory) throws ComponentLookupException, ScmException {
System.out.println("Checking out from SCM connection URL : " + connectionUrl + " (" + name + "-" + version + ")");
ScmManager scmManager = SCMManagerFactory.getInstance().createScmManager();
ScmRepository repository = scmManager.makeScmRepository(connectionUrl);
CheckOutScmResult result = scmManager.checkOut(repository, new ScmFileSet(checkoutDirectory), new ScmTag(name + "-" + version));

if (!result.isSuccess()) {
throw new RuntimeException(result.getProviderMessage() + " || " + result.getCommandOutput());
}
}

private boolean localCheckoutProvided() {
return config.getLocalCheckoutDir() != null && config.getLocalCheckoutDir().exists();
}
Expand Down
20 changes: 19 additions & 1 deletion pom.xml
Expand Up @@ -170,8 +170,26 @@
<goals>deploy</goals>
</configuration>
</plugin>
<!-- TODO: remove when library parent POM enables FindBugs by default -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<configuration>
<xmlOutput>true</xmlOutput>
<effort>Max</effort>
<!-- TODO: issues need to be fixed first-->
<failOnError>false</failOnError>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

</build>

</project>

0 comments on commit f531b97

Please sign in to comment.