Skip to content

Commit a5b9eeb

Browse files
committed
Fixed plugins initialization
1 parent d79f461 commit a5b9eeb

File tree

4 files changed

+44
-32
lines changed

4 files changed

+44
-32
lines changed

logicaldoc-core/src/main/java/com/logicaldoc/core/CorePlugin.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ protected void onStart() throws PluginException {
4141
File dest = new File(getPluginPath());
4242
dest = dest.getParentFile().getParentFile().getParentFile();
4343
dest = new File(dest.getAbsolutePath() + "/frontend/sc/skins/Tahoe/images/FileIcons");
44-
for (File icon : dest.listFiles((File dir, String name) -> name.endsWith(".svg")))
45-
IconSelector.getAvailableIcons().add(FilenameUtils.getBaseName(icon.getName().toLowerCase()));
44+
File[] icons = dest.listFiles((File dir, String name) -> name.endsWith(".svg"));
45+
if (icons != null)
46+
for (File icon : icons)
47+
IconSelector.getAvailableIcons().add(FilenameUtils.getBaseName(icon.getName().toLowerCase()));
4648
}
4749

4850
@Override

logicaldoc-util/src/main/java/com/logicaldoc/util/junit/AbstractTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.context.support.ClassPathXmlApplicationContext;
2929
import org.springframework.util.CollectionUtils;
3030

