import fr.gouv.finances.dgfip.xemelios.data.DataLayerManager;
import fr.gouv.finances.dgfip.xemelios.importers.EtatImporteur;
import fr.gouv.finances.cp.xemelios.importers.ImportServiceSwingProvider;
-import fr.gouv.finances.cp.xemelios.starter.Bootstrap;
import fr.gouv.finances.cp.xemelios.ui.admin.DlgSystemConfiguration;
import fr.gouv.finances.cp.xemelios.ui.collectivites.DlgSelectNavigationTarget;
import fr.gouv.finances.cp.xemelios.ui.firststart.PnlFirstAbo;
import fr.gouv.finances.cp.xemelios.updater.GeneratorHelpIndex;
import fr.gouv.finances.cp.xemelios.updater.PnlUpdaterProgress;
import fr.gouv.finances.cp.xemelios.updater.UpdateUtil;
+import fr.gouv.finances.cp.xemelios.updater.installed.InstalledModel;
+import fr.gouv.finances.cp.xemelios.updater.profils.ComponentModel;
import fr.gouv.finances.dgfip.utils.ClassPathUtils;
import fr.gouv.finances.dgfip.utils.IoUtils;
import fr.gouv.finances.dgfip.utils.xml.FactoryProvider;
import java.io.FilenameFilter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.sql.Connection;
import org.netbeans.spi.wizard.Wizard;
import org.netbeans.spi.wizard.WizardPage;
import org.w3c.dom.NodeList;
+import org.xeustechnologies.jcl.JarClassLoader;
/**
* Main Xemelios window
} else if (fc.getSelectedFile() != null && fc.getSelectedFile().isDirectory()) {
// si l'utilisateur a choisi un r?ertoire
logger.debug("path=" + fc.getSelectedFile().getAbsolutePath());
- // on cr? le mod?e de donn?s pour l'affichage dans la boite de dialogue d'import
+ // on crée le modèle de données pour l'affichage dans la boite de dialogue d'import
String[] extensions = {"xml", "zip", extension};
// on affiche les fichiers trouvés dans les répertoires à l'utilisateur, pour
for (Iterator iter = resultats.iterator(); iter.hasNext();) {
ret[counter++] = ((ImportFile) iter.next()).getFile();
}
- lastInputDirectory = fc.getSelectedFile();
+ lastInputDirectory = fc.getSelectedFile().getParentFile()!=null ? fc.getSelectedFile().getParentFile() : fc.getSelectedFile();
} else {
- // l'utilisateur n'a rien choisi, appuy?sur "Annuler"
+ // l'utilisateur n'a rien choisi, appuyé sur "Annuler"
ret = new File[0];
}
// on regarde si l'un des fichiers a importer est un zip
currentDirectory = applicationProperties.replace(currentDirectory);
File dir = new File(currentDirectory);
if (dir.exists() && dir.isDirectory()) {
+ String installedFileLocation = applicationProperties.getProperty(Constants.SYS_PROP_INSTALLED_FILENAME);
+ InstalledModel installedComponents = new InstalledModel(InstalledModel.QN);
+ try {
+ installedComponents = InstalledModel.readFromFile(installedFileLocation);
+ } catch(Exception ex) {
+ logger.error("unable to find "+installedFileLocation);
+ }
File[] jars = dir.listFiles(new java.io.FileFilter() {
@Override
});
for (File jar : jars) {
try {
+ logger.debug("looking into "+jar.toURI().toURL().toExternalForm());
JarFile jf = new JarFile(jar);
Manifest mn = jf.getManifest();
- System.out.println("***************************************************************************");
+// System.out.println("***************************************************************************");
String toolClassName = mn.getMainAttributes().getValue(ToolConstants.TOOL_CLASS);
- System.out.println(toolClassName);
+// System.out.println(toolClassName);
String toolRequires = mn.getMainAttributes().getValue(ToolConstants.TOOL_REQUIRES);
String toolDescription = null;
String toolIcon = mn.getMainAttributes().getValue(ToolConstants.TOOL_ICON);
jf.close();
if (toolClassName != null && toolClassName.length() > 0) {
try {
- /*if (toolRequires != null && toolRequires.length() > 3) {
- String[] requiredComps = toolRequires.split(";");
+ if (toolRequires != null && toolRequires.length() > 3) {
+ String[] requiredComps = toolRequires.split(",");
for (String comp : requiredComps) {
- String[] compDetails = comp.split(",");
+ String[] compDetails = comp.split("#");
if (compDetails.length == 2) {
- fr.gouv.finances.dgfip.xemelios.common.components.ComponentModel installedComp = components.getComponent(compDetails[0]);
- if (installedComp == null) {
+ ComponentModel existingComponent = installedComponents.getComponent(compDetails[0]);
+ if (existingComponent == null) {
throw new Exception("Component " + compDetails[0] + " (" + compDetails[1] + ") required");
}
- if (!installedComp.isNewerOrEqualThan(compDetails[1])) {
- throw new Exception(installedComp.getId() + " " + installedComp.getVersion() + ") to old: " + compDetails[1] + " required");
+ if (!existingComponent.isNewerOrEqualThan(compDetails[1])) {
+ throw new Exception(existingComponent.getUri() + "#" + existingComponent.getVersion() + ") to old: " + compDetails[1] + " required");
}
}
}
- }*/
- // tout est OK, on ajoute le jar au classpath
+ }
+ // tout est OK, on crée un ClassLoader pour cet outil
+ ClassLoader classLoader = null;
if (!"true".equals(applicationProperties.getProperty(Constants.SYS_PROP_XEMELIOS_AVOID_TOOL_JAR_LOADING))) {
logger.debug(jar.toURI().toURL().toExternalForm());
- Bootstrap.addFile(jar);
+ // on met un JarClassLoader pour ne pas verrouiller le fichier, qui n'est en fait pas utilisé pour le moment...
+ classLoader = new JarClassLoader();
+ ((JarClassLoader)classLoader).add(jar.toURI().toURL());
+ } else {
+ classLoader = this.getClass().getClassLoader();
}
Class clazz = null;
try {
- clazz = Class.forName(toolClassName);
+ clazz = Class.forName(toolClassName, true, classLoader);
+ Class menuTitleClass = Class.forName(MenuTitle.class.getName(),true,classLoader);
@SuppressWarnings("unchecked")
- MenuTitle mt = (MenuTitle) clazz.getAnnotation(MenuTitle.class);
+ Object mt = clazz.getAnnotation(menuTitleClass);
if (mt != null) {
- toolDescription = mt.value();
+ toolDescription = menuTitleClass.getMethod("value").invoke(mt).toString();
} else {
logger.error("Plugin Class " + toolClassName + " doesn't provide annotation @MenuTitle");
}
if (toolDescription != null && toolDescription.length() > 0) {
Action a = null;
if (toolIcon != null) {
- ImageIcon img = IhmFactory.getIconFromResource(toolIcon);
+ ImageIcon img = IhmFactory.getIconFromResource(toolIcon, classLoader);
if (img != null) {
- a = new ActionPlugin(toolClassName, toolDescription, img);
+ a = new ActionPlugin(jar.toURI().toURL(), toolClassName, toolDescription, img);
} else {
- a = new ActionPlugin(toolClassName, toolDescription);
+ a = new ActionPlugin(jar.toURI().toURL(), toolClassName, toolDescription);
}
} else {
- a = new ActionPlugin(toolClassName, toolDescription);
+ a = new ActionPlugin(jar.toURI().toURL(), toolClassName, toolDescription);
}
JMenuItem mnuItem = new JMenuItem(a);
ret.add(mnuItem);
private static final long serialVersionUID = 1L;
private String className = null;
+ private URL jarUrl;
- public ActionPlugin(String className, String desc) {
+ public ActionPlugin(URL jarUrl, String className, String desc) {
super(desc);
+ this.jarUrl=jarUrl;
this.className = className;
}
- public ActionPlugin(String className, String desc, Icon icon) {
+ public ActionPlugin(URL jarUrl, String className, String desc, Icon icon) {
super(desc, icon);
+ this.jarUrl = jarUrl;
this.className = className;
}
@Override
public void actionPerformed(ActionEvent e) {
try {
- Class clazz = Class.forName(className);
- Object o = clazz.newInstance();
- if (o instanceof AbstractTool) {
- AbstractTool at = (AbstractTool) o;
- at.run();
+// URLClassLoader cl = new URLClassLoader(new URL[] {jarUrl},this.getClass().getClassLoader());
+ ClassLoader cl = null;
+ if(!"true".equals(applicationProperties.getProperty(Constants.SYS_PROP_XEMELIOS_AVOID_TOOL_JAR_LOADING))) {
+// cl = new ToolClassLoader(getClass().getClassLoader(), jarUrl);
+ cl = new URLClassLoader(new URL[] { jarUrl }, this.getClass().getClassLoader());
+ } else {
+ cl = this.getClass().getClassLoader();
+ }
+ // TODO: autoriser l'accès aux classes du classloader parent
+ Class clazz = Class.forName(className, true, cl);
+ Class abstractToolClass = Class.forName(AbstractTool.class.getName(), true, cl);
+ final Object o = clazz.newInstance();
+ if (abstractToolClass.isAssignableFrom(clazz)) {
+// AbstractTool at = (AbstractTool) o;
+// at.run();
+ final Method meth = clazz.getMethod("run");
+ Runnable runner = new Runnable() {
+ @Override
+ public void run() {
+ try {
+ meth.invoke(o);
+ } catch(Throwable t) {
+ logger.error(t.getMessage(), t);
+ }
+ }
+ };
+ Thread th = new Thread(runner);
+ th.setContextClassLoader(cl);
+ th.run();
} else {
throw new Exception(className + " does not extends " + AbstractTool.class.getName());
}