OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Rev 156 | 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
 
16
import org.openconcerto.erp.config.Gestion;
73 ilm 17
import org.openconcerto.erp.modules.ModulePackager.ModuleFiles;
25 ilm 18
import org.openconcerto.utils.FileUtils;
19
 
20
import java.io.File;
21
import java.io.IOException;
22
 
23
/**
24
 * Package a module from a project and launch it. The system property {@link #MODULE_DIR_PROP} must
25
 * be defined.
26
 *
27
 * @author Sylvain CUAZ
28
 * @see ModulePackager
29
 */
30
public class ModuleLauncher {
31
    /**
32
     * Required system property, it must point to a directory with module classes in bin/, this
33
     * class will put the packaged module in the dist/ subdirectory.
34
     */
35
    public static final String MODULE_DIR_PROP = "module.dir";
36
    /**
37
     * System property to use if the module properties files isn't "module.properties" (this
38
     * property is evaluated relative to {@link #MODULE_DIR_PROP}).
39
     */
40
    public static final String MODULE_PROPS_FILE_PROP = "module.propsFile";
41
 
73 ilm 42
    static ModuleFiles createModuleFiles(String moduleDirPath) throws IOException {
43
        return new ModuleFiles(new File(moduleDirPath), System.getProperty(MODULE_PROPS_FILE_PROP));
44
    }
45
 
25 ilm 46
    public static void main(String[] args) throws IOException {
73 ilm 47
        final ModuleFiles moduleFiles = createModuleFiles(System.getProperty(MODULE_DIR_PROP));
25 ilm 48
        final boolean launchFromPackage = !Boolean.getBoolean("module.fromProject");
49
 
50
        // always update dist/ to avoid out of date problems
73 ilm 51
        final File jar = ModulePackager.createDist(moduleFiles);
25 ilm 52
        // to avoid out of date modules from OpenConcerto (e.g. when launching this module, the jars
53
        // of MODULES_DIR are used for dependencies)
41 ilm 54
        FileUtils.mkdir_p(Gestion.MODULES_DIR);
25 ilm 55
        FileUtils.copyFile(jar, new File(Gestion.MODULES_DIR, jar.getName()));
56
 
80 ilm 57
        final PropsModuleFactory factory;
25 ilm 58
        if (launchFromPackage) {
59
            factory = new JarModuleFactory(jar);
60
        } else {
73 ilm 61
            factory = new RuntimeModuleFactory(moduleFiles.getPropertiesFile());
25 ilm 62
            try {
63
                Class.forName(factory.getMainClass());
64
            } catch (ClassNotFoundException e) {
73 ilm 65
                throw new IllegalStateException("Module classes are not in the classpath (they should be in " + moduleFiles.getClassesDir() + ")", e);
25 ilm 66
            }
67
        }
68
 
69
        Gestion.main(args);
70
        // add after main() otherwise we could be overwritten by an older jar
71
        ModuleManager.getInstance().addFactoryAndStart(factory, false);
72
    }
73
}