Skip to content

Commit

Permalink
app: Do not generate a temporary file. #TASK-5055
Browse files Browse the repository at this point in the history
  • Loading branch information
j-coll committed Oct 31, 2023
1 parent ccf0089 commit 35389bf
Showing 1 changed file with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.io.InputStream;
import java.io.UncheckedIOException;

public class CliConfiguration {

Expand All @@ -20,7 +19,7 @@ public class CliConfiguration {
/**
* The instance of Usage that stores the "usage" information
*/
private static CliUsage cliUsage;
private CliUsage cliUsage;

/**
* FILENAME is the file location of the configuration yml file
Expand All @@ -41,15 +40,11 @@ public static CliConfiguration getInstance() {
}

private CliUsage loadConfiguration() throws IOException {
// Loading the YAML file from the /conf folder
File file = new File(FileUtils.getTempDirectory()+File.separator+cliUsageFileName);

FileUtils.copyURLToFile(getClass().getClassLoader().getResource(cliUsageFileName),file);

// Mapping the config from the YAML file to the Configuration class
logger.info("Loading CLI configuration from: " + file.getAbsolutePath());
ObjectMapper yamlObjectMapper = new ObjectMapper(new YAMLFactory());
return yamlObjectMapper.readValue(file, CliUsage.class);
try (InputStream is = getClass().getClassLoader().getResourceAsStream(cliUsageFileName)) {
// Mapping the config from the YAML file to the Configuration class
ObjectMapper yamlObjectMapper = new ObjectMapper(new YAMLFactory());
return yamlObjectMapper.readValue(is, CliUsage.class);
}
}

/*
Expand All @@ -60,15 +55,14 @@ public CliUsage getUsage() {
try {
cliUsage = loadConfiguration();
} catch (IOException e) {
logger.error("Loading CLI configuration from: " + cliUsageFileName + " Failed");
System.err.println("Loading CLI configuration from: " + cliUsageFileName + " Failed");
throw new UncheckedIOException(e);
}
}
return cliUsage;
}

public void setUsage(CliUsage cliUsage) {
CliConfiguration.cliUsage = cliUsage;
this.cliUsage = cliUsage;
}

public String getCliUsageFileName() {
Expand Down

0 comments on commit 35389bf

Please sign in to comment.