From 72418fa47cd3b24513e0529843a5f419998e140a Mon Sep 17 00:00:00 2001 From: joergviola Date: Fri, 12 Mar 2010 18:15:16 +0000 Subject: [PATCH] Plugin Utility Bundle --- plugins/pluginUtils/.classpath | 7 ++ plugins/pluginUtils/.project | 28 +++++ .../.settings/org.eclipse.jdt.core.prefs | 8 ++ .../.settings/org.eclipse.pde.core.prefs | 4 + plugins/pluginUtils/META-INF/MANIFEST.MF | 11 ++ plugins/pluginUtils/build.properties | 4 + .../plugin/utils/AdempiereActivator.java | 103 ++++++++++++++++++ 7 files changed, 165 insertions(+) create mode 100644 plugins/pluginUtils/.classpath create mode 100644 plugins/pluginUtils/.project create mode 100644 plugins/pluginUtils/.settings/org.eclipse.jdt.core.prefs create mode 100644 plugins/pluginUtils/.settings/org.eclipse.pde.core.prefs create mode 100644 plugins/pluginUtils/META-INF/MANIFEST.MF create mode 100644 plugins/pluginUtils/build.properties create mode 100644 plugins/pluginUtils/src/org/adempiere/plugin/utils/AdempiereActivator.java diff --git a/plugins/pluginUtils/.classpath b/plugins/pluginUtils/.classpath new file mode 100644 index 0000000000..ad32c83a78 --- /dev/null +++ b/plugins/pluginUtils/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/plugins/pluginUtils/.project b/plugins/pluginUtils/.project new file mode 100644 index 0000000000..29dc1d61a3 --- /dev/null +++ b/plugins/pluginUtils/.project @@ -0,0 +1,28 @@ + + + pluginUtils + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/plugins/pluginUtils/.settings/org.eclipse.jdt.core.prefs b/plugins/pluginUtils/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..ef6af465ad --- /dev/null +++ b/plugins/pluginUtils/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Fri Mar 12 08:32:19 CET 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/plugins/pluginUtils/.settings/org.eclipse.pde.core.prefs b/plugins/pluginUtils/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 0000000000..e72eeee76a --- /dev/null +++ b/plugins/pluginUtils/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,4 @@ +#Fri Mar 12 08:32:19 CET 2010 +eclipse.preferences.version=1 +pluginProject.extensions=false +resolve.requirebundle=false diff --git a/plugins/pluginUtils/META-INF/MANIFEST.MF b/plugins/pluginUtils/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..b2e9d65818 --- /dev/null +++ b/plugins/pluginUtils/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: PluginUtils +Bundle-SymbolicName: org.adempiere.pluginUtils +Bundle-Version: 0.0.0.1 +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Import-Package: org.adempiere.base, + org.compiere.model, + org.compiere.util, + org.osgi.framework;version="1.5.0" +Export-Package: org.adempiere.plugin.utils diff --git a/plugins/pluginUtils/build.properties b/plugins/pluginUtils/build.properties new file mode 100644 index 0000000000..34d2e4d2da --- /dev/null +++ b/plugins/pluginUtils/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/plugins/pluginUtils/src/org/adempiere/plugin/utils/AdempiereActivator.java b/plugins/pluginUtils/src/org/adempiere/plugin/utils/AdempiereActivator.java new file mode 100644 index 0000000000..33cacb20a4 --- /dev/null +++ b/plugins/pluginUtils/src/org/adempiere/plugin/utils/AdempiereActivator.java @@ -0,0 +1,103 @@ +package org.adempiere.plugin.utils; + +import java.io.InputStream; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.adempiere.base.IDictionaryService; +import org.adempiere.base.Service; +import org.compiere.model.Query; +import org.compiere.model.X_AD_Package_Imp; +import org.compiere.model.X_AD_Package_Imp_Inst; +import org.compiere.util.Env; +import org.compiere.util.Trx; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class AdempiereActivator implements BundleActivator { + + private final static Logger logger = Logger + .getLogger(AdempiereActivator.class.getName()); + private BundleContext context; + + @Override + public void start(BundleContext context) throws Exception { + this.context = context; + logger.info(getName() + " " + getVersion() + " starting..."); + installPackage(); + start(); + logger.info(getName() + " " + getVersion() + " ready."); + } + + public String getName() { + return context.getBundle().getSymbolicName(); + } + + public String getVersion() { + return (String) context.getBundle().getHeaders().get("Bundle-Version"); + } + + public String getDescription() { + return getName(); + } + + private void installPackage() { + String trxName = Trx.createTrxName(); + String where = "Name=? AND PK_Version=?"; + Query q = new Query(Env.getCtx(), X_AD_Package_Imp.Table_Name, + where.toString(), trxName); + q.setParameters(new Object[] { getName(), getVersion() }); + X_AD_Package_Imp pkg = q.first(); + if (pkg == null) { + packIn(trxName); + install(); + logger.info(getName() + " " + getVersion() + " installed."); + } else { + logger.info(getName() + " " + getVersion() + " was installed: " + + pkg.getCreated()); + } + Trx.get(trxName, false).commit(); + } + + protected void packIn(String trxName) { + InputStream packout = this.getClass().getResourceAsStream( + "/META-INF/PackOut.xml"); + if (packout != null) { + IDictionaryService service = Service.locate(IDictionaryService.class); + try { + service.merge(packout); + } catch (Exception e) { + logger.log(Level.WARNING, "Error on Dictionary service", e); + } + } + X_AD_Package_Imp pkg = new X_AD_Package_Imp(Env.getCtx(), + 0, trxName); + pkg.setName(getName()); + pkg.setPK_Version(getVersion()); + pkg.setPK_Status("Installed."); + pkg.setDescription(getDescription()); + pkg.save(trxName); + } + + protected BundleContext getContext() { + return context; + } + + @Override + public void stop(BundleContext context) throws Exception { + stop(); + logger.info(context.getBundle().getSymbolicName() + " " + + context.getBundle().getHeaders().get("Bundle-Version") + + " stopped."); + } + + protected void install() { + }; + + protected void start() { + }; + + protected void stop() { + }; + +}