• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmrs / openmrs-core / 10290281517

07 Aug 2024 07:08PM CUT coverage: 64.834% (-0.1%) from 64.952%
10290281517

push

github

web-flow
maven(deps): bump org.apache.commons:commons-lang3 from 3.15.0 to 3.16.0 (#4707)

Bumps org.apache.commons:commons-lang3 from 3.15.0 to 3.16.0.

---
updated-dependencies:
- dependency-name: org.apache.commons:commons-lang3
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

22918 of 35349 relevant lines covered (64.83%)

0.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.13
/api/src/main/java/org/openmrs/module/Module.java
1
/**
2
 * This Source Code Form is subject to the terms of the Mozilla Public License,
3
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6
 *
7
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8
 * graphic logo is a trademark of OpenMRS Inc.
9
 */
10
package org.openmrs.module;
11

12
import java.io.File;
13
import java.util.ArrayList;
14
import java.util.HashMap;
15
import java.util.HashSet;
16
import java.util.IdentityHashMap;
17
import java.util.List;
18
import java.util.Map;
19
import java.util.Properties;
20
import java.util.Set;
21

22
import org.apache.commons.lang3.builder.HashCodeBuilder;
23
import org.openmrs.GlobalProperty;
24
import org.openmrs.Privilege;
25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
27
import org.w3c.dom.Document;
28

29
/**
30
 * Generic module class that openmrs manipulates
31
 *
32
 * @version 1.0
33
 */
34
public final class Module {
35
        
36
        private static final Logger log = LoggerFactory.getLogger(Module.class);
1✔
37
        
38
        private String name;
39
        
40
        private String moduleId;
41
        
42
        private String packageName;
43
        
44
        private String description;
45
        
46
        private String author;
47
        
48
        private String version;
49
        
50
        private String updateURL; // should be a URL to an update.rdf file
51
        
52
        private String updateVersion = null; // version obtained from the remote update.rdf file
1✔
53
        
54
        private String downloadURL = null; // will only be populated when the remote file is newer than the current module
1✔
55
        
56
        private ModuleActivator moduleActivator;
57
        
58
        private String activatorName;
59
        
60
        private String requireOpenmrsVersion;
61
        
62
        private String requireDatabaseVersion;
63
        
64
        private Map<String, String> requiredModulesMap;
65
        
66
        private Map<String, String> awareOfModulesMap;
67
        
68
        private Map<String, String> startBeforeModulesMap;
69
        
70
        private List<AdvicePoint> advicePoints = new ArrayList<>();
1✔
71
        
72
        private Map<String, String> extensionNames = new IdentityHashMap<>();
1✔
73
        
74
        private List<Extension> extensions = new ArrayList<>();
1✔
75
        
76
        private Map<String, Properties> messages = new HashMap<>();
1✔
77
        
78
        private List<Privilege> privileges = new ArrayList<>();
1✔
79
        
80
        private List<GlobalProperty> globalProperties = new ArrayList<>();
1✔
81
        
82
        private List<String> mappingFiles = new ArrayList<>();
1✔
83
        
84
        private Set<String> packagesWithMappedClasses = new HashSet<>();
1✔
85
        
86
        private Document config = null;
1✔
87
        
88
        private Document sqldiff = null;
1✔
89
        
90
        private boolean mandatory = Boolean.FALSE;
1✔
91
        
92
        private List<ModuleConditionalResource> conditionalResources = new ArrayList<>();
1✔
93
        
94
        // keep a reference to the file that we got this module from so we can delete
95
        // it if necessary
96
        private File file = null;
1✔
97
        
98
        private String startupErrorMessage = null;
1✔
99
        
100
        /**
101
         * Simple constructor
102
         *
103
         * @param name
104
         */
105
        public Module(String name) {
1✔
106
                this.name = name;
1✔
107
        }
1✔
108
        
109
        /**
110
         * Main constructor
111
         *
112
         * @param name
113
         * @param moduleId
114
         * @param packageName
115
         * @param author
116
         * @param description
117
         * @param version
118
         */
119
        public Module(String name, String moduleId, String packageName, String author, String description, String version) {
1✔
120
                this.name = name;
1✔
121
                this.moduleId = moduleId;
1✔
122
                this.packageName = packageName;
1✔
123
                this.author = author;
1✔
124
                this.description = description;
1✔
125
                this.version = version;
1✔
126
                log.debug("Creating module " + name);
1✔
127
        }
1✔
128
        
129
        @Override
130
        public boolean equals(Object obj) {
131
                if (obj != null && obj instanceof Module) {
1✔
132
                        Module mod = (Module) obj;
1✔
133
                        return getModuleId().equals(mod.getModuleId());
1✔
134
                }
135
                return false;
1✔
136
        }
137
        
138
        @Override
139
        public int hashCode() {
140
                return new HashCodeBuilder().append(getModuleId()).toHashCode();
1✔
141
        }
142
        
143
        /**
144
         * @return the moduleActivator
145
         */
146
        public ModuleActivator getModuleActivator() {
147
                try {
148
                        if (moduleActivator == null) {
1✔
149
                                ModuleClassLoader classLoader = ModuleFactory.getModuleClassLoader(this);
1✔
150
                                if (classLoader == null) {
1✔
151
                                        throw new ModuleException("The classloader is null", getModuleId());
×
152
                                }
153
                                
154
                                Class<?> c = classLoader.loadClass(getActivatorName());
1✔
155
                                Object o = c.newInstance();
1✔
156
                                if (ModuleActivator.class.isAssignableFrom(o.getClass())) {
1✔
157
                                        setModuleActivator((ModuleActivator) o);
1✔
158
                                }
159
                        }
160
                        
161
                }
162
                catch (ClassNotFoundException | NoClassDefFoundError e) {
×
163
                        
164
                        throw new ModuleException("Unable to load/find moduleActivator: '" + getActivatorName() + "'", name, e);
×
165
                }
166
                catch (IllegalAccessException e) {
×
167
                        throw new ModuleException("Unable to load/access moduleActivator: '" + getActivatorName() + "'", name, e);
×
168
                }
169
                catch (InstantiationException e) {
×
170
                        throw new ModuleException("Unable to load/instantiate moduleActivator: '" + getActivatorName() + "'", name, e);
×
171
                }
1✔
172

173
                return moduleActivator;
1✔
174
        }
175
        
176
        /**
177
         * @param moduleActivator the moduleActivator to set
178
         */
179
        public void setModuleActivator(ModuleActivator moduleActivator) {
180
                this.moduleActivator = moduleActivator;
1✔
181
        }
1✔
182
        
183
        /**
184
         * @return the activatorName
185
         */
186
        public String getActivatorName() {
187
                return activatorName;
1✔
188
        }
189
        
190
        /**
191
         * @param activatorName the activatorName to set
192
         */
193
        public void setActivatorName(String activatorName) {
194
                this.activatorName = activatorName;
1✔
195
        }
1✔
196
        
197
        /**
198
         * @return the author
199
         */
200
        public String getAuthor() {
201
                return author;
1✔
202
        }
203
        
204
        /**
205
         * @param author the author to set
206
         */
207
        public void setAuthor(String author) {
208
                this.author = author;
×
209
        }
×
210
        
211
        /**
212
         * @return the description
213
         */
214
        public String getDescription() {
215
                return description;
1✔
216
        }
217
        
218
        /**
219
         * @param description the description to set
220
         */
221
        public void setDescription(String description) {
222
                this.description = description;
×
223
        }
×
224
        
225
        /**
226
         * @return the name
227
         */
228
        public String getName() {
229
                return name;
1✔
230
        }
231
        
232
        /**
233
         * @param name the name to set
234
         */
235
        public void setName(String name) {
236
                this.name = name;
×
237
        }
×
238
        
239
        /**
240
         * @return the requireDatabaseVersion
241
         */
242
        public String getRequireDatabaseVersion() {
243
                return requireDatabaseVersion;
1✔
244
        }
245
        
246
        /**
247
         * @param requireDatabaseVersion the requireDatabaseVersion to set
248
         */
249
        public void setRequireDatabaseVersion(String requireDatabaseVersion) {
250
                this.requireDatabaseVersion = requireDatabaseVersion;
1✔
251
        }
1✔
252
        
253
        /**
254
         * This list of strings is just what is included in the config.xml file, the full package names:
255
         * e.g. org.openmrs.module.formentry
256
         *
257
         * @return the list of requiredModules
258
         */
259
        public List<String> getRequiredModules() {
260
                return requiredModulesMap == null ? null : new ArrayList<>(requiredModulesMap.keySet());
1✔
261
        }
262
        
263
        /**
264
         * Convenience method to get the version of this given module that is required
265
         *
266
         * @return the version of the given required module, or null if there are no version constraints
267
         * @since 1.5
268
         * <strong>Should</strong> return null if no required modules exist
269
         * <strong>Should</strong> return null if no required module by given name exists
270
         */
271
        public String getRequiredModuleVersion(String moduleName) {
272
                return requiredModulesMap == null ? null : requiredModulesMap.get(moduleName);
1✔
273
        }
274
        
275
        /**
276
         * This is a convenience method to set all the required modules without any version requirements
277
         *
278
         * @param requiredModules the requiredModules to set for this module
279
         * <strong>Should</strong> set modules when there is a null required modules map
280
         */
281
        public void setRequiredModules(List<String> requiredModules) {
282
                if (requiredModulesMap == null) {
1✔
283
                        requiredModulesMap = new HashMap<>();
1✔
284
                }
285
                
286
                for (String module : requiredModules) {
1✔
287
                        requiredModulesMap.put(module, null);
1✔
288
                }
1✔
289
        }
1✔
290
        
291
        /**
292
         * @param requiredModule the requiredModule to add for this module
293
         * @param version version requiredModule
294
         * <strong>Should</strong> add module to required modules map
295
         */
296
        public void addRequiredModule(String requiredModule, String version) {
297
                if (requiredModulesMap != null) {
1✔
298
                        requiredModulesMap.put(requiredModule, version);
1✔
299
                }
300
        }
1✔
301
        
302
        /**
303
         * @param requiredModulesMap <code>Map&lt;String,String&gt;</code> of the <code>requiredModule</code>s
304
         *            to set
305
         * @since 1.5
306
         */
307
        public void setRequiredModulesMap(Map<String, String> requiredModulesMap) {
308
                this.requiredModulesMap = requiredModulesMap;
1✔
309
        }
1✔
310
        
311
        /**
312
         * Get the modules that are required for this module. The keys in this map are the module
313
         * package names. The values in the map are the required version. If no specific version is
314
         * required, it will be null.
315
         *
316
         * @return a map from required module to the version that is required
317
         */
318
        public Map<String, String> getRequiredModulesMap() {
319
                return requiredModulesMap;
1✔
320
        }
321
        
322
        /**
323
         * Sets modules that must start after this module
324
         * @param startBeforeModulesMap the startedBefore modules to set
325
         */
326
        public void setStartBeforeModulesMap(Map<String, String> startBeforeModulesMap) {
327
                this.startBeforeModulesMap = startBeforeModulesMap;
1✔
328
        }
1✔
329
        
330
        /**
331
         * Gets modules which should start after this
332
         * @return map where key is module name and value is module version
333
         */
334
        public Map<String, String> getStartBeforeModulesMap() {
335
                return this.startBeforeModulesMap;
1✔
336
        }
337
        
338
        /**
339
         * Gets names of modules which should start after this
340
         * @since 1.11
341
         * @return list of module names or null
342
         */
343
        public List<String> getStartBeforeModules() {
344
                return this.startBeforeModulesMap == null ? null : new ArrayList<>(this.startBeforeModulesMap.keySet());
1✔
345
        }
346
        
347
        /**
348
         * Sets the modules that this module is aware of.
349
         *
350
         * @param awareOfModulesMap <code>Map&lt;String,String&gt;</code> of the
351
         *            <code>awareOfModulesMap</code>s to set
352
         * @since 1.9
353
         */
354
        public void setAwareOfModulesMap(Map<String, String> awareOfModulesMap) {
355
                this.awareOfModulesMap = awareOfModulesMap;
1✔
356
        }
1✔
357
        
358
        /**
359
         * This list of strings is just what is included in the config.xml file, the full package names:
360
         * e.g. org.openmrs.module.formentry, for the modules that this module is aware of.
361
         *
362
         * @since 1.9
363
         * @return the list of awareOfModules
364
         */
365
        public List<String> getAwareOfModules() {
366
                return awareOfModulesMap == null ? null : new ArrayList<>(awareOfModulesMap.keySet());
1✔
367
        }
368
        
369
        public String getAwareOfModuleVersion(String awareOfModule) {
370
                return awareOfModulesMap == null ? null : awareOfModulesMap.get(awareOfModule);
×
371
        }
372
        
373
        /**
374
         * @return the requireOpenmrsVersion
375
         */
376
        public String getRequireOpenmrsVersion() {
377
                return requireOpenmrsVersion;
1✔
378
        }
379
        
380
        /**
381
         * @param requireOpenmrsVersion the requireOpenmrsVersion to set
382
         */
383
        public void setRequireOpenmrsVersion(String requireOpenmrsVersion) {
384
                this.requireOpenmrsVersion = requireOpenmrsVersion;
1✔
385
        }
1✔
386
        
387
        /**
388
         * @return the module id
389
         */
390
        public String getModuleId() {
391
                return moduleId;
1✔
392
        }
393
        
394
        /**
395
         * @return the module id, with all . replaced with /
396
         */
397
        public String getModuleIdAsPath() {
398
                return moduleId == null ? null : moduleId.replace('.', '/');
1✔
399
        }
400
        
401
        /**
402
         * @param moduleId the module id to set
403
         */
404
        public void setModuleId(String moduleId) {
405
                this.moduleId = moduleId;
1✔
406
        }
1✔
407
        
408
        /**
409
         * @return the packageName
410
         */
411
        public String getPackageName() {
412
                return packageName;
1✔
413
        }
414
        
415
        /**
416
         * @param packageName the packageName to set
417
         */
418
        public void setPackageName(String packageName) {
419
                this.packageName = packageName;
×
420
        }
×
421
        
422
        /**
423
         * @return the version
424
         */
425
        public String getVersion() {
426
                return version;
1✔
427
        }
428
        
429
        /**
430
         * @param version the version to set
431
         */
432
        public void setVersion(String version) {
433
                this.version = version;
×
434
        }
×
435
        
436
        /**
437
         * @return the updateURL
438
         */
439
        public String getUpdateURL() {
440
                return updateURL;
1✔
441
        }
442
        
443
        /**
444
         * @param updateURL the updateURL to set
445
         */
446
        public void setUpdateURL(String updateURL) {
447
                this.updateURL = updateURL;
1✔
448
        }
1✔
449
        
450
        /**
451
         * @return the downloadURL
452
         */
453
        public String getDownloadURL() {
454
                return downloadURL;
×
455
        }
456
        
457
        /**
458
         * @param downloadURL the downloadURL to set
459
         */
460
        public void setDownloadURL(String downloadURL) {
461
                this.downloadURL = downloadURL;
×
462
        }
×
463
        
464
        /**
465
         * @return the updateVersion
466
         */
467
        public String getUpdateVersion() {
468
                return updateVersion;
×
469
        }
470
        
471
        /**
472
         * @param updateVersion the updateVersion to set
473
         */
474
        public void setUpdateVersion(String updateVersion) {
475
                this.updateVersion = updateVersion;
×
476
        }
×
477
        
478
        /**
479
         * Expands (i.e. creates instances of) {@code Extension}s defined by their class name in {@link #setExtensionNames(Map)}.
480
         * 
481
         * @return the extensions
482
         *
483
         * <strong>Should</strong> not expand extensionNames if extensionNames is null
484
         * <strong>Should</strong> not expand extensionNames if extensionNames is empty
485
         * <strong>Should</strong> not expand extensionNames if extensions matches extensionNames
486
         * <strong>Should</strong> expand extensionNames if extensions does not match extensionNames 
487
         */
488
        public List<Extension> getExtensions() {
489
                if (isNoNeedToExpand()) {
1✔
490
                        return extensions;
1✔
491
                }
492
                return expandExtensionNames();
1✔
493
        }
494
        
495
        /**
496
         * @param extensions the extensions to set
497
         */
498
        public void setExtensions(List<Extension> extensions) {
499
                this.extensions = extensions;
×
500
        }
×
501
        
502
        /**
503
         * A map of pointId to classname. The classname is expected to be a class that extends the
504
         * {@link Extension} object.
505
         * <br>
506
         * This map will be expanded into full Extension objects the first time {@link #getExtensions()}
507
         * is called.
508
         * <p>
509
         * The map is a direct representation of {@code extension} tags in a module's config.xml. For example
510
         * <pre>{@code
511
         * <extension>
512
         *     <point>org.openmrs.admin.list</point>
513
         *     <class>org.openmrs.module.reporting.web.extension.ManageAdminListExt</class>
514
         * </extension>
515
         * }
516
         * </pre>
517
         * </p>
518
         *
519
         * @param map from pointid to classname of an extension
520
         * @see ModuleFileParser
521
         */
522
        public void setExtensionNames(Map<String, String> map) {
523
                if (log.isDebugEnabled()) {
1✔
524
                        for (Map.Entry<String, String> entry : extensionNames.entrySet()) {
×
525
                                log.debug("Setting extension names: {} : {}", entry.getKey(), entry.getValue());
×
526
                        }
×
527
                }
528
                this.extensionNames = map;
1✔
529
        }
1✔
530

531
        private boolean isNoNeedToExpand() {
532
                if (extensionNames == null || extensionNames.isEmpty()) {
1✔
533
                        return true;
1✔
534
                }
535
                
536
                for (Extension ext : extensions) {
1✔
537
                        if (!extensionNames.get(ext.getPointId()).equals(ext.getClass().getName())) {
1✔
538
                                return false;
1✔
539
                        }
540
                }
1✔
541
                return extensions.size() == extensionNames.size();
1✔
542
        }
543
        
544
        /**
545
         * Expand the temporary extensionNames map of pointid-classname to full pointid-classobject. <br>
546
         * This has to be done after the fact because when the pointid-classnames are parsed, the
547
         * module's objects aren't fully realized yet and so not all classes can be loaded. <br>
548
         * <br>
549
         *
550
         * @return a list of full Extension objects
551
         */
552
        private List<Extension> expandExtensionNames() {
553
                ModuleClassLoader moduleClsLoader = ModuleFactory.getModuleClassLoader(this);
1✔
554
                if (moduleClsLoader == null) {
1✔
555
                        log.debug("Module class loader is not available, maybe the module {} is stopped/stopping", getName());
1✔
556
                        return extensions;
1✔
557
                }
558
                
559
                extensions.clear();
1✔
560
                for (Map.Entry<String, String> entry : extensionNames.entrySet()) {
1✔
561
                        String point = entry.getKey();
1✔
562
                        String className = entry.getValue();
1✔
563
                        log.debug(getModuleId() + ": Expanding extension name (point|class): {}|{}", point, className);
1✔
564
                        try {
565
                                Class<?> cls = moduleClsLoader.loadClass(className);
1✔
566
                                Extension ext = (Extension) cls.newInstance();
1✔
567
                                ext.setPointId(point);
1✔
568
                                ext.setModuleId(this.getModuleId());
1✔
569
                                extensions.add(ext);
1✔
570
                                log.debug(getModuleId() + ": Added extension: {}|{}", ext.getExtensionId(), ext.getClass());
1✔
571
                        }
572
                        catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoClassDefFoundError e) {
1✔
573
                                log.warn(getModuleId() + ": Unable to create instance of class defined for extension point: " + point, e);
1✔
574
                        }
1✔
575
                }
1✔
576
                return extensions;
1✔
577
        }
578
        
579
        /**
580
         * @return the advicePoints
581
         */
582
        public List<AdvicePoint> getAdvicePoints() {
583
                return advicePoints;
1✔
584
        }
585
        
586
        /**
587
         * @param advicePoints the advicePoints to set
588
         */
589
        public void setAdvicePoints(List<AdvicePoint> advicePoints) {
590
                this.advicePoints = advicePoints;
1✔
591
        }
1✔
592
        
593
        public File getFile() {
594
                return file;
1✔
595
        }
596
        
597
        public void setFile(File file) {
598
                this.file = file;
1✔
599
        }
1✔
600
        
601
        /**
602
         * Gets a mapping from locale to properties used by this module. The locales are represented as
603
         * a string containing language and country codes.
604
         *
605
         * @return mapping from locales to properties
606
         * @deprecated as of 2.0 because messages are automatically loaded from the classpath
607
         */
608
        @Deprecated
609
        public Map<String, Properties> getMessages() {
610
                return messages;
×
611
        }
612
        
613
        /**
614
         * Sets the map from locale to properties used by this module.
615
         *
616
         * @param messages map of locale to properties for that locale
617
         * @deprecated as of 2.0 because messages are automatically loaded from the classpath
618
         */
619
        @Deprecated
620
        public void setMessages(Map<String, Properties> messages) {
621
                this.messages = messages;
×
622
        }
×
623
        
624
        public List<GlobalProperty> getGlobalProperties() {
625
                return globalProperties;
1✔
626
        }
627
        
628
        public void setGlobalProperties(List<GlobalProperty> globalProperties) {
629
                this.globalProperties = globalProperties;
1✔
630
        }
1✔
631
        
632
        public List<Privilege> getPrivileges() {
633
                return privileges;
1✔
634
        }
635
        
636
        public void setPrivileges(List<Privilege> privileges) {
637
                this.privileges = privileges;
1✔
638
        }
1✔
639
        
640
        public Document getConfig() {
641
                return config;
×
642
        }
643
        
644
        public void setConfig(Document config) {
645
                this.config = config;
1✔
646
        }
1✔
647
        
648
        public Document getSqldiff() {
649
                return sqldiff;
×
650
        }
651
        
652
        public void setSqldiff(Document sqldiff) {
653
                this.sqldiff = sqldiff;
×
654
        }
×
655
        
656
        public List<String> getMappingFiles() {
657
                return mappingFiles;
1✔
658
        }
659
        
660
        public void setMappingFiles(List<String> mappingFiles) {
661
                this.mappingFiles = mappingFiles;
1✔
662
        }
1✔
663
        
664
        /**
665
         * Packages to scan for classes with JPA annotated classes.
666
         * @return the set of packages to scan
667
         * @since 1.9.2, 1.10
668
         */
669
        public Set<String> getPackagesWithMappedClasses() {
670
                return packagesWithMappedClasses;
1✔
671
        }
672
        
673
        /**
674
         * @param packagesToScan
675
         * @see #getPackagesWithMappedClasses()
676
         * @since 1.9.2, 1.10
677
         */
678
        public void setPackagesWithMappedClasses(Set<String> packagesToScan) {
679
                this.packagesWithMappedClasses = packagesToScan;
1✔
680
        }
1✔
681
        
682
        /**
683
         * This property is set by the module owner to tell OpenMRS that once it is installed, it must
684
         * always startup. This is intended for modules with system-critical monitoring or security
685
         * checks that should always be in place.
686
         *
687
         * @return true if this module has said that it should always start up
688
         */
689
        public boolean isMandatory() {
690
                return mandatory;
1✔
691
        }
692
        
693
        public void setMandatory(boolean mandatory) {
694
                this.mandatory = mandatory;
1✔
695
        }
1✔
696
        
697
        /**
698
         * This is a convenience method to know whether this module is core to OpenMRS. A module is
699
         * 'core' when this module is essentially part of the core code and must exist at all times
700
         *
701
         * @return true if this is an OpenMRS core module
702
         * @see ModuleConstants#CORE_MODULES
703
         */
704
        public boolean isCoreModule() {
705
                return !ModuleUtil.ignoreCoreModules() && ModuleConstants.CORE_MODULES.containsKey(moduleId);
×
706
        }
707
        
708
        public boolean isStarted() {
709
                return ModuleFactory.isModuleStarted(this);
1✔
710
        }
711
        
712
        /**
713
         * @param e string to set as startup error message
714
         * <strong>Should</strong> throw exception when message is null
715
         */
716
        public void setStartupErrorMessage(String e) {
717
                if (e == null) {
1✔
718
                        throw new ModuleException("Startup error message cannot be null", this.getModuleId());
1✔
719
                }
720
                
721
                this.startupErrorMessage = e;
×
722
        }
×
723
        
724
        /**
725
         * Add the given exceptionMessage and throwable as the startup error for this module. This
726
         * method loops over the stacktrace and adds the detailed message
727
         *
728
         * @param exceptionMessage optional. the default message to show on the first line of the error
729
         *            message
730
         * @param t throwable stacktrace to include in the error message
731
         *
732
         * <strong>Should</strong> throw exception when throwable is null
733
         * <strong>Should</strong> set StartupErrorMessage when exceptionMessage is null
734
         * <strong>Should</strong> append throwable's message to exceptionMessage
735
         */
736
        public void setStartupErrorMessage(String exceptionMessage, Throwable t) {
737
                if (t == null) {
1✔
738
                        throw new ModuleException("Startup error value cannot be null", this.getModuleId());
1✔
739
                }
740
                
741
                StringBuilder sb = new StringBuilder();
1✔
742
                
743
                // if exceptionMessage is not null, append it
744
                if (exceptionMessage != null) {
1✔
745
                        sb.append(exceptionMessage);
1✔
746
                        sb.append("\n");
1✔
747
                }
748
                
749
                sb.append(t.getMessage());
1✔
750
                sb.append("\n");
1✔
751
                
752
                this.startupErrorMessage = sb.toString();
1✔
753
        }
1✔
754
        
755
        public String getStartupErrorMessage() {
756
                return startupErrorMessage;
1✔
757
        }
758
        
759
        public Boolean hasStartupError() {
760
                return (this.startupErrorMessage != null);
1✔
761
        }
762
        
763
        public void clearStartupError() {
764
                this.startupErrorMessage = null;
1✔
765
        }
1✔
766
        
767
        @Override
768
        public String toString() {
769
                if (moduleId == null) {
1✔
770
                        return super.toString();
×
771
                }
772
                
773
                return moduleId;
1✔
774
        }
775

776
        /*
777
         * <strong>Should</strong> dispose all classInstances, not AdvicePoints
778
         */        
779
        public void disposeAdvicePointsClassInstance() {
780
                if (advicePoints == null) {
1✔
781
                        return;
1✔
782
                }
783
                
784
                for (AdvicePoint advicePoint : advicePoints) {
1✔
785
                        advicePoint.disposeClassInstance();
1✔
786
                }
1✔
787
        }
1✔
788
        
789
        public List<ModuleConditionalResource> getConditionalResources() {
790
                return conditionalResources;
1✔
791
        }
792
        
793
        public void setConditionalResources(List<ModuleConditionalResource> conditionalResources) {
794
                this.conditionalResources = conditionalResources;
1✔
795
        }
1✔
796
        
797
        public boolean isCore() {
798
                return ModuleConstants.CORE_MODULES.containsKey(getModuleId());
1✔
799
        }
800
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc