Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS Translator improvements ( #1570

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CodenameOne/src/com/codename1/ui/TextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ private void initRowString() {
return;
}
}
System.out.println("Test5");
Style style = getUnselectedStyle();
rowStrings= new ArrayList();
widthForRowCalculations = getWidth() - style.getPadding(false, RIGHT) - style.getPadding(false, LEFT);
Expand Down
Binary file modified Ports/iOSPort/nativeSources/libzbar.a
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public String generateCSharpCode() {
}

public static void markDependencies(List<ByteCodeClass> lst) {
if (mainClass == null) {
throw new RuntimeException("Missing main class..");
}
mainClass.markDependent(lst);
for(ByteCodeClass bc : lst) {
if(bc.clsName.equals("java_lang_Boolean")) {
Expand Down Expand Up @@ -1522,5 +1525,8 @@ public boolean isUsedByNative() {
return usedByNative;
}


@Override
public String toString() {
return "[ByteCodeClass "+clsName+"]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public String extension() {
public abstract String extension();
};
public static OutputType output = OutputType.OUTPUT_TYPE_IOS;
public static boolean verbose = true;

public static boolean verbose = Boolean.parseBoolean(System.getProperty("ByteCodeTranslator.verbose","true"));
public static boolean draft = Boolean.parseBoolean(System.getProperty("ByteCodeTranslator.draft","false"));

ByteCodeTranslator() {
}

Expand Down Expand Up @@ -95,7 +96,9 @@ public boolean accept(File pathname) {
} else {
if(!f.isDirectory()) {
// copy the file to the dest dir
copy(new FileInputStream(f), new FileOutputStream(new File(outputDir, f.getName())));
if (f.getName().equals("package.html"))
continue;
copy(new FileInputStream(f), new PreservingFileOutputStream(new File(outputDir, f.getName())));
}
}
}
Expand All @@ -111,17 +114,23 @@ public boolean accept(File pathname) {
}
}

private void copyDir(File source, File destDir) throws IOException {
private boolean copyDir(File source, File destDir) throws IOException {
File destFile = new File(destDir, source.getName());
destFile.mkdirs();
File[] files = source.listFiles();
boolean retval = false;
for(File f : files) {
if(f.isDirectory()) {
copyDir(f, destFile);
long savedModified = destFile.lastModified();
boolean modified = copyDir(f, destFile);
if (!modified) {
destFile.setLastModified(savedModified);
}
} else {
copy(new FileInputStream(f), new FileOutputStream(new File(destFile, f.getName())));
retval |= copy(new FileInputStream(f), new PreservingFileOutputStream(new File(destFile, f.getName())));
}
}
return retval;
}

/**
Expand All @@ -145,6 +154,7 @@ public static void main(String[] args) throws Exception {
final String appVersion = args[6];
final String appType = args[7];
final String addFrameworks = args[8];
StringBuilder appFonts = new StringBuilder("\n");
// we accept 3 arguments output type, input directory & output directory
if(args[0].equalsIgnoreCase("csharp")) {
output = OutputType.OUTPUT_TYPE_CSHARP;
Expand Down Expand Up @@ -179,11 +189,11 @@ public static void main(String[] args) throws Exception {
imagesXcassets.mkdirs();
File launchImageLaunchimage = new File(imagesXcassets, "LaunchImage.launchimage");
launchImageLaunchimage.mkdirs();
copy(ByteCodeTranslator.class.getResourceAsStream("/LaunchImages.json"), new FileOutputStream(new File(launchImageLaunchimage, "Contents.json")));
copy(ByteCodeTranslator.class.getResourceAsStream("/LaunchImages.json"), new PreservingFileOutputStream(new File(launchImageLaunchimage, "Contents.json")));

File appIconAppiconset = new File(imagesXcassets, "AppIcon.appiconset");
appIconAppiconset.mkdirs();
copy(ByteCodeTranslator.class.getResourceAsStream("/Icons.json"), new FileOutputStream(new File(appIconAppiconset, "Contents.json")));
copy(ByteCodeTranslator.class.getResourceAsStream("/Icons.json"), new PreservingFileOutputStream(new File(appIconAppiconset, "Contents.json")));


File xcproj = new File(root, appName + ".xcodeproj");
Expand All @@ -196,35 +206,38 @@ public static void main(String[] args) throws Exception {
b.execute(sources, srcRoot);

File cn1Globals = new File(srcRoot, "cn1_globals.h");
copy(ByteCodeTranslator.class.getResourceAsStream("/cn1_globals.h"), new FileOutputStream(cn1Globals));
copy(ByteCodeTranslator.class.getResourceAsStream("/cn1_globals.h"), new PreservingFileOutputStream(cn1Globals));
File cn1GlobalsM = new File(srcRoot, "cn1_globals.m");
copy(ByteCodeTranslator.class.getResourceAsStream("/cn1_globals.m"), new FileOutputStream(cn1GlobalsM));
copy(ByteCodeTranslator.class.getResourceAsStream("/cn1_globals.m"), new PreservingFileOutputStream(cn1GlobalsM));
File nativeMethods = new File(srcRoot, "nativeMethods.m");
copy(ByteCodeTranslator.class.getResourceAsStream("/nativeMethods.m"), new FileOutputStream(nativeMethods));
copy(ByteCodeTranslator.class.getResourceAsStream("/nativeMethods.m"), new PreservingFileOutputStream(nativeMethods));

Parser.writeOutput(srcRoot);

File templateInfoPlist = new File(srcRoot, appName + "-Info.plist");
copy(ByteCodeTranslator.class.getResourceAsStream("/template/template/template-Info.plist"), new FileOutputStream(templateInfoPlist));
File templateInfoPlist = new File(srcRoot, appName + "-Info.plist" + PreservingFileOutputStream.NEW_SUFFIX);
copy(ByteCodeTranslator.class.getResourceAsStream("/template/template/template-Info.plist"), new PreservingFileOutputStream(templateInfoPlist));

File templatePch = new File(srcRoot, appName + "-Prefix.pch");
copy(ByteCodeTranslator.class.getResourceAsStream("/template/template/template-Prefix.pch"), new FileOutputStream(templatePch));
copy(ByteCodeTranslator.class.getResourceAsStream("/template/template/template-Prefix.pch"), new PreservingFileOutputStream(templatePch));

File xmlvm = new File(srcRoot, "xmlvm.h");
copy(ByteCodeTranslator.class.getResourceAsStream("/xmlvm.h"), new FileOutputStream(xmlvm));
copy(ByteCodeTranslator.class.getResourceAsStream("/xmlvm.h"), new PreservingFileOutputStream(xmlvm));

File projectWorkspaceData = new File(projectXCworkspace, "contents.xcworkspacedata");
copy(ByteCodeTranslator.class.getResourceAsStream("/template/template.xcodeproj/project.xcworkspace/contents.xcworkspacedata"), new FileOutputStream(projectWorkspaceData));
File projectWorkspaceData = new File(projectXCworkspace, "contents.xcworkspacedata"+ PreservingFileOutputStream.NEW_SUFFIX);
copy(ByteCodeTranslator.class.getResourceAsStream("/template/template.xcodeproj/project.xcworkspace/contents.xcworkspacedata"), new PreservingFileOutputStream(projectWorkspaceData));
replaceInFile(projectWorkspaceData, "KitchenSink", appName);


File projectPbx = new File(xcproj, "project.pbxproj");
copy(ByteCodeTranslator.class.getResourceAsStream("/template/template.xcodeproj/project.pbxproj"), new FileOutputStream(projectPbx));
File projectPbx = new File(xcproj, "project.pbxproj"+ PreservingFileOutputStream.NEW_SUFFIX);
copy(ByteCodeTranslator.class.getResourceAsStream("/template/template.xcodeproj/project.pbxproj"), new PreservingFileOutputStream(projectPbx));

String[] sourceFiles = srcRoot.list(new FilenameFilter() {
@Override
public boolean accept(File pathname, String string) {
return string.endsWith(".bundle") || string.endsWith(".xcdatamodeld") || !pathname.isHidden() && !string.startsWith(".") && !"Images.xcassets".equals(string);
public boolean accept(File pathname, String filename) {
if (filename.endsWith(".ttf")) {
appFonts.append("<string>"+filename+"</string>\n");
}
return filename.endsWith(".bundle") || filename.endsWith(".xcdatamodeld") || !pathname.isHidden() && !filename.startsWith(".") && !"Images.xcassets".equals(filename);
}
});

Expand Down Expand Up @@ -278,6 +291,11 @@ public boolean accept(File pathname, String string) {
arr.addAll(Arrays.asList(sourceFiles));

for(String file : arr) {
if (file.endsWith(PreservingFileOutputStream.NEW_SUFFIX)) {
file = file.substring(0, file.length()-PreservingFileOutputStream.NEW_SUFFIX.length());
} else {
if (arr.contains(file + PreservingFileOutputStream.NEW_SUFFIX)) continue; // remove duplicates
}
fileListEntry.append(" 0");
currentValue++;
String fileOneValue = Integer.toHexString(currentValue).toUpperCase();
Expand Down Expand Up @@ -417,7 +435,15 @@ public boolean accept(File pathname, String string) {
}

String bundleVersion = System.getProperty("bundleVersionNumber", appVersion);
replaceInFile(templateInfoPlist, "com.codename1pkg", appPackageName, "${PRODUCT_NAME}", appDisplayName, "VERSION_VALUE", appVersion, "VERSION_BUNDLE_VALUE", bundleVersion);
replaceInFile(templateInfoPlist,
"com.codename1pkg", appPackageName,
"${PRODUCT_NAME}", appDisplayName,
"VERSION_VALUE", appVersion,
"VERSION_BUNDLE_VALUE", bundleVersion,
"${APP_FONTS}", appFonts.toString());
PreservingFileOutputStream.finishWithNewFile(projectPbx);
PreservingFileOutputStream.finishWithNewFile(templateInfoPlist);
PreservingFileOutputStream.finishWithNewFile(projectWorkspaceData);
} else {
b.execute(sources, dest);
Parser.writeOutput(dest);
Expand Down Expand Up @@ -495,8 +521,8 @@ private static void replaceInFile(File sourceFile, String... values) throws IOEx
* @param i source
* @param o destination
*/
public static void copy(InputStream i, OutputStream o) throws IOException {
copy(i, o, 8192);
public static boolean copy(InputStream i, OutputStream o) throws IOException {
return copy(i, o, 8192);
}

/**
Expand All @@ -507,7 +533,8 @@ public static void copy(InputStream i, OutputStream o) throws IOException {
* @param o destination
* @param bufferSize the size of the buffer, which should be a power of 2 large enoguh
*/
public static void copy(InputStream i, OutputStream o, int bufferSize) throws IOException {
public static boolean copy(InputStream i, OutputStream o, int bufferSize) throws IOException {
boolean modified = true;
try {
byte[] buffer = new byte[bufferSize];
int size = i.read(buffer);
Expand All @@ -516,29 +543,35 @@ public static void copy(InputStream i, OutputStream o, int bufferSize) throws IO
size = i.read(buffer);
}
} finally {
cleanup(o);
cleanup(i);
modified = cleanup(o);
}
return modified;
}

/**
* Closes the object (connection, stream etc.) without throwing any exception, even if the
* object is null
*
* @param o Connection, Stream or other closeable object
* @return true if modified
*/
public static void cleanup(Object o) {
public static boolean cleanup(Object o) {
try {
if(o instanceof OutputStream) {
((OutputStream)o).close();
return;
if (o instanceof PreservingFileOutputStream) {
return !((PreservingFileOutputStream)o).equal;
}
return true;
}
if(o instanceof InputStream) {
((InputStream)o).close();
return;
return false;
}
} catch(IOException err) {
err.printStackTrace();
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,12 @@ public void addDebugInfo(int line) {
}

public void addLabel(Label l) {
addInstruction(new com.codename1.tools.translator.bytecodes.LabelInstruction(l));
addInstruction(new com.codename1.tools.translator.bytecodes.LabelInstruction(l) {
@Override
public String toString() {
return "BL_"+clsName+"__"+methodName+"__"+instructions.size();
}
});
}

public void addInvoke(int opcode, String owner, String name, String desc, boolean itf) {
Expand Down
Loading