-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Johannes Schüth
committed
Dec 9, 2019
1 parent
f0f94cf
commit f865e84
Showing
3 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>mesh-cli</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Mesh - CLI</name> | ||
<description>The Gentics Mesh CLI</description> | ||
|
||
<parent> | ||
<groupId>com.gentics.mesh</groupId> | ||
<artifactId>mesh</artifactId> | ||
<version>1.3.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<mainClass>com.gentics.mesh.cli.MeshCLI</mainClass> | ||
<graal.version>19.3.0</graal.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.gentics.mesh</groupId> | ||
<artifactId>mesh-bom</artifactId> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<!-- Mesh --> | ||
<dependency> | ||
<groupId>com.gentics.mesh</groupId> | ||
<artifactId>mesh-rest-client</artifactId> | ||
</dependency> | ||
|
||
<!-- CLI --> | ||
<dependency> | ||
<groupId>info.picocli</groupId> | ||
<artifactId>picocli</artifactId> | ||
<version>4.1.2</version> | ||
</dependency> | ||
|
||
<!-- Test dependencies --> | ||
<dependency> | ||
<groupId>com.gentics.mesh</groupId> | ||
<artifactId>mesh-test-common</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.1.1</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>${mainClass}</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.oracle.substratevm</groupId> | ||
<artifactId>native-image-maven-plugin</artifactId> | ||
<version>${graal.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>native-image</goal> | ||
</goals> | ||
<phase>package</phase> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<imageName>mesh-cli</imageName> | ||
<mainClass>${mainClass}</mainClass> | ||
<buildArgs>--enable-all-security-services | ||
-H:+ReportUnsupportedElementsAtRuntime | ||
-H:+ReportExceptionStackTraces | ||
--no-fallback | ||
-Duser.country=GB | ||
-Duser.language=en | ||
-H:ResourceConfigurationFiles=${basedir}/svm/resources.json | ||
-Dlog4j2.jmx.disable=true | ||
-Dfile.encoding=UTF-8 | ||
-H:+AddAllCharsets | ||
--enable-https | ||
--enable-http | ||
--allow-incomplete-classpath</buildArgs> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.gentics.mesh.cli; | ||
|
||
import java.io.File; | ||
import java.math.BigInteger; | ||
import java.nio.file.Files; | ||
import java.security.MessageDigest; | ||
import java.util.concurrent.Callable; | ||
|
||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
import picocli.CommandLine.Parameters; | ||
|
||
@Command(name = "checksum", mixinStandardHelpOptions = true, version = "checksum 4.0", description = "Prints the checksum (MD5 by default) of a file to STDOUT.") | ||
public class MeshCLI implements Callable<Integer> { | ||
|
||
@Parameters(index = "0", description = "The file whose checksum to calculate.") | ||
private File file; | ||
|
||
@Option(names = { "-a", "--algorithm" }, description = "MD5, SHA-1, SHA-256, ...") | ||
private String algorithm = "MD5"; | ||
|
||
// this example implements Callable, so parsing, error handling and handling user | ||
// requests for usage help or version help can be done with one line of code. | ||
public static void main(String... args) { | ||
int exitCode = new CommandLine(new MeshCLI()).execute(args); | ||
System.exit(exitCode); | ||
} | ||
|
||
@Override | ||
public Integer call() throws Exception { // your business logic goes here... | ||
byte[] fileContents = Files.readAllBytes(file.toPath()); | ||
byte[] digest = MessageDigest.getInstance(algorithm).digest(fileContents); | ||
System.out.printf("%0" + (digest.length * 2) + "x%n", new BigInteger(1, digest)); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters