Skip to content

Commit

Permalink
fixed #49 build version is commit id from git
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1380 committed Oct 10, 2017
1 parent c0c912b commit d6befd2
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ www-test/

/src/main/java/META-INF/persistence.xml
/deps/
/buildNumber.properties
38 changes: 38 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<maven>3.2.1</maven>
</prerequisites>

<scm>
<connection>scm:git:https://github.com/billy1380/blogwt.git</connection>
</scm>
<build>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>

Expand All @@ -46,6 +49,25 @@
</resources>

<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>true</doCheck>
<doUpdate>true</doUpdate>
<!-- <shortRevisionLength>5</shortRevisionLength> -->
</configuration>
</plugin>

<plugin>
<!-- Don't deploy gwt-dev jar to GAE -->
<artifactId>maven-clean-plugin</artifactId>
Expand Down Expand Up @@ -90,6 +112,22 @@
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
</manifestEntries>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
Expand Down
21 changes: 15 additions & 6 deletions src/main/java/com/willshex/blogwt/client/part/FooterPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.willshex.blogwt.client.Resources;
import com.willshex.blogwt.client.controller.PropertyController;
import com.willshex.blogwt.client.helper.ApiHelper;
import com.willshex.blogwt.shared.helper.PropertyHelper;

public class FooterPart extends Composite {

Expand All @@ -32,13 +33,13 @@ interface FooterPartUiBinder extends UiBinder<Widget, FooterPart> {}
public interface FooterTemplates extends SafeHtmlTemplates {
FooterTemplates FOOTER_TEMPLATES = GWT.create(FooterTemplates.class);

@Template("Copyright &copy; <a href=\"{0}\" class=\"{4}\" target=\"_blank\" rel=\"noopener\">{1}</a> {2}. All rights reserved - {3}.")
@Template("{5}Copyright &copy; <a href=\"{0}\" class=\"{4}\" target=\"_blank\" rel=\"noopener\">{1}</a> {2}. All rights reserved - {3}.")
SafeHtml copyrightNotice (SafeUri uri, String holder, String years,
String name, String styleNames);
String name, String styleNames, String version);

@Template("Copyright &copy; <a href=\"{0}\">{1}</a> {2}. All rights reserved - {3}.")
@Template("{4}Copyright &copy; <a href=\"{0}\">{1}</a> {2}. All rights reserved - {3}.")
SafeHtml copyrightNoticeInternal (SafeUri uri, String holder,
String years, String name);
String years, String name, String version);
}

@UiField DivElement divCopyright;
Expand All @@ -55,15 +56,23 @@ private FooterPart () {
|| urlAsString.startsWith("#")) {
divCopyright.setInnerSafeHtml(FooterTemplates.FOOTER_TEMPLATES
.copyrightNoticeInternal(url, controller.copyrightHolder(),
years(controller), controller.title()));
years(controller), controller.title(), version()));
} else {
divCopyright.setInnerSafeHtml(FooterTemplates.FOOTER_TEMPLATES
.copyrightNotice(url, controller.copyrightHolder(),
years(controller), controller.title(),
Resources.RES.styles().externalLink()));
Resources.RES.styles().externalLink(), version()));
}
}

private String version () {
return PropertyController.get()
.booleanProperty(PropertyHelper.FOOTER_SHOW_VERSION, false)
? (PropertyController.get()
.stringProperty(PropertyHelper.VERSION) + " - ")
: "";
}

@SuppressWarnings("deprecation")
private String years (PropertyController controller) {
Date started = controller.started();
Expand Down
32 changes: 28 additions & 4 deletions src/main/java/com/willshex/blogwt/server/MainServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import java.io.InputStreamReader;
import java.util.List;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import javax.servlet.ServletException;
Expand Down Expand Up @@ -49,6 +53,9 @@
@WebServlet(name = "Site", urlPatterns = MainServlet.URL)
public class MainServlet extends ContextAwareServlet {

private static final Logger LOG = Logger
.getLogger(MainServlet.class.getName());

public static final String URL = "/";

private static String PAGE_FORMAT = null;
Expand Down Expand Up @@ -224,12 +231,29 @@ private List<Property> appendProperties (StringBuffer scriptVariables) {
List<Property> properties = PropertyServiceProvider.provide()
.getProperties(0, 10000, null, null);

String build = null;
try {
Manifest m = new Manifest(getServletContext()
.getResourceAsStream("/META-INF/MANIFEST.MF"));
Attributes a = m.getMainAttributes();

build = a.getValue("Implementation-Build");
} catch (IOException | NullPointerException e) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Could not retrieve version number", e);
}
}

final String version = build == null ? "none" : build;

properties.add(new Property().name(PropertyHelper.VERSION)
.type("string").value(version));

if (properties.size() >= 0) {
scriptVariables.append("var properties='[")
.append(String.join(", ", properties.stream()
.filter( (property) -> !PropertyHelper
.isSecretProperty(property))
.map( (property) -> jsonForJsVar(slim(property)))
.append(String.join(",", properties.stream()
.filter(p -> !PropertyHelper.isSecretProperty(p))
.map(p -> jsonForJsVar(slim(p)))
.collect(Collectors.toList())))
.append("]';");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class PropertyHelper {

public static final String PASSWORD_HASH_SALT = "setup.password.hash.salt";

public static final String VERSION = "system.version";

// functional properties
public static final String MARKDOWN_MAPS_API_KEY = "markdown.maps.api.key";
public static final String MARKDOWN_PREFETCH_INCLUDES = "markdown.include.prefectch";
Expand Down

0 comments on commit d6befd2

Please sign in to comment.