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 52... |
Line 52... |
52 |
import org.openconcerto.sql.utils.SQLCreateTable;
|
52 |
import org.openconcerto.sql.utils.SQLCreateTable;
|
53 |
import org.openconcerto.sql.utils.SQLUtils;
|
53 |
import org.openconcerto.sql.utils.SQLUtils;
|
54 |
import org.openconcerto.sql.utils.SQLUtils.SQLFactory;
|
54 |
import org.openconcerto.sql.utils.SQLUtils.SQLFactory;
|
55 |
import org.openconcerto.sql.view.list.IListeAction;
|
55 |
import org.openconcerto.sql.view.list.IListeAction;
|
56 |
import org.openconcerto.ui.SwingThreadUtils;
|
56 |
import org.openconcerto.ui.SwingThreadUtils;
|
- |
|
57 |
import org.openconcerto.utils.BaseDirs;
|
57 |
import org.openconcerto.utils.CollectionMap2.Mode;
|
58 |
import org.openconcerto.utils.CollectionMap2.Mode;
|
58 |
import org.openconcerto.utils.CollectionUtils;
|
59 |
import org.openconcerto.utils.CollectionUtils;
|
59 |
import org.openconcerto.utils.ExceptionHandler;
|
60 |
import org.openconcerto.utils.ExceptionHandler;
|
60 |
import org.openconcerto.utils.ExceptionUtils;
|
61 |
import org.openconcerto.utils.ExceptionUtils;
|
61 |
import org.openconcerto.utils.FileUtils;
|
62 |
import org.openconcerto.utils.FileUtils;
|
Line 223... |
Line 224... |
223 |
return res;
|
224 |
return res;
|
224 |
}
|
225 |
}
|
225 |
|
226 |
|
226 |
// final (thus safely published) and thread-safe
|
227 |
// final (thus safely published) and thread-safe
|
227 |
private final FactoriesByID factories;
|
228 |
private final FactoriesByID factories;
|
- |
|
229 |
@GuardedBy("this")
|
- |
|
230 |
private List<File> folders = Collections.emptyList();
|
228 |
// to avoid starting twice the same module
|
231 |
// to avoid starting twice the same module
|
229 |
// we synchronize the whole install/start and stop/uninstall
|
232 |
// we synchronize the whole install/start and stop/uninstall
|
230 |
@GuardedBy("this")
|
233 |
@GuardedBy("this")
|
231 |
private final Map<String, AbstractModule> runningModules;
|
234 |
private final Map<String, AbstractModule> runningModules;
|
232 |
// in fact it is also already guarded by "this"
|
235 |
// in fact it is also already guarded by "this"
|
Line 314... |
Line 317... |
314 |
throw new IllegalArgumentException("Illegal action " + action);
|
317 |
throw new IllegalArgumentException("Illegal action " + action);
|
315 |
}
|
318 |
}
|
316 |
|
319 |
|
317 |
// *** factories (thread-safe)
|
320 |
// *** factories (thread-safe)
|
318 |
|
321 |
|
- |
|
322 |
public final void setFolders(final File... dirs) {
|
- |
|
323 |
this.setFolders(Arrays.asList(dirs));
|
- |
|
324 |
}
|
- |
|
325 |
|
- |
|
326 |
// The system directories should be before the user directories.
|
- |
|
327 |
// This order is important for getFolderToWrite() and allow the user modules to replace the
|
- |
|
328 |
// system ones.
|
- |
|
329 |
public final void setFolders(final List<File> dirs) {
|
- |
|
330 |
final List<File> absolutes = new ArrayList<>(dirs.size());
|
- |
|
331 |
for (final File dir : dirs) {
|
- |
|
332 |
final File abs = dir.getAbsoluteFile();
|
- |
|
333 |
this.addFactories(abs);
|
- |
|
334 |
absolutes.add(abs);
|
- |
|
335 |
}
|
- |
|
336 |
synchronized (this) {
|
- |
|
337 |
this.folders = Collections.unmodifiableList(absolutes);
|
- |
|
338 |
}
|
- |
|
339 |
}
|
- |
|
340 |
|
- |
|
341 |
public synchronized final List<File> getFolders() {
|
- |
|
342 |
return this.folders;
|
- |
|
343 |
}
|
- |
|
344 |
|
- |
|
345 |
public static final File getFolderToWrite(final List<File> dirs) {
|
- |
|
346 |
// Try to install in system directory first, then fall back to user directory.
|
- |
|
347 |
for (final File dir : dirs) {
|
- |
|
348 |
try {
|
- |
|
349 |
return BaseDirs.getFolderToWrite(dir);
|
- |
|
350 |
} catch (IOException e) {
|
- |
|
351 |
// try next one
|
- |
|
352 |
}
|
- |
|
353 |
}
|
- |
|
354 |
return null;
|
- |
|
355 |
}
|
- |
|
356 |
|
319 |
public final int addFactories(final File dir) {
|
357 |
public final int addFactories(final File dir) {
|
320 |
if (!dir.exists()) {
|
358 |
if (!dir.exists()) {
|
321 |
L.warning("Module factory directory not found: " + dir.getAbsolutePath());
|
359 |
L.warning("Module factory directory not found: " + dir.getAbsolutePath());
|
322 |
return 0;
|
360 |
return 0;
|
323 |
}
|
361 |
}
|