Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create hook for structs #65

Merged
4 commits merged into from Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -11,7 +11,6 @@
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCheckout;

import java.io.File;
import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -55,7 +54,7 @@ public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception
firstRun = false;

// Change the "download"" directory; after download, it's simply used for reference
File childPath = new File(config.workDirectory.getAbsolutePath() + "/" + getParentFolder() + "/" + currentPlugin.name);
File childPath = new File(config.workDirectory.getAbsolutePath() + "/" + getParentFolder() + "/" + getPluginFolderName(currentPlugin));

System.out.println("Child path for " + currentPlugin.getDisplayName() + " " + childPath);
moreInfo.put("checkoutDir", childPath);
Expand All @@ -80,4 +79,11 @@ public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception
*/
protected abstract String getParentProjectName();

/**
* Returns the plugin folder name, by default it will be the plugin name, but can be overriden to support plugins
* (like structs) that are not located in a folder with the same name than the plugin itself
*/
protected String getPluginFolderName(UpdateSite.Plugin currentPlugin) {
return currentPlugin.name;
}
}
Expand Up @@ -17,37 +17,36 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

public class BOAndDPCompileHook extends PluginCompatTesterHookBeforeCompile {
public class MultiParentCompileHook extends PluginCompatTesterHookBeforeCompile {

protected MavenRunner runner;
protected MavenRunner.Config mavenConfig;

public static final String ESLINTRC = ".eslintrc";

public BOAndDPCompileHook() {
System.out.println("Loaded Blue Ocean and Declarative Pipeline compile hook");
public MultiParentCompileHook() {
System.out.println("Loaded multi-parent compile hook");
}


@Override
public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception {
try {
System.out.println("Executing Blue Ocean and Declarative Pipeline compile hook");
System.out.println("Executing multi-parent 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");
Path pluginSourcesDir = config.getLocalCheckoutDir().toPath();
System.out.println("Plugin dir is " + pluginDir);

if (pluginSourcesDir != null) {
if (config.getLocalCheckoutDir() != null) {
Path pluginSourcesDir = config.getLocalCheckoutDir().toPath();
boolean isMultipleLocalPlugins = config.getIncludePlugins() != null && config.getIncludePlugins().size() > 1;
// We are running for local changes, let's copy the .eslintrc file if we can
// If we are using localCheckoutDir with multiple plugins the .eslintrc must be located at the top level
Expand All @@ -57,7 +56,7 @@ public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception
}
// Copy the file if it exists
Files.walk(pluginSourcesDir, 1)
.filter(file -> isEslintFile(file))
.filter(this::isEslintFile)
.forEach(eslintrc -> copy(eslintrc, pluginDir));
}

Expand All @@ -69,7 +68,7 @@ public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception
moreInfo.put(OVERRIDE_DEFAULT_COMPILE, true);
}

System.out.println("Executed Blue Ocean and Declarative Pipeline compile hook");
System.out.println("Executed multi-parent compile hook");
return moreInfo;
// Exceptions get swallowed, so we print to console here and rethrow again
} catch (Exception e) {
Expand All @@ -86,7 +85,7 @@ public void validate(Map<String, Object> toCheck) throws Exception {

@Override
public boolean check(Map<String, Object> info) throws Exception {
return BlueOceanHook.isBOPlugin(info) || DeclarativePipelineHook.isDPPlugin(info);
return BlueOceanHook.isBOPlugin(info) || DeclarativePipelineHook.isDPPlugin(info) || StructsHook.isStructsPlugin(info);
}

private boolean isEslintFile(Path file) {
Expand Down
@@ -0,0 +1,39 @@
package org.jenkins.tools.test.hook;

import hudson.model.UpdateSite;
import org.jenkins.tools.test.model.PomData;

import java.util.Map;

public class StructsHook extends AbstractMultiParentHook {

@Override
protected String getParentFolder() {
return "structs-plugin";
}

@Override
protected String getParentUrl() {
return "scm:git:git://github.com/jenkinsci/structs-plugin.git";
}

@Override
protected String getParentProjectName() {
return "structs-parent";
}

@Override
public boolean check(Map<String, Object> info) throws Exception {
return isStructsPlugin(info);
}

@Override
protected String getPluginFolderName(UpdateSite.Plugin currentPlugin) {
return "plugin";
}

public static boolean isStructsPlugin(Map<String, Object> moreInfo) {
PomData data = (PomData) moreInfo.get("pomData");
return data.parent.artifactId.equalsIgnoreCase("structs-parent");
}
}
Expand Up @@ -5,7 +5,6 @@
import org.jenkins.tools.test.model.PomData;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeExecution;

import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -35,13 +34,14 @@ public boolean check(Map<String, Object> info) {
parent.matches("com.cloudbees.operations-center.common", "operations-center-parent") ||
parent.matches("com.cloudbees.operations-center.client", "operations-center-parent-client");
boolean isBO = parent.matches("io.jenkins.blueocean", "blueocean-parent");
boolean isStructs = parent.matches("org.jenkins-ci.plugins", "structs-parent");
boolean pluginPOM = parent.matches("org.jenkins-ci.plugins", "plugin");
boolean parentV2 = parent.compareVersionTo("2.0") >= 0;
boolean parentUnder233 = parentV2 && parent.compareVersionTo(PLUGINS_PARENT_POM_FOR_CORE_WITHOUT_WAR_TEST) < 0;
boolean coreRequiresNewParentPOM = coreCoordinates.compareVersionTo(CORE_NEW_PARENT_POM) >= 0;
boolean coreRequiresPluginOver233 = coreCoordinates.compareVersionTo(CORE_WITHOUT_WAR_FOR_TEST) >= 0;

if (isDeclarativePipeline || isBO || isCB || (pluginPOM && parentV2)) {
if (isDeclarativePipeline || isBO || isCB || isStructs || (pluginPOM && parentV2)) {
List<String> argsToMod = (List<String>)info.get("args");
argsToMod.add("-Djenkins.version=" + coreCoordinates.version);
// There are rules that avoid dependencies on a higher java level. Depending on the baselines and target cores
Expand Down