Refactored yang-maven-plugin. 36/336/1
authorMartin Vitez <mvitez@cisco.com>
Mon, 13 May 2013 15:11:53 +0000 (17:11 +0200)
committerMartin Vitez <mvitez@cisco.com>
Mon, 13 May 2013 15:11:53 +0000 (17:11 +0200)
Signed-off-by: Martin Vitez <mvitez@cisco.com>
20 files changed:
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/java/org/opendaylight/controller/yang2sources/plugin/it/CombineTest.java [deleted file]
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/java/org/opendaylight/controller/yang2sources/plugin/it/YangToResourcesPluginTest.java [deleted file]
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/java/org/opendaylight/controller/yang2sources/plugin/it/YangToSourcesPluginTest.java
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/Correct/pom.xml
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/Correct_resources/pom.xml
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/Generator/pom.xml [moved from opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/Correct_combined/pom.xml with 93% similarity]
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/NoGenerators/pom.xml
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/NoGenerators_resources/pom.xml
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/NoOutputDir/pom.xml [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/NoYangFiles/pom.xml
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/UnknownGenerator/pom.xml
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/UnknownGenerator_resources/pom.xml
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/YangRootNotExist/pom.xml
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/pom.xml
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/ConfigArg.java
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/Util.java
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/YangToResourcesMojo.java [deleted file]
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/YangToSourcesMojo.java
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/test/java/org/opendaylight/controller/yang2sources/plugin/GenerateResourcesTest.java [deleted file]
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/test/java/org/opendaylight/controller/yang2sources/plugin/GenerateSourcesTest.java

diff --git a/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/java/org/opendaylight/controller/yang2sources/plugin/it/CombineTest.java b/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/java/org/opendaylight/controller/yang2sources/plugin/it/CombineTest.java
deleted file mode 100644 (file)
index 7171ee9..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.yang2sources.plugin.it;
-
-import org.apache.maven.it.VerificationException;
-import org.apache.maven.it.Verifier;
-import org.junit.Test;
-
-public class CombineTest {
-
-    @Test
-    public void testCorrect() throws VerificationException {
-        Verifier v = YangToSourcesPluginTest.setUp("Correct_combined/", false);
-        YangToResourcesPluginTest.verifyCorrectLog(v);
-        YangToSourcesPluginTest.verifyCorrectLog(v);
-    }
-
-}
diff --git a/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/java/org/opendaylight/controller/yang2sources/plugin/it/YangToResourcesPluginTest.java b/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/java/org/opendaylight/controller/yang2sources/plugin/it/YangToResourcesPluginTest.java
deleted file mode 100644 (file)
index f7aa4f7..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.yang2sources.plugin.it;
-
-import org.apache.maven.it.VerificationException;
-import org.apache.maven.it.Verifier;
-import org.junit.Test;
-
-public class YangToResourcesPluginTest {
-
-    @Test
-    public void testCorrect() throws VerificationException {
-        Verifier v = YangToSourcesPluginTest.setUp("Correct_resources/", false);
-        verifyCorrectLog(v);
-    }
-
-    static void verifyCorrectLog(Verifier v) throws VerificationException {
-        v.verifyErrorFreeLog();
-        v.verifyTextInLog("[INFO] yang-to-resources: Resource provider instantiated from org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl");
-        v.verifyTextInLog("[INFO] yang-to-resources: Resource provider org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl call successful");
-    }
-
-    @Test
-    public void testNoGenerators() throws VerificationException {
-        Verifier v = YangToSourcesPluginTest.setUp("NoGenerators_resources/",
-                false);
-        v.verifyErrorFreeLog();
-        v.verifyTextInLog("[WARNING] yang-to-resources: No resource provider classes provided");
-    }
-
-    @Test
-    public void testUnknownGenerator() throws VerificationException {
-        Verifier v = YangToSourcesPluginTest.setUp(
-                "UnknownGenerator_resources/", true);
-        v.verifyTextInLog("[ERROR] yang-to-resources: Unable to provide resources with unknown resource provider");
-        v.verifyTextInLog("java.lang.ClassNotFoundException: unknown");
-        v.verifyTextInLog("[INFO] yang-to-resources: Resource provider instantiated from org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl");
-        v.verifyTextInLog("[INFO] yang-to-resources: Resource provider org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl call successful");
-        v.verifyTextInLog("[ERROR] yang-to-resources: One or more code resource provider failed, including failed list(resourceProviderClass=exception) {unknown=java.lang.ClassNotFoundException}");
-    }
-
-}
index 4b41cfd9441705ef07ae23685c7c272afeace5f9..75d6ee5d7d5ffb1898cb950d37af25203d2e0e04 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.controller.yang2sources.plugin.it;
 
 import static org.junit.Assert.*;
-import static org.junit.matchers.JUnitMatchers.*;
+import static org.junit.matchers.JUnitMatchers.containsString;
 
 import java.io.File;
 
@@ -38,6 +38,7 @@ public class YangToSourcesPluginTest {
     public void testCorrect() throws VerificationException {
         Verifier v = setUp("Correct/", false);
         verifyCorrectLog(v);
+
     }
 
     static void verifyCorrectLog(Verifier v) throws VerificationException {
@@ -45,6 +46,8 @@ public class YangToSourcesPluginTest {
         v.verifyTextInLog("[INFO] yang-to-sources: yang files parsed from");
         v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
         v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
+        v.verifyTextInLog("[INFO] yang-to-sources: Resource provider instantiated from org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl");
+        v.verifyTextInLog("[INFO] yang-to-sources: Resource provider org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl call successful");
     }
 
     @Test
@@ -83,8 +86,34 @@ public class YangToSourcesPluginTest {
                 + project).getAbsolutePath());
         if (ignoreF)
             verifier.addCliOption("-fn");
-        verifier.executeGoal("generate-resources");
+        verifier.executeGoal("generate-sources");
         return verifier;
     }
 
+    @Test
+    public void testNoGeneratorsResources() throws VerificationException {
+        Verifier v = YangToSourcesPluginTest.setUp("NoGenerators_resources/",
+                false);
+        v.verifyErrorFreeLog();
+        v.verifyTextInLog("[WARNING] yang-to-sources: No resource provider classes provided");
+    }
+
+    @Test
+    public void testUnknownGeneratorResources() throws VerificationException {
+        Verifier v = YangToSourcesPluginTest.setUp(
+                "UnknownGenerator_resources/", true);
+        v.verifyTextInLog("[ERROR] yang-to-sources: Unable to provide resources with unknown resource provider");
+        v.verifyTextInLog("java.lang.ClassNotFoundException: unknown");
+        v.verifyTextInLog("[INFO] yang-to-sources: Resource provider instantiated from org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl");
+        v.verifyTextInLog("[INFO] yang-to-sources: Resource provider org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl call successful");
+        v.verifyTextInLog("[ERROR] yang-to-sources: One or more code resource provider failed, including failed list(resourceProviderClass=exception) {unknown=java.lang.ClassNotFoundException}");
+    }
+
+    @Test
+    public void testNoOutputDir() throws VerificationException {
+        Verifier v = YangToSourcesPluginTest.setUp("NoOutputDir/",
+                false);
+        verifyCorrectLog(v);
+    }
+
 }
