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

Commit c7a1d89

Browse files
committed
#118 Can easily remove a command now
1 parent 7024b3a commit c7a1d89

File tree

3 files changed

+93
-68
lines changed

3 files changed

+93
-68
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
group=com.marklogic
22
javadocsDir=../gh-pages-marklogic-java/javadocs
3-
version=2.3.2
3+
version=2.4.0
Lines changed: 84 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,104 @@
11
package com.marklogic.appdeployer.impl;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
5-
63
import com.marklogic.appdeployer.command.Command;
74
import com.marklogic.mgmt.ManageClient;
85
import com.marklogic.mgmt.admin.AdminManager;
96

7+
import java.util.ArrayList;
8+
import java.util.List;
9+
1010
/**
1111
* Simple implementation that allows for a list of commands to be set.
1212
*/
1313
public class SimpleAppDeployer extends AbstractAppDeployer {
1414

15-
private List<Command> commands;
15+
private List<Command> commands;
16+
17+
public SimpleAppDeployer(Command... commandArray) {
18+
super();
19+
buildModifiableCommandList(commandArray);
20+
}
1621

17-
public SimpleAppDeployer(Command... commandArray) {
18-
super();
19-
buildModifiableCommandList(commandArray);
20-
}
22+
public SimpleAppDeployer(ManageClient manageClient, AdminManager adminManager, Command... commandArray) {
23+
super(manageClient, adminManager);
24+
buildModifiableCommandList(commandArray);
25+
}
2126

22-
public SimpleAppDeployer(ManageClient manageClient, AdminManager adminManager, Command... commandArray) {
23-
super(manageClient, adminManager);
24-
buildModifiableCommandList(commandArray);
25-
}
27+
/**
28+
* Arrays.asList produces an unmodifiable list, but we want a client to be able to modify the list.
29+
*
30+
* @param commandArray
31+
*/
32+
protected void buildModifiableCommandList(Command... commandArray) {
33+
if (commandArray != null) {
34+
commands = new ArrayList<Command>(commandArray.length);
35+
for (Command c : commandArray) {
36+
commands.add(c);
37+
}
38+
} else {
39+
commands = new ArrayList<Command>();
40+
}
41+
}
2642

27-
/**
28-
* Arrays.asList produces an unmodifiable list, but we want a client to be able to modify the list.
29-
*
30-
* @param commandArray
31-
*/
32-
protected void buildModifiableCommandList(Command... commandArray) {
33-
if (commandArray != null) {
34-
commands = new ArrayList<Command>(commandArray.length);
35-
for (Command c : commandArray) {
36-
commands.add(c);
37-
}
38-
} else {
39-
commands = new ArrayList<Command>();
40-
}
41-
}
43+
/**
44+
* Convenience method for finding a command of a certain type, presumably so it can be modified/reconfigured.
45+
*
46+
* @param clazz
47+
* @return
48+
*/
49+
public Command getCommandOfType(Class<?> clazz) {
50+
for (Command c : commands) {
51+
if (c.getClass().equals(clazz)) {
52+
return c;
53+
}
54+
}
55+
return null;
56+
}
4257

43-
/**
44-
* Convenience method for finding a command of a certain type, presumably so it can be modified/reconfigured.
45-
*
46-
* @param clazz
47-
* @return
48-
*/
49-
public Command getCommandOfType(Class<?> clazz) {
50-
for (Command c : commands) {
51-
if (c.getClass().equals(clazz)) {
52-
return c;
53-
}
54-
}
55-
return null;
56-
}
58+
/**
59+
* Convenience method for finding a command with the given short class name (i.e. no package info in it), presumably so it can be
60+
* modified/reconfigured.
61+
*
62+
* @param shortClassName
63+
* @return
64+
*/
65+
public Command getCommand(String shortClassName) {
66+
for (Command c : commands) {
67+
if (c.getClass().getSimpleName().equals(shortClassName)) {
68+
return c;
69+
}
70+
}
71+
return null;
72+
}
5773

58-
/**
59-
* Convenience method for finding a command with the given class name, presumably so it can be
60-
* modified/reconfigured.
61-
*
62-
* @param className
63-
* @return
64-
*/
65-
public Command getCommand(String className) {
66-
for (Command c : commands) {
67-
if (c.getClass().getSimpleName().equals(className)) {
68-
return c;
69-
}
70-
}
71-
return null;
72-
}
74+
/**
75+
* Remove the first command that has the same short class name as the given argument, and return it
76+
* if it's removed.
77+
*
78+
* @param shortClassName
79+
* @return
80+
*/
81+
public Command removeCommand(String shortClassName) {
82+
for (Command c : commands) {
83+
if (c.getClass().getSimpleName().equals(shortClassName)) {
84+
commands.remove(c);
85+
return c;
86+
}
87+
}
88+
return null;
89+
}
7390

74-
/**
75-
* Keep this public so that a client can easily manipulate the list in case a default set of commands has been
76-
* provided.
77-
*/
78-
@Override
79-
public List<Command> getCommands() {
80-
return commands;
81-
}
91+
/**
92+
* Keep this public so that a client can easily manipulate the list in case a default set of commands has been
93+
* provided.
94+
*/
95+
@Override
96+
public List<Command> getCommands() {
97+
return commands;
98+
}
8299

83-
public void setCommands(List<Command> commands) {
84-
this.commands = commands;
85-
}
100+
public void setCommands(List<Command> commands) {
101+
this.commands = commands;
102+
}
86103

87104
}

src/test/java/com/marklogic/appdeployer/impl/SimpleAppDeployerTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,12 @@ public void getCommand() {
3434
assertEquals(dbCommand, deployer.getCommand("DeployContentDatabasesCommand"));
3535
assertNull(deployer.getCommand("SomeOtherCommand"));
3636
}
37+
38+
@Test
39+
public void removeCommand() {
40+
assertEquals(restApiCommand, deployer.removeCommand("DeployRestApiServersCommand"));
41+
assertEquals(1, deployer.getCommands().size());
42+
assertEquals(dbCommand, deployer.removeCommand("DeployContentDatabasesCommand"));
43+
assertTrue(deployer.getCommands().isEmpty());
44+
}
3745
}

0 commit comments

Comments
 (0)