Various updates

This commit is contained in:
Norberto Lopez
2013-04-17 21:56:38 +00:00
parent 86a247640c
commit d609c0d46c
5 changed files with 145 additions and 104 deletions

View File

@@ -48,7 +48,7 @@ def buildRelease(args, buildPath):
subprocess.call(cmd, stderr=subprocess.STDOUT)
# Perform cleanup: Remove the tmp folder
shutil.rmtree(tmpPath)
# shutil.rmtree(tmpPath)

View File

@@ -19,6 +19,7 @@ import java.util.Map;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import distMaker.apple.PropFileUtil;
import distMaker.gui.PickReleasePanel;
import distMaker.node.Node;
@@ -43,9 +44,9 @@ public class DistMakerEngine
parentFrame = aParentFrame;
msgPanel = new MessagePanel(parentFrame);
msgPanel.setSize(375, 180);
msgPanel.setSize(450, 250);
promptPanel = new PromptPanel(parentFrame);
promptPanel.setSize(300, 150);
promptPanel.setSize(350, 150);
initialize();
}
@@ -83,7 +84,8 @@ public class DistMakerEngine
// Setup our TaskPanel
taskPanel = new FullTaskPanel(parentFrame, true, false);
taskPanel.setTitle(appName + ": Checking for updates...");
taskPanel.setSize(640, taskPanel.getPreferredSize().height);
// taskPanel.setSize(680, taskPanel.getPreferredSize().height);
taskPanel.setSize(680, 400);
taskPanel.setTabSize(2);
taskPanel.setVisible(true);
@@ -197,6 +199,7 @@ public class DistMakerEngine
// Form the PickReleasePanel
pickVersionPanel = new PickReleasePanel(parentFrame, currRelease);
pickVersionPanel.setSize(320, 350);
}
/**
@@ -313,9 +316,10 @@ public class DistMakerEngine
*/
private boolean downloadRelease(Task aTask, Release aRelease, File destPath)
{
Map<String, Node> currMap, updateMap;
URL staleUrl, updateUrl;
Map<String, Node> staleMap, updateMap;
Node staleNode, updateNode;
URL catUrl, staleUrl, updateUrl;
File catalogFile;
boolean isPass;
try
@@ -329,14 +333,22 @@ public class DistMakerEngine
aExp.printStackTrace();
return false;
}
// Download the update catalog to the (local) delta location
catUrl = IoUtil.createURL(updateUrl.toString() + "/catalog.txt");
catalogFile = new File(destPath, "catalog.txt");
if (DistUtils.downloadFile(aTask, catUrl, catalogFile, refCredential) == false)
return false;
// Load the map of stale nodes
currMap = DistUtils.readCatalog(aTask, staleUrl, null);
if (currMap == null)
catalogFile = new File(DistUtils.getAppPath(), "catalog.txt");
staleMap = DistUtils.readCatalog(aTask, catalogFile, staleUrl);
if (staleMap == null)
return false;
// Load the map of update nodes
updateMap = DistUtils.readCatalog(aTask, updateUrl, refCredential);
catalogFile = new File(destPath, "catalog.txt");
updateMap = DistUtils.readCatalog(aTask, catalogFile, updateUrl);
if (updateMap == null)
return false;
@@ -349,7 +361,7 @@ public class DistMakerEngine
return false;
updateNode = updateMap.get(aFileName);
staleNode = currMap.get(aFileName);
staleNode = staleMap.get(aFileName);
// Attempt to use the local copy
isPass = false;
@@ -360,7 +372,7 @@ public class DistMakerEngine
aTask.infoAppendln("\t(L) " + staleNode.getFileName());
}
// Use the remote update copy
// Use the remote update copy, if we were not able to use a local stale copy
if (isPass == false)
{
isPass = updateNode.transferContentTo(aTask, refCredential, destPath);
@@ -378,6 +390,39 @@ public class DistMakerEngine
return false;
}
}
// Update the Info.plist file (Apple specific)
File pFile;
String errMsg;
pFile = new File(destPath.getParentFile(), "Info.plist");
if (pFile.isFile() == true)
{
errMsg = null;
if (pFile.setWritable(true) == false)
errMsg = "Failure. No writable permmisions for file: " + pFile;
else if (PropFileUtil.updateVersion(pFile, aRelease.getVersion()) == false)
errMsg = "Failure. Failed to update file: " + pFile;
if (errMsg != null)
{
aTask.infoAppendln(errMsg);
return false;
}
}
return true;
}

View File