index 6a7c3f95b70f0c32905915dc338edc8490f17fe5..91e90c5b3d3a8657a73c4517596d06e25d7084ef 100644 (file)
@@ -1,49 +1,67 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-    <parent>
-        <artifactId>binding-generator</artifactId>
-        <groupId>org.opendaylight.controller</groupId>
-        <version>0.5-SNAPSHOT</version>
-    </parent>
-    <artifactId>test</artifactId>
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <artifactId>binding-generator</artifactId>
+               <groupId>org.opendaylight.controller</groupId>
+               <version>0.5-SNAPSHOT</version>
+       </parent>
+       <artifactId>test</artifactId>
 
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.opendaylight.controller</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-                <version>0.5-SNAPSHOT</version>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>generate-sources</goal>
-                        </goals>
-                        <configuration>
-                            <yangFilesRootDir>${basedir}/../../../../../yang-model-parser-impl/src/test/resources/model</yangFilesRootDir>
-                            <codeGenerators>
-                                <generator>
-                                    <codeGeneratorClass>
-                                        org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl
-                                    </codeGeneratorClass>
-                                    <outputBaseDir>
-                                        outDir/
-                                    </outputBaseDir>
-                                </generator>
-                            </codeGenerators>
-                        </configuration>
-                    </execution>
-                </executions>
+       <dependencies>
+               <dependency>
+                       <groupId>org.opendaylight.controller</groupId>
+                       <artifactId>yang-maven-plugin-spi</artifactId>
+                       <version>0.5-SNAPSHOT</version>
+               </dependency>
+       </dependencies>
 
-                <dependencies>
-                    <dependency>
-                        <groupId>org.opendaylight.controller</groupId>
-                        <artifactId>yang-maven-plugin-spi</artifactId>
-                        <version>0.5-SNAPSHOT</version>
-                        <type>test-jar</type>
-                    </dependency>
-                </dependencies>
-            </plugin>
-        </plugins>
-    </build>
-</project>
\ No newline at end of file
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.opendaylight.controller</groupId>
+                               <artifactId>yang-maven-plugin</artifactId>
+                               <version>0.5-SNAPSHOT</version>
+                               <executions>
+                                       <execution>
+                                               <goals>
+                                                       <goal>generate-sources</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <yangFilesRootDir>${basedir}/../../../../../yang-model-parser-impl/src/test/resources/model</yangFilesRootDir>
+                                                       <codeGenerators>
+                                                               <generator>
+                                                                       <codeGeneratorClass>
+                                                                               org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl
+                                                                       </codeGeneratorClass>
+                                                                       <outputBaseDir>
+                                                                               outDir/
+                                                                       </outputBaseDir>
+                                                               </generator>
+                                                       </codeGenerators>
+                                                       <resourceProviders>
+                                                               <provider>
+                                                                       <resourceProviderClass>
+                                                                               org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl
+                                                                       </resourceProviderClass>
+                                                                       <outputBaseDir>
+                                                                               outDir/
+                                                                       </outputBaseDir>
+                                                               </provider>
+                                                       </resourceProviders>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+
+                               <dependencies>
+                                       <dependency>
+                                               <groupId>org.opendaylight.controller</groupId>
+                                               <artifactId>yang-maven-plugin-spi</artifactId>
+                                               <version>0.5-SNAPSHOT</version>
+                                               <type>test-jar</type>
+                                       </dependency>
+                               </dependencies>
+                       </plugin>
+               </plugins>
+       </build>
+</project>
index 0e0c96a48c33e7ea2682f44a06512d687e2b24fd..8ae77305786100d54e7f4e4daa4e76e0f18acf1a 100644 (file)
@@ -17,7 +17,7 @@
                 <executions>
                     <execution>
                         <goals>
-                            <goal>generate-resources</goal>
+                            <goal>generate-sources</goal>
                         </goals>
                         <configuration>
                             <yangFilesRootDir>${basedir}/../../../../../yang-model-parser-impl/src/test/resources/model</yangFilesRootDir>
