Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-44524 Support configuring a site on a folder
- Loading branch information
Brian Saville
committed
Jun 5, 2017
1 parent
45e79b3
commit b1408fe
Showing
7 changed files
with
151 additions
and
37 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/hudson/plugins/jira/EmptyFriendlyURLConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package hudson.plugins.jira; | ||
|
||
import org.apache.commons.beanutils.Converter; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* It's little hackish. | ||
*/ | ||
@Restricted(NoExternalUse.class) | ||
public class EmptyFriendlyURLConverter implements Converter { | ||
private static final Logger LOGGER = Logger | ||
.getLogger(JiraProjectProperty.class.getName()); | ||
|
||
public Object convert(Class aClass, Object o) { | ||
if (o == null || "".equals(o) || "null".equals(o)) { | ||
return null; | ||
} | ||
try { | ||
return new URL(o.toString()); | ||
} catch (MalformedURLException e) { | ||
LOGGER.log(Level.WARNING, "{0} is not a valid URL", o); | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package hudson.plugins.jira; | ||
|
||
import com.cloudbees.hudson.plugins.folder.AbstractFolder; | ||
import com.cloudbees.hudson.plugins.folder.AbstractFolderProperty; | ||
import com.cloudbees.hudson.plugins.folder.AbstractFolderPropertyDescriptor; | ||
import hudson.Extension; | ||
import hudson.model.Descriptor; | ||
import hudson.util.CopyOnWriteList; | ||
import net.sf.json.JSONObject; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
import org.kohsuke.stapler.Stapler; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.List; | ||
|
||
/** | ||
* Provides folder level JIRA configuration. | ||
*/ | ||
public class JiraFolderProperty extends AbstractFolderProperty<AbstractFolder<?>> { | ||
/** | ||
* Hold the JIRA sites configuration. | ||
*/ | ||
private final CopyOnWriteList<JiraSite> sites = new CopyOnWriteList<JiraSite>(); | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
@DataBoundConstructor | ||
public JiraFolderProperty() { | ||
} | ||
|
||
@Override | ||
public AbstractFolderProperty<?> reconfigure(StaplerRequest req, JSONObject formData) | ||
throws Descriptor.FormException { | ||
if (formData == null) { | ||
return null; | ||
} | ||
//Fix^H^H^HDirty hack for empty string to URL conversion error | ||
//Should check for existing handler etc, but since this is a dirty hack, | ||
//we won't | ||
Stapler.CONVERT_UTILS.deregister(java.net.URL.class); | ||
Stapler.CONVERT_UTILS.register(new EmptyFriendlyURLConverter(), java.net.URL.class); | ||
//End hack | ||
|
||
sites.replaceBy(req.bindJSONToList(JiraSite.class, formData.get("sites"))); | ||
return this; | ||
} | ||
|
||
/** | ||
* Return the JIRA sites. | ||
* | ||
* @return the JIRA sites | ||
*/ | ||
public JiraSite[] getSites() { | ||
return sites.toArray(new JiraSite[0]); | ||
} | ||
|
||
/** | ||
* Adds a JIRA site. | ||
* | ||
* @param site the JIRA site | ||
*/ | ||
@DataBoundSetter | ||
public void setSites(JiraSite site) { | ||
sites.add(site); | ||
} | ||
|
||
/** | ||
* Descriptor class. | ||
*/ | ||
@Extension | ||
public static class DescriptorImpl extends AbstractFolderPropertyDescriptor { | ||
|
||
@Nonnull | ||
@Override | ||
public String getDisplayName() { | ||
return Messages.JiraFolderProperty_DisplayName(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/resources/hudson/plugins/jira/JiraFolderProperty/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<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"> | ||
<f:section title="JIRA"> | ||
<f:entry title="${%JIRA sites}" description=""> | ||
<f:repeatableProperty field="sites"/> | ||
</f:entry> | ||
</f:section> | ||
</j:jelly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters