Revision: 16853
Author: pavel.slegr
Date: Mon Feb 14 12:12:54 2011
Log: update JbcpPatcher - CRC enable/disable functionality
http://code.google.com/p/mobicents/source/detail?r=16853
Modified:
/tools/productization/tags/JbcpPatcher/0.9.1/pom.xml
/tools/productization/tags/JbcpPatcher/0.9.1/src/main/java/com/rh/jbcp/patcher/AbstractJbcpPatcher.java
/tools/productization/tags/JbcpPatcher/0.9.1/src/main/java/com/rh/jbcp/patcher/JbcpPatcher.java
=======================================
--- /tools/productization/tags/JbcpPatcher/0.9.1/pom.xml Tue May 11
06:08:42 2010
+++ /tools/productization/tags/JbcpPatcher/0.9.1/pom.xml Mon Feb 14
12:12:54 2011
@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>jbcp</groupId>
<artifactId>JbcpPatchCreator</artifactId>
- <version>0.9</version>
+ <version>0.9.1</version>
<build>
<plugins>
<plugin>
@@ -41,7 +41,7 @@
<attribute name="Main-Class"
value="com.rh.jbcp.patcher.JbcpPatcher"/>
</manifest>
- <jar destfile="target/JbcpPatcher-0.9.jar"
+ <jar destfile="target/JbcpPatcher-0.9.1.jar"
basedir="target/classes"
includes="**/AbstractJbcpPatcher.class,
**/JbcpPatcher.class,**/FileDetails.class"
=======================================
---
/tools/productization/tags/JbcpPatcher/0.9.1/src/main/java/com/rh/jbcp/patcher/AbstractJbcpPatcher.java
Tue May 11 06:08:42 2010
+++
/tools/productization/tags/JbcpPatcher/0.9.1/src/main/java/com/rh/jbcp/patcher/AbstractJbcpPatcher.java
Mon Feb 14 12:12:54 2011
@@ -74,7 +74,7 @@
}
- public void extractZipFile(String baseDir, String zipFilename, boolean
createMode)
+ public void extractZipFile(String baseDir, String zipFilename, boolean
createMode, boolean checkCrc)
{
try
{
@@ -84,12 +84,12 @@
{
//extract CRC and delete files first
final ZipEntry crcEntry = zipFile.getEntry(CrcFileName);
- extractEntryFromZip(null, crcEntry,
zipFile.getInputStream(crcEntry), true);
+ extractEntryFromZip(null, crcEntry,
zipFile.getInputStream(crcEntry), true, checkCrc);
System.out.println("extracted crcFile");
setupCrcMaps(crcEntry.getName());
System.out.println("extracting patchDeleteList");
final ZipEntry patchEntry =
zipFile.getEntry(patchDeleteListFile);
- extractEntryFromZip(null, patchEntry,
zipFile.getInputStream(patchEntry), true);
+ extractEntryFromZip(null, patchEntry,
zipFile.getInputStream(patchEntry), true, checkCrc);
}
@@ -99,13 +99,17 @@
while (entries.hasMoreElements())
{
final ZipEntry zipEntry = (ZipEntry) entries.nextElement();
-
- if (zipEntry.getName().equals(CrcFileName) ||
zipEntry.getName().equals(patchDeleteListFile))
- {
- continue;
+
+ // check CRC
+ if (checkCrc) {
+
+ if (zipEntry.getName().equals(CrcFileName) ||
zipEntry.getName().equals(patchDeleteListFile))
+ {
+ continue;
+ }
}
// System.out.println("extracting " + zipEntry.getName());
- extractEntryFromZip(baseDir, zipEntry,
zipFile.getInputStream(zipEntry), false);
+ extractEntryFromZip(baseDir, zipEntry,
zipFile.getInputStream(zipEntry), false, checkCrc);
}
if (warningsGenerated)
{
@@ -144,7 +148,7 @@
}
- private void extractEntryFromZip(String baseDir, ZipEntry zipEntry,
InputStream zipinputstream, boolean controlFile) throws IOException
+ private void extractEntryFromZip(String baseDir, ZipEntry zipEntry,
InputStream zipinputstream, boolean controlFile, boolean checkCrc) throws
IOException
{
byte[] buf = new byte[1024];
if (zipEntry.isDirectory())
@@ -181,7 +185,11 @@
FileDetails details = fileDetails.get(zipEntry.getName());
if ((fileToUpgrade.length() != details.getLength()) ||
(getChecksumValue(new CRC32(), fileToUpgrade.getAbsolutePath()) !=
details.getCrc()))
{
- fileToUpgrade = new File(baseDir, zipEntry.getName()
+ ".patched");
+ // do not upgrade when CRC check is enabled, but rather
produce *.patched file instead
+ // As default CRC check is disabled, so all files will be
updated
+ if(checkCrc) {
+ fileToUpgrade = new File(baseDir, zipEntry.getName()
+ ".patched");
+ }
System.out.println("Warning: " + zipEntry.getName()
+ " Has changed from original - saving patch version in " +
fileToUpgrade.getName());
warningsGenerated = true;
} else
@@ -204,13 +212,19 @@
}
- public void applyPatch(String patchFilename, String
patchDeleteListFile, String appsrvParentDirname)
- {
+ public void applyPatch(String patchFilename, String
patchDeleteListFile, String appsrvParentDirname, boolean checkCrc)
+ {
+ if(checkCrc) {
+ System.out.println("*** Checking CRC is turned on now ***");
+ }
+ else {
+ System.out.println("*** Checking CRC is turned off now ***");
+ }
checkFileExists(patchFilename);
checkFileExists(appsrvParentDirname);
File tmpFile = new File(appsrvParentDirname);
- extractZipFile(tmpFile.getAbsolutePath(), patchFilename,
createMode);
+ extractZipFile(tmpFile.getAbsolutePath(), patchFilename,
createMode, checkCrc);
deleteObsolete(tmpFile.getAbsolutePath(), patchDeleteListFile);
}
@@ -266,7 +280,7 @@
}
CRCStream.close();
- extractZipFile(null, latestVersionFileName, createMode);
+ extractZipFile(null, latestVersionFileName, createMode, true);
makePatchZip(patchList, deleteList, zipBasename);
}
=======================================
---
/tools/productization/tags/JbcpPatcher/0.9.1/src/main/java/com/rh/jbcp/patcher/JbcpPatcher.java
Tue May 11 06:08:42 2010
+++
/tools/productization/tags/JbcpPatcher/0.9.1/src/main/java/com/rh/jbcp/patcher/JbcpPatcher.java
Mon Feb 14 12:12:54 2011
@@ -11,6 +11,7 @@
String patchFilename = null;
String appsrvParentDirname = null;
String zipBasename = null;
+ boolean checkCrc = false;
for (int i = 0; i < args.length; i++)
@@ -34,6 +35,10 @@
zipBasename = zipBasename.substring(0, index);
}
+ if (args[i].equals("-crc"))
+ {
+ checkCrc = true;
+ }
}
if (patchFilename == null || appsrvParentDirname == null)
{
@@ -44,7 +49,7 @@
patchDeleteListFile = zipBasename +
AbstractJbcpPatcher.PATCH_DELETE_LIST_FILE_NAME_SUFFIX;
CrcFileName = zipBasename + AbstractJbcpPatcher.CRC_FILE_NAME;
// apply patch
- patch.applyPatch(patchFilename, patchDeleteListFile,
appsrvParentDirname);
+ patch.applyPatch(patchFilename, patchDeleteListFile,
appsrvParentDirname, checkCrc);
}
public void usageError() {