1

を使用してディレクトリ構造からいくつかのソースを処理したいのですがSourceDirectorySet、元のディレクトリ構造を模倣して、ビルド ディレクトリの下に出力を保存したいと考えています。例えば:

src / main / plantuml
                + dir1
                   + dir11
                       + file.pu

結果は次のようになります。

build / doc / plantuml
                + dir1
                   + dir11
                       + file.png

どうすればそれを達成できますか?

注意:SourceDirectorySetですPatternFilterable

バックグラウンド

janvolck のプラグイン「gradle-plantuml-plugin」 (対応する機能リクエストが既に存在する) を拡張して、構成されたディレクトリの下に出力ファイルを生成するが、元のディレクトリ階層を維持したい。gradle プラグインの現在の実装は、a のすべてのファイルをトラバースしSourceDirectorySet、ソース ファイルが存在する同じディレクトリに出力ファイルを生成します。

これは私が出すことができる最も近いものです:

// Process directory trees
mySourceDirectorySet.srcDirTrees.each { DirectoryTree d ->
    project.logger.debug("Processing srcDirTree " + d.dir
        + "; patterns.excludes: " + d.patterns.excludes
        + "; patterns.includes" + d.patterns.includes)

    // Reconstruct a FileTree from the directory tree, as I cannot find
    // any means to get the files directly from 'd' (1)
    // ... and traverse its files
    project.fileTree(dir: d.dir,
        excludes: d.patterns.excludes,
        includes: d.patterns.includes).each { File f ->
            project.logger.info("-- Input file: " + f)

            def relPath = d.dir.toURI().relativize(f.parentFile.toURI())
            def outputPath = "/myOutputDir/" + relPath

            option.setOutputDir(project.file(outputPath))
            processFile(f, option);
    }
}

残念ながら、このトリックは(1)機能していないようで、適切な FileTree を再作成できません。

私の訓練されていないグラドルの直感は、このタスクを簡単に達成できるはずだと言っています。私は確かに何かが欠けていますか?

4

1 に答える 1

0

私はプラグインに精通していませんが、要件を理解しているように、 sourceRoot ディレクトリ内のすべてのファイルについて、ディレクトリ構造を維持しながら、 destRoot に同様の名前のファイルを生成したいと考えています。

これを試してください:

def File sourceRoot = new File("src/main/plantuml")
def File destRoot = new File("build/doc/plantuml")

sourceRoot.eachFileRecurse(FileType.FILES) { File file ->
    def relPath = sourceRoot.toURI().relativize(file.toURI())
    def destFile = new File(destRoot, relPath.toString())
    destFile.parentFile.mkdirs()
    destFile.createNewFile() //alternatively use this path to create your png
}
于 2015-10-30T02:23:41.713 に答える