[ 1755255 ] 2pack should support installation of compile java file

- enabled deployment of jar.
This commit is contained in:
Heng Sin Low 2007-08-24 02:17:12 +00:00
parent 9a86f89870
commit 0fcde7bce9
1 changed files with 29 additions and 28 deletions

View File

@ -51,17 +51,17 @@ public class DistFileElementHandler extends AbstractElementHandler {
//log.info(Compiere.MAIN_VERSION); //log.info(Compiere.MAIN_VERSION);
//Check Release Number //Check Release Number
if(releaseNumber==null||Adempiere.MAIN_VERSION.equals(releaseNumber)||releaseNumber.equals("all")){ if(releaseNumber==null||Adempiere.MAIN_VERSION.equals(releaseNumber)||releaseNumber.equals("all")){
String sourceName = atts.getValue("name"); String fileName = atts.getValue("name");
String sourceDirectory = atts.getValue("sourceDirectory"); String sourceDirectory = atts.getValue("sourceDirectory");
String targetDirectory = atts.getValue("targetDirectory"); String targetDirectory = atts.getValue("targetDirectory");
Object_Status = "New"; Object_Status = "New";
int idDetail=0; int idDetail=0;
InputStream source; // Stream for reading from the source file. InputStream inputStream; // Stream for reading from the source file.
OutputStream copy; // Stream for writing the copy. OutputStream outputStream; // Stream for writing the copy.
String packagePath=null; String packagePath=null;
String sourcePath=null; String adempiereSourcePath=null;
//get adempiere-all directory //get adempiere-all directory
try { try {
@ -71,7 +71,7 @@ public class DistFileElementHandler extends AbstractElementHandler {
parentDirectory = parentDirectory.getParentFile(); parentDirectory = parentDirectory.getParentFile();
} }
parentDirectory = parentDirectory.getParentFile(); parentDirectory = parentDirectory.getParentFile();
sourcePath = parentDirectory.getCanonicalPath(); adempiereSourcePath = parentDirectory.getCanonicalPath();
} catch (IOException e1) { } catch (IOException e1) {
System.out.println("Can't find adempiere-all directory."); System.out.println("Can't find adempiere-all directory.");
} }
@ -86,18 +86,19 @@ public class DistFileElementHandler extends AbstractElementHandler {
} }
} }
//Correct target directory for proper file seperator //Correct target directory for proper file seperator
String fullDirectory = sourcePath+targetDirectory; String fullTargetPath =
String targetDirectoryModified=null; fileName.endsWith(".jar")
? packagePath + targetDirectory
: adempiereSourcePath+targetDirectory;
char slash1 = '\\'; char slash1 = '\\';
char slash2 = '/'; char slash2 = '/';
if (File.separator.equals("/")) if (File.separator.equals("/"))
targetDirectoryModified = fullDirectory.replace(slash1,slash2); fullTargetPath = fullTargetPath.replace(slash1,slash2);
else else
targetDirectoryModified = fullDirectory.replace(slash2,slash1); fullTargetPath = fullTargetPath.replace(slash2,slash1);
File file = new File(targetDirectoryModified+sourceName); File file = new File(fullTargetPath+fileName);
//TODO: derive force from user parameter //TODO: derive force from user parameter
boolean force = true; boolean force = true;
String fileDate = null; String fileDate = null;
@ -110,48 +111,48 @@ public class DistFileElementHandler extends AbstractElementHandler {
//backup file to package directory //backup file to package directory
else if (file.exists() && force == true) { else if (file.exists() && force == true) {
Object_Status = "Update"; Object_Status = "Update";
log.info("Target Backup:"+targetDirectoryModified+sourceName); log.info("Target Backup:"+fullTargetPath+fileName);
source = OpenInputfile(targetDirectoryModified+sourceName); inputStream = OpenInputfile(fullTargetPath+fileName);
SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssSSSSZ"); SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssSSSSZ");
Date today = new Date(); Date today = new Date();
fileDate = formatter_file.format(today); fileDate = formatter_file.format(today);
copy = OpenOutputfile(packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName); outputStream = OpenOutputfile(packagePath+File.separator+"backup"+File.separator+fileDate+"_"+fileName);
log.info("Source Backup:"+packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName); log.info("Source Backup:"+packagePath+File.separator+"backup"+File.separator+fileDate+"_"+fileName);
copyFile (source,copy); copyFile (inputStream, outputStream);
log.info("Backup Complete"); log.info("Backup Complete");
} }
// Correct dist directory for proper file seperator // Correct dist directory for proper file seperator
String distDirectoryModified=null; String fullSourcePath=null;
if (File.separator.equals("/")) if (File.separator.equals("/"))
distDirectoryModified = sourceDirectory.replace(slash1,slash2); fullSourcePath = sourceDirectory.replace(slash1,slash2);
else else
distDirectoryModified = sourceDirectory.replace(slash2,slash1); fullSourcePath = sourceDirectory.replace(slash2,slash1);
source = OpenInputfile(packagePath+distDirectoryModified+sourceName); inputStream = OpenInputfile(packagePath+fullSourcePath+fileName);
// Create Target directory if required // Create Target directory if required
File targetDir = new File(targetDirectoryModified); File targetDir = new File(fullTargetPath);
if (!targetDir.exists()){ if (!targetDir.exists()){
boolean success = (new File(targetDirectoryModified)).mkdirs(); boolean success = (new File(fullTargetPath)).mkdirs();
if (!success) { if (!success) {
log.info("Target directory creation failed"); log.info("Target directory creation failed");
} }
} }
copy = OpenOutputfile(targetDirectoryModified+sourceName); outputStream = OpenOutputfile(fullTargetPath+fileName);
//Copy File //Copy File
int success = copyFile (source,copy); int success = copyFile (inputStream,outputStream);
//Record in log //Record in log
int idBackup = MSequence.getNextID (getClientId(ctx), "AD_Package_Imp_Backup", getTrxName(ctx)); int idBackup = MSequence.getNextID (getClientId(ctx), "AD_Package_Imp_Backup", getTrxName(ctx));
if (success != -1){ if (success != -1){
try { try {
idDetail = record_log (ctx, 1, sourceName,"file", 0,0, Object_Status,sourceName,0); idDetail = record_log (ctx, 1, fileName,"file", 0,0, Object_Status,fileName,0);
} catch (SAXException e) { } catch (SAXException e) {
log.info ("setfile:"+e); log.info ("setfile:"+e);
} }
} }
else{ else{
try { try {
idDetail = record_log (ctx, 0, sourceName,"file", 0,0, Object_Status,sourceName,0); idDetail = record_log (ctx, 0, fileName,"file", 0,0, Object_Status,fileName,0);
} catch (SAXException e) { } catch (SAXException e) {
log.info ("setfile:"+e); log.info ("setfile:"+e);
} }
@ -169,8 +170,8 @@ public class DistFileElementHandler extends AbstractElementHandler {
.append( ", " + idBackup ) .append( ", " + idBackup )
.append( ", " + idDetail ) .append( ", " + idDetail )
.append( ", " + getPackageImpId(ctx) ) .append( ", " + getPackageImpId(ctx) )
.append( ", '" + targetDirectoryModified+sourceName ) .append( ", '" + fullTargetPath+fileName )
.append( "', '" + packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName ) .append( "', '" + packagePath+File.separator+"backup"+File.separator+fileDate+"_"+fileName )
.append( "')"); .append( "')");
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));