Index: src/main/java/org/jvnet/hudson/plugins/backup/BackupLink.java =================================================================== --- src/main/java/org/jvnet/hudson/plugins/backup/BackupLink.java (revision 32934) +++ src/main/java/org/jvnet/hudson/plugins/backup/BackupLink.java (working copy) @@ -1,7 +1,7 @@ /* * The MIT License * - * Copyright (c) 2009-2010, Vincent Sellier, Manufacture Française des Pneumatiques Michelin, Romain Seguy + * Copyright (c) 2009-2010, Vincent Sellier, Manufacture Française des Pneumatiques Michelin, Romain Seguy, Jeremy Davidson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -101,6 +101,13 @@ } } + runBackup(); + + // redirect to observation page + rsp.sendRedirect("backup"); + } + + public void runBackup() throws IOException { BackupConfig configuration = getConfiguration(); String fileNameTemplate = configuration.getTargetDirectory() + File.separator + configuration.getFileNameTemplate(); @@ -113,9 +120,6 @@ // Launching the task Thread thread = Executors.defaultThreadFactory().newThread(task); thread.start(); - - // redirect to observation page - rsp.sendRedirect("backup"); } public void doRestoreFile(StaplerRequest res, StaplerResponse rsp, Index: src/main/java/org/jvnet/hudson/plugins/backup/utils/BackupBuilder.java =================================================================== --- src/main/java/org/jvnet/hudson/plugins/backup/utils/BackupBuilder.java (revision 0) +++ src/main/java/org/jvnet/hudson/plugins/backup/utils/BackupBuilder.java (revision 0) @@ -0,0 +1,105 @@ +/* + * The MIT License + * + * Copyright (c) 2010, Jeremy Davidson + * + * 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 org.jvnet.hudson.plugins.backup.utils; + +import hudson.Extension; +import hudson.Launcher; +import hudson.model.AbstractBuild; +import hudson.model.AbstractProject; +import hudson.model.Action; +import hudson.model.BuildListener; +import hudson.model.Descriptor; +import hudson.tasks.Builder; +import hudson.tasks.BuildStep; + +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.sf.json.JSONObject; + +import org.jvnet.hudson.plugins.backup.BackupLink; +import org.kohsuke.stapler.StaplerRequest; + +/** + * + * @author jeremydavidson + */ +@Extension +public class BackupBuilder extends Builder { + + public BackupBuilder() { + } + + @Override + public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException { + BackupBuildStep buildStep = new BackupBuildStep(); + + return buildStep.perform(build, launcher, listener); + } + + @Extension + public static final class BackupBuildStep implements BuildStep { + + public boolean prebuild(AbstractBuild build, BuildListener listener) { + return true; + } + + public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException { + + BackupLink backupLink = new BackupLink(); + try { + backupLink.runBackup(); + listener.getLogger().append("Hudson is backing up its configuration now.\n"); + listener.getLogger().append("Please wait for the shutdown notification to disappear.\n"); + } catch (IOException ex) { + Logger.getLogger(BackupBuilder.class.getName()).log(Level.SEVERE, null, ex); + } + + return true; + } + + public Action getProjectAction(AbstractProject project) { + throw new UnsupportedOperationException("Not supported yet."); + } + } + + @Extension + public static final class DescriptorImpl extends Descriptor { + + public DescriptorImpl() { + super(BackupBuilder.class); + } + + @Override + public Builder newInstance(StaplerRequest req, JSONObject formData) { + return new BackupBuilder(); + } + + public String getDisplayName() { + return "Backup Hudson configuration"; + } + } +} Index: src/main/resources/org/jvnet/hudson/plugins/backup/utils/BackupBuilder/config.jelly =================================================================== --- src/main/resources/org/jvnet/hudson/plugins/backup/utils/BackupBuilder/config.jelly (revision 0) +++ src/main/resources/org/jvnet/hudson/plugins/backup/utils/BackupBuilder/config.jelly (revision 0) @@ -0,0 +1,27 @@ + + + +