31+
import com.logicaldoc.util.config.ContextProperties;
3132
import com.logicaldoc.util.io.FileUtil;
3233
import com.logicaldoc.util.plugin.PluginException;
3334
import com.logicaldoc.util.plugin.PluginRegistry;
@@ -114,7 +115,7 @@ protected void initializePlugins() throws IOException, PluginException {
114115
if (CollectionUtils.isEmpty(pluginArchives))
115116
return;
116117

117-
File pluginsDir = new File("target/tests-plugins");
118+
File pluginsDir = new File(new ContextProperties().getProperty("conf.plugindir","target/tests-plugins"));
118119
pluginsDir.mkdir();
119120

120121
for (String pluginArchive : pluginArchives) {

logicaldoc-util/src/main/java/com/logicaldoc/util/plugin/DefaultPluginRegistry.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.util.Set;
66

77
import org.java.plugin.Plugin;
8-
import org.java.plugin.PluginLifecycleException;
98
import org.java.plugin.registry.Identity;
109
import org.java.plugin.registry.PluginDescriptor;
1110
import org.slf4j.Logger;
@@ -22,7 +21,7 @@ public class DefaultPluginRegistry extends PluginRegistry {
2221

2322
protected void initPlugins(Map<String, Identity> plugins) {
2423
Logger console = LoggerFactory.getLogger("console");
25-
console.info("Intialising plugins");
24+
console.info("Intializing plugins");
2625
Set<String> keys = plugins.keySet();
2726
Iterator<String> iterator = keys.iterator();
2827
while (iterator.hasNext()) {
@@ -33,21 +32,15 @@ protected void initPlugins(Map<String, Identity> plugins) {
3332
console.info("plugin located: {} @ {}", pluginDescriptor.getId(), pluginDescriptor.getLocation());
3433

3534
try {
36-
Plugin plugin = manager.getPlugin(pluginDescriptor.getId());
35+
console.info("Intializing plugin: {} located in {}", pluginDescriptor.getId(),
36+
pluginDescriptor.getLocation());
3737

38-
console.info("Intialising plugin: {}", plugin.getDescriptor());
39-
console.info("plugin located: {}", plugin.getDescriptor().getLocation());
38+
manager.activatePlugin(pluginDescriptor.getId());
4039

41-
manager.activatePlugin(plugin.getDescriptor().getId());
40+
Plugin plugin = manager.getPlugin(pluginDescriptor.getId());
4241
console.info("Activated plugin {}", plugin.getDescriptor().getId());
43-
} catch (SecurityException e) {
44-
console.error("PluginRegistry -> SecurityException: {}", e.getMessage());
45-
} catch (IllegalArgumentException e) {
46-
console.error("PluginRegistry -> IllegalArgumentException: {}", e.getMessage());
47-
} catch (PluginLifecycleException e) {
48-
console.error("PluginRegistry -> PluginLifecycleException: {}", e.getMessage());
4942
} catch (Exception e) {
50-
console.error("PluginRegistry -> Error: {}", e.getMessage());
43+
console.error(e.getMessage(), e);
5144
}
5245
}
5346
}

logicaldoc-util/src/main/java/com/logicaldoc/util/plugin/LogicalDOCPlugin.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -230,38 +230,45 @@ protected void addScheduling(String taskName) {
230230
pbean.write();
231231
} catch (IOException e) {
232232
logger.warn("Cannot add task {} to the configuration", taskName);
233+
logger.warn(e.getMessage(), e);
233234
}
234235
}
235236

236237
/**
237238
* Utility method to add a new appender into the log configuration
238239
*
239-
* @param logger name of the logger
240+
* @param name name of the logger
240241
* @param additivity the additivity flag
241242
* @param level the log level
242243
* @param appender name of the appender
243244
*/
244-
protected void addLogger(String logger, boolean additivity, String level, String appender) {
245-
// Add notifier log issues
246-
LogConfigurator logging = new LogConfigurator();
247-
logging.addTextAppender(appender);
248-
logging.write();
249-
250-
String appenderWeb = appender + "_WEB";
251-
logging.addHtmlAppender(appenderWeb);
252-
logging.write();
253-
254-
logging.setLogger(logger, additivity, level, List.of(appender, appenderWeb));
255-
logging.write();
245+
protected void addLogger(String name, boolean additivity, String level, String appender) {
246+
try {
247+
// Add notifier log issues
248+
LogConfigurator logging = new LogConfigurator();
249+
logging.addTextAppender(appender);
250+
logging.write();
251+
252+
String appenderWeb = appender + "_WEB";
253+
logging.addHtmlAppender(appenderWeb);
254+
logging.write();
255+
256+
logging.setLogger(name, additivity, level, List.of(appender, appenderWeb));
257+
logging.write();
258+
} catch (Exception e) {
259+
logger.warn("Cannot add logger {}", name);
260+
logger.warn(e.getMessage(), e);
261+
}
256262
}
257263

258264
/**
259265
* Utility method to add a new appender into the log configuration
260266
*
261-
* @param logger name of the logger
267+
* @param name name of the logger
262268
* @param appender name of the appender
263269
*/
264-
protected void addLogger(String logger, String appender) {
270+
protected void addLogger(String name, String appender) {
271+
try {
265272
// Add notifier log issues
266273
LogConfigurator logging = new LogConfigurator();
267274
logging.addTextAppender(appender);
@@ -271,8 +278,12 @@ protected void addLogger(String logger, String appender) {
271278
logging.addHtmlAppender(appenderWeb);
272279
logging.write();
273280

274-
logging.addLogger(logger, List.of(appender, appenderWeb));
281+
logging.addLogger(name, List.of(appender, appenderWeb));
275282
logging.write();
283+
} catch (Exception e) {
284+
logger.warn("Cannot add logger {}", name);
285+
logger.warn(e.getMessage(), e);
286+
}
276287
}
277288

278289
/**
@@ -295,6 +306,7 @@ protected void addServlet(String name, String servletClass, String mapping) {
295306
* @param optional index when loading the servlet on startup
296307
*/
297308
protected void addServlet(String name, String servletClass, String mapping, Integer loadOnStartup) {
309+
try {
298310
File dest = new File(getPluginPath());
299311
dest = dest.getParentFile().getParentFile();
300312
WebConfigurator config = new WebConfigurator(dest.getPath() + "/web.xml");
@@ -308,5 +320,9 @@ protected void addServlet(String name, String servletClass, String mapping, Inte
308320
config.addServletMapping(name, mapping);
309321
config.writeXMLDoc();
310322
}
323+
} catch (Exception e) {
324+
logger.warn("Cannot add servlet {}", name);
325+
logger.warn(e.getMessage(), e);
326+
}
311327
}
312328
}

0 commit comments

Comments
 (0)