예제 #1
0
  @Override
  public String getArgumentAdditions(TestServerConfiguration config) {
    StringBuilder buf = new StringBuilder(100);

    buf.append(" -dd \""); // $NON-NLS-1$
    List<DDFile> ddFiles =
        DeploymentDescriptorFinder.findDeploymentDescriptors(config.getProject());
    buf.append(DeploymentDescriptorFinder.toArgumentString(ddFiles));

    buf.append("\" -ddd \""); // $NON-NLS-1$
    String defaultDDName = DeploymentDescriptorFinder.getDefaultDDName(config.getProject());
    buf.append(defaultDDName);

    String orderedDDNames = DeploymentDescriptorFinder.toOrderedArgumentString(ddFiles);
    buf.append("\" -odd \""); // $NON-NLS-1$
    buf.append(orderedDDNames);
    buf.append("\""); // $NON-NLS-1$

    synchronized (syncObj) {
      currentDDFiles.put(config, ddFiles);
      currentDefaultDDName.put(config, defaultDDName);
      currentDDNameOrder.put(config, orderedDDNames);
    }

    return buf.toString();
  }
예제 #2
0
  public synchronized void updateDDSettingsOnServer(TestServerConfiguration config) {
    String oldDDNameOrder;
    String oldDefaultDD;
    List<DDFile> oldDDs;

    synchronized (syncObj) {
      oldDefaultDD = currentDefaultDDName.get(config);
      oldDDNameOrder = currentDDNameOrder.get(config);
      oldDDs = currentDDFiles.get(config);
    }

    String defaultDD = DeploymentDescriptorFinder.getDefaultDDName(config.getProject());
    boolean defaultDDChanged = !oldDefaultDD.equals(defaultDD);

    // Iterate through, keep track of those that are no longer in the list, those that were already
    // in the list but have
    // changed, and those that are new to the list. Updates are treated as additions, and the server
    // will handle it appropriately.
    List<DDFile> newDDFiles =
        DeploymentDescriptorFinder.findDeploymentDescriptors(config.getProject());
    List<DDFile> addedOrChangedDDFiles = new ArrayList<DDFile>();
    List<DDFile> copyOfCurrentDDFiles = new ArrayList<DDFile>(oldDDs);
    for (DDFile next : newDDFiles) {
      int size = copyOfCurrentDDFiles.size();
      DDFile old = null;
      for (int i = 0; i < size; i++) {
        if (next.name.equals(copyOfCurrentDDFiles.get(i).name)) {
          old = copyOfCurrentDDFiles.remove(i);
          break;
        }
      }
      if (old == null || !old.equals(next)) {
        addedOrChangedDDFiles.add(next);
      }
    }

    String newDDNameOrder = DeploymentDescriptorFinder.toOrderedArgumentString(newDDFiles);
    boolean ddOrderChanged = !oldDDNameOrder.equals(newDDNameOrder);

    if (defaultDDChanged
        || ddOrderChanged
        || addedOrChangedDDFiles.size() > 0
        || copyOfCurrentDDFiles.size() > 0) {
      String addedDDArg = DeploymentDescriptorFinder.toArgumentString(addedOrChangedDDFiles);
      String removedDDArg =
          DeploymentDescriptorFinder.toArgumentString(
              copyOfCurrentDDFiles); // leftovers get removed

      StringBuilder args =
          new StringBuilder(
              addedDDArg.length()
                  + newDDNameOrder.length()
                  + removedDDArg.length()
                  + defaultDD.length()
                  + 50);
      if (addedDDArg.length() > 0) {
        if (args.length() > 0) {
          args.append('&');
        }
        args.append(ConfigServlet.ARG_DD_ADDED);
        args.append('=');
        args.append(addedDDArg);
      }
      if (removedDDArg.length() > 0) {
        if (args.length() > 0) {
          args.append('&');
        }
        args.append(ConfigServlet.ARG_DD_REMOVED);
        args.append('=');
        args.append(removedDDArg);
      }
      if (defaultDDChanged) {
        if (args.length() > 0) {
          args.append('&');
        }
        args.append(ConfigServlet.ARG_DEFAULT_DD);
        args.append('=');
        try {
          args.append(URLEncoder.encode(defaultDD, "UTF-8")); // $NON-NLS-1$
        } catch (UnsupportedEncodingException e) {
          // Shouldn't happen.
          args.append(defaultDD);
        }
      }
      if (ddOrderChanged) {
        if (args.length() > 0) {
          args.append('&');
        }
        args.append(ConfigServlet.ARG_ORDERED_DDS);
        args.append('=');
        try {
          args.append(URLEncoder.encode(newDDNameOrder, "UTF-8")); // $NON-NLS-1$
        } catch (UnsupportedEncodingException e) {
          // Shouldn't happen.
          args.append(newDDNameOrder);
        }
      }

      try {
        int status = config.invokeServlet(ConfigServlet.SERVLET_PATH, args.toString());
        if (status != 200) {
          TestServerPlugin.getDefault().log(NLS.bind(Messages.ConfigServletBadStatus, status));
        }
      } catch (IOException e) {
        TestServerPlugin.getDefault().log(e);
      }
    }

    synchronized (syncObj) {
      currentDDNameOrder.put(config, newDDNameOrder);
      currentDDFiles.put(config, newDDFiles);
      currentDefaultDDName.put(config, defaultDD);
    }
  }