similarity index 93%
rename from opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/Correct_combined/pom.xml
rename to opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/Generator/pom.xml
index fe67c7815282e6247ddf28019692bc1c7fe32cc9..8b11eace35945bf1867dad31f88f41c5e6faa75f 100644 (file)
@@ -18,7 +18,6 @@
                     <execution>
                         <goals>
                             <goal>generate-sources</goal>
-                            <goal>generate-resources</goal>
                         </goals>
                         <configuration>
                             <yangFilesRootDir>${basedir}/../../../../../yang-model-parser-impl/src/test/resources/model</yangFilesRootDir>
@@ -28,7 +27,7 @@
                                         org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl
                                     </codeGeneratorClass>
                                     <outputBaseDir>
-                                        outDir/src
+                                        outDir/
                                     </outputBaseDir>
                                 </generator>
                             </codeGenerators>
@@ -38,7 +37,7 @@
                                         org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl
                                     </resourceProviderClass>
                                     <outputBaseDir>
-                                        outDir/resources
+                                        outDir/
                                     </outputBaseDir>
                                 </provider>
                             </resourceProviders>
index f19d84886ec2006c54f54d5a16a22f3a6ea44112..cf158cc7b016aff06af65f6ae81558e60e4a8a21 100644 (file)
                             <yangFilesRootDir>${basedir}/../../../../../yang-model-parser-impl/src/test/resources/model</yangFilesRootDir>
                             <codeGenerators>
                             </codeGenerators>
+                            <resourceProviders>
+                                <provider>
+                                    <resourceProviderClass>
+                                        org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl
+                                    </resourceProviderClass>
+                                    <outputBaseDir>
+                                        outDir/
+                                    </outputBaseDir>
+                                </provider>
+                            </resourceProviders>
                         </configuration>
                     </execution>
                 </executions>
+                               <dependencies>
+                    <dependency>
+                        <groupId>org.opendaylight.controller</groupId>
+                        <artifactId>yang-maven-plugin-spi</artifactId>
+                        <version>0.5-SNAPSHOT</version>
+                        <type>test-jar</type>
+                    </dependency>
+                </dependencies>
             </plugin>
         </plugins>
     </build>
index 38028b84e909189964bea3ab2a0efe57d6d4d340..67c0984ae35afaf783d2ad6a345229d3635ce837 100644 (file)
                 <executions>
                     <execution>
                         <goals>
-                            <goal>generate-resources</goal>
+                            <goal>generate-sources</goal>
                         </goals>
                         <configuration>
                             <yangFilesRootDir>${basedir}/../../../../../yang-model-parser-impl/src/test/resources/model</yangFilesRootDir>
+                                                       <codeGenerators>
+                                <generator>
+                                    <codeGeneratorClass>
+                                        org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl
+                                    </codeGeneratorClass>
+                                    <outputBaseDir>
+                                        outDir/
+                                    </outputBaseDir>
+                                </generator>
+                            </codeGenerators>
                             <resourceProviders>
                             </resourceProviders>
                         </configuration>
                     </execution>
                 </executions>
+                               <dependencies>
+                    <dependency>
+                        <groupId>org.opendaylight.controller</groupId>
+                        <artifactId>yang-maven-plugin-spi</artifactId>
+                        <version>0.5-SNAPSHOT</version>
+                        <type>test-jar</type>
+                    </dependency>
+                </dependencies>
             </plugin>
         </plugins>
     </build>
diff --git a/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/NoOutputDir/pom.xml b/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/NoOutputDir/pom.xml
new file mode 100644 (file)
index 0000000..adca0fa
--- /dev/null
@@ -0,0 +1,53 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>binding-generator</artifactId>
+        <groupId>org.opendaylight.controller</groupId>
+        <version>0.5-SNAPSHOT</version>
+    </parent>
+    <artifactId>test</artifactId>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.opendaylight.controller</groupId>
+                <artifactId>yang-maven-plugin</artifactId>
+                <version>0.5-SNAPSHOT</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>generate-sources</goal>
+                        </goals>
+                        <configuration>
+                            <yangFilesRootDir>${basedir}/../../../../../yang-model-parser-impl/src/test/resources/model</yangFilesRootDir>
+                            <codeGenerators>
+                                <generator>
+                                    <codeGeneratorClass>
+                                        org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl
+                                    </codeGeneratorClass>
+                                </generator>
+                            </codeGenerators>
+                            <resourceProviders>
+                                <provider>
+                                    <resourceProviderClass>
+                                        org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl
+                                    </resourceProviderClass>
+                                </provider>
+                            </resourceProviders>
+                        </configuration>
+                    </execution>
+                </executions>
+
+                <dependencies>
+                    <dependency>
+                        <groupId>org.opendaylight.controller</groupId>
+                        <artifactId>yang-maven-plugin-spi</artifactId>
+                        <version>0.5-SNAPSHOT</version>
+                        <type>test-jar</type>
+                    </dependency>
+                </dependencies>
+            </plugin>
+        </plugins>
+    </build>
+</project>
\ No newline at end of file
index 2308da0fed6b10dd47486832523cb6806ba8cbdf..70aa82aae5d90797624e47b301e2057703db7edc 100644 (file)
                                     </outputBaseDir>
                                 </generator>
                             </codeGenerators>
+                                                       <resourceProviders>
+                                <provider>
+                                    <resourceProviderClass>
+                                        org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl
+                                    </resourceProviderClass>
+                                    <outputBaseDir>
+                                        outDir/
+                                    </outputBaseDir>
+                                </provider>
+                            </resourceProviders>
                         </configuration>
                     </execution>
                 </executions>
