http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-pig/src/site/markdown/index.md ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-pig/src/site/markdown/index.md b/streams-plugins/streams-plugin-pig/src/site/markdown/index.md index d0d4791..5ab4375 100644 --- a/streams-plugins/streams-plugin-pig/src/site/markdown/index.md +++ b/streams-plugins/streams-plugin-pig/src/site/markdown/index.md @@ -3,17 +3,33 @@ org.apache.streams.plugins:streams-plugin-pig streams-plugin-pig generates resources from json schemas to assist with analysis of json data using Apache Pig. -#### Usage +### Usage + +Output will be placed in target/generated-resources/pig by default + +##### Maven Run within a module containing a src/main/jsonschema directory mvn org.apache.streams.plugins:streams-plugin-pig:0.3-incubating-SNAPSHOT:pig -Output will be placed in target/generated-resources/pig by default +[streams-plugin-pig/pom.xml](streams-plugin-pig/pom.xml "streams-plugin-pig/pom.xml") -#### Example +##### SDK -[streams-plugin-pig/pom.xml](streams-plugin-pig/pom.xml "streams-plugin-pig/pom.xml") +Embed within your own java code + + StreamsPigGenerationConfig config = new StreamsPigGenerationConfig(); + config.setSourceDirectory("src/main/jsonschema"); + config.setTargetDirectory("target/generated-resources"); + StreamsPigGenerationConfig generator = new StreamsPigGenerationConfig(config); + generator.run(); + +##### CLI + +Run from CLI without Maven + + java -jar streams-plugin-pig-jar-with-dependencies.jar StreamsPigResourceGenerator src/main/jsonschema target/generated-resources #### Documentation
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorCLITest.java ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorCLITest.java b/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorCLITest.java index c94bca9..8190d50 100644 --- a/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorCLITest.java +++ b/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorCLITest.java @@ -19,8 +19,8 @@ public class StreamsPigResourceGeneratorCLITest { @Test public void testStreamsPigResourceGeneratorCLI() throws Exception { - String sourceDirectory = "target/test-classes/streams-schemas"; - String targetDirectory = "target/generated-resources/hive-cli"; + String sourceDirectory = "target/test-classes/streams-schema-activitystreams"; + String targetDirectory = "target/generated-resources/pig-cli"; List<String> argsList = Lists.newArrayList(sourceDirectory, targetDirectory); StreamsPigResourceGenerator.main(argsList.toArray(new String[0])); http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorMojoTest.java ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorMojoTest.java b/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorMojoTest.java index 401c506..76c4eb2 100644 --- a/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorMojoTest.java +++ b/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorMojoTest.java @@ -31,7 +31,7 @@ public class StreamsPigResourceGeneratorMojoTest extends TestCase { @Test - public void testStreamsHiveResourceGeneratorMojo() throws Exception { + public void testStreamsPigResourceGeneratorMojo() throws Exception { File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/streams-plugin-pig" ); @@ -50,7 +50,7 @@ public class StreamsPigResourceGeneratorMojoTest extends TestCase { verifier.resetStreams(); - File testOutput = new File(testDir.getAbsolutePath() + "/target/generated-resources/test-mojo"); + File testOutput = new File(testDir.getAbsolutePath() + "/target/generated-resources/pig-mojo"); assert( testOutput != null ); assert( testOutput.exists() == true ); http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorTest.java ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorTest.java b/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorTest.java index a1ab281..98442ad 100644 --- a/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorTest.java +++ b/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorTest.java @@ -17,7 +17,7 @@ import java.io.File; import java.util.Collection; import java.util.Iterator; -import static org.apache.streams.schema.FileUtil.dropSourcePathPrefix; +import static org.apache.streams.util.schema.FileUtil.dropSourcePathPrefix; /** * Test that Activity beans are compatible with the example activities in the spec. @@ -45,28 +45,20 @@ public class StreamsPigResourceGeneratorTest { StreamsPigGenerationConfig config = new StreamsPigGenerationConfig(); - String sourceDirectory = "target/test-classes/streams-schemas"; + String sourceDirectory = "target/test-classes/streams-schema-activitystreams"; config.setSourceDirectory(sourceDirectory); - config.setTargetDirectory("target/generated-sources/test"); + config.setTargetDirectory("target/generated-resources/pig"); config.setExclusions(Sets.newHashSet("attachments")); config.setMaxDepth(2); StreamsPigResourceGenerator streamsPigResourceGenerator = new StreamsPigResourceGenerator(config); - Thread thread = new Thread(streamsPigResourceGenerator); - thread.start(); - try { - thread.join(); - } catch (InterruptedException e) { - LOGGER.error("InterruptedException", e); - } catch (Exception e) { - LOGGER.error("Exception", e); - } + streamsPigResourceGenerator.run(); - File testOutput = new File( "./target/generated-sources/test"); + File testOutput = config.getTargetDirectory(); assert( testOutput != null ); assert( testOutput.exists() == true ); @@ -104,19 +96,5 @@ public class StreamsPigResourceGeneratorTest { LOGGER.info("Fails: {}", fails); Assert.fail(); } - - -// assert( new File(testOutput + "/traits").exists() == true ); -// assert( new File(testOutput + "/traits").isDirectory() == true ); -// assert( new File(testOutput + "/traits").listFiles(scalaFilter) != null ); -// assert( new File(testOutput + "/traits").listFiles(scalaFilter).length == 4 ); -// assert( new File(testOutput + "/objectTypes").exists() == true ); -// assert( new File(testOutput + "/objectTypes").isDirectory() == true ); -// assert( new File(testOutput + "/objectTypes").listFiles(scalaFilter) != null ); -// assert( new File(testOutput + "/objectTypes").listFiles(scalaFilter).length == 43 ); -// assert( new File(testOutput + "/verbs").exists() == true ); -// assert( new File(testOutput + "/verbs").isDirectory() == true ); -// assert( new File(testOutput + "/verbs").listFiles(scalaFilter) != null ); -// assert( new File(testOutput + "/verbs").listFiles(scalaFilter).length == 89 ); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-pig/src/test/resources/streams-plugin-pig/pom.xml ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-pig/src/test/resources/streams-plugin-pig/pom.xml b/streams-plugins/streams-plugin-pig/src/test/resources/streams-plugin-pig/pom.xml index 7027446..f3976fa 100644 --- a/streams-plugins/streams-plugin-pig/src/test/resources/streams-plugin-pig/pom.xml +++ b/streams-plugins/streams-plugin-pig/src/test/resources/streams-plugin-pig/pom.xml @@ -18,9 +18,10 @@ </dependency> <dependency> <groupId>org.apache.streams</groupId> - <artifactId>streams-schemas</artifactId> + <artifactId>streams-schema-activitystreams</artifactId> <version>${project.version}</version> <scope>test</scope> + <type>test-jar</type> </dependency> </dependencies> @@ -32,19 +33,19 @@ <version>0.3-incubating-SNAPSHOT</version> <configuration> <sourcePaths> - <sourcePath>target/test-classes/streams-schemas/activity.json</sourcePath> - <sourcePath>target/test-classes/streams-schemas/collection.json</sourcePath> - <sourcePath>target/test-classes/streams-schemas/media_link.json</sourcePath> - <sourcePath>target/test-classes/streams-schemas/object.json</sourcePath> - <sourcePath>target/test-classes/streams-schemas/objectTypes</sourcePath> - <sourcePath>target/test-classes/streams-schemas/verbs</sourcePath> + <sourcePath>target/test-classes/streams-schema-activitystreams/activity.json</sourcePath> + <sourcePath>target/test-classes/streams-schema-activitystreams/collection.json</sourcePath> + <sourcePath>target/test-classes/streams-schema-activitystreams/media_link.json</sourcePath> + <sourcePath>target/test-classes/streams-schema-activitystreams/object.json</sourcePath> + <sourcePath>target/test-classes/streams-schema-activitystreams/objectTypes</sourcePath> + <sourcePath>target/test-classes/streams-schema-activitystreams/verbs</sourcePath> </sourcePaths> - <targetDirectory>target/generated-resources/test-mojo</targetDirectory> + <targetDirectory>target/generated-resources/pig-mojo</targetDirectory> </configuration> <executions> <execution> <goals> - <goal>pig</goal> + <goal>generate-resources</goal> </goals> </execution> </executions> @@ -55,9 +56,9 @@ <version>2.10</version> <configuration> <includes>**/*.json</includes> - <outputDirectory>${project.build.directory}/test-classes/streams-schemas</outputDirectory> + <outputDirectory>${project.build.directory}/test-classes/streams-schema-activitystreams</outputDirectory> <includeGroupIds>org.apache.streams</includeGroupIds> - <includeArtifactIds>streams-schemas</includeArtifactIds> + <includeArtifactIds>streams-schema-activitystreams</includeArtifactIds> <includeTypes>jar,test-jar</includeTypes> </configuration> <executions> http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-pojo/pom.xml ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-pojo/pom.xml b/streams-plugins/streams-plugin-pojo/pom.xml index bfa3480..da7c0b2 100644 --- a/streams-plugins/streams-plugin-pojo/pom.xml +++ b/streams-plugins/streams-plugin-pojo/pom.xml @@ -44,10 +44,17 @@ </dependency> <dependency> <groupId>org.apache.streams</groupId> - <artifactId>streams-schemas</artifactId> + <artifactId>streams-util</artifactId> <version>${project.version}</version> </dependency> <dependency> + <groupId>org.apache.streams</groupId> + <artifactId>streams-schema-activitystreams</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.jsonschema2pojo</groupId> <artifactId>jsonschema2pojo-core</artifactId> <version>0.4.10</version> @@ -224,9 +231,9 @@ <artifactId>maven-dependency-plugin</artifactId> <configuration> <includes>**/*.json</includes> - <outputDirectory>${project.build.directory}/test-classes/streams-schemas</outputDirectory> + <outputDirectory>${project.build.directory}/test-classes/streams-schema-activitystreams</outputDirectory> <includeGroupIds>org.apache.streams</includeGroupIds> - <includeArtifactIds>streams-schemas</includeArtifactIds> + <includeArtifactIds>streams-schema-activitystreams</includeArtifactIds> <includeTypes>jar,test-jar</includeTypes> </configuration> <executions> http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoSourceGenerator.java ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoSourceGenerator.java b/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoSourceGenerator.java index f7b6617..504eb80 100644 --- a/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoSourceGenerator.java +++ b/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoSourceGenerator.java @@ -25,7 +25,7 @@ public class StreamsPojoSourceGenerator implements Runnable { StreamsPojoGenerationConfig config = new StreamsPojoGenerationConfig(); String sourceDirectory = "./target/test-classes/activities"; - String targetDirectory = "./target/generated-sources/streams-plugin-pojo"; + String targetDirectory = "./target/generated-sources/pojo"; String targetPackage = ""; if( args.length > 0 ) @@ -40,15 +40,8 @@ public class StreamsPojoSourceGenerator implements Runnable { config.setTargetDirectory(targetDirectory); StreamsPojoSourceGenerator streamsPojoSourceGenerator = new StreamsPojoSourceGenerator(config); - Thread thread = new Thread(streamsPojoSourceGenerator); - thread.start(); - try { - thread.join(); - } catch (InterruptedException e) { - LOGGER.error("InterruptedException", e); - } catch (Exception e) { - LOGGER.error("Exception", e); - } + streamsPojoSourceGenerator.run(); + return; } @@ -68,8 +61,6 @@ public class StreamsPojoSourceGenerator implements Runnable { } } - - private void writeFile(String pojoFile, String pojoHive) { try { File path = new File(pojoFile); http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoSourceGeneratorMojo.java ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoSourceGeneratorMojo.java b/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoSourceGeneratorMojo.java index 8cf1697..2a4978a 100644 --- a/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoSourceGeneratorMojo.java +++ b/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoSourceGeneratorMojo.java @@ -30,10 +30,10 @@ import java.util.List; import static org.apache.commons.lang.StringUtils.isNotBlank; -@Mojo( name = "pojo", +@Mojo( name = "generate-sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES ) -@Execute( goal = "pojo", +@Execute( goal = "generate-sources", phase = LifecyclePhase.GENERATE_SOURCES ) public class StreamsPojoSourceGeneratorMojo extends AbstractMojo { @@ -45,16 +45,6 @@ public class StreamsPojoSourceGeneratorMojo extends AbstractMojo { @Component public MavenProject project; -// @Component -// private Settings settings; -// -// @Parameter( defaultValue = "${localRepository}", readonly = true, required = true ) -// protected ArtifactRepository localRepository; -// -// @Parameter( defaultValue = "${plugin}", readonly = true ) // Maven 3 only -// private PluginDescriptor plugin; -// - @Parameter( defaultValue = "${project.basedir}", readonly = true ) public File basedir; @@ -64,7 +54,7 @@ public class StreamsPojoSourceGeneratorMojo extends AbstractMojo { @Parameter( readonly = true ) // Maven 3 only public List<String> sourcePaths; - @Parameter(defaultValue = "./target/generated-sources/streams-plugin-pojo", readonly = true) + @Parameter(defaultValue = "./target/generated-sources/pojo", readonly = true) public String targetDirectory; @Parameter(readonly = true) @@ -84,30 +74,7 @@ public class StreamsPojoSourceGeneratorMojo extends AbstractMojo { config.setTargetDirectory(targetDirectory); StreamsPojoSourceGenerator streamsPojoSourceGenerator = new StreamsPojoSourceGenerator(config); - - Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() { - public void uncaughtException(Thread th, Throwable ex) { - LOGGER.error("Exception", ex); - mojoFailureException = new MojoFailureException("Exception", ex); - } - }; - Thread.setDefaultUncaughtExceptionHandler(h); - Thread thread = new Thread(streamsPojoSourceGenerator); - thread.setUncaughtExceptionHandler(h); - try { - thread.start(); - thread.join(); - } catch (InterruptedException e) { - LOGGER.error("InterruptedException", e); - } catch (Exception e) { - LOGGER.error("Exception", e); - throw new MojoFailureException("Exception", e); - } - - if( mojoFailureException != null ) - throw mojoFailureException; - - return; + streamsPojoSourceGenerator.run(); } @@ -125,117 +92,4 @@ public class StreamsPojoSourceGeneratorMojo extends AbstractMojo { } -// public List<Class<?>> detectSerializableClasses() { -// -// Set<Class<? extends Serializable>> classes = -// reflections.getSubTypesOf(java.io.Serializable.class); -// -// List<Class<?>> result = Lists.newArrayList(); -// -// for( Class clazz : classes ) { -// result.add(clazz); -// } -// -// return result; -// } -// -// public List<Class<?>> detectPojoClasses(List<Class<?>> classes) { -// -// List<Class<?>> result = Lists.newArrayList(); -// -// for( Class clazz : classes ) { -// try { -// clazz.newInstance().toString(); -// } catch( Exception e) {} -// // super-halfass way to know if this is a jsonschema2pojo -// if( clazz.getAnnotations().length >= 1 ) -// result.add(clazz); -// } -// -// return result; -// } -// -// public String renderPojo(Class<?> pojoClass) { -// StringBuffer stringBuffer = new StringBuffer(); -// stringBuffer.append("CREATE TABLE "); -// stringBuffer.append(pojoClass.getPackage().getName().replace(".pojo.json", ".hive")); -// stringBuffer.append(LS); -// stringBuffer.append("("); -// stringBuffer.append(LS); -// -// Set<Field> fields = ReflectionUtils.getAllFields(pojoClass); -// appendFields(stringBuffer, fields, "", ","); -// -// stringBuffer.append(")"); -// -// return stringBuffer.toString(); -// } -// -// private void appendFields(StringBuffer stringBuffer, Set<Field> fields, String varDef, String fieldDelimiter) { -// if( fields.size() > 0 ) { -// stringBuffer.append(LS); -// Map<String,Field> fieldsToAppend = uniqueFields(fields); -// for( Iterator<Field> iter = fieldsToAppend.values().iterator(); iter.hasNext(); ) { -// Field field = iter.next(); -// stringBuffer.append(name(field)); -// stringBuffer.append(": "); -// stringBuffer.append(type(field)); -// if( iter.hasNext()) stringBuffer.append(fieldDelimiter); -// stringBuffer.append(LS); -// } -// } else { -// stringBuffer.append(LS); -// } -// } -// -// private String value(Field field) { -// if( field.getName().equals("verb")) { -// return "\"post\""; -// } else if( field.getName().equals("objectType")) { -// return "\"application\""; -// } else return null; -// } -// -// private String type(Field field) { -// if( field.getType().equals(java.lang.String.class)) { -// return "STRING"; -// } else if( field.getType().equals(java.lang.Integer.class)) { -// return "INT"; -// } else if( field.getType().equals(org.joda.time.DateTime.class)) { -// return "DATE"; -// }else if( field.getType().equals(java.util.Map.class)) { -// return "MAP"; -// } else if( field.getType().equals(java.util.List.class)) { -// return "ARRAY"; -// } -// return field.getType().getCanonicalName().replace(".pojo.json", ".scala"); -// } -// -// private Map<String,Field> uniqueFields(Set<Field> fieldset) { -// Map<String,Field> fields = Maps.newTreeMap(); -// Field item = null; -// for( Iterator<Field> it = fieldset.iterator(); it.hasNext(); item = it.next() ) { -// if( item != null && item.getName() != null ) { -// Field added = fields.put(item.getName(), item); -// } -// // ensure right class will get used -// } -// return fields; -// } -// -// private String name(Field field) { -// if( field.getName().equals("object")) -// return "obj"; -// else return field.getName(); -// } -// -// private boolean override(Field field) { -// try { -// if( field.getDeclaringClass().getSuperclass().getField(field.getName()) != null ) -// return true; -// else return false; -// } catch( Exception e ) { -// return false; -// } -// } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-pojo/src/site/markdown/index.md ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-pojo/src/site/markdown/index.md b/streams-plugins/streams-plugin-pojo/src/site/markdown/index.md index d1bd848..996fa86 100644 --- a/streams-plugins/streams-plugin-pojo/src/site/markdown/index.md +++ b/streams-plugins/streams-plugin-pojo/src/site/markdown/index.md @@ -3,17 +3,33 @@ org.apache.streams.plugins:streams-plugin-pojo streams-plugin-pojo generates source files from json schemas suitable for writing Apache Streams components and libraries in Java. -#### Usage +### Usage + +Output will be placed in target/generated-sources/pojo by default + +##### Maven Run within a module containing a src/main/jsonschema directory mvn org.apache.streams.plugins:streams-plugin-pojo:0.3-incubating-SNAPSHOT:pojo -Output will be placed in target/generated-sources/pojo by default +[streams-plugin-pojo/pom.xml](streams-plugin-pojo/pom.xml "streams-plugin-pojo/pom.xml") -#### Example +##### SDK -[streams-plugin-pojo/pom.xml](streams-plugin-pojo/pom.xml "streams-plugin-pojo/pom.xml") +Embed within your own java code + + StreamsPojoGenerationConfig config = new StreamsPojoGenerationConfig(); + config.setSourceDirectory("src/main/jsonschema"); + config.setTargetDirectory("target/generated-resources"); + StreamsPojoSourceGenerator generator = new StreamsPojoSourceGenerator(config); + generator.run(); + +##### CLI + +Run from CLI without Maven + + java -jar streams-plugin-pojo-jar-with-dependencies.jar StreamsPojoSourceGenerator src/main/jsonschema target/generated-sources #### Documentation http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorCLITest.java ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorCLITest.java b/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorCLITest.java index f808b28..07049ed 100644 --- a/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorCLITest.java +++ b/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorCLITest.java @@ -23,7 +23,7 @@ public class StreamsPojoSourceGeneratorCLITest { @Test public void testStreamsPojoSourceGeneratorCLI() throws Exception { - String sourceDirectory = "target/test-classes/streams-schemas"; + String sourceDirectory = "target/test-classes/streams-schema-activitystreams"; String targetDirectory = "target/generated-sources/test-cli"; List<String> argsList = Lists.newArrayList(sourceDirectory, targetDirectory); http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorMojoTest.java ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorMojoTest.java b/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorMojoTest.java index 1968d90..41d762d 100644 --- a/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorMojoTest.java +++ b/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorMojoTest.java @@ -53,7 +53,7 @@ public class StreamsPojoSourceGeneratorMojoTest extends TestCase { verifier.resetStreams(); - File testOutput = new File(testDir.getAbsolutePath() + "/target/generated-sources/test-mojo"); + File testOutput = new File(testDir.getAbsolutePath() + "/target/generated-sources/pojo-mojo"); assert( testOutput != null ); assert( testOutput.exists() == true ); http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorTest.java ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorTest.java b/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorTest.java index 8d904af..6e7400e 100644 --- a/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorTest.java +++ b/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorTest.java @@ -43,53 +43,30 @@ public class StreamsPojoSourceGeneratorTest { StreamsPojoGenerationConfig config = new StreamsPojoGenerationConfig(); List<String> sourcePaths = Lists.newArrayList( - "target/test-classes/streams-schemas/activity.json", - "target/test-classes/streams-schemas/collection.json", - "target/test-classes/streams-schemas/media_link.json", - "target/test-classes/streams-schemas/object.json", - "target/test-classes/streams-schemas/objectTypes", - "target/test-classes/streams-schemas/verbs" + "target/test-classes/streams-schema-activitystreams/activity.json", + "target/test-classes/streams-schema-activitystreams/collection.json", + "target/test-classes/streams-schema-activitystreams/media_link.json", + "target/test-classes/streams-schema-activitystreams/object.json", + "target/test-classes/streams-schema-activitystreams/objectTypes", + "target/test-classes/streams-schema-activitystreams/verbs" ); config.setSourcePaths(sourcePaths); // config.setSourceDirectory("target/test-classes/streams-schemas"); - config.setTargetPackage("org.apache.streams.pojo.test"); - config.setTargetDirectory("target/generated-sources/test"); + config.setTargetPackage("org.apache.streams.pojo"); + config.setTargetDirectory("target/generated-sources/pojo"); StreamsPojoSourceGenerator streamsPojoSourceGenerator = new StreamsPojoSourceGenerator(config); - Thread thread = new Thread(streamsPojoSourceGenerator); - thread.start(); - try { - thread.join(); - } catch (InterruptedException e) { - LOGGER.error("InterruptedException", e); - } catch (Exception e) { - LOGGER.error("Exception", e); - } - - File testOutput = new File( "target/generated-sources/test"); + streamsPojoSourceGenerator.run(); - assert( testOutput != null ); - assert( testOutput.exists() == true ); - assert( testOutput.isDirectory() == true ); + assert( config.getTargetDirectory() != null ); + assert( config.getTargetDirectory().exists() == true ); + assert( config.getTargetDirectory().isDirectory() == true ); - Iterable<File> outputIterator = Files.fileTreeTraverser().breadthFirstTraversal(testOutput) + Iterable<File> outputIterator = Files.fileTreeTraverser().breadthFirstTraversal(config.getTargetDirectory()) .filter(javaFilter); Collection<File> outputCollection = Lists.newArrayList(outputIterator); assert( outputCollection.size() > 133 ); -// assert( testOutput.listFiles(javaFilter).length == 11 ); -// assert( new File(testOutput + "/traits").exists() == true ); -// assert( new File(testOutput + "/traits").isDirectory() == true ); -// assert( new File(testOutput + "/traits").listFiles(scalaFilter) != null ); -// assert( new File(testOutput + "/traits").listFiles(scalaFilter).length == 4 ); -// assert( new File(testOutput + "/objectTypes").exists() == true ); -// assert( new File(testOutput + "/objectTypes").isDirectory() == true ); -// assert( new File(testOutput + "/objectTypes").listFiles(scalaFilter) != null ); -// assert( new File(testOutput + "/objectTypes").listFiles(scalaFilter).length == 43 ); -// assert( new File(testO`utput + "/verbs").exists() == true ); -// assert( new File(testOutput + "/verbs").isDirectory() == true ); -// assert( new File(testOutput + "/verbs").listFiles(scalaFilter) != null ); -// assert( new File(testOutput + "/verbs").listFiles(scalaFilter).length == 89 ); - } + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-pojo/src/test/resources/streams-plugin-pojo/pom.xml ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-pojo/src/test/resources/streams-plugin-pojo/pom.xml b/streams-plugins/streams-plugin-pojo/src/test/resources/streams-plugin-pojo/pom.xml index 21fd50e..2ca3f7c 100644 --- a/streams-plugins/streams-plugin-pojo/src/test/resources/streams-plugin-pojo/pom.xml +++ b/streams-plugins/streams-plugin-pojo/src/test/resources/streams-plugin-pojo/pom.xml @@ -23,9 +23,15 @@ </dependency> <dependency> <groupId>org.apache.streams</groupId> - <artifactId>streams-schemas</artifactId> + <artifactId>streams-util</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.streams</groupId> + <artifactId>streams-schema-activitystreams</artifactId> <version>${project.version}</version> <scope>test</scope> + <type>test-jar</type> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> @@ -62,20 +68,20 @@ <version>0.3-incubating-SNAPSHOT</version> <configuration> <sourcePaths> - <sourcePath>target/test-classes/streams-schemas/activity.json</sourcePath> - <sourcePath>target/test-classes/streams-schemas/collection.json</sourcePath> - <sourcePath>target/test-classes/streams-schemas/media_link.json</sourcePath> - <sourcePath>target/test-classes/streams-schemas/object.json</sourcePath> - <sourcePath>target/test-classes/streams-schemas/objectTypes</sourcePath> - <sourcePath>target/test-classes/streams-schemas/verbs</sourcePath> + <sourcePath>target/test-classes/streams-schema-activitystreams/activity.json</sourcePath> + <sourcePath>target/test-classes/streams-schema-activitystreams/collection.json</sourcePath> + <sourcePath>target/test-classes/streams-schema-activitystreams/media_link.json</sourcePath> + <sourcePath>target/test-classes/streams-schema-activitystreams/object.json</sourcePath> + <sourcePath>target/test-classes/streams-schema-activitystreams/objectTypes</sourcePath> + <sourcePath>target/test-classes/streams-schema-activitystreams/verbs</sourcePath> </sourcePaths> - <targetPackage>org.apache.streams.pojo.testmojo</targetPackage> - <targetDirectory>target/generated-sources/test-mojo</targetDirectory> + <targetPackage>org.apache.streams.pojo.mojo</targetPackage> + <targetDirectory>target/generated-sources/pojo-mojo</targetDirectory> </configuration> <executions> <execution> <goals> - <goal>pojo</goal> + <goal>generate-sources</goal> </goals> </execution> </executions> @@ -86,9 +92,9 @@ <version>2.10</version> <configuration> <includes>**/*.json</includes> - <outputDirectory>${project.build.directory}/test-classes/streams-schemas</outputDirectory> + <outputDirectory>${project.build.directory}/test-classes/streams-schema-activitystreams</outputDirectory> <includeGroupIds>org.apache.streams</includeGroupIds> - <includeArtifactIds>streams-schemas</includeArtifactIds> + <includeArtifactIds>streams-schema-activitystreams</includeArtifactIds> <includeTypes>jar,test-jar</includeTypes> </configuration> <executions> http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-scala/pom.xml ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-scala/pom.xml b/streams-plugins/streams-plugin-scala/pom.xml index f718260..3988142 100644 --- a/streams-plugins/streams-plugin-scala/pom.xml +++ b/streams-plugins/streams-plugin-scala/pom.xml @@ -42,6 +42,18 @@ <version>${project.version}</version> </dependency> <dependency> + <groupId>org.apache.streams</groupId> + <artifactId>streams-util</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.streams</groupId> + <artifactId>streams-schema-activitystreams</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.jsonschema2pojo</groupId> <artifactId>jsonschema2pojo-core</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsPojoScala.java ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsPojoScala.java b/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsPojoScala.java deleted file mode 100644 index 1c3e317..0000000 --- a/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsPojoScala.java +++ /dev/null @@ -1,371 +0,0 @@ -package org.apache.streams.plugins; - -import com.google.common.base.Strings; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import org.apache.streams.data.DocumentClassifier; -import org.reflections.ReflectionUtils; -import org.reflections.Reflections; -import org.reflections.scanners.SubTypesScanner; -import org.reflections.scanners.TypeAnnotationsScanner; -import org.reflections.util.ClasspathHelper; -import org.reflections.util.ConfigurationBuilder; -import org.reflections.ReflectionUtils.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.Generated; -import java.io.File; -import java.io.IOException; -import java.io.Serializable; -import java.lang.reflect.Field; -import java.nio.file.Files; -import java.nio.file.OpenOption; -import java.nio.file.Paths; -import java.nio.file.StandardOpenOption; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Created by sblackmon on 11/18/15. - */ -public class StreamsPojoScala implements Runnable { - - private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPojoScala.class); - - private final static String LS = System.getProperty("line.separator"); - - private StreamsPojoScalaMojo mojo; - - String outDir = "./target/generated-sources/scala"; - String packages = "org.apache.streams.pojo.json"; - - private final Reflections reflections = new Reflections( - new ConfigurationBuilder() - // TODO - .forPackages(packages) - .setScanners( - new SubTypesScanner(), - new TypeAnnotationsScanner())); - - public void main(String[] args) { - StreamsPojoScala streamsPojoScala = new StreamsPojoScala(); - Thread thread = new Thread(streamsPojoScala); - thread.start(); - try { - thread.join(); - } catch (InterruptedException e) { - LOGGER.error("InterruptedException", e); - } catch (Exception e) { - LOGGER.error("Exception", e); - } - return; - } - - public StreamsPojoScala(StreamsPojoScalaMojo mojo) { - this.mojo = mojo; - if ( mojo != null && - mojo.getTarget() != null && - !Strings.isNullOrEmpty(mojo.getTarget().getAbsolutePath()) - ) - outDir = mojo.getTarget().getAbsolutePath(); - - if ( mojo != null && - mojo.getPackages() != null && - !Strings.isNullOrEmpty(mojo.getPackages()) - ) - packages = mojo.getPackages(); - } - - public StreamsPojoScala() { - } - - public void run() { - - List<Class<?>> serializableClasses = detectSerializableClasses(); - - LOGGER.info("Detected {} serialiables:", serializableClasses.size()); - for( Class clazz : serializableClasses ) - LOGGER.debug(clazz.toString()); - - List<Class<?>> pojoClasses = detectPojoClasses(serializableClasses); - - LOGGER.info("Detected {} pojos:", pojoClasses.size()); - for( Class clazz : pojoClasses ) - LOGGER.debug(clazz.toString()); - - List<Class<?>> traits = detectTraits(pojoClasses); - - LOGGER.info("Detected {} traits:", traits.size()); - for( Class clazz : traits ) - LOGGER.debug(clazz.toString()); - - List<Class<?>> cases = detectCases(pojoClasses); - - LOGGER.info("Detected {} cases:", cases.size()); - for( Class clazz : cases ) - LOGGER.debug(clazz.toString()); - - - for( Class clazz : traits ) { - String pojoPath = clazz.getPackage().getName().replace(".pojo.json", ".scala").replace(".","/")+"/traits/"; - String pojoName = clazz.getSimpleName()+".scala"; - String pojoScala = renderTrait(clazz); - writeFile(outDir+"/"+pojoPath+pojoName, pojoScala); - } - - for( Class clazz : traits ) { - String pojoPath = clazz.getPackage().getName().replace(".pojo.json", ".scala").replace(".","/")+"/"; - String pojoName = clazz.getSimpleName()+".scala"; - String pojoScala = renderClass(clazz); - writeFile(outDir+"/"+pojoPath+pojoName, pojoScala); - } - - for( Class clazz : cases ) { - String pojoPath = clazz.getPackage().getName().replace(".pojo.json", ".scala").replace(".","/")+"/"; - String pojoName = clazz.getSimpleName()+".scala"; - String pojoScala = renderCase(clazz); - writeFile(outDir+"/"+pojoPath+pojoName, pojoScala); - } - - } - - private void writeFile(String pojoFile, String pojoScala) { - try { - File path = new File(pojoFile); - File dir = path.getParentFile(); - if( !dir.exists() ) - dir.mkdirs(); - Files.write(Paths.get(pojoFile), pojoScala.getBytes(), StandardOpenOption.CREATE_NEW); - } catch (Exception e) { - LOGGER.error("Write Exception: {}", e); - } - } - - public List<Class<?>> detectSerializableClasses() { - - Set<Class<? extends Serializable>> classes = - reflections.getSubTypesOf(java.io.Serializable.class); - - List<Class<?>> result = Lists.newArrayList(); - - for( Class clazz : classes ) { - result.add(clazz); - } - - return result; - } - - public List<Class<?>> detectPojoClasses(List<Class<?>> classes) { - - List<Class<?>> result = Lists.newArrayList(); - - for( Class clazz : classes ) { - try { - clazz.newInstance().toString(); - } catch( Exception e) {} - // super-halfass way to know if this is a jsonschema2pojo - if( clazz.getAnnotations().length >= 1 ) - result.add(clazz); - } - - return result; - } - - public List<Class<?>> detectTraits(List<Class<?>> classes) { - - List<Class<?>> traits = Lists.newArrayList(); - - for( Class clazz : classes ) { - if (reflections.getSubTypesOf(clazz).size() > 0) - traits.add(clazz); - } - - return traits; - } - - public List<Class<?>> detectCases(List<Class<?>> classes) { - - List<Class<?>> cases = Lists.newArrayList(); - - for( Class clazz : classes ) { - if (reflections.getSubTypesOf(clazz).size() == 0) - cases.add(clazz); - } - - return cases; - } - - - public String renderTrait(Class<?> pojoClass) { - StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append("package "); - stringBuffer.append(pojoClass.getPackage().getName().replace(".pojo.json", ".scala")); - stringBuffer.append(".traits"); - stringBuffer.append(LS); - stringBuffer.append("trait "+pojoClass.getSimpleName()); - stringBuffer.append(" extends Serializable"); - stringBuffer.append(" {"); - - Set<Field> fields = ReflectionUtils.getAllFields(pojoClass); - appendFields(stringBuffer, fields, "def", ";"); - - stringBuffer.append("}"); - - return stringBuffer.toString(); - } - - public String renderClass(Class<?> pojoClass) { - StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append("package "); - stringBuffer.append(pojoClass.getPackage().getName().replace(".pojo.json", ".scala")); - stringBuffer.append(LS); - stringBuffer.append("import org.apache.commons.lang.builder.{HashCodeBuilder, EqualsBuilder, ToStringBuilder}"); - stringBuffer.append(LS); - stringBuffer.append("class "+pojoClass.getSimpleName()); - stringBuffer.append(" ("); - - Set<Field> fields = ReflectionUtils.getAllFields(pojoClass); - appendFields(stringBuffer, fields, "var", ","); - - stringBuffer.append(")"); - stringBuffer.append(" extends "+pojoClass.getPackage().getName().replace(".pojo.json", ".scala")+".traits."+pojoClass.getSimpleName()); - stringBuffer.append(" with Serializable "); - stringBuffer.append("{ "); - stringBuffer.append(LS); - stringBuffer.append("override def equals(obj: Any) = obj match { "); - stringBuffer.append(LS); - stringBuffer.append(" case other: "); - stringBuffer.append(pojoClass.getSimpleName()); - stringBuffer.append(" => other.getClass == getClass && EqualsBuilder.reflectionEquals(this,obj)"); - stringBuffer.append(LS); - stringBuffer.append(" case _ => false"); - stringBuffer.append(LS); - stringBuffer.append("}"); - stringBuffer.append(LS); - stringBuffer.append("override def hashCode = new HashCodeBuilder().hashCode"); - stringBuffer.append(LS); - stringBuffer.append("}"); - - return stringBuffer.toString(); - } - - public String renderCase(Class<?> pojoClass) { - StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append("package "); - stringBuffer.append(pojoClass.getPackage().getName().replace(".pojo.json", ".scala")); - stringBuffer.append(LS); - stringBuffer.append("case class "+pojoClass.getSimpleName()); - stringBuffer.append("("); - Set<Field> fields = ReflectionUtils.getAllFields(pojoClass); - appendFields(stringBuffer, fields, "var", ","); - stringBuffer.append(")"); - if( pojoClass.getSuperclass() != null && !pojoClass.getSuperclass().equals(java.lang.Object.class)) { - stringBuffer.append(" extends "+pojoClass.getSuperclass().getPackage().getName().replace(".pojo.json", ".scala")+".traits."+pojoClass.getSuperclass().getSimpleName()); - } - stringBuffer.append(LS); - - return stringBuffer.toString(); - } - - private void appendFields(StringBuffer stringBuffer, Set<Field> fields, String varDef, String fieldDelimiter) { - if( fields.size() > 0 ) { - stringBuffer.append(LS); - Map<String,Field> fieldsToAppend = uniqueFields(fields); - for( Iterator<Field> iter = fieldsToAppend.values().iterator(); iter.hasNext(); ) { - Field field = iter.next(); - if( override( field ) ) - stringBuffer.append("override "); - stringBuffer.append(varDef); - stringBuffer.append(" "); - stringBuffer.append(name(field)); - stringBuffer.append(": "); - if( option(field) ) { - stringBuffer.append("scala.Option["); - stringBuffer.append(type(field)); - stringBuffer.append("]"); - } else { - stringBuffer.append(type(field)); - } - if( !fieldDelimiter.equals(";") && value(field) != null) { - stringBuffer.append(" = "); - if( option(field) ) { - stringBuffer.append("scala.Some("); - stringBuffer.append(value(field)); - stringBuffer.append(")"); - } else { - stringBuffer.append(value(field)); - } - } - if( iter.hasNext()) stringBuffer.append(fieldDelimiter); - stringBuffer.append(LS); - } - } else { - stringBuffer.append(LS); - } - } - - private boolean option(Field field) { - if( field.getName().equals("verb")) { - return false; - } else if( field.getType().equals(java.util.Map.class)) { - return false; - } else if( field.getType().equals(java.util.List.class)) { - return false; - } else return true; - } - - private String value(Field field) { - if( field.getName().equals("verb")) { - return "\"post\""; - } else if( field.getName().equals("objectType")) { - return "\"application\""; - } else return null; - } - - private String type(Field field) { - if( field.getType().equals(java.lang.String.class)) { - return "String"; - } else if( field.getType().equals(java.util.Map.class)) { - return "scala.collection.mutable.Map[String,Any]"; - } else if( field.getType().equals(java.util.List.class)) { - return "scala.collection.mutable.MutableList[Any]"; - } - return field.getType().getCanonicalName().replace(".pojo.json", ".scala"); - } - - private Map<String,Field> uniqueFields(Set<Field> fieldset) { - Map<String,Field> fields = Maps.newTreeMap(); - Field item = null; - for( Iterator<Field> it = fieldset.iterator(); it.hasNext(); item = it.next() ) { - if( item != null && item.getName() != null ) { - Field added = fields.put(item.getName(), item); - } - // ensure right class will get used - } - return fields; - } - - private String name(Field field) { - if( field.getName().equals("object")) - return "obj"; - else return field.getName(); - } - - private boolean override(Field field) { - try { - if( field.getDeclaringClass().getSuperclass().getField(field.getName()) != null ) - return true; - else return false; - } catch( Exception e ) { - return false; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsPojoScalaMojo.java ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsPojoScalaMojo.java b/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsPojoScalaMojo.java deleted file mode 100644 index baa0f50..0000000 --- a/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsPojoScalaMojo.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.apache.streams.plugins; - -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.Execute; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; -import org.apache.maven.settings.Settings; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; - -@Mojo( name = "scala", - defaultPhase = LifecyclePhase.GENERATE_SOURCES -) -@Execute( goal = "scala", - phase = LifecyclePhase.GENERATE_SOURCES -) -public class StreamsPojoScalaMojo extends AbstractMojo { - - private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPojoScalaMojo.class); - - @Component - private MavenProject project; - -// @Component -// private Settings settings; -// -// @Parameter( defaultValue = "${localRepository}", readonly = true, required = true ) -// protected ArtifactRepository localRepository; -// -// @Parameter( defaultValue = "${plugin}", readonly = true ) // Maven 3 only -// private PluginDescriptor plugin; -// - @Parameter( defaultValue = "${project.basedir}", readonly = true ) - private File basedir; - - @Parameter(defaultValue = "${project.build.directory}", readonly = true) - private File target; - - @Parameter(defaultValue = "org.apache.streams.pojo.json", readonly = true) - private String packages; - - public void execute() throws MojoExecutionException { - StreamsPojoScala streamsPojoScala = new StreamsPojoScala(this); - Thread thread = new Thread(streamsPojoScala); - thread.start(); - try { - thread.join(); - } catch (InterruptedException e) { - LOGGER.error("InterruptedException", e); - } catch (Exception e) { - LOGGER.error("Exception", e); - } - return; - } - - public File getTarget() { - return target; - } - - public String getPackages() { - return packages; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsScalaSourceGenerator.java ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsScalaSourceGenerator.java b/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsScalaSourceGenerator.java new file mode 100644 index 0000000..7199be3 --- /dev/null +++ b/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsScalaSourceGenerator.java @@ -0,0 +1,351 @@ +package org.apache.streams.plugins; + +import com.google.common.base.Strings; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.reflections.ReflectionUtils; +import org.reflections.Reflections; +import org.reflections.scanners.SubTypesScanner; +import org.reflections.scanners.TypeAnnotationsScanner; +import org.reflections.util.ConfigurationBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.Serializable; +import java.lang.reflect.Field; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Created by sblackmon on 11/18/15. + */ +public class StreamsScalaSourceGenerator implements Runnable { + + private final static Logger LOGGER = LoggerFactory.getLogger(StreamsScalaSourceGenerator.class); + + private final static String LS = System.getProperty("line.separator"); + + private StreamsScalaSourceGeneratorMojo mojo; + + String outDir = "./target/generated-sources/scala"; + String packages = "org.apache.streams.pojo.json"; + + private final Reflections reflections = new Reflections( + new ConfigurationBuilder() + // TODO + .forPackages(packages) + .setScanners( + new SubTypesScanner(), + new TypeAnnotationsScanner())); + + public void main(String[] args) { + StreamsScalaSourceGenerator streamsScalaSourceGenerator = new StreamsScalaSourceGenerator(); + streamsScalaSourceGenerator.run(); + } + + public StreamsScalaSourceGenerator(StreamsScalaSourceGeneratorMojo mojo) { + this.mojo = mojo; + if ( mojo != null && + mojo.getTarget() != null && + !Strings.isNullOrEmpty(mojo.getTarget().getAbsolutePath()) + ) + outDir = mojo.getTarget().getAbsolutePath(); + + if ( mojo != null && + mojo.getPackages() != null && + !Strings.isNullOrEmpty(mojo.getPackages()) + ) + packages = mojo.getPackages(); + } + + public StreamsScalaSourceGenerator() { + } + + public void run() { + + List<Class<?>> serializableClasses = detectSerializableClasses(); + + LOGGER.info("Detected {} serialiables:", serializableClasses.size()); + for( Class clazz : serializableClasses ) + LOGGER.debug(clazz.toString()); + + List<Class<?>> pojoClasses = detectPojoClasses(serializableClasses); + + LOGGER.info("Detected {} pojos:", pojoClasses.size()); + for( Class clazz : pojoClasses ) + LOGGER.debug(clazz.toString()); + + List<Class<?>> traits = detectTraits(pojoClasses); + + LOGGER.info("Detected {} traits:", traits.size()); + for( Class clazz : traits ) + LOGGER.debug(clazz.toString()); + + List<Class<?>> cases = detectCases(pojoClasses); + + LOGGER.info("Detected {} cases:", cases.size()); + for( Class clazz : cases ) + LOGGER.debug(clazz.toString()); + + + for( Class clazz : traits ) { + String pojoPath = clazz.getPackage().getName().replace(".pojo.json", ".scala").replace(".","/")+"/traits/"; + String pojoName = clazz.getSimpleName()+".scala"; + String pojoScala = renderTrait(clazz); + writeFile(outDir+"/"+pojoPath+pojoName, pojoScala); + } + + for( Class clazz : traits ) { + String pojoPath = clazz.getPackage().getName().replace(".pojo.json", ".scala").replace(".","/")+"/"; + String pojoName = clazz.getSimpleName()+".scala"; + String pojoScala = renderClass(clazz); + writeFile(outDir+"/"+pojoPath+pojoName, pojoScala); + } + + for( Class clazz : cases ) { + String pojoPath = clazz.getPackage().getName().replace(".pojo.json", ".scala").replace(".","/")+"/"; + String pojoName = clazz.getSimpleName()+".scala"; + String pojoScala = renderCase(clazz); + writeFile(outDir+"/"+pojoPath+pojoName, pojoScala); + } + + } + + private void writeFile(String pojoFile, String pojoScala) { + try { + File path = new File(pojoFile); + File dir = path.getParentFile(); + if( !dir.exists() ) + dir.mkdirs(); + Files.write(Paths.get(pojoFile), pojoScala.getBytes(), StandardOpenOption.CREATE_NEW); + } catch (Exception e) { + LOGGER.error("Write Exception: {}", e); + } + } + + public List<Class<?>> detectSerializableClasses() { + + Set<Class<? extends Serializable>> classes = + reflections.getSubTypesOf(java.io.Serializable.class); + + List<Class<?>> result = Lists.newArrayList(); + + for( Class clazz : classes ) { + result.add(clazz); + } + + return result; + } + + public List<Class<?>> detectPojoClasses(List<Class<?>> classes) { + + List<Class<?>> result = Lists.newArrayList(); + + for( Class clazz : classes ) { + try { + clazz.newInstance().toString(); + } catch( Exception e) {} + // super-halfass way to know if this is a jsonschema2pojo + if( clazz.getAnnotations().length >= 1 ) + result.add(clazz); + } + + return result; + } + + public List<Class<?>> detectTraits(List<Class<?>> classes) { + + List<Class<?>> traits = Lists.newArrayList(); + + for( Class clazz : classes ) { + if (reflections.getSubTypesOf(clazz).size() > 0) + traits.add(clazz); + } + + return traits; + } + + public List<Class<?>> detectCases(List<Class<?>> classes) { + + List<Class<?>> cases = Lists.newArrayList(); + + for( Class clazz : classes ) { + if (reflections.getSubTypesOf(clazz).size() == 0) + cases.add(clazz); + } + + return cases; + } + + + public String renderTrait(Class<?> pojoClass) { + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("package "); + stringBuffer.append(pojoClass.getPackage().getName().replace(".pojo.json", ".scala")); + stringBuffer.append(".traits"); + stringBuffer.append(LS); + stringBuffer.append("trait "+pojoClass.getSimpleName()); + stringBuffer.append(" extends Serializable"); + stringBuffer.append(" {"); + + Set<Field> fields = ReflectionUtils.getAllFields(pojoClass); + appendFields(stringBuffer, fields, "def", ";"); + + stringBuffer.append("}"); + + return stringBuffer.toString(); + } + + public String renderClass(Class<?> pojoClass) { + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("package "); + stringBuffer.append(pojoClass.getPackage().getName().replace(".pojo.json", ".scala")); + stringBuffer.append(LS); + stringBuffer.append("import org.apache.commons.lang.builder.{HashCodeBuilder, EqualsBuilder, ToStringBuilder}"); + stringBuffer.append(LS); + stringBuffer.append("class "+pojoClass.getSimpleName()); + stringBuffer.append(" ("); + + Set<Field> fields = ReflectionUtils.getAllFields(pojoClass); + appendFields(stringBuffer, fields, "var", ","); + + stringBuffer.append(")"); + stringBuffer.append(" extends "+pojoClass.getPackage().getName().replace(".pojo.json", ".scala")+".traits."+pojoClass.getSimpleName()); + stringBuffer.append(" with Serializable "); + stringBuffer.append("{ "); + stringBuffer.append(LS); + stringBuffer.append("override def equals(obj: Any) = obj match { "); + stringBuffer.append(LS); + stringBuffer.append(" case other: "); + stringBuffer.append(pojoClass.getSimpleName()); + stringBuffer.append(" => other.getClass == getClass && EqualsBuilder.reflectionEquals(this,obj)"); + stringBuffer.append(LS); + stringBuffer.append(" case _ => false"); + stringBuffer.append(LS); + stringBuffer.append("}"); + stringBuffer.append(LS); + stringBuffer.append("override def hashCode = new HashCodeBuilder().hashCode"); + stringBuffer.append(LS); + stringBuffer.append("}"); + + return stringBuffer.toString(); + } + + public String renderCase(Class<?> pojoClass) { + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("package "); + stringBuffer.append(pojoClass.getPackage().getName().replace(".pojo.json", ".scala")); + stringBuffer.append(LS); + stringBuffer.append("case class "+pojoClass.getSimpleName()); + stringBuffer.append("("); + Set<Field> fields = ReflectionUtils.getAllFields(pojoClass); + appendFields(stringBuffer, fields, "var", ","); + stringBuffer.append(")"); + if( pojoClass.getSuperclass() != null && !pojoClass.getSuperclass().equals(java.lang.Object.class)) { + stringBuffer.append(" extends "+pojoClass.getSuperclass().getPackage().getName().replace(".pojo.json", ".scala")+".traits."+pojoClass.getSuperclass().getSimpleName()); + } + stringBuffer.append(LS); + + return stringBuffer.toString(); + } + + private void appendFields(StringBuffer stringBuffer, Set<Field> fields, String varDef, String fieldDelimiter) { + if( fields.size() > 0 ) { + stringBuffer.append(LS); + Map<String,Field> fieldsToAppend = uniqueFields(fields); + for( Iterator<Field> iter = fieldsToAppend.values().iterator(); iter.hasNext(); ) { + Field field = iter.next(); + if( override( field ) ) + stringBuffer.append("override "); + stringBuffer.append(varDef); + stringBuffer.append(" "); + stringBuffer.append(name(field)); + stringBuffer.append(": "); + if( option(field) ) { + stringBuffer.append("scala.Option["); + stringBuffer.append(type(field)); + stringBuffer.append("]"); + } else { + stringBuffer.append(type(field)); + } + if( !fieldDelimiter.equals(";") && value(field) != null) { + stringBuffer.append(" = "); + if( option(field) ) { + stringBuffer.append("scala.Some("); + stringBuffer.append(value(field)); + stringBuffer.append(")"); + } else { + stringBuffer.append(value(field)); + } + } + if( iter.hasNext()) stringBuffer.append(fieldDelimiter); + stringBuffer.append(LS); + } + } else { + stringBuffer.append(LS); + } + } + + private boolean option(Field field) { + if( field.getName().equals("verb")) { + return false; + } else if( field.getType().equals(java.util.Map.class)) { + return false; + } else if( field.getType().equals(java.util.List.class)) { + return false; + } else return true; + } + + private String value(Field field) { + if( field.getName().equals("verb")) { + return "\"post\""; + } else if( field.getName().equals("objectType")) { + return "\"application\""; + } else return null; + } + + private String type(Field field) { + if( field.getType().equals(java.lang.String.class)) { + return "String"; + } else if( field.getType().equals(java.util.Map.class)) { + return "scala.collection.mutable.Map[String,Any]"; + } else if( field.getType().equals(java.util.List.class)) { + return "scala.collection.mutable.MutableList[Any]"; + } + return field.getType().getCanonicalName().replace(".pojo.json", ".scala"); + } + + private Map<String,Field> uniqueFields(Set<Field> fieldset) { + Map<String,Field> fields = Maps.newTreeMap(); + Field item = null; + for( Iterator<Field> it = fieldset.iterator(); it.hasNext(); item = it.next() ) { + if( item != null && item.getName() != null ) { + Field added = fields.put(item.getName(), item); + } + // ensure right class will get used + } + return fields; + } + + private String name(Field field) { + if( field.getName().equals("object")) + return "obj"; + else return field.getName(); + } + + private boolean override(Field field) { + try { + if( field.getDeclaringClass().getSuperclass().getField(field.getName()) != null ) + return true; + else return false; + } catch( Exception e ) { + return false; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsScalaSourceGeneratorMojo.java ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsScalaSourceGeneratorMojo.java b/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsScalaSourceGeneratorMojo.java new file mode 100644 index 0000000..8d85c90 --- /dev/null +++ b/streams-plugins/streams-plugin-scala/src/main/java/org/apache/streams/plugins/StreamsScalaSourceGeneratorMojo.java @@ -0,0 +1,59 @@ +package org.apache.streams.plugins; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; + +@Mojo( name = "scala", + defaultPhase = LifecyclePhase.GENERATE_SOURCES +) +@Execute( goal = "scala", + phase = LifecyclePhase.GENERATE_SOURCES +) +public class StreamsScalaSourceGeneratorMojo extends AbstractMojo { + + private final static Logger LOGGER = LoggerFactory.getLogger(StreamsScalaSourceGeneratorMojo.class); + + @Component + private MavenProject project; + +// @Component +// private Settings settings; +// +// @Parameter( defaultValue = "${localRepository}", readonly = true, required = true ) +// protected ArtifactRepository localRepository; +// +// @Parameter( defaultValue = "${plugin}", readonly = true ) // Maven 3 only +// private PluginDescriptor plugin; +// + @Parameter( defaultValue = "${project.basedir}", readonly = true ) + private File basedir; + + @Parameter(defaultValue = "${project.build.directory}", readonly = true) + private File target; + + @Parameter(defaultValue = "org.apache.streams.pojo.json", readonly = true) + private String packages; + + public void execute() throws MojoExecutionException { + StreamsScalaSourceGenerator streamsScalaSourceGenerator = new StreamsScalaSourceGenerator(this); + streamsScalaSourceGenerator.run(); + } + + public File getTarget() { + return target; + } + + public String getPackages() { + return packages; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-scala/src/site/markdown/index.md ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-scala/src/site/markdown/index.md b/streams-plugins/streams-plugin-scala/src/site/markdown/index.md new file mode 100644 index 0000000..34f94f5 --- /dev/null +++ b/streams-plugins/streams-plugin-scala/src/site/markdown/index.md @@ -0,0 +1,36 @@ +org.apache.streams.plugins:streams-plugin-scala +============================================= + +streams-plugin-scala generates source files from json schemas suitable for writing Apache Streams components and libraries in Scala. + +### Usage + +##### Maven + +Run within a module containing a src/main/jsonschema directory + + mvn org.apache.streams.plugins:streams-plugin-scala:0.3-incubating-SNAPSHOT:pig + +[streams-plugin-scala/pom.xml](streams-plugin-scala/pom.xml "streams-plugin-scala/pom.xml") + +##### SDK + +Embed within your own java code + + StreamsScalaGenerationConfig config = new StreamsScalaGenerationConfig(); + config.setSourceDirectory("src/main/jsonschema"); + config.setTargetDirectory("target/generated-resources"); + StreamsScalaSourceGenerator generator = new StreamsScalaSourceGenerator(config); + generator.run(); + +##### CLI + +Run from CLI without Maven + + java -jar streams-plugin-scala-jar-with-dependencies.jar StreamsScalaSourceGenerator src/main/jsonschema target/generated-sources + +#### Documentation + +[JavaDocs](apidocs/index.html "JavaDocs") + +###### Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-scala/src/test/java/org/apache/streams/plugins/test/StreamsPojoScalaTest.java ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-scala/src/test/java/org/apache/streams/plugins/test/StreamsPojoScalaTest.java b/streams-plugins/streams-plugin-scala/src/test/java/org/apache/streams/plugins/test/StreamsPojoScalaTest.java deleted file mode 100644 index 4e5e7e3..0000000 --- a/streams-plugins/streams-plugin-scala/src/test/java/org/apache/streams/plugins/test/StreamsPojoScalaTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.apache.streams.plugins.test; - -import org.apache.streams.plugins.StreamsPojoScala; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.FileFilter; - -/** - * Test that Activity beans are compatible with the example activities in the spec. - */ -public class StreamsPojoScalaTest { - - private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPojoScalaTest.class); - - /** - * Tests that all example activities can be loaded into Activity beans - * - * @throws Exception - */ - @Test - public void testDetectPojoScala() throws Exception { - StreamsPojoScala streamsPojoScala = new StreamsPojoScala(); - streamsPojoScala.main(new String[0]); - - File testOutput = new File( "./target/generated-sources/scala/org/apache/streams/scala"); - FileFilter scalaFilter = new FileFilter() { - @Override - public boolean accept(File pathname) { - if( pathname.getName().endsWith(".scala") ) - return true; - return false; - } - }; - - assert( testOutput != null ); - assert( testOutput.exists() == true ); - assert( testOutput.isDirectory() == true ); - assert( testOutput.listFiles(scalaFilter).length == 11 ); - assert( new File(testOutput + "/traits").exists() == true ); - assert( new File(testOutput + "/traits").isDirectory() == true ); - assert( new File(testOutput + "/traits").listFiles(scalaFilter) != null ); - assert( new File(testOutput + "/traits").listFiles(scalaFilter).length == 4 ); - assert( new File(testOutput + "/objectTypes").exists() == true ); - assert( new File(testOutput + "/objectTypes").isDirectory() == true ); - assert( new File(testOutput + "/objectTypes").listFiles(scalaFilter) != null ); - assert( new File(testOutput + "/objectTypes").listFiles(scalaFilter).length == 43 ); - assert( new File(testOutput + "/verbs").exists() == true ); - assert( new File(testOutput + "/verbs").isDirectory() == true ); - assert( new File(testOutput + "/verbs").listFiles(scalaFilter) != null ); - assert( new File(testOutput + "/verbs").listFiles(scalaFilter).length == 89 ); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-plugins/streams-plugin-scala/src/test/java/org/apache/streams/plugins/test/StreamsScalaSourceGeneratorTest.java ---------------------------------------------------------------------- diff --git a/streams-plugins/streams-plugin-scala/src/test/java/org/apache/streams/plugins/test/StreamsScalaSourceGeneratorTest.java b/streams-plugins/streams-plugin-scala/src/test/java/org/apache/streams/plugins/test/StreamsScalaSourceGeneratorTest.java new file mode 100644 index 0000000..65e496f --- /dev/null +++ b/streams-plugins/streams-plugin-scala/src/test/java/org/apache/streams/plugins/test/StreamsScalaSourceGeneratorTest.java @@ -0,0 +1,55 @@ +package org.apache.streams.plugins.test; + +import org.apache.streams.plugins.StreamsScalaSourceGenerator; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileFilter; + +/** + * Test that Activity beans are compatible with the example activities in the spec. + */ +public class StreamsScalaSourceGeneratorTest { + + private final static Logger LOGGER = LoggerFactory.getLogger(StreamsScalaSourceGeneratorTest.class); + + /** + * Tests that all example activities can be loaded into Activity beans + * + * @throws Exception + */ + @Test + public void testDetectPojoScala() throws Exception { + StreamsScalaSourceGenerator streamsScalaSourceGenerator = new StreamsScalaSourceGenerator(); + streamsScalaSourceGenerator.main(new String[0]); + + File testOutput = new File( "./target/generated-sources/scala/org/apache/streams/scala"); + FileFilter scalaFilter = new FileFilter() { + @Override + public boolean accept(File pathname) { + if( pathname.getName().endsWith(".scala") ) + return true; + return false; + } + }; + + assert( testOutput != null ); + assert( testOutput.exists() == true ); + assert( testOutput.isDirectory() == true ); + assert( testOutput.listFiles(scalaFilter).length == 11 ); + assert( new File(testOutput + "/traits").exists() == true ); + assert( new File(testOutput + "/traits").isDirectory() == true ); + assert( new File(testOutput + "/traits").listFiles(scalaFilter) != null ); + assert( new File(testOutput + "/traits").listFiles(scalaFilter).length == 4 ); + assert( new File(testOutput + "/objectTypes").exists() == true ); + assert( new File(testOutput + "/objectTypes").isDirectory() == true ); + assert( new File(testOutput + "/objectTypes").listFiles(scalaFilter) != null ); + assert( new File(testOutput + "/objectTypes").listFiles(scalaFilter).length == 43 ); + assert( new File(testOutput + "/verbs").exists() == true ); + assert( new File(testOutput + "/verbs").isDirectory() == true ); + assert( new File(testOutput + "/verbs").listFiles(scalaFilter) != null ); + assert( new File(testOutput + "/verbs").listFiles(scalaFilter).length == 89 ); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-runtimes/streams-runtime-dropwizard/pom.xml ---------------------------------------------------------------------- diff --git a/streams-runtimes/streams-runtime-dropwizard/pom.xml b/streams-runtimes/streams-runtime-dropwizard/pom.xml index 94c3a3e..6574637 100644 --- a/streams-runtimes/streams-runtime-dropwizard/pom.xml +++ b/streams-runtimes/streams-runtime-dropwizard/pom.xml @@ -223,7 +223,7 @@ <addCompileSourceRoot>true</addCompileSourceRoot> <generateBuilders>true</generateBuilders> <sourcePaths> - <sourcePath>src/main/jsonschema</sourcePath> + <sourcePath>${project.basedir}/src/main/jsonschema</sourcePath> </sourcePaths> <outputDirectory>target/generated-sources/jsonschema2pojo</outputDirectory> <targetPackage>org.apache.streams.dropwizard</targetPackage> http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-runtimes/streams-runtime-local/pom.xml ---------------------------------------------------------------------- diff --git a/streams-runtimes/streams-runtime-local/pom.xml b/streams-runtimes/streams-runtime-local/pom.xml index dbde89f..d8fae26 100644 --- a/streams-runtimes/streams-runtime-local/pom.xml +++ b/streams-runtimes/streams-runtime-local/pom.xml @@ -137,7 +137,7 @@ <addCompileSourceRoot>true</addCompileSourceRoot> <generateBuilders>true</generateBuilders> <sourcePaths> - <sourcePath>src/main/jsonschema/LocalRuntimeConfiguration.json</sourcePath> + <sourcePath>${project.basedir}/src/main/jsonschema</sourcePath> </sourcePaths> <outputDirectory>target/generated-sources/jsonschema2pojo</outputDirectory> <targetPackage>org.apache.streams.local</targetPackage> http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-schemas/pom.xml ---------------------------------------------------------------------- diff --git a/streams-schemas/pom.xml b/streams-schemas/pom.xml index 0625cb6..dbfd719 100644 --- a/streams-schemas/pom.xml +++ b/streams-schemas/pom.xml @@ -28,79 +28,12 @@ <artifactId>streams-schemas</artifactId> <name>${project.artifactId}</name> + <packaging>pom</packaging> - <description>Activity Streams schemas and schema utilities</description> + <description>Aggregator for schema modules</description> - <dependencies> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - </dependency> - <dependency> - <groupId>org.jsonschema2pojo</groupId> - <artifactId>jsonschema2pojo-core</artifactId> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - </dependency> + <modules> + <module>streams-schema-activitystreams</module> + </modules> - </dependencies> - <build> - <sourceDirectory>src/main/java</sourceDirectory> - <testSourceDirectory>src/test/java</testSourceDirectory> - <resources> - <resource> - <directory>src/main/resources</directory> - </resource> - </resources> - <testResources> - <testResource> - <directory>src/test/resources</directory> - </testResource> - </testResources> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <executions> - <execution> - <id>add-source</id> - <phase>generate-sources</phase> - <goals> - <goal>add-resource</goal> - </goals> - <configuration> - <resources> - <resource> - <directory>src/main/jsonschema</directory> - </resource> - <resource> - <directory>src/main/xmlschema</directory> - </resource> - </resources> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> </project> http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-schemas/src/main/java/org/apache/streams/schema/FieldType.java ---------------------------------------------------------------------- diff --git a/streams-schemas/src/main/java/org/apache/streams/schema/FieldType.java b/streams-schemas/src/main/java/org/apache/streams/schema/FieldType.java deleted file mode 100644 index 1ad9dcc..0000000 --- a/streams-schemas/src/main/java/org/apache/streams/schema/FieldType.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.apache.streams.schema; - -/** - * Created by steve on 5/1/16. - */ -public enum FieldType { - STRING, - INTEGER, - NUMBER, - BOOLEAN, - OBJECT, - ARRAY -} http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/6187265f/streams-schemas/src/main/java/org/apache/streams/schema/FieldUtil.java ---------------------------------------------------------------------- diff --git a/streams-schemas/src/main/java/org/apache/streams/schema/FieldUtil.java b/streams-schemas/src/main/java/org/apache/streams/schema/FieldUtil.java deleted file mode 100644 index 4173e50..0000000 --- a/streams-schemas/src/main/java/org/apache/streams/schema/FieldUtil.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.apache.streams.schema; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; - -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Created by steve on 5/1/16. - */ -public class FieldUtil { - - public static FieldType determineFieldType(ObjectNode fieldNode) { - String typeSchemaField = "type"; - if( !fieldNode.has(typeSchemaField)) - return null; - String typeSchemaFieldValue = fieldNode.get(typeSchemaField).asText(); - if( typeSchemaFieldValue.equals("string")) { - return FieldType.STRING; - } else if( typeSchemaFieldValue.equals("integer")) { - return FieldType.INTEGER; - } else if( typeSchemaFieldValue.equals("number")) { - return FieldType.NUMBER; - } else if( typeSchemaFieldValue.equals("object")) { - return FieldType.OBJECT; - } else if( typeSchemaFieldValue.equals("boolean")) { - return FieldType.BOOLEAN; - } else if( typeSchemaFieldValue.equals("array")) { - return FieldType.ARRAY; - } - else return null; - } - - public static FieldType determineArrayType(ObjectNode fieldNode) { - if( fieldNode == null ) return null; - ObjectNode itemsObjectNode = resolveItemsNode(fieldNode); - if( itemsObjectNode != null) - return determineFieldType(itemsObjectNode); - return null; - } - - public static ObjectNode resolveItemsNode(ObjectNode fieldNode) { - ObjectNode itemsObjectNode = null; - - if( fieldNode.get("items").isObject() ) - itemsObjectNode = (ObjectNode) fieldNode.get("items"); - else if( fieldNode.get("items").isArray() && fieldNode.size() > 0 && fieldNode.get(0).isObject()) { - itemsObjectNode = (ObjectNode) fieldNode.get("items").get(0); - } - - return itemsObjectNode; - } - -}