Skip to content

Commit

Permalink
add a none
Browse files Browse the repository at this point in the history
  • Loading branch information
drdamour committed Mar 1, 2019
1 parent 88b79f4 commit 0851ee3
Show file tree
Hide file tree
Showing 8 changed files with 380 additions and 2 deletions.
@@ -0,0 +1,144 @@
/*
* The MIT License
*
* Copyright (c) 2018-2019, Bodybuilding.com, CloudBees, Inc.
*
* 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 jenkins.branch.buildstrategies.basic;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.Util;
import jenkins.branch.BranchBuildStrategy;
import jenkins.branch.BranchBuildStrategyDescriptor;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

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

/**
* A {@link BranchBuildStrategy} that builds branches based on the results of all sub strategy NOT matching.
*
* @since 1.0.1
*/
public class NoneBranchBuildStrategyImpl extends BranchBuildStrategy {

/**
* The list of sub strategies.
*/
@NonNull
private final List<BranchBuildStrategy> strategies;

/**
* Our constructor.
* @param strategies the strategies to apply.
*/
@DataBoundConstructor
public NoneBranchBuildStrategyImpl(List<BranchBuildStrategy> strategies) {
this.strategies = new ArrayList<>(Util.fixNull(strategies));
}

/**
* {@inheritDoc}
*/
@Override
public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision,
SCMRevision prevRevision) {

if(strategies.isEmpty()){
return false;
}

for (BranchBuildStrategy strategy: strategies) {
if(strategy.isAutomaticBuild(
source,
head,
currRevision,
prevRevision
)){
return false;
};

}
return true;
}

@NonNull
public List<BranchBuildStrategy> getStrategies() {
return Collections.unmodifiableList(strategies);
}

/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

NoneBranchBuildStrategyImpl that = (NoneBranchBuildStrategyImpl) o;

return strategies.equals(that.strategies);
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return strategies.hashCode();
}

@Override
public String toString() {
return "NoneBranchBuildStrategyImpl{" +
"strategies=" + strategies +
'}';
}


/**
* Our descriptor.
*/
@Symbol("buildNoneBranches")
@Extension
public static class DescriptorImpl extends BranchBuildStrategyDescriptor {
/**
* {@inheritDoc}
*/
@NonNull
@Override
public String getDisplayName() {
return Messages.NoneBranchBuildStrategyImpl_displayName();
}
}



}
Expand Up @@ -22,5 +22,5 @@
~ THE SOFTWARE.
-->
<div>
The strategies to check when matching. All must pass for this strategy to match.
The strategies to check when matching. All must match for this strategy to match.
</div>
Expand Up @@ -22,5 +22,5 @@
~ THE SOFTWARE.
-->
<div>
The strategies to check when matching. Any must pass for this strategy to match.
The strategies to check when matching. Any must match for the any strategy to match.
</div>
Expand Up @@ -5,5 +5,6 @@ NamedBranchBuildStrategyImpl.regexDisplayName=Regular expression
NamedBranchBuildStrategyImpl.wildcardDisplayName=Wildcard include/excludes
AllBranchBuildStrategyImpl.displayName=All Strategies Match
AnyBranchBuildStrategyImpl.displayName=Any Strategies Match
NoneBranchBuildStrategyImpl.displayName=None Strategies Match
TagBuildStrategyImpl.displayName=Tags
ChangeRequestBuildStrategyImpl.displayName=Change requests
@@ -0,0 +1,29 @@
<!--
~ The MIT License
~
~ Copyright (c) 2018-2019, Bodybuilding.com, CloudBees, Inc.
~
~ 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:f="/lib/form">
<f:entry field="strategies" title="${%None of}">
<f:repeatableHeteroProperty field="strategies" hasHeader="true"/>
</f:entry>
</j:jelly>
@@ -0,0 +1,26 @@
<!--
~ The MIT License
~
~ Copyright (c) 2018-2019, Bodybuilding.com, CloudBees, Inc.
~
~ 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.
-->
<div>
The strategies to check when matching. All must NOT match for the none strategy to match.
</div>
@@ -0,0 +1,26 @@
<!--
~ The MIT License
~
~ Copyright (c) 2018-2019, Bodybuilding.com, CloudBees, Inc.
~
~ 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.
-->
<div>
Builds branches only if none of the sub strategies match.
</div>

0 comments on commit 0851ee3

Please sign in to comment.