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/11/25 20:24:53 UTC
[12/42] incubator-streams git commit: STREAMS-440: custom
checkstyle.xml, address compliance
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/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 8638046..eb9490d 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
@@ -34,49 +34,57 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.List;
-@Mojo( name = "generate-resources",
- defaultPhase = LifecyclePhase.GENERATE_RESOURCES
-)
-@Execute( goal = "generate-resources",
- phase = LifecyclePhase.GENERATE_RESOURCES
-)
+@Mojo (
+ name = "generate-resources",
+ defaultPhase = LifecyclePhase.GENERATE_RESOURCES
+ )
+@Execute (
+ goal = "generate-resources",
+ phase = LifecyclePhase.GENERATE_RESOURCES
+ )
public class StreamsHiveResourceGeneratorMojo extends AbstractMojo {
- private final static Logger LOGGER = LoggerFactory.getLogger(StreamsHiveResourceGeneratorMojo.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(StreamsHiveResourceGeneratorMojo.class);
- private volatile MojoFailureException mojoFailureException;
+ private volatile MojoFailureException mojoFailureException;
- @Component
- private MavenProject project;
+ @Component
+ private MavenProject project;
- @Parameter( defaultValue = "${project.basedir}", readonly = true )
- private File basedir;
+ @Parameter( defaultValue = "${project.basedir}", readonly = true )
+ private File basedir;
- @Parameter( defaultValue = "src/main/jsonschema", readonly = true ) // Maven 3 only
- public String sourceDirectory;
+ @Parameter( defaultValue = "src/main/jsonschema", readonly = true ) // Maven 3 only
+ public String sourceDirectory;
- @Parameter( readonly = true ) // Maven 3 only
- public List<String> sourcePaths;
+ @Parameter( readonly = true ) // Maven 3 only
+ public List<String> sourcePaths;
- @Parameter(defaultValue = "./target/generated-resources/hive", readonly = true)
- public String targetDirectory;
+ @Parameter(defaultValue = "./target/generated-resources/hive", readonly = true)
+ public String targetDirectory;
- public void execute() throws MojoExecutionException, MojoFailureException {
+ /**
+ * execute StreamsHiveResourceGeneratorMojo.
+ * @throws MojoExecutionException MojoExecutionException
+ * @throws MojoFailureException MojoFailureException
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
- //addProjectDependenciesToClasspath();
+ //addProjectDependenciesToClasspath();
- StreamsHiveGenerationConfig config = new StreamsHiveGenerationConfig();
+ StreamsHiveGenerationConfig config = new StreamsHiveGenerationConfig();
- if( sourcePaths != null && sourcePaths.size() > 0)
- config.setSourcePaths(sourcePaths);
- else
- config.setSourceDirectory(sourceDirectory);
- config.setTargetDirectory(targetDirectory);
+ if ( sourcePaths != null && sourcePaths.size() > 0) {
+ config.setSourcePaths(sourcePaths);
+ } else {
+ config.setSourceDirectory(sourceDirectory);
+ }
+ config.setTargetDirectory(targetDirectory);
- StreamsHiveResourceGenerator streamsHiveResourceGenerator = new StreamsHiveResourceGenerator(config);
+ StreamsHiveResourceGenerator streamsHiveResourceGenerator = new StreamsHiveResourceGenerator(config);
- streamsHiveResourceGenerator.run();
+ streamsHiveResourceGenerator.run();
- }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/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
index 33113aa..827a992 100644
--- 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
@@ -19,13 +19,12 @@
package org.apache.streams.plugins.test;
-import com.google.common.base.Predicate;
+import org.apache.streams.plugins.hive.StreamsHiveResourceGenerator;
+
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;
@@ -33,28 +32,28 @@ import java.util.List;
import static org.apache.streams.plugins.test.StreamsHiveResourceGeneratorTest.hqlFilter;
/**
- * Created by sblackmon on 5/5/16.
+ * Test whether StreamsHiveResourceGeneratorCLI generates resources.
*/
public class StreamsHiveResourceGeneratorCLITest {
- @Test
- public void testStreamsHiveResourceGeneratorCLI() throws Exception {
+ @Test
+ public void testStreamsHiveResourceGeneratorCLI() throws Exception {
- String sourceDirectory = "target/test-classes/activitystreams-schemas";
- String targetDirectory = "target/generated-resources/hive-cli";
+ String sourceDirectory = "target/test-classes/activitystreams-schemas";
+ String targetDirectory = "target/generated-resources/hive-cli";
- List<String> argsList = Lists.newArrayList(sourceDirectory, targetDirectory);
- StreamsHiveResourceGenerator.main(argsList.toArray(new String[0]));
+ List<String> argsList = Lists.newArrayList(sourceDirectory, targetDirectory);
+ StreamsHiveResourceGenerator.main(argsList.toArray(new String[0]));
- File testOutput = new File(targetDirectory);
+ File testOutput = new File(targetDirectory);
- assert( testOutput != null );
- assert( testOutput.exists() == true );
- assert( testOutput.isDirectory() == true );
+ 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 );
- }
+ 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/5dffd5c3/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorMojoIT.java
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorMojoIT.java b/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorMojoIT.java
index e78a175..b5ea4b4 100644
--- a/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorMojoIT.java
+++ b/streams-plugins/streams-plugin-hive/src/test/java/org/apache/streams/plugins/test/StreamsHiveResourceGeneratorMojoIT.java
@@ -36,48 +36,47 @@ import java.util.List;
import static org.apache.streams.plugins.test.StreamsHiveResourceGeneratorTest.hqlFilter;
/**
- * Tests that streams-plugin-hive running via maven generates hql resources
+ * Tests that streams-plugin-hive running via maven generates txt resources.
*/
public class StreamsHiveResourceGeneratorMojoIT extends TestCase {
- private final static Logger LOGGER = LoggerFactory.getLogger(StreamsHiveResourceGeneratorMojoIT.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(StreamsHiveResourceGeneratorMojoIT.class);
- protected void setUp() throws Exception
- {
- // required for mojo lookups to work
- super.setUp();
- }
+ protected void setUp() throws Exception {
+ // required for mojo lookups to work
+ super.setUp();
+ }
- @Test
- public void testStreamsHiveResourceGeneratorMojo() throws Exception {
+ @Test
+ public void testStreamsHiveResourceGeneratorMojo() throws Exception {
- File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/streams-plugin-hive" );
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/streams-plugin-hive" );
- Verifier verifier;
+ Verifier verifier;
- verifier = new Verifier( testDir.getAbsolutePath() );
+ verifier = new Verifier( testDir.getAbsolutePath() );
- List cliOptions = new ArrayList();
- cliOptions.add( "-N" );
- verifier.executeGoals( Lists.<String>newArrayList(
- "clean",
- "dependency:unpack-dependencies",
- "generate-resources"));
+ List cliOptions = new ArrayList();
+ cliOptions.add( "-N" );
+ verifier.executeGoals( Lists.<String>newArrayList(
+ "clean",
+ "dependency:unpack-dependencies",
+ "generate-resources"));
- verifier.verifyErrorFreeLog();
+ verifier.verifyErrorFreeLog();
- verifier.resetStreams();
+ verifier.resetStreams();
- File testOutput = new File(testDir.getAbsolutePath() + "/target/generated-resources/hive-mojo");
+ File testOutput = new File(testDir.getAbsolutePath() + "/target/generated-resources/hive-mojo");
- assert( testOutput != null );
- assert( testOutput.exists() == true );
- assert( testOutput.isDirectory() == true );
+ 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 );
- }
+ 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/5dffd5c3/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 c5f5ed7..a5374a0 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
@@ -19,25 +19,21 @@
package org.apache.streams.plugins.test;
+import org.apache.streams.plugins.hive.StreamsHiveGenerationConfig;
+import org.apache.streams.plugins.hive.StreamsHiveResourceGenerator;
+
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.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;
-import javax.annotation.Nullable;
import java.io.File;
import java.util.Collection;
-import java.util.Iterator;
-
-import static org.apache.streams.util.schema.FileUtil.dropSourcePathPrefix;
+import javax.annotation.Nullable;
/**
* Test that Activity beans are compatible with the example activities in the spec.
@@ -45,79 +41,81 @@ import static org.apache.streams.util.schema.FileUtil.dropSourcePathPrefix;
@Ignore
public class StreamsHiveResourceGeneratorTest {
- private final static Logger LOGGER = LoggerFactory.getLogger(StreamsHiveResourceGeneratorTest.class);
+ private static final 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;
- }
- };
+ 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
- *
- * @throws Exception
- */
- @Test
- public void StreamsHiveResourceGenerator() throws Exception {
+ /**
+ * Tests that all example activities can be loaded into Activity beans.
+ *
+ * @throws Exception Exception
+ */
+ @Test
+ public void testStreamsHiveResourceGenerator() throws Exception {
- StreamsHiveGenerationConfig config = new StreamsHiveGenerationConfig();
+ StreamsHiveGenerationConfig config = new StreamsHiveGenerationConfig();
- String sourceDirectory = "target/test-classes/activitystreams-schemas";
+ String sourceDirectory = "target/test-classes/activitystreams-schemas";
- config.setSourceDirectory(sourceDirectory);
+ config.setSourceDirectory(sourceDirectory);
- config.setTargetDirectory("target/generated-resources/test");
+ config.setTargetDirectory("target/generated-resources/test");
- config.setExclusions(Sets.newHashSet("attachments"));
+ config.setExclusions(Sets.newHashSet("attachments"));
- config.setMaxDepth(2);
+ config.setMaxDepth(2);
- StreamsHiveResourceGenerator streamsHiveResourceGenerator = new StreamsHiveResourceGenerator(config);
- streamsHiveResourceGenerator.run();
+ StreamsHiveResourceGenerator streamsHiveResourceGenerator = new StreamsHiveResourceGenerator(config);
+ streamsHiveResourceGenerator.run();
- File testOutput = config.getTargetDirectory();
+ File testOutput = config.getTargetDirectory();
- assert( testOutput != null );
- assert( testOutput.exists() == true );
- assert( testOutput.isDirectory() == true );
+ 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 );
+ Iterable<File> outputIterator = Files.fileTreeTraverser().breadthFirstTraversal(testOutput)
+ .filter(hqlFilter);
+ Collection<File> outputCollection = Lists.newArrayList(outputIterator);
+ assert ( outputCollection.size() == 133 );
- /* TODO: figure out how to compare without AL header interfering
- String expectedDirectory = "target/test-classes/expected";
- File testExpected = new File( expectedDirectory );
+ /* TODO: figure out how to compare without AL header interfering
+ String expectedDirectory = "target/test-classes/expected";
+ File testExpected = new File( expectedDirectory );
- Iterable<File> expectedIterator = Files.fileTreeTraverser().breadthFirstTraversal(testExpected)
- .filter(hqlFilter);
- Collection<File> expectedCollection = Lists.newArrayList(expectedIterator);
+ Iterable<File> expectedIterator = Files.fileTreeTraverser().breadthFirstTraversal(testExpected)
+ .filter(hqlFilter);
+ Collection<File> expectedCollection = Lists.newArrayList(expectedIterator);
- int fails = 0;
+ 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();
+ 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();
+ }
+ */
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/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
index 2af8eeb..c4358a0 100644
--- 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
@@ -20,6 +20,7 @@
package org.apache.streams.plugins.pig;
import org.apache.streams.util.schema.GenerationConfig;
+
import org.jsonschema2pojo.DefaultGenerationConfig;
import org.jsonschema2pojo.util.URLUtil;
@@ -33,70 +34,73 @@ import java.util.List;
import java.util.Set;
/**
- * Configures StreamsHiveResourceGenerator
- *
- *
+ * Configures StreamsPigResourceGenerator.
*/
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;
+ 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);
+ }
+
+ /**
+ * get all sources.
+ * @return Iterator of URL
+ */
+ @Override
+ public Iterator<URL> getSource() {
+ if (null != sourceDirectory) {
+ return Collections.singleton(URLUtil.parseURL(sourceDirectory)).iterator();
}
-
- private Set<String> exclusions = new HashSet<String>();
-
- public int getMaxDepth() {
- return maxDepth;
+ 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 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;
- }
+ public void setMaxDepth(int maxDepth) {
+ this.maxDepth = maxDepth;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/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
index 465cdb2..039f45b 100644
--- 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
@@ -19,12 +19,6 @@
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.util.schema.FieldType;
import org.apache.streams.util.schema.FieldUtil;
import org.apache.streams.util.schema.FileUtil;
@@ -32,6 +26,13 @@ import org.apache.streams.util.schema.GenerationConfig;
import org.apache.streams.util.schema.Schema;
import org.apache.streams.util.schema.SchemaStore;
import org.apache.streams.util.schema.SchemaStoreImpl;
+
+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.jsonschema2pojo.util.URLUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,276 +50,312 @@ import static org.apache.streams.util.schema.FileUtil.dropSourcePathPrefix;
import static org.apache.streams.util.schema.FileUtil.swapExtension;
import static org.apache.streams.util.schema.FileUtil.writeFile;
+/**
+ * Embed within your own java code
+ *
+ * <p/>
+ * StreamsPigGenerationConfig config = new StreamsPigGenerationConfig();
+ * config.setSourceDirectory("src/main/jsonschema");
+ * config.setTargetDirectory("target/generated-resources");
+ * StreamsPigResourceGenerator generator = new StreamsPigResourceGenerator(config);
+ * generator.run();
+ *
+ */
public class StreamsPigResourceGenerator implements Runnable {
- private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPigResourceGenerator.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(StreamsPigResourceGenerator.class);
- private final static String LS = System.getProperty("line.separator");
+ private static final String LS = System.getProperty("line.separator");
- private StreamsPigGenerationConfig config;
+ private StreamsPigGenerationConfig config;
- private SchemaStore schemaStore = new SchemaStoreImpl();
+ private SchemaStore schemaStore = new SchemaStoreImpl();
- private int currentDepth = 0;
+ private int currentDepth = 0;
- public static void main(String[] args) {
- StreamsPigGenerationConfig config = new StreamsPigGenerationConfig();
+ /**
+ * Run from CLI without Maven
+ *
+ * <p/>
+ * java -jar streams-plugin-pig-jar-with-dependencies.jar StreamsPigResourceGenerator src/main/jsonschema target/generated-resources
+ *
+ * @param args [sourceDirectory, targetDirectory]
+ * */
+ public static void main(String[] args) {
+ StreamsPigGenerationConfig config = new StreamsPigGenerationConfig();
- String sourceDirectory = "src/main/jsonschema";
- String targetDirectory = "target/generated-resources/pig-cli";
+ 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);
+ if ( args.length > 0 ) {
+ sourceDirectory = args[0];
+ }
+ if ( args.length > 1 ) {
+ targetDirectory = args[1];
+ }
- StreamsPigResourceGenerator streamsPigResourceGenerator = new StreamsPigResourceGenerator(config);
- streamsPigResourceGenerator.run();
+ config.setSourceDirectory(sourceDirectory);
+ config.setTargetDirectory(targetDirectory);
- }
+ StreamsPigResourceGenerator streamsPigResourceGenerator = new StreamsPigResourceGenerator(config);
+ streamsPigResourceGenerator.run();
- public StreamsPigResourceGenerator(StreamsPigGenerationConfig config) {
- this.config = config;
- }
+ }
- public void run() {
+ public StreamsPigResourceGenerator(StreamsPigGenerationConfig config) {
+ this.config = config;
+ }
- checkNotNull(config);
+ @Override
+ public void run() {
- generate(config);
+ checkNotNull(config);
- }
+ generate(config);
- public void generate(StreamsPigGenerationConfig config) {
+ }
- LinkedList<File> sourceFiles = new LinkedList<File>();
+ /**
+ * run generate using supplied StreamsPigGenerationConfig.
+ * @param config StreamsPigGenerationConfig
+ */
+ public void generate(StreamsPigGenerationConfig config) {
- for (Iterator<URL> sources = config.getSource(); sources.hasNext(); ) {
- URL source = sources.next();
- sourceFiles.add(URLUtil.getFileFromURL(source));
- }
+ LinkedList<File> sourceFiles = new LinkedList<File>();
- LOGGER.info("Seeded with {} source paths:", sourceFiles.size());
+ for (Iterator<URL> sources = config.getSource(); sources.hasNext(); ) {
+ URL source = sources.next();
+ sourceFiles.add(URLUtil.getFileFromURL(source));
+ }
- FileUtil.resolveRecursive((GenerationConfig) config, sourceFiles);
+ LOGGER.info("Seeded with {} source paths:", sourceFiles.size());
- LOGGER.info("Resolved {} schema files:", sourceFiles.size());
+ FileUtil.resolveRecursive((GenerationConfig) config, sourceFiles);
- for (Iterator<File> iterator = sourceFiles.iterator(); iterator.hasNext(); ) {
- File item = iterator.next();
- schemaStore.create(item.toURI());
- }
+ LOGGER.info("Resolved {} schema files:", sourceFiles.size());
- LOGGER.info("Identified {} objects:", schemaStore.getSize());
+ for (Iterator<File> iterator = sourceFiles.iterator(); iterator.hasNext(); ) {
+ File item = iterator.next();
+ schemaStore.create(item.toURI());
+ }
- 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("Identified {} objects:", schemaStore.getSize());
- LOGGER.info("Processing {}:", resourcePath);
+ 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");
- String resourceId = schemaSymbol(schema);
+ LOGGER.info("Processing {}:", resourcePath);
- String resourceContent = generateResource(schema, resourceId);
+ String resourceId = schemaSymbol(schema);
- writeFile(outputFile, resourceContent);
+ String resourceContent = generateResource(schema, resourceId);
- LOGGER.info("Wrote {}:", outputFile);
- }
- }
- }
+ writeFile(outputFile, resourceContent);
- 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();
+ LOGGER.info("Wrote {}:", outputFile);
+ }
}
-
- 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;
+ }
+
+ /**
+ * generateResource String from schema and resourceId.
+ * @param schema Schema
+ * @param resourceId String
+ * @return mapping
+ */
+ 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();
+ }
+
+ protected 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);
}
-
- 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 resolvedItems = schemaStore.resolveItems(schema, fieldNode, fieldId);
- if( resolvedItems != null && currentDepth <= config.getMaxDepth()) {
- StringBuilder arrayItemsBuilder = appendArrayItems(new StringBuilder(), schema, fieldId, resolvedItems, 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());
- }
- }
+ 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 resolvedItems = schemaStore.resolveItems(schema, fieldNode, fieldId);
+ if ( resolvedItems != null && currentDepth <= config.getMaxDepth()) {
+ StringBuilder arrayItemsBuilder = appendArrayItems(new StringBuilder(), schema, fieldId, resolvedItems, 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;
+ 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;
+ }
+
+ protected StringBuilder appendArrayItems(StringBuilder builder, Schema schema, String fieldId, ObjectNode itemsNode, Character seperator) {
+ // not safe to append nothing
+ checkNotNull(builder);
+ if ( itemsNode == null ) {
+ 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;
+ 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 ex) {
+ LOGGER.warn("No item type resolvable for {}", fieldId);
}
- 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;
+ 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);
+ 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 ) {
+ if ( propertiesNode != null && propertiesNode.isObject() && propertiesNode.size() > 0 ) {
- currentDepth += 1;
+ currentDepth += 1;
- if( !Strings.isNullOrEmpty(fieldId)) {
- builder.append(pigEscape(fieldId));
- builder.append(seperator);
- builder.append("(");
- builder = appendPropertiesNode(builder, schema, propertiesNode, ':');
- builder.append(")");
- }
+ if ( !Strings.isNullOrEmpty(fieldId)) {
+ builder.append(pigEscape(fieldId));
+ builder.append(seperator);
+ builder.append("(");
+ builder = appendPropertiesNode(builder, schema, propertiesNode, ':');
+ builder.append(")");
+ }
- currentDepth -= 1;
+ currentDepth -= 1;
- }
- checkNotNull(builder);
- return builder;
}
-
- private static String pigEscape( String fieldId ) {
- return fieldId;
+ 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 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;
}
-
- 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";
- }
+ // 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/5dffd5c3/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
index 1d2673f..b1087c4 100644
--- 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
@@ -34,47 +34,55 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.List;
-@Mojo( name = "generate-resources",
- defaultPhase = LifecyclePhase.GENERATE_RESOURCES
-)
-@Execute( goal = "generate-resources",
- phase = LifecyclePhase.GENERATE_RESOURCES
-)
+@Mojo (
+ name = "generate-resources",
+ defaultPhase = LifecyclePhase.GENERATE_RESOURCES
+ )
+@Execute (
+ goal = "generate-resources",
+ phase = LifecyclePhase.GENERATE_RESOURCES
+ )
public class StreamsPigResourceGeneratorMojo extends AbstractMojo {
- private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPigResourceGeneratorMojo.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(StreamsPigResourceGeneratorMojo.class);
- private volatile MojoFailureException mojoFailureException;
+ private volatile MojoFailureException mojoFailureException;
- @Component
- private MavenProject project;
+ @Component
+ private MavenProject project;
- @Parameter( defaultValue = "${project.basedir}", readonly = true )
- private File basedir;
+ @Parameter( defaultValue = "${project.basedir}", readonly = true )
+ private File basedir;
- @Parameter( defaultValue = "src/main/jsonschema", readonly = true ) // Maven 3 only
- public String sourceDirectory;
+ @Parameter( defaultValue = "src/main/jsonschema", readonly = true ) // Maven 3 only
+ public String sourceDirectory;
- @Parameter( readonly = true ) // Maven 3 only
- public List<String> sourcePaths;
+ @Parameter( readonly = true ) // Maven 3 only
+ public List<String> sourcePaths;
- @Parameter(defaultValue = "target/generated-resources/pig", readonly = true)
- public String targetDirectory;
+ @Parameter(defaultValue = "target/generated-resources/pig", readonly = true)
+ public String targetDirectory;
- public void execute() throws MojoExecutionException, MojoFailureException {
+ /**
+ * execute StreamsPigResourceGeneratorMojo.
+ * @throws MojoExecutionException MojoExecutionException
+ * @throws MojoFailureException MojoFailureException
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
- //addProjectDependenciesToClasspath();
+ //addProjectDependenciesToClasspath();
- StreamsPigGenerationConfig config = new StreamsPigGenerationConfig();
+ 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);
- streamsPigResourceGenerator.run();
+ if ( sourcePaths != null && sourcePaths.size() > 0) {
+ config.setSourcePaths(sourcePaths);
+ } else {
+ config.setSourceDirectory(sourceDirectory);
}
+ config.setTargetDirectory(targetDirectory);
+
+ StreamsPigResourceGenerator streamsPigResourceGenerator = new StreamsPigResourceGenerator(config);
+ streamsPigResourceGenerator.run();
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/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 7157023..9cf39ef 100644
--- a/streams-plugins/streams-plugin-pig/src/site/markdown/index.md
+++ b/streams-plugins/streams-plugin-pig/src/site/markdown/index.md
@@ -22,7 +22,7 @@ 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);
+ StreamsPigResourceGenerator generator = new StreamsPigResourceGenerator(config);
generator.run();
##### CLI
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/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 55daaf2..6802667 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,9 +19,10 @@
package org.apache.streams.plugins.pig.test;
+import org.apache.streams.plugins.pig.StreamsPigResourceGenerator;
+
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;
@@ -31,28 +32,28 @@ import java.util.List;
import static org.apache.streams.plugins.pig.test.StreamsPigResourceGeneratorTest.pigFilter;
/**
- * Created by sblackmon on 5/5/16.
+ * Test whether StreamsPigResourceGeneratorCLI generates resources.
*/
public class StreamsPigResourceGeneratorCLITest {
- @Test
- public void testStreamsPigResourceGeneratorCLI() throws Exception {
+ @Test
+ public void testStreamsPigResourceGeneratorCLI() throws Exception {
- String sourceDirectory = "target/test-classes/activitystreams-schemas";
- String targetDirectory = "target/generated-resources/pig-cli";
+ String sourceDirectory = "target/test-classes/activitystreams-schemas";
+ String targetDirectory = "target/generated-resources/pig-cli";
- List<String> argsList = Lists.newArrayList(sourceDirectory, targetDirectory);
- StreamsPigResourceGenerator.main(argsList.toArray(new String[0]));
+ List<String> argsList = Lists.newArrayList(sourceDirectory, targetDirectory);
+ StreamsPigResourceGenerator.main(argsList.toArray(new String[0]));
- File testOutput = new File(targetDirectory);
+ File testOutput = new File(targetDirectory);
- assert( testOutput != null );
- assert( testOutput.exists() == true );
- assert( testOutput.isDirectory() == true );
+ 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 );
- }
+ 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/5dffd5c3/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorMojoIT.java
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorMojoIT.java b/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorMojoIT.java
index a584774..5cd612f 100644
--- a/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorMojoIT.java
+++ b/streams-plugins/streams-plugin-pig/src/test/java/org/apache/streams/plugins/pig/test/StreamsPigResourceGeneratorMojoIT.java
@@ -36,48 +36,47 @@ 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
+ * Tests that streams-plugin-pig running via maven generates pig resources.
*/
public class StreamsPigResourceGeneratorMojoIT extends TestCase {
- private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPigResourceGeneratorMojoIT.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(StreamsPigResourceGeneratorMojoIT.class);
- protected void setUp() throws Exception
- {
- // required for mojo lookups to work
- super.setUp();
- }
+ protected void setUp() throws Exception {
+ // required for mojo lookups to work
+ super.setUp();
+ }
- @Test
- public void testStreamsPigResourceGeneratorMojo() throws Exception {
+ @Test
+ public void testStreamsPigResourceGeneratorMojo() throws Exception {
- File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/streams-plugin-pig" );
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/streams-plugin-pig" );
- Verifier verifier;
+ Verifier verifier;
- verifier = new Verifier( testDir.getAbsolutePath() );
+ verifier = new Verifier( testDir.getAbsolutePath() );
- List cliOptions = new ArrayList();
- cliOptions.add( "-N" );
- verifier.executeGoals( Lists.<String>newArrayList(
- "clean",
- "dependency:unpack-dependencies",
- "generate-resources"));
+ List cliOptions = new ArrayList();
+ cliOptions.add( "-N" );
+ verifier.executeGoals( Lists.<String>newArrayList(
+ "clean",
+ "dependency:unpack-dependencies",
+ "generate-resources"));
- verifier.verifyErrorFreeLog();
+ verifier.verifyErrorFreeLog();
- verifier.resetStreams();
+ verifier.resetStreams();
- File testOutput = new File(testDir.getAbsolutePath() + "/target/generated-resources/pig-mojo");
+ File testOutput = new File(testDir.getAbsolutePath() + "/target/generated-resources/pig-mojo");
- assert( testOutput != null );
- assert( testOutput.exists() == true );
- assert( testOutput.isDirectory() == true );
+ 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 );
- }
+ 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/5dffd5c3/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 82284dc..a51778f 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
@@ -19,102 +19,100 @@
package org.apache.streams.plugins.pig.test;
+import org.apache.streams.plugins.pig.StreamsPigGenerationConfig;
+import org.apache.streams.plugins.pig.StreamsPigResourceGenerator;
+
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.util.schema.FileUtil.dropSourcePathPrefix;
+import javax.annotation.Nullable;
/**
* 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/activitystreams-schemas";
-
- config.setSourceDirectory(sourceDirectory);
-
- config.setTargetDirectory("target/generated-resources/pig");
-
- config.setExclusions(Sets.newHashSet("attachments"));
-
- config.setMaxDepth(2);
-
- StreamsPigResourceGenerator streamsPigResourceGenerator = new StreamsPigResourceGenerator(config);
- streamsPigResourceGenerator.run();
-
- File testOutput = config.getTargetDirectory();
-
- 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 );
-
- // TODO: figure out how to do a match to a test resources that has an apache header.
-// 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(objectActual, objectExpected) == true ) {
-// LOGGER.info("Exact Match!");
-// } else {
-// LOGGER.info("No Match!");
-// fails++;
-// }
-// }
-// if( fails > 0 ) {
-// LOGGER.info("Fails: {}", fails);
-// Assert.fail();
-// }
+ private static final 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 StreamsPigResourceGenerator via SDK generates pig resources.
+ *
+ * @throws Exception Exception
+ */
+ @Test
+ public void testStreamsPigResourceGenerator() throws Exception {
+
+ StreamsPigGenerationConfig config = new StreamsPigGenerationConfig();
+
+ String sourceDirectory = "target/test-classes/activitystreams-schemas";
+
+ config.setSourceDirectory(sourceDirectory);
+
+ config.setTargetDirectory("target/generated-resources/pig");
+
+ config.setExclusions(Sets.newHashSet("attachments"));
+
+ config.setMaxDepth(2);
+
+ StreamsPigResourceGenerator streamsPigResourceGenerator = new StreamsPigResourceGenerator(config);
+ streamsPigResourceGenerator.run();
+
+ File testOutput = config.getTargetDirectory();
+
+ 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 );
+
+ // TODO: figure out how to do a match to a test resources that has an apache header.
+ // 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(objectActual, objectExpected) == true ) {
+ // LOGGER.info("Exact Match!");
+ // } else {
+ // LOGGER.info("No Match!");
+ // fails++;
+ // }
+ // }
+ // if( fails > 0 ) {
+ // LOGGER.info("Fails: {}", fails);
+ // Assert.fail();
+ // }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoGenerationConfig.java
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoGenerationConfig.java b/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoGenerationConfig.java
index b25cc9f..b2b156f 100644
--- a/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoGenerationConfig.java
+++ b/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoGenerationConfig.java
@@ -19,16 +19,10 @@
package org.apache.streams.plugins;
-import org.jsonschema2pojo.AnnotationStyle;
-import org.jsonschema2pojo.Annotator;
import org.jsonschema2pojo.DefaultGenerationConfig;
-import org.jsonschema2pojo.GenerationConfig;
-import org.jsonschema2pojo.SourceType;
-import org.jsonschema2pojo.rules.RuleFactory;
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;
@@ -36,87 +30,88 @@ import java.util.Iterator;
import java.util.List;
/**
- * Created by sblackmon on 3/27/16.
+ * Configures StreamsPojoSourceGenerator.
*/
public class StreamsPojoGenerationConfig extends DefaultGenerationConfig {
- private String sourceDirectory;
- private List<String> sourcePaths;
- private String targetPackage;
- private String targetDirectory;
-
- public void setSourceDirectory(String sourceDirectory) {
- this.sourceDirectory = sourceDirectory;
- }
-
- public void setSourcePaths(List<String> sourcePaths) {
- this.sourcePaths = sourcePaths;
+ private String sourceDirectory;
+ private List<String> sourcePaths;
+ private String targetPackage;
+ private String targetDirectory;
+
+ public void setSourceDirectory(String sourceDirectory) {
+ this.sourceDirectory = sourceDirectory;
+ }
+
+ public void setSourcePaths(List<String> sourcePaths) {
+ this.sourcePaths = sourcePaths;
+ }
+
+ public void setTargetPackage(String targetPackage) {
+ this.targetPackage = targetPackage;
+ }
+
+ public void setTargetDirectory(String targetDirectory) {
+ this.targetDirectory = targetDirectory;
+ }
+
+ @Override
+ public String getTargetPackage() {
+ return targetPackage;
+ }
+
+ @Override
+ public File getTargetDirectory() {
+ return new File(targetDirectory);
+ }
+
+ @Override
+ public Iterator<URL> getSource() {
+ if (null != sourceDirectory) {
+ return Collections.singleton(URLUtil.parseURL(sourceDirectory)).iterator();
}
-
- public void setTargetPackage(String targetPackage) {
- this.targetPackage = targetPackage;
+ List<URL> sourceUrls = new ArrayList<URL>();
+ if ( sourcePaths != null && sourcePaths.size() > 0) {
+ for (String source : sourcePaths) {
+ sourceUrls.add(URLUtil.parseURL(source));
+ }
}
-
- public void setTargetDirectory(String targetDirectory) {
- this.targetDirectory = targetDirectory;
- }
-
- @Override
- public String getTargetPackage() {
- return targetPackage;
- }
-
- @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();
- }
-
- @Override
- public boolean isGenerateBuilders() {
- return true;
- }
-
- @Override
- public boolean isUseLongIntegers() {
- return true;
- }
-
- @Override
- public boolean isRemoveOldOutput() {
- return true;
- }
-
- @Override
- public boolean isUseJodaDates() {
- return true;
- }
-
- @Override
- public boolean isIncludeJsr303Annotations() {
- return true;
- }
-
- @Override
- public boolean isUseCommonsLang3() {
- return true;
- }
-
-// @Override
-// public boolean isIncludeAdditionalProperties() {
-// return true;
-// }
+ return sourceUrls.iterator();
+ }
+
+ @Override
+ public boolean isGenerateBuilders() {
+ return true;
+ }
+
+ @Override
+ public boolean isUseLongIntegers() {
+ return true;
+ }
+
+ @Override
+ public boolean isRemoveOldOutput() {
+ return true;
+ }
+
+ @Override
+ public boolean isUseJodaDates() {
+ return true;
+ }
+
+ @Override
+ public boolean isIncludeJsr303Annotations() {
+ return true;
+ }
+
+ @Override
+ public boolean isUseCommonsLang3() {
+ return true;
+ }
+
+ // @Override
+ // public boolean isIncludeAdditionalProperties() {
+ // return true;
+ // }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/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 7115c60c..e5a516e 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
@@ -30,65 +30,85 @@ import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
/**
- * Created by sblackmon on 4/20/16.
+ * Embed within your own java code
+ *
+ * <p/>
+ * StreamsPojoGenerationConfig config = new StreamsPojoGenerationConfig();
+ * config.setSourceDirectory("src/main/jsonschema");
+ * config.setTargetDirectory("target/generated-sources/pojo");
+ * StreamsPojoSourceGenerator generator = new StreamsPojoSourceGenerator(config);
+ * generator.run();
+ *
*/
public class StreamsPojoSourceGenerator implements Runnable {
- private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPojoSourceGenerator.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(StreamsPojoSourceGenerator.class);
- private final static String LS = System.getProperty("line.separator");
+ private static final String LS = System.getProperty("line.separator");
- private StreamsPojoGenerationConfig config;
+ private StreamsPojoGenerationConfig config;
- public static void main(String[] args) {
- StreamsPojoGenerationConfig config = new StreamsPojoGenerationConfig();
+ /**
+ * Run from CLI without Maven
+ *
+ * <p/>
+ * java -jar streams-plugin-pojo-jar-with-dependencies.jar StreamsPojoSourceGenerator src/main/jsonschema target/generated-sources
+ *
+ * @param args [sourceDirectory, targetDirectory, targetPackage]
+ * */
+ public static void main(String[] args) {
+ StreamsPojoGenerationConfig config = new StreamsPojoGenerationConfig();
- String sourceDirectory = "src/main/jsonschema";
- String targetDirectory = "target/generated-sources/pojo";
- String targetPackage = "";
+ String sourceDirectory = "src/main/jsonschema";
+ String targetDirectory = "target/generated-sources/pojo";
+ String targetPackage = "";
- if( args.length > 0 )
- sourceDirectory = args[0];
- if( args.length > 1 )
- targetDirectory = args[1];
- if( args.length > 2 )
- targetPackage = args[2];
+ if ( args.length > 0 ) {
+ sourceDirectory = args[0];
+ }
+ if ( args.length > 1 ) {
+ targetDirectory = args[1];
+ }
+ if ( args.length > 2 ) {
+ targetPackage = args[2];
+ }
- config.setSourceDirectory(sourceDirectory);
- config.setTargetPackage(targetPackage);
- config.setTargetDirectory(targetDirectory);
+ config.setSourceDirectory(sourceDirectory);
+ config.setTargetPackage(targetPackage);
+ config.setTargetDirectory(targetDirectory);
- StreamsPojoSourceGenerator streamsPojoSourceGenerator = new StreamsPojoSourceGenerator(config);
- streamsPojoSourceGenerator.run();
+ StreamsPojoSourceGenerator streamsPojoSourceGenerator = new StreamsPojoSourceGenerator(config);
+ streamsPojoSourceGenerator.run();
- return;
- }
+ return;
+ }
- public StreamsPojoSourceGenerator(StreamsPojoGenerationConfig config) {
- this.config = config;
- }
+ public StreamsPojoSourceGenerator(StreamsPojoGenerationConfig config) {
+ this.config = config;
+ }
- @Override
- public void run() {
+ @Override
+ public void run() {
- Preconditions.checkNotNull(config);
+ Preconditions.checkNotNull(config);
- try {
- Jsonschema2Pojo.generate(config);
- } catch (Throwable e) {
- LOGGER.error("{} {}", e.getClass(), e.getMessage());
- }
+ try {
+ Jsonschema2Pojo.generate(config);
+ } catch (Throwable ex) {
+ LOGGER.error("{} {}", ex.getClass(), ex.getMessage());
}
-
- private void writeFile(String pojoFile, String pojoHive) {
- try {
- File path = new File(pojoFile);
- File dir = path.getParentFile();
- if( !dir.exists() )
- dir.mkdirs();
- Files.write(Paths.get(pojoFile), pojoHive.getBytes(), StandardOpenOption.CREATE_NEW);
- } catch (Exception e) {
- LOGGER.error("Write Exception: {}", e);
- }
+ }
+
+ private void writeFile(String pojoFile, String pojoHive) {
+ try {
+ File path = new File(pojoFile);
+ File dir = path.getParentFile();
+ if ( !dir.exists() ) {
+ dir.mkdirs();
+ }
+ Files.write(Paths.get(pojoFile), pojoHive.getBytes(), StandardOpenOption.CREATE_NEW);
+ } catch (Exception ex) {
+ LOGGER.error("Write Exception: {}", ex);
}
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/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 c265bb6..7585e7b 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
@@ -29,86 +29,81 @@ 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.jsonschema2pojo.Jsonschema2Pojo;
-import org.jsonschema2pojo.maven.Jsonschema2PojoMojo;
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;
-
-@Mojo( name = "generate-sources",
- defaultPhase = LifecyclePhase.GENERATE_SOURCES
-)
-@Execute( goal = "generate-sources",
- phase = LifecyclePhase.GENERATE_SOURCES
-)
+@Mojo (
+ name = "generate-sources",
+ defaultPhase = LifecyclePhase.GENERATE_SOURCES
+ )
+@Execute (
+ goal = "generate-sources",
+ phase = LifecyclePhase.GENERATE_SOURCES
+ )
public class StreamsPojoSourceGeneratorMojo extends AbstractMojo {
- private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPojoSourceGeneratorMojo.class);
-
- private volatile MojoFailureException mojoFailureException;
-
- @Component
- public MavenProject project;
+ private static final Logger LOGGER = LoggerFactory.getLogger(StreamsPojoSourceGeneratorMojo.class);
- @Parameter( defaultValue = "${project.basedir}", readonly = true )
- public File basedir;
+ private volatile MojoFailureException mojoFailureException;
- @Parameter( defaultValue = "./src/main/jsonschema", readonly = true ) // Maven 3 only
- public String sourceDirectory;
+ @Component
+ public MavenProject project;
- @Parameter( readonly = true ) // Maven 3 only
- public List<String> sourcePaths;
+ @Parameter( defaultValue = "${project.basedir}", readonly = true )
+ public File basedir;
- @Parameter(defaultValue = "./target/generated-sources/pojo", readonly = true)
- public String targetDirectory;
+ @Parameter( defaultValue = "./src/main/jsonschema", readonly = true ) // Maven 3 only
+ public String sourceDirectory;
- @Parameter(readonly = true)
- public String targetPackage;
+ @Parameter( readonly = true ) // Maven 3 only
+ public List<String> sourcePaths;
- public void execute() throws MojoExecutionException, MojoFailureException {
+ @Parameter(defaultValue = "./target/generated-sources/pojo", readonly = true)
+ public String targetDirectory;
- addProjectDependenciesToClasspath();
+ @Parameter(readonly = true)
+ public String targetPackage;
- StreamsPojoGenerationConfig config = new StreamsPojoGenerationConfig();
+ /**
+ * execute StreamsPojoSourceGenerator.
+ * @throws MojoExecutionException MojoExecutionException
+ * @throws MojoFailureException MojoFailureException
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
- if( sourcePaths != null && sourcePaths.size() > 0)
- config.setSourcePaths(sourcePaths);
- else
- config.setSourceDirectory(sourceDirectory);
- config.setTargetPackage(targetPackage);
- config.setTargetDirectory(targetDirectory);
+ addProjectDependenciesToClasspath();
- StreamsPojoSourceGenerator streamsPojoSourceGenerator = new StreamsPojoSourceGenerator(config);
- streamsPojoSourceGenerator.run();
+ StreamsPojoGenerationConfig config = new StreamsPojoGenerationConfig();
+ if ( sourcePaths != null && sourcePaths.size() > 0) {
+ config.setSourcePaths(sourcePaths);
+ } else {
+ config.setSourceDirectory(sourceDirectory);
}
+ config.setTargetPackage(targetPackage);
+ config.setTargetDirectory(targetDirectory);
- private void addProjectDependenciesToClasspath() {
+ StreamsPojoSourceGenerator streamsPojoSourceGenerator = new StreamsPojoSourceGenerator(config);
+ streamsPojoSourceGenerator.run();
- try {
+ }
- ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
- ClassLoader newClassLoader = new ProjectClasspath().getClassLoader(project, oldClassLoader, getLog());
- Thread.currentThread().setContextClassLoader(newClassLoader);
+ private void addProjectDependenciesToClasspath() {
- } catch (DependencyResolutionRequiredException e) {
- LOGGER.info("Skipping addition of project artifacts, there appears to be a dependecy resolution problem", e);
- }
+ try {
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader newClassLoader = new ProjectClasspath().getClassLoader(project, oldClassLoader, getLog());
+ Thread.currentThread().setContextClassLoader(newClassLoader);
+
+ } catch (DependencyResolutionRequiredException ex) {
+ LOGGER.info("Skipping addition of project artifacts, there appears to be a dependecy resolution problem", ex);
}
+ }
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/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 bb41032..4239a31 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
@@ -19,9 +19,10 @@
package org.apache.streams.plugins.test;
+import org.apache.streams.plugins.StreamsPojoSourceGenerator;
+
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;
@@ -33,30 +34,30 @@ import java.util.List;
import static org.apache.streams.plugins.test.StreamsPojoSourceGeneratorTest.javaFilter;
/**
- * Created by sblackmon on 5/5/16.
+ * Test whether StreamsPojoSourceGeneratorCLI generates source files.
*/
public class StreamsPojoSourceGeneratorCLITest {
- private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPojoSourceGeneratorTest.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(StreamsPojoSourceGeneratorTest.class);
- @Test
- public void testStreamsPojoSourceGeneratorCLI() throws Exception {
+ @Test
+ public void testStreamsPojoSourceGeneratorCLI() throws Exception {
- String sourceDirectory = "target/test-classes/activitystreams-schemas";
- String targetDirectory = "target/generated-sources/test-cli";
+ String sourceDirectory = "target/test-classes/activitystreams-schemas";
+ String targetDirectory = "target/generated-sources/test-cli";
- List<String> argsList = Lists.newArrayList(sourceDirectory, targetDirectory);
- StreamsPojoSourceGenerator.main(argsList.toArray(new String[0]));
+ List<String> argsList = Lists.newArrayList(sourceDirectory, targetDirectory);
+ StreamsPojoSourceGenerator.main(argsList.toArray(new String[0]));
- File testOutput = new File(targetDirectory);
+ File testOutput = new File(targetDirectory);
- assert( testOutput != null );
- assert( testOutput.exists() == true );
- assert( testOutput.isDirectory() == true );
+ 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 );
- }
+ Iterable<File> outputIterator = Files.fileTreeTraverser().breadthFirstTraversal(testOutput)
+ .filter(javaFilter);
+ Collection<File> outputCollection = Lists.newArrayList(outputIterator);
+ assert ( outputCollection.size() > 133 );
+ }
}