Generated source files are deleted before new ones are genarated, after that implemantaion code from stub.txt is inserted.
Change-Id: I24d0748bd9ed10908785ba88341e8a4f4cde6958
Signed-off-by: Milos Fabian <milfabia@cisco.com>
<module>netty-event-executor-config</module>
<module>netty-timer-config</module>
<module>config-persister-directory-adapter</module>
+ <module>yang-test-plugin</module>
</modules>
<profiles>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+ <parent>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-plugin-parent</artifactId>
+ <version>0.2.3-SNAPSHOT</version>
+ <relativePath>../config-plugin-parent</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>maven-plugin</packaging>
+ <artifactId>yang-test-plugin</artifactId>
+
+ <description>Remove generated source files, after new files generation, implementation is inserted.</description>
+ <name>${project.artifactId}</name>
+ <prerequisites>
+ <maven>3.0.4</maven>
+ </prerequisites>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>3.0.5</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
--- /dev/null
+/*
+ * 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.config.yang.test.plugin;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.io.File;
+
+/**
+ * Delete all Module/ModuleFactory sources
+ *
+ * @goal delete-sources
+ *
+ * @phase initialize
+ */
+public class DeleteSources extends AbstractMojo{
+ /**
+ * @parameter expression="${project.build.sourceDirectory}"
+ * @readOnly
+ * @required
+ */
+ private File directory;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (directory == null || !directory.exists()) {
+ super.getLog().error("Directory does not exists.");
+ }
+ File sourceDirectory = new File(directory.getPath() + Util.replaceDots(".org.opendaylight.controller.config.yang.test.impl"));
+ if (sourceDirectory == null || !sourceDirectory.exists()) {
+ super.getLog().error("Source directory does not exists " + sourceDirectory.getPath());
+ }
+ File[] sourceFiles = sourceDirectory.listFiles();
+ for (File sourceFile: sourceFiles) {
+ if(sourceFile.getName().endsWith("Module.java") || sourceFile.getName().endsWith("ModuleFactory.java")) {
+ super.getLog().debug("Source file deleted: " + sourceFile.getName());
+ sourceFile.delete();
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.config.yang.test.plugin;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+
+/**
+ * Add implementation code from stub.txt
+ *
+ * @goal process-sources
+ *
+ * @phase process-sources
+ *
+ */
+public class ProcessSources extends AbstractMojo{
+ /**
+ * @parameter expression="${project.build.sourceDirectory}"
+ * @readOnly
+ * @required
+ */
+ private File directory;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (directory == null || !directory.exists()) {
+ super.getLog().error("Directory does not exists.");
+ }
+ File sourceDirectory = new File(directory.getPath() + Util.replaceDots(".org.opendaylight.controller.config.yang.test.impl"));
+ if (!sourceDirectory.exists()) {
+ super.getLog().error("Source directory does not exists " + sourceDirectory.getPath());
+ }
+ String header = "";
+ try {
+ header = Util.loadHeader();
+ } catch (IOException e) {
+ super.getLog().error("Header.txt not found.");
+ }
+ File[] sourceFiles = sourceDirectory.listFiles();
+ for (File sourceFile: sourceFiles) {
+ if(sourceFile.getName().endsWith("Module.java") || sourceFile.getName().endsWith("ModuleFactory.java")) {
+ File stubFile = new File(sourceFile.getPath().replace(".java", "Stub.txt"));
+ String stubLines = null;
+ try {
+ if (stubFile.exists()) {
+ stubLines = Util.loadStubFile(stubFile.getPath());
+ }
+
+ InputStream javaIn = new FileInputStream(sourceFile.getPath());
+ BufferedReader javaBuf = new BufferedReader(new InputStreamReader(javaIn));
+ StringBuffer output = new StringBuffer();
+ String line = javaBuf.readLine();
+ boolean writeLine = false;
+ while ((line = javaBuf.readLine()) != null) {
+ if(!writeLine && line.contains("*/")) {
+ line = header;
+ writeLine = true;
+ } else {
+ if (line.contains("TODO")) {
+ writeLine = false;
+ } else {
+ if (stubLines != null && line.contains("throw new")) {
+ line = stubLines.toString();
+ writeLine = true;
+ }
+ }
+ }
+ if(writeLine) {
+ output.append(line).append(System.lineSeparator());
+ }
+ }
+ javaBuf.close();
+
+ OutputStream javaOut = new FileOutputStream(sourceFile.getPath());
+ javaOut.write(output.toString().getBytes());
+ javaOut.close();
+ } catch (IOException e) {
+ getLog().error("Error while reading/writing to files.", e);
+ }
+
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.config.yang.test.plugin;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.regex.Matcher;
+
+public class Util {
+
+ public static String replaceDots(String path) {
+ path = path.replace(".", Matcher.quoteReplacement(File.separator));
+ return path;
+ }
+
+ public static String loadHeader() throws IOException {
+ StringBuffer header = new StringBuffer();
+ InputStream headIn = Util.class.getClassLoader().getResourceAsStream("Header.txt");
+ BufferedReader headBuf = new BufferedReader(new InputStreamReader(headIn));
+ String line = null;
+ while ((line = headBuf.readLine()) != null) {
+ header.append(line).append(System.lineSeparator());
+ }
+ headBuf.close();
+ return header.toString();
+ }
+
+ public static String loadStubFile(String fileName) throws IOException {
+ InputStream stubIn = new FileInputStream(fileName);
+ BufferedReader stubBuf = new BufferedReader(new InputStreamReader(stubIn));
+
+ StringBuffer stubLines = new StringBuffer();
+ String stubLine = null;
+ while ((stubLine = stubBuf.readLine()) != null) {
+ stubLines.append(stubLine).append(System.lineSeparator());
+ }
+ stubBuf.close();
+ return stubLines.toString();
+ }
+}
--- /dev/null
+/*
+ * 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
+ */
\ No newline at end of file
</dependency>
</dependencies>
</plugin>
+ <plugin>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>yang-test-plugin</artifactId>
+ <version>${config.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>delete-sources</goal>
+ <goal>process-sources</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
+/*
+ * 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.config.yang.test.impl;
/**
public void close() throws Exception {
}
};
+
}
}
+/*
+ * 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.config.yang.test.impl;
/**
+/*
+ * 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.config.yang.test.impl;
/**
@Override
public java.lang.AutoCloseable createInstance() {
- return NetconfTestImplModuleUtil.registerRuntimeBeans(this);
+return NetconfTestImplModuleUtil.registerRuntimeBeans(this);
+
}
}
+/*
+ * 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.config.yang.test.impl;
/**
-/**
- * @author Tomas Olvecky
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
- * 11 2013
- *
- * Copyright (c) 2013 by Cisco Systems, Inc.
- * 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.config.yang.test.impl;
+/*
+ * 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.config.yang.test.impl;
/**
public void close() throws Exception {
}
};
+
}
}
+/*
+ * 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.config.yang.test.impl;
/**