You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2020/10/28 17:29:03 UTC
[royale-compiler] branch develop updated: GoogDepsWriter: rewrites
sourceRoot for framework source maps so that it points to the local SDK
path instead of CI server SDK path
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 ecfd694 GoogDepsWriter: rewrites sourceRoot for framework source maps so that it points to the local SDK path instead of CI server SDK path
ecfd694 is described below
commit ecfd694e2b3064839e9a41dc864ec8b5321ec334
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 28 10:28:00 2020 -0700
GoogDepsWriter: rewrites sourceRoot for framework source maps so that it points to the local SDK path instead of CI server SDK path
---
.../compiler/internal/graph/GoogDepsWriter.java | 58 +++++++++++++++++++---
1 file changed, 51 insertions(+), 7 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 e64e17b..da29ceb 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
@@ -34,6 +34,7 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.royale.compiler.clients.problems.ProblemQuery;
import org.apache.royale.compiler.common.DependencyType;
import org.apache.royale.compiler.common.DependencyTypeSet;
@@ -1351,15 +1352,43 @@ public class GoogDepsWriter {
String sourceMapFn = outputFolderPath + File.separator + classPath + ".js.map";
File sourceMapDestFile = new File(sourceMapFn);
inStream = sourceMapFileEntry.createInputStream();
- outStream = FileUtils.openOutputStream(sourceMapDestFile);
- b = new byte[1024 * 1024];
- while ((bytes_read = inStream.read(b)) != -1)
+ String sourceMapContents = IOUtils.toString(inStream, Charset.forName("utf8"));
+ SourceMapConsumerV3 sourceMapConsumer = new SourceMapConsumerV3();
+ try
{
- outStream.write(b, 0, bytes_read);
+ 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 = sourceMapConsumerToGenerator(sourceMapConsumer);
+ String newSourceRootUri = convertSourcePathToURI(newSourceRoot.getAbsolutePath());
+ sourceMapGenerator.setSourceRoot(newSourceRootUri);
+ StringBuilder builder = new StringBuilder();
+ try
+ {
+ sourceMapGenerator.appendTo(builder, destFile.getName());
+ }
+ catch(IOException e)
+ {
+ return "";
+ }
+ FileUtils.writeStringToFile(sourceMapDestFile, builder.toString(), Charset.forName("utf8"));
+ }
+ else
+ {
+ FileUtils.writeStringToFile(sourceMapDestFile, sourceMapContents, Charset.forName("utf8"));
+ }
}
- outStream.flush();
- outStream.close();
- inStream.close();
}
}
@@ -1533,6 +1562,21 @@ public class GoogDepsWriter {
path = path.replace('\\', '/');
return path;
}
+
+ private String convertSourcePathToURI(String sourcePath)
+ {
+ if (sourcePath == null)
+ {
+ return null;
+ }
+ File file = new File(sourcePath);
+ if (file.isAbsolute())
+ {
+ sourcePath = "file:///" + sourcePath;
+ }
+ //prefer forward slash because web browser devtools expect it
+ return sourcePath.replace('\\', '/');
+ }
boolean isGoogProvided(String className)
{