<?xml version="1.0" encoding="UTF-8"?>
-<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
-name="md-sal-apps"
- xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-
+<archetype-descriptor
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
+ name="md-sal-apps"
+ xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<requiredProperties>
<requiredProperty key="appName">
<defaultValue>task</defaultValue>
</requiredProperty>
</requiredProperties>
<modules>
- <module id="sample-generate" dir="generate" name="sample-generate">
- <fileSets>
- <fileSet filtered="true" packaged="true" encoding="UTF-8">
- <directory>src/main/java</directory>
- <includes>
- <include>**/*.java</include>
- </includes>
- </fileSet>
- <fileSet encoding="UTF-8">
- <directory>src/main/template</directory>
- <includes>
- <include>**/*.vm</include>
- </includes>
- </fileSet>
- </fileSets>
- </module>
<module id="sample-model" dir="model" name="sample-model">
<fileSets>
<fileSet encoding="UTF-8">
</fileSets>
</module>
</modules>
-</archetype-descriptor>
+
+ <fileSets>
+ <!-- explicitly copy over the .gitignore file to ignore the generate project -->
+ <fileSet>
+ <directory></directory>
+ <includes>
+ <include>.gitignore</include>
+ </includes>
+ </fileSet>
+
+ <!-- The following 3 file sets copy over the "generate" project, which is a one time use
+ project which should be used to generate additional files that are needed.
+ We do NOT want this project included in the final project so we need to manually copy
+ the files instead of calling it a "module" like we do for other folders above. -->
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>generate/src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ <fileSet encoding="UTF-8">
+ <directory>generate/src/main/template</directory>
+ <includes>
+ <include>**/*.vm</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory>generate</directory>
+ <includes>
+ <include>pom.xml</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</archetype-descriptor>
\ No newline at end of file
--- /dev/null
+
+#####standard .git ignore entries#####
+
+*.class
+**/target
+bin/
+dist
+workspace
+*~
+target
+target-ide
+.classpath
+.project
+.settings
+MANIFEST.MF
+opendaylight/northbound/integrationtest/logs/*
+*.ipr
+*.iml
+*.iws
+.idea
+yang-gen-config
+yang-gen-sal
+classes
+out/
+.externalToolBuilders
+maven-eclipse.xml
+.DS_STORE
+.metadata
+
+#####Archetype .git ignore entries#######
+generate
\ No newline at end of file
public class CodeGenerator {
private static String basePackage = "${package}";
-
+ /**
+ * This variable holds the relative path from the working directory to the root folder where
+ * we want to generate the specified files. Since the CodeGenerator is expected to be invoked from
+ * the child "generate" folder, we will set the path to root to be its parent.
+ */
+ public static final String PATH_TO_ROOT_DIR = "../";
+
/**
* This method expects two arguments application name and fields for application,
* which it will receive from command line, while generating the project.
context.put("fields", fields);
/* now render the template into a File */
String path = "model/src/main/yang/"+appName + ".yang";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile(PATH_TO_ROOT_DIR, path, context, template);
}
private static void processInitialConfig(String appName, VelocityEngine ve) throws Exception{
context.put("app", appName);
/* now render the template into a File */
String path = "configuration/initial/05-"+appName + "-sample.xml";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile(PATH_TO_ROOT_DIR, path, context, template);
}
context.put("app", appName);
context.put("capitalApp", CodeGeneratorUtil.capitalizeFirstLetter(appName));
String path = "web/src/main/resources/WEB-INF/pages/view.jsp";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile(PATH_TO_ROOT_DIR, path, context, template);
}
}
*
*/
public class CodeGeneratorUtil {
-
- public static void writeFile(String path, VelocityContext context, Template template) throws Exception {
- File file = new File(path);
+
+ /**
+ * Writes a file in the given <code>path</give>, using the <code>generateLocation</code> as
+ * the working (parent) directory.
+ */
+ public static void writeFile(String generateLocation,
+ String path, VelocityContext context, Template template) throws Exception {
+ File file = new File( generateLocation, path);
File parent = file.getParentFile();
if(!parent.exists()){
parent.mkdirs();
context.put("package", basePackage);
String path = "consumer/src/main/java/"+ basePackage.replaceAll("\\.", "/") + "/consumer/"
+ CodeGeneratorUtil.capitalizeFirstLetter(appName)+"ConsumerImpl.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processConsumerService(String appName, VelocityEngine ve) throws Exception{
context.put("package", basePackage);
String path = "consumer/src/main/java/"+ basePackage.replaceAll("\\.", "/") + "/consumer/"
+ CodeGeneratorUtil.capitalizeFirstLetter(appName)+"ConsumerService.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processConsumerModule(String appName, VelocityEngine ve) throws Exception{
context.put("package", basePackage);
String path = "consumer/src/main/java/org/opendaylight/controller/config/yang/config/"+
appName +"_consumer/impl/" + CodeGeneratorUtil.capitalizeFirstLetter(appName)+"ConsumerModule.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processConsumerModuleFactory(String appName, VelocityEngine ve) throws Exception{
context.put("package", basePackage);
String path = "consumer/src/main/java/org/opendaylight/controller/config/yang/config/"+
appName +"_consumer/impl/" + CodeGeneratorUtil.capitalizeFirstLetter(appName)+"ConsumerModuleFactory.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processConsumerYang(String appName, VelocityEngine ve) throws Exception{
VelocityContext context = CodeGeneratorUtil.createBasicVelocityContext(appName);
context.put("package", basePackage);
String path = "consumer/src/main/yang/"+ appName + "-consumer-impl.yang";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processConsumerServiceInterface(String appName, VelocityEngine ve) throws Exception{
context.put("package", basePackage);
String path = "consumer/src/main/yang-gen-config/org/opendaylight/controller/config/yang/config/"
+ appName+"_consumer/impl/"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) + "ConsumerServiceServiceInterface.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processAbstractConsumerModule(String appName, VelocityEngine ve) throws Exception{
VelocityContext context = CodeGeneratorUtil.createBasicVelocityContext(appName);
String path = "consumer/src/main/yang-gen-config/org/opendaylight/controller/config/yang/config/"
+ appName+"_consumer/impl/Abstract"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) + "ConsumerModule.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processAbstractConsumerModuleFactory(String appName, VelocityEngine ve) throws Exception{
VelocityContext context = CodeGeneratorUtil.createBasicVelocityContext(appName);
String path = "consumer/src/main/yang-gen-config/org/opendaylight/controller/config/yang/config/"
+ appName+"_consumer/impl/Abstract"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) + "ConsumerModuleFactory.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processConsumerModuleMXBean(String appName, VelocityEngine ve) throws Exception{
VelocityContext context = CodeGeneratorUtil.createBasicVelocityContext(appName);
String path = "consumer/src/main/yang-gen-config/org/opendaylight/controller/config/yang/config/"
+ appName+"_consumer/impl/"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) + "ConsumerModuleMXBean.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processAbstractConsumerService(String appName, VelocityEngine ve) throws Exception{
context.put("lowerApp", lowerApp);
String path = "consumer/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp+"/consumer/impl/rev140523/"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) + "ConsumerService.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processAbstractConsumerImpl(String appName, VelocityEngine ve) throws Exception{
context.put("lowerApp", lowerApp);
String path = "consumer/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp+"/consumer/impl/rev140523/"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) + "ConsumerImpl.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processYangModelBindingProvider(String appName, VelocityEngine ve) throws Exception{
context.put("lowerApp", lowerApp);
String path = "consumer/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp+"/consumer/impl/rev140523/$YangModelBindingProvider.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processYangModuleInfoImpl(String appName, VelocityEngine ve) throws Exception{
context.put("lowerApp", lowerApp);
String path = "consumer/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp+"/consumer/impl/rev140523/$YangModuleInfoImpl.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processConsumerImplInterface(String appName, VelocityEngine ve) throws Exception{
String path = "consumer/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp+"/consumer/impl/rev140523/modules/module/configuration/"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) +
"ConsumerImpl.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processConsumerImplBuilder(String appName, VelocityEngine ve) throws Exception{
String path = "consumer/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp+"/consumer/impl/rev140523/modules/module/configuration/"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) +
"ConsumerImplBuilder.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processRpcRegistry(String appName, VelocityEngine ve) throws Exception{
String path = "consumer/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp+"/consumer/impl/rev140523/modules/module/configuration/"+ lowerApp+
"/consumer/impl/RpcRegistry.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processRpcRegistryBuilder(String appName, VelocityEngine ve) throws Exception{
String path = "consumer/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp+"/consumer/impl/rev140523/modules/module/configuration/"+ lowerApp+
"/consumer/impl/RpcRegistryBuilder.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
}
\ No newline at end of file
context.put("fields", fields);
context.put("package", basePackage);
String path = "provider/src/main/java/"+ basePackage.replaceAll("\\.", "/") + "/provider/"+capitalAppName+"Provider.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderYang(String appName, VelocityEngine ve) throws Exception {
Template template = ve.getTemplate( "provider/providerYang.vm" );
VelocityContext context = CodeGeneratorUtil.createBasicVelocityContext(appName);
String path = "provider/src/main/yang/"+ appName + "-provider-impl.yang";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderSalImpl(String appName, VelocityEngine ve) throws Exception {
String path = "provider/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp + "/provider/impl/rev140523/" + CodeGeneratorUtil.capitalizeFirstLetter(appName) +"ProviderImpl.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderSalYangModImpl(String appName, VelocityEngine ve) throws Exception {
context.put("lowerApp", lowerApp);
String path = "provider/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp + "/provider/impl/rev140523/$YangModuleInfoImpl.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderSalYangBinding(String appName, VelocityEngine ve) throws Exception {
context.put("lowerApp", lowerApp);
String path = "provider/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp + "/provider/impl/rev140523/$YangModelBindingProvider.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderSalConfImpl(String appName, VelocityEngine ve) throws Exception {
context.put("lowerApp", lowerApp);
String path = "provider/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp + "/provider/impl/rev140523/modules/module/configuration/"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) +"ProviderImpl.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderSalConfBuilder(String appName, VelocityEngine ve) throws Exception {
context.put("lowerApp", lowerApp);
String path = "provider/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp + "/provider/impl/rev140523/modules/module/configuration/"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) +"ProviderImplBuilder.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderSalDataBroker(String appName, VelocityEngine ve) throws Exception {
context.put("lowerApp", lowerApp);
String path = "provider/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp + "/provider/impl/rev140523/modules/module/configuration/"+ lowerApp +"/provider/impl/DataBroker.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderSalBrokerBuilder(String appName, VelocityEngine ve) throws Exception {
context.put("lowerApp", lowerApp);
String path = "provider/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp + "/provider/impl/rev140523/modules/module/configuration/"+ lowerApp +"/provider/impl/DataBrokerBuilder.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderSalRpc(String appName, VelocityEngine ve) throws Exception {
context.put("lowerApp", lowerApp);
String path = "provider/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp + "/provider/impl/rev140523/modules/module/configuration/"+ lowerApp +"/provider/impl/RpcRegistry.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderSalRpcBuilder(String appName, VelocityEngine ve) throws Exception {
context.put("lowerApp", lowerApp);
String path = "provider/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/"
+ lowerApp + "/provider/impl/rev140523/modules/module/configuration/"+ lowerApp +"/provider/impl/RpcRegistryBuilder.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderAbstractModule(String appName, VelocityEngine ve) throws Exception {
VelocityContext context = CodeGeneratorUtil.createBasicVelocityContext(appName);
String path = "provider/src/main/yang-gen-config/org/opendaylight/controller/config/yang/config/"
+ appName + "_provider/impl/Abstract"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) +"ProviderModule.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderAbstractModuleFactory(String appName, VelocityEngine ve) throws Exception {
VelocityContext context = CodeGeneratorUtil.createBasicVelocityContext(appName);
String path = "provider/src/main/yang-gen-config/org/opendaylight/controller/config/yang/config/"
+ appName + "_provider/impl/Abstract"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) +"ProviderModuleFactory.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderMXBean(String appName, VelocityEngine ve) throws Exception {
VelocityContext context = CodeGeneratorUtil.createBasicVelocityContext(appName);
String path = "provider/src/main/yang-gen-config/org/opendaylight/controller/config/yang/config/"
+ appName + "_provider/impl/"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) +"ProviderModuleMXBean.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderModule(String appName, VelocityEngine ve) throws Exception {
context.put("package", basePackage);
String path = "provider/src/main/java/org/opendaylight/controller/config/yang/config/"
+ appName + "_provider/impl/"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) +"ProviderModule.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
private static void processProviderModuleFactory(String appName, VelocityEngine ve) throws Exception {
VelocityContext context = CodeGeneratorUtil.createBasicVelocityContext(appName);
String path = "provider/src/main/java/org/opendaylight/controller/config/yang/config/"
+ appName + "_provider/impl/"+ CodeGeneratorUtil.capitalizeFirstLetter(appName) +"ProviderModuleFactory.java";
- CodeGeneratorUtil.writeFile(path, context, template);
+ CodeGeneratorUtil.writeFile( CodeGenerator.PATH_TO_ROOT_DIR, path, context, template);
}
}
\ No newline at end of file