OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
25 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.modules;
15
 
156 ilm 16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
25 ilm 17
import org.openconcerto.erp.config.Gestion;
73 ilm 18
import org.openconcerto.erp.modules.ModulePackager.ModuleFiles;
25 ilm 19
import org.openconcerto.utils.FileUtils;
20
 
21
import java.io.File;
22
import java.io.IOException;
23
 
24
/**
25
 * Package a module from a project and launch it. The system property {@link #MODULE_DIR_PROP} must
26
 * be defined.
27
 *
28
 * @author Sylvain CUAZ
29
 * @see ModulePackager
30
 */
31
public class ModuleLauncher {
32
    /**
33
     * Required system property, it must point to a directory with module classes in bin/, this
34
     * class will put the packaged module in the dist/ subdirectory.
35
     */
36
    public static final String MODULE_DIR_PROP = "module.dir";
37
    /**
38
     * System property to use if the module properties files isn't "module.properties" (this
39
     * property is evaluated relative to {@link #MODULE_DIR_PROP}).
40
     */
41
    public static final String MODULE_PROPS_FILE_PROP = "module.propsFile";
42
 
73 ilm 43
    static ModuleFiles createModuleFiles(String moduleDirPath) throws IOException {
44
        return new ModuleFiles(new File(moduleDirPath), System.getProperty(MODULE_PROPS_FILE_PROP));
45
    }
46
 
25 ilm 47
    public static void main(String[] args) throws IOException {
73 ilm 48
        final ModuleFiles moduleFiles = createModuleFiles(System.getProperty(MODULE_DIR_PROP));
25 ilm 49
        final boolean launchFromPackage = !Boolean.getBoolean("module.fromProject");
50
 
51
        // always update dist/ to avoid out of date problems
73 ilm 52
        final File jar = ModulePackager.createDist(moduleFiles);
25 ilm 53
        // to avoid out of date modules from OpenConcerto (e.g. when launching this module, the jars
54
        // of MODULES_DIR are used for dependencies)
41 ilm 55
        FileUtils.mkdir_p(Gestion.MODULES_DIR);
25 ilm 56
        FileUtils.copyFile(jar, new File(Gestion.MODULES_DIR, jar.getName()));
57
 
80 ilm 58
        final PropsModuleFactory factory;
25 ilm 59
        if (launchFromPackage) {
60
            factory = new JarModuleFactory(jar);
61
        } else {
73 ilm 62
            factory = new RuntimeModuleFactory(moduleFiles.getPropertiesFile());
25 ilm 63
            try {
64
                Class.forName(factory.getMainClass());
65
            } catch (ClassNotFoundException e) {
73 ilm 66
                throw new IllegalStateException("Module classes are not in the classpath (they should be in " + moduleFiles.getClassesDir() + ")", e);
25 ilm 67
            }
68
        }
69
 
70
        Gestion.main(args);
71
        // add after main() otherwise we could be overwritten by an older jar
156 ilm 72
        ComptaPropsConfiguration.getInstanceCompta().getModuleManager().addFactoryAndStart(factory, false);
25 ilm 73
    }
74
}