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

[JENKINS-44266, JENKINS-36654] Fix PCT for 2.46.2 #103

Merged
merged 6 commits into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 11 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.17</version>
<version>2.29</version>
</parent>

<artifactId>promoted-builds</artifactId>
<version>2.28.2-SNAPSHOT</version>
<packaging>hpi</packaging>

<name>Jenkins promoted builds plugin</name>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Promoted+Builds+Plugin</url>
<url>https://wiki.jenkins-ci.org/display/JENKINS/Promoted+Builds+Plugin</url>

<properties>
<jenkins.version>1.565</jenkins.version>
<jenkins.version>1.609.3</jenkins.version>
<java.level>6</java.level>
</properties>

Expand Down Expand Up @@ -48,42 +48,23 @@
</licenses>

<repositories>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 In such case it won't be able to retrieve Parent pom if it is missing in the local cache.

OTOH you can simplify it to

    <repositories> 
      <repository>
        <id>repo.jenkins-ci.org</id>
        <url>http://repo.jenkins-ci.org/public/</url>
      </repository>
    </repositories>
    <pluginRepositories>
      <pluginRepository>
        <id>repo.jenkins-ci.org</id>
        <url>http://repo.jenkins-ci.org/public/</url>
      </pluginRepository>
    </pluginRepositories>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, use https but otherwise yes that is the standard blurb.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copypasted from the wrong plugin :(

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I thought this was already included in the parent POM.

<!-- needed unless you have a profile for those -->
<repository>
<id>jenkins-releases</id>
<url>http://repo.jenkins-ci.org/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>

<pluginRepositories>
<!-- needed unless you have a profile for those -->
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
<version>2.0</version>
<version>2.13</version>
</dependency>
<dependency>
<groupId>com.sonyericsson.hudson.plugins.rebuild</groupId>
Expand All @@ -106,7 +87,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>token-macro</artifactId>
<version>1.10</version>
<version>1.12.1</version>
<optional>true</optional>
</dependency>
<dependency>
Expand All @@ -124,7 +105,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<version>1.16</version>
<version>1.26</version>
</dependency>
<dependency>
<groupId>org.jvnet.hudson</groupId>
Expand All @@ -135,19 +116,19 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>parameterized-trigger</artifactId>
<version>2.30</version>
<version>2.33</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-auth</artifactId>
<version>1.0</version>
<version>1.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.0</version>
<version>1.11</version>
<scope>test</scope>
</dependency>
<dependency> <!-- required to workaround the missing CookieSpecProvider class -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import jenkins.security.MasterToSlaveCallable;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
Expand All @@ -35,7 +36,6 @@
import hudson.model.JobProperty;
import hudson.model.JobPropertyDescriptor;
import hudson.model.listeners.ItemListener;
import hudson.remoting.Callable;
import hudson.util.IOUtils;
import javax.annotation.CheckForNull;
import jenkins.model.Jenkins;
Expand Down Expand Up @@ -305,7 +305,7 @@ public PromotionProcess createProcessFromXml(final String name, InputStream xml)
}
try {
IOUtils.copy(xml, configXml);
PromotionProcess result = Items.whileUpdatingByXml(new Callable<PromotionProcess,IOException>() {
PromotionProcess result = Items.whileUpdatingByXml(new MasterToSlaveCallable<PromotionProcess, IOException>() {
@Override public PromotionProcess call() throws IOException {
setOwner(owner);
return getItem(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@
import hudson.model.FreeStyleProject;
import hudson.plugins.promoted_builds.conditions.DownstreamPassCondition;
import hudson.tasks.JavadocArchiver;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

import static com.gargoylesoftware.htmlunit.html.HtmlFormUtil.submit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author Seiji Sogabe
*/
public class ConfigurationDoCheckTest extends HudsonTestCase {
public class ConfigurationDoCheckTest {

@Rule
public JenkinsRule j = new JenkinsRule();

@Bug(7972)
@Issue("7972")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use full id, e.g. "JENKINS-7972"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Test
public void testCheckProcessNameRequired() throws Exception {
FreeStyleProject down = createFreeStyleProject();
FreeStyleProject down = j.createFreeStyleProject();

FreeStyleProject p = createFreeStyleProject();
FreeStyleProject p = j.createFreeStyleProject();
JobPropertyImpl pp = new JobPropertyImpl(p);
p.addProperty(pp);

Expand All @@ -26,18 +36,20 @@ public void testCheckProcessNameRequired() throws Exception {
proc.getBuildSteps().add(new JavadocArchiver("somedir",true));
proc.icon = "star-blue";

WebClient client = new WebClient();
JenkinsRule.WebClient client = j.createWebClient();
client.getOptions().setThrowExceptionOnFailingStatusCode(false);
HtmlPage page = submit(client.getPage(p, "configure").getFormByName("config"));

HtmlPage page = (HtmlPage) submit(client.getPage(p, "configure").getFormByName("config"));
assertTrue(page.asText().contains("No name is specified"));

}

@Bug(7972)
@Issue("7972")
@Test
public void testCheckInvalidProcessName() throws Exception {
FreeStyleProject down = createFreeStyleProject();
FreeStyleProject down = j.createFreeStyleProject();

FreeStyleProject p = createFreeStyleProject();
FreeStyleProject p = j.createFreeStyleProject();
JobPropertyImpl pp = new JobPropertyImpl(p);
p.addProperty(pp);

Expand All @@ -47,9 +59,10 @@ public void testCheckInvalidProcessName() throws Exception {
proc.getBuildSteps().add(new JavadocArchiver("somedir",true));
proc.icon = "star-blue";

WebClient client = new WebClient();
JenkinsRule.WebClient client = j.createWebClient();
client.getOptions().setThrowExceptionOnFailingStatusCode(false);
HtmlPage page = submit(client.getPage(p, "configure").getFormByName("config"));

HtmlPage page = (HtmlPage) submit(client.getPage(p, "configure").getFormByName("config"));
assertTrue(page.asText().contains("unsafe character"));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,33 @@
import hudson.model.FreeStyleProject;
import hudson.plugins.promoted_builds.conditions.DownstreamPassCondition;
import hudson.tasks.JavadocArchiver;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;

import static com.gargoylesoftware.htmlunit.html.HtmlFormUtil.submit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

/**
* @author Kohsuke Kawaguchi
*/
public class ConfigurationRoundtripTest extends HudsonTestCase {
public class ConfigurationRoundtripTest {

@Rule
public JenkinsRule j = new JenkinsRule();

/**
* Configuration roundtrip test to detect data loss.
*/
@Test
public void testRoundtrip() throws Exception {
FreeStyleProject down = createFreeStyleProject();
FreeStyleProject down = j.createFreeStyleProject();

FreeStyleProject p = createFreeStyleProject();
FreeStyleProject p = j.createFreeStyleProject();
JobPropertyImpl pp = new JobPropertyImpl(p);
p.addProperty(pp);

Expand All @@ -51,7 +63,8 @@ public void testRoundtrip() throws Exception {
proc.icon = "star-blue";

// round trip
submit(new WebClient().getPage(p,"configure").getFormByName("config"));
JenkinsRule.WebClient wc = j.createWebClient();
submit(wc.getPage(p,"configure").getFormByName("config"));

// assert that the configuration is still intact
pp = p.getProperty(JobPropertyImpl.class);
Expand All @@ -68,11 +81,12 @@ public void testRoundtrip() throws Exception {
}

@LocalData
@Bug(17341)
@Issue("17341")
@Test
public void testLoad() throws Exception {
FreeStyleProject j = jenkins.getItemByFullName("j", FreeStyleProject.class);
assertNotNull(j);
Promotion p = j.getProperty(JobPropertyImpl.class).getItem("OK").getBuildByNumber(1);
FreeStyleProject jProj = j.jenkins.getItemByFullName("j", FreeStyleProject.class);
assertNotNull(jProj);
Promotion p = jProj.getProperty(JobPropertyImpl.class).getItem("OK").getBuildByNumber(1);
assertNotNull(p);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,26 @@
import hudson.tasks.ArtifactArchiver;
import hudson.tasks.Fingerprinter;
import hudson.tasks.Recorder;
import org.jvnet.hudson.test.HudsonTestCase;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestBuilder;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import static hudson.plugins.promoted_builds.util.ItemListenerHelper.fireItemListeners;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class KeepBuildForeverActionTest extends HudsonTestCase {

public class KeepBuildForeverActionTest {

@Rule
public JenkinsRule j = new JenkinsRule();

@Test
public void testCanMarkBuildKeepForever() throws Exception {
FreeStyleProject upJob = createProject("up");
upJob.getBuildersList().add(successfulBuilder());
Expand All @@ -37,14 +46,15 @@ public void testCanMarkBuildKeepForever() throws Exception {
// fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+
fireItemListeners();

FreeStyleBuild upBuild = assertBuildStatusSuccess(upJob.scheduleBuild2(0).get());
FreeStyleBuild upBuild = j.assertBuildStatusSuccess(upJob.scheduleBuild2(0).get());
assertFalse(upBuild.isKeepLog());

assertBuildStatusSuccess(downJob.scheduleBuild2(0).get());
j.assertBuildStatusSuccess(downJob.scheduleBuild2(0).get());
waitForBuild(promotionJob, 1);
assertTrue(upBuild.isKeepLog());
}


@Test
public void testDoesNotMarkBuildIfPromotionNotGoodEnough() throws Exception {
FreeStyleProject upJob = createProject("up");
upJob.getBuildersList().add(successfulBuilder());
Expand All @@ -58,14 +68,15 @@ public void testDoesNotMarkBuildIfPromotionNotGoodEnough() throws Exception {
// fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+
fireItemListeners();

FreeStyleBuild upBuild = assertBuildStatusSuccess(upJob.scheduleBuild2(0).get());
FreeStyleBuild upBuild = j.assertBuildStatusSuccess(upJob.scheduleBuild2(0).get());
assertFalse(upBuild.isKeepLog());

assertBuildStatusSuccess(downJob.scheduleBuild2(0).get());
j.assertBuildStatusSuccess(downJob.scheduleBuild2(0).get());
waitForBuild(promotionJob, 1);
assertFalse(upBuild.isKeepLog());
}

@Test
public void testDoesNotCareAboutResultOfOriginalBuild() throws Exception {
FreeStyleProject upJob = createProject("up");
upJob.getBuildersList().add(new FixedResultBuilder(Result.FAILURE));
Expand All @@ -78,14 +89,15 @@ public void testDoesNotCareAboutResultOfOriginalBuild() throws Exception {
// fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+
fireItemListeners();

FreeStyleBuild upBuild = assertBuildStatus(Result.FAILURE, upJob.scheduleBuild2(0).get());
FreeStyleBuild upBuild = j.assertBuildStatus(Result.FAILURE, upJob.scheduleBuild2(0).get());
assertFalse(upBuild.isKeepLog());

assertBuildStatusSuccess(downJob.scheduleBuild2(0).get());
j.assertBuildStatusSuccess(downJob.scheduleBuild2(0).get());
waitForBuild(promotionJob, 1);
assertTrue(upBuild.isKeepLog());
}

@Test
public void testDoesNotMarkBuildIfBuildNotPromotion() throws Exception {
FreeStyleProject job = createProject("job");
job.getBuildersList().add(successfulBuilder());
Expand All @@ -94,7 +106,7 @@ public void testDoesNotMarkBuildIfBuildNotPromotion() throws Exception {
// fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+
fireItemListeners();

FreeStyleBuild build = assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get());
FreeStyleBuild build = j.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get());
assertFalse(build.isKeepLog());
}

Expand Down Expand Up @@ -135,16 +147,15 @@ private PromotionProcess createDownstreamSuccessPromotion(FreeStyleProject upStr
}

private FreeStyleProject createProject(String name) throws Exception {
FreeStyleProject project = createFreeStyleProject(name);
FreeStyleProject project = j.createFreeStyleProject(name);
project.getPublishersList().replaceBy(createFingerprinters());
return project;
}

private List<Recorder> createFingerprinters() {
return Arrays.asList(
new ArtifactArchiver("*", null, false),
new Fingerprinter("", true)
);
Recorder r1 = new ArtifactArchiver("*", null, false);
Recorder r2 = new Fingerprinter("", true);
return Arrays.asList(r1, r2);
}

private FixedResultBuilder successfulBuilder() {
Expand Down
Loading