From f22faccda1ea5f50a9d84171e12f72c9f341e8cf Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 19 Sep 2012 19:20:36 -0500 Subject: [PATCH] IDEMPIERE-436 AdempiereActivator is not able to run 2Pack --- .../pipo/srv/PipoDictionaryService.java | 26 ++++++++++++++++++- .../plugin/utils/AdempiereActivator.java | 17 +++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/org.adempiere.pipo/src/org/adempiere/pipo/srv/PipoDictionaryService.java b/org.adempiere.pipo/src/org/adempiere/pipo/srv/PipoDictionaryService.java index fb0397be14..3c80a19b54 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo/srv/PipoDictionaryService.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo/srv/PipoDictionaryService.java @@ -1,12 +1,15 @@ package org.adempiere.pipo.srv; import java.io.File; +import java.sql.Timestamp; import java.util.logging.Level; import java.util.logging.Logger; import org.adempiere.base.IDictionaryService; import org.adempiere.pipo2.PackIn; +import org.adempiere.pipo2.Zipper; import org.compiere.Adempiere; +import org.compiere.model.X_AD_Package_Imp_Proc; import org.compiere.util.Env; import org.compiere.util.Trx; import org.osgi.framework.BundleContext; @@ -28,7 +31,28 @@ public class PipoDictionaryService implements IDictionaryService { packIn.setPackageVersion((String) context.getBundle().getHeaders().get("Bundle-Version")); packIn.setUpdateDictionary(false); packIn.setPackageDirectory(getPackageDir()); - packIn.importXML(packageFile.getAbsolutePath(), Env.getCtx(), trxName); + + X_AD_Package_Imp_Proc adPackageImp = new X_AD_Package_Imp_Proc(Env.getCtx(), + 0, trxName); + File zipFilepath = packageFile; + logger.info("zipFilepath->" + zipFilepath); + String parentDir = Zipper.getParentDir(zipFilepath); + File targetDir = new File(System.getProperty("java.io.tmpdir")); + Zipper.unpackFile(zipFilepath, targetDir); + + String dict_file = targetDir + File.separator + parentDir + File.separator + + "dict" + File.separator + "PackOut.xml"; + + logger.info("dict file->" + dict_file); + + // call XML Handler + String msg = packIn.importXML(dict_file, Env.getCtx(), trxName); + adPackageImp.setName(packIn.getPackageName()); + adPackageImp.setDateProcessed(new Timestamp(System.currentTimeMillis())); + adPackageImp.setP_Msg(msg); + adPackageImp.setAD_Package_Source_Type("File"); + adPackageImp.saveEx(); + Trx.get(trxName, false).commit(); logger.info("commit " + trxName); } catch (Exception e) { diff --git a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AdempiereActivator.java b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AdempiereActivator.java index 789913306a..7ae0a580a9 100644 --- a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AdempiereActivator.java +++ b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AdempiereActivator.java @@ -1,6 +1,8 @@ package org.adempiere.plugin.utils; import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; import java.net.URL; import java.util.logging.Level; import java.util.logging.Logger; @@ -60,12 +62,21 @@ public class AdempiereActivator implements BundleActivator { } protected void packIn(String trxName) { - URL packout = this.getClass().getResource( - "/META-INF/2Pack.zip"); + URL packout = this.getClass().getClassLoader().getResource("/META-INF/2Pack.zip"); if (packout != null) { IDictionaryService service = Service.locate(IDictionaryService.class); try { - service.merge(context, new File(packout.getFile())); + // copy the resource to a temporary file to process it with 2pack + InputStream stream = this.getClass().getResourceAsStream("/META-INF/2Pack.zip"); + File zipfile = File.createTempFile(getName(), ".zip"); + FileOutputStream zipstream = new FileOutputStream(zipfile); + byte[] buffer = new byte[1024]; + int read; + while((read = stream.read(buffer)) != -1){ + zipstream.write(buffer, 0, read); + } + // call 2pack + service.merge(context, zipfile); } catch (Exception e) { logger.log(Level.WARNING, "Error on Dictionary service", e); }