Skip to content
Permalink
Browse files

Merge pull request #66 from ikedam/feature/JENKINS-28972_FixSimpleBui…

…ldSelectorDescriptor

[JENKINS-28972] Make SimpleBuildSelectorDescriptor usable from other plugins
  • Loading branch information...
ikedam committed Jul 4, 2015
2 parents fab46fd + 37881e0 commit 4a6c542e5b6d2cc4eecf4eb07d6f5e4e4754f2d6
@@ -24,6 +24,7 @@
package hudson.plugins.copyartifact;

import hudson.model.Descriptor;

import org.jvnet.localizer.Localizable;

/**
@@ -45,4 +46,22 @@ public SimpleBuildSelectorDescriptor(Class<? extends BuildSelector> clazz,
public String getDisplayName() {
return displayName.toString();
}

@Override
public String getConfigPage() {
if (!getClass().equals(SimpleBuildSelectorDescriptor.class)) {
return super.getConfigPage();
}
// Workaround for JENKINS-28972, JENKINS-29048
// Jenkins tries to load view file
// not from the plugin the BuildSelector is located,
// but from the plugin the Descriptor is located (JENKINS-29048).
// This cause failures for BuildSelectors
// using SimpleBuildSelectorDescriptor (JENKINS-28972).
return getViewPage(SimpleBuildSelectorDescriptor.class, "config.jelly");
}

public String getBuildSelectorConfigPage() {
return super.getConfigPage();
}
}
@@ -0,0 +1,32 @@
<!--
The MIT License
Copyright (c) 2015 IKEDA Yasuyuki
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
<!--
Workaround for JENKINS-28972, JENKINS-29048.
See SimpleBuildSelectorDescriptor#getConfigPage() for details.
-->

<st:include class="${descriptor.clazz}" page="${descriptor.buildSelectorConfigPage}" optional="true" />
</j:jelly>
@@ -76,11 +76,13 @@
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.CaptureEnvironmentBuilder;
import org.jvnet.hudson.test.FailureBuilder;
import org.jvnet.hudson.test.MockFolder;
import org.jvnet.hudson.test.UnstableBuilder;
import org.jvnet.hudson.test.recipes.LocalData;
import org.jvnet.hudson.test.recipes.WithPlugin;

import com.cloudbees.hudson.plugins.folder.Folder;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
@@ -1792,4 +1794,33 @@ public void testQueueItemAuthenticator() throws Exception {
assertBuildStatus(Result.FAILURE, copier.scheduleBuild2(0).get(TIMEOUT, TimeUnit.SECONDS));
}
}

@Issue("JENKINS-28972")
@LocalData
@WithPlugin("copyartifact-extension-test.hpi") // JENKINS-28792 reproduces only when classes are located in different class loaders.
public void testSimpleBuildSelectorDescriptorInOtherPlugin() throws Exception {
WebClient wc = createWebClient();

// An extension using SimpleBuildSelectorDescriptorSelector
{
FreeStyleProject p = jenkins.getItemByFullName("UsingSimpleBuildSelectorDescriptorSelector", FreeStyleProject.class);
assertNotNull(p);
wc.getPage(p, "configure");
}

// An extension using SimpleBuildSelectorDescriptorSelector without configuration pages.
{
FreeStyleProject p = jenkins.getItemByFullName("NoConfigPageSimpleBuildSelectorDescriptorSelector", FreeStyleProject.class);
assertNotNull(p);
wc.getPage(p, "configure");
}

// An extension extending SimpleBuildSelectorDescriptorSelector.
// (Even though generally it is useless)
{
FreeStyleProject p = jenkins.getItemByFullName("ExtendingSimpleBuildSelectorDescriptorSelector", FreeStyleProject.class);
assertNotNull(p);
wc.getPage(p, "configure");
}
}
}
@@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<hudson>
<version>1.580.1</version>
</hudson>
@@ -0,0 +1,28 @@
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.plugins.copyartifact.CopyArtifact plugin="copyartifact@1.35">
<project>ExtendingSimpleBuildSelectorDescriptorSelector</project>
<filter>**/*</filter>
<target></target>
<excludes></excludes>
<selector class="org.jenkinsci.plugins.copyartifactextensiontest.ExtendingSimpleBuildSelectorDescriptorSelector" plugin="copyartifact-extension-test@1.0-SNAPSHOT">
<field>test</field>
</selector>
<doNotFingerprintArtifacts>false</doNotFingerprintArtifacts>
</hudson.plugins.copyartifact.CopyArtifact>
</builders>
<publishers/>
<buildWrappers/>
</project>
@@ -0,0 +1,26 @@
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.plugins.copyartifact.CopyArtifact plugin="copyartifact@1.35">
<project>NoConfigPageSimpleBuildSelectorDescriptorSelector</project>
<filter>**/*</filter>
<target></target>
<excludes></excludes>
<selector class="org.jenkinsci.plugins.copyartifactextensiontest.NoConfigPageSimpleBuildSelectorDescriptorSelector" plugin="copyartifact-extension-test@1.0-SNAPSHOT"/>
<doNotFingerprintArtifacts>false</doNotFingerprintArtifacts>
</hudson.plugins.copyartifact.CopyArtifact>
</builders>
<publishers/>
<buildWrappers/>
</project>
@@ -0,0 +1,28 @@
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.plugins.copyartifact.CopyArtifact plugin="copyartifact@1.35">
<project>UsingSimpleBuildSelectorDescriptorSelector</project>
<filter>**/*</filter>
<target></target>
<excludes></excludes>
<selector class="org.jenkinsci.plugins.copyartifactextensiontest.UsingSimpleBuildSelectorDescriptorSelector" plugin="copyartifact-extension-test@1.0-SNAPSHOT">
<field>test</field>
</selector>
<doNotFingerprintArtifacts>false</doNotFingerprintArtifacts>
</hudson.plugins.copyartifact.CopyArtifact>
</builders>
<publishers/>
<buildWrappers/>
</project>
@@ -0,0 +1,3 @@
* copyartifact-extension-test.hpi
* A plugin to test plugins depending copyartifact-plugin.
* You can get sources at https://github.com/ikedam/copyartifact-extension-test.
Binary file not shown.

0 comments on commit 4a6c542

Please sign in to comment.
You can’t perform that action at this time.