Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
-Fixed (RebuildActionFactory): JENKINS-14905 Make "Rebuild" button av…
…ailable for builds before plugin installation time -Fixed in test: JENKINS-14387 Cause of rebuilt job should be Cause.UserIdCause -Added new feature: Rebuild Last on project level (see attached screenshot) -Added HtmlUnit test to validate Rebuild and Rebuild links
- Loading branch information
1 parent
3f147ce
commit da8dc71
Showing
6 changed files
with
205 additions
and
88 deletions.
There are no files selected for viewing
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
src/main/java/com/sonyericsson/rebuild/RebuildActionFactory.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,32 @@ | ||
package com.sonyericsson.rebuild; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static java.util.Collections.singleton; | ||
|
||
import java.util.Collection; | ||
|
||
import hudson.Extension; | ||
import hudson.model.*; | ||
|
||
/** | ||
* Enables rebuild for builds that ran before installing the rebuild plugin. | ||
*/ | ||
@Extension | ||
public class RebuildActionFactory extends TransientBuildActionFactory { | ||
|
||
@Override | ||
public Collection<? extends Action> createFor(Run target) { | ||
AbstractBuild build = (AbstractBuild) target; | ||
boolean hasRebuildAction = target.getAction(RebuildAction.class) != null; | ||
if (hasRebuildAction) { | ||
return emptyList(); | ||
} | ||
for (RebuildValidator rebuildValidator : Hudson.getInstance(). | ||
getExtensionList(RebuildValidator.class)) { | ||
if (rebuildValidator.isApplicable(build)) { | ||
return emptyList(); | ||
} | ||
} | ||
return singleton(new RebuildAction()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/sonyericsson/rebuild/RebuildLastCompletedBuildAction.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,22 @@ | ||
package com.sonyericsson.rebuild; | ||
|
||
/** | ||
* Reschedules last completed build for the project if available. | ||
* Otherwise it behaves as if the user click on the build now button. | ||
*/ | ||
public class RebuildLastCompletedBuildAction extends RebuildAction { | ||
|
||
@Override | ||
public String getUrlName() { | ||
if (getProject() != null && getProject().getLastCompletedBuild() != null && getProject().isBuildable()) { | ||
return getProject().getLastCompletedBuild().getNumber() + "/rebuild"; | ||
} else { | ||
return "build?delay=0sec"; | ||
} | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Rebuild Last"; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/sonyericsson/rebuild/RebuildProjectActionFactory.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,23 @@ | ||
package com.sonyericsson.rebuild; | ||
|
||
import static java.util.Collections.singleton; | ||
|
||
import java.util.Collection; | ||
|
||
import hudson.Extension; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.Action; | ||
import hudson.model.TransientProjectActionFactory; | ||
|
||
/** | ||
* Makes the rebuild button available on the project level. | ||
* Rebuilds the last completed build. | ||
*/ | ||
@Extension | ||
public class RebuildProjectActionFactory extends TransientProjectActionFactory { | ||
|
||
@Override | ||
public Collection<? extends Action> createFor(AbstractProject abstractProject) { | ||
return singleton(new RebuildLastCompletedBuildAction()); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,64 +1,62 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved. | ||
* Copyright 2012 Sony Mobile Communications AB. All rights reservered. | ||
* | ||
* 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.sonyericsson.rebuild; | ||
|
||
import hudson.Extension; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.Hudson; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.model.listeners.RunListener; | ||
|
||
/** | ||
* Runtime Listner class which allows | ||
* the user to rebuild the parameterized | ||
* build. | ||
* @author Shemeer S. | ||
*/ | ||
@Extension | ||
public class Rebuilder extends RunListener<Run> { | ||
|
||
/** | ||
* Rebuilder class constructor. | ||
*/ | ||
public Rebuilder() { | ||
super(Run.class); | ||
} | ||
|
||
@Override | ||
public void onCompleted(Run r, TaskListener listener) { | ||
if (r instanceof AbstractBuild) { | ||
AbstractBuild build = (AbstractBuild)r; | ||
for (RebuildValidator rebuildValidator : Hudson.getInstance(). | ||
getExtensionList(RebuildValidator.class)) { | ||
if (rebuildValidator.isApplicable(build)) { | ||
return; | ||
} | ||
} | ||
RebuildAction rebuildAction = new RebuildAction(); | ||
build.getActions().add(rebuildAction); | ||
} | ||
} | ||
} | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved. | ||
* Copyright 2012 Sony Mobile Communications AB. All rights reservered. | ||
* | ||
* 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.sonyericsson.rebuild; | ||
|
||
|
||
import hudson.Extension; | ||
import hudson.model.*; | ||
import hudson.model.listeners.RunListener; | ||
|
||
/** | ||
* Runtime Listner class which allows the user to rebuild the parameterized build. | ||
* | ||
* @author Shemeer S. | ||
*/ | ||
@Extension | ||
public class Rebuilder extends RunListener<Run> { | ||
|
||
/** | ||
* Rebuilder class constructor. | ||
*/ | ||
public Rebuilder() { | ||
super(Run.class); | ||
} | ||
|
||
@Override | ||
public void onCompleted(Run r, TaskListener listener) { | ||
if (r instanceof AbstractBuild) { | ||
AbstractBuild build = (AbstractBuild) r; | ||
for (RebuildValidator rebuildValidator : Hudson.getInstance(). | ||
getExtensionList(RebuildValidator.class)) { | ||
if (rebuildValidator.isApplicable(build)) { | ||
return; | ||
} | ||
} | ||
RebuildAction rebuildAction = new RebuildAction(); | ||
build.getActions().add(rebuildAction); | ||
} | ||
} | ||
|
||
} |
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