Skip to content

Commit

Permalink
Merge pull request #44 from raul-arabaolaza/JENKINS-45333
Browse files Browse the repository at this point in the history
[JENKINS-45333] Remove node folders before compiling on local checkout of BO
  • Loading branch information
andresrc committed Sep 19, 2017
2 parents 2930c8d + ea4af3c commit 593fc90
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
Expand Up @@ -5,7 +5,16 @@
* Plugins Compat Tester.
*
* This exists simply for the ability to check when a subclass should be implemented.
*
* Hooks of this type can be used to implement custom compile configurations that override the one done by the PCT
*
* To do that add a ranCompile property to the returned map with a true value, and make sure the hook runs the compilation
* phase. As hooks are not executed in any particular order any hook that performs the compilation must check before if
* it has already been performed by another hook and decide on consequence.
*
*/
public abstract class PluginCompatTesterHookBeforeCompile implements PluginCompatTesterHook {

public static final String OVERRIDE_DEFAULT_COMPILE = "ranCompile";

}
Expand Up @@ -52,6 +52,7 @@
import org.jenkins.tools.test.model.PluginCompatReport;
import org.jenkins.tools.test.model.PluginCompatResult;
import org.jenkins.tools.test.model.PluginCompatTesterConfig;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCompile;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHooks;
import org.jenkins.tools.test.model.PluginInfos;
import org.jenkins.tools.test.model.PluginRemoting;
Expand Down Expand Up @@ -403,14 +404,18 @@ private TestExecutionResult testPluginAgainst(MavenCoordinates coreCoordinates,
beforeCompile.put("pluginDir", pluginCheckoutDir);
beforeCompile.put("pomData", pomData);
beforeCompile.put("config", config);
pcth.runBeforeCompilation(beforeCompile);
boolean ranCompile = false;
beforeCompile.put("core", coreCoordinates);
Map<String, Object> hookInfo = pcth.runBeforeCompilation(beforeCompile);

boolean ranCompile = hookInfo.containsKey(PluginCompatTesterHookBeforeCompile.OVERRIDE_DEFAULT_COMPILE) ? (boolean) hookInfo.get(PluginCompatTesterHookBeforeCompile.OVERRIDE_DEFAULT_COMPILE) : false;
try {
// First build against the original POM.
// This defends against source incompatibilities (which we do not care about for this purpose);
// and ensures that we are testing a plugin binary as close as possible to what was actually released.
// We also skip potential javadoc execution to avoid general test failure.
runner.run(mconfig, pluginCheckoutDir, buildLogFile, "clean", "process-test-classes", "-Dmaven.javadoc.skip");
if (!ranCompile) {
runner.run(mconfig, pluginCheckoutDir, buildLogFile, "clean", "process-test-classes", "-Dmaven.javadoc.skip");
}
ranCompile = true;

// Then transform the POM and run tests against that.
Expand Down
@@ -1,11 +1,13 @@
package org.jenkins.tools.test.hook;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.jenkins.tools.test.exception.PomExecutionException;
import org.jenkins.tools.test.maven.ExternalMavenRunner;
import org.jenkins.tools.test.maven.InternalMavenRunner;
import org.jenkins.tools.test.maven.MavenRunner;
import org.jenkins.tools.test.model.MavenCoordinates;
import org.jenkins.tools.test.model.PluginCompatTesterConfig;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCompile;

Expand All @@ -17,12 +19,12 @@
import java.util.Map;
import java.util.Properties;

public class TransformPomToEffectiveOne extends PluginCompatTesterHookBeforeCompile {
public class BOAndDPCompileHook extends PluginCompatTesterHookBeforeCompile {

protected MavenRunner runner;
protected MavenRunner.Config mavenConfig;

public TransformPomToEffectiveOne() {
public BOAndDPCompileHook() {
System.out.println("Loaded TransformPomToEffectiveOne");
}

Expand All @@ -41,15 +43,27 @@ public void validate(Map<String, Object> toCheck) throws Exception {

public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception {
try {
System.out.println("Executing tarnsformtoeffective hook");
System.out.println("Executing BO and DO compile hook");
PluginCompatTesterConfig config = (PluginCompatTesterConfig) moreInfo.get("config");
MavenCoordinates core = (MavenCoordinates) moreInfo.get("core");

runner = config.getExternalMaven() == null ? new InternalMavenRunner() : new ExternalMavenRunner(config.getExternalMaven());
mavenConfig = getMavenConfig(config);

File pluginDir = (File) moreInfo.get("pluginDir");
generateEffectivePom(mavenConfig, pluginDir);
System.out.println("Executed transform hook");

// We need to compile before generating effective pom overriding jenkins.version
// only if the plugin is not already compiled
boolean ranCompile = moreInfo.containsKey(OVERRIDE_DEFAULT_COMPILE) ? (boolean) moreInfo.get(OVERRIDE_DEFAULT_COMPILE) : false;
if (!ranCompile) {
compile(mavenConfig, pluginDir);
moreInfo.put(OVERRIDE_DEFAULT_COMPILE, true);
}

// Now we can generate effective pom
generateEffectivePom(mavenConfig, pluginDir, core);

System.out.println("Executed BO and DP compile hook");
return moreInfo;
// Exceptions get swallowed, so we print to console here and rethrow again
} catch (Exception e) {
Expand Down Expand Up @@ -87,9 +101,28 @@ private MavenRunner.Config getMavenConfig(PluginCompatTesterConfig config) throw
return mconfig;
}

private void generateEffectivePom(MavenRunner.Config mavenConfig, File path) throws PomExecutionException {
private void generateEffectivePom(MavenRunner.Config mavenConfig, File path, MavenCoordinates core) throws PomExecutionException {
System.out.println("Generating effective pom in " + path);
File effectivePomLogfile = new File(path + "/effectivePomTransformationLog.log");
runner.run(mavenConfig, path, effectivePomLogfile, "help:effective-pom", "-Doutput=pom.xml");
runner.run(mavenConfig, path, effectivePomLogfile, "help:effective-pom", "-Doutput=pom.xml", "-Djenkins.version=" + core.version);
}

private void compile(MavenRunner.Config mavenConfig, File path) throws PomExecutionException, IOException {
System.out.println("Cleaning up node modules if neccessary");
removeNodeFolders(path);
System.out.println("Compile plugin log in " + path);
File compilePomLogfile = new File(path + "/compilePluginLog.log");
runner.run(mavenConfig, path, compilePomLogfile, "clean", "process-test-classes", "-Dmaven.javadoc.skip");
}

private void removeNodeFolders(File path) throws PomExecutionException, IOException {
File nodeFolder = new File(path, "node");
if (nodeFolder.exists() && nodeFolder.isDirectory()) {
FileUtils.deleteDirectory(nodeFolder);
}
File nodeModulesFolder = new File(path, "node_modules");
if (nodeModulesFolder.exists() && nodeModulesFolder.isDirectory()) {
FileUtils.deleteDirectory(nodeModulesFolder);
}
}
}
Expand Up @@ -26,7 +26,7 @@ public class BlueOceanHook extends AbstractMultiParentHook {
public static final List<String> BO_PLUGINS = Arrays.asList("blueocean", "blueocean-commons",
"blueocean-config", "blueocean-dashboard", "blueocean-events", "blueocean-git-pipeline", "blueocean-github-pipeline",
"blueocean-i18n", "blueocean-jwt", "blueocean-personalization", "blueocean-pipeline-api-impl", "blueocean-rest",
"blueocean-rest-impl", "blueocean-web", "blueocean-pipeline-scm-api");
"blueocean-rest-impl", "blueocean-web", "blueocean-pipeline-scm-api", "blueocean-pipeline-editor", "blueocean-jira");

@Override
protected List<String> getBundledPlugins() {
Expand Down

0 comments on commit 593fc90

Please sign in to comment.