/**
  * Adds the connections between two boxes.
  *
  * @param nameBox1 Name of the upper box.
  * @param nameBox2 Name of the lower box.
  */
 public void addConnection(String nameBox1, String nameBox2) {
   for (Box box1 : this.boxes) {
     if (box1.getName().equals(nameBox1)) {
       for (Box box2 : this.boxes) {
         if (box2.getName().equals(nameBox2)) {
           box1.addBoxUnder(box2);
           box2.addBoxAbove(box1);
         }
       }
     }
   }
 }
 /**
  * Removes a box from the list if it's a top box.
  *
  * @param box The box to remove from the list.
  */
 public void remove(Box box) {
   if (box.isTopBox()) {
     box.destroy(); /* Removes all connections to and from the box */
     boxes.remove(box); /* Removes box from the list */
     return;
   }
   System.err.println("Box " + box.getName() + " is not on the top.");
 }
Example #3
0
  public void ensureBoxExists(Box box) {
    for (String boxName : vagrant.execute(new ListBoxes())) {
      if (boxName.equals(box.getName())) {
        return;
      }
    }

    File oldWorkingDir = sh.getWorkingDir();
    try {
      sh.setWorkingDir(File.createTempFile("ignore", "").getParentFile());

      vagrant.execute(new AddBox(box));

      sh.setWorkingDir(oldWorkingDir);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }