Skip to content

Commit

Permalink
Cleanup IOException handling
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo committed Dec 18, 2024
1 parent 7a40047 commit 860dbb8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Stub
*/
public class MavenProjectBasicStub extends MavenProject {
public class MavenProjectBasicStub extends MavenPreroject {
protected String identifier;

protected String testRootDir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,8 @@ public Build getBuild() {
}

/**
* returns true if the path is relative
* and false if absolute
* also returns false if it is relative to
* the parent
*
* @param path
* @return
* Returns true if the path is relative and false if absolute.
* Also returns false if it is relative to the parent
*/
private boolean isValidPath(String path) {
boolean bRetVal = true;
Expand Down Expand Up @@ -196,10 +191,8 @@ public void setupBuildEnvironment() throws Exception {
}

private void createDirectories(String parent, String testparent) {
File currentDirectory;

for (String aDirectoryList : directoryList) {
currentDirectory = new File(parent, "/" + aDirectoryList);
File currentDirectory = new File(parent, "/" + aDirectoryList);

if (!currentDirectory.exists()) {
currentDirectory.mkdirs();
Expand Down Expand Up @@ -235,17 +228,15 @@ private List<String> getList(int type) {
return retVal;
}

private void createFiles(String parent, int type) {
File currentFile;
private void createFiles(String parent, int type) throws IOException {
List<String> list = getList(type);

// guard
if (list == null) {
return;
}

for (String aList : list) {
currentFile = new File(parent, aList);
File currentFile = new File(parent, aList);

// create the necessary parent directories
// before we create the files
Expand All @@ -254,41 +245,31 @@ private void createFiles(String parent, int type) {
}

if (!currentFile.exists()) {
try {
currentFile.createNewFile();
populateFile(currentFile, RESOURCES_FILE);
} catch (IOException io) {
// TODO: handle exception
}
currentFile.createNewFile();
populateFile(currentFile, RESOURCES_FILE);
}
}
}

private void setupRootFiles() {
private void setupRootFiles() throws IOException {
createFiles(testRootDir, ROOT_FILE);
}

private void setupTargetFiles() {
private void setupTargetFiles() throws IOException {
createFiles(getOutputDirectory(), OUTPUT_FILE);
}

private void createFiles(String parent, String testparent) {
private void createFiles(String parent, String testparent) throws IOException {
createFiles(parent, RESOURCES_FILE);
createFiles(testparent, RESOURCES_FILE);
}

private void populateFile(File file, int type) {
FileOutputStream outputStream;
private void populateFile(File file, int type) throws IOException {
String data = dataMap.get(file.getName());

if ((data != null) && file.exists()) {
try {
outputStream = new FileOutputStream(file);
try (FileOutputStream outputStream = new FileOutputStream(file)) {
outputStream.write(data.getBytes());
outputStream.flush();
outputStream.close();
} catch (IOException ex) {
// TODO: handle exception here
}
}
}
Expand Down

0 comments on commit 860dbb8

Please sign in to comment.