Skip to content

Commit

Permalink
Merge pull request jenkinsci#193 from jglick/saveProgram-JENKINS-29656
Browse files Browse the repository at this point in the history
[JENKINS-29656] Diagnostics
  • Loading branch information
jglick committed Sep 15, 2015
2 parents b557c21 + a0d7302 commit feb5bf4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;
import java.util.Map;
import java.util.NavigableMap;
Expand All @@ -55,6 +57,7 @@
import java.util.logging.Logger;

import static java.util.logging.Level.*;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
import static org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.*;
import static org.jenkinsci.plugins.workflow.cps.persistence.PersistenceContext.*;

Expand Down Expand Up @@ -345,9 +348,14 @@ public void saveProgram(File f) throws IOException {
} finally {
w.close();
}
Util.deleteFile(f);
if (!tmpFile.renameTo(f)) {
throw new IOException("rename " + tmpFile + " to " + f + " failed");
try {
Class.forName("java.nio.file.Files");
rename(tmpFile, f);
} catch (ClassNotFoundException x) { // Java 6
Util.deleteFile(f);
if (!tmpFile.renameTo(f)) {
throw new IOException("rename " + tmpFile + " to " + f + " failed");
}
}
LOGGER.log(FINE, "program state saved");
} catch (RuntimeException e) {
Expand All @@ -363,6 +371,10 @@ public void saveProgram(File f) throws IOException {
Util.deleteFile(tmpFile);
}
}
@IgnoreJRERequirement
private static void rename(File from, File to) throws IOException {
Files.move(from.toPath(), to.toPath(), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
}

/**
* Propagates the failure to the workflow by passing an exception
Expand Down
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.13</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<id>check</id>
</execution>
</executions>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java16</artifactId>
</signature>
</configuration>
</plugin>
<plugin>
<!-- why is this necessary!? -->
<!-- fix attempted at https://github.com/jenkinsci/jenkins/commit/101507f49873de0239ccb7839649ea71187712b2 but apparently failed. -->
Expand Down

0 comments on commit feb5bf4

Please sign in to comment.