You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2013/09/30 17:21:14 UTC
git commit: MARMOTTA-323 marmotta-maven-plugin has a goal to render
the version-string into the splash image. use
org.apache.marmotta
marmotta-maven-plugin
${marmotta.version}
Updated Branches:
refs/heads/develop 8642282d8 -> b8a907b04
MARMOTTA-323 marmotta-maven-plugin has a goal to render the version-string into the splash image.
use
<plugin>
<groupId>org.apache.marmotta</groupId>
<artifactId>marmotta-maven-plugin</artifactId>
<version>${marmotta.version}</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>createSplash</goal>
</goals>
<configuration>
<input>${resource}/splashscreen.png</input>
<output>${target}/splashscreen.png</output>
<versionString>${project.version}</versionString>
<color>#1d1d1b</color>
<snapshotColor>#f8651d</snapshotColor>
<vAlign>base</vAlign>
<hAlign>right</hAlign>
<xPos>467</xPos>
<yPos>333</yPos>
</configuration>
</execution>
</executions>
</plugin>
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/b8a907b0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/b8a907b0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/b8a907b0
Branch: refs/heads/develop
Commit: b8a907b04ad1690b71fc2dbaa51b04c447b48093
Parents: 8642282
Author: Jakob Frank <ja...@apache.org>
Authored: Mon Sep 30 17:15:35 2013 +0200
Committer: Jakob Frank <ja...@apache.org>
Committed: Mon Sep 30 17:20:40 2013 +0200
----------------------------------------------------------------------
.../marmotta/SplashScreenBuilderMojo.java | 165 +++++++++++++++++++
launchers/marmotta-installer/pom.xml | 24 +++
2 files changed, 189 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/b8a907b0/build/plugins/marmotta-maven-plugin/src/main/java/org/apache/marmotta/maven/plugins/marmotta/SplashScreenBuilderMojo.java
----------------------------------------------------------------------
diff --git a/build/plugins/marmotta-maven-plugin/src/main/java/org/apache/marmotta/maven/plugins/marmotta/SplashScreenBuilderMojo.java b/build/plugins/marmotta-maven-plugin/src/main/java/org/apache/marmotta/maven/plugins/marmotta/SplashScreenBuilderMojo.java
new file mode 100644
index 0000000..bd95971
--- /dev/null
+++ b/build/plugins/marmotta-maven-plugin/src/main/java/org/apache/marmotta/maven/plugins/marmotta/SplashScreenBuilderMojo.java
@@ -0,0 +1,165 @@
+package org.apache.marmotta.maven.plugins.marmotta;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.regex.Pattern;
+
+import javax.imageio.ImageIO;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+/**
+ * Maven Plugin to print the version number on the splash screen.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@Mojo(name="createSplash")
+public class SplashScreenBuilderMojo extends AbstractMojo {
+
+ private static final Pattern SNAPSHOT_PATTERN = Pattern.compile(".*-SNAPSHOT$", Pattern.CASE_INSENSITIVE);
+
+ @Parameter(property="createSplash.input", required=true)
+ private File input;
+
+ @Parameter(property="createSplash.output", required=true)
+ private File output;
+
+ @Parameter(property="createSplash.versionString", required=true)
+ private String versionString;
+
+ @Parameter(property="createSplash.xPos", defaultValue="467")
+ private int xPos;
+
+ @Parameter(property="createSplash.yPos", defaultValue="333")
+ private int yPos;
+
+ @Parameter(property="createSplash.vAlign", defaultValue="base")
+ private String vAlign;
+
+ @Parameter(property="createSplash.hAlign", defaultValue="right")
+ private String hAlign;
+
+ @Parameter(property="createSplash.color", defaultValue="#1d1d1b")
+ private String color;
+
+ @Parameter(property="createSplash.snapshotColor")
+ private String snapshotColor;
+
+ @Parameter(property="createSplash.font", defaultValue="Arial bold 18")
+ private String font;
+
+ public SplashScreenBuilderMojo() {
+ super();
+ }
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ // load the template image
+ BufferedImage splash;
+ try {
+ splash = ImageIO.read(input);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Could not read input file", e);
+ }
+
+ final Graphics2D g = (Graphics2D) splash.getGraphics();
+
+ if (font != null) {
+ // set the font, this will use the default as fallback.
+ g.setFont(Font.decode(font));
+ }
+ // for alignment, we need to do some calculations
+ final FontMetrics fm = g.getFontMetrics();
+
+ // if the position is not set, use the center of the template
+ if (xPos < 0) {
+ xPos = splash.getWidth()/2;
+ }
+ if (yPos < 0) {
+ yPos = splash.getHeight()/2;
+ }
+
+ // adjust print-position based on the alignment (vertical)
+ if ("top".equalsIgnoreCase(vAlign)) {
+ yPos = yPos + fm.getAscent();
+ } else if ("middle".equalsIgnoreCase(vAlign)) {
+ yPos = yPos + (fm.getAscent()/2);
+ } else if ("bottom".equalsIgnoreCase(vAlign)) {
+ yPos = yPos - fm.getDescent();
+ } else if ("base".equalsIgnoreCase(vAlign)) {
+ // nop;
+ // yPos = yPos;
+ } else {
+ getLog().warn(String.format("invalid param value for \"vAlign\": \"%s\", using fallback \"base\"", vAlign));
+ // nop;
+ // yPos = yPos;
+ }
+
+ // adjust print-position based on the alignment (horizontal)
+ final int w = fm.stringWidth(versionString);
+ if ("left".equalsIgnoreCase(hAlign)) {
+ // nop;
+ // xPos = xPos;
+ } else if ("right".equalsIgnoreCase(hAlign)) {
+ xPos = xPos - w;
+ } else if ("center".equalsIgnoreCase(hAlign)) {
+ xPos = xPos - (w/2);
+ } else {
+ getLog().warn(String.format("invalid param value for \"hAlign\": \"%s\", using fallback \"center\"", hAlign));
+ // nop;
+ xPos = xPos - (w/2);
+ }
+
+ // parse the color to print in
+ Color c = getColor(color, Color.BLACK);
+ // if the version string ends with "-SNAPSHOT", we might want to use a different color
+ if (SNAPSHOT_PATTERN.matcher(versionString).matches()) {
+ c = getColor(snapshotColor, c);
+ }
+ g.setColor(c);
+
+ // we want pretty printing...
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+ g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+ g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+
+ // this is where the version is printed!
+ g.drawString(versionString, xPos, yPos);
+
+ // save the resulting splash image.
+ try {
+ final String fName = output.getName();
+ ImageIO.write(splash, fName.substring(fName.lastIndexOf('.') + 1), output);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Could not write output file", e);
+ }
+ }
+
+ private Color getColor(String color, Color fallback) {
+ if (color != null) {
+ if (color.startsWith("#") && color.length() == 7) {
+ return new Color(Integer.parseInt(color.substring(1), 16));
+ } else if (color.length() == 6) {
+ getLog().warn("color should be provided in html notation: '#rrggbb'");
+ return new Color(Integer.parseInt(color, 16));
+ } else {
+ getLog().warn("invalid color definition: '" + color + "'. Using fallback: black");
+ return fallback;
+ }
+ } else {
+ return fallback;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/b8a907b0/launchers/marmotta-installer/pom.xml
----------------------------------------------------------------------
diff --git a/launchers/marmotta-installer/pom.xml b/launchers/marmotta-installer/pom.xml
index d2e7902..7c92676 100644
--- a/launchers/marmotta-installer/pom.xml
+++ b/launchers/marmotta-installer/pom.xml
@@ -145,6 +145,30 @@
</plugin>
<plugin>
<groupId>org.apache.marmotta</groupId>
+ <artifactId>marmotta-maven-plugin</artifactId>
+ <version>${project.version}</version>
+ <executions>
+ <execution>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>createSplash</goal>
+ </goals>
+ <configuration>
+ <input>src/main/resources/images/splashscreen.png</input>
+ <output>${stagingDir}/images/splashscreen.png</output>
+ <versionString>${project.version}</versionString>
+ <color>#1d1d1b</color>
+ <snapshotColor>#f8651d</snapshotColor>
+ <vAlign>base</vAlign>
+ <hAlign>right</hAlign>
+ <xPos>467</xPos>
+ <yPos>333</yPos>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.marmotta</groupId>
<artifactId>refpack-maven-plugin</artifactId>
<version>${project.version}</version>
<configuration>