Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement json schema generator plugin, fix #305
- Loading branch information
Showing
8 changed files
with
369 additions
and
1 deletion.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
hawtio-json-schema-generator/hawtio-json-schema-generator-plugin/pom.xml
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,79 @@ | ||
<?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/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>hawtio-json-schema-generator</artifactId> | ||
<groupId>io.hawt</groupId> | ||
<version>1.2-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>hawtio-json-schema-generator-plugin</artifactId> | ||
<name>${project.parent.artifactId}/${project.artifactId}</name> | ||
|
||
<packaging>maven-plugin</packaging> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>io.hawt</groupId> | ||
<artifactId>hawtio-json-schema-mbean</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-plugin-api</artifactId> | ||
<version>3.0.4</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.maven.plugin-tools</groupId> | ||
<artifactId>maven-plugin-annotations</artifactId> | ||
<version>3.2</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- generated help mojo has a dependency to plexus-utils --> | ||
<dependency> | ||
<groupId>org.codehaus.plexus</groupId> | ||
<artifactId>plexus-utils</artifactId> | ||
<version>3.0.4</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
|
||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-plugin-plugin</artifactId> | ||
<version>3.2</version> | ||
<configuration> | ||
<!-- see http://jira.codehaus.org/browse/MNG-5346 --> | ||
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>mojo-descriptor</id> | ||
<goals> | ||
<goal>descriptor</goal> | ||
</goals> | ||
</execution> | ||
<!-- if you want to generate help goal --> | ||
<execution> | ||
<id>help-goal</id> | ||
<goals> | ||
<goal>helpmojo</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
|
||
</project> |
56 changes: 56 additions & 0 deletions
56
...nerator-plugin/src/main/java/io/hawt/jsonschema/maven/plugin/JsonSchemaGeneratorMojo.java
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,56 @@ | ||
package io.hawt.jsonschema.maven.plugin; | ||
|
||
import io.hawt.jsonschema.SchemaLookup; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
import java.io.BufferedOutputStream; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.util.Map; | ||
|
||
/** | ||
* Uses hawtio-json-schema-mbean to generate Json Schema for Java classes | ||
* | ||
*/ | ||
@Mojo( name="generate-json-schema", defaultPhase = LifecyclePhase.GENERATE_SOURCES ) | ||
public class JsonSchemaGeneratorMojo extends AbstractMojo | ||
{ | ||
|
||
/** | ||
* Java classes to be converted into schema | ||
*/ | ||
@Parameter(required=true) | ||
private Map<String, String> classes; | ||
|
||
public void execute() throws MojoExecutionException | ||
{ | ||
SchemaLookup lookup = new SchemaLookup(); | ||
lookup.init(); | ||
|
||
for (String clazz : this.classes.keySet()) { | ||
try { | ||
getLog().info("Looking up schema for class " + clazz); | ||
|
||
String targetFileName = this.classes.get(clazz); | ||
String fileContents = "var " + clazz + " = " + lookup.getSchemaForClass(clazz); | ||
|
||
File outputFile = new File(targetFileName); | ||
|
||
if (outputFile.getParentFile().mkdirs()) { | ||
getLog().info("Created path " + outputFile.getParentFile()); | ||
} | ||
|
||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outputFile)); | ||
out.write(fileContents.getBytes()); | ||
out.flush(); | ||
out.close(); | ||
} catch (Exception e) { | ||
throw new MojoExecutionException("Failed to generate schema for " + clazz, e); | ||
} | ||
} | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
hawtio-json-schema-generator/hawtio-json-schema-generator-test/pom.xml
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,126 @@ | ||
<?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/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>hawtio-json-schema-generator</artifactId> | ||
<groupId>io.hawt</groupId> | ||
<version>1.2-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>hawtio-json-schema-generator-test</artifactId> | ||
<name>${project.parent.artifactId}/${project.artifactId}</name> | ||
|
||
<properties> | ||
<!-- stupid maven test harness is stupid --> | ||
<maven.test.skip>true</maven.test.skip> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<!-- these are all totally ignored at the moment --> | ||
<dependency> | ||
<groupId>io.hawt</groupId> | ||
<artifactId>hawtio-json-schema-generator-plugin</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.codehaus.plexus</groupId> | ||
<artifactId>plexus-container-default</artifactId> | ||
<version>1.5.5</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.sonatype.aether</groupId> | ||
<artifactId>aether-api</artifactId> | ||
<version>1.13.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.sonatype.aether</groupId> | ||
<artifactId>aether-util</artifactId> | ||
<version>1.13.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-core</artifactId> | ||
<version>3.0.4</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.maven.plugin-testing</groupId> | ||
<artifactId>maven-plugin-testing-harness</artifactId> | ||
<version>2.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit-version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
|
||
<testResources> | ||
<testResource> | ||
<directory>src/test/resources</directory> | ||
<filtering>true</filtering> | ||
</testResource> | ||
</testResources> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>io.hawt</groupId> | ||
<artifactId>hawtio-json-schema-generator-plugin</artifactId> | ||
<version>${project.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>generate-json-schema</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<classes> | ||
<org.fusesource.fabric.api.CreateContainerChildOptions> | ||
${project.build.outputDirectory}/webapp/fabric/js/createContainerChildOptions.js | ||
</org.fusesource.fabric.api.CreateContainerChildOptions> | ||
<org.fusesource.fabric.api.CreateSshContainerOptions> | ||
${project.build.outputDirectory}/webapp/fabric/js/createSshContainerOptions.js | ||
</org.fusesource.fabric.api.CreateSshContainerOptions> | ||
<org.fusesource.fabric.api.CreateJCloudsContainerOptions> | ||
${project.build.outputDirectory}/webapp/fabric/js/createJcloudsContainerOptions.js | ||
</org.fusesource.fabric.api.CreateJCloudsContainerOptions> | ||
</classes> | ||
</configuration> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.fusesource.fabric</groupId> | ||
<artifactId>fabric-core</artifactId> | ||
<version>${fabric-version}</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
|
||
</plugins> | ||
|
||
</build> | ||
|
||
</project> |
27 changes: 27 additions & 0 deletions
27
.../hawtio-json-schema-generator-test/src/test/java/io/hawt/JsonSchemaGeneratorMojoTest.java
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,27 @@ | ||
package io.hawt; | ||
|
||
import io.hawt.jsonschema.maven.plugin.JsonSchemaGeneratorMojo; | ||
import org.apache.maven.plugin.testing.AbstractMojoTestCase; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* @author Stan Lewis | ||
*/ | ||
public class JsonSchemaGeneratorMojoTest extends AbstractMojoTestCase { | ||
|
||
/* | ||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
} | ||
*/ | ||
|
||
public void testMojoGoal() throws Exception { | ||
File testPom = new File( getBasedir(), "/target/test-classes/test-pom.xml"); | ||
JsonSchemaGeneratorMojo mojo = new JsonSchemaGeneratorMojo(); | ||
configureMojo(mojo, "hawtio-json-schema-generator-plugin", testPom); | ||
mojo.execute(); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...o-json-schema-generator/hawtio-json-schema-generator-test/src/test/resources/test-pom.xml
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,56 @@ | ||
<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> | ||
|
||
<parent> | ||
<artifactId>project</artifactId> | ||
<groupId>io.hawt</groupId> | ||
<version>1.2-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>org.apache.maven.plugin.my.unit</groupId> | ||
<artifactId>project-to-test</artifactId> | ||
|
||
<packaging>jar</packaging> | ||
<name>Test MyMojo</name> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.fusesource.fabric</groupId> | ||
<artifactId>fabric-core</artifactId> | ||
<version>${fabric-version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.hawt</groupId> | ||
<artifactId>hawtio-json-schema-generator-plugin</artifactId> | ||
<version>${project.version}</version> | ||
<configuration> | ||
<classes> | ||
<org.fusesource.fabric.api.CreateSshContainerOptions> | ||
createSshContainerOptions.json | ||
</org.fusesource.fabric.api.CreateSshContainerOptions> | ||
</classes> | ||
</configuration> | ||
<dependencies> | ||
</dependencies> | ||
</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,23 @@ | ||
<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"> | ||
<parent> | ||
<artifactId>project</artifactId> | ||
<groupId>io.hawt</groupId> | ||
<version>1.2-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>hawtio-json-schema-generator</artifactId> | ||
|
||
<packaging>pom</packaging> | ||
|
||
<name>${project.parent.artifactId}/${project.artifactId}</name> | ||
<description>${project.parent.artifactId} :: ${project.artifactId}</description> | ||
|
||
<modules> | ||
<module>hawtio-json-schema-generator-plugin</module> | ||
<module>hawtio-json-schema-generator-test</module> | ||
</modules> | ||
|
||
|
||
</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
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