-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDefaultModule.java
More file actions
1602 lines (1374 loc) · 50.3 KB
/
DefaultModule.java
File metadata and controls
1602 lines (1374 loc) · 50.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2005-2018 Fred Hutchinson Cancer Research Center
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.labkey.api.module;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;
import org.labkey.api.action.HasViewContext;
import org.labkey.api.action.PermissionCheckableAction;
import org.labkey.api.action.SpringActionController;
import org.labkey.api.collections.CaseInsensitiveHashSet;
import org.labkey.api.data.CompareType;
import org.labkey.api.data.Container;
import org.labkey.api.data.CoreSchema;
import org.labkey.api.data.DbSchema;
import org.labkey.api.data.DbSchemaType;
import org.labkey.api.data.DbScope;
import org.labkey.api.data.FileSqlScriptProvider;
import org.labkey.api.data.SchemaTableInfoFactory;
import org.labkey.api.data.SimpleFilter;
import org.labkey.api.data.Sort;
import org.labkey.api.data.SqlScriptManager;
import org.labkey.api.data.SqlScriptRunner;
import org.labkey.api.data.SqlScriptRunner.SqlScript;
import org.labkey.api.data.SqlScriptRunner.SqlScriptProvider;
import org.labkey.api.data.Table;
import org.labkey.api.data.TableInfo;
import org.labkey.api.data.TableSelector;
import org.labkey.api.data.UpgradeCode;
import org.labkey.api.data.dialect.SqlDialect;
import org.labkey.api.module.ModuleXml.ModuleXmlCacheHandler;
import org.labkey.api.query.FieldKey;
import org.labkey.api.query.OlapSchemaInfo;
import org.labkey.api.resource.Resource;
import org.labkey.api.security.User;
import org.labkey.api.settings.AppProps;
import org.labkey.api.usageMetrics.SimpleMetricsService;
import org.labkey.api.util.ConfigurationException;
import org.labkey.api.util.DateUtil;
import org.labkey.api.util.ExceptionUtil;
import org.labkey.api.util.FileUtil;
import org.labkey.api.util.MemTracker;
import org.labkey.api.util.Pair;
import org.labkey.api.util.Path;
import org.labkey.api.util.ResponseHelper;
import org.labkey.api.util.URLHelper;
import org.labkey.api.util.logging.LogHelper;
import org.labkey.api.view.ActionURL;
import org.labkey.api.view.HttpView;
import org.labkey.api.view.NotFoundException;
import org.labkey.api.view.Portal;
import org.labkey.api.view.RedirectException;
import org.labkey.api.view.UnauthorizedException;
import org.labkey.api.view.ViewContext;
import org.labkey.api.view.ViewServlet;
import org.labkey.api.view.WebPartFactory;
import org.labkey.api.view.template.ClientDependency;
import org.labkey.api.writer.ContainerUser;
import org.labkey.vfs.FileLike;
import org.labkey.vfs.FileSystemLike;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.servlet.mvc.Controller;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
/**
* Standard base class for modules, supplies no-op implementations for many optional methods.
*/
public abstract class DefaultModule implements Module, ApplicationContextAware
{
public static final String CORE_MODULE_NAME = "Core";
private static final Logger _log = LogHelper.getLogger(DefaultModule.class, "Module issues");
private static final Set<Pair<Class<? extends DefaultModule>, String>> INSTANTIATED_MODULES = new HashSet<>();
static final ModuleResourceCache<ModuleXml> MODULE_XML_CACHE = ModuleResourceCaches.create("module.xml files", new ModuleXmlCacheHandler(), ResourceRootProvider.getStandard(new Path()));
private final Map<String, Class<? extends Controller>> _controllerNameToClass = new LinkedHashMap<>();
private final Map<Class<? extends Controller>, String> _controllerClassToName = new HashMap<>();
private final Set<String> _moduleDependencies = new CaseInsensitiveHashSet();
private final Map<String, ModuleProperty> _moduleProperties = new LinkedHashMap<>();
private Set<Module> _resolvedModuleDependencies;
private Collection<WebPartFactory> _webPartFactories;
private ModuleResourceResolver _resolver;
private String _name = null;
private String _label = null;
private String _description = null;
private Double _schemaVersion = null;
private double _requiredServerVersion = 0.0;
private String _moduleDependenciesString = null;
private String _url = null;
private String _organization = null;
private String _organizationUrl = null;
private String _buildType = null;
private String _author = null;
private String _maintainer = null;
private String _license = null;
private String _licenseUrl = null;
private String _vcsRevision = null;
private String _vcsUrl = null;
private String _vcsBranch = "Unknown";
private String _buildUser = null;
private String _buildTime = null;
private String _buildOS = null;
private String _buildPath = null;
private String _sourcePath = null;
private String _buildNumber = null;
private String _enlistmentId = null;
private File _explodedPath = null;
private File _zippedPath = null;
private Boolean _manageVersion = null;
private String _releaseVersion = null;
// for displaying development status of module
private boolean _sourcePathMatched = false;
private boolean _sourceEnlistmentIdMatched = false;
protected String _resourcePath = null;
protected DefaultModule()
{
assert MemTracker.getInstance().put(this);
}
@Override
final public void initialize()
{
for (String dsName : ModuleLoader.getInstance().getModuleDataSourceNames(this))
{
Throwable t = DbScope.getDataSourceFailure(dsName);
// Data source is defined but connection wasn't successful
if (null != t)
throw new ConfigurationException("This module requires a properly configured data source called \"" + dsName + "\"", t);
// Data source is defined and ready to go
if (null != DbScope.getDbScope(dsName))
continue;
if (AppProps.getInstance().isDevMode())
{
// A module data source is missing and we're in dev mode, so attempt to create a proxy data source that uses the labkey
// database. This can be helpful on test and dev machines. See #23730.
DbScope scope = DbScope.getLabKeyScope();
_log.warn("Module \"" + getName() + "\" requires a data source called \"" + dsName + "\". It's not configured, so it will be created against the primary labkey database (\"" + scope.getDatabaseName() + "\") instead.");
DbScope.addScope(dsName, scope.getLabKeyDataSource());
if (null == DbScope.getDbScope(dsName)) // Force immediate connection to test
throw new ConfigurationException("Failed to connect to data source \"" + dsName + "\", created against the labkey database (\"" + scope.getDatabaseName() + "\").");
}
else
{
// A module data source is missing and we're in production mode, so issue a warning. The data source might be optional, e.g., on staging servers. See #23830
_log.warn("Module \"" + getName() + "\" requires a data source called \"" + dsName + "\" but it's not configured. This module will be loaded, but it might not operate correctly.");
}
}
synchronized (INSTANTIATED_MODULES)
{
//simple modules all use the same Java class, so we need to also include
//the module name in the instantiated modules set
Pair<Class<? extends DefaultModule>, String> reg = new Pair<>(getClass(), getName());
if (INSTANTIATED_MODULES.contains(reg))
throw new IllegalStateException("An instance of module " + getClass() + " with name '" + getName() + "' has already been created. Modules should be singletons");
else
INSTANTIATED_MODULES.add(reg);
}
ModuleLoader.getInstance().registerResourcePrefix(getResourcePath(), this);
// _resolver = new ModuleResourceResolver(this, getResourceDirectories(), getResourceClasses());
init();
}
public void unregister()
{
synchronized(INSTANTIATED_MODULES)
{
Pair<Class<?>, String> reg = new Pair<>(getClass(), getName());
INSTANTIATED_MODULES.remove(reg);
}
}
protected abstract void init();
/**
* Create the WebPartFactories that this module defines in code. File-based webpart factories are handled implicitly.
*
* @return A collection of WebPartFactories
*/
protected abstract @NotNull Collection<? extends WebPartFactory> createWebPartFactories();
/** @return true if this module has SQL upgrade scripts that should be run as part of startup */
public abstract boolean hasScripts();
@Override
final public void startup(ModuleContext moduleContext)
{
doStartup(moduleContext);
}
protected abstract void doStartup(ModuleContext moduleContext);
@Override
public String getResourcePath()
{
return _resourcePath;
}
// resourcePath can optionally be set in the module.properties / xml files; called by spring
@SuppressWarnings("UnusedDeclaration")
public void setResourcePath(String resourcePath)
{
// If the resourcePath was set in the module.properties or xml file, override the path derived from the
// module class.
if (StringUtils.isNotEmpty(resourcePath))
{
_resourcePath = resourcePath;
}
else _resourcePath = "/" + getClass().getPackage().getName().replaceAll("\\.", "/");
}
// Note: First controller registered in a module is special: getTabURL() treats it as the "default controller", e.g.
protected void addController(String primaryName, Class<? extends Controller> cl, String... aliases)
{
if (!Controller.class.isAssignableFrom(cl))
throw new IllegalArgumentException(cl.toString());
// Map controller class to canonical name
addControllerClass(cl, primaryName);
// Map aliases to controller class
for (String alias : aliases)
addControllerName(alias, cl);
}
// Map controller class to canonical name
private void addControllerClass(Class<? extends Controller> controllerClass, String primaryName)
{
assert !_controllerNameToClass.containsValue(controllerClass) : "Controller class '" + controllerClass + "' is already registered";
_controllerClassToName.put(controllerClass, primaryName);
addControllerName(primaryName, controllerClass);
}
// Map all names to controller class
private void addControllerName(String controllerName, Class<? extends Controller> controllerClass)
{
assert null == _controllerNameToClass.get(controllerName) : "Controller name '" + controllerName + "' is already registered";
_controllerNameToClass.put(controllerName, controllerClass);
}
@Override
public String getTabName(ViewContext context)
{
return getName();
}
@Override
public void beforeUpdate(ModuleContext moduleContext)
{
if (!moduleContext.isNewInstall())
ModuleLoader.getInstance().runUpgradeScripts(this, SchemaUpdateType.Before);
}
/**
* Upgrade each schema in this module to the latest version.
*/
@Override
public void versionUpdate(ModuleContext moduleContext) throws Exception
{
if (hasScripts())
{
if (null == getSchemaVersion())
{
throw new IllegalStateException("getSchemaVersion() was null for module: " + getName() + " even though hasScripts() was true");
}
SqlScriptProvider provider = new FileSqlScriptProvider(this);
SqlScriptRunner runner = ModuleLoader.getInstance().getUpgradeScriptRunner();
for (DbSchema schema : provider.getSchemas())
{
SqlScriptManager manager = SqlScriptManager.get(provider, schema);
List<SqlScript> scripts = manager.getRecommendedScripts(getSchemaVersion());
if (!scripts.isEmpty())
runner.runScripts(this, scripts);
SqlScript script = SchemaUpdateType.After.getScript(provider, schema);
if (null != script)
runner.runScripts(this, Collections.singletonList(script));
}
}
}
@Override
public void afterUpdate(ModuleContext moduleContext)
{
}
private final Object FACTORY_LOCK = new Object();
@Override
public final @NotNull Collection<WebPartFactory> getWebPartFactories()
{
synchronized (FACTORY_LOCK)
{
if (null == _webPartFactories)
{
Collection<WebPartFactory> wpf = new ArrayList<>();
// Get all the Java webpart factories
for (WebPartFactory webPartFactory : createWebPartFactories())
{
// Must setModule(), since they aren't initialized with this information
webPartFactory.setModule(this);
wpf.add(webPartFactory);
}
// File-based webpart factories; no need to call setModule() since module is initialized in constructor
wpf.addAll(Portal.WEB_PART_FACTORY_CACHE.getResourceMap(this));
_webPartFactories = wpf;
}
return _webPartFactories;
}
}
public final void clearWebPartFactories()
{
synchronized (FACTORY_LOCK)
{
_webPartFactories = null;
}
}
@Override
public void destroy()
{
}
@Override
@NotNull
public Collection<String> getSummary(Container c)
{
return Collections.emptyList();
}
@Override
public @NotNull List<Summary> getDetailedSummary(Container c, User user)
{
return Collections.emptyList();
}
@Override
public final Map<String, Class<? extends Controller>> getControllerNameToClass()
{
return _controllerNameToClass;
}
@Override
public final Map<Class<? extends Controller>, String> getControllerClassToName()
{
return _controllerClassToName;
}
@Override
public ActionURL getTabURL(Container c, User user)
{
Map<String, Class<? extends Controller>> map = getControllerNameToClass();
// Some modules have no controllers (e.g., BigIron)
if (!map.isEmpty())
{
// Note: First registered controller is special -- its BeginAction becomes the tab URL for the module
Map.Entry<String, Class<? extends Controller>> entry = map.entrySet().iterator().next();
Controller controller = getController(null, entry.getValue());
if (controller instanceof SpringActionController)
{
Controller action = ((SpringActionController) controller).getActionResolver().resolveActionName(controller, "begin");
if (action != null)
{
// In some cases the begin action requires more than read permission
if (action instanceof PermissionCheckableAction checkable && HttpView.hasCurrentView())
{
try
{
checkable.setViewContext(HttpView.currentContext());
checkable.checkPermissions();
}
catch (UnauthorizedException e)
{
return null;
}
catch (RedirectException ignored)
{
// Likely a terms-of-use redirect, like for setting compliance activity
}
}
// Use the deprecated constructor, since passing in an action class like SimpleAction that is used
// to back multiple URLs with different static HTML files can't be resolved to the right URL
return new ActionURL(entry.getKey(), "begin", c);
}
}
}
return null;
}
@Override
public TabDisplayMode getTabDisplayMode()
{
return Module.TabDisplayMode.DISPLAY_USER_PREFERENCE;
}
protected void addWebPart(String name, Container c, @Nullable String location)
{
addWebPart(name, c, location, -1, new HashMap<>());
}
protected void addWebPart(String name, Container c, String location, int partIndex)
{
addWebPart(name, c, location, partIndex, new HashMap<>());
}
protected void addWebPart(String name, Container c, @Nullable String location, int partIndex, Map<String, String> properties)
{
boolean foundPart = false;
for (Portal.WebPart part : Portal.getParts(c))
{
if (name.equals(part.getName()))
{
foundPart = true;
break;
}
}
if (!foundPart)
{
WebPartFactory desc = Portal.getPortalPart(name);
if (desc != null)
{
Portal.addPart(c, desc, location, partIndex, properties);
}
}
}
@Override
public @NotNull Set<Class<?>> getIntegrationTests()
{
return Collections.emptySet();
}
@Override
public @NotNull Set<Class<?>> getUnitTests()
{
return Collections.emptySet();
}
/**
* Returns all non-provisioned schemas claimed by the module in {@link #getSchemaNames()}. Override if a different
* set of schemas should be tested.
*/
@Override
@NotNull
@JsonIgnore
public Set<DbSchema> getSchemasToTest()
{
Set<String> schemaNames = new LinkedHashSet<>(getSchemaNames());
schemaNames.removeAll(getProvisionedSchemaNames());
Set<DbSchema> result = new LinkedHashSet<>();
for (String schemaName : schemaNames)
{
DbSchema schema = DbSchema.get(schemaName, DbSchemaType.Module);
result.add(schema);
}
return result;
}
@NotNull
@Override
public Collection<String> getProvisionedSchemaNames()
{
return Collections.emptySet();
}
protected static final Set<SupportedDatabase> ONLY_POSTGRESQL = Set.of(SupportedDatabase.pgsql);
private Set<SupportedDatabase> _supportedDatabases = ONLY_POSTGRESQL;
@NotNull
@Override
public final Set<SupportedDatabase> getSupportedDatabasesSet()
{
return _supportedDatabases;
}
// Used by Spring configuration reflection
@SuppressWarnings("UnusedDeclaration")
public final String getSupportedDatabases()
{
Set<SupportedDatabase> set = getSupportedDatabasesSet();
return StringUtils.join(set, ",");
}
// Used by Spring configuration reflection
@SuppressWarnings("UnusedDeclaration")
public final void setSupportedDatabases(String list)
{
Set<SupportedDatabase> supported = SupportedDatabase.parseSupportedDatabases(list);
if (!supported.isEmpty())
_supportedDatabases = supported;
}
@Override
public String getName()
{
return _name;
}
public final void setName(String name)
{
checkLocked();
if (StringUtils.isEmpty(name))
return;
if (!StringUtils.isEmpty(_name))
{
if (!_name.equals(name))
_log.error("Attempt to change name of module from {} to {}.", _name, name);
return;
}
_name = name;
}
@Override
public @Nullable Double getSchemaVersion()
{
return _schemaVersion;
}
public final void setSchemaVersion(Double schemaVersion)
{
checkLocked();
if (null == schemaVersion)
return;
if (null != _schemaVersion)
{
if (!_schemaVersion.equals(schemaVersion))
_log.error("Attempt to change version of module from {} to {}.", _schemaVersion, schemaVersion);
return;
}
_schemaVersion = schemaVersion;
}
public final double getRequiredServerVersion()
{
return _requiredServerVersion;
}
public final void setRequiredServerVersion(double requiredServerVersion)
{
checkLocked();
if (0.0 != requiredServerVersion)
_requiredServerVersion = requiredServerVersion;
}
@Nullable
@Override
public final String getLabel()
{
return _label;
}
public final void setLabel(String label)
{
checkLocked();
_label = label;
}
@Nullable
@Override
public final String getDescription()
{
return _description;
}
public final void setDescription(String description)
{
checkLocked();
_description = description;
}
@Nullable
@Override
public final String getUrl()
{
return _url;
}
public final void setUrl(String url)
{
checkLocked();
_url = url;
}
@Nullable
@Override
public final String getAuthor()
{
return _author;
}
public final void setAuthor(String author)
{
checkLocked();
_author = author;
}
@Nullable
@Override
public final String getMaintainer()
{
return _maintainer;
}
@SuppressWarnings("unused")
public final void setMaintainer(String maintainer)
{
checkLocked();
_maintainer = maintainer;
}
@Nullable
@Override
public final String getOrganization()
{
return _organization;
}
public final void setOrganization(String organization)
{
checkLocked();
_organization = organization;
}
@Nullable
@Override
public String getBuildType()
{
return _buildType;
}
@SuppressWarnings("unused")
public void setBuildType(String buildType)
{
_buildType = buildType;
}
@Nullable
@Override
public final String getOrganizationUrl()
{
return _organizationUrl;
}
@SuppressWarnings("unused")
public final void setOrganizationUrl(String organizationUrl)
{
checkLocked();
_organizationUrl = organizationUrl;
}
@Nullable
@Override
public final String getLicense()
{
return _license;
}
@SuppressWarnings("unused")
public final void setLicense(String license)
{
checkLocked();
_license = license;
}
@Nullable
@Override
public final String getLicenseUrl()
{
return _licenseUrl;
}
@SuppressWarnings("unused")
public final void setLicenseUrl(String licenseUrl)
{
checkLocked();
_licenseUrl = licenseUrl;
}
@Override
public final Set<String> getModuleDependenciesAsSet()
{
return _moduleDependencies;
}
@SuppressWarnings({"UnusedDeclaration"})
public final void setModuleDependencies(String dependencies)
{
checkLocked();
_moduleDependenciesString = dependencies;
if (null == dependencies || dependencies.isEmpty())
return;
String[] depArray = dependencies.split(",");
for (String dependency : depArray)
{
dependency = dependency.trim();
if (!dependency.isEmpty())
_moduleDependencies.add(dependency.toLowerCase());
}
_resolvedModuleDependencies = null;
}
public final String getModuleDependencies()
{
return _moduleDependenciesString;
}
@Nullable
@Override
public final String getVcsRevision()
{
return _vcsRevision;
}
@SuppressWarnings({"UnusedDeclaration"})
public final void setVcsRevision(String vcsRevision)
{
checkLocked();
_vcsRevision = vcsRevision;
}
@Nullable
@Override
public final String getVcsUrl()
{
return _vcsUrl;
}
@SuppressWarnings({"UnusedDeclaration"})
public final void setVcsUrl(String vcsUrl)
{
checkLocked();
_vcsUrl = vcsUrl;
}
@Nullable
@Override
public String getVcsBranch()
{
return _vcsBranch;
}
@SuppressWarnings({"UnusedDeclaration"})
public void setVcsBranch(String vcsBranch)
{
_vcsBranch = vcsBranch;
}
@SuppressWarnings({"UnusedDeclaration"})
public void setVcsTag(String vcsTag)
{
// Ignored - present in module.xml but not used
}
public final String getBuildUser()
{
return _buildUser;
}
@SuppressWarnings({"UnusedDeclaration"})
public final void setBuildUser(String buildUser)
{
_buildUser = buildUser;
}
@Override
public final String getBuildTime()
{
return _buildTime;
}
@SuppressWarnings({"UnusedDeclaration"})
public final void setBuildTime(String buildTime)
{
_buildTime = buildTime;
}
public final String getBuildOS()
{
return _buildOS;
}
@SuppressWarnings({"UnusedDeclaration"})
public final void setBuildOS(String buildOS)
{
_buildOS = buildOS;
}
@Override
public final String getSourcePath()
{
return _sourcePath;
}
public final void setSourcePath(String sourcePath)
{
if (!AppProps.getInstance().isIgnoreModuleSource())
{
_sourcePath = sourcePath;
}
}
@Override
public final String getBuildPath()
{
return _buildPath;
}
@SuppressWarnings({"UnusedDeclaration"})
public final void setBuildPath(String buildPath)
{
if (!AppProps.getInstance().isIgnoreModuleSource())
{
_buildPath = buildPath;
}
}
@Override
public final String getBuildNumber()
{
return _buildNumber;
}
@SuppressWarnings({"UnusedDeclaration"})
public final void setBuildNumber(String buildNumber)
{
_buildNumber = buildNumber;
}
public final String getEnlistmentId()
{
return _enlistmentId;
}
@SuppressWarnings("UnusedDeclaration")
public final void setEnlistmentId(String enlistmentId)
{
_enlistmentId = enlistmentId;
}
@SuppressWarnings("unused")
public Boolean getManageVersion()
{
return _manageVersion;
}
@SuppressWarnings("unused")
public void setManageVersion(Boolean manageVersion)
{
_manageVersion = manageVersion;
}
@Override
public boolean shouldManageVersion()
{
return _manageVersion != Boolean.FALSE;
}
@Override
public @Nullable String getReleaseVersion()
{
return _releaseVersion;
}
@SuppressWarnings("unused")
public void setReleaseVersion(String releaseVersion)
{
_releaseVersion = releaseVersion;
}
@Override
public final Map<String, String> getProperties()
{
Map<String, String> props = new LinkedHashMap<>();
props.put("Module Class", getClass().getName());
props.put("Schema Version", getFormattedSchemaVersion());
if (StringUtils.isNotBlank(getReleaseVersion()))
props.put("Release Version", getReleaseVersion());
if (StringUtils.isNotBlank(getAuthor()))
props.put("Author", getAuthor());
if (StringUtils.isNotBlank(getMaintainer()))
props.put("Maintainer", getMaintainer());
if (StringUtils.isNotBlank(getOrganization()))
props.put("Organization", getOrganization());
if (StringUtils.isNotBlank(getOrganizationUrl()))
props.put("OrganizationURL", getOrganizationUrl());
if (StringUtils.isNotBlank(getBuildType()))
props.put("Build Type", getBuildType());
if (StringUtils.isNotBlank(getLicense()))
props.put("License", getLicense());
if (StringUtils.isNotBlank(getLicenseUrl()))
props.put("LicenseURL", getLicenseUrl());
props.put("Extracted Path", getExplodedPath().getAbsolutePath());
props.put("VCS URL", getVcsUrl());
props.put("VCS Revision", getVcsRevision());
props.put("VCS Branch", getVcsBranch());
props.put("Build OS", getBuildOS());
props.put("Build Time", getBuildTime());
props.put("Build User", getBuildUser());
props.put("Build Path", getBuildPath());
props.put("Source Path", getSourcePath());
if (null != getZippedPath())
props.put("Module File", getZippedPath().getPath());
props.put("Build Number", getBuildNumber());
props.put("Enlistment ID", getEnlistmentId());
props.put("Module Dependencies", StringUtils.trimToNull(getModuleDependencies()) == null ? "<none>" : getModuleDependencies());
return props;
}
@Override
@Deprecated // prefer getExplodedFileLike()
public final File getExplodedPath()
{
return _explodedPath;
}
@Override
public final FileLike getExplodedFileLike()
{
return new FileSystemLike.Builder(_explodedPath).readonly().root();
}
@Override
public final void setExplodedPath(File path)
{
_explodedPath = path.getAbsoluteFile();