OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
Line 14... Line 14...
14
 package org.openconcerto.erp.modules;
14
 package org.openconcerto.erp.modules;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.config.Gestion;
17
import org.openconcerto.erp.config.Gestion;
18
import org.openconcerto.erp.modules.ModulePackager.ModuleFiles;
18
import org.openconcerto.erp.modules.ModulePackager.ModuleFiles;
19
import org.openconcerto.utils.FileUtils;
19
import org.openconcerto.utils.BaseDirs;
20
 
20
 
21
import java.io.File;
21
import java.io.File;
22
import java.io.IOException;
22
import java.io.IOException;
-
 
23
import java.nio.file.Files;
-
 
24
import java.nio.file.StandardCopyOption;
23
 
25
 
24
/**
26
/**
25
 * Package a module from a project and launch it. The system property {@link #MODULE_DIR_PROP} must
27
 * Package a module from a project and launch it. The system property {@link #MODULE_DIR_PROP} must
26
 * be defined.
28
 * be defined.
27
 * 
29
 * 
Line 48... Line 50...
48
        final ModuleFiles moduleFiles = createModuleFiles(System.getProperty(MODULE_DIR_PROP));
50
        final ModuleFiles moduleFiles = createModuleFiles(System.getProperty(MODULE_DIR_PROP));
49
        final boolean launchFromPackage = !Boolean.getBoolean("module.fromProject");
51
        final boolean launchFromPackage = !Boolean.getBoolean("module.fromProject");
50
 
52
 
51
        // always update dist/ to avoid out of date problems
53
        // always update dist/ to avoid out of date problems
52
        final File jar = ModulePackager.createDist(moduleFiles);
54
        final File jar = ModulePackager.createDist(moduleFiles);
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)
-
 
55
        FileUtils.mkdir_p(Gestion.MODULES_DIR);
-
 
56
        FileUtils.copyFile(jar, new File(Gestion.MODULES_DIR, jar.getName()));
-
 
57
 
55
 
58
        final PropsModuleFactory factory;
56
        final PropsModuleFactory factory;
59
        if (launchFromPackage) {
57
        if (launchFromPackage) {
60
            factory = new JarModuleFactory(jar);
58
            factory = new JarModuleFactory(jar);
61
        } else {
59
        } else {
Line 66... Line 64...
66
                throw new IllegalStateException("Module classes are not in the classpath (they should be in " + moduleFiles.getClassesDir() + ")", e);
64
                throw new IllegalStateException("Module classes are not in the classpath (they should be in " + moduleFiles.getClassesDir() + ")", e);
67
            }
65
            }
68
        }
66
        }
69
 
67
 
70
        Gestion.main(args);
68
        Gestion.main(args);
-
 
69
 
-
 
70
        final ModuleManager moduleManager = ComptaPropsConfiguration.getInstanceCompta().getModuleManager();
-
 
71
        // to avoid out of date modules from OpenConcerto (e.g. when launching this module, the jars
-
 
72
        // of MODULES_DIR are used for dependencies)
-
 
73
        final File modulesDir = BaseDirs.getFolderToWrite(moduleManager.getFolders().get(0));
-
 
74
        Files.copy(jar.toPath(), modulesDir.toPath().resolve(jar.getName()), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
-
 
75
 
71
        // add after main() otherwise we could be overwritten by an older jar
76
        // add after main() otherwise we could be overwritten by an older jar
72
        ComptaPropsConfiguration.getInstanceCompta().getModuleManager().addFactoryAndStart(factory, false);
77
        moduleManager.addFactoryAndStart(factory, false);
73
    }
78
    }
74
}
79
}