Skip to content

Commit

Permalink
Merge branch 'TASK-4688' into TASK-4688-2.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
j-coll committed Sep 15, 2023
2 parents d65e926 + 9f49693 commit 3fe5d62
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion opencga-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
<arg value="${build.dir}/misc/git"/>
</exec>
<exec executable="cp">
<arg value="${project.basedir}/../opencga-core/target/generated-resources/git.properties"/>
<arg value="${project.basedir}/../opencga-core/target/generated-resources/org/opencb/opencga/core/git.properties"/>
<arg value="${build.dir}/misc/git"/>
</exec>

Expand Down
2 changes: 1 addition & 1 deletion opencga-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<generateGitPropertiesFile>true</generateGitPropertiesFile>

<!-- The path for the to be generated properties file, it's relative to ${project.basedir} -->
<generateGitPropertiesFilename>target/generated-resources/git.properties</generateGitPropertiesFilename>
<generateGitPropertiesFilename>target/generated-resources/org/opencb/opencga/core/git.properties</generateGitPropertiesFilename>
<gitDescribe>
<!-- don't generate the describe property -->
<skip>false</skip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
*/
public class GitRepositoryState {

public static final String DEFAULT_RESOURCE_NAME = "git.properties";
public static final String DEFAULT_RESOURCE_NAME = "org/opencb/opencga/core/git.properties";
private static GitRepositoryState gitRepositoryState;
private static Properties properties;
private static final Logger logger = LoggerFactory.getLogger(GitRepositoryState.class);

private Properties properties;
private String tags; // =${git.tags} // comma separated tag names
private String branch; // =${git.branch}
private String dirty; // =${git.dirty}
Expand All @@ -59,42 +59,43 @@ public class GitRepositoryState {
private String buildVersion; // =${git.build.version}

public static String get(String key) {
if (properties == null) {
getInstance();
}
return properties.getProperty(key);
return getInstance().properties.getProperty(key);
}

public static GitRepositoryState getInstance() {
if (gitRepositoryState == null) {
properties = new Properties();
InputStream stream = null;
try {
stream = GitRepositoryState.class.getClassLoader().getResourceAsStream(DEFAULT_RESOURCE_NAME);
if (stream != null) {
properties.load(stream);
}
} catch (IOException e) {
logger.warn("Error reading " + DEFAULT_RESOURCE_NAME, e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
logger.warn("Error closing stream from " + DEFAULT_RESOURCE_NAME, e);
}
gitRepositoryState = load(DEFAULT_RESOURCE_NAME);
}
return gitRepositoryState;
}

public static GitRepositoryState load(String resourceName) {
Properties properties = new Properties();
InputStream stream = null;
try {
stream = GitRepositoryState.class.getClassLoader().getResourceAsStream(resourceName);
if (stream != null) {
properties.load(stream);
}
} catch (IOException e) {
logger.warn("Error reading " + resourceName, e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
logger.warn("Error closing stream from " + resourceName, e);
}
}

gitRepositoryState = new GitRepositoryState(properties);
}
return gitRepositoryState;
return new GitRepositoryState(properties);
}

GitRepositoryState() {
}

private GitRepositoryState(Properties properties) {
this.properties = properties;
this.tags = properties.getProperty("git.tags");
this.branch = properties.getProperty("git.branch");
this.dirty = properties.getProperty("git.dirty");
Expand Down

0 comments on commit 3fe5d62

Please sign in to comment.