Various updates

This commit is contained in:
Norberto Lopez
2013-05-07 22:13:41 +00:00
parent 4d6894cdca
commit 214c89df00
3 changed files with 93 additions and 4 deletions

View File

@@ -23,9 +23,9 @@ import java.util.Map;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import distMaker.apple.PropFileUtil;
import distMaker.gui.PickReleasePanel;
import distMaker.node.Node;
import distMaker.platform.AppleFileUtil;
public class DistMakerEngine
{
@@ -498,7 +498,7 @@ public class DistMakerEngine
errMsg = null;
if (pFile.setWritable(true) == false)
errMsg = "Failure. No writable permmisions for file: " + pFile;
else if (PropFileUtil.updateVersion(pFile, aRelease.getVersion()) == false)
else if (AppleFileUtil.updateVersion(pFile, aRelease.getVersion()) == false)
errMsg = "Failure. Failed to update file: " + pFile;
if (errMsg != null)

View File

@@ -308,6 +308,13 @@ public class DistUtils
*/
public static boolean isFullyWriteable(File aPath)
{
// There is no known way to change, the write bit to true, in windows,
// so by default, assume the path is writable. This method is totally unreliable on
// the Windows platform (Gives bogus results for files on CDs).
// TODO: See if File.canWrite(), returns the proper value on Windows
if (System.getProperty("os.name").startsWith("Windows") == true)
return true;
if (aPath.isDirectory() == false)
throw new RuntimeException("Specified path is not a folder: " + aPath);

View File

@@ -1,4 +1,4 @@
package distMaker.apple;
package distMaker.platform;
import glum.io.IoUtil;
@@ -16,8 +16,90 @@ import org.w3c.dom.*;
/**
* Utility class which contains a set of methods to interact with an Apple Info.plist file.
*/
public class PropFileUtil
public class AppleFileUtil
{
/**
* Utility method to update the specified max memory (-Xmx) value in the plist file (aFile) to the specified
* maxMemVal.
* <P>
* Note this method is very brittle, and assumes that the value occurs within <string> tags. The assumption is that
* the occurrence of the string, -Xmx, will be once and refer to the max heap memory.
*/
public static boolean updateMaxMem(File aFile, long numBytes)
{
DocumentBuilderFactory dbf;
Document dom;
Element doc;
String evalStr, memStr, oldStr;
String[] evalArr;
// Determine the memStr to use
if (numBytes % (1024 * 1024 * 1024) == 0)
memStr = "-Xmx" + (numBytes / (1024 * 1024 * 1024)) + "G";
else
memStr = "-Xmx" + (numBytes / (1024 * 1024)) + "M";
// Make an instance of the DocumentBuilderFactory
dbf = DocumentBuilderFactory.newInstance();
try
{
// use the factory to take an instance of the document builder
DocumentBuilder db = dbf.newDocumentBuilder();
// Parse using the builder to get the DOM mapping of the XML file
dom = db.parse(aFile);
doc = dom.getDocumentElement();
NodeList nodeList;
Node keyNode;
nodeList = doc.getElementsByTagName("string");
for (int c1 = 0; c1 < nodeList.getLength(); c1++)
{
keyNode = nodeList.item(c1).getFirstChild();
if (keyNode != null)
{
evalStr = keyNode.getNodeValue();
if (evalStr != null && evalStr.contains("-Xmx") == true)
{
evalArr = evalStr.split(" ");
for (int c2 = 0; c2 < evalArr.length; c2++)
{
oldStr = evalArr[c2];
if (oldStr.startsWith("-Xmx") == true)
evalArr[c2] = memStr;
}
System.out.println("Updating contents of file: " + aFile);
System.out.println(" Old Version: " + evalStr);
// Reconstitute the new evalStr
evalStr = "";
for (String aStr : evalArr)
evalStr += " " + aStr;
if (evalStr.length() > 0)
evalStr = evalStr.substring(1);
System.out.println(" New Version: " + evalStr);
keyNode.setNodeValue(evalStr);
break;
}
}
}
// Update the file with the changed document
writeDoc(aFile, dom);
return true;
}
catch (Exception aExp)
{
aExp.printStackTrace();
}
return false;
}
/**
* Utility method to update the specified version in the plist file (aFile) to the new version.
* <P>