IDEMPIERE-3043: fix for bundle install after framework complete run

remove duplicate code, call install 2pack when IDictionaryService exists
This commit is contained in:
hieplq 2019-11-11 16:01:57 +07:00
parent 42b22108e9
commit 0a6ea1a3e5
5 changed files with 58 additions and 212 deletions

View File

@ -36,6 +36,7 @@ import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
@ -50,6 +51,30 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack
private IProcessUI m_processUI = null;
public static boolean isFrameworkCompletedSrart = false;
@Override
public void start(BundleContext context) throws Exception {
this.context = context;
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " starting...");
serviceTracker = new ServiceTracker<IDictionaryService, IDictionaryService>(context, IDictionaryService.class.getName(), this);
serviceTracker.open();
if (!isFrameworkCompletedSrart)
context.addFrameworkListener(this);
start();
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " ready.");
}
@Override
public void stop(BundleContext context) throws Exception {
stop();
serviceTracker.close();
context.removeFrameworkListener(this);
this.context = null;
if (logger.isLoggable(Level.INFO)) logger.info(context.getBundle().getSymbolicName() + " "
+ context.getBundle().getHeaders().get("Bundle-Version")
+ " stopped.");
}
protected boolean merge(File zipfile, String version) throws Exception {
boolean success = false;
@ -197,13 +222,39 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack
}
protected abstract void frameworkStarted();
/**
* call when bundle have been started ( after this.context have been set )
*/
protected void start() {
};
/**
* call when bundle is stop ( before this.context is set to null )
*/
protected void stop() {
}
protected void registryRunPackin() {
if (isFrameworkCompletedSrart) {
public String getVersion() {
return "";
}
@Override
public IDictionaryService addingService(
ServiceReference<IDictionaryService> reference) {
service = context.getService(reference);
if (isFrameworkCompletedSrart)
frameworkStarted ();
}else {
context.addFrameworkListener(this);
}
return null;
}
@Override
public void modifiedService(ServiceReference<IDictionaryService> reference,
IDictionaryService service) {
}
@Override
public void removedService(ServiceReference<IDictionaryService> reference,
IDictionaryService service) {
}
}

View File

