IDEMPIERE-734 autostarting plug-ins causes a lot of errors if 2Pack/AdempiereActivator is used.
This commit is contained in:
parent
02260d11f3
commit
7ad7e681c3
|
@ -5,7 +5,10 @@ Bundle-SymbolicName: org.adempiere.plugin.utils
|
||||||
Bundle-Version: 0.0.0.1
|
Bundle-Version: 0.0.0.1
|
||||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||||
Import-Package: org.adempiere.base,
|
Import-Package: org.adempiere.base,
|
||||||
|
org.adempiere.util,
|
||||||
|
org.compiere,
|
||||||
org.compiere.model,
|
org.compiere.model,
|
||||||
org.compiere.util,
|
org.compiere.util,
|
||||||
org.osgi.framework;version="1.5.0"
|
org.osgi.framework;version="1.5.0",
|
||||||
|
org.osgi.util.tracker;version="1.5.0"
|
||||||
Export-Package: org.adempiere.plugin.utils
|
Export-Package: org.adempiere.plugin.utils
|
||||||
|
|
|
@ -4,30 +4,36 @@ import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.adempiere.base.IDictionaryService;
|
import org.adempiere.base.IDictionaryService;
|
||||||
import org.adempiere.base.Service;
|
import org.adempiere.util.ServerContext;
|
||||||
|
import org.compiere.Adempiere;
|
||||||
import org.compiere.model.Query;
|
import org.compiere.model.Query;
|
||||||
import org.compiere.model.X_AD_Package_Imp;
|
import org.compiere.model.X_AD_Package_Imp;
|
||||||
import org.compiere.util.AdempiereSystemError;
|
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.Trx;
|
import org.compiere.util.Trx;
|
||||||
import org.osgi.framework.BundleActivator;
|
import org.osgi.framework.BundleActivator;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.osgi.framework.ServiceReference;
|
||||||
|
import org.osgi.util.tracker.*;
|
||||||
|
|
||||||
public class AdempiereActivator implements BundleActivator {
|
public class AdempiereActivator implements BundleActivator, ServiceTrackerCustomizer<IDictionaryService, IDictionaryService> {
|
||||||
|
|
||||||
protected final static Logger logger = Logger
|
protected final static Logger logger = Logger
|
||||||
.getLogger(AdempiereActivator.class.getName());
|
.getLogger(AdempiereActivator.class.getName());
|
||||||
private BundleContext context;
|
private BundleContext context;
|
||||||
|
private ServiceTracker<IDictionaryService, IDictionaryService> serviceTracker;
|
||||||
|
private IDictionaryService service;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(BundleContext context) throws Exception {
|
public void start(BundleContext context) throws Exception {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " starting...");
|
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " starting...");
|
||||||
installPackage();
|
serviceTracker = new ServiceTracker<IDictionaryService, IDictionaryService>(context, IDictionaryService.class.getName(), this);
|
||||||
|
serviceTracker.open();
|
||||||
start();
|
start();
|
||||||
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " ready.");
|
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " ready.");
|
||||||
}
|
}
|
||||||
|
@ -94,12 +100,9 @@ public class AdempiereActivator implements BundleActivator {
|
||||||
|
|
||||||
protected void packIn(String trxName) {
|
protected void packIn(String trxName) {
|
||||||
URL packout = context.getBundle().getEntry("/META-INF/2Pack.zip");
|
URL packout = context.getBundle().getEntry("/META-INF/2Pack.zip");
|
||||||
if (packout != null) {
|
if (packout != null && service != null) {
|
||||||
IDictionaryService service = Service.locator().locate(IDictionaryService.class).getService();
|
|
||||||
FileOutputStream zipstream = null;
|
FileOutputStream zipstream = null;
|
||||||
try {
|
try {
|
||||||
if (service == null)
|
|
||||||
throw new AdempiereSystemError("Could not find/load OSGi service for packin");
|
|
||||||
// copy the resource to a temporary file to process it with 2pack
|
// copy the resource to a temporary file to process it with 2pack
|
||||||
InputStream stream = context.getBundle().getEntry("/META-INF/2Pack.zip").openStream();
|
InputStream stream = context.getBundle().getEntry("/META-INF/2Pack.zip").openStream();
|
||||||
File zipfile = File.createTempFile(getName(), ".zip");
|
File zipfile = File.createTempFile(getName(), ".zip");
|
||||||
|
@ -135,6 +138,8 @@ public class AdempiereActivator implements BundleActivator {
|
||||||
@Override
|
@Override
|
||||||
public void stop(BundleContext context) throws Exception {
|
public void stop(BundleContext context) throws Exception {
|
||||||
stop();
|
stop();
|
||||||
|
serviceTracker.close();
|
||||||
|
this.context = null;
|
||||||
if (logger.isLoggable(Level.INFO)) logger.info(context.getBundle().getSymbolicName() + " "
|
if (logger.isLoggable(Level.INFO)) logger.info(context.getBundle().getSymbolicName() + " "
|
||||||
+ context.getBundle().getHeaders().get("Bundle-Version")
|
+ context.getBundle().getHeaders().get("Bundle-Version")
|
||||||
+ " stopped.");
|
+ " stopped.");
|
||||||
|
@ -147,5 +152,39 @@ public class AdempiereActivator implements BundleActivator {
|
||||||
};
|
};
|
||||||
|
|
||||||
protected void stop() {
|
protected void stop() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IDictionaryService addingService(
|
||||||
|
ServiceReference<IDictionaryService> reference) {
|
||||||
|
service = context.getService(reference);
|
||||||
|
Adempiere.getThreadPoolExecutor().execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
setupPackInContext();
|
||||||
|
try {
|
||||||
|
installPackage();
|
||||||
|
} finally {
|
||||||
|
ServerContext.dispose();
|
||||||
|
service = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void modifiedService(ServiceReference<IDictionaryService> reference,
|
||||||
|
IDictionaryService service) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removedService(ServiceReference<IDictionaryService> reference,
|
||||||
|
IDictionaryService service) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setupPackInContext() {
|
||||||
|
Properties serverContext = new Properties();
|
||||||
|
ServerContext.setCurrentInstance(serverContext);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue