⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 batchgenerate.groovy

📁 大名鼎鼎的java动态脚本语言。已经通过了sun的认证
💻 GROOVY
字号:
/** * @author Jeremy Rayner */package org.codehaus.groovy.tckimport java.io.File;class BatchGenerate {    def generator;    def srcDirPath;    def targetDir;    def srcEncoding;    def srcs;    def spew    public BatchGenerate() {        generator = new TestGenerator();        // verbose = false;        spew = true;        srcDirPath = "./";    }    public void setSrcdirPath(String pathName) {        if (spew) {println("srcDir:${pathName}") }        srcDirPath = pathName;    }    public void setTargetDirectory(File destDir) {        if (spew) { println("destDir:${destDir}") }        targetDir = destDir;    }    public void setSourceEncoding(String encoding) {        if (spew) { println("encoding:${encoding}") }        srcEncoding = encoding;    }    public void addSources( File[] compileList ) {        if (spew) { println("compileList:${compileList}") }        srcs = compileList    }    public void setVerbose(boolean verbose) {        spew = verbose    }    public void compile() {        if (spew) { println("compile()") }        for (src in srcs) {            println( src )            // mung the ${test.src.dir}/gls/ch14/s4 path into ${dest.dir}/gls/ch14/s4            // first determine the relative path e.g. gls/ch14/s4            def relativeSrcFilePathAndName = src.getAbsolutePath().substring(srcDirPath.length() + 1)            def relativeSrcFileNameStartIndex = relativeSrcFilePathAndName.lastIndexOf(File.separator);            def relativeOutputPath = ""            if (relativeSrcFileNameStartIndex >= 0) {                relativeOutputPath = relativeSrcFilePathAndName.substring(0,relativeSrcFileNameStartIndex);            }            // then determine the absolute output path            def ghostOutputFile = new File(targetDir, relativeSrcFilePathAndName)            def ghostOutputFilePath = ghostOutputFile.getAbsolutePath()            def fileNameStartIndex = ghostOutputFilePath.lastIndexOf(File.separator);            def realOutputPath = ghostOutputFilePath.substring(0,fileNameStartIndex);            // mkdir if does not exist            File directory = new File(realOutputPath)            if (directory != null && !directory.exists()) {                directory.mkdirs();            }            // generate a suitable java file to put there            def fileStem = src.name.tokenize(".")[0]            def targetFileName = "${fileStem}Test.java"            def anOutputFile = new File(realOutputPath, targetFileName)            System.out.println("generating " + targetFileName)            def someOutputText = generator.generate(relativeOutputPath, targetDir, src.name,src.text);            if (someOutputText != null && someOutputText != "") {                anOutputFile.write(someOutputText);            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -