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:40:59 UTC
[10/32] incubator-streams git commit: STREAMS-398 - pojo generation
STREAMS-398 - pojo generation
code and plugin for generating POJOs now resides in streams-project
unit testing for generating POJOs without maven
unit testing for generating POJOs with maven
Project: http://git-wip-us.apache.org/repos/asf/incubator-streams/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams/commit/bf31cbe0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams/tree/bf31cbe0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams/diff/bf31cbe0
Branch: refs/feature/STREAMS-389,398
Commit: bf31cbe000b950cb07298d7dbc735726d4b91e3d
Parents: 02b5add
Author: Steve Blackmon @steveblackmon <sb...@apache.org>
Authored: Thu Apr 21 11:42:44 2016 -0500
Committer: Steve Blackmon @steveblackmon <sb...@apache.org>
Committed: Thu Apr 21 11:42:44 2016 -0500
----------------------------------------------------------------------
pom.xml | 1 +
streams-plugins/streams-plugin-pojo/pom.xml | 28 ++-
.../plugins/StreamsPojoGenerationConfig.java | 230 ++++---------------
.../plugins/StreamsPojoSourceGenerator.java | 98 ++++++++
.../plugins/StreamsPojoSourceGeneratorMojo.java | 80 +++----
.../StreamsPojoSourceGeneratorMojoTest.java | 96 ++++++++
.../test/StreamsPojoSourceGeneratorTest.java | 43 +++-
.../test/resources/streams-plugin-pojo/pom.xml | 90 +++++++-
streams-pojo/pom.xml | 6 +
9 files changed, 421 insertions(+), 251 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/bf31cbe0/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index b284ae2..30ec5e7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -177,6 +177,7 @@
<module>streams-pojo-extensions</module>
<module>streams-plugins</module>
<module>streams-runtimes</module>
+ <module>streams-schemas</module>
<module>streams-testing</module>
<module>streams-util</module>
<module>streams-verbs</module>
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/bf31cbe0/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 399a371..d7210c8 100644
--- a/streams-plugins/streams-plugin-pojo/pom.xml
+++ b/streams-plugins/streams-plugin-pojo/pom.xml
@@ -43,8 +43,14 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.streams</groupId>
+ <artifactId>streams-schemas</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-core</artifactId>
+ <version>0.4.10</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
@@ -55,6 +61,7 @@
<dependency>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
+ <version>0.4.10</version>
</dependency>
<dependency>
<groupId>org.apache.streams</groupId>
@@ -86,6 +93,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>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.3.3</version>
@@ -216,19 +229,20 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
- <version>2.4</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>resource-dependencies</id>
+ <id>test-resource-dependencies</id>
<phase>process-test-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
- <configuration>
- <includeArtifactIds>streams-pojo</includeArtifactIds>
- <includes>**/*.json</includes>
- <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
- </configuration>
</execution>
</executions>
</plugin>
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/bf31cbe0/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 b42ccf9..4c1f850 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
@@ -2,197 +2,67 @@ 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;
import java.util.Iterator;
+import java.util.List;
/**
* Created by sblackmon on 3/27/16.
*/
-public class StreamsPojoGenerationConfig implements GenerationConfig {
+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;
+ }
+
+ 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();
+ }
+ 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 false;
- }
-
- @Override
- public boolean isUsePrimitives() {
- return false;
- }
-
- @Override
- public Iterator<URL> getSource() {
- return null;
- }
-
- @Override
- public File getTargetDirectory() {
- return null;
- }
-
- @Override
- public String getTargetPackage() {
- return null;
- }
-
- @Override
- public char[] getPropertyWordDelimiters() {
- return new char[0];
- }
-
- @Override
- public boolean isUseLongIntegers() {
- return false;
- }
-
- @Override
- public boolean isUseDoubleNumbers() {
- return false;
- }
-
- @Override
- public boolean isUseBigDecimals() {
- return false;
- }
-
- @Override
- public boolean isIncludeHashcodeAndEquals() {
- return false;
- }
-
- @Override
- public boolean isIncludeToString() {
- return false;
- }
-
- @Override
- public AnnotationStyle getAnnotationStyle() {
- return null;
- }
-
- @Override
- public Class<? extends Annotator> getCustomAnnotator() {
- return null;
- }
-
- @Override
- public Class<? extends RuleFactory> getCustomRuleFactory() {
- return null;
- }
-
- @Override
- public boolean isIncludeJsr303Annotations() {
- return false;
- }
-
- @Override
- public SourceType getSourceType() {
- return null;
- }
-
- @Override
- public boolean isRemoveOldOutput() {
- return false;
- }
-
- @Override
- public String getOutputEncoding() {
- return null;
- }
-
- @Override
- public boolean isUseJodaDates() {
- return false;
- }
-
- @Override
- public boolean isUseJodaLocalDates() {
- return false;
- }
-
- @Override
- public boolean isUseJodaLocalTimes() {
- return false;
- }
-
- @Override
- public boolean isUseCommonsLang3() {
- return false;
- }
-
- @Override
- public boolean isParcelable() {
- return false;
- }
-
- @Override
- public FileFilter getFileFilter() {
- return null;
- }
-
- @Override
- public boolean isInitializeCollections() {
- return false;
- }
-
- @Override
- public String getClassNamePrefix() {
- return null;
- }
-
- @Override
- public String getClassNameSuffix() {
- return null;
- }
-
- @Override
- public boolean isIncludeConstructors() {
- return false;
- }
-
- @Override
- public boolean isConstructorsRequiredPropertiesOnly() {
- return false;
- }
-
- @Override
- public boolean isIncludeAdditionalProperties() {
- return false;
- }
-
- @Override
- public boolean isIncludeAccessors() {
- return false;
- }
-
- @Override
- public String getTargetVersion() {
- return null;
- }
-
- @Override
- public boolean isIncludeDynamicAccessors() {
- return false;
- }
-
- @Override
- public String getDateTimeType() {
- return null;
- }
-
- @Override
- public String getDateType() {
- return null;
- }
-
- @Override
- public String getTimeType() {
- return null;
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/bf31cbe0/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
new file mode 100644
index 0000000..d80123d
--- /dev/null
+++ b/streams-plugins/streams-plugin-pojo/src/main/java/org/apache/streams/plugins/StreamsPojoSourceGenerator.java
@@ -0,0 +1,98 @@
+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.
+ */
+public class StreamsPojoSourceGenerator implements Runnable {
+
+ private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPojoSourceGenerator.class);
+
+ private final static String LS = System.getProperty("line.separator");
+
+ private StreamsPojoSourceGeneratorMojo mojo;
+
+ private StreamsPojoGenerationConfig config;
+
+ public void main(String[] args) {
+ StreamsPojoGenerationConfig config = new StreamsPojoGenerationConfig();
+
+ String sourceDirectory = "./target/test-classes/activities";
+ String targetDirectory = "./target/generated-sources/streams-plugin-pojo";
+ String targetPackage = "";
+
+ 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);
+
+ StreamsPojoSourceGenerator streamsPojoSourceGenerator = new StreamsPojoSourceGenerator(config);
+ Thread thread = new Thread(streamsPojoSourceGenerator);
+ thread.start();
+ try {
+ thread.join();
+ } catch (InterruptedException e) {
+ LOGGER.error("InterruptedException", e);
+ } catch (Exception e) {
+ LOGGER.error("Exception", e);
+ }
+ return;
+ }
+
+ public StreamsPojoSourceGenerator(StreamsPojoGenerationConfig config) {
+ this.config = config;
+ }
+
+ @Override
+ public void run() {
+
+ Preconditions.checkNotNull(config);
+
+ try {
+ Jsonschema2Pojo.generate(config);
+ } catch (Throwable e) {
+ LOGGER.error("{} {}", e.getClass(), e.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);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/bf31cbe0/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 8980daa..9d595fe 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,10 +29,10 @@ import java.util.List;
import static org.apache.commons.lang.StringUtils.isNotBlank;
-@Mojo( name = "hive",
+@Mojo( name = "pojo",
defaultPhase = LifecyclePhase.GENERATE_SOURCES
)
-@Execute( goal = "hive",
+@Execute( goal = "pojo",
phase = LifecyclePhase.GENERATE_SOURCES
)
public class StreamsPojoSourceGeneratorMojo extends AbstractMojo {
@@ -55,45 +55,42 @@ public class StreamsPojoSourceGeneratorMojo extends AbstractMojo {
@Parameter( defaultValue = "${project.basedir}", readonly = true )
public File basedir;
- @Parameter( defaultValue = "${jsonschema2pojo.sourceDirectory}", readonly = true ) // Maven 3 only
+ @Parameter( defaultValue = "./src/main/jsonschema", readonly = true ) // Maven 3 only
public String sourceDirectory;
- @Parameter( defaultValue = "${jsonschema2pojo.sourcePaths}", readonly = true ) // Maven 3 only
- public String[] sourcePaths;
+ @Parameter( readonly = true ) // Maven 3 only
+ public List<String> sourcePaths;
- @Parameter(defaultValue = "${project.build.directory}", readonly = true)
- public File target;
+ @Parameter(defaultValue = "./target/generated-sources/streams-plugin-pojo", readonly = true)
+ public String targetDirectory;
+
+ @Parameter(readonly = true)
+ public String targetPackage;
public void execute() throws MojoExecutionException {
addProjectDependenciesToClasspath();
- // verify source directories
- if (isNotBlank(sourceDirectory)) {
- // verify sourceDirectory
- try {
- URLUtil.parseURL(sourceDirectory);
- } catch (IllegalArgumentException e) {
- throw new MojoExecutionException(e.getMessage(), e);
- }
- } else if (sourcePaths != null) {
- // verify individual source paths
- for (String source : sourcePaths) {
- try {
- URLUtil.parseURL(source);
- } catch (IllegalArgumentException e) {
- throw new MojoExecutionException(e.getMessage(), e);
- }
- }
- } else {
- throw new MojoExecutionException("One of sourceDirectory or sourcePaths must be provided");
- }
+ StreamsPojoGenerationConfig config = new StreamsPojoGenerationConfig();
+ if( sourcePaths != null && sourcePaths.size() > 0)
+ config.setSourcePaths(sourcePaths);
+ else
+ config.setSourceDirectory(sourceDirectory);
+ config.setTargetPackage(targetPackage);
+ config.setTargetDirectory(targetDirectory);
+
+ StreamsPojoSourceGenerator streamsPojoSourceGenerator = new StreamsPojoSourceGenerator(config);
+ Thread thread = new Thread(streamsPojoSourceGenerator);
+ thread.start();
try {
- Jsonschema2Pojo.generate(new StreamsPojoGenerationConfig());
- } catch (IOException e) {
- throw new MojoExecutionException("Error generating classes from JSON Schema file(s) " + sourceDirectory, e);
+ thread.join();
+ } catch (InterruptedException e) {
+ LOGGER.error("InterruptedException", e);
+ } catch (Exception e) {
+ LOGGER.error("Exception", e);
}
+ return;
// List<Class<?>> serializableClasses = detectSerializableClasses();
//
@@ -133,29 +130,6 @@ public class StreamsPojoSourceGeneratorMojo extends AbstractMojo {
}
- 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);
- }
- }
-
- public Iterator<URL> getSource() {
- if (null != sourceDirectory) {
- return Collections.singleton(URLUtil.parseURL(sourceDirectory)).iterator();
- }
- List<URL> sourceURLs = new ArrayList<URL>();
- for (String source : sourcePaths) {
- sourceURLs.add(URLUtil.parseURL(source));
- }
- return sourceURLs.iterator();
- }
-
// public List<Class<?>> detectSerializableClasses() {
//
// Set<Class<? extends Serializable>> classes =
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/bf31cbe0/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
new file mode 100644
index 0000000..a99f059
--- /dev/null
+++ b/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorMojoTest.java
@@ -0,0 +1,96 @@
+package org.apache.streams.plugins.test;
+
+import com.google.common.collect.Lists;
+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.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Test that Activity beans are compatible with the example activities in the spec.
+ */
+public class StreamsPojoSourceGeneratorMojoTest extends TestCase {
+
+ private final static Logger LOGGER = LoggerFactory.getLogger(StreamsPojoSourceGeneratorMojoTest.class);
+
+ protected void setUp() throws Exception
+ {
+ // required for mojo lookups to work
+ 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 {
+
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/streams-plugin-pojo" );
+
+ Verifier verifier;
+
+ verifier = new Verifier( testDir.getAbsolutePath() );
+
+ List cliOptions = new ArrayList();
+ cliOptions.add( "-N" );
+ verifier.executeGoals( Lists.<String>newArrayList(
+ "clean",
+ "dependency:unpack-dependencies",
+ "generate-sources",
+ "compile"));
+
+ 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 );
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/bf31cbe0/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorTest.java
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorTest.java b/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorTest.java
index 63d4995..667661f 100644
--- a/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorTest.java
+++ b/streams-plugins/streams-plugin-pojo/src/test/java/org/apache/streams/plugins/test/StreamsPojoSourceGeneratorTest.java
@@ -1,11 +1,15 @@
package org.apache.streams.plugins.test;
+import com.google.common.collect.Lists;
+import org.apache.streams.plugins.StreamsPojoGenerationConfig;
+import org.apache.streams.plugins.StreamsPojoSourceGenerator;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileFilter;
+import java.util.List;
/**
* Test that Activity beans are compatible with the example activities in the spec.
@@ -21,23 +25,48 @@ public class StreamsPojoSourceGeneratorTest {
*/
@Test
public void testStreamsPojoSourceGenerator() throws Exception {
-// StreamsPojoSourceGenerator streamsPojoSourceGenerator = new StreamsPojoSourceGenerator();
-// StreamsPojoSourceGenerator.main(new String[0]);
- File testOutput = new File( "./target/generated-sources/streams-pojo");
+ StreamsPojoGenerationConfig config = new StreamsPojoGenerationConfig();
+
+ List<String> sourcePaths = Lists.newArrayList(
+ "target/test-classes/streams-schemas/activity.json",
+ "target/test-classes/streams-schemas/collection.json",
+ "target/test-classes/streams-schemas/media_link.json",
+ "target/test-classes/streams-schemas/object.json",
+ "target/test-classes/streams-schemas/objectTypes",
+ "target/test-classes/streams-schemas/verbs"
+ );
+ config.setSourcePaths(sourcePaths);
+
+// config.setSourceDirectory("target/test-classes/streams-schemas");
+ config.setTargetPackage("org.apache.streams.pojo.test");
+ config.setTargetDirectory("target/generated-sources/test");
+
+ StreamsPojoSourceGenerator streamsPojoSourceGenerator = new StreamsPojoSourceGenerator(config);
+ Thread thread = new Thread(streamsPojoSourceGenerator);
+ thread.start();
+ try {
+ thread.join();
+ } catch (InterruptedException e) {
+ LOGGER.error("InterruptedException", e);
+ } catch (Exception e) {
+ LOGGER.error("Exception", e);
+ }
+
+ File testOutput = new File( "target/generated-sources/test");
FileFilter javaFilter = new FileFilter() {
@Override
public boolean accept(File pathname) {
- if( pathname.getName().endsWith(".java") )
- return true;
- return false;
+ 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( 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 );
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/bf31cbe0/streams-plugins/streams-plugin-pojo/src/test/resources/streams-plugin-pojo/pom.xml
----------------------------------------------------------------------
diff --git a/streams-plugins/streams-plugin-pojo/src/test/resources/streams-plugin-pojo/pom.xml b/streams-plugins/streams-plugin-pojo/src/test/resources/streams-plugin-pojo/pom.xml
index fbb2864..359179e 100644
--- a/streams-plugins/streams-plugin-pojo/src/test/resources/streams-plugin-pojo/pom.xml
+++ b/streams-plugins/streams-plugin-pojo/src/test/resources/streams-plugin-pojo/pom.xml
@@ -9,12 +9,49 @@
<packaging>jar</packaging>
<name>Test StreamsPojoMojo</name>
+ <properties>
+ <jackson.version>2.6.1</jackson.version>
+ <commons-lang.version>2.6</commons-lang.version>
+ </properties>
+
<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>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.datatype</groupId>
+ <artifactId>jackson-datatype-joda</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>${commons-lang.version}</version>
+ </dependency>
</dependencies>
<build>
@@ -24,10 +61,16 @@
<artifactId>streams-plugin-pojo</artifactId>
<version>0.3-incubating-SNAPSHOT</version>
<configuration>
- <packages>
- <package>org.apache.streams.pojo.json</package>
- </packages>
- <target>target/test-classes/streams-pojo-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>
+ <targetPackage>org.apache.streams.pojo.testmojo</targetPackage>
+ <targetDirectory>target/generated-sources/test-mojo</targetDirectory>
</configuration>
<executions>
<execution>
@@ -37,6 +80,45 @@
</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>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>target/generated-sources/test-mojo</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/bf31cbe0/streams-pojo/pom.xml
----------------------------------------------------------------------
diff --git a/streams-pojo/pom.xml b/streams-pojo/pom.xml
index 942156a..055b842 100644
--- a/streams-pojo/pom.xml
+++ b/streams-pojo/pom.xml
@@ -39,6 +39,12 @@
<artifactId>jsonschema2pojo-core</artifactId>
<type>jar</type>
<scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>