Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Schüth committed Dec 9, 2019
1 parent f0f94cf commit f865e84
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 0 deletions.
114 changes: 114 additions & 0 deletions cli/pom.xml
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>
37 changes: 37 additions & 0 deletions cli/src/main/java/com/gentics/mesh/cli/MeshCLI.java
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;
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<module>madl</module>
<module>rest-model</module>
<module>api</module>
<module>cli</module>
<module>plugin-api</module>
<module>plugin-bom</module>
<module>plugin-dep</module>
Expand Down

0 comments on commit f865e84

Please sign in to comment.