Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-38644] - Add draft support for the Jenkins World PoC
- Loading branch information
1 parent
a3b25df
commit e8c0ea8
Showing
7 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
...opsys/arc/jenkinsci/plugins/jobrestrictions/restrictions/job/JobClassNameRestriction.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,96 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2016 Oleg Nenashev | ||
* | ||
* 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. | ||
*/ | ||
|
||
package com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.job; | ||
|
||
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.Messages; | ||
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.JobRestriction; | ||
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.JobRestrictionDescriptor; | ||
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.util.ClassSelector; | ||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import hudson.Extension; | ||
import hudson.model.Queue; | ||
import hudson.model.Run; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import javax.annotation.Nonnull; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
/** | ||
* Handles job class restrictions. | ||
* @author Oleg Nenashev | ||
* @see ClassSelector | ||
* @since TODO | ||
*/ | ||
// TODO: it's a real issue, needs some love | ||
@SuppressFBWarnings(value = "SE_NO_SERIALVERSIONID", | ||
justification = "XStream does actually need serialization, the code needs refactoring in 1.0") | ||
public class JobClassNameRestriction extends JobRestriction { | ||
|
||
private final List<ClassSelector> jobClasses; | ||
|
||
private transient Set<String> acceptedClassesHash = null; | ||
|
||
@DataBoundConstructor | ||
public JobClassNameRestriction(List<ClassSelector> jobClasses) { | ||
this.jobClasses = jobClasses; | ||
} | ||
|
||
@Nonnull | ||
public List<ClassSelector> getJobClasses() { | ||
return jobClasses; | ||
} | ||
|
||
@Nonnull | ||
private synchronized Set<String> getAcceptedJobClasses() { | ||
if (acceptedClassesHash == null) { | ||
final List<ClassSelector> selectors = getJobClasses(); | ||
acceptedClassesHash = new HashSet<String>(selectors.size()); | ||
for (ClassSelector selector : selectors) { | ||
acceptedClassesHash.add(selector.getSelectedClass()); // merge equal entries | ||
} | ||
} | ||
return acceptedClassesHash; | ||
} | ||
|
||
@Override | ||
public boolean canTake(Queue.BuildableItem item) { | ||
return getAcceptedJobClasses().contains(item.task.getClass().getName()); | ||
} | ||
|
||
@Override | ||
public boolean canTake(Run run) { | ||
return getAcceptedJobClasses().contains(run.getParent().getClass().getName()); | ||
} | ||
|
||
@Extension | ||
public static class DescriptorImpl extends JobRestrictionDescriptor { | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return Messages.restrictions_Job_JobClassNameRestriction_displayName(); | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/util/ClassSelector.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,101 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2016 Oleg Nenashev | ||
* | ||
* 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. | ||
*/ | ||
package com.synopsys.arc.jenkinsci.plugins.jobrestrictions.util; | ||
|
||
import hudson.Extension; | ||
import hudson.Util; | ||
import hudson.model.Describable; | ||
import hudson.model.Descriptor; | ||
import hudson.util.FormValidation; | ||
import java.io.Serializable; | ||
import javax.annotation.CheckForNull; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.QueryParameter; | ||
|
||
/** | ||
* Describable Item, which allows to select class. | ||
* Class existence is being verified. | ||
* @since TODO | ||
*/ | ||
public class ClassSelector implements Describable<ClassSelector>, Serializable { | ||
|
||
/**ID of the user*/ | ||
final @CheckForNull String selectedClass; | ||
|
||
@DataBoundConstructor | ||
public ClassSelector(@CheckForNull String selectedClass) { | ||
this.selectedClass = hudson.Util.fixEmptyAndTrim(selectedClass); | ||
} | ||
|
||
@CheckForNull | ||
public String getSelectedClass() { | ||
return selectedClass; | ||
} | ||
|
||
@Override | ||
public Descriptor<ClassSelector> getDescriptor() { | ||
return DESCRIPTOR; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof ClassSelector) { | ||
ClassSelector cmp = (ClassSelector)obj; | ||
return selectedClass != null ? selectedClass.equals(cmp.selectedClass) : cmp.selectedClass == null; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hash = 7; | ||
hash = 17 * hash + (selectedClass != null ? selectedClass.hashCode() : 0); | ||
return hash; | ||
} | ||
|
||
@Extension | ||
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl(); | ||
public static class DescriptorImpl extends Descriptor<ClassSelector> { | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "N/A"; | ||
} | ||
|
||
public FormValidation doCheckSelectedClass(final @QueryParameter String selectedClass) { | ||
String _selectedClass = Util.fixEmptyAndTrim(selectedClass); | ||
if (_selectedClass == null) { | ||
return FormValidation.error("Field is empty"); | ||
} | ||
|
||
try { | ||
Class.forName(selectedClass); | ||
} catch (Exception ex) { | ||
return FormValidation.warning("Class " + _selectedClass + " cannot be resolved: " + ex.toString()); | ||
} | ||
|
||
return FormValidation.ok(); | ||
} | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
...c/jenkinsci/plugins/jobrestrictions/restrictions/job/JobClassNameRestriction/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,32 @@ | ||
<!-- | ||
* The MIT License | ||
* | ||
* Copyright 2016 Oleg Nenashev | ||
* | ||
* 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" xmlns:d="jelly:define" | ||
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" | ||
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project"> | ||
|
||
<f:entry title="${%Job Classes}"> | ||
<f:repeatableProperty field="jobClasses" add="${%Add job class}"/> | ||
</f:entry> | ||
</j:jelly> |
3 changes: 3 additions & 0 deletions
3
...kinsci/plugins/jobrestrictions/restrictions/job/JobClassNameRestriction/config.properties
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,3 @@ | ||
usersList=Users list | ||
checkUpstreamProjects=Accept upstream runs started by users above | ||
acceptAnonymousUsers=Accept runs started by anonymous users |
36 changes: 36 additions & 0 deletions
36
...ources/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/util/ClassSelector/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,36 @@ | ||
<!-- | ||
* The MIT License | ||
* | ||
* Copyright 2016 Oleg Nenashev | ||
* | ||
* 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" xmlns:d="jelly:define" | ||
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" | ||
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project"> | ||
<f:entry title="${%Class name}" field="selectedClass"> | ||
<f:textbox/> | ||
</f:entry> | ||
<f:entry title=""> | ||
<div align="right"> | ||
<f:repeatableDeleteButton /> | ||
</div> | ||
</f:entry> | ||
</j:jelly> |
3 changes: 3 additions & 0 deletions
3
...synopsys/arc/jenkinsci/plugins/jobrestrictions/util/ClassSelector/help-selectedClass.html
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,3 @@ | ||
<div> | ||
Class name to be checked. | ||
</div> |