You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streams.apache.org by sb...@apache.org on 2016/06/01 17:41:07 UTC
[18/32] incubator-streams git commit: WIP for apachecon
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/streams-plugins/streams-plugin-hbase/src/test/resources/streams-plugin-hbase/pom.xml
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-hbase/src/test/resources/streams-plugin-hbase/pom.xml b/streams-plugins/streams-plugin-hbase/src/test/resources/streams-plugin-hbase/pom.xml
new file mode 100644
index 0000000..9aa7d8d
--- /dev/null
+++ b/streams-plugins/streams-plugin-hbase/src/test/resources/streams-plugin-hbase/pom.xml
@@ -0,0 +1,76 @@
+<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>
+
+ <groupId>org.apache.streams.plugins</groupId>
+ <artifactId>streams-plugin-hbase-test</artifactId>
+ <version>0.3-incubating-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Test StreamsHbaseResourceGeneratorMojo</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.streams</groupId>
+ <artifactId>streams-schemas</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.streams.plugins</groupId>
+ <artifactId>streams-plugin-hbase</artifactId>
+ <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>
+ </sourcePaths>
+ <targetDirectory>target/generated-resources/test-mojo</targetDirectory>
+ <columnFamily>cf</columnFamily>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>hbase</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.10</version>
+ <configuration>
+ <includes>**/*.json</includes>
+ <outputDirectory>${project.build.directory}/test-classes/streams-schemas</outputDirectory>
+ <includeGroupIds>org.apache.streams</includeGroupIds>
+ <includeArtifactIds>streams-schemas</includeArtifactIds>
+ <includeTypes>jar,test-jar</includeTypes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>unpack-schemas</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>unpack-dependencies</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/streams-plugins/streams-plugin-hive/pom.xml
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-hive/pom.xml b/streams-plugins/streams-plugin-hive/pom.xml
index b173a8d..515314a 100644
--- a/streams-plugins/streams-plugin-hive/pom.xml
+++ b/streams-plugins/streams-plugin-hive/pom.xml
@@ -148,6 +148,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-verifier</artifactId>
+ <version>1.6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/streams-plugins/streams-plugin-hive/src/main/java/org/apache/streams/plugins/hive/StreamsHiveResourceGenerator.java
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-hive/src/main/java/org/apache/streams/plugins/hive/StreamsHiveResourceGenerator.java b/streams-plugins/streams-plugin-hive/src/main/java/org/apache/streams/plugins/hive/StreamsHiveResourceGenerator.java
index 06c1499..c09f7dd 100644
--- a/streams-plugins/streams-plugin-hive/src/main/java/org/apache/streams/plugins/hive/StreamsHiveResourceGenerator.java
+++ b/streams-plugins/streams-plugin-hive/src/main/java/org/apache/streams/plugins/hive/StreamsHiveResourceGenerator.java
@@ -46,12 +46,11 @@ public class StreamsHiveResourceGenerator implements Runnable {
private int currentDepth = 0;
- public void main(String[] args) {
+ public static void main(String[] args) {
StreamsHiveGenerationConfig config = new StreamsHiveGenerationConfig();
- String sourceDirectory = "./target/test-classes/activities";
- String targetDirectory = "./target/generated-sources/streams-plugin-hive";
- String targetPackage = "";
+ String sourceDirectory = "src/main/jsonschema";
+ String targetDirectory = "target/generated-resources/hive";
if( args.length > 0 )
sourceDirectory = args[0];
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/streams-plugins/streams-plugin-hive/src/main/java/org/apache/streams/plugins/hive/StreamsHiveResourceGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-hive/src/main/java/org/apache/streams/plugins/hive/StreamsHiveResourceGeneratorMojo.java b/streams-plugins/streams-plugin-hive/src/main/java/org/apache/streams/plugins/hive/StreamsHiveResourceGeneratorMojo.java
index 9cf71a9..16466cf 100644
--- a/streams-plugins/streams-plugin-hive/src/main/java/org/apache/streams/plugins/hive/StreamsHiveResourceGeneratorMojo.java
+++ b/streams-plugins/streams-plugin-hive/src/main/java/org/apache/streams/plugins/hive/StreamsHiveResourceGeneratorMojo.java
@@ -2,6 +2,7 @@ package org.apache.streams.plugins.hive;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -15,15 +16,17 @@ import java.io.File;
import java.util.List;
@Mojo( name = "hive",
- defaultPhase = LifecyclePhase.GENERATE_SOURCES
+ defaultPhase = LifecyclePhase.GENERATE_RESOURCES
)
@Execute( goal = "hive",
- phase = LifecyclePhase.GENERATE_SOURCES
+ phase = LifecyclePhase.GENERATE_RESOURCES
)
public class StreamsHiveResourceGeneratorMojo extends AbstractMojo {
private final static Logger LOGGER = LoggerFactory.getLogger(StreamsHiveResourceGeneratorMojo.class);
+ private volatile MojoFailureException mojoFailureException;
+
@Component
private MavenProject project;
@@ -39,16 +42,16 @@ public class StreamsHiveResourceGeneratorMojo extends AbstractMojo {
@Parameter( defaultValue = "${project.basedir}", readonly = true )
private File basedir;
- @Parameter( defaultValue = "./src/main/jsonschema", readonly = true ) // Maven 3 only
+ @Parameter( defaultValue = "src/main/jsonschema", readonly = true ) // Maven 3 only
public String sourceDirectory;
@Parameter( readonly = true ) // Maven 3 only
public List<String> sourcePaths;
- @Parameter(defaultValue = "./target/generated-sources/streams-plugin-hive", readonly = true)
+ @Parameter(defaultValue = "./target/generated-resources/hive", readonly = true)
public String targetDirectory;
- public void execute() throws MojoExecutionException {
+ public void execute() throws MojoExecutionException, MojoFailureException {
//addProjectDependenciesToClasspath();
@@ -60,16 +63,30 @@ public class StreamsHiveResourceGeneratorMojo extends AbstractMojo {
config.setSourceDirectory(sourceDirectory);
config.setTargetDirectory(targetDirectory);
- StreamsHiveResourceGenerator streamsPojoScala = new StreamsHiveResourceGenerator(config);
- Thread thread = new Thread(streamsPojoScala);
- thread.start();
+ StreamsHiveResourceGenerator streamsHiveResourceGenerator = new StreamsHiveResourceGenerator(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(streamsHiveResourceGenerator);
+ thread.setUncaughtExceptionHandler(h);
try {
+ thread.start();
thread.join();
} catch (InterruptedException e) {
LOGGER.error("InterruptedException", e);
} catch (Exception e) {
LOGGER.error("Exception", e);
+ mojoFailureException = new MojoFailureException("Exception", e);
}
+
+ if( mojoFailureException != null )
+ throw mojoFailureException;
+
return;
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/streams-plugins/streams-plugin-hive/src/site/markdown/index.md
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-hive/src/site/markdown/index.md b/streams-plugins/streams-plugin-hive/src/site/markdown/index.md
new file mode 100644
index 0000000..4df9103
--- /dev/null
+++ b/streams-plugins/streams-plugin-hive/src/site/markdown/index.md
@@ -0,0 +1,22 @@
+org.apache.streams.plugins:streams-plugin-hive
+==============================================
+
+streams-plugin-hive generates resources from json schemas to assist with analysis of json data using Apache Hive.
+
+#### Usage
+
+Run within a module containing a src/main/jsonschema directory
+
+ mvn org.apache.streams.plugins:streams-plugin-hive:0.3-incubating-SNAPSHOT:hive
+
+Output will be placed in target/generated-resources/hive by default
+
+#### Example
+
+[streams-plugin-hive/pom.xml](streams-plugin-hive/pom.xml "streams-plugin-hive/pom.xml")
+
+#### 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/95a02d71/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorCLITest.java
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorCLITest.java b/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorCLITest.java
new file mode 100644
index 0000000..21c82f9
--- /dev/null
+++ b/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorCLITest.java
@@ -0,0 +1,41 @@
+package org.apache.streams.plugins.test;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.io.Files;
+import org.apache.streams.plugins.hive.StreamsHiveResourceGenerator;
+import org.junit.Test;
+
+import javax.annotation.Nullable;
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+
+import static org.apache.streams.plugins.test.StreamsHiveResourceGeneratorTest.hqlFilter;
+
+/**
+ * Created by sblackmon on 5/5/16.
+ */
+public class StreamsHiveResourceGeneratorCLITest {
+
+ @Test
+ public void testStreamsHiveResourceGeneratorCLI() throws Exception {
+
+ String sourceDirectory = "target/test-classes/streams-schemas";
+ String targetDirectory = "target/generated-resources/hive-cli";
+
+ List<String> argsList = Lists.newArrayList(sourceDirectory, targetDirectory);
+ StreamsHiveResourceGenerator.main(argsList.toArray(new String[0]));
+
+ File testOutput = new File(targetDirectory);
+
+ assert( testOutput != null );
+ assert( testOutput.exists() == true );
+ assert( testOutput.isDirectory() == true );
+
+ Iterable<File> outputIterator = Files.fileTreeTraverser().breadthFirstTraversal(testOutput)
+ .filter(hqlFilter);
+ Collection<File> outputCollection = Lists.newArrayList(outputIterator);
+ assert( outputCollection.size() == 133 );
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorMojoTest.java
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorMojoTest.java b/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorMojoTest.java
new file mode 100644
index 0000000..b2f3e14
--- /dev/null
+++ b/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorMojoTest.java
@@ -0,0 +1,64 @@
+package org.apache.streams.plugins.test;
+
+import com.google.common.collect.Lists;
+import com.google.common.io.Files;
+import junit.framework.TestCase;
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import static org.apache.streams.plugins.test.StreamsHiveResourceGeneratorTest.hqlFilter;
+
+/**
+ * Tests that streams-plugin-hive running via maven generates hql resources
+ */
+public class StreamsHiveResourceGeneratorMojoTest extends TestCase {
+
+ private final static Logger LOGGER = LoggerFactory.getLogger(StreamsHiveResourceGeneratorMojoTest.class);
+
+ protected void setUp() throws Exception
+ {
+ // required for mojo lookups to work
+ super.setUp();
+ }
+
+
+ @Test
+ public void testStreamsHiveResourceGeneratorMojo() throws Exception {
+
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/streams-plugin-hive" );
+
+ Verifier verifier;
+
+ verifier = new Verifier( testDir.getAbsolutePath() );
+
+ List cliOptions = new ArrayList();
+ cliOptions.add( "-N" );
+ verifier.executeGoals( Lists.<String>newArrayList(
+ "clean",
+ "dependency:unpack-dependencies",
+ "generate-resources"));
+
+ verifier.verifyErrorFreeLog();
+
+ verifier.resetStreams();
+
+ File testOutput = new File(testDir.getAbsolutePath() + "/target/generated-resources/test-mojo");
+
+ assert( testOutput != null );
+ assert( testOutput.exists() == true );
+ assert( testOutput.isDirectory() == true );
+
+ Iterable<File> outputIterator = Files.fileTreeTraverser().breadthFirstTraversal(testOutput)
+ .filter(hqlFilter);
+ Collection<File> outputCollection = Lists.newArrayList(outputIterator);
+ assert( outputCollection.size() == 133 );
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorTest.java
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorTest.java b/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorTest.java
index 9be908d..3944ddf 100644
--- a/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorTest.java
+++ b/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorTest.java
@@ -8,6 +8,7 @@ import org.apache.commons.io.FileUtils;
import org.apache.streams.plugins.hive.StreamsHiveGenerationConfig;
import org.apache.streams.plugins.hive.StreamsHiveResourceGenerator;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -22,10 +23,20 @@ import static org.apache.streams.schema.FileUtil.dropSourcePathPrefix;
/**
* Test that Activity beans are compatible with the example activities in the spec.
*/
+@Ignore
public class StreamsHiveResourceGeneratorTest {
private final static Logger LOGGER = LoggerFactory.getLogger(StreamsHiveResourceGeneratorTest.class);
+ public static final Predicate<File> hqlFilter = new Predicate<File>() {
+ @Override
+ public boolean apply(@Nullable File file) {
+ if( file.getName().endsWith(".hql") )
+ return true;
+ else return false;
+ }
+ };
+
/**
* Tests that all example activities can be loaded into Activity beans
*
@@ -57,15 +68,7 @@ public class StreamsHiveResourceGeneratorTest {
LOGGER.error("Exception", e);
}
- File testOutput = new File( "./target/generated-sources/test");
- Predicate<File> hqlFilter = new Predicate<File>() {
- @Override
- public boolean apply(@Nullable File file) {
- if( file.getName().endsWith(".hql") )
- return true;
- else return false;
- }
- };
+ File testOutput = config.getTargetDirectory();
assert( testOutput != null );
assert( testOutput.exists() == true );
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/streams-plugins/streams-plugin-hive/src/test/resources/streams-plugin-hive/pom.xml
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-hive/src/test/resources/streams-plugin-hive/pom.xml b/streams-plugins/streams-plugin-hive/src/test/resources/streams-plugin-hive/pom.xml
index b1de7b8..ae4bb66 100644
--- a/streams-plugins/streams-plugin-hive/src/test/resources/streams-plugin-hive/pom.xml
+++ b/streams-plugins/streams-plugin-hive/src/test/resources/streams-plugin-hive/pom.xml
@@ -13,6 +13,13 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.streams</groupId>
+ <artifactId>streams-schemas</artifactId>
+ <version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -24,10 +31,15 @@
<artifactId>streams-plugin-hive</artifactId>
<version>0.3-incubating-SNAPSHOT</version>
<configuration>
- <packages>
- <package>org.apache.streams.pojo.json</package>
- </packages>
- <target>target/test-classes/streams-hive-plugin/</target>
+ <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>
+ </sourcePaths>
+ <targetDirectory>target/generated-resources/test-mojo</targetDirectory>
</configuration>
<executions>
<execution>
@@ -37,6 +49,27 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.10</version>
+ <configuration>
+ <includes>**/*.json</includes>
+ <outputDirectory>${project.build.directory}/test-classes/streams-schemas</outputDirectory>
+ <includeGroupIds>org.apache.streams</includeGroupIds>
+ <includeArtifactIds>streams-schemas</includeArtifactIds>
+ <includeTypes>jar,test-jar</includeTypes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>unpack-schemas</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>unpack-dependencies</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/streams-plugins/streams-plugin-pig/pom.xml
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-pig/pom.xml b/streams-plugins/streams-plugin-pig/pom.xml
new file mode 100644
index 0000000..ef59587
--- /dev/null
+++ b/streams-plugins/streams-plugin-pig/pom.xml
@@ -0,0 +1,244 @@
+<?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
+ ~
+ ~ 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>
+ <groupId>org.apache.streams.plugins</groupId>
+ <artifactId>streams-plugin-pig</artifactId>
+ <version>0.3-incubating-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+
+ <parent>
+ <groupId>org.apache.streams</groupId>
+ <artifactId>streams-plugins</artifactId>
+ <version>0.3-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <properties>
+ <pig.version>1.0</pig.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.streams</groupId>
+ <artifactId>streams-config</artifactId>
+ <version>${project.version}</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-logging</artifactId>
+ <groupId>commons-logging</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.streams</groupId>
+ <artifactId>streams-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.streams</groupId>
+ <artifactId>streams-schemas</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.reflections</groupId>
+ <artifactId>reflections</artifactId>
+ <version>0.9.9</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-aether-provider</artifactId>
+ <version>3.3.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>3.3.3</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-compat</artifactId>
+ <version>3.3.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.3.3</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>3.3.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-verifier</artifactId>
+ <version>1.6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.7</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>3.0.15</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>3.4</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-logging</artifactId>
+ <groupId>commons-logging</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-api</artifactId>
+ <version>3.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <version>3.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-generators</artifactId>
+ <version>3.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-testing</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ <version>3.3.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.6</version>
+ </dependency>
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ <version>2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.joda</groupId>
+ <artifactId>joda-convert</artifactId>
+ <version>1.8.1</version>
+ </dependency>
+ </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>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>3.4</version>
+ <configuration>
+ <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+ </configuration>
+ <executions>
+ <execution>
+ <id>mojo-descriptor</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>descriptor</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.reflections</groupId>
+ <artifactId>reflections-maven</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>reflections</goal>
+ </goals>
+ <phase>process-classes</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.4</version>
+ <executions>
+ <execution>
+ <id>resource-dependencies</id>
+ <phase>process-test-resources</phase>
+ <goals>
+ <goal>unpack-dependencies</goal>
+ </goals>
+ <configuration>
+ <includeGroupIds>org.apache.streams</includeGroupIds>
+ <includeArtifactIds>streams-schemas</includeArtifactIds>
+ <includes>**/*.json</includes>
+ <outputDirectory>${project.build.directory}/test-classes/streams-schemas</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/streams-plugins/streams-plugin-pig/src/main/java/org/apache/streams/plugins/pig/StreamsPigGenerationConfig.java
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-pig/src/main/java/org/apache/streams/plugins/pig/StreamsPigGenerationConfig.java b/streams-plugins/streams-plugin-pig/src/main/java/org/apache/streams/plugins/pig/StreamsPigGenerationConfig.java
new file mode 100644
index 0000000..5aa55ed
--- /dev/null
+++ b/streams-plugins/streams-plugin-pig/src/main/java/org/apache/streams/plugins/pig/StreamsPigGenerationConfig.java
@@ -0,0 +1,84 @@
+package org.apache.streams.plugins.pig;
+
+import org.apache.streams.schema.GenerationConfig;
+import org.jsonschema2pojo.DefaultGenerationConfig;
+import org.jsonschema2pojo.util.URLUtil;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Configures StreamsHiveResourceGenerator
+ *
+ *
+ */
+public class StreamsPigGenerationConfig extends DefaultGenerationConfig implements GenerationConfig {
+
+ public String getSourceDirectory() {
+ return sourceDirectory;
+ }
+
+ public List<String> getSourcePaths() {
+ return sourcePaths;
+ }
+
+ private String sourceDirectory;
+ private List<String> sourcePaths = new ArrayList<String>();
+ private String targetDirectory;
+ private int maxDepth = 1;
+
+ public Set<String> getExclusions() {
+ return exclusions;
+ }
+
+ public void setExclusions(Set<String> exclusions) {
+ this.exclusions = exclusions;
+ }
+
+ private Set<String> exclusions = new HashSet<String>();
+
+ public int getMaxDepth() {
+ return maxDepth;
+ }
+
+ public void setSourceDirectory(String sourceDirectory) {
+ this.sourceDirectory = sourceDirectory;
+ }
+
+ public void setSourcePaths(List<String> sourcePaths) {
+ this.sourcePaths = sourcePaths;
+ }
+
+ public void setTargetDirectory(String targetDirectory) {
+ this.targetDirectory = targetDirectory;
+ }
+
+ @Override
+ public File getTargetDirectory() {
+ return new File(targetDirectory);
+ }
+
+ @Override
+ public Iterator<URL> getSource() {
+ if (null != sourceDirectory) {
+ return Collections.singleton(URLUtil.parseURL(sourceDirectory)).iterator();
+ }
+ List<URL> sourceURLs = new ArrayList<URL>();
+ if( sourcePaths != null && sourcePaths.size() > 0)
+ for (String source : sourcePaths) {
+ sourceURLs.add(URLUtil.parseURL(source));
+ }
+ return sourceURLs.iterator();
+ }
+
+ public void setMaxDepth(int maxDepth) {
+ this.maxDepth = maxDepth;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/streams-plugins/streams-plugin-pig/src/main/java/org/apache/streams/plugins/pig/StreamsPigResourceGenerator.java
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-pig/src/main/java/org/apache/streams/plugins/pig/StreamsPigResourceGenerator.java b/streams-plugins/streams-plugin-pig/src/main/java/org/apache/streams/plugins/pig/StreamsPigResourceGenerator.java
new file mode 100644
index 0000000..072e1b6
--- /dev/null
+++ b/streams-plugins/streams-plugin-pig/src/main/java/org/apache/streams/plugins/pig/StreamsPigResourceGenerator.java
@@ -0,0 +1,317 @@
+package org.apache.streams.plugins.pig;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+import org.apache.streams.plugins.pig.StreamsPigGenerationConfig;
+import org.apache.streams.schema.FieldType;
+import org.apache.streams.schema.FieldUtil;
+import org.apache.streams.schema.FileUtil;
+import org.apache.streams.schema.GenerationConfig;
+import org.apache.streams.schema.Schema;
+import org.apache.streams.schema.SchemaStore;
+import org.jsonschema2pojo.util.URLUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.streams.schema.FileUtil.dropExtension;
+import static org.apache.streams.schema.FileUtil.dropSourcePathPrefix;
+import static org.apache.streams.schema.FileUtil.swapExtension;
+import static org.apache.streams.schema.FileUtil.writeFile;
+
+public class StreamsPigResourceGenerator implements Runnable {
+
+ private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPigResourceGenerator.class);
+
+ private final static String LS = System.getProperty("line.separator");
+
+ private StreamsPigGenerationConfig config;
+
+ private SchemaStore schemaStore = new SchemaStore();
+
+ private int currentDepth = 0;
+
+ public static void main(String[] args) {
+ StreamsPigGenerationConfig config = new StreamsPigGenerationConfig();
+
+ String sourceDirectory = "src/main/jsonschema";
+ String targetDirectory = "target/generated-resources/pig-cli";
+
+ if (args.length > 0)
+ sourceDirectory = args[0];
+ if (args.length > 1)
+ targetDirectory = args[1];
+
+ config.setSourceDirectory(sourceDirectory);
+ config.setTargetDirectory(targetDirectory);
+
+ 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);
+ }
+ return;
+ }
+
+ public StreamsPigResourceGenerator(StreamsPigGenerationConfig config) {
+ this.config = config;
+ }
+
+ public void run() {
+
+ checkNotNull(config);
+
+ generate(config);
+
+ }
+
+ public void generate(StreamsPigGenerationConfig config) {
+
+ LinkedList<File> sourceFiles = new LinkedList<File>();
+
+ for (Iterator<URL> sources = config.getSource(); sources.hasNext(); ) {
+ URL source = sources.next();
+ sourceFiles.add(URLUtil.getFileFromURL(source));
+ }
+
+ LOGGER.info("Seeded with {} source paths:", sourceFiles.size());
+
+ FileUtil.resolveRecursive((GenerationConfig) config, sourceFiles);
+
+ LOGGER.info("Resolved {} schema files:", sourceFiles.size());
+
+ for (Iterator<File> iterator = sourceFiles.iterator(); iterator.hasNext(); ) {
+ File item = iterator.next();
+ schemaStore.create(item.toURI());
+ }
+
+ LOGGER.info("Identified {} objects:", schemaStore.getSize());
+
+ for (Iterator<Schema> schemaIterator = schemaStore.getSchemaIterator(); schemaIterator.hasNext(); ) {
+ Schema schema = schemaIterator.next();
+ currentDepth = 0;
+ if (schema.getURI().getScheme().equals("file")) {
+ String inputFile = schema.getURI().getPath();
+ String resourcePath = dropSourcePathPrefix(inputFile, config.getSourceDirectory());
+ for (String sourcePath : config.getSourcePaths()) {
+ resourcePath = dropSourcePathPrefix(resourcePath, sourcePath);
+ }
+ String outputFile = config.getTargetDirectory() + "/" + swapExtension(resourcePath, "json", "pig");
+
+ LOGGER.info("Processing {}:", resourcePath);
+
+ String resourceId = schemaSymbol(schema);
+
+ String resourceContent = generateResource(schema, resourceId);
+
+ writeFile(outputFile, resourceContent);
+
+ LOGGER.info("Wrote {}:", outputFile);
+ }
+ }
+ }
+
+ public String generateResource(Schema schema, String resourceId) {
+ StringBuilder resourceBuilder = new StringBuilder();
+ resourceBuilder.append(pigEscape(resourceId));
+ resourceBuilder.append(" = ");
+ resourceBuilder.append("LOAD '' USING JsonLoader('");
+ resourceBuilder = appendRootObject(resourceBuilder, schema, resourceId, ':');
+ resourceBuilder.append("');");
+ return resourceBuilder.toString();
+ }
+
+ public StringBuilder appendRootObject(StringBuilder builder, Schema schema, String resourceId, Character seperator) {
+ ObjectNode propertiesNode = schemaStore.resolveProperties(schema, null, resourceId);
+ if (propertiesNode != null && propertiesNode.isObject() && propertiesNode.size() > 0) {
+ builder = appendPropertiesNode(builder, schema, propertiesNode, seperator);
+ }
+ return builder;
+ }
+
+ private StringBuilder appendPropertiesNode(StringBuilder builder, Schema schema, ObjectNode propertiesNode, Character seperator) {
+ checkNotNull(builder);
+ checkNotNull(propertiesNode);
+ Iterator<Map.Entry<String, JsonNode>> fields = propertiesNode.fields();
+ Joiner joiner = Joiner.on(", ").skipNulls();
+ List<String> fieldStrings = Lists.newArrayList();
+ for( ; fields.hasNext(); ) {
+ Map.Entry<String, JsonNode> field = fields.next();
+ String fieldId = field.getKey();
+ if( !config.getExclusions().contains(fieldId) && field.getValue().isObject()) {
+ ObjectNode fieldNode = (ObjectNode) field.getValue();
+ FieldType fieldType = FieldUtil.determineFieldType(fieldNode);
+ if (fieldType != null ) {
+ switch (fieldType) {
+ case ARRAY:
+ ObjectNode itemsNode = FieldUtil.resolveItemsNode(fieldNode);
+ if( itemsNode == null ) {
+ ObjectNode resolvedItems = schemaStore.resolveProperties(schema, fieldNode, fieldId);
+ itemsNode = FieldUtil.resolveItemsNode();
+ }
+ if( itemsNode != null && currentDepth <= config.getMaxDepth()) {
+ StringBuilder arrayItemsBuilder = appendArrayItems(new StringBuilder(), schema, fieldId, itemsNode, seperator);
+ if( !Strings.isNullOrEmpty(arrayItemsBuilder.toString())) {
+ fieldStrings.add(arrayItemsBuilder.toString());
+ }
+ }
+ break;
+ case OBJECT:
+ ObjectNode childProperties = schemaStore.resolveProperties(schema, fieldNode, fieldId);
+ if( currentDepth < config.getMaxDepth()) {
+ StringBuilder structFieldBuilder = appendStructField(new StringBuilder(), schema, fieldId, childProperties, seperator);
+ if( !Strings.isNullOrEmpty(structFieldBuilder.toString())) {
+ fieldStrings.add(structFieldBuilder.toString());
+ }
+ }
+ break;
+ default:
+ StringBuilder valueFieldBuilder = appendValueField(new StringBuilder(), schema, fieldId, fieldType, seperator);
+ if( !Strings.isNullOrEmpty(valueFieldBuilder.toString())) {
+ fieldStrings.add(valueFieldBuilder.toString());
+ }
+ }
+ }
+ }
+ }
+ joiner.appendTo(builder, fieldStrings);
+ Preconditions.checkNotNull(builder);
+ return builder;
+ }
+
+ private StringBuilder appendValueField(StringBuilder builder, Schema schema, String fieldId, FieldType fieldType, Character seperator) {
+ // safe to append nothing
+ checkNotNull(builder);
+ builder.append(pigEscape(fieldId));
+ builder.append(seperator);
+ builder.append(pigType(fieldType));
+ return builder;
+ }
+
+ public StringBuilder appendArrayItems(StringBuilder builder, Schema schema, String fieldId, ObjectNode itemsNode, Character seperator) {
+ // not safe to append nothing
+ checkNotNull(builder);
+ if( itemsNode == null ) return builder;
+ FieldType itemType = FieldUtil.determineFieldType(itemsNode);
+ try {
+ switch( itemType ) {
+ case OBJECT:
+ builder = appendArrayObject(builder, schema, fieldId, itemsNode, seperator);
+ break;
+ case ARRAY:
+ ObjectNode subArrayItems = (ObjectNode) itemsNode.get("items");
+ builder = appendArrayItems(builder, schema, fieldId, subArrayItems, seperator);
+ break;
+ default:
+ builder = appendArrayField(builder, schema, fieldId, itemType, seperator);
+ }
+ } catch (Exception e) {
+ LOGGER.warn("No item type resolvable for {}", fieldId);
+ }
+
+ checkNotNull(builder);
+ return builder;
+ }
+
+ private StringBuilder appendArrayField(StringBuilder builder, Schema schema, String fieldId, FieldType fieldType, Character seperator) {
+ // safe to append nothing
+ checkNotNull(builder);
+ checkNotNull(fieldId);
+ builder.append("{t: (");
+ builder.append(pigEscape(fieldId));
+ builder.append(seperator);
+ builder.append(pigType(fieldType));
+ builder.append(")}");
+ checkNotNull(builder);
+ return builder;
+ }
+
+ private StringBuilder appendArrayObject(StringBuilder builder, Schema schema, String fieldId, ObjectNode fieldNode, Character seperator) {
+ // safe to append nothing
+ checkNotNull(builder);
+ checkNotNull(fieldId);
+ checkNotNull(fieldNode);
+ ObjectNode propertiesNode = schemaStore.resolveProperties(schema, fieldNode, fieldId);
+ if( propertiesNode.size() > 0 ) {
+ builder.append("{t: (");
+ builder = appendStructField(builder, schema, "", propertiesNode, ':');
+ builder.append(")}");
+ }
+ checkNotNull(builder);
+ return builder;
+ }
+
+ private StringBuilder appendStructField(StringBuilder builder, Schema schema, String fieldId, ObjectNode propertiesNode, Character seperator) {
+ // safe to append nothing
+ checkNotNull(builder);
+ checkNotNull(propertiesNode);
+
+ if( propertiesNode != null && propertiesNode.isObject() && propertiesNode.size() > 0 ) {
+
+ currentDepth += 1;
+
+ if( !Strings.isNullOrEmpty(fieldId)) {
+ builder.append(pigEscape(fieldId));
+ builder.append(seperator);
+ builder.append("(");
+ builder = appendPropertiesNode(builder, schema, propertiesNode, ':');
+ builder.append(")");
+ }
+
+ currentDepth -= 1;
+
+ }
+ checkNotNull(builder);
+ return builder;
+ }
+
+ private static String pigEscape( String fieldId ) {
+ return fieldId;
+ }
+
+ private static String pigType( FieldType fieldType ) {
+ switch( fieldType ) {
+ case STRING:
+ return "chararray";
+ case INTEGER:
+ return "int";
+ case NUMBER:
+ return "double";
+ case OBJECT:
+ return "tuple";
+ default:
+ return fieldType.name().toLowerCase();
+ }
+ }
+
+ private String schemaSymbol( Schema schema ) {
+ if (schema == null) return null;
+ // this needs to return whatever
+ if (schema.getURI().getScheme().equals("file")) {
+ String inputFile = schema.getURI().getPath();
+ String resourcePath = dropSourcePathPrefix(inputFile, config.getSourceDirectory());
+ for (String sourcePath : config.getSourcePaths()) {
+ resourcePath = dropSourcePathPrefix(resourcePath, sourcePath);
+ }
+ return dropExtension(resourcePath).replace("/", "_").replace("-", "");
+ } else {
+ return "IDK";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/streams-plugins/streams-plugin-pig/src/main/java/org/apache/streams/plugins/pig/StreamsPigResourceGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-pig/src/main/java/org/apache/streams/plugins/pig/StreamsPigResourceGeneratorMojo.java b/streams-plugins/streams-plugin-pig/src/main/java/org/apache/streams/plugins/pig/StreamsPigResourceGeneratorMojo.java
new file mode 100644
index 0000000..4763b60
--- /dev/null
+++ b/streams-plugins/streams-plugin-pig/src/main/java/org/apache/streams/plugins/pig/StreamsPigResourceGeneratorMojo.java
@@ -0,0 +1,93 @@
+package org.apache.streams.plugins.pig;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+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;
+import java.util.List;
+
+@Mojo( name = "pig",
+ defaultPhase = LifecyclePhase.GENERATE_RESOURCES
+)
+@Execute( goal = "pig",
+ phase = LifecyclePhase.GENERATE_RESOURCES
+)
+public class StreamsPigResourceGeneratorMojo extends AbstractMojo {
+
+ private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPigResourceGeneratorMojo.class);
+
+ private volatile MojoFailureException mojoFailureException;
+
+ @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 = "src/main/jsonschema", readonly = true ) // Maven 3 only
+ public String sourceDirectory;
+
+ @Parameter( readonly = true ) // Maven 3 only
+ public List<String> sourcePaths;
+
+ @Parameter(defaultValue = "target/generated-resources/pig", readonly = true)
+ public String targetDirectory;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ //addProjectDependenciesToClasspath();
+
+ StreamsPigGenerationConfig config = new StreamsPigGenerationConfig();
+
+ if( sourcePaths != null && sourcePaths.size() > 0)
+ config.setSourcePaths(sourcePaths);
+ else
+ config.setSourceDirectory(sourceDirectory);
+ config.setTargetDirectory(targetDirectory);
+
+ StreamsPigResourceGenerator streamsPigResourceGenerator = new StreamsPigResourceGenerator(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(streamsPigResourceGenerator);
+ thread.setUncaughtExceptionHandler(h);
+ try {
+ thread.start();
+ thread.join();
+ } catch (InterruptedException e) {
+ LOGGER.error("InterruptedException", e);
+ } catch (Exception e) {
+ LOGGER.error("Exception", e);
+ mojoFailureException = new MojoFailureException("Exception", e);
+ }
+
+ if( mojoFailureException != null )
+ throw mojoFailureException;
+
+ return;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/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
new file mode 100644
index 0000000..d0d4791
--- /dev/null
+++ b/streams-plugins/streams-plugin-pig/src/site/markdown/index.md
@@ -0,0 +1,22 @@
+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
+
+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
+
+#### Example
+
+[streams-plugin-pig/pom.xml](streams-plugin-pig/pom.xml "streams-plugin-pig/pom.xml")
+
+#### 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/95a02d71/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
new file mode 100644
index 0000000..c94bca9
--- /dev/null
+++ b/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorCLITest.java
@@ -0,0 +1,39 @@
+package org.apache.streams.plugins.pig.test;
+
+import com.google.common.collect.Lists;
+import com.google.common.io.Files;
+import org.apache.streams.plugins.pig.StreamsPigResourceGenerator;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+
+import static org.apache.streams.plugins.pig.test.StreamsPigResourceGeneratorTest.pigFilter;
+
+/**
+ * Created by sblackmon on 5/5/16.
+ */
+public class StreamsPigResourceGeneratorCLITest {
+
+ @Test
+ public void testStreamsPigResourceGeneratorCLI() throws Exception {
+
+ String sourceDirectory = "target/test-classes/streams-schemas";
+ String targetDirectory = "target/generated-resources/hive-cli";
+
+ List<String> argsList = Lists.newArrayList(sourceDirectory, targetDirectory);
+ StreamsPigResourceGenerator.main(argsList.toArray(new String[0]));
+
+ File testOutput = new File(targetDirectory);
+
+ assert( testOutput != null );
+ assert( testOutput.exists() == true );
+ assert( testOutput.isDirectory() == true );
+
+ Iterable<File> outputIterator = Files.fileTreeTraverser().breadthFirstTraversal(testOutput)
+ .filter(pigFilter);
+ Collection<File> outputCollection = Lists.newArrayList(outputIterator);
+ assert( outputCollection.size() == 133 );
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/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
new file mode 100644
index 0000000..401c506
--- /dev/null
+++ b/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorMojoTest.java
@@ -0,0 +1,64 @@
+package org.apache.streams.plugins.pig.test;
+
+import com.google.common.collect.Lists;
+import com.google.common.io.Files;
+import junit.framework.TestCase;
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import static org.apache.streams.plugins.pig.test.StreamsPigResourceGeneratorTest.pigFilter;
+
+/**
+ * Tests that streams-plugin-hive running via maven generates hql resources
+ */
+public class StreamsPigResourceGeneratorMojoTest extends TestCase {
+
+ private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPigResourceGeneratorMojoTest.class);
+
+ protected void setUp() throws Exception
+ {
+ // required for mojo lookups to work
+ super.setUp();
+ }
+
+
+ @Test
+ public void testStreamsHiveResourceGeneratorMojo() throws Exception {
+
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/streams-plugin-pig" );
+
+ Verifier verifier;
+
+ verifier = new Verifier( testDir.getAbsolutePath() );
+
+ List cliOptions = new ArrayList();
+ cliOptions.add( "-N" );
+ verifier.executeGoals( Lists.<String>newArrayList(
+ "clean",
+ "dependency:unpack-dependencies",
+ "generate-resources"));
+
+ verifier.verifyErrorFreeLog();
+
+ verifier.resetStreams();
+
+ File testOutput = new File(testDir.getAbsolutePath() + "/target/generated-resources/test-mojo");
+
+ assert( testOutput != null );
+ assert( testOutput.exists() == true );
+ assert( testOutput.isDirectory() == true );
+
+ Iterable<File> outputIterator = Files.fileTreeTraverser().breadthFirstTraversal(testOutput)
+ .filter(pigFilter);
+ Collection<File> outputCollection = Lists.newArrayList(outputIterator);
+ assert( outputCollection.size() == 133 );
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/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
new file mode 100644
index 0000000..a1ab281
--- /dev/null
+++ b/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorTest.java
@@ -0,0 +1,122 @@
+package org.apache.streams.plugins.pig.test;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import com.google.common.io.Files;
+import org.apache.commons.io.FileUtils;
+import org.apache.streams.plugins.pig.StreamsPigGenerationConfig;
+import org.apache.streams.plugins.pig.StreamsPigResourceGenerator;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+import java.io.File;
+import java.util.Collection;
+import java.util.Iterator;
+
+import static org.apache.streams.schema.FileUtil.dropSourcePathPrefix;
+
+/**
+ * Test that Activity beans are compatible with the example activities in the spec.
+ */
+public class StreamsPigResourceGeneratorTest {
+
+ private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPigResourceGeneratorTest.class);
+
+ public static final Predicate<File> pigFilter = new Predicate<File>() {
+ @Override
+ public boolean apply(@Nullable File file) {
+ if( file.getName().endsWith(".pig") )
+ return true;
+ else return false;
+ }
+ };
+
+ /**
+ * Tests that all example activities can be loaded into Activity beans
+ *
+ * @throws Exception
+ */
+ @Test
+ public void StreamsPigResourceGenerator() throws Exception {
+
+ StreamsPigGenerationConfig config = new StreamsPigGenerationConfig();
+
+ String sourceDirectory = "target/test-classes/streams-schemas";
+
+ config.setSourceDirectory(sourceDirectory);
+
+ config.setTargetDirectory("target/generated-sources/test");
+
+ 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);
+ }
+
+ File testOutput = new File( "./target/generated-sources/test");
+
+ assert( testOutput != null );
+ assert( testOutput.exists() == true );
+ assert( testOutput.isDirectory() == true );
+
+ Iterable<File> outputIterator = Files.fileTreeTraverser().breadthFirstTraversal(testOutput)
+ .filter(pigFilter);
+ Collection<File> outputCollection = Lists.newArrayList(outputIterator);
+ assert( outputCollection.size() == 133 );
+
+ String expectedDirectory = "target/test-classes/expected";
+ File testExpected = new File( expectedDirectory );
+
+ Iterable<File> expectedIterator = Files.fileTreeTraverser().breadthFirstTraversal(testExpected)
+ .filter(pigFilter);
+ Collection<File> expectedCollection = Lists.newArrayList(expectedIterator);
+
+ int fails = 0;
+
+ Iterator<File> iterator = expectedCollection.iterator();
+ while( iterator.hasNext() ) {
+ File objectExpected = iterator.next();
+ String expectedEnd = dropSourcePathPrefix(objectExpected.getAbsolutePath(), expectedDirectory);
+ File objectActual = new File(config.getTargetDirectory() + "/" + expectedEnd);
+ LOGGER.info("Comparing: {} and {}", objectExpected.getAbsolutePath(), objectActual.getAbsolutePath());
+ assert( objectActual.exists());
+ if( FileUtils.contentEquals(objectActual, objectExpected) == true ) {
+ LOGGER.info("Exact Match!");
+ } else {
+ LOGGER.info("No Match!");
+ fails++;
+ }
+ }
+ if( fails > 0 ) {
+ 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/95a02d71/streams-plugins/streams-plugin-pig/src/test/resources/expected/media_link.pig
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-pig/src/test/resources/expected/media_link.pig b/streams-plugins/streams-plugin-pig/src/test/resources/expected/media_link.pig
new file mode 100644
index 0000000..643686e
--- /dev/null
+++ b/streams-plugins/streams-plugin-pig/src/test/resources/expected/media_link.pig
@@ -0,0 +1 @@
+media_link = LOAD '' USING JsonLoader('duration:double, height:int, width:int, url:chararray');
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/streams-plugins/streams-plugin-pig/src/test/resources/expected/objectTypes/file.pig
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-pig/src/test/resources/expected/objectTypes/file.pig b/streams-plugins/streams-plugin-pig/src/test/resources/expected/objectTypes/file.pig
new file mode 100644
index 0000000..9aa8d63
--- /dev/null
+++ b/streams-plugins/streams-plugin-pig/src/test/resources/expected/objectTypes/file.pig
@@ -0,0 +1 @@
+objectTypes_file = LOAD '' USING JsonLoader('id:chararray, image:(duration:double, height:int, width:int, url:chararray), displayName:chararray, summary:chararray, content:chararray, url:chararray, objectType:chararray, author:(id:chararray, image:(duration:double, height:int, width:int, url:chararray), displayName:chararray, summary:chararray, content:chararray, url:chararray, objectType:chararray, author:(id:chararray, displayName:chararray, summary:chararray, content:chararray, url:chararray, objectType:chararray, published:chararray, updated:chararray, {t: (upstreamDuplicates:chararray)}, {t: (downstreamDuplicates:chararray)}), published:chararray, updated:chararray, {t: (upstreamDuplicates:chararray)}, {t: (downstreamDuplicates:chararray)}), published:chararray, updated:chararray, {t: (upstreamDuplicates:chararray)}, {t: (downstreamDuplicates:chararray)}, fileUrl:chararray, mimeType:chararray');
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/streams-plugins/streams-plugin-pig/src/test/resources/expected/objectTypes/photo-album.pig
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-pig/src/test/resources/expected/objectTypes/photo-album.pig b/streams-plugins/streams-plugin-pig/src/test/resources/expected/objectTypes/photo-album.pig
new file mode 100644
index 0000000..83b150f
--- /dev/null
+++ b/streams-plugins/streams-plugin-pig/src/test/resources/expected/objectTypes/photo-album.pig
@@ -0,0 +1 @@
+objectTypes_photoalbum = LOAD '' USING JsonLoader('objectType:chararray, {t: ()}');
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/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
new file mode 100644
index 0000000..7027446
--- /dev/null
+++ b/streams-plugins/streams-plugin-pig/src/test/resources/streams-plugin-pig/pom.xml
@@ -0,0 +1,75 @@
+<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>
+
+ <groupId>org.apache.streams.plugins</groupId>
+ <artifactId>streams-plugin-pig-test</artifactId>
+ <version>0.3-incubating-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Test StreamsPigResourceGeneratorMojo</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.streams</groupId>
+ <artifactId>streams-schemas</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.streams.plugins</groupId>
+ <artifactId>streams-plugin-pig</artifactId>
+ <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>
+ </sourcePaths>
+ <targetDirectory>target/generated-resources/test-mojo</targetDirectory>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>pig</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.10</version>
+ <configuration>
+ <includes>**/*.json</includes>
+ <outputDirectory>${project.build.directory}/test-classes/streams-schemas</outputDirectory>
+ <includeGroupIds>org.apache.streams</includeGroupIds>
+ <includeArtifactIds>streams-schemas</includeArtifactIds>
+ <includeTypes>jar,test-jar</includeTypes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>unpack-schemas</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>unpack-dependencies</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/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 d7210c8..bfa3480 100644
--- a/streams-plugins/streams-plugin-pojo/pom.xml
+++ b/streams-plugins/streams-plugin-pojo/pom.xml
@@ -64,13 +64,6 @@
<version>0.4.10</version>
</dependency>
<dependency>
- <groupId>org.apache.streams</groupId>
- <artifactId>streams-pojo</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- <type>test-jar</type>
- </dependency>
- <dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.9</version>
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/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 d80123d..f7b6617 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
@@ -1,26 +1,14 @@
package org.apache.streams.plugins;
import com.google.common.base.Preconditions;
-import org.apache.maven.artifact.DependencyResolutionRequiredException;
-import org.apache.maven.plugin.MojoExecutionException;
import org.jsonschema2pojo.Jsonschema2Pojo;
-import org.jsonschema2pojo.maven.ProjectClasspath;
-import org.jsonschema2pojo.util.URLUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
-import java.io.IOException;
-import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import static org.apache.commons.lang.StringUtils.isNotBlank;
/**
* Created by sblackmon on 4/20/16.
@@ -31,11 +19,9 @@ public class StreamsPojoSourceGenerator implements Runnable {
private final static String LS = System.getProperty("line.separator");
- private StreamsPojoSourceGeneratorMojo mojo;
-
private StreamsPojoGenerationConfig config;
- public void main(String[] args) {
+ public static void main(String[] args) {
StreamsPojoGenerationConfig config = new StreamsPojoGenerationConfig();
String sourceDirectory = "./target/test-classes/activities";
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/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 9d595fe..8cf1697 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
@@ -3,6 +3,7 @@ package org.apache.streams.plugins;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -39,6 +40,8 @@ public class StreamsPojoSourceGeneratorMojo extends AbstractMojo {
private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPojoSourceGeneratorMojo.class);
+ private volatile MojoFailureException mojoFailureException;
+
@Component
public MavenProject project;
@@ -67,7 +70,7 @@ public class StreamsPojoSourceGeneratorMojo extends AbstractMojo {
@Parameter(readonly = true)
public String targetPackage;
- public void execute() throws MojoExecutionException {
+ public void execute() throws MojoExecutionException, MojoFailureException {
addProjectDependenciesToClasspath();
@@ -81,38 +84,30 @@ 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.start();
+ 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);
}
- return;
-// 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());
-//
-// }
-//
-//
-// for( Class clazz : pojoClasses ) {
-// String pojoPath = clazz.getPackage().getName().replace(".pojo.json", ".hive").replace(".","/")+"/";
-// String pojoName = clazz.getSimpleName()+".hql";
-// String pojoHive = renderPojo(clazz);
-// writeFile(outDir+"/"+pojoPath+pojoName, pojoHive);
-// }
+ if( mojoFailureException != null )
+ throw mojoFailureException;
+
+ return;
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/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
new file mode 100644
index 0000000..d1bd848
--- /dev/null
+++ b/streams-plugins/streams-plugin-pojo/src/site/markdown/index.md
@@ -0,0 +1,22 @@
+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
+
+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
+
+#### Example
+
+[streams-plugin-pojo/pom.xml](streams-plugin-pojo/pom.xml "streams-plugin-pojo/pom.xml")
+
+#### 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/95a02d71/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
new file mode 100644
index 0000000..f808b28
--- /dev/null
+++ b/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorCLITest.java
@@ -0,0 +1,43 @@
+package org.apache.streams.plugins.test;
+
+import com.google.common.collect.Lists;
+import com.google.common.io.Files;
+import org.apache.streams.plugins.StreamsPojoSourceGenerator;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+
+import static org.apache.streams.plugins.test.StreamsPojoSourceGeneratorTest.javaFilter;
+
+/**
+ * Created by sblackmon on 5/5/16.
+ */
+public class StreamsPojoSourceGeneratorCLITest {
+
+ private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPojoSourceGeneratorTest.class);
+
+ @Test
+ public void testStreamsPojoSourceGeneratorCLI() throws Exception {
+
+ String sourceDirectory = "target/test-classes/streams-schemas";
+ String targetDirectory = "target/generated-sources/test-cli";
+
+ List<String> argsList = Lists.newArrayList(sourceDirectory, targetDirectory);
+ StreamsPojoSourceGenerator.main(argsList.toArray(new String[0]));
+
+ File testOutput = new File(targetDirectory);
+
+ assert( testOutput != null );
+ assert( testOutput.exists() == true );
+ assert( testOutput.isDirectory() == true );
+
+ Iterable<File> outputIterator = Files.fileTreeTraverser().breadthFirstTraversal(testOutput)
+ .filter(javaFilter);
+ Collection<File> outputCollection = Lists.newArrayList(outputIterator);
+ assert( outputCollection.size() > 133 );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/95a02d71/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 a99f059..1968d90 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
@@ -1,24 +1,25 @@
package org.apache.streams.plugins.test;
import com.google.common.collect.Lists;
+import com.google.common.io.Files;
import junit.framework.TestCase;
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor;
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.apache.streams.plugins.StreamsPojoGenerationConfig;
-import org.apache.streams.plugins.StreamsPojoSourceGenerator;
-import org.apache.streams.plugins.StreamsPojoSourceGeneratorMojo;
+import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
-import java.io.FileFilter;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
+import static org.apache.streams.plugins.test.StreamsPojoSourceGeneratorTest.javaFilter;
+
/**
- * Test that Activity beans are compatible with the example activities in the spec.
+ * Tests that streams-plugin-pojo running via maven can convert activity schemas into pojos
+ * which then compile.
*/
public class StreamsPojoSourceGeneratorMojoTest extends TestCase {
@@ -30,12 +31,7 @@ public class StreamsPojoSourceGeneratorMojoTest extends TestCase {
super.setUp();
}
- /**
- * Tests that streams-plugin-pojo running via maven can convert activity schemas into pojos
- * which then compile.
- *
- * @throws Exception
- */
+
@Test
public void testStreamsPojoSourceGeneratorMojo() throws Exception {
@@ -56,41 +52,17 @@ public class StreamsPojoSourceGeneratorMojoTest extends TestCase {
verifier.verifyErrorFreeLog();
verifier.resetStreams();
-//
-// File pom = getTestFile( );
-// assertNotNull( pom );
-// assertTrue( pom.exists() );
-//
-// StreamsPojoSourceGeneratorMojo myMojo = (StreamsPojoSourceGeneratorMojo)
-// lookupMojo( "pojo", pom);
-// assertNotNull( myMojo );
-// myMojo.execute();
-//
-// File testOutput = new File( "target/generated-sources/test-mojo");
-// FileFilter javaFilter = new FileFilter() {
-// @Override
-// public boolean accept(File pathname) {
-// if( pathname.getName().endsWith(".java") )
-// return true;
-// return false;
-// }
-// };
-//
-// assert( testOutput != null );
-// assert( testOutput.exists() == true );
-// assert( testOutput.isDirectory() == true );
-// 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 );
+
+ File testOutput = new File(testDir.getAbsolutePath() + "/target/generated-sources/test-mojo");
+
+ assert( testOutput != null );
+ assert( testOutput.exists() == true );
+ assert( testOutput.isDirectory() == true );
+
+ Iterable<File> outputIterator = Files.fileTreeTraverser().breadthFirstTraversal(testOutput)
+ .filter(javaFilter);
+ Collection<File> outputCollection = Lists.newArrayList(outputIterator);
+ assert( outputCollection.size() > 133 );
+
}
}
\ No newline at end of file