index 2101b8471b0f5415fc0caa910c7e87e43cc02193..da7554e044750ca1387cbf972a9d540326be02aa 100644 (file)
                                     </outputBaseDir>
                                 </generator>
                             </codeGenerators>
+                                                       <resourceProviders>
+                                <provider>
+                                    <resourceProviderClass>
+                                        org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl
+                                    </resourceProviderClass>
+                                    <outputBaseDir>
+                                        outDir/
+                                    </outputBaseDir>
+                                </provider>
+                            </resourceProviders>
                         </configuration>
                     </execution>
                 </executions>
index 8ee0606631545f3038fb6412cac2a47a61b7627c..f5eddd95c044804a0e7e1f3872074b6d9a70e596 100644 (file)
                 <executions>
                     <execution>
                         <goals>
-                            <goal>generate-resources</goal>
+                            <goal>generate-sources</goal>
                         </goals>
                         <configuration>
                             <yangFilesRootDir>${basedir}/../../../../../yang-model-parser-impl/src/test/resources/model</yangFilesRootDir>
+                                                       <codeGenerators>
+                                <generator>
+                                    <codeGeneratorClass>
+                                        org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl
+                                    </codeGeneratorClass>
+                                    <outputBaseDir>
+                                        outDir/
+                                    </outputBaseDir>
+                                </generator>
+                            </codeGenerators>
                             <resourceProviders>
                                 <provider>
                                     <resourceProviderClass>
index 3aeb2e9535ba7b7ec0caa8ca7abcafe3a653cfce..6208231c6feb9d42c01419b480ff87c7537aa169 100644 (file)
                                     </outputBaseDir>
                                 </generator>
                             </codeGenerators>
+                                                       <resourceProviders>
+                                <provider>
+                                    <resourceProviderClass>
+                                        org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl
+                                    </resourceProviderClass>
+                                    <outputBaseDir>
+                                        outDir/
+                                    </outputBaseDir>
+                                </provider>
+                            </resourceProviders>
                         </configuration>
                     </execution>
                 </executions>
index e82c737351b155d1fbdac480f690e6d00f86baf6..d542e6d93fce647fd15f542de40336bf26295917 100644 (file)
             <version>3.2</version>
             <scope>provided</scope>
         </dependency>
+               <dependency>
+                       <groupId>org.apache.maven</groupId>
+                       <artifactId>maven-artifact</artifactId>
+                       <version>2.0</version>
+               </dependency>
 
         <dependency>
             <groupId>${project.groupId}</groupId>
