diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/package/Packager.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/package/Packager.rsc index b67301edc4..e0a835e1a6 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/package/Packager.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/package/Packager.rsc @@ -33,30 +33,45 @@ import ParseTree; import Location; import util::Reflective; -void main(PathConfig pcfg = pathConfig(), loc sourceLookup = |unknown:///|) { +void main(PathConfig pcfg = pathConfig(), loc sourceLookup = |unknown:///|, loc relocatedClasses = pcfg.projectRoot + "/target/relocatedClasses") { if (!(sourceLookup?)) { throw "sourceLookup is not an optional parameter. The packager needs something like `|mvn://groupId--artifactId--version|`"; } - package(pcfg.srcs, pcfg.bin, sourceLookup); + package(pcfg.srcs, pcfg.bin, relocatedClasses, sourceLookup); } -void package(list[loc] srcs, loc bin, loc sourceLookup) { - packageSourceFiles(srcs, bin); - rewriteTypeFiles(srcs, bin, sourceLookup); +void package(list[loc] srcs, loc bin, loc relocated, loc sourceLookup) { + packageSourceFiles(srcs, relocated); + copyAllTargetFiles(bin, relocated); + rewriteTypeFiles(srcs, bin, relocated, sourceLookup); } -void packageSourceFiles(list[loc] srcs, loc bin) { +void packageSourceFiles(list[loc] srcs, loc relocated) { for (folder <- srcs, file <- find(folder, "rsc")) { - copy(file, bin + relativize(folder, file).path); + copy(file, relocated + relativize(folder, file).path); } } -void rewriteTypeFiles(list[loc] srcs, loc bin, loc sourceLookup) { - for (file <- find(bin, "tpl")) { +void copyAllTargetFiles(loc bin, loc relocated) { + mkDirectory(relocated); + + // A pom file may include any thing (resources and classes) + // and we just copy everything just in case it is needed at runtime. + copy(bin, relocated, recursive = true); + + // But we remove the superfluous tpl files just in case. + // They will be rewritten and copied later again. + for (loc file <- find(relocated, "tpl")) { + remove(file); + } +} + +void rewriteTypeFiles(list[loc] srcs, loc bin, loc relocated, loc sourceLookup) { + for (loc file <- find(bin, "tpl")) { model = readBinaryValueFile(file); model = rewriteTypeModel(model, paths(srcs), sourceLookup); - writeBinaryValueFile(file, model); + writeBinaryValueFile(relocated + relativize(bin, file).path, model); } }