Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from christiangalsterer/master
[JENKINS-11374] - Add deletion option on 'list of Shelved Projects'
- Loading branch information
Showing
5 changed files
with
380 additions
and
3 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/main/java/org/jvnet/hudson/plugins/shelveproject/DeleteProjectExecutable.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,75 @@ | ||
package org.jvnet.hudson.plugins.shelveproject; | ||
|
||
import hudson.model.Hudson; | ||
import hudson.model.Queue; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
import java.io.File; | ||
import java.util.Collection; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class DeleteProjectExecutable | ||
implements Queue.Executable | ||
{ | ||
private final static Logger LOGGER = Logger.getLogger( DeleteProjectExecutable.class.getName() ); | ||
|
||
private final String[] shelvedProjectArchiveNames; | ||
|
||
private final Queue.Task parentTask; | ||
|
||
public DeleteProjectExecutable(Queue.Task parentTask, String[] shelvedProjectArchiveNames) | ||
{ | ||
this.parentTask = parentTask; | ||
this.shelvedProjectArchiveNames = shelvedProjectArchiveNames; | ||
} | ||
|
||
public Queue.Task getParent() | ||
{ | ||
return parentTask; | ||
} | ||
|
||
public void run() | ||
{ | ||
for (String shelvedProjectArchiveName : shelvedProjectArchiveNames) | ||
{ | ||
final File shelvedProjectArchive = getArchiveFile(shelvedProjectArchiveName); | ||
LOGGER.info( "Deleting project [" + shelvedProjectArchiveName + "]." ); | ||
try | ||
{ | ||
shelvedProjectArchive.delete(); | ||
} | ||
catch ( Exception e ) | ||
{ | ||
LOGGER.log( Level.SEVERE, "Could not delete project archive [" + shelvedProjectArchiveName + "].", e ); | ||
} | ||
} | ||
} | ||
|
||
private File getArchiveFile(String shelvedProjectArchiveName) { | ||
// JENKINS-8759 - The archive name comes from the html form, so take a bit extra care for security reasons by | ||
// only accessing the archive if it exists in the directory of shevled projects. | ||
File shelvedProjectsDirectory = new File( Hudson.getInstance().getRootDir(), "shelvedProjects" ); | ||
Collection<File> files = FileUtils.listFiles(shelvedProjectsDirectory, null, false); | ||
for (File file : files) | ||
{ | ||
if (StringUtils.equals(file.getName(), shelvedProjectArchiveName)) | ||
{ | ||
return file; | ||
} | ||
} | ||
return null; // Project was already unshelved? | ||
} | ||
|
||
public long getEstimatedDuration() | ||
{ | ||
return -1; // impossible to estimate duration | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "Deleting Project"; | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
src/main/java/org/jvnet/hudson/plugins/shelveproject/DeleteProjectTask.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,124 @@ | ||
package org.jvnet.hudson.plugins.shelveproject; | ||
|
||
import hudson.model.Label; | ||
import hudson.model.Node; | ||
import hudson.model.Queue; | ||
import hudson.model.ResourceList; | ||
import hudson.model.queue.CauseOfBlockage; | ||
import hudson.model.queue.SubTask; | ||
import hudson.security.ACL; | ||
import org.acegisecurity.Authentication; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
public class DeleteProjectTask | ||
implements Queue.FlyweightTask, Queue.TransientTask | ||
{ | ||
private final String[] shelvedProjectArchiveNames; | ||
|
||
public DeleteProjectTask(String[] shelvedProjectArchiveNames) | ||
{ | ||
this.shelvedProjectArchiveNames = shelvedProjectArchiveNames; | ||
} | ||
|
||
public Label getAssignedLabel() | ||
{ | ||
return null; | ||
} | ||
|
||
public Node getLastBuiltOn() | ||
{ | ||
return null; | ||
} | ||
|
||
public boolean isBuildBlocked() | ||
{ | ||
return false; | ||
} | ||
|
||
public String getWhyBlocked() | ||
{ | ||
return null; | ||
} | ||
|
||
public CauseOfBlockage getCauseOfBlockage() { | ||
return null; | ||
} | ||
|
||
public String getName() | ||
{ | ||
return "Deleting Project"; | ||
} | ||
|
||
public String getFullDisplayName() | ||
{ | ||
return getName(); | ||
} | ||
|
||
public long getEstimatedDuration() | ||
{ | ||
return -1; | ||
} | ||
|
||
public Queue.Executable createExecutable() | ||
throws IOException | ||
{ | ||
return new DeleteProjectExecutable(this, shelvedProjectArchiveNames); | ||
} | ||
|
||
public Queue.Task getOwnerTask() | ||
{ | ||
return this; | ||
} | ||
|
||
public Object getSameNodeConstraint() | ||
{ | ||
return null; | ||
} | ||
|
||
public void checkAbortPermission() | ||
{ | ||
} | ||
|
||
public boolean hasAbortPermission() | ||
{ | ||
return false; | ||
} | ||
|
||
public String getUrl() | ||
{ | ||
return null; | ||
} | ||
|
||
public boolean isConcurrentBuild() | ||
{ | ||
return false; | ||
} | ||
|
||
public Collection<? extends SubTask> getSubTasks() | ||
{ | ||
final List<SubTask> subTasks = new LinkedList<SubTask>(); | ||
subTasks.add(this); | ||
return subTasks; | ||
} | ||
|
||
public ResourceList getResourceList() | ||
{ | ||
return new ResourceList(); | ||
} | ||
|
||
public String getDisplayName() | ||
{ | ||
return getName(); | ||
} | ||
|
||
@Nonnull | ||
public Authentication getDefaultAuthentication() { | ||
return ACL.SYSTEM; | ||
} | ||
|
||
} |
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
Oops, something went wrong.