Skip to content

Commit

Permalink
Fix for Unicode chars being mangled when building.
Browse files Browse the repository at this point in the history
Closes cappuccino#146.

Reviewed by me.
  • Loading branch information
Francisco Ryan Tolmasky I committed May 27, 2009
1 parent fc7b5a8 commit 90e7508
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 32 deletions.
6 changes: 3 additions & 3 deletions AppKit/Tools/blend/main.j
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function main()
temporaryCibFile = Packages.java.io.File.createTempFile("temp", ".cib"),
temporaryCibFilePath = String(temporaryCibFile.getAbsolutePath());

File.write(temporaryCibFilePath, [data string], { charset:"UTF8" });
File.write(temporaryCibFilePath, [data string], { charset:"UTF-8" });

cibFiles.push(temporaryCibFilePath);
}
Expand Down Expand Up @@ -171,8 +171,8 @@ function buildBlendFromCibFiles(cibFiles, outputFilePath, resourcesPath)

outputFile.mkdirs();

File.write(outputFilePath + "/Info.plist", [CPPropertyListCreate280NorthData(infoDictionary) string], { charset:"UTF8" });
File.write(outputFilePath + '/' + staticContentName, staticContent, { charset:"UTF8" });
File.write(outputFilePath + "/Info.plist", [CPPropertyListCreate280NorthData(infoDictionary) string], { charset:"UTF-8" });
File.write(outputFilePath + '/' + staticContentName, staticContent, { charset:"UTF-8" });

if (resourcesPath)
rsync(new Packages.java.io.File(resourcesPath), new Packages.java.io.File(outputFilePath));
Expand Down
34 changes: 10 additions & 24 deletions Objective-J/Tools/objj/bin/objjc
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/usr/bin/env narwhal

var objjc = require("objj/objjc");
var objjc = require("objj/objjc"),
File = require("file");

with (objjc)
{

importPackage(java.lang);

importClass(java.io.BufferedReader);
importClass(java.io.FileReader);
importClass(java.io.BufferedWriter);
importClass(java.io.FileWriter);


OBJJ_PREPROCESSOR_PREPROCESS = 1 << 10;
Expand All @@ -22,7 +21,7 @@ function exec(/*Array*/ command, /*Boolean*/ showOutput)
output = "",

process = Packages.java.lang.Runtime.getRuntime().exec(command),//jsArrayToJavaArray(command));
reader = new Packages.java.io.BufferedReader(new Packages.java.io.InputStreamReader(process.getInputStream()));
reader = new Packages.java.io.BufferedReader(new Packages.java.io.InputStreamReader(process.getInputStream(), "UTF-8"));

while (line = reader.readLine())
{
Expand All @@ -32,7 +31,7 @@ function exec(/*Array*/ command, /*Boolean*/ showOutput)
output += line + '\n';
}

reader = new Packages.java.io.BufferedReader(new Packages.java.io.InputStreamReader(process.getErrorStream()));
reader = new Packages.java.io.BufferedReader(new Packages.java.io.InputStreamReader(process.getErrorStream(), "UTF-8"));

while (line = reader.readLine())
System.out.println(line);
Expand All @@ -52,13 +51,9 @@ function exec(/*Array*/ command, /*Boolean*/ showOutput)

function compress(/*String*/ aCode, /*Object*/ flags, /*File*/ tmpFile)
{
var writer = new BufferedWriter(new FileWriter(tmpFile));

writer.write(aCode);

writer.close();
File.write(tmpFile, aCode, { charset:"UTF-8" });

return exec(["java", "-classpath", OBJJ_HOME + "/lib/js.jar" + ":" + OBJJ_HOME + "/lib/shrinksafe.jar", "org.dojotoolkit.shrinksafe.Main", tmpFile.getCanonicalPath(), "-escape-unicode"]);
return exec(["java", "-Dfile.encoding=UTF-8", "-classpath", OBJJ_HOME + "/lib/js.jar" + ":" + OBJJ_HOME + "/lib/shrinksafe.jar", "org.dojotoolkit.shrinksafe.Main", tmpFile.getCanonicalPath()]);
}

//#define SET_CONTEXT(aFragment, aContext) aFragment.context = aContext
Expand Down Expand Up @@ -112,15 +107,8 @@ function preprocess(aFilePath, outFilePath, gccArgs, flags)
return;

// Read file and preprocess it.
var reader = new BufferedReader(new FileReader(tmpFile)),
fileContents = "";

// Get contents of the file
while (reader.ready())
fileContents += reader.readLine() + '\n';

reader.close();

var fileContents = File.read(tmpFile, { charset: "UTF-8" });

// Preprocess contents into fragments.
var filePath = new String(new java.io.File(aFilePath).getName()),
fragments = objj_preprocess(fileContents, { path:"/x" }, {path:filePath}, flags),
Expand Down Expand Up @@ -171,9 +159,7 @@ function preprocess(aFilePath, outFilePath, gccArgs, flags)
}

