You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@johnzon.apache.org by rm...@apache.org on 2015/11/09 19:54:12 UTC
incubator-johnzon git commit: JOHNZON-60 sample to java plugin
Repository: incubator-johnzon
Updated Branches:
refs/heads/master 81373d997 -> 3bdbe3996
JOHNZON-60 sample to java plugin
Project: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/commit/3bdbe399
Tree: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/tree/3bdbe399
Diff: http://git-wip-us.apache.org/repos/asf/incubator-johnzon/diff/3bdbe399
Branch: refs/heads/master
Commit: 3bdbe399659ccf40ffa62dfb2441f76e91b72db3
Parents: 81373d9
Author: Romain Manni-Bucau <rm...@gmail.com>
Authored: Mon Nov 9 10:54:00 2015 -0800
Committer: Romain Manni-Bucau <rm...@gmail.com>
Committed: Mon Nov 9 10:54:00 2015 -0800
----------------------------------------------------------------------
johnzon-distribution/pom.xml | 18 +
johnzon-maven-plugin/pom.xml | 93 ++++++
.../maven/plugin/ExampleToModelMojo.java | 330 +++++++++++++++++++
.../maven/plugin/ExampleToModelMojoTest.java | 117 +++++++
.../src/test/resources/SomeValue.java | 249 ++++++++++++++
pom.xml | 1 +
6 files changed, 808 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/3bdbe399/johnzon-distribution/pom.xml
----------------------------------------------------------------------
diff --git a/johnzon-distribution/pom.xml b/johnzon-distribution/pom.xml
index 75a531c..3f2c10f 100644
--- a/johnzon-distribution/pom.xml
+++ b/johnzon-distribution/pom.xml
@@ -121,6 +121,24 @@
<version>${project.version}</version>
<classifier>javadoc</classifier>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.johnzon</groupId>
+ <artifactId>johnzon-maven-plugin</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.johnzon</groupId>
+ <artifactId>johnzon-maven-plugin</artifactId>
+ <version>${project.version}</version>
+ <classifier>sources</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.johnzon</groupId>
+ <artifactId>johnzon-maven-plugin</artifactId>
+ <version>${project.version}</version>
+ <classifier>javadoc</classifier>
+ </dependency>
</dependencies>
<build>
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/3bdbe399/johnzon-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/johnzon-maven-plugin/pom.xml b/johnzon-maven-plugin/pom.xml
new file mode 100644
index 0000000..edb8d92
--- /dev/null
+++ b/johnzon-maven-plugin/pom.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>johnzon</artifactId>
+ <groupId>org.apache.johnzon</groupId>
+ <version>0.9.3-incubating-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>johnzon-maven-plugin</artifactId>
+ <name>Johnzon :: Maven Plugin</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-json_1.0_spec</artifactId>
+ <version>${jsonspecversion}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.johnzon</groupId>
+ <artifactId>johnzon-mapper</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <version>3.2</version>
+ </dependency>
+ </dependencies>
+
+ <properties>
+ <maven.version>3.0.5</maven.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>3.4</version>
+ <executions>
+ <execution>
+ <id>mojo-descriptor</id>
+ <goals>
+ <goal>descriptor</goal>
+ <goal>helpmojo</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <goalPrefix>johnzon</goalPrefix>
+ <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/3bdbe399/johnzon-maven-plugin/src/main/java/org/apache/johnzon/maven/plugin/ExampleToModelMojo.java
----------------------------------------------------------------------
diff --git a/johnzon-maven-plugin/src/main/java/org/apache/johnzon/maven/plugin/ExampleToModelMojo.java b/johnzon-maven-plugin/src/main/java/org/apache/johnzon/maven/plugin/ExampleToModelMojo.java
new file mode 100644
index 0000000..99b860f
--- /dev/null
+++ b/johnzon-maven-plugin/src/main/java/org/apache/johnzon/maven/plugin/ExampleToModelMojo.java
@@ -0,0 +1,330 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.johnzon.maven.plugin;
+
+import org.apache.commons.lang3.StringUtils;
+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;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.json.JsonReaderFactory;
+import javax.json.JsonStructure;
+import javax.json.JsonValue;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import static java.util.Arrays.asList;
+import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
+
+@Mojo(name = "example-to-model", defaultPhase = GENERATE_SOURCES)
+public class ExampleToModelMojo extends AbstractMojo {
+ // not strictly forbidden but kind of file to java convertion
+ private static final List<Character> FORBIDDEN_JAVA_NAMES = asList('-', '_', '.');
+
+ @Parameter(property = "johnzon.source")
+ protected File source;
+
+ @Parameter(property = "johnzon.target", defaultValue = "${}")
+ protected File target;
+
+ @Parameter(property = "johnzon.package", defaultValue = "com.johnzon.generated")
+ protected String packageBase;
+
+ @Parameter
+ protected String header;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ final JsonReaderFactory readerFactory = Json.createReaderFactory(Collections.<String, Object>emptyMap());
+ if (source.isFile()) {
+ generateFile(readerFactory, source);
+ } else {
+ final File[] children = source.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(final File dir, final String name) {
+ return name.endsWith(".json");
+ }
+ });
+ if (children == null || children.length == 0) {
+ throw new MojoExecutionException("No json file found in " + source);
+ }
+ for (final File child : children) {
+ generateFile(readerFactory, child);
+ }
+ }
+ }
+
+ // TODO: unicity of field name, better nested array/object handling
+ private void generate(final JsonReaderFactory readerFactory, final File source, final Writer writer, final String javaName) throws MojoExecutionException {
+ JsonReader reader = null;
+ try {
+ reader = readerFactory.createReader(new FileReader(source));
+ final JsonStructure structure = reader.read();
+ if (JsonArray.class.isInstance(structure) || !JsonObject.class.isInstance(structure)) { // quite redundant for now but to avoid surprises in future
+ throw new MojoExecutionException("This plugin doesn't support array generation, generate the model (generic) and handle arrays in your code");
+ }
+
+ final JsonObject object = JsonObject.class.cast(structure);
+ final Collection<String> imports = new TreeSet<String>();
+
+ // while we browse the example tree just store imports as well, avoids a 2 passes processing duplicating imports logic
+ final StringWriter memBuffer = new StringWriter();
+ generateFieldsAndMethods(memBuffer, object, " ", imports);
+
+ if (header != null) {
+ writer.write(header);
+ writer.write('\n');
+ }
+
+ writer.write("package " + packageBase + ";\n\n");
+
+ if (!imports.isEmpty()) {
+ for (final String imp : imports) {
+ writer.write("import " + imp + ";\n");
+ }
+ writer.write('\n');
+ }
+
+ writer.write("public class " + javaName + " {\n");
+ writer.write(memBuffer.toString());
+ writer.write("}\n");
+ } catch (final IOException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+
+ private void generateFieldsAndMethods(final Writer writer, final JsonObject object, final String prefix,
+ final Collection<String> imports) throws IOException {
+ final Map<String, JsonObject> nestedTypes = new TreeMap<String, JsonObject>();
+ {
+ final Iterator<Map.Entry<String, JsonValue>> iterator = object.entrySet().iterator();
+ while (iterator.hasNext()) {
+ final Map.Entry<String, JsonValue> entry = iterator.next();
+ final String key = entry.getKey();
+ final String fieldName = toJavaFieldName(key);
+ switch (entry.getValue().getValueType()) {
+ case ARRAY:
+ imports.add("java.util.List");
+ handleArray(writer, prefix, nestedTypes, entry.getValue(), key, fieldName, 1, imports);
+ break;
+ case OBJECT:
+ final String type = toJavaName(fieldName);
+ nestedTypes.put(type, JsonObject.class.cast(entry.getValue()));
+ fieldGetSetMethods(writer, key, fieldName, type, prefix, 0, imports);
+ break;
+ case TRUE:
+ case FALSE:
+ fieldGetSetMethods(writer, key, fieldName, "Boolean", prefix, 0, imports);
+ break;
+ case NUMBER:
+ fieldGetSetMethods(writer, key, fieldName, "Integer", prefix, 0, imports);
+ break;
+ case STRING:
+ fieldGetSetMethods(writer, key, fieldName, "String", prefix, 0, imports);
+ break;
+ case NULL:
+ default:
+ throw new UnsupportedOperationException("Unsupported " + entry.getValue() + ".");
+ }
+ if (iterator.hasNext()) {
+ writer.write("\n");
+ }
+ }
+ }
+
+ if (!object.isEmpty() && !nestedTypes.isEmpty()) {
+ writer.write("\n");
+ }
+
+ final Iterator<Map.Entry<String, JsonObject>> entries = nestedTypes.entrySet().iterator();
+ while (entries.hasNext()) {
+ final Map.Entry<String, JsonObject> entry = entries.next();
+ writer.write(prefix + "public static class " + entry.getKey() + " {\n");
+ generateFieldsAndMethods(writer, entry.getValue(), " " + prefix, imports);
+ writer.write(prefix + "}\n");
+ if (entries.hasNext()) {
+ writer.write("\n");
+ }
+ }
+ }
+
+ private void handleArray(final Writer writer, final String prefix,
+ final Map<String, JsonObject> nestedTypes,
+ final JsonValue value,
+ final String jsonField,final String fieldName,
+ final int arrayLevel,
+ final Collection<String> imports) throws IOException {
+ final JsonArray array = JsonArray.class.cast(value);
+ if (array.size() > 0) { // keep it simple for now - 1 level, we can have an awesome recursive algo later if needed
+ final JsonValue jsonValue = array.get(0);
+ switch (jsonValue.getValueType()) {
+ case OBJECT:
+ final String javaName = toJavaName(fieldName);
+ nestedTypes.put(javaName, JsonObject.class.cast(jsonValue));
+ fieldGetSetMethods(writer, jsonField, fieldName, javaName, prefix, arrayLevel, imports);
+ break;
+ case TRUE:
+ case FALSE:
+ fieldGetSetMethods(writer, jsonField, fieldName, "Boolean", prefix, arrayLevel, imports);
+ break;
+ case NUMBER:
+ fieldGetSetMethods(writer, jsonField, fieldName, "Integer", prefix, arrayLevel, imports);
+ break;
+ case STRING:
+ fieldGetSetMethods(writer, jsonField, fieldName, "String", prefix, arrayLevel, imports);
+ break;
+ case ARRAY:
+ handleArray(writer, prefix, nestedTypes, jsonValue, jsonField, fieldName, arrayLevel + 1, imports);
+ break;
+ case NULL:
+ default:
+ throw new UnsupportedOperationException("Unsupported " + value + ".");
+ }
+ } else {
+ getLog().warn("Empty arrays are ignored");
+ }
+ }
+
+ private void fieldGetSetMethods(final Writer writer,
+ final String jsonField, final String field,
+ final String type, final String prefix, final int arrayLevel,
+ final Collection<String> imports) throws IOException {
+ final String actualType = buildArrayType(arrayLevel, type);
+ final String actualField = buildValidFieldName(jsonField);
+ final String methodName = StringUtils.capitalize(actualField);
+
+ if (!jsonField.equals(field)) { // TODO: add it to imports in eager visitor
+ imports.add("org.apache.johnzon.mapper.JohnzonProperty");
+ writer.append(prefix).append("@JohnzonProperty(\"").append(jsonField).append("\")\n");
+ }
+
+ writer.append(prefix).append("private ").append(actualType).append(" ").append(actualField).append(";\n");
+ writer.append(prefix).append("public ").append(actualType).append(" get").append(methodName).append("() {\n");
+ writer.append(prefix).append(" return ").append(actualField).append(";\n");
+ writer.append(prefix).append("}\n");
+ writer.append(prefix).append("public void set").append(methodName).append("(final ").append(actualType).append(" newValue) {\n");
+ writer.append(prefix).append(" this.").append(actualField).append(" = newValue;\n");
+ writer.append(prefix).append("}\n");
+ }
+
+ private String buildArrayType(final int arrayLevel, final String type) {
+ if (arrayLevel == 0) { // quick exit
+ return type;
+ }
+
+ final StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < arrayLevel; i++) {
+ builder.append("List<");
+ }
+ builder.append(type);
+ for (int i = 0; i < arrayLevel; i++) {
+ builder.append(">");
+ }
+ return builder.toString();
+ }
+
+ private void visit(final JsonStructure structure, final Visitor visitor) {
+ if (JsonObject.class.isInstance(structure)) {
+ visitor.visitObject(JsonObject.class.cast(structure));
+ } else if (JsonArray.class.isInstance(structure)) {
+ visitor.visitArray(JsonArray.class.cast(structure));
+ } else {
+ throw new UnsupportedOperationException("Can't visit " + structure);
+ }
+ }
+
+ private void generateFile(final JsonReaderFactory readerFactory, final File source) throws MojoExecutionException {
+ final String javaName = StringUtils.capitalize(toJavaName(source.getName()));
+ final String jsonToClass = packageBase + '.' + javaName;
+ final File outputFile = new File(target, jsonToClass.replace('.', '/') + ".java");
+
+ outputFile.getParentFile().mkdirs();
+ FileWriter writer = null;
+ try {
+ writer = new FileWriter(outputFile);
+ generate(readerFactory, source, writer, javaName);
+ } catch (IOException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ } finally {
+ try {
+ if (writer != null) {
+ writer.close();
+ }
+ } catch (final IOException e) {
+ // no-op
+ }
+ }
+ }
+
+ private String buildValidFieldName(final String jsonField) {
+ String val = jsonField;
+ if (Character.isDigit(jsonField.charAt(0))) {
+ val = "_" + jsonField;
+ }
+ return val.replace(".", "");
+ }
+
+ private String toJavaFieldName(final String key) {
+ return StringUtils.uncapitalize(toJavaName(key));
+ }
+
+ private String toJavaName(final String file) {
+ final StringBuilder builder = new StringBuilder();
+ boolean nextUpper = false;
+ for (final char anIn : file.replace(".json", "").toCharArray()) {
+ if (FORBIDDEN_JAVA_NAMES.contains(anIn)) {
+ nextUpper = true;
+ } else if (nextUpper) {
+ builder.append(Character.toUpperCase(anIn));
+ nextUpper = false;
+ } else {
+ builder.append(anIn);
+ }
+ }
+ return StringUtils.capitalize(builder.toString());
+ }
+
+ private interface Visitor {
+ void visitObject(JsonObject structure);
+
+ void visitArray(JsonArray structure);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/3bdbe399/johnzon-maven-plugin/src/test/java/org/apache/johnzon/maven/plugin/ExampleToModelMojoTest.java
----------------------------------------------------------------------
diff --git a/johnzon-maven-plugin/src/test/java/org/apache/johnzon/maven/plugin/ExampleToModelMojoTest.java b/johnzon-maven-plugin/src/test/java/org/apache/johnzon/maven/plugin/ExampleToModelMojoTest.java
new file mode 100644
index 0000000..13e7ec5
--- /dev/null
+++ b/johnzon-maven-plugin/src/test/java/org/apache/johnzon/maven/plugin/ExampleToModelMojoTest.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.johnzon.maven.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.IOUtil;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class ExampleToModelMojoTest {
+ @Test
+ public void generate() throws MojoFailureException, MojoExecutionException, IOException {
+ final File sourceFolder = new File("target/ExampleToModelMojoTest/source/");
+ final File targetFolder = new File("target/ExampleToModelMojoTest/target/");
+ final ExampleToModelMojo mojo = new ExampleToModelMojo() {{
+ source = sourceFolder;
+ target = targetFolder;
+ packageBase = "org.test.apache.johnzon.mojo";
+ header =
+ "/*\n" +
+ " * Licensed to the Apache Software Foundation (ASF) under one\n" +
+ " * or more contributor license agreements. See the NOTICE file\n" +
+ " * distributed with this work for additional information\n" +
+ " * regarding copyright ownership. The ASF licenses this file\n" +
+ " * to you under the Apache License, Version 2.0 (the\n" +
+ " * \"License\"); you may not use this file except in compliance\n" +
+ " * with the License. You may obtain a copy of the License at\n" +
+ " *\n" +
+ " * http://www.apache.org/licenses/LICENSE-2.0\n" +
+ " *\n" +
+ " * Unless required by applicable law or agreed to in writing,\n" +
+ " * software distributed under the License is distributed on an\n" +
+ " * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" +
+ " * KIND, either express or implied. See the License for the\n" +
+ " * specific language governing permissions and limitations\n" +
+ " * under the License.\n" +
+ " */";
+ }};
+
+ sourceFolder.mkdirs();
+ final FileWriter writer = new FileWriter(new File(sourceFolder, "some-value.json"));
+ writer.write( // using openjmh as sample data
+ " {\n" +
+ " \"benchmark\" : \"com.sample.Perf.method\",\n" +
+ " \"mode\" : \"sample\",\n" +
+ " \"threads\" : 32,\n" +
+ " \"forks\" : 1,\n" +
+ " \"warmupIterations\" : 2,\n" +
+ " \"warmupTime\" : \"1 s\",\n" +
+ " \"measurementIterations\" : 3,\n" +
+ " \"measurementTime\" : \"1 s\",\n" +
+ " \"primaryMetric\" : {\n" +
+ " \"score\" : 6.951927808,\n" +
+ " \"scoreError\" : 0.7251433665600178,\n" +
+ " \"scoreConfidence\" : [\n" +
+ " 6.226784441439982,\n" +
+ " 7.677071174560018\n" +
+ " ],\n" +
+ " \"scorePercentiles\" : {\n" +
+ " \"0.0\" : 3.9468400640000003,\n" +
+ " \"50.0\" : 6.593445888000001,\n" +
+ " \"90.0\" : 9.925400985600001,\n" +
+ " \"95.0\" : 11.301132697600002,\n" +
+ " \"99.0\" : 11.844714496,\n" +
+ " \"99.9\" : 11.844714496,\n" +
+ " \"99.99\" : 11.844714496,\n" +
+ " \"99.999\" : 11.844714496,\n" +
+ " \"99.9999\" : 11.844714496,\n" +
+ " \"100.0\" : 11.844714496\n" +
+ " },\n" +
+ " \"scoreUnit\" : \"s/op\",\n" +
+ " \"rawData\" : [\n" +
+ " [\n" +
+ " 6.687817728,\n" +
+ " 7.169245184,\n" +
+ " 6.998720512\n" +
+ " ]\n" +
+ " ]\n" +
+ " },\n" +
+ " \"secondaryMetrics\" : {\n" +
+ " }\n" +
+ " }\n");
+ writer.close();
+
+ mojo.execute();
+
+ final File output = new File(targetFolder, "org/test/apache/johnzon/mojo/SomeValue.java");
+ assertTrue(output.isFile());
+ assertEquals(
+ new String(IOUtil.toByteArray(Thread.currentThread().getContextClassLoader().getResourceAsStream("SomeValue.java"))),
+ new String(IOUtil.toByteArray(new FileReader(output))));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/3bdbe399/johnzon-maven-plugin/src/test/resources/SomeValue.java
----------------------------------------------------------------------
diff --git a/johnzon-maven-plugin/src/test/resources/SomeValue.java b/johnzon-maven-plugin/src/test/resources/SomeValue.java
new file mode 100644
index 0000000..882f9d3
--- /dev/null
+++ b/johnzon-maven-plugin/src/test/resources/SomeValue.java
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.test.apache.johnzon.mojo;
+
+import java.util.List;
+import org.apache.johnzon.mapper.JohnzonProperty;
+
+public class SomeValue {
+ private String benchmark;
+ public String getBenchmark() {
+ return benchmark;
+ }
+ public void setBenchmark(final String newValue) {
+ this.benchmark = newValue;
+ }
+
+ private String mode;
+ public String getMode() {
+ return mode;
+ }
+ public void setMode(final String newValue) {
+ this.mode = newValue;
+ }
+
+ private Integer threads;
+ public Integer getThreads() {
+ return threads;
+ }
+ public void setThreads(final Integer newValue) {
+ this.threads = newValue;
+ }
+
+ private Integer forks;
+ public Integer getForks() {
+ return forks;
+ }
+ public void setForks(final Integer newValue) {
+ this.forks = newValue;
+ }
+
+ private Integer warmupIterations;
+ public Integer getWarmupIterations() {
+ return warmupIterations;
+ }
+ public void setWarmupIterations(final Integer newValue) {
+ this.warmupIterations = newValue;
+ }
+
+ private String warmupTime;
+ public String getWarmupTime() {
+ return warmupTime;
+ }
+ public void setWarmupTime(final String newValue) {
+ this.warmupTime = newValue;
+ }
+
+ private Integer measurementIterations;
+ public Integer getMeasurementIterations() {
+ return measurementIterations;
+ }
+ public void setMeasurementIterations(final Integer newValue) {
+ this.measurementIterations = newValue;
+ }
+
+ private String measurementTime;
+ public String getMeasurementTime() {
+ return measurementTime;
+ }
+ public void setMeasurementTime(final String newValue) {
+ this.measurementTime = newValue;
+ }
+
+ private PrimaryMetric primaryMetric;
+ public PrimaryMetric getPrimaryMetric() {
+ return primaryMetric;
+ }
+ public void setPrimaryMetric(final PrimaryMetric newValue) {
+ this.primaryMetric = newValue;
+ }
+
+ private SecondaryMetrics secondaryMetrics;
+ public SecondaryMetrics getSecondaryMetrics() {
+ return secondaryMetrics;
+ }
+ public void setSecondaryMetrics(final SecondaryMetrics newValue) {
+ this.secondaryMetrics = newValue;
+ }
+
+ public static class PrimaryMetric {
+ private Integer score;
+ public Integer getScore() {
+ return score;
+ }
+ public void setScore(final Integer newValue) {
+ this.score = newValue;
+ }
+
+ private Integer scoreError;
+ public Integer getScoreError() {
+ return scoreError;
+ }
+ public void setScoreError(final Integer newValue) {
+ this.scoreError = newValue;
+ }
+
+ private List<Integer> scoreConfidence;
+ public List<Integer> getScoreConfidence() {
+ return scoreConfidence;
+ }
+ public void setScoreConfidence(final List<Integer> newValue) {
+ this.scoreConfidence = newValue;
+ }
+
+ private ScorePercentiles scorePercentiles;
+ public ScorePercentiles getScorePercentiles() {
+ return scorePercentiles;
+ }
+ public void setScorePercentiles(final ScorePercentiles newValue) {
+ this.scorePercentiles = newValue;
+ }
+
+ private String scoreUnit;
+ public String getScoreUnit() {
+ return scoreUnit;
+ }
+ public void setScoreUnit(final String newValue) {
+ this.scoreUnit = newValue;
+ }
+
+ private List<List<Integer>> rawData;
+ public List<List<Integer>> getRawData() {
+ return rawData;
+ }
+ public void setRawData(final List<List<Integer>> newValue) {
+ this.rawData = newValue;
+ }
+
+ public static class ScorePercentiles {
+ @JohnzonProperty("0.0")
+ private Integer _00;
+ public Integer get_00() {
+ return _00;
+ }
+ public void set_00(final Integer newValue) {
+ this._00 = newValue;
+ }
+
+ @JohnzonProperty("50.0")
+ private Integer _500;
+ public Integer get_500() {
+ return _500;
+ }
+ public void set_500(final Integer newValue) {
+ this._500 = newValue;
+ }
+
+ @JohnzonProperty("90.0")
+ private Integer _900;
+ public Integer get_900() {
+ return _900;
+ }
+ public void set_900(final Integer newValue) {
+ this._900 = newValue;
+ }
+
+ @JohnzonProperty("95.0")
+ private Integer _950;
+ public Integer get_950() {
+ return _950;
+ }
+ public void set_950(final Integer newValue) {
+ this._950 = newValue;
+ }
+
+ @JohnzonProperty("99.0")
+ private Integer _990;
+ public Integer get_990() {
+ return _990;
+ }
+ public void set_990(final Integer newValue) {
+ this._990 = newValue;
+ }
+
+ @JohnzonProperty("99.9")
+ private Integer _999;
+ public Integer get_999() {
+ return _999;
+ }
+ public void set_999(final Integer newValue) {
+ this._999 = newValue;
+ }
+
+ @JohnzonProperty("99.99")
+ private Integer _9999;
+ public Integer get_9999() {
+ return _9999;
+ }
+ public void set_9999(final Integer newValue) {
+ this._9999 = newValue;
+ }
+
+ @JohnzonProperty("99.999")
+ private Integer _99999;
+ public Integer get_99999() {
+ return _99999;
+ }
+ public void set_99999(final Integer newValue) {
+ this._99999 = newValue;
+ }
+
+ @JohnzonProperty("99.9999")
+ private Integer _999999;
+ public Integer get_999999() {
+ return _999999;
+ }
+ public void set_999999(final Integer newValue) {
+ this._999999 = newValue;
+ }
+
+ @JohnzonProperty("100.0")
+ private Integer _1000;
+ public Integer get_1000() {
+ return _1000;
+ }
+ public void set_1000(final Integer newValue) {
+ this._1000 = newValue;
+ }
+ }
+ }
+
+ public static class SecondaryMetrics {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/3bdbe399/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7bac50d..5cb8afd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,6 +54,7 @@
<module>johnzon-mapper</module>
<module>johnzon-jaxrs</module>
<module>johnzon-distribution</module>
+ <module>johnzon-maven-plugin</module>
</modules>
<dependencies>