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