Skip to content

Commit 8cb8be8

Browse files
committed
Add version command
1 parent 2a467f1 commit 8cb8be8

File tree

9 files changed

+152
-2
lines changed

9 files changed

+152
-2
lines changed

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ $GRAALVM_HOME/bin/native-image --verbose \
44
-H:ReflectionConfigurationFiles=src/config/config_geom.json \
55
-H:ReflectionConfigurationFiles=src/config/config_args4j.json \
66
-H:IncludeResources=META-INF/services/*.* \
7+
-H:IncludeResources=application.properties \
78
-H:IncludeResourceBundles=org.kohsuke.args4j.Messages \
89
-H:IncludeResourceBundles=org.kohsuke.args4j.spi.Messages \
910
-H:+JNI \

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
</dependency>
3636
</dependencies>
3737
<build>
38+
<resources>
39+
<resource>
40+
<directory>src/main/resources</directory>
41+
<filtering>true</filtering>
42+
</resource>
43+
</resources>
3844
<plugins>
3945
<plugin>
4046
<groupId>org.apache.maven.plugins</groupId>

src/config/config_geom.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@
1717
"allPublicFields": true,
1818
"allDeclaredFields": true
1919
},
20+
{
21+
"name": "org.geometrycommands.VersionCommand",
22+
"allDeclaredConstructors": true,
23+
"allPublicConstructors": true,
24+
"allDeclaredMethods": true,
25+
"allPublicMethods": true,
26+
"allPublicFields": true,
27+
"allDeclaredFields": true
28+
},
29+
{
30+
"name": "org.geometrycommands.VersionCommand$VersionOptions",
31+
"allDeclaredConstructors": true,
32+
"allPublicConstructors": true,
33+
"allDeclaredMethods": true,
34+
"allPublicMethods": true,
35+
"allPublicFields": true,
36+
"allDeclaredFields": true
37+
},
2038
{
2139
"name": "org.geometrycommands.ListCommand",
2240
"allDeclaredConstructors": true,
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.geometrycommands;
2+
3+
import org.geometrycommands.VersionCommand.VersionOptions;
4+
5+
import java.io.InputStream;
6+
import java.io.Reader;
7+
import java.io.Writer;
8+
import java.util.Properties;
9+
10+
public class VersionCommand implements Command<VersionOptions> {
11+
12+
13+
/**
14+
* Get the Command's name
15+
*
16+
* @return The Command's name
17+
*/
18+
@Override
19+
public String getName() {
20+
return "version";
21+
}
22+
23+
/**
24+
* Get the description of what the Command does
25+
*
26+
* @return The description of what the Command does
27+
*/
28+
@Override
29+
public String getDescription() {
30+
return "Get the version";
31+
}
32+
33+
/**
34+
* Get a new Options
35+
*
36+
* @return A new Options
37+
*/
38+
@Override
39+
public VersionOptions getOptions() {
40+
return new VersionOptions();
41+
}
42+
43+
/**
44+
* Execute this Command with the given Options
45+
*
46+
* @param options The Options
47+
* @param reader The java.io.Reader
48+
* @param writer The java.io.Writer
49+
* @throws Exception if an error occurs
50+
*/
51+
@Override
52+
public void execute(VersionOptions options, Reader reader, Writer writer) throws Exception {
53+
try(InputStream inputStream = VersionCommand.class.getClassLoader().getResourceAsStream("application.properties")) {
54+
Properties properties = new Properties();
55+
properties.load(inputStream);
56+
writer.write(properties.getProperty("version"));
57+
}
58+
}
59+
60+
public static class VersionOptions extends Options {
61+
}
62+
63+
}

src/main/resources/META-INF/services/org.geometrycommands.Command

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,5 @@ org.geometrycommands.ToWkbCommand
9595
org.geometrycommands.TranslateCommand
9696
org.geometrycommands.UnionCommand
9797
org.geometrycommands.VoronoiDiagramCommand
98-
org.geometrycommands.WithinCommand
98+
org.geometrycommands.WithinCommand
99+
org.geometrycommands.VersionCommand
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version=${project.version}

src/man/geom-version.1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.TH "geom-version" "1" "4 May 2012" "version 0.1"
2+
.SH NAME
3+
geom version
4+
.SH DESCRIPTION
5+
Get the version
6+
.SH USAGE
7+
geom version
8+
.SH OPTIONS
9+
--help : Print help message
10+
.PP
11+
--web-help : Open help in a web browser
12+
.PP

