Skip to content
Permalink
Browse files

o JENKINS-10994: more fixes for environment var support. not yet test…

…ed extensively

git-svn-id: https://svn.jenkins-ci.org/trunk/hudson/plugins/thinBackup@40133 71c3de6d-444a-0410-be80-ed276b4c234a
  • Loading branch information...
msteinkogler committed Nov 22, 2011
1 parent 2eb9740 commit f8925dc0f312e0bd23768162fa639029604e4a6b
@@ -44,6 +44,7 @@
public class ThinBackupMgmtLink extends ManagementLink {
private static final Logger LOGGER = Logger.getLogger("hudson.plugins.thinbackup");

@Override
public String getDisplayName() {
return "ThinBackup";
}
@@ -70,7 +71,7 @@ public void doBackupManual(final StaplerRequest res, final StaplerResponse rsp)

final ThinBackupPeriodicWork manualBackupWorker = new ThinBackupPeriodicWork() {
@Override
protected void execute(final TaskListener arg0) throws IOException, InterruptedException {
protected void execute(final TaskListener arg0) {
backupNow(BackupType.FULL);
}
};
@@ -160,4 +161,5 @@ public ThinBackupPluginImpl getConfiguration() {
final ThinBackupPluginImpl plugin = ThinBackupPluginImpl.getInstance();
return Utils.getBackupsAsDates(new File(plugin.getExpandedBackupPath()));
}
}

}
@@ -57,7 +57,7 @@ public long getRecurrencePeriod() {
}

@Override
protected void execute(final TaskListener arg0) throws IOException, InterruptedException {
protected void execute(final TaskListener arg0) {
final long currentTime = System.currentTimeMillis();
final String fullCron = plugin.getFullBackupSchedule();
final String diffCron = plugin.getDiffBackupSchedule();
@@ -22,6 +22,7 @@
import hudson.util.FormValidation;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@@ -106,7 +107,16 @@ public String getBackupPath() {
* @return the backup path with possibly contained environment variables expanded.
*/
public String getExpandedBackupPath() {
return Utils.expandEnvironmentVariables(backupPath);
String expandedPath = "";

try {
expandedPath = Utils.expandEnvironmentVariables(backupPath);
} catch (final EnvironmentVariableNotDefinedException evnde) {
LOGGER.log(Level.SEVERE, "Error while expanding path. Using unexpanded path.", evnde);
expandedPath = backupPath;
}

return expandedPath;
}

public void setNrMaxStoredFull(final int nrMaxStoredFull) {
@@ -419,6 +419,7 @@ private String getFormattedLatestDiffBackupDate() {
* @return -1 if this BackupSet's full backup date is before the other's, 0 if they are equal, 1 if is after the
* other's.
*/
@Override
public int compareTo(final BackupSet other) {
final String otherFullBackupName = other.getFullBackupName();
if ((other == this) || ((fullBackupName == null) && (otherFullBackupName == null))) {
@@ -33,6 +33,7 @@ public void addToZip(final File directory) throws IOException {
walk(directory, null);
}

@Override
public void close() throws IOException {
zipStream.close();
}
@@ -36,7 +36,7 @@ public void removeEmptyDirectories(final File rootDir) throws IOException {

@Override
protected void handleDirectoryEnd(final File directory, final int depth,
@SuppressWarnings("rawtypes") final Collection results) throws IOException {
@SuppressWarnings("rawtypes") final Collection results) {
if (directory.list().length == 0) {
directory.delete();
}
@@ -381,6 +381,7 @@ private Date getLatestFullBackupDate() {

return result;
}

}

/**
@@ -63,6 +63,7 @@ public void load() throws IOException {
* @param other
* @return -1 if <i>other</i> is different than <b>this</b>.
*/
@Override
public int compareTo(final PluginList other) {
if (other == null) {
return -1;
@@ -42,6 +42,7 @@ public final void doRun() {
return;
}
thread = new Thread(new Runnable() {
@Override
public void run() {
logger.log(Level.FINEST, "Started " + name);
final long startTime = System.currentTimeMillis();
@@ -86,12 +87,9 @@ protected File getLogFile() {
/**
* Executes the task. Subclasses implement this method and can carry out a long-running task.
*
* @param listener
* Output sent will be reported to the users. (this work is TBD.)
* @throws InterruptedException
* The caller will record the exception and moves on.
* @throws IOException
* The caller will record the exception and moves on.
* @param listener Output sent will be reported to the users. (this work is TBD.)
* @throws InterruptedException The caller will record the exception and moves on.
* @throws IOException The caller will record the exception and moves on.
*/
protected abstract void execute(TaskListener listener) throws IOException, InterruptedException;

@@ -133,37 +133,42 @@ private boolean restoreFromZipFile() throws IOException {
}

private void restore(final File toRestore) throws IOException {
IOFileFilter nextBuildNumberFileFilter = FileFilterUtils.nameFileFilter("nextBuildNumber");
final IOFileFilter nextBuildNumberFileFilter = FileFilterUtils.nameFileFilter("nextBuildNumber");
IOFileFilter restoreNextBuildNumberFilter;

if (restoreNextBuildNumber) {
restoreNextBuildNumberFilter = FileFilterUtils.trueFileFilter();

Collection<File> restore = FileUtils.listFiles(toRestore, nextBuildNumberFileFilter, TrueFileFilter.INSTANCE);
Map<String, Integer> nextBuildNumbers = new HashMap<String, Integer>();
for (File file : restore) {
final Collection<File> restore = FileUtils.listFiles(toRestore, nextBuildNumberFileFilter,
TrueFileFilter.INSTANCE);
final Map<String, Integer> nextBuildNumbers = new HashMap<String, Integer>();
for (final File file : restore) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
nextBuildNumbers.put(file.getParentFile().getName(), Integer.parseInt(reader.readLine()));
} finally {
if (reader != null)
if (reader != null) {
reader.close();
}
}
}

Collection<File> current = FileUtils.listFiles(hudsonHome, nextBuildNumberFileFilter, TrueFileFilter.INSTANCE);
for (File file : current) {
final Collection<File> current = FileUtils.listFiles(hudsonHome, nextBuildNumberFileFilter,
TrueFileFilter.INSTANCE);
for (final File file : current) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
int currentBuildNumber = Integer.parseInt(reader.readLine());
Integer toRestoreNextBuildNumber = nextBuildNumbers.get(file.getParentFile().getName());
if (currentBuildNumber < toRestoreNextBuildNumber)
final int currentBuildNumber = Integer.parseInt(reader.readLine());
final Integer toRestoreNextBuildNumber = nextBuildNumbers.get(file.getParentFile().getName());
if (currentBuildNumber < toRestoreNextBuildNumber) {
restoreNextBuildNumber(file, toRestoreNextBuildNumber);
}
} finally {
if (reader != null)
if (reader != null) {
reader.close();
}
}
}
} else {
@@ -173,16 +178,18 @@ private void restore(final File toRestore) throws IOException {
FileUtils.copyDirectory(toRestore, this.hudsonHome, restoreNextBuildNumberFilter, true);
}

private void restoreNextBuildNumber(File file, Integer toRestoreNextBuildNumber) throws IOException {
private void restoreNextBuildNumber(final File file, final Integer toRestoreNextBuildNumber) throws IOException {
file.delete();
file.createNewFile();
Writer writer = null;
try {
writer = new FileWriter(file);
writer.write(toRestoreNextBuildNumber);
} finally {
if (writer != null)
if (writer != null) {
writer.close();
}
}
}

}

0 comments on commit f8925dc

Please sign in to comment.
You can’t perform that action at this time.