Created
August 15, 2012 18:20
-
-
Save irof/3362135 to your computer and use it in GitHub Desktop.
GroovyでJavaのpackage-info.javaを一括生成するスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RubyでJavaのpackage-info.javaを一括生成するスクリプト | |
http://d.hatena.ne.jp/tbpg/20120808/1344447924 | |
をGroovyにしてみた。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.nio.file.* | |
import java.nio.file.attribute.* | |
import static java.nio.file.FileVisitResult.CONTINUE | |
import static groovy.io.FileType.FILES | |
def PACKAGE_INFO = 'package-info.java' | |
def SOURCE_DIR = './src' | |
def package_detail = '// TODO パッケージ内容の詳細を記述してください' | |
def generate_package_info_code = { package_name -> | |
"""\ | |
/** | |
* ${package_name}パッケージ。 | |
* | |
* <pre> | |
* ${package_detail} | |
* </pre> | |
* | |
*/ | |
package ${package_name}; | |
""" | |
} | |
def generate_package_info_file = {file, code -> | |
Files.write(file.resolve(PACKAGE_INFO), code.getBytes()) | |
} | |
Path root = Paths.get(SOURCE_DIR) | |
Files.walkFileTree(root, new SimpleFileVisitor<Path>() { | |
public FileVisitResult preVisitDirectory(Path file, BasicFileAttributes attrs) { | |
if (root == file) return CONTINUE | |
def name = root.relativize(file).toString().replaceAll('/', '.') | |
def package_info_code = generate_package_info_code(name) | |
generate_package_info_file(file, package_info_code) | |
CONTINUE | |
} | |
} | |
); | |
println "出力完了。出力結果" | |
root.toFile().eachFileRecurse(FILES) { | |
if (it.name == PACKAGE_INFO) println it | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment