Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use java.nio.file.Files to create tmp directories for test classes #152

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -64,13 +65,7 @@ public static String createTempJsonKeyFile(String clientEmail, PrivateKey privat

private static File getTempFolder() throws IOException {
if (tempFolder == null) {
tempFolder = File.createTempFile("temp", Long.toString(System.nanoTime()));
if (!tempFolder.delete()) {
throw new IOException("Could not delete temp file: " + tempFolder.getAbsolutePath());
}
if (!tempFolder.mkdir()) {
throw new IOException("Could not create temp directory: " + tempFolder.getAbsolutePath());
}
tempFolder = Files.createTempDirectory("temp" + Long.toString(System.nanoTime())).toFile();
tempFolder.deleteOnExit();
}
return tempFolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;

/**
* Util class for {@link com.google.jenkins.plugins.credentials.oauth
Expand Down Expand Up @@ -86,13 +87,7 @@ public static String createTempInvalidLegacyJsonKeyFile() throws IOException {

private static File getTempFolder() throws IOException {
if (tempFolder == null) {
tempFolder = File.createTempFile("temp", Long.toString(System.nanoTime()));
if (!tempFolder.delete()) {
throw new IOException("Could not delete temp file: " + tempFolder.getAbsolutePath());
}
if (!tempFolder.mkdir()) {
throw new IOException("Could not create temp directory: " + tempFolder.getAbsolutePath());
}
tempFolder = Files.createTempDirectory("temp" + Long.toString(System.nanoTime())).toFile();
tempFolder.deleteOnExit();
}
return tempFolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.Files;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
Expand Down Expand Up @@ -64,13 +65,7 @@ public static String createTempP12KeyFile(KeyPair keyPair)

private static File getTempFolder() throws IOException {
if (tempFolder == null) {
tempFolder = File.createTempFile("temp", Long.toString(System.nanoTime()));
if (!tempFolder.delete()) {
throw new IOException("Could not delete temp file: " + tempFolder.getAbsolutePath());
}
if (!tempFolder.mkdir()) {
throw new IOException("Could not create temp directory: " + tempFolder.getAbsolutePath());
}
tempFolder = Files.createTempDirectory("temp" + Long.toString(System.nanoTime())).toFile();
tempFolder.deleteOnExit();
}
return tempFolder;
Expand Down