src/shell/geom_bash_comp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ _geom()
55
local line=${COMP_LINE}
66
COMPREPLY=()
77
if [[ "$line" == *"geom " ]]; then
8-
COMPREPLY=($(compgen -W 'angle arc arcpoly area asciiart boundary buffer centroid closelinestring combine contains convexHull coordinates count countpoints coveredby covers crosses delaunay densify difference dimension disjoint distance distanceline draw drawbase64 dump ellipse endpoint envelope equals fromwkb get grid hausdorffdistance interiorpoint interpolatepoint intersection intersects isccw isclosed isempty isrectangle isring issimple isvalid iswithindistance kochsnowflake linedissolve linemerge list locatepoint mincircle minclearance mindiameter minrect narrow nearestpoints node normalize octagonalenvelope overlaps placepoint pointatangle polygonize project random randomwalk rectangle reduceprecision reflect relate reverse rotate scale shear sierpinskicarpet similarity simplify sinestar slice snap split spoke squircle startpoint subline supercircle symdifference text touches towkb translate type union voronoi within' -- $cur))
8+
COMPREPLY=($(compgen -W 'angle arc arcpoly area asciiart boundary buffer centroid closelinestring combine contains convexHull coordinates count countpoints coveredby covers crosses delaunay densify difference dimension disjoint distance distanceline draw drawbase64 dump ellipse endpoint envelope equals fromwkb get grid hausdorffdistance interiorpoint interpolatepoint intersection intersects isccw isclosed isempty isrectangle isring issimple isvalid iswithindistance kochsnowflake linedissolve linemerge list locatepoint mincircle minclearance mindiameter minrect narrow nearestpoints node normalize octagonalenvelope overlaps placepoint pointatangle polygonize project random randomwalk rectangle reduceprecision reflect relate reverse rotate scale shear sierpinskicarpet similarity simplify sinestar slice snap split spoke squircle startpoint subline supercircle symdifference text touches towkb translate type union version voronoi within' -- $cur))
99
elif [[ "$line" == *"geom angle "* ]]; then
1010
COMPREPLY=($(compgen -W '--help --web-help -g --geometry -o --otherGeometry -t --type' -- $cur))
1111
elif [[ "$line" == *"geom arc "* ]]; then
@@ -198,6 +198,8 @@ _geom()
198198
COMPREPLY=($(compgen -W '--help --web-help -g --geometry' -- $cur))
199199
elif [[ "$line" == *"geom union "* ]]; then
200200
COMPREPLY=($(compgen -W '--help --web-help -g --geometry -o --otherGeometry' -- $cur))
201+
elif [[ "$line" == *"geom version "* ]]; then
202+
COMPREPLY=($(compgen -W '--help --web-help' -- $cur))
201203
elif [[ "$line" == *"geom voronoi "* ]]; then
202204
COMPREPLY=($(compgen -W '--help --web-help -g --geometry' -- $cur))
203205
elif [[ "$line" == *"geom within "* ]]; then
@@ -492,6 +494,9 @@ _geom()
492494
if [[ "union" == "$nm"* ]]; then
493495
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'union'))
494496
fi
497+
if [[ "version" == "$nm"* ]]; then
498+
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'version'))
499+
fi
495500
if [[ "voronoi" == "$nm"* ]]; then
496501
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'voronoi'))
497502
fi
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.geometrycommands;
2+
3+
import org.junit.Test;
4+
5+
import java.io.*;
6+
import java.util.Properties;
7+
8+
import org.geometrycommands.VersionCommand.VersionOptions;
9+
10+
import static org.junit.Assert.assertEquals;
11+
12+
public class VersionCommandTest extends BaseTest {
13+
14+
@Test
15+
public void execute() throws Exception {
16+
VersionOptions options = new VersionOptions();
17+
Reader reader = new StringReader("");
18+
StringWriter writer = new StringWriter();
19+
20+
VersionCommand command = new VersionCommand();
21+
command.execute(options, reader, writer);
22+
assertEquals(getExpectedVersion(), writer.getBuffer().toString());
23+
}
24+
25+
@Test
26+
public void run() throws Exception {
27+
String result = runApp(new String[]{
28+
"Version"
29+
}, null);
30+
assertEquals(getExpectedVersion(), result);
31+
}
32+
33+
private String getExpectedVersion() throws IOException {
34+
String expectedVersion = null;
35+
try(InputStream inputStream = VersionCommand.class.getClassLoader().getResourceAsStream("application.properties")) {
36+
Properties properties = new Properties();
37+
properties.load(inputStream);
38+
expectedVersion = properties.getProperty("version");
39+
}
40+
return expectedVersion;
41+
}
42+
43+
}

0 commit comments

Comments
 (0)