This is an automated email from the ASF dual-hosted git repository.
joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
The following commit(s) were added to refs/heads/develop by this push:
new 8ab9808 GoogDepsWriter: rewriting framework sourceRoot in source maps
now also checks for /frameworks/projects/
8ab9808 is described below
commit 8ab9808355d477acd6a7c6a25a9492725c3507bb
Author: Josh Tynjala <[email protected]>
AuthorDate: Thu Oct 29 10:15:23 2020 -0700
GoogDepsWriter: rewriting framework sourceRoot in source maps now also
checks for /frameworks/projects/
This is in addition to the previous check for /frameworks/js/projects/
---
.../compiler/internal/graph/GoogDepsWriter.java | 134 ++++++++++++++-------
1 file changed, 90 insertions(+), 44 deletions(-)
diff --git
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java
index 5f2f828..8bcf02a 100644
---
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java
+++
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java
@@ -125,9 +125,16 @@ public class GoogDepsWriter {
else
files.add(gd.filePath);
visited.put(gd.className, gd);
- if(sourceMaps && sourceMapsSourceRoot != null)
+ if(sourceMaps)
{
- rewriteSourceMapSourceRoot(gd);
+ if(sourceMapsSourceRoot != null &&
sourceMapsSourceRoot.length() > 0)
+ {
+ rewriteSourceMapSourceRoot(gd);
+ }
+ else
+ {
+
rewriteSourceMapSourceRootForFramework(gd);
+ }
}
}
rewriteSourceMapSourceRoot(depMap.get(mainName));
@@ -150,6 +157,70 @@ public class GoogDepsWriter {
return files;
}
+ private void rewriteSourceMapSourceRootForFramework(GoogDep gd)
+ {
+ if (!sourceMaps)
+ {
+ return;
+ }
+ File sourceMapFile = new File(gd.filePath + ".map");
+ if (!sourceMapFile.exists())
+ {
+ return;
+ }
+ String sourceMapContents = null;
+ try
+ {
+ sourceMapContents =
FileUtils.readFileToString(sourceMapFile, Charset.forName("utf8"));
+ }
+ catch(IOException e)
+ {
+ return;
+ }
+ SourceMapConsumerV3 sourceMapConsumer = new
SourceMapConsumerV3();
+ try
+ {
+ sourceMapConsumer.parse(sourceMapContents);
+ }
+ catch(SourceMapParseException e)
+ {
+ sourceMapConsumer = null;
+ }
+ if (sourceMapConsumer == null)
+ {
+ return;
+ }
+ String sourceRoot = sourceMapConsumer.getSourceRoot();
+ int index = sourceRoot.indexOf("/frameworks/js/projects/");
+ if(index == -1)
+ {
+ index = sourceRoot.indexOf("/frameworks/projects/");
+ }
+ if(index == -1)
+ {
+ return;
+ }
+ File royalelib = new File(System.getProperty("royalelib"));
+ File newSourceRoot = new File(royalelib.getParent(),
sourceRoot.substring(index + 1));
+ String newSourceRootUri =
convertSourcePathToURI(newSourceRoot.getAbsolutePath());
+ if (newSourceRootUri.equals(sourceMapConsumer.getSourceRoot()))
+ {
+ //no need to rewrite
+ return;
+ }
+ SourceMapGeneratorV3 sourceMapGenerator =
SourceMapUtils.sourceMapConsumerToGenerator(sourceMapConsumer);
+ sourceMapGenerator.setSourceRoot(newSourceRootUri);
+ String newSourceMapContents =
SourceMapUtils.sourceMapGeneratorToString(sourceMapGenerator, new
File(gd.filePath).getName());
+ try
+ {
+ FileUtils.write(sourceMapFile, newSourceMapContents,
"utf8");
+ }
+ catch(IOException e)
+ {
+ return;
+ }
+ }
+
private void rewriteSourceMapSourceRoot(GoogDep gd)
{
if (!sourceMaps || sourceMapsSourceRoot == null ||
sourceMapsSourceRoot.length() == 0)
@@ -179,23 +250,24 @@ public class GoogDepsWriter {
{
sourceMapConsumer = null;
}
- if (sourceMapConsumer != null)
+ if (sourceMapConsumer == null)
{
- if
(sourceMapsSourceRoot.equals(sourceMapConsumer.getSourceRoot()))
- {
- //no need to rewrite
- return;
- }
- SourceMapGeneratorV3 sourceMapGenerator =
SourceMapUtils.sourceMapConsumerToGeneratorWithRemappedSourceRoot(sourceMapConsumer,
sourceMapsSourceRoot, gd.className);
- String newSourceMapContents =
SourceMapUtils.sourceMapGeneratorToString(sourceMapGenerator, new
File(gd.filePath).getName());
- try
- {
- FileUtils.write(sourceMapFile,
newSourceMapContents, "utf8");
- }
- catch(IOException e)
- {
- return;
- }
+ return;
+ }
+ if
(sourceMapsSourceRoot.equals(sourceMapConsumer.getSourceRoot()))
+ {
+ //no need to rewrite
+ return;
+ }
+ SourceMapGeneratorV3 sourceMapGenerator =
SourceMapUtils.sourceMapConsumerToGeneratorWithRemappedSourceRoot(sourceMapConsumer,
sourceMapsSourceRoot, gd.className);
+ String newSourceMapContents =
SourceMapUtils.sourceMapGeneratorToString(sourceMapGenerator, new
File(gd.filePath).getName());
+ try
+ {
+ FileUtils.write(sourceMapFile, newSourceMapContents,
"utf8");
+ }
+ catch(IOException e)
+ {
+ return;
}
}
@@ -1229,32 +1301,6 @@ public class GoogDepsWriter {
File sourceMapDestFile
= new File(sourceMapFn);
inStream =
sourceMapFileEntry.createInputStream();
String
sourceMapContents = IOUtils.toString(inStream, Charset.forName("utf8"));
- if
(sourceMapsSourceRoot == null)
- {
-
SourceMapConsumerV3 sourceMapConsumer = new SourceMapConsumerV3();
- try
- {
-
sourceMapConsumer.parse(sourceMapContents);
- }
-
catch(SourceMapParseException e)
- {
-
sourceMapConsumer = null;
- }
-
if(sourceMapConsumer != null)
- {
- String
sourceRoot = sourceMapConsumer.getSourceRoot();
- int
index = sourceRoot.indexOf("/frameworks/js/projects/");
-
if(index != -1)
- {
-
File royalelib = new File(System.getProperty("royalelib"));
-
File newSourceRoot = new File(royalelib.getParent(), sourceRoot.substring(index
+ 1));
-
SourceMapGeneratorV3 sourceMapGenerator =
SourceMapUtils.sourceMapConsumerToGenerator(sourceMapConsumer);
-
String newSourceRootUri =
convertSourcePathToURI(newSourceRoot.getAbsolutePath());
-
sourceMapGenerator.setSourceRoot(newSourceRootUri);
-
sourceMapContents =
SourceMapUtils.sourceMapGeneratorToString(sourceMapGenerator,
destFile.getName());
- }
- }
- }
FileUtils.writeStringToFile(sourceMapDestFile, sourceMapContents,
Charset.forName("utf8"));
}
}