X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fyang-test-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Ftest%2Fplugin%2FProcessSources.java;h=7a20f22440a75dc97f45ed9575c1d9364f40c3fb;hp=f2a56f2b1bfbe2a1e1066a90f3ef16ba6afef660;hb=31b7a44c89d1057489338492fcf62a64147bea24;hpb=aacafb25b08def6ea9f2537356da418805c80ba9 diff --git a/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/ProcessSources.java b/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/ProcessSources.java index f2a56f2b1b..7a20f22440 100644 --- a/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/ProcessSources.java +++ b/opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/ProcessSources.java @@ -44,22 +44,53 @@ public class ProcessSources extends AbstractMojo{ 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")); - if (stubFile.exists()) { - try { - rewrite(sourceFile, FileUtils.readFileToString(stubFile)); - } catch (IOException e) { - getLog().error("Error while reading/writing to files.", e); + if (sourceFile.getName().endsWith(".java")) { + String sourceContent; + try { + sourceContent = FileUtils.readFileToString(sourceFile); + } catch (IOException e) { + getLog().error("Cannot read " + sourceFile.getAbsolutePath(), e); + continue; + } + if (sourceFile.getName().endsWith("Module.java") || sourceFile.getName().endsWith("ModuleFactory.java")) { + File stubFile = new File(sourceFile.getPath().replace(".java", "Stub.txt")); + if (stubFile.exists()) { + String stubContent = null; + try { + stubContent = FileUtils.readFileToString(stubFile); + } catch (IOException e) { + getLog().error("Cannot read " + stubFile.getAbsolutePath(), e); + } + if (stubContent != null) { + sourceContent = rewriteStub(sourceContent, stubContent); + } } } + // remove copyright headers as they can contain timestamp + sourceContent = removeCopyrights(sourceContent); + + // replace the file content + try { + FileUtils.write(sourceFile, sourceContent); + } catch (IOException e) { + getLog().error("Cannot write " + sourceFile.getAbsolutePath(), e); + } } + } } - private static void rewrite(File sourceFile, String replaceTODOWith) throws IOException { - String source = FileUtils.readFileToString(sourceFile); - String target = Pattern.compile("^.*TODO.*\n.*throw new java.lang.UnsupportedOperationException.*$", Pattern.MULTILINE).matcher(source).replaceFirst(replaceTODOWith); - FileUtils.write(sourceFile, target); + private static Pattern MULTILINE_COMMENT_PATTERN = Pattern.compile("/\\*.*\\*/", Pattern.MULTILINE | Pattern.DOTALL); + private static String removeCopyrights(String source) { + String target = MULTILINE_COMMENT_PATTERN.matcher(source).replaceAll("\n"); + //FileUtils.write(sourceFile, target); + return target; + } + + private static Pattern UNSUPPORTED_OP_PATTERN = Pattern.compile("^.*TODO.*\n.*throw new java.lang.UnsupportedOperationException.*$", Pattern.MULTILINE); + + private static String rewriteStub(String source, String replaceTODOWith) { + String target = UNSUPPORTED_OP_PATTERN.matcher(source).replaceFirst(replaceTODOWith); + return target; } }