jadams-tresys commented on code in PR #183:
URL: https://github.com/apache/daffodil-sbt/pull/183#discussion_r3262236684
##########
src/main/scala/org/apache/daffodil/DaffodilPlugin.scala:
##########
@@ -887,123 +887,159 @@ object DaffodilPlugin extends AutoPlugin {
daffodilFlattenSchemas / excludeFilter := HiddenFileFilter,
daffodilFlattenResourceReferencePatterns := List(
- """schemaLocation=\"([^\"]*)\"""".r,
- "href=\"([^\"]*)\"".r,
- "document[(]'([^']*)'[)]".r),
+ """(?<!xsi:)schemaLocation=\"([^\"]*)\"""".r,
+ "href=\"([^\"]*)\"".r,
+ "document[(]'([^']*)'[)]".r
+ ),
daffodilFlattenSchemas / products := {
val logger = streams.value.log
- val filter = (daffodilFlattenSchemas / includeFilter).value --
(daffodilFlattenSchemas / excludeFilter).value
+ val filter =
+ (daffodilFlattenSchemas / includeFilter).value --
(daffodilFlattenSchemas / excludeFilter).value
val flatDir = target.value / "flatDir"
if (flatDir.exists())
IO.delete(flatDir)
IO.createDirectory(flatDir)
- val projectResources = (Compile / resourceDirectories).value
- .map { root => root.toURI.toURL -> (root **
filter).get.map(_.toURI.toURL).toList }
- .toMap
+ val projectURLs = (Compile / resourceDirectories).value.map { root =>
+ (root ** filter).get.map(_.toURI.toURL).toList
+ }.flatten
/**
* Create a URLClassLoader object with URLs to all resources used by the
* project. The class loader will be used to resolve references made
* within the flattened files.
*/
- val projectURLs = (Compile /
resourceDirectories).value.map(_.toURI.toURL)
val allClasspathURLs = (Test /
externalDependencyClasspath).value.map(_.data.toURI.toURL)
val classLoader = new URLClassLoader((projectURLs ++
allClasspathURLs).toArray, null)
val referenceRegexes = daffodilFlattenResourceReferencePatterns.value
-
- val processed = scala.collection.mutable.Set[URI]()
- projectResources foreach { case (rootURL, urls) =>
- val unprocessed = scala.collection.mutable.Stack[URI]()
- val rootURI = rootURL.toURI
- val rootPath = Paths.get(rootURI)
- unprocessed.pushAll(urls.map(_.toURI))
- while (!unprocessed.isEmpty) {
- val contextURI = unprocessed.pop
- val bytes = contextURI.toURL.openStream().readAllBytes()
- val contextRelPath = contextURI.getScheme match {
- case "jar" => Paths.get(contextURI.toString.split("!")(1).tail)
- case "file" => Paths.get(rootURI.relativize(contextURI).getPath)
- case _ => throw new IllegalArgumentException(s"Unrecognized URI
scheme: $contextURI")
- }
- val contextFlatPath = Paths.get(
- flatDir.toString,
- contextRelPath.toString.replaceAll("/", "__"))
- val bw = Files.newBufferedWriter(contextFlatPath)
- val fileAsString = new String(bytes, Charset.defaultCharset())
-
- val references = referenceRegexes.flatMap { re =>
- re.findAllIn(fileAsString).matchData.map(_.group(1))
+ val jarRegex = "(.*)!(.*)".r
+
+ val seen = scala.collection.mutable.Set[URI]()
+ val unprocessed = scala.collection.mutable.Stack[URI]()
+ unprocessed.pushAll(projectURLs.map(_.toURI))
+ seen ++= projectURLs.map(_.toURI)
+ while (!unprocessed.isEmpty) {
+ val contextURI = unprocessed.pop
+ val bytes = contextURI.toURL.openStream().readAllBytes()
+ val (contextPath, flatPath) = contextURI.getScheme match {
+ case "jar" =>
+ contextURI.toString match {
+ case jarRegex(jarPath, path) => {
+ val fs = try {
+ FileSystems.getFileSystem(contextURI)
+ } catch {
+ case e: FileSystemNotFoundException =>
+ FileSystems.newFileSystem(contextURI, new
java.util.HashMap[String, Any]())
+ }
+ val cPath = fs.getPath(path)
+ (cPath, Paths.get(flatDir.toString,
cPath.toString.tail.replaceAll("/", "__")))
+ }
+ case _ =>
+ throw new IllegalArgumentException(s"Unable to parse JAR URI:
$contextURI")
+ }
+ case "file" => {
+ val path = Paths.get(contextURI)
+ val root = (Compile / resourceDirectories).value
+ .find(file => contextURI.toString.contains(file.toString))
Review Comment:
Unfortunately it can't. The resource directories don't include "file:"
whereas the URI's do.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]