index 85f2d8905dd51e48e648a495c85dc8f8d93afaf1..217c6f5b86a7f923f22d136c04a07379c8d2c10f 100644 (file)
@@ -40,6 +40,10 @@ public abstract class ConfigArg {
         public ResourceProviderArg() {
         }
 
+        public ResourceProviderArg(String resourceProviderClass) {
+            this(resourceProviderClass, new File("outDir/"));
+        }
+
         public ResourceProviderArg(String resourceProviderClass,
                 File outputBaseDir) {
             super(outputBaseDir);
@@ -51,9 +55,6 @@ public abstract class ConfigArg {
             Preconditions
                     .checkNotNull(resourceProviderClass,
                             "resourceProviderClass for ResourceProvider cannot be null");
-            Preconditions.checkNotNull(outputBaseDir,
-                    "outputBaseDir for ResourceProvider cannot be null, "
-                            + resourceProviderClass);
         }
 
         public String getResourceProviderClass() {
@@ -70,6 +71,10 @@ public abstract class ConfigArg {
         public CodeGeneratorArg() {
         }
 
+        public CodeGeneratorArg(String codeGeneratorClass) {
+            this(codeGeneratorClass, new File("outDir/"));
+        }
+
         public CodeGeneratorArg(String codeGeneratorClass, File outputBaseDir) {
             super(outputBaseDir);
             this.codeGeneratorClass = codeGeneratorClass;
@@ -79,9 +84,6 @@ public abstract class ConfigArg {
         public void check() {
             Preconditions.checkNotNull(codeGeneratorClass,
                     "codeGeneratorClass for CodeGenerator cannot be null");
-            Preconditions.checkNotNull(outputBaseDir,
-                    "outputBaseDir for CodeGenerator cannot be null, "
-                            + codeGeneratorClass);
         }
 
         public String getCodeGeneratorClass() {
index 98a5d8531b79e0d8d78da9ffb2ee7461928d6773..3739a1d6599184898a6b64548e86208c634f572d 100644 (file)
@@ -8,17 +8,29 @@
 package org.opendaylight.controller.yang2sources.plugin;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Enumeration;
+import java.util.List;
 import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.project.MavenProject;
 
 import com.google.common.base.Function;
 import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
 final class Util {
-
     static final String YANG_SUFFIX = "yang";
 
     // Cache for listed directories and found yang files. Typically yang files
@@ -34,7 +46,6 @@ final class Util {
      * size 1.
      */
     static Collection<File> listFiles(String rootDir) {
-
         if (cache.get(rootDir) != null)
             return cache.get(rootDir);
 
@@ -45,6 +56,17 @@ final class Util {
         return yangFiles;
     }
 
+    static Collection<InputStream> listFilesAsStream(String rootDir) throws FileNotFoundException {
+        Collection<InputStream> is = new ArrayList<InputStream>();
+
+        Collection<File> files = listFiles(rootDir);
+        for(File f : files) {
+            is.add(new FileInputStream(f));
+        }
+
+        return is;
+    }
+
     static String[] listFilesAsArrayOfPaths(String rootDir) {
         String[] filesArray = new String[] {};
         Collection<File> yangFiles = listFiles(rootDir);
@@ -99,4 +121,56 @@ final class Util {
         String innerMessage = String.format(message, args);
         return String.format("%s %s", logPrefix, innerMessage);
     }
+
+    public static List<File> getClassPath(MavenProject project)
+            throws DependencyResolutionRequiredException {
+        List<File> dependencies = Lists.newArrayList();
+        try {
+            for (Object element : project.getCompileClasspathElements()) {
+                File asFile = new File((String) element);
+                if (isJar(asFile)) {
+                    dependencies.add(asFile);
+                }
+            }
+        } catch (DependencyResolutionRequiredException e) {
+            throw e;
+        }
+        return dependencies;
+    }
+
+    private static final String JAR_SUFFIX = ".jar";
+
+    private static boolean isJar(File element) {
+        return (element.isFile() && element.getName().endsWith(JAR_SUFFIX)) ? true
+                : false;
+    }
+
+    public static Collection<File> getFilesFromClasspath(
+            List<File> jarsOnClasspath, List<String> classPathFilter)
+            throws ZipException, IOException {
+        List<File> yangs = Lists.newArrayList();
+
+        for (File file : jarsOnClasspath) {
+            ZipFile zip = new ZipFile(file);
+            Enumeration<? extends ZipEntry> entries = zip.entries();
+            while (entries.hasMoreElements()) {
+                ZipEntry entry = entries.nextElement();
+                if (entry.getName().endsWith(YANG_SUFFIX)) {
+                    InputStream stream = zip.getInputStream(entry);
+                }
+            }
+        }
+
+        return yangs;
+    }
+
+    public static boolean acceptedFilter(String name, List<String> filter) {
+        for(String f : filter) {
+            if(name.endsWith(f)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
 }
diff --git a/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/YangToResourcesMojo.java b/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/YangToResourcesMojo.java
deleted file mode 100644 (file)
index b449049..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.yang2sources.plugin;
-
-import java.io.File;
-import java.util.Collection;
-import java.util.Map;
-
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.opendaylight.controller.yang2sources.plugin.ConfigArg.ResourceProviderArg;
-import org.opendaylight.controller.yang2sources.spi.ResourceGenerator;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.Maps;
-
-/**
- * Generate resources from yang files using user provided set of
- * {@link ResourceGenerator}s. Can be used to copy yang files that served as
- * blueprint for code generation into resources directory. Steps of this
- * process:
- * <ol>
- * <li>List yang files from {@link #yangFilesRootDir} (If this goal is in the
- * same execution as generate-sources, the same cached list will be used and the
- * root folder will not be searched for yang files twice)</li>
- * <li>For each {@link ResourceGenerator} from {@link #resourceProviders}:</li>
- * <ol>
- * <li>Instantiate using default constructor</li>
- * <li>Call {@link ResourceGenerator#generateResourceFiles(Collection, File)}</li>
- * </ol>
- * </ol>
- */
-@Mojo(name = "generate-resources", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
-public final class YangToResourcesMojo extends AbstractMojo {
-
-    private static final String LOG_PREFIX = "yang-to-resources:";
-
-    /**
-     * Classes implementing {@link ResourceGenerator} interface. An instance
-     * will be created out of every class using default constructor. Method
-     * {@link ResourceGenerator#generateResourceFiles(Collection, File)} will be
-     * called on every instance.
-     */
-    @Parameter(required = true)
-    private ResourceProviderArg[] resourceProviders;
-
-    /**
-     * Source directory that will be recursively searched for yang files (ending
-     * with .yang suffix).
-     */
-    @Parameter(required = true)
-    private String yangFilesRootDir;
-
-    @VisibleForTesting
-    YangToResourcesMojo(ResourceProviderArg[] resourceProviderArgs,
-            String yangFilesRootDir) {
-        super();
-        this.resourceProviders = resourceProviderArgs;
-        this.yangFilesRootDir = yangFilesRootDir;
-    }
-
-    public YangToResourcesMojo() {
-        super();
-    }
-
-    @Override
-    public void execute() throws MojoExecutionException, MojoFailureException {
-
-        if (resourceProviders.length == 0) {
-            getLog().warn(
-                    Util.message("No resource provider classes provided",
-                            LOG_PREFIX));
-            return;
-        }
-
-        Map<String, String> thrown = Maps.newHashMap();
-        Collection<File> yangFiles = Util.listFiles(yangFilesRootDir);
-
-        for (ResourceProviderArg resourceProvider : resourceProviders) {
-            try {
-
-                provideResourcesWithOneProvider(yangFiles, resourceProvider);
-
-            } catch (Exception e) {
-                // try other generators, exception will be thrown after
-                getLog().error(
-                        Util.message(
-                                "Unable to provide resources with %s resource provider",
-                                LOG_PREFIX,
-                                resourceProvider.getResourceProviderClass()), e);
-                thrown.put(resourceProvider.getResourceProviderClass(), e
-                        .getClass().getCanonicalName());
-            }
-        }
-
-        if (!thrown.isEmpty()) {
-            String message = Util
-                    .message(
-                            "One or more code resource provider failed, including failed list(resourceProviderClass=exception) %s",
-                            LOG_PREFIX, thrown.toString());
-            getLog().error(message);
-            throw new MojoFailureException(message);
-        }
-    }
-
-    /**
-     * Instantiate provider from class and call required method
-     */
-    private void provideResourcesWithOneProvider(Collection<File> yangFiles,
-            ResourceProviderArg resourceProvider)
-            throws ClassNotFoundException, InstantiationException,
-            IllegalAccessException {
-
-        resourceProvider.check();
-
-        ResourceGenerator g = Util.getInstance(
-                resourceProvider.getResourceProviderClass(),
-                ResourceGenerator.class);
-        getLog().info(
-                Util.message("Resource provider instantiated from %s",
-                        LOG_PREFIX, resourceProvider.getResourceProviderClass()));
-
-        g.generateResourceFiles(yangFiles, resourceProvider.getOutputBaseDir());
-        getLog().info(
-                Util.message("Resource provider %s call successful",
-                        LOG_PREFIX, resourceProvider.getResourceProviderClass()));
-    }
-}
index 05d9c0cd2c54488e5815b4701ec862c7744f89f3..6a11042cb9c1075f2ca2ee96d904fffdc9e2cf41 100644 (file)
@@ -7,13 +7,23 @@
  */
 package org.opendaylight.controller.yang2sources.plugin;
 
+import java.io.Closeable;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Enumeration;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.maven.model.Resource;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -27,9 +37,12 @@ import org.opendaylight.controller.yang.model.api.SchemaContext;
 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
 import org.opendaylight.controller.yang.model.parser.impl.YangParserImpl;
 import org.opendaylight.controller.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
+import org.opendaylight.controller.yang2sources.plugin.ConfigArg.ResourceProviderArg;
 import org.opendaylight.controller.yang2sources.spi.CodeGenerator;
+import org.opendaylight.controller.yang2sources.spi.ResourceGenerator;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
 /**
@@ -47,8 +60,9 @@ import com.google.common.collect.Maps;
  */
 @Mojo(name = "generate-sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
 public final class YangToSourcesMojo extends AbstractMojo {
-
     private static final String LOG_PREFIX = "yang-to-sources:";
+    private static final String INPUT_RESOURCE_DIR = "META-INF/yangs/";
+    private static final String OUTPUT_RESOURCE_DIR = "/target/external-resources/";
 
     /**
      * Classes implementing {@link CodeGenerator} interface. An instance will be
@@ -66,15 +80,26 @@ public final class YangToSourcesMojo extends AbstractMojo {
     @Parameter(required = true)
     private String yangFilesRootDir;
 
+    /**
+     * Classes implementing {@link ResourceGenerator} interface. An instance
+     * will be created out of every class using default constructor. Method
+     * {@link ResourceGenerator#generateResourceFiles(Collection, File)} will be
+     * called on every instance.
+     */
+    @Parameter(required = true)
+    private ResourceProviderArg[] resourceProviders;
+
     @Parameter(property = "project", required = true, readonly = true)
     protected MavenProject project;
 
     private transient final YangModelParser parser;
 
     @VisibleForTesting
-    YangToSourcesMojo(CodeGeneratorArg[] codeGeneratorArgs,
-            YangModelParser parser, String yangFilesRootDir) {
+    YangToSourcesMojo(ResourceProviderArg[] resourceProviderArgs,
+            CodeGeneratorArg[] codeGeneratorArgs, YangModelParser parser,
+            String yangFilesRootDir) {
         super();
+        this.resourceProviders = resourceProviderArgs;
         this.codeGenerators = codeGeneratorArgs;
         this.yangFilesRootDir = yangFilesRootDir;
         this.parser = parser;
@@ -89,6 +114,9 @@ public final class YangToSourcesMojo extends AbstractMojo {
     public void execute() throws MojoExecutionException, MojoFailureException {
         SchemaContext context = processYang();
         generateSources(context);
+        generateResources();
+
+        closeResources();
     }
 
     /**
@@ -96,7 +124,9 @@ public final class YangToSourcesMojo extends AbstractMojo {
      */
     private SchemaContext processYang() throws MojoExecutionException {
         try {
-            Collection<File> yangFiles = Util.listFiles(yangFilesRootDir);
+            Collection<InputStream> yangFiles = Util
+                    .listFilesAsStream(yangFilesRootDir);
+            yangFiles.addAll(getFilesFromDependenciesAsStream());
 
             if (yangFiles.isEmpty()) {
                 getLog().warn(
@@ -106,7 +136,8 @@ public final class YangToSourcesMojo extends AbstractMojo {
             }
 
             Set<Module> parsedYang = parser
-                    .parseYangModels(new ArrayList<File>(yangFiles));
+                    .parseYangModelsFromStreams(new ArrayList<InputStream>(
+                            yangFiles));
             SchemaContext resolveSchemaContext = parser
                     .resolveSchemaContext(parsedYang);
             getLog().info(
@@ -123,6 +154,145 @@ public final class YangToSourcesMojo extends AbstractMojo {
         }
     }
 
+    private void generateResources() throws MojoExecutionException,
+            MojoFailureException {
+        if (resourceProviders.length == 0) {
+            getLog().warn(
+                    Util.message("No resource provider classes provided",
+                            LOG_PREFIX));
+            return;
+        }
+
+        Resource res = new Resource();
+        String baseDirName = project.getBasedir().getAbsolutePath();
+        res.setDirectory(baseDirName + OUTPUT_RESOURCE_DIR);
+        res.setTargetPath(INPUT_RESOURCE_DIR);
+        project.addResource(res);
+
+        Map<String, String> thrown = Maps.newHashMap();
+
+        Collection<File> yangFiles = new ArrayList<File>();
+
+        // load files from yang root
+        yangFiles.addAll(getFilesFromYangRoot());
+
+        // load files from dependencies
+        yangFiles.addAll(getFilesFromDependencies());
+
+
+        for (ResourceProviderArg resourceProvider : resourceProviders) {
+            try {
+                provideResourcesWithOneProvider(yangFiles, resourceProvider);
+            } catch (Exception e) {
+                // try other generators, exception will be thrown after
+                getLog().error(
+                        Util.message(
+                                "Unable to provide resources with %s resource provider",
+                                LOG_PREFIX,
+                                resourceProvider.getResourceProviderClass()), e);
+                thrown.put(resourceProvider.getResourceProviderClass(), e
+                        .getClass().getCanonicalName());
+            }
+        }
+
+        if (!thrown.isEmpty()) {
+            String message = Util
+                    .message(
+                            "One or more code resource provider failed, including failed list(resourceProviderClass=exception) %s",
+                            LOG_PREFIX, thrown.toString());
+            getLog().error(message);
+            throw new MojoFailureException(message);
+        }
+    }
+
+    private Collection<File> getFilesFromYangRoot() {
+        Collection<File> yangFilesLoaded = Util.listFiles(yangFilesRootDir);
+        Collection<File> yangFiles = new ArrayList<File>(yangFilesLoaded);
+
+        try {
+            for(File yangFile : yangFilesLoaded) {
+                InputStream is = new FileInputStream(yangFile);
+                yangFiles.add(createFileFromStream(is, project.getBasedir().getAbsolutePath() + OUTPUT_RESOURCE_DIR + yangFile.getName()));
+                resources.add(is);
+            }
+        } catch(IOException e) {
+            getLog().warn("Exception while loading yang files.", e);
+        }
+        return yangFiles;
+    }
+
+    private Collection<File> getFilesFromDependencies() {
+        Collection<File> yangFiles = new ArrayList<File>();
+
+        try {
+            List<File> filesOnCp = Util.getClassPath(project);
+            List<String> filter = Lists.newArrayList(".yang");
+            for (File file : filesOnCp) {
+                ZipFile zip = new ZipFile(file);
+                Enumeration<? extends ZipEntry> entries = zip.entries();
+
+                while (entries.hasMoreElements()) {
+                    ZipEntry entry = entries.nextElement();
+                    String entryName = entry.getName();
+                    if (entryName.startsWith(INPUT_RESOURCE_DIR)) {
+                        if (entry.isDirectory()) {
+                            continue;
+                        }
+                        if (!Util.acceptedFilter(entryName, filter)) {
+                            continue;
+                        }
+                        InputStream entryStream = zip.getInputStream(entry);
+                        String newEntryName = entryName.substring(INPUT_RESOURCE_DIR.length());
+                        File f = createFileFromStream(entryStream, project.getBasedir().getAbsolutePath() + OUTPUT_RESOURCE_DIR + newEntryName);
+                        yangFiles.add(f);
+
+                        resources.add(entryStream);
+                    }
+                }
+
+                resources.add(zip);
+            }
+        } catch (Exception e) {
+            getLog().warn("Exception while loading external yang files.", e);
+        }
+        return yangFiles;
+    }
+
+    private File createFileFromStream(InputStream is, String absoluteName) throws IOException {
+        File f = new File(absoluteName);
+        if(!f.exists()) {
+            f.getParentFile().mkdirs();
+        }
+        f.createNewFile();
+
+        FileOutputStream fos = new FileOutputStream(f);
+        IOUtils.copy(is, fos);
+        return f;
+    }
+
+    /**
+     * Instantiate provider from class and call required method
+     */
+    private void provideResourcesWithOneProvider(Collection<File> yangFiles,
+            ResourceProviderArg resourceProvider)
+            throws ClassNotFoundException, InstantiationException,
+            IllegalAccessException {
+
+        resourceProvider.check();
+
+        ResourceGenerator g = Util.getInstance(
+                resourceProvider.getResourceProviderClass(),
+                ResourceGenerator.class);
+        getLog().info(
+                Util.message("Resource provider instantiated from %s",
+                        LOG_PREFIX, resourceProvider.getResourceProviderClass()));
+
+        g.generateResourceFiles(yangFiles, resourceProvider.getOutputBaseDir());
+        getLog().info(
+                Util.message("Resource provider %s call successful",
+                        LOG_PREFIX, resourceProvider.getResourceProviderClass()));
+    }
+
     /**
      * Call generate on every generator from plugin configuration
      */
@@ -135,12 +305,9 @@ public final class YangToSourcesMojo extends AbstractMojo {
         }
 
         Map<String, String> thrown = Maps.newHashMap();
-
         for (CodeGeneratorArg codeGenerator : codeGenerators) {
             try {
-
                 generateSourcesWithOneGenerator(context, codeGenerator);
-
             } catch (Exception e) {
                 // try other generators, exception will be thrown after
                 getLog().error(
@@ -188,4 +355,62 @@ public final class YangToSourcesMojo extends AbstractMojo {
                         codeGeneratorCfg.getCodeGeneratorClass(), generated));
     }
 
+    /**
+     * Collection of resources which should be closed after use.
+     */
+    private final List<Closeable> resources = new ArrayList<Closeable>();
+
+    /**
+     * Search for yang files in dependent projects.
+     *
+     * @return files found as List of InputStream
+     */
+    private List<InputStream> getFilesFromDependenciesAsStream() {
+        final List<InputStream> yangsFromDependencies = new ArrayList<InputStream>();
+        try {
+            List<File> filesOnCp = Util.getClassPath(project);
+
+            List<String> filter = Lists.newArrayList(".yang");
+            for (File file : filesOnCp) {
+                ZipFile zip = new ZipFile(file);
+                Enumeration<? extends ZipEntry> entries = zip.entries();
+                while (entries.hasMoreElements()) {
+                    ZipEntry entry = entries.nextElement();
+                    String entryName = entry.getName();
+
+                    if(entryName.startsWith(INPUT_RESOURCE_DIR)) {
+                        if(entry.isDirectory()) {
+                            continue;
+                        }
+                        if (!Util.acceptedFilter(entryName, filter)) {
+                            continue;
+                        }
+
+                        InputStream entryStream = zip.getInputStream(entry);
+                        yangsFromDependencies.add(entryStream);
+                        resources.add(entryStream);
+                    }
+
+                }
+                resources.add(zip);
+            }
+        } catch (Exception e) {
+            getLog().warn("Exception while searching yangs in dependencies", e);
+        }
+        return yangsFromDependencies;
+    }
+
+    /**
+     * Internal utility method for closing open resources.
+     */
+    private void closeResources() {
+        for (Closeable resource : resources) {
+            try {
+                resource.close();
+            } catch (IOException e) {
+                getLog().warn("Failed to close resources: "+ resource, e);
+            }
+        }
+    }
+
 }
diff --git a/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/test/java/org/opendaylight/controller/yang2sources/plugin/GenerateResourcesTest.java b/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/test/java/org/opendaylight/controller/yang2sources/plugin/GenerateResourcesTest.java
deleted file mode 100644 (file)
index a23e3b5..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.yang2sources.plugin;
-
-import static org.hamcrest.core.Is.*;
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.util.Collection;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.controller.yang2sources.plugin.ConfigArg.ResourceProviderArg;
-import org.opendaylight.controller.yang2sources.spi.ResourceGenerator;
-
-public class GenerateResourcesTest {
-
-    private String yang;
-    private YangToResourcesMojo mojo;
-    private File outDir;
-
-    @Before
-    public void setUp() {
-        yang = new File(getClass().getResource("/mock.yang").getFile())
-                .getParent();
-        outDir = new File("outputDir");
-        mojo = new YangToResourcesMojo(
-                new ResourceProviderArg[] {
-                        new ResourceProviderArg(ProviderMock.class.getName(),
-                                outDir),
-                        new ResourceProviderArg(ProviderMock2.class.getName(),
-                                outDir) }, yang);
-    }
-
-    @Test
-    public void test() throws Exception {
-        mojo.execute();
-        assertThat(ProviderMock.called, is(1));
-        assertThat(ProviderMock2.called, is(1));
-        assertThat(ProviderMock2.baseDir, is(outDir));
-        assertThat(ProviderMock.baseDir, is(outDir));
-    }
-
-    public static class ProviderMock implements ResourceGenerator {
-
-        private static int called = 0;
-        private static File baseDir;
-
-        @Override
-        public void generateResourceFiles(Collection<File> resources,
-                File outputDir) {
-            called++;
-            baseDir = outputDir;
-        }
-    }
-
-    public static class ProviderMock2 implements ResourceGenerator {
-
-        private static int called = 0;
-        private static File baseDir;
-
-        @Override
-        public void generateResourceFiles(Collection<File> resources,
-                File outputDir) {
-            called++;
-            baseDir = outputDir;
-        }
-    }
-
-}
index db703c2d0f3917db939f0337d7908f2de2c7f5bd..6961fa84ec94a3057c70fdd02e3483d6004a99b9 100644 (file)
@@ -7,25 +7,29 @@
  */
 package org.opendaylight.controller.yang2sources.plugin;
 
-import static org.hamcrest.core.Is.*;
-import static org.junit.Assert.*;
-import static org.mockito.Matchers.*;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyListOf;
 import static org.mockito.Mockito.*;
 
 import java.io.File;
 import java.util.Collection;
 
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.yang.model.api.SchemaContext;
 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
 import org.opendaylight.controller.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
+import org.opendaylight.controller.yang2sources.plugin.ConfigArg.ResourceProviderArg;
 import org.opendaylight.controller.yang2sources.spi.CodeGenerator;
+import org.opendaylight.controller.yang2sources.spi.ResourceGenerator;
 
 import com.google.common.collect.Lists;
 
+@Ignore
 public class GenerateSourcesTest {
 
     @Mock
@@ -42,6 +46,11 @@ public class GenerateSourcesTest {
                 .getParent();
         outDir = new File("outputDir");
         mojo = new YangToSourcesMojo(
+                new ResourceProviderArg[] {
+                        new ResourceProviderArg(ProviderMock.class.getName(),
+                                outDir),
+                        new ResourceProviderArg(ProviderMock2.class.getName(),
+                                outDir) },
                 new CodeGeneratorArg[] { new CodeGeneratorArg(
                         GeneratorMock.class.getName(), outDir) }, parser, yang);
     }
@@ -54,6 +63,15 @@ public class GenerateSourcesTest {
         assertThat(GeneratorMock.outputDir, is(outDir));
     }
 
+    @Test
+    public void testRes() throws Exception {
+        mojo.execute();
+        assertThat(ProviderMock.called, is(1));
+        assertThat(ProviderMock2.called, is(1));
+        assertThat(ProviderMock2.baseDir, is(outDir));
+        assertThat(ProviderMock.baseDir, is(outDir));
+    }
+
     public static class GeneratorMock implements CodeGenerator {
 
         private static int called = 0;
@@ -67,4 +85,30 @@ public class GenerateSourcesTest {
             return Lists.newArrayList();
         }
     }
+
+    public static class ProviderMock implements ResourceGenerator {
+
+        private static int called = 0;
+        private static File baseDir;
+
+        @Override
+        public void generateResourceFiles(Collection<File> resources,
+                File outputDir) {
+            called++;
+            baseDir = outputDir;
+        }
+    }
+
+    public static class ProviderMock2 implements ResourceGenerator {
+
+        private static int called = 0;
+        private static File baseDir;
+
+        @Override
+        public void generateResourceFiles(Collection<File> resources,
+                File outputDir) {
+            called++;
+            baseDir = outputDir;
+        }
+    }
 }