Commit d0eba7a0 by Tuomas Riihimäki

Fix parsing of git version from package generation

There was already a somewhat broken version of maven
plugin which saves the current git versions from build
time. Fixed it.. :)
1 parent ac295b49
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
<!-- The path for the to be generated properties file, it's relative <!-- The path for the to be generated properties file, it's relative
to ${project.basedir} --> to ${project.basedir} -->
<generateGitPropertiesFilename>src/main/java/moya-git.properties</generateGitPropertiesFilename>
<dotGitDirectory>${project.basedir}/../../.git</dotGitDirectory> <dotGitDirectory>${project.basedir}/../../.git</dotGitDirectory>
</configuration> </configuration>
</plugin> </plugin>
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
*/ */
package fi.codecrew.moya.utilities; package fi.codecrew.moya.utilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Properties; import java.util.Properties;
...@@ -25,100 +28,43 @@ import java.util.Properties; ...@@ -25,100 +28,43 @@ import java.util.Properties;
public class GitRepositoryState { public class GitRepositoryState {
private static GitRepositoryState gitRepositoryState; private static GitRepositoryState gitRepositoryState;
private static final Logger logger = LoggerFactory.getLogger(GitRepositoryState.class);
private final Properties properties;
public static GitRepositoryState getGitRepositoryState() throws IOException public static GitRepositoryState getGitRepositoryState() {
{
if (gitRepositoryState == null) { if (gitRepositoryState == null) {
gitRepositoryState = new GitRepositoryState(); gitRepositoryState = new GitRepositoryState();
} }
return gitRepositoryState; return gitRepositoryState;
} }
private final String branch; private GitRepositoryState() {
private final String describe; logger.info("Initializing git status");
private final String describeShort; this.properties = new Properties();
private final String commitId; try {
private final String buildUserName; InputStream resource = getClass().getResourceAsStream("/git.properties");
private final String buildUserEmail;
private final String buildTime;
private final String commitUserName;
private final String commitUserEmail;
private final String commitMessageShort;
private final String commitMessageFull;
private final String commitTime;
private GitRepositoryState() throws IOException
{
InputStream resource = getClass().getClassLoader().getResourceAsStream("moya-git.properties");
if (resource == null)
{
throw new IOException("ResourceFile not found");
}
Properties properties = new Properties();
properties.load(resource);
this.branch = properties.get("git.branch").toString();
this.describe = properties.get("git.commit.id.describe").toString();
this.describeShort = properties.get("git.commit.id.describe-short").toString();
this.commitId = properties.get("git.commit.id").toString();
this.buildUserName = properties.get("git.build.user.name").toString();
this.buildUserEmail = properties.get("git.build.user.email").toString();
this.buildTime = properties.get("git.build.time").toString();
this.commitUserName = properties.get("git.commit.user.name").toString();
this.commitUserEmail = properties.get("git.commit.user.email").toString();
this.commitMessageShort = properties.get("git.commit.message.short").toString();
this.commitMessageFull = properties.get("git.commit.message.full").toString();
this.commitTime = properties.get("git.commit.time").toString();
}
public String getBranch() {
return branch;
}
public String getDescribe() {
return describe;
}
public String getDescribeShort() {
return describeShort;
}
public String getCommitId() {
return commitId;
}
public String getBuildUserName() { if (resource == null) {
return buildUserName; logger.warn("Resource not found!");
return;
} }
public String getBuildUserEmail() { this.properties.load(resource);
return buildUserEmail; logger.info("Git keys:", this.properties.keys());
} catch (IOException e) {
logger.warn("Error initializing git proerties", e);
} }
public String getBuildTime() {
return buildTime;
} }
public String getCommitUserName() { public String getProperty(String key) {
return commitUserName; String retStr = null;
if (properties != null || key != null) {
Object ret = properties.get(key);
if (ret != null) {
retStr = ret.toString();
} }
public String getCommitUserEmail() {
return commitUserEmail;
} }
return retStr;
public String getCommitMessageShort() {
return commitMessageShort;
}
public String getCommitMessageFull() {
return commitMessageFull;
}
public String getCommitTime() {
return commitTime;
} }
} }
...@@ -14,6 +14,15 @@ ...@@ -14,6 +14,15 @@
<h:commandButton action="#{testView.resetMenu()}" value="Reset to newui menu" onclick="return confirm('THIS WILL RESET ALL MODIFICATIONS TO DEFAULT MENU!!\n Are you really sure?!');" /> <h:commandButton action="#{testView.resetMenu()}" value="Reset to newui menu" onclick="return confirm('THIS WILL RESET ALL MODIFICATIONS TO DEFAULT MENU!!\n Are you really sure?!');" />
<h:commandButton action="#{testView.resetOldMenu()}" value="Reset to old menu" onclick="return confirm('THIS WILL RESET ALL MODIFICATIONS TO DEFAULT MENU!!\n Are you really sure?!');" /> <h:commandButton action="#{testView.resetOldMenu()}" value="Reset to old menu" onclick="return confirm('THIS WILL RESET ALL MODIFICATIONS TO DEFAULT MENU!!\n Are you really sure?!');" />
</h:form> </h:form>
<ul>
<li>Build time #{testView.gitProps.getProperty('git.build.time')}</li>
<li>Build user: #{testView.gitProps.getProperty('git.build.user.name')}</li>
<li>Commit time #{testView.gitProps.getProperty('git.commit.time')}</li>
<li>Git id #{testView.gitProps.getProperty('git.commit.id.abbrev')}</li>
</ul>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
......
...@@ -30,6 +30,7 @@ import javax.enterprise.context.RequestScoped; ...@@ -30,6 +30,7 @@ import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import fi.codecrew.moya.utilities.GitRepositoryState;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -105,6 +106,10 @@ public class TestDataView extends GenericCDIView { ...@@ -105,6 +106,10 @@ public class TestDataView extends GenericCDIView {
return null; return null;
} }
public GitRepositoryState getGitProps() {
return GitRepositoryState.getGitRepositoryState();
}
public void sendMultibuggageSpam() { public void sendMultibuggageSpam() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!