4444import org .scijava .log .Logger ;
4545import org .scijava .plugin .Parameter ;
4646import org .scijava .plugin .Plugin ;
47+ import org .scijava .ui .DialogPrompt ;
48+ import org .scijava .ui .UIService ;
4749
4850/**
4951 * SciJava command wrapper to build a Python environment.
@@ -65,13 +67,31 @@ public class RebuildEnvironment implements Command {
6567 @ Parameter (label = "Target directory" )
6668 private File targetDir ;
6769
70+ @ Parameter (required = false )
71+ private UIService uiService ;
72+
6873 // -- OptionsPython methods --
6974
7075 @ Override
7176 public void run () {
7277 final File backupDir = new File (targetDir .getPath () + ".old" );
78+ if (targetDir .exists ()) {
79+ boolean confirmed = true ;
80+ if (uiService != null ) {
81+ String msg =
82+ "The environment directory already exists. If you continue, it will be renamed to '" +
83+ backupDir .getName () +
84+ "' (and any previous backup will be deleted). Continue?" ;
85+ DialogPrompt .Result result = uiService .showDialog (msg ,
86+ "Confirm Environment Rebuild" ,
87+ DialogPrompt .MessageType .QUESTION_MESSAGE ,
88+ DialogPrompt .OptionType .YES_NO_OPTION );
89+ confirmed = result == DialogPrompt .Result .YES_OPTION ;
90+ }
91+ if (!confirmed ) return ;
92+ }
93+ // Delete the previous backup environment recursively.
7394 if (backupDir .exists ()) {
74- // Delete the previous backup environment recursively.
7595 try (Stream <Path > x = Files .walk (backupDir .toPath ())) {
7696 x .sorted (Comparator .reverseOrder ()).forEach (p -> {
7797 try {
0 commit comments