// Write file.
var writer = new BufferedWriter(new FileWriter(outFilePath));
writer.write(preprocessed);
writer.close();
File.write(outFilePath, preprocessed, { charset: "UTF-8" });
}

function main()
Expand Down
2 changes: 1 addition & 1 deletion Objective-J/Tools/objj/lib/objj/objj.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ window.args = system.args;

with (window)
{
eval(File.read(OBJJ_HOME+"/lib/Frameworks/Objective-J/rhino.platform/Objective-J.js", { charset : "UTF-8" }));
eval(File.read(OBJJ_HOME + "/lib/Frameworks/Objective-J/rhino.platform/Objective-J.js", { charset:"UTF-8" }));

if (system.args.length > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion Objective-J/Tools/objj/lib/objj/objjc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var OBJJ_HOME = system.prefix + "/..";

with (window)
{
eval(File.read(OBJJ_HOME+"/lib/Frameworks/Objective-J/rhino.platform/Objective-J.js").toString());
eval(File.read(OBJJ_HOME + "/lib/Frameworks/Objective-J/rhino.platform/Objective-J.js", { charset:"UTF-8" }).toString());

for (var i = 0; i < exported.length; i++)
exports[exported[i]] = eval(exported[i]);
Expand Down
6 changes: 3 additions & 3 deletions Tools/nib2cib/main.j
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function convert(inputFileName, outputFileName, resourcesPath)
return;
}

var data = [CPData dataWithString:File.read(String(temporaryPlistFilePath), { charset:"UTF8" })];
var data = [CPData dataWithString:File.read(String(temporaryPlistFilePath), { charset:"UTF-8" })];

// Minor NSKeyedArchive to CPKeyedArchive conversion.
[data setString:[data string].replace(/\<key\>\s*CF\$UID\s*\<\/key\>/g, "<key>CP$UID</key>")];
Expand All @@ -141,7 +141,7 @@ function convert(inputFileName, outputFileName, resourcesPath)
[archiver encodeObject:objectData forKey:@"CPCibObjectDataKey"];
[archiver finishEncoding];

File.write(outputFileName, [data string], { charset:"UTF8" });
File.write(outputFileName, [data string], { charset:"UTF-8" });
}

function loadFrameworks(frameworkPaths, aCallback)
Expand All @@ -159,7 +159,7 @@ function loadFrameworks(frameworkPaths, aCallback)
java.lang.System.exit(1);
}

var infoDictionary = CPPropertyListCreateFromData([CPData dataWithString:File.read(frameworkPath + "/Info.plist", { charset:"UTF8" })]);
var infoDictionary = CPPropertyListCreateFromData([CPData dataWithString:File.read(frameworkPath + "/Info.plist", { charset:"UTF-8" })]);

if ([infoDictionary objectForKey:@"CPBundlePackageType"] !== "FMWK")
{
Expand Down

0 comments on commit 90e7508

Please sign in to comment.