Plugin Utility Bundle
This commit is contained in:
parent
21d6e6a8a2
commit
72418fa47c
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>pluginUtils</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -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
|
|
@ -0,0 +1,4 @@
|
|||
#Fri Mar 12 08:32:19 CET 2010
|
||||
eclipse.preferences.version=1
|
||||
pluginProject.extensions=false
|
||||
resolve.requirebundle=false
|
|
@ -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
|
|
@ -0,0 +1,4 @@
|
|||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
|
@ -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() {
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue