Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit dc3b25f
Author: Mads Nielsen <man@praqma.net>
Date:   Thu Jan 11 10:30:27 2018 +0100

    Fix for Praqma#97

commit 034d32e
Author: Mads Nielsen <man@praqma.net>
Date:   Thu Jan 11 09:59:48 2018 +0100

    Fixed merge conflict. For Praqma#97

commit 15cd353
Author: Mads Nielsen <man@praqma.net>
Date:   Thu Jan 11 09:09:40 2018 +0100

    Implemented Praqma#97. Close issue Praqma#97

commit a06d856
Author: Mads Nielsen <man@praqma.net>
Date:   Thu Jan 11 08:49:12 2018 +0100

    Rename to IT to be picked up in integration test. For Praqma#97

commit 6768dfc
Author: Mads Nielsen <man@praqma.net>
Date:   Thu Jan 11 08:34:15 2018 +0100

    Implemented Praqma#97. Close
  • Loading branch information
MadsNielsen authored and Praqma committed Jan 11, 2018
1 parent 573c6b8 commit 2562658
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 26 deletions.
20 changes: 17 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@
<version>4.5.2</version>
</dependency>



<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
Expand Down Expand Up @@ -244,6 +242,14 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jenkins-multijob-plugin</artifactId>
<scope>test</scope>
<optional>true</optional>
<version>1.28</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
Expand All @@ -258,14 +264,22 @@
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>

<!--
Added because of multijob plugin and maven job's depend on two older ant libraries.
We need to use the newest as plugins are not forwards compatible.
-->
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.9.2</version>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import hudson.AbortException;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.matrix.MatrixAggregatable;
import hudson.matrix.MatrixAggregator;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixConfiguration;
import hudson.matrix.*;
import hudson.model.*;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.extensions.impl.RelativeTargetDirectory;
Expand All @@ -23,12 +19,13 @@
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.pretestedintegration.scm.git.GitBridge;
import org.jenkinsci.plugins.pretestedintegration.scm.git.PretestTriggerCommitAction;
import org.jenkinsci.plugins.pretestedintegration.scm.git.PretestedIntegrationAsGitPluginExt;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -45,8 +42,7 @@ public class PretestedIntegrationPostCheckout extends Recorder implements Serial
* Constructor for PretestedIntegrationPostCheckout
*/
@DataBoundConstructor
public PretestedIntegrationPostCheckout() {
}
public PretestedIntegrationPostCheckout() { }

///**
// * Gets the SCM Bridge of the BuildWrapper of this project.
Expand Down Expand Up @@ -85,7 +81,7 @@ private AbstractSCMBridge getScmBridge(AbstractBuild<?, ?> build, BuildListener
*/

/**
* Calls the SCM-specific function according to the chosen SCM.
* Calls the SCM-specific function according to the chosen SCM. Only called for Non pipeline jobs
*
* @param build The Build
* @param launcher The Launcher
Expand All @@ -103,6 +99,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
RelativeTargetDirectory rtd = scm.getExtensions().get(RelativeTargetDirectory.class);
try {
FilePath wsForUs = rtd != null ? rtd.getWorkingDirectory(scm, proj, build.getWorkspace(), build.getEnvironment(listener), listener) : build.getWorkspace();
printWarningIfUnsupported(proj.getClass(), listener);
perform((Run) build, wsForUs, launcher, listener);
} catch (IOException ex) {
listener.getLogger().println("[PREINT] FATAL: Unable to determine workspace");
Expand All @@ -112,6 +109,35 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
return true;
}

/**
* For #97. Whitelist certain job types. We include only those we support. We need not include pipeline jobs since
* they do not call the perform method.
*/
private static final List<String> WHITELIST = new ArrayList<>();
static {
WHITELIST.add(FreeStyleProject.class.getName());
WHITELIST.add(MatrixProject.class.getName());
//Maven job type. Several kinds here. We can with 100% certainty say that we match everything with maven here
WHITELIST.add("hudson.maven");
}

public boolean isSupported(Class classname) {
for(String whiteListed : WHITELIST) {
if (classname.getName().contains(whiteListed)) {
return true;
}
}
return false;
}

public void printWarningIfUnsupported(Class classname, BuildListener listener) {
if(!isSupported(classname)) {
String message = LOG_PREFIX+"Warning: Unsupported job type "+classname.getSimpleName()+" "+"plugin might not work as expected";
listener.getLogger().println(message);
LOGGER.log(Level.WARNING, message);
}
}

/**
* For a matrix project, push should only happen once.
*/
Expand Down Expand Up @@ -176,7 +202,6 @@ public BuildStepMonitor getRequiredMonitorService() {
@Symbol("pretestedIntegration")
@Extension(ordinal = Integer.MIN_VALUE)
public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> {

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.jenkinsci.plugins.pretestedintegration.integration.scm.git;

import com.tikal.jenkins.plugins.multijob.MultiJobProject;
import hudson.matrix.MatrixProject;
import hudson.model.FreeStyleProject;
import hudson.model.ItemGroup;
import org.jenkinsci.plugins.pretestedintegration.PretestedIntegrationPostCheckout;
import org.junit.Test;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

public class GHI97_SupportChecksIT {

/**
* See GitHub issue #97
*/
@Test
public void validateReturnsFromSupportedChecks_ValidatesGHI97() {
PretestedIntegrationPostCheckout pipPost = new PretestedIntegrationPostCheckout();
MultiJobProject multiJobProject = new MultiJobProject(null, "MultiJobMustNotBeSupported");
FreeStyleProject freeStyleProject = new FreeStyleProject((ItemGroup)null, "FreeStyleProjectMustBeSupported");
MatrixProject matrix = new MatrixProject(null,"MatrixJobsMustBeSupported");
assertFalse(pipPost.isSupported(multiJobProject.getClass()));
assertTrue(pipPost.isSupported(freeStyleProject.getClass()));
assertTrue(pipPost.isSupported(matrix.getClass()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,24 @@
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.plugins.git.BranchSpec;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.SubmoduleConfig;
import hudson.plugins.git.UserRemoteConfig;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.impl.CleanCheckout;
import hudson.plugins.git.extensions.impl.PruneStaleBranch;
import hudson.plugins.git.extensions.impl.RelativeTargetDirectory;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.SubmoduleConfig;
import hudson.plugins.git.UserRemoteConfig;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;

import org.eclipse.jgit.lib.Repository;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.JenkinsRule;

import java.util.*;

import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;

public class GeneralBehaviourIT {

@Rule
Expand Down Expand Up @@ -392,4 +387,5 @@ public void validateSquashCommitMessageContents() throws Exception {
}

}

}

0 comments on commit 2562658

Please sign in to comment.