Skip to content

Commit

Permalink
app: The cli-usage.yml now is in the jar #TASK-5055
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfeSanahuja committed Oct 31, 2023
1 parent 769f964 commit 8e2d0e9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
14 changes: 11 additions & 3 deletions opencga-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,21 @@
<sourceDirectory>src/main/java</sourceDirectory>

<resources>
<!-- <resource>-->
<!-- <directory>src/main/resources</directory>-->
<!-- <filtering>true</filtering>-->
<!-- <targetPath>${project.basedir}/target/clients/R</targetPath>-->
<!-- <includes>-->
<!-- <include>compileR.sh</include>-->
<!-- </includes>-->
<!-- </resource>-->
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<targetPath>${project.basedir}/target/clients/R</targetPath>
<includes>
<include>compileR.sh</include>
<include>cli-usage.yml</include>
</includes>
<targetPath>${project.basedir}/target/classes</targetPath>
</resource>
<resource>
<directory>app/cloud/docker/compose</directory>
Expand Down Expand Up @@ -346,7 +354,7 @@
<arg value="${project.basedir}/../opencga-core/target/classes/log4j2.internal.xml"/>
<arg value="${project.basedir}/../opencga-storage/opencga-storage-core/target/classes/storage-configuration.yml"/>
<arg value="${project.basedir}/../opencga-client/target/classes/client-configuration.yml"/>
<arg value="${project.basedir}/src/main/resources/usage.yml"/>
<!-- <arg value="${project.basedir}/src/main/resources/usage.yml"/>-->
<arg value="${build.dir}/conf"/>
</exec>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

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;

public class CliConfiguration {

Expand All @@ -23,7 +25,7 @@ public class CliConfiguration {
/**
* FILENAME is the file location of the configuration yml file
*/
public static final String CLI_USAGE_FILENAME = "cli-usage.yml";
private String cliUsageFileName = "cli-usage.yml";

/**
* LOGGER is an instance of the Logger class so that we can do proper
Expand All @@ -38,12 +40,10 @@ public static CliConfiguration getInstance() {
return CliConfiguration.instance;
}

private static CliUsage loadConfiguration() throws IOException {
private CliUsage loadConfiguration() throws IOException {
// Loading the YAML file from the /conf folder
String appHome = System.getProperty("app.home", System.getenv("OPENCGA_HOME"));
String conf = appHome + "/conf";
File file = new File(conf + File.separator + CLI_USAGE_FILENAME);

File file = new File(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());
Expand All @@ -53,18 +53,27 @@ private static CliUsage loadConfiguration() throws IOException {
/*
* We keep an instance of cliUsage for the Shell
*/
public static CliUsage getUsage() {
public CliUsage getUsage() {
if (cliUsage == null) {
try {
cliUsage = loadConfiguration();
} catch (IOException e) {
logger.error("Loading CLI configuration from: " + CLI_USAGE_FILENAME + " Failed");
logger.error("Loading CLI configuration from: " + cliUsageFileName + " Failed");
System.err.println("Loading CLI configuration from: " + cliUsageFileName + " Failed");
}
}
return cliUsage;
}

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

public String getCliUsageFileName() {
return cliUsageFileName;
}

public void setCliUsageFileName(String cliUsageFileName) {
this.cliUsageFileName = cliUsageFileName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private String getPrefix() {
*/
@Override
protected void printMainUsage() {
CliUsage cliUsage = CliConfiguration.getUsage();
CliUsage cliUsage = CliConfiguration.getInstance().getUsage();
CliCategory[] categories = cliUsage.getCategories();
for (CliCategory cliCategory : categories) {
String[] options = cliCategory.getOptions();
Expand Down

0 comments on commit 8e2d0e9

Please sign in to comment.