Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SECURITY-49] dependency changes needed for the fix.
- Loading branch information
Showing
4 changed files
with
144 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package jenkins.util.io; | ||
|
||
import jenkins.model.Jenkins; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Uses a presence/absence of a file as a persisted boolean storage. | ||
* | ||
* <p> | ||
* This is convenient when you need to store just a few bits of infrequently accessed information | ||
* as you can forget the explicit persistence of it. This class masks I/O problem, so if the persistence | ||
* fails, you'll get no error report. | ||
* | ||
* @author Kohsuke Kawaguchi | ||
* @since 1.498 | ||
*/ | ||
public class FileBoolean { | ||
private final File file; | ||
|
||
public FileBoolean(File file) { | ||
this.file = file; | ||
} | ||
|
||
public FileBoolean(Class owner, String name) { | ||
this(new File(Jenkins.getInstance().getRootDir(),owner.getName().replace('$','.')+'/'+name)); | ||
} | ||
|
||
/** | ||
* Gets the current state. True if the file exists, false if it doesn't. | ||
*/ | ||
public boolean get() { | ||
return file.exists(); | ||
} | ||
|
||
public boolean isOn() { return get(); } | ||
public boolean isOff() { return !get(); } | ||
|
||
public void set(boolean b) { | ||
if (b) on(); else off(); | ||
} | ||
|
||
public void on() { | ||
try { | ||
file.getParentFile().mkdirs(); | ||
new FileOutputStream(file).close(); | ||
} catch (IOException e) { | ||
LOGGER.log(Level.WARNING, "Failed to touch "+file); | ||
} | ||
} | ||
|
||
public void off() { | ||
file.delete(); | ||
} | ||
|
||
private static final Logger LOGGER = Logger.getLogger(FileBoolean.class.getName()); | ||
} |
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
4 changes: 4 additions & 0 deletions
4
core/src/test/resources/jenkins/util/xstream/XStreamDOMTest.data2.xml
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,4 @@ | ||
<foo abc="def"> | ||
<bar></bar> | ||
<zot>abc</zot> | ||
</foo> |