Skip to content

Commit c7b006f

Browse files
committed
Refactors Deployment to use dependency injection
1 parent 764b534 commit c7b006f

9 files changed

Lines changed: 68 additions & 34 deletions

ui/src/main/java/edu/wpi/grip/ui/DeployerController.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33

44
import com.google.common.base.Throwables;
5-
import com.google.common.eventbus.EventBus;
65
import com.google.inject.Inject;
7-
import com.google.inject.Singleton;
86
import edu.wpi.grip.ui.annotations.ParametrizedController;
97
import edu.wpi.grip.ui.components.StartStoppableButton;
108
import edu.wpi.grip.ui.deployment.DeploymentOptionsController;
@@ -24,7 +22,6 @@
2422
import java.util.function.Supplier;
2523
import java.util.stream.Collectors;
2624

27-
@Singleton
2825
@ParametrizedController(url = "DeployerPane.fxml")
2926
public class DeployerController {
3027

@@ -46,7 +43,6 @@ public class DeployerController {
4643
@FXML
4744
private ProgressBar progressIndicator;
4845

49-
private final EventBus eventBus;
5046
private final StartStoppableButton.Factory startStopButtonFactory;
5147
private final DeploymentOptionsControllersFactory optionsControllersFactory;
5248

@@ -74,8 +70,7 @@ public interface Factory {
7470
}
7571

7672
@Inject
77-
DeployerController(EventBus eventBus, StartStoppableButton.Factory startStopButtonFactory, DeploymentOptionsControllersFactory optionsControllersFactory) {
78-
this.eventBus = eventBus;
73+
DeployerController(StartStoppableButton.Factory startStopButtonFactory, DeploymentOptionsControllersFactory optionsControllersFactory) {
7974
this.startStopButtonFactory = startStopButtonFactory;
8075
this.optionsControllersFactory = optionsControllersFactory;
8176
}

ui/src/main/java/edu/wpi/grip/ui/GRIPUIModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import edu.wpi.grip.core.Source;
1111
import edu.wpi.grip.ui.annotations.ParametrizedController;
1212
import edu.wpi.grip.ui.components.StartStoppableButton;
13+
import edu.wpi.grip.ui.deployment.FRCAdvancedDeploymentOptionsController;
14+
import edu.wpi.grip.ui.deployment.FRCDeploymentOptionsController;
1315
import edu.wpi.grip.ui.pipeline.OutputSocketController;
1416
import edu.wpi.grip.ui.pipeline.SocketHandleView;
1517
import edu.wpi.grip.ui.pipeline.StepController;
@@ -68,6 +70,9 @@ public <I> void hear(final TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEnco
6870
install(new FactoryModuleBuilder().build(OperationController.Factory.class));
6971
install(new FactoryModuleBuilder().build(SocketHandleView.Factory.class));
7072
install(new FactoryModuleBuilder().build(OutputSocketController.Factory.class));
73+
install(new FactoryModuleBuilder().build(DeployerController.Factory.class));
74+
install(new FactoryModuleBuilder().build(FRCDeploymentOptionsController.Factory.class));
75+
install(new FactoryModuleBuilder().build(FRCAdvancedDeploymentOptionsController.Factory.class));
7176
// End arbitrary controllers
7277

7378
// InputSocketController Factories

ui/src/main/java/edu/wpi/grip/ui/deployment/DeploymentOptionsController.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package edu.wpi.grip.ui.deployment;
22

3+
import edu.wpi.grip.ui.annotations.ParametrizedController;
34
import edu.wpi.grip.ui.util.SupplierWithIO;
45
import edu.wpi.grip.ui.util.deployment.DeployedInstanceManager;
56
import javafx.application.Platform;
67
import javafx.fxml.FXML;
7-
import javafx.fxml.FXMLLoader;
88
import javafx.scene.control.Button;
99
import javafx.scene.control.Label;
1010
import javafx.scene.control.ProgressIndicator;
@@ -19,6 +19,7 @@
1919
import java.net.InetAddress;
2020
import java.util.function.Consumer;
2121

22+
@ParametrizedController(url = "DeploymentOptions.fxml")
2223
public abstract class DeploymentOptionsController {
2324

2425
@FXML
@@ -39,14 +40,9 @@ public abstract class DeploymentOptionsController {
3940
private final String title;
4041
private final Consumer<DeployedInstanceManager> onDeployCallback;
4142

42-
protected DeploymentOptionsController(String title, Consumer<DeployedInstanceManager> onDeployCallback) {
43+
DeploymentOptionsController(String title, Consumer<DeployedInstanceManager> onDeployCallback) {
4344
this.title = title;
4445
this.onDeployCallback = onDeployCallback;
45-
try {
46-
FXMLLoader.load(DeploymentOptionsController.class.getResource("DeploymentOptions.fxml"), null, null, c -> this);
47-
} catch (IOException e) {
48-
throw new IllegalStateException("Could not load FXML", e);
49-
}
5046
}
5147

5248
@FXML
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package edu.wpi.grip.ui.deployment;
22

33

4+
import com.google.inject.Inject;
5+
import com.google.inject.Singleton;
46
import edu.wpi.grip.ui.util.deployment.DeployedInstanceManager;
57

68
import java.io.OutputStream;
@@ -9,19 +11,25 @@
911
import java.util.function.Consumer;
1012
import java.util.function.Supplier;
1113

14+
@Singleton
1215
public class DeploymentOptionsControllersFactory {
1316

14-
private final DeployedInstanceManager.Factory deployedInstanceManagerFactory;
17+
private final FRCDeploymentOptionsController.Factory frcDeploymentOptionsControllerFactory;
18+
private final FRCAdvancedDeploymentOptionsController.Factory frcAdvancedDeploymentOptionsControllerFactory;
1519

16-
public DeploymentOptionsControllersFactory(DeployedInstanceManager.Factory deployedInstanceManagerFactory) {
17-
this.deployedInstanceManagerFactory = deployedInstanceManagerFactory;
20+
@Inject
21+
DeploymentOptionsControllersFactory(
22+
FRCDeploymentOptionsController.Factory frcDeploymentOptionsControllerFactory,
23+
FRCAdvancedDeploymentOptionsController.Factory frcAdvancedDeploymentOptionsControllerFactory) {
24+
this.frcDeploymentOptionsControllerFactory = frcDeploymentOptionsControllerFactory;
25+
this.frcAdvancedDeploymentOptionsControllerFactory = frcAdvancedDeploymentOptionsControllerFactory;
1826
}
1927

2028

2129
public Collection<DeploymentOptionsController> createControllers(Consumer<DeployedInstanceManager> onDeployCallback, Supplier<OutputStream> stdOut, Supplier<OutputStream> stdErr) {
2230
return Arrays.asList(
23-
new FRCDeploymentOptionsController(deployedInstanceManagerFactory, onDeployCallback, stdOut, stdErr),
24-
new FRCAdvancedDeployment(deployedInstanceManagerFactory, onDeployCallback, stdOut, stdErr)
31+
frcDeploymentOptionsControllerFactory.create(onDeployCallback, stdOut, stdErr),
32+
frcAdvancedDeploymentOptionsControllerFactory.create(onDeployCallback, stdOut, stdErr)
2533
);
2634
}
2735
}

ui/src/main/java/edu/wpi/grip/ui/deployment/FRCAdvancedDeployment.java renamed to ui/src/main/java/edu/wpi/grip/ui/deployment/FRCAdvancedDeploymentOptionsController.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package edu.wpi.grip.ui.deployment;
22

3+
import com.google.inject.Inject;
4+
import com.google.inject.assistedinject.Assisted;
35
import edu.wpi.grip.ui.util.deployment.DeployedInstanceManager;
46
import javafx.scene.control.Label;
57
import javafx.scene.control.TextField;
@@ -12,18 +14,27 @@
1214
import java.util.function.Consumer;
1315
import java.util.function.Supplier;
1416

15-
public class FRCAdvancedDeployment extends DeploymentOptionsController {
17+
public class FRCAdvancedDeploymentOptionsController extends DeploymentOptionsController {
1618

1719

1820
private final DeployedInstanceManager.Factory deployedInstanceManagerFactor;
1921
private final Supplier<OutputStream> stdOut, stdErr;
2022

2123
private TextField address;
2224

23-
protected FRCAdvancedDeployment(DeployedInstanceManager.Factory deployedInstanceManagerFactor,
24-
Consumer<DeployedInstanceManager> onDeployCallback,
25-
Supplier<OutputStream> stdOut,
26-
Supplier<OutputStream> stdErr) {
25+
public interface Factory {
26+
FRCAdvancedDeploymentOptionsController create(
27+
Consumer<DeployedInstanceManager> onDeployCallback,
28+
@Assisted("stdOut") Supplier<OutputStream> stdOut,
29+
@Assisted("stdErr") Supplier<OutputStream> stdErr
30+
);
31+
}
32+
33+
@Inject
34+
FRCAdvancedDeploymentOptionsController(DeployedInstanceManager.Factory deployedInstanceManagerFactor,
35+
@Assisted Consumer<DeployedInstanceManager> onDeployCallback,
36+
@Assisted("stdOut") Supplier<OutputStream> stdOut,
37+
@Assisted("stdErr") Supplier<OutputStream> stdErr) {
2738
super("FRC Advanced", onDeployCallback);
2839
this.deployedInstanceManagerFactor = deployedInstanceManagerFactor;
2940
this.stdOut = stdOut;

ui/src/main/java/edu/wpi/grip/ui/deployment/FRCDeploymentOptionsController.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package edu.wpi.grip.ui.deployment;
22

3+
import com.google.inject.Inject;
4+
import com.google.inject.assistedinject.Assisted;
35
import edu.wpi.grip.ui.util.deployment.DeployedInstanceManager;
46
import javafx.scene.control.Label;
57
import javafx.scene.control.Spinner;
@@ -21,10 +23,19 @@ public class FRCDeploymentOptionsController extends DeploymentOptionsController
2123
private final DeployedInstanceManager.Factory deployedInstanceManagerFactor;
2224
private final Supplier<OutputStream> stdOut, stdErr;
2325

24-
protected FRCDeploymentOptionsController(DeployedInstanceManager.Factory deployedInstanceManagerFactor,
25-
Consumer<DeployedInstanceManager> onDeployCallback,
26-
Supplier<OutputStream> stdOut,
27-
Supplier<OutputStream> stdErr) {
26+
public interface Factory {
27+
FRCDeploymentOptionsController create(
28+
Consumer<DeployedInstanceManager> onDeployCallback,
29+
@Assisted("stdOut") Supplier<OutputStream> stdOut,
30+
@Assisted("stdErr") Supplier<OutputStream> stdErr
31+
);
32+
}
33+
34+
@Inject
35+
FRCDeploymentOptionsController(DeployedInstanceManager.Factory deployedInstanceManagerFactor,
36+
@Assisted Consumer<DeployedInstanceManager> onDeployCallback,
37+
@Assisted("stdOut") Supplier<OutputStream> stdOut,
38+
@Assisted("stdErr") Supplier<OutputStream> stdErr) {
2839
super("FRC", onDeployCallback);
2940
this.deployedInstanceManagerFactor = deployedInstanceManagerFactor;
3041
this.stdOut = stdOut;

ui/src/main/java/edu/wpi/grip/ui/util/deployment/DeployedInstanceManager.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33

44
import com.google.common.eventbus.EventBus;
5+
import com.google.inject.Inject;
6+
import com.google.inject.Singleton;
57
import com.jcabi.ssh.Shell;
68
import com.jcraft.jsch.JSch;
79
import edu.wpi.grip.core.StartStoppable;
@@ -43,14 +45,20 @@ public class DeployedInstanceManager implements StartStoppable {
4345
private final Supplier<OutputStream> stdErr;
4446
private Optional<Thread> sshThread;
4547

48+
@Singleton
4649
public static class Factory {
4750
private final EventBus eventBus;
4851
private final File coreJAR;
4952
private final Project project;
5053
private final SecureShellDetails.Factory secureShellDetailsFactory;
5154
private final DeploymentCommands.Factory deploymentCommandsFactory;
5255

53-
public Factory(EventBus eventBus, Project project, SecureShellDetails.Factory secureShellDetailsFactory, DeploymentCommands.Factory deploymentCommandsFactory) {
56+
@Inject
57+
public Factory(
58+
EventBus eventBus,
59+
Project project,
60+
SecureShellDetails.Factory secureShellDetailsFactory,
61+
DeploymentCommands.Factory deploymentCommandsFactory) {
5462
this.eventBus = eventBus;
5563
try {
5664
this.coreJAR = new File(edu.wpi.grip.core.Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
@@ -62,10 +70,6 @@ public Factory(EventBus eventBus, Project project, SecureShellDetails.Factory se
6270
this.deploymentCommandsFactory = deploymentCommandsFactory;
6371
}
6472

65-
public Factory(EventBus eventBus, Project project) {
66-
this(eventBus, project, new SecureShellDetails.Factory(), new DeploymentCommands.Factory());
67-
}
68-
6973
public DeployedInstanceManager createFRC(InetAddress address) {
7074
return createFRC(address, NullOutputStream::new, NullOutputStream::new);
7175
}
@@ -93,7 +97,7 @@ public DeployedInstanceManager createFRC(InetAddress addresses, File projectFile
9397
* @param stdOut Supplies the stream to be used for the standard output from the ssh command
9498
* @param stdErr Supplies the stream to be used for the standard error from the ssh command
9599
*/
96-
public DeployedInstanceManager(EventBus eventBus,
100+
private DeployedInstanceManager(EventBus eventBus,
97101
File coreJar,
98102
File projectFile,
99103
SecureShellDetails details,

ui/src/main/java/edu/wpi/grip/ui/util/deployment/DeploymentCommands.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package edu.wpi.grip.ui.util.deployment;
22

33

4+
import com.google.inject.Singleton;
5+
46
import java.util.function.Function;
57

68
import static com.google.common.base.Preconditions.checkNotNull;
@@ -17,8 +19,8 @@ public class DeploymentCommands {
1719
private final String javaCommand;
1820
private final Function<String, String> killByNameCommand;
1921

22+
@Singleton
2023
public static class Factory {
21-
2224
public DeploymentCommands createFRC() {
2325
return new DeploymentCommands("/usr/local/frc/JRE/bin/java", DEFAULT_KILL_BY_NAME);
2426
}

ui/src/main/java/edu/wpi/grip/ui/util/deployment/SecureShellDetails.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package edu.wpi.grip.ui.util.deployment;
22

3+
import com.google.inject.Singleton;
34
import com.jcabi.ssh.SSHByPassword;
45
import com.jcabi.ssh.Shell;
56
import org.apache.tools.ant.Project;
@@ -23,6 +24,7 @@ public class SecureShellDetails {
2324
private final Optional<String> remoteDir;
2425
private final int port;
2526

27+
@Singleton
2628
public static class Factory {
2729
SecureShellDetails createFRC(InetAddress address) {
2830
return new SecureShellDetails("lvuser", address.getHostAddress());

0 commit comments

Comments
 (0)