Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit c3baa91

Browse files
authored
Merge pull request #445 from hansenmc/cleanupLinting
Apply various code quality fixes, remove unused imports, use diamond operator, try-with-resources, etc
2 parents 67b3092 + ae90312 commit c3baa91

File tree

51 files changed

+94
-153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+94
-153
lines changed

src/main/java/com/marklogic/appdeployer/DefaultAppConfigFactory.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,7 @@ public void initialize() {
457457
logger.info("Databases that will have their forest(s) created on a single host: " + prop);
458458
String[] names = prop.split(",");
459459
Set<String> set = new HashSet<>();
460-
for (String name : names) {
461-
set.add(name);
462-
}
460+
set.addAll(Arrays.asList(names));
463461
config.setDatabasesWithForestsOnOneHost(set);
464462
});
465463

@@ -904,9 +902,7 @@ protected Map<String, List<String>> buildMapOfListsFromDelimitedString(String st
904902
String dbName = tokens[i];
905903
String[] hostNames = tokens[i + 1].split("\\|");
906904
List<String> names = new ArrayList<>();
907-
for (String name : hostNames) {
908-
names.add(name);
909-
}
905+
names.addAll(Arrays.asList(hostNames));
910906
map.put(dbName, names);
911907
}
912908
return map;

src/main/java/com/marklogic/appdeployer/cli/Main.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,8 @@ private static PropertySource buildPropertySource(Options options) throws IOExce
102102
if (logger.isInfoEnabled()) {
103103
logger.info("Reading properties from file path: " + propertiesFilePath);
104104
}
105-
FileInputStream fis = new FileInputStream(propertiesFilePath);
106-
try {
105+
try (FileInputStream fis = new FileInputStream(propertiesFilePath)) {
107106
props.load(fis);
108-
} finally {
109-
fis.close();
110107
}
111108

112109
// Dynamic params override what's in the properties file

src/main/java/com/marklogic/appdeployer/command/AbstractCommand.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ public void setFilenamesToIgnore(String... filenames) {
7575
} else {
7676
set = new HashSet<>();
7777
}
78-
for (String f : filenames) {
79-
set.add(f);
80-
}
78+
set.addAll(Arrays.asList(filenames));
8179
rff.setFilenamesToIgnore(set);
8280
} else {
8381
logger.warn("resourceFilenameFilter is not an instanceof ResourceFilenameFilter, so unable to set resource filenames to ignore");

src/main/java/com/marklogic/appdeployer/command/CommandMapBuilder.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,35 +92,35 @@ public List<Command> getCommandsForReplicaCluster() {
9292
}
9393

9494
private void addCommandsThatDoNotWriteToDatabases(Map<String, List<Command>> map) {
95-
List<Command> clusterCommands = new ArrayList<Command>();
95+
List<Command> clusterCommands = new ArrayList<>();
9696
clusterCommands.add(new ModifyLocalClusterCommand());
9797
map.put("mlClusterCommands", clusterCommands);
9898

9999
List<Command> configurationCommands = new ArrayList<>();
100100
configurationCommands.add(new DeployConfigurationsCommand());
101101
map.put("mlConfigurationCommands", configurationCommands);
102102

103-
List<Command> dbCommands = new ArrayList<Command>();
103+
List<Command> dbCommands = new ArrayList<>();
104104
dbCommands.add(new DeployOtherDatabasesCommand());
105105
map.put("mlDatabaseCommands", dbCommands);
106106

107-
List<Command> forestCommands = new ArrayList<Command>();
107+
List<Command> forestCommands = new ArrayList<>();
108108
forestCommands.add(new DeployCustomForestsCommand());
109109
map.put("mlForestCommands", forestCommands);
110110

111-
List<Command> replicaCommands = new ArrayList<Command>();
111+
List<Command> replicaCommands = new ArrayList<>();
112112
replicaCommands.add(new ConfigureForestReplicasCommand());
113113
map.put("mlForestReplicaCommands", replicaCommands);
114114

115-
List<Command> groupCommands = new ArrayList<Command>();
115+
List<Command> groupCommands = new ArrayList<>();
116116
groupCommands.add(new DeployGroupsCommand());
117117
map.put("mlGroupCommands", groupCommands);
118118

119-
List<Command> hostCommands = new ArrayList<Command>();
119+
List<Command> hostCommands = new ArrayList<>();
120120
hostCommands.add(new AssignHostsToGroupsCommand());
121121
map.put("mlHostCommands", hostCommands);
122122

123-
List<Command> mimetypeCommands = new ArrayList<Command>();
123+
List<Command> mimetypeCommands = new ArrayList<>();
124124
mimetypeCommands.add(new DeployMimetypesCommand());
125125
map.put("mlMimetypeCommands", mimetypeCommands);
126126

@@ -137,7 +137,7 @@ private void addCommandsThatDoNotWriteToDatabases(Map<String, List<Command>> map
137137
restApiCommands.add(new DeployRestApiServersCommand());
138138
map.put("mlRestApiCommands", restApiCommands);
139139

140-
List<Command> securityCommands = new ArrayList<Command>();
140+
List<Command> securityCommands = new ArrayList<>();
141141
securityCommands.add(new DeployRolesCommand());
142142
securityCommands.add(new DeployUsersCommand());
143143
securityCommands.add(new DeployAmpsCommand());
@@ -157,20 +157,20 @@ private void addCommandsThatDoNotWriteToDatabases(Map<String, List<Command>> map
157157
serverCommands.add(new UpdateRestApiServersCommand());
158158
map.put("mlServerCommands", serverCommands);
159159

160-
List<Command> taskCommands = new ArrayList<Command>();
160+
List<Command> taskCommands = new ArrayList<>();
161161
taskCommands.add(new DeployScheduledTasksCommand());
162162
taskCommands.add(new UpdateTaskServerCommand());
163163
map.put("mlTaskCommands", taskCommands);
164164
}
165165

166166
private void addCommandsThatWriteToDatabases(Map<String, List<Command>> map) {
167-
List<Command> alertCommands = new ArrayList<Command>();
167+
List<Command> alertCommands = new ArrayList<>();
168168
alertCommands.add(new DeployAlertConfigsCommand());
169169
alertCommands.add(new DeployAlertActionsCommand());
170170
alertCommands.add(new DeployAlertRulesCommand());
171171
map.put("mlAlertCommands", alertCommands);
172172

173-
List<Command> cpfCommands = new ArrayList<Command>();
173+
List<Command> cpfCommands = new ArrayList<>();
174174
cpfCommands.add(new DeployCpfConfigsCommand());
175175
cpfCommands.add(new DeployDomainsCommand());
176176
cpfCommands.add(new DeployPipelinesCommand());
@@ -180,7 +180,7 @@ private void addCommandsThatWriteToDatabases(Map<String, List<Command>> map) {
180180
dataCommands.add(new LoadDataCommand());
181181
map.put("mlDataCommands", dataCommands);
182182

183-
List<Command> flexrepCommands = new ArrayList<Command>();
183+
List<Command> flexrepCommands = new ArrayList<>();
184184
flexrepCommands.add(new DeployConfigsCommand());
185185
flexrepCommands.add(new DeployTargetsCommand());
186186
flexrepCommands.add(new DeployFlexrepCommand());
@@ -201,11 +201,11 @@ private void addCommandsThatWriteToDatabases(Map<String, List<Command>> map) {
201201
temporalCommands.add(new DeployTemporalCollectionsLSQTCommand());
202202
map.put("mlTemporalCommands", temporalCommands);
203203

204-
List<Command> triggerCommands = new ArrayList<Command>();
204+
List<Command> triggerCommands = new ArrayList<>();
205205
triggerCommands.add(new DeployTriggersCommand());
206206
map.put("mlTriggerCommands", triggerCommands);
207207

208-
List<Command> viewCommands = new ArrayList<Command>();
208+
List<Command> viewCommands = new ArrayList<>();
209209
viewCommands.add(new DeployViewSchemasCommand());
210210
map.put("mlViewCommands", viewCommands);
211211
}

src/main/java/com/marklogic/appdeployer/command/ResourceFilenameFilter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.marklogic.client.ext.helper.LoggingObject;
44

55
import java.io.File;
6+
import java.util.Arrays;
67
import java.util.HashSet;
78
import java.util.Set;
89
import java.util.regex.Pattern;
@@ -38,9 +39,7 @@ public ResourceFilenameFilter(ResourceFileManager resourceFileManager) {
3839
public ResourceFilenameFilter(String... filenamesToIgnore) {
3940
this();
4041
this.filenamesToIgnore = new HashSet<>();
41-
for (String f : filenamesToIgnore) {
42-
this.filenamesToIgnore.add(f);
43-
}
42+
this.filenamesToIgnore.addAll(Arrays.asList(filenamesToIgnore));
4443
}
4544

4645
public ResourceFilenameFilter(Set<String> filenamesToIgnore) {

src/main/java/com/marklogic/appdeployer/command/alert/DeployAlertRulesCommand.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.marklogic.appdeployer.command.alert;
22

3-
import java.io.File;
4-
53
import com.marklogic.appdeployer.AppConfig;
64
import com.marklogic.appdeployer.ConfigDir;
75
import com.marklogic.appdeployer.command.AbstractCommand;

src/main/java/com/marklogic/appdeployer/command/databases/DeployDatabaseCommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.marklogic.appdeployer.command.UndoableCommand;
99
import com.marklogic.appdeployer.command.forests.DeployForestsCommand;
1010
import com.marklogic.mgmt.PayloadParser;
11-
import com.marklogic.mgmt.SaveReceipt;
1211
import com.marklogic.mgmt.api.database.Database;
1312
import com.marklogic.mgmt.resource.databases.DatabaseManager;
1413

src/main/java/com/marklogic/appdeployer/command/databases/DeployOtherDatabasesCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ protected List<DatabasePlan> mergeDatabasePlanFiles(CommandContext context, Data
249249
ObjectReader objectReader = ObjectMapperFactory.getObjectMapper().readerFor(Database.class);
250250

251251
List<DatabasePlan> databasePlanList = new ArrayList<>();
252-
databasePlans.getDatabasePlanMap().values().forEach(ref -> databasePlanList.add(ref));
252+
databasePlanList.addAll(databasePlans.getDatabasePlanMap().values());
253253

254254
DatabasePlan testDatabasePlan = null;
255255

src/main/java/com/marklogic/appdeployer/command/databases/DeploySubDatabasesCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void execute(CommandContext context) {
3737
}
3838

3939
if (subdbDir.exists()) {
40-
List<String> subDbNames = new ArrayList<String>();
40+
List<String> subDbNames = new ArrayList<>();
4141
for (File subDatabaseFile : listFilesInDirectory(subdbDir)) {
4242
logger.info(format("Processing sub-database for %s found in file: %s", superDatabaseName, subDatabaseFile.getAbsolutePath()));
4343

src/main/java/com/marklogic/appdeployer/command/flexrep/DeployTargetsCommand.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
package com.marklogic.appdeployer.command.flexrep;
22

3-
import java.io.File;
4-
53
import com.marklogic.appdeployer.AppConfig;
64
import com.marklogic.appdeployer.ConfigDir;
75
import com.marklogic.appdeployer.command.AbstractCommand;
86
import com.marklogic.appdeployer.command.CommandContext;
97
import com.marklogic.appdeployer.command.SortOrderConstants;
10-
import com.marklogic.mgmt.ManageClient;
118
import com.marklogic.mgmt.SaveReceipt;
129
import com.marklogic.mgmt.resource.flexrep.TargetManager;
1310

1411
import java.io.File;
15-
import java.net.URI;
1612

1713
/**
1814
* The directory structure for this is a bit different from most command. Since targets belong to a certain flexrep

src/main/java/com/marklogic/appdeployer/command/forests/DistributedReplicaBuilderStrategy.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ public void buildReplicas(List<Forest> forests, ForestPlan forestPlan, AppConfig
2020
final List<String> hostNames = forestPlan.getReplicaHostNames();
2121
final int replicaCount = forestPlan.getReplicaCount();
2222

23-
HashMap<String, List<Forest>> hostToForests = new HashMap<String, List<Forest>>();
23+
HashMap<String, List<Forest>> hostToForests = new HashMap<>();
2424

2525
for (Forest f : forests) {
2626
String host = f.getHost();
2727
if (hostToForests.containsKey(host)) {
2828
hostToForests.get(host).add(f);
2929
}
3030
else {
31-
ArrayList<Forest> hostForests = new ArrayList<Forest>();
31+
ArrayList<Forest> hostForests = new ArrayList<>();
3232
hostForests.add(f);
3333
hostToForests.put(host, hostForests);
3434
}
@@ -41,7 +41,7 @@ public void buildReplicas(List<Forest> forests, ForestPlan forestPlan, AppConfig
4141
// the forest lives. We also want to have the hosts in different order as we assign replicas to hosts, so
4242
// that we don't overload any of them. So if we have five hosts, and we're looking to build replicas for
4343
// the forests on host 2, this list will be [host3, host4, host5, host1].
44-
List<String> availableHosts = new ArrayList<String>();
44+
List<String> availableHosts = new ArrayList<>();
4545
int hostIndex = hostNames.indexOf(host);
4646
if (hostIndex != -1 && hostIndex < hostNames.size()) {
4747
availableHosts.addAll(hostNames.subList(hostIndex + 1, hostNames.size()));

src/main/java/com/marklogic/appdeployer/command/forests/ForestBuilder.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,9 @@ protected Map<String, Map<String, List<Forest>>> existingForestsMap(ForestPlan f
125125
dataDirectory = "";
126126
}
127127

128-
Map<String, List<Forest>> dataDirectoryMap = existingForestsMap.get(host);
129-
if (dataDirectoryMap == null) {
130-
dataDirectoryMap = new LinkedHashMap<>();
131-
existingForestsMap.put(host, dataDirectoryMap);
132-
}
128+
Map<String, List<Forest>> dataDirectoryMap = existingForestsMap.computeIfAbsent(host, k -> new LinkedHashMap<>());
133129

134-
List<Forest> list = dataDirectoryMap.get(dataDirectory);
135-
if (list == null) {
136-
list = new ArrayList<>();
137-
dataDirectoryMap.put(dataDirectory, list);
138-
}
130+
List<Forest> list = dataDirectoryMap.computeIfAbsent(dataDirectory, k -> new ArrayList<>());
139131
list.add(f);
140132
}
141133
return existingForestsMap;
@@ -236,8 +228,7 @@ protected List<String> determineReplicaDataDirectories(ForestPlan forestPlan, Ap
236228
Map<String, List<String>> replicaDataDirectoryMap = appConfig.getDatabaseReplicaDataDirectories();
237229
final String databaseName = forestPlan.getDatabaseName();
238230
if (replicaDataDirectoryMap != null && replicaDataDirectoryMap.containsKey(databaseName)) {
239-
replicaDataDirectories = new ArrayList<>();
240-
replicaDataDirectories.addAll(replicaDataDirectoryMap.get(databaseName));
231+
replicaDataDirectories = new ArrayList<>(replicaDataDirectoryMap.get(databaseName));
241232
}
242233

243234
return replicaDataDirectories;

src/main/java/com/marklogic/appdeployer/command/forests/ForestNamingStrategy.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.marklogic.appdeployer.command.forests;
22

33
import com.marklogic.appdeployer.AppConfig;
4-
import com.marklogic.mgmt.api.forest.Forest;
54

65
public interface ForestNamingStrategy {
76

src/main/java/com/marklogic/appdeployer/command/hosts/AssignHostsToGroupsCommand.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
import com.marklogic.appdeployer.command.AbstractUndoableCommand;
66
import com.marklogic.appdeployer.command.CommandContext;
77
import com.marklogic.appdeployer.command.SortOrderConstants;
8-
import com.marklogic.mgmt.api.server.AppServicesServer;
9-
import com.marklogic.mgmt.api.server.ManageServer;
10-
import com.marklogic.mgmt.api.server.Server;
11-
import com.marklogic.mgmt.resource.appservers.ServerManager;
128
import com.marklogic.mgmt.resource.hosts.HostManager;
139

1410
public class AssignHostsToGroupsCommand extends AbstractUndoableCommand {

src/main/java/com/marklogic/appdeployer/command/modules/DeleteModulesCommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.marklogic.appdeployer.command.AbstractCommand;
55
import com.marklogic.appdeployer.command.CommandContext;
66
import com.marklogic.client.DatabaseClient;
7-
import com.marklogic.client.DatabaseClientFactory;
87

98
public class DeleteModulesCommand extends AbstractCommand {
109

src/main/java/com/marklogic/appdeployer/command/temporal/DeployTemporalCollectionsCommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.marklogic.appdeployer.command.CommandContext;
77
import com.marklogic.appdeployer.command.SortOrderConstants;
88
import com.marklogic.mgmt.resource.ResourceManager;
9-
import com.marklogic.mgmt.resource.temporal.TemporalAxesManager;
109
import com.marklogic.mgmt.resource.temporal.TemporalCollectionManager;
1110

1211
import java.io.File;

src/main/java/com/marklogic/appdeployer/command/triggers/DeployTriggersCommand.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import com.marklogic.appdeployer.command.AbstractResourceCommand;
66
import com.marklogic.appdeployer.command.CommandContext;
77
import com.marklogic.appdeployer.command.SortOrderConstants;
8-
import com.marklogic.mgmt.PayloadParser;
98
import com.marklogic.mgmt.resource.ResourceManager;
10-
import com.marklogic.mgmt.resource.databases.DatabaseManager;
119
import com.marklogic.mgmt.resource.triggers.TriggerManager;
1210

1311
import java.io.File;

src/main/java/com/marklogic/appdeployer/command/viewschemas/DeployViewSchemasCommand.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.marklogic.appdeployer.command.viewschemas;
22

3-
import java.io.File;
4-
53
import com.marklogic.appdeployer.AppConfig;
64
import com.marklogic.appdeployer.ConfigDir;
75
import com.marklogic.appdeployer.command.AbstractResourceCommand;

src/main/java/com/marklogic/appdeployer/export/Exporter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.marklogic.appdeployer.export.cpf.PipelineExporter;
77
import com.marklogic.appdeployer.export.databases.DatabaseExporter;
88
import com.marklogic.appdeployer.export.groups.GroupExporter;
9-
import com.marklogic.appdeployer.export.impl.AbstractNamedResourceExporter;
109
import com.marklogic.appdeployer.export.impl.CompositeResourceExporter;
1110
import com.marklogic.appdeployer.export.security.AmpExporter;
1211
import com.marklogic.appdeployer.export.security.PrivilegeExporter;

src/main/java/com/marklogic/appdeployer/export/impl/CompositeResourceExporter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.io.File;
99
import java.util.ArrayList;
10+
import java.util.Arrays;
1011
import java.util.List;
1112

1213
/**
@@ -21,9 +22,7 @@ public class CompositeResourceExporter extends LoggingObject implements Resource
2122

2223
public CompositeResourceExporter(ResourceExporter... resourceExporters) {
2324
this.resourceExporters = new ArrayList<>();
24-
for (ResourceExporter exporter : resourceExporters) {
25-
this.resourceExporters.add(exporter);
26-
}
25+
this.resourceExporters.addAll(Arrays.asList(resourceExporters));
2726
}
2827

2928
public void add(ResourceExporter exporter) {

src/main/java/com/marklogic/appdeployer/impl/AbstractAppDeployer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void undeploy(AppConfig appConfig) {
122122

123123
List<Command> commands = getCommands();
124124

125-
List<UndoableCommand> undoableCommands = new ArrayList<UndoableCommand>();
125+
List<UndoableCommand> undoableCommands = new ArrayList<>();
126126
for (Command command : commands) {
127127
if (command instanceof UndoableCommand) {
128128
undoableCommands.add((UndoableCommand) command);

src/main/java/com/marklogic/appdeployer/impl/SimpleAppDeployer.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.marklogic.mgmt.admin.AdminManager;
66

77
import java.util.ArrayList;
8+
import java.util.Arrays;
89
import java.util.List;
910

1011
/**
@@ -35,12 +36,10 @@ public SimpleAppDeployer(ManageClient manageClient, AdminManager adminManager, C
3536
*/
3637
protected void buildModifiableCommandList(Command... commandArray) {
3738
if (commandArray != null) {
38-
commands = new ArrayList<Command>(commandArray.length);
39-
for (Command c : commandArray) {
40-
commands.add(c);
41-
}
39+
commands = new ArrayList<>(commandArray.length);
40+
commands.addAll(Arrays.asList(commandArray));
4241
} else {
43-
commands = new ArrayList<Command>();
42+
commands = new ArrayList<>();
4443
}
4544
}
4645

src/main/java/com/marklogic/appdeployer/util/ModulesWatcher.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.marklogic.client.ext.modulesloader.impl.DefaultModulesLoader;
1313
import com.marklogic.mgmt.util.SystemPropertySource;
1414

15-
import java.io.File;
1615
import java.util.List;
1716

1817
/**

0 commit comments

Comments
 (0)