@ -7,7 +7,6 @@ import java.net.URL;
import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.base.IDictionaryService;
import org.adempiere.util.ServerContext;
import org.compiere.Adempiere;
import org.compiere.model.MSession;
@ -20,28 +19,16 @@ import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
public class AdempiereActivator extends AbstractActivator {
protected final static CLogger logger = CLogger.getCLogger(AdempiereActivator.class.getName());
@Override
public void start(BundleContext context) throws Exception {
this.context = context;
registryRunPackin ();
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " starting...");
serviceTracker = new ServiceTracker<IDictionaryService, IDictionaryService>(context, IDictionaryService.class.getName(), this);
serviceTracker.open();
start();
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " ready.");
}
public String getName() {
return context.getBundle().getSymbolicName();
}
@Override
public String getVersion() {
return (String) context.getBundle().getHeaders().get("Bundle-Version");
}
@ -143,44 +130,10 @@ public class AdempiereActivator extends AbstractActivator {
protected void setContext(BundleContext context) {
this.context = context;
}
@Override
public void stop(BundleContext context) throws Exception {
stop();
serviceTracker.close();
context.removeFrameworkListener(this);
this.context = null;
if (logger.isLoggable(Level.INFO)) logger.info(context.getBundle().getSymbolicName() + " "
+ context.getBundle().getHeaders().get("Bundle-Version")
+ " stopped.");
}
protected void install() {
};
protected void start() {
};
protected void stop() {
}
@Override
public IDictionaryService addingService(
ServiceReference<IDictionaryService> reference) {
service = context.getService(reference);
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.setProperty("#AD_Client_ID", "0");

View File

@ -25,7 +25,6 @@ import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.base.IDictionaryService;
import org.adempiere.util.ServerContext;
import org.compiere.Adempiere;
import org.compiere.model.MSession;
@ -38,8 +37,6 @@ import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Trx;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
/**
*
@ -50,21 +47,11 @@ public class Incremental2PackActivator extends AbstractActivator {
protected final static CLogger logger = CLogger.getCLogger(Incremental2PackActivator.class.getName());
@Override
public void start(BundleContext context) throws Exception {
this.context = context;
registryRunPackin ();
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " starting...");
serviceTracker = new ServiceTracker<IDictionaryService, IDictionaryService>(context, IDictionaryService.class.getName(), this);
serviceTracker.open();
start();
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " ready.");
}
public String getName() {
return context.getBundle().getSymbolicName();
}
@Override
public String getVersion() {
String version = (String) context.getBundle().getHeaders().get("Bundle-Version");
// e.g. 1.0.0.qualifier, check only the "1.0.0" part
@ -261,50 +248,10 @@ public class Incremental2PackActivator extends AbstractActivator {
protected void setContext(BundleContext context) {
this.context = context;
}
@Override
public void stop(BundleContext context) throws Exception {
stop();
serviceTracker.close();
context.removeFrameworkListener(this);
this.context = null;
if (logger.isLoggable(Level.INFO)) logger.info(context.getBundle().getSymbolicName() + " "
+ context.getBundle().getHeaders().get("Bundle-Version")
+ " stopped.");
}
protected void afterPackIn() {
};
/**
* call when bundle have been started ( after this.context have been set )
*/
protected void start() {
};
/**
* call when bundle is stop ( before this.context is set to null )
*/
protected void stop() {
}
@Override
public IDictionaryService addingService(
ServiceReference<IDictionaryService> reference) {
service = context.getService(reference);
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.setProperty("#AD_Client_ID", "0");

View File

@ -41,57 +41,14 @@ import org.compiere.util.AdempiereSystemError;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Util;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
public class PackInApplicationActivator extends AbstractActivator{
protected final static CLogger logger = CLogger.getCLogger(PackInApplicationActivator.class.getName());
private List<File> filesToProcess = new ArrayList<>();
private File currentFile;
@Override
public void start(BundleContext context) throws Exception {
this.context = context;
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " starting...");
context.addFrameworkListener(this);
serviceTracker = new ServiceTracker<IDictionaryService, IDictionaryService>(context, IDictionaryService.class.getName(), this);
serviceTracker.open();
start();
if (logger.isLoggable(Level.INFO))
logger.info(getName() + " ready.");
}
/**
* call when bundle have been started ( after this.context have been set )
*/
protected void start() {
};
/**
* call when bundle is stop ( before this.context is set to null )
*/
protected void stop() {
}
@Override
public void stop(BundleContext context) throws Exception {
stop();
serviceTracker.close();
context.removeFrameworkListener(this);
this.context = null;
if (logger.isLoggable(Level.INFO)) logger.info(context.getBundle().getSymbolicName() + " "
+ context.getBundle().getHeaders().get("Bundle-Version")
+ " stopped.");
}
@Override
public IDictionaryService addingService(ServiceReference<IDictionaryService> reference) {
service = context.getService(reference);
return null;
}
public void automaticPackin(int timeout, String folders, boolean fromService) {
if (fromService) {
//Initial delay - starting from service
@ -369,14 +326,6 @@ public class PackInApplicationActivator extends AbstractActivator{
.setOnlyActiveRecords(true);
return q.getIDs();
}
@Override
public void modifiedService(ServiceReference<IDictionaryService> reference, IDictionaryService service) {
}
@Override
public void removedService(ServiceReference<IDictionaryService> reference, IDictionaryService service) {
}
@Override
public String getName() {

View File

@ -25,7 +25,6 @@ import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.base.IDictionaryService;
import org.adempiere.util.ServerContext;
import org.compiere.Adempiere;
import org.compiere.model.MSession;
@ -38,8 +37,6 @@ import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Util;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
/**
*
@ -50,17 +47,6 @@ public class Version2PackActivator extends AbstractActivator{
protected final static CLogger logger = CLogger.getCLogger(Version2PackActivator.class.getName());
@Override
public void start(BundleContext context) throws Exception {
this.context = context;
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " starting...");
context.addFrameworkListener(this);
serviceTracker = new ServiceTracker<IDictionaryService, IDictionaryService>(context, IDictionaryService.class.getName(), this);
serviceTracker.open();
start();
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " ready.");
}
public String getName() {
return context.getBundle().getSymbolicName();
}
@ -230,49 +216,9 @@ public class Version2PackActivator extends AbstractActivator{
this.context = context;
}
@Override
public void stop(BundleContext context) throws Exception {
stop();
serviceTracker.close();
context.removeFrameworkListener(this);
this.context = null;
if (logger.isLoggable(Level.INFO)) logger.info(context.getBundle().getSymbolicName() + " "
+ context.getBundle().getHeaders().get("Bundle-Version")
+ " stopped.");
}
protected void afterPackIn() {
};
/**
* call when bundle have been started ( after this.context have been set )
*/
protected void start() {
};
/**
* call when bundle is stop ( before this.context is set to null )
*/
protected void stop() {
}
@Override
public IDictionaryService addingService(
ServiceReference<IDictionaryService> reference) {
service = context.getService(reference);
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.setProperty("#AD_Client_ID", "0");