@@ -7,6 +7,7 @@ import glum.reflect.ReflectUtil;
import glum.task.ConsoleTask;
import glum.task.Task;
import glum.unit.DateUnit;
import glum.util.ThreadUtil;
import java.io.*;
import java.net.*;
@@ -230,92 +231,6 @@ public class DistUtils
return fullList;
}
/**
* Returns the list of files (relative to destPath) that are needed for the specified release.
*/
public static Map<String, Node> readCatalog(Task aTask, URL aUpdateUrl, Credential aCredential)
{
Map<String, Node> retMap;
URL md5sumUrl;
URLConnection connection;
InputStream inStream;
BufferedReader bufReader;
String errMsg;
errMsg = null;
retMap = Maps.newLinkedHashMap();
md5sumUrl = IoUtil.createURL(aUpdateUrl.toString() + "/catalog.txt");
connection = null;
inStream = null;
bufReader = null;
try
{
String[] tokens;
String strLine, filename, md5sum;
long fileLen;
// Read the contents of the file
connection = md5sumUrl.openConnection();
inStream = NetUtil.getInputStream(connection, aCredential);
bufReader = new BufferedReader(new InputStreamReader(new BufferedInputStream(inStream)));
// Read the lines
while (true)
{
strLine = bufReader.readLine();
// Bail once we are done
if (strLine == null)
break;
tokens = strLine.split(",", 4);
if (strLine.isEmpty() == true || strLine.startsWith("#") == true)
; // Nothing to do
else if (tokens.length == 2 && tokens[0].equals("P") == true)
{
filename = tokens[1];
retMap.put(filename, new PathNode(aUpdateUrl, filename));
}
else if (tokens.length == 4 && tokens[0].equals("F") == true)
{
md5sum = tokens[1];
fileLen = GuiUtil.readLong(tokens[2], -1);
filename = tokens[3];
retMap.put(filename, new FileNode(aUpdateUrl, filename, md5sum, fileLen));
}
else
{
aTask.infoAppendln("Unreconized line: " + strLine);
}
}
}
catch (IOException aExp)
{
errMsg = getErrorCodeMessage(aUpdateUrl, connection, aExp, "md5sum.txt");
}
finally
{
IoUtil.forceClose(inStream);
IoUtil.forceClose(bufReader);
}
// See if we are in a valid state
if (errMsg != null)
; // Nothing to do, as an earlier error has occured
else if (retMap.size() == 0)
errMsg = "The md5sum URL appears to be invalid.";
// Bail if there were issues
if (errMsg != null)
{
aTask.infoAppendln(errMsg);
return null;
}
return retMap;
}
/**
* Helper method that converts an IOException to an understandable message
*
@@ -383,4 +298,85 @@ public class DistUtils
return true;
}
/**
* Returns a map of Nodes which describe the full content of an update specified in <aUpdateUrl>/catalog.txt
*/
public static Map<String, Node> readCatalog(Task aTask, File catalogFile, URL aUpdateUrl)
{
Map<String, Node> retMap;
InputStream inStream;
BufferedReader bufReader;
String errMsg;
errMsg = null;
retMap = Maps.newLinkedHashMap();
inStream = null;
bufReader = null;
try
{
String[] tokens;
String strLine, filename, md5sum;
long fileLen;
// Read the contents of the file
inStream = new FileInputStream(catalogFile);
bufReader = new BufferedReader(new InputStreamReader(new BufferedInputStream(inStream)));
// Read the lines
while (true)
{
strLine = bufReader.readLine();
// Bail once we are done
if (strLine == null)
break;
tokens = strLine.split(",", 4);
if (strLine.isEmpty() == true || strLine.startsWith("#") == true)
; // Nothing to do
else if (tokens.length == 2 && tokens[0].equals("P") == true)
{
filename = tokens[1];
retMap.put(filename, new PathNode(aUpdateUrl, filename));
}
else if (tokens.length == 4 && tokens[0].equals("F") == true)
{
md5sum = tokens[1];
fileLen = GuiUtil.readLong(tokens[2], -1);
filename = tokens[3];
retMap.put(filename, new FileNode(aUpdateUrl, filename, md5sum, fileLen));
}
else
{
aTask.infoAppendln("Unreconized line: " + strLine);
}
}
}
catch (IOException aExp)
{
errMsg = ThreadUtil.getStackTrace(aExp);
}
finally
{
IoUtil.forceClose(inStream);
IoUtil.forceClose(bufReader);
}
// See if we are in a valid state
if (errMsg != null)
; // Nothing to do, as an earlier error has occurred
else if (retMap.size() == 0)
errMsg = "The catalog appears to be invalid.";
// Bail if there were issues
if (errMsg != null)
{
aTask.infoAppendln(errMsg);
return null;
}
return retMap;
}
}

View File

@@ -11,10 +11,10 @@ import distMaker.DistUtils;
public class FileNode implements Node
{
private URL rootUrl;
private String md5sum;
private String fileName;
private long fileLen;
protected URL rootUrl;
protected String md5sum;
protected String fileName;
protected long fileLen;
public FileNode(URL aRootUrl, String aFileName, String aMd5sum, long aFileLen)
{

View File

@@ -8,8 +8,8 @@ import java.net.URL;
public class PathNode implements Node
{
private URL rootUrl;
private String fileName;
protected URL rootUrl;
protected String fileName;
public PathNode(URL aRootUrl, String aFileName)
{