コード例 #1
0
ファイル: ServicesContribution.java プロジェクト: eclipse/edt
 @Override
 public void resourceChanged(IResourceChangeEvent event, final TestServerConfiguration config) {
   // We need to recalculate all the DD settings if even 1 DD file in the EGL path changed. It
   // could be that there
   // were duplicate settings among the files, and a setting that was included before has now been
   // changed/removed, so
   // the duplicate that was previously skipped needs to be used (replacing the setting on the
   // server).
   try {
     class RecomputeSettings extends RuntimeException {
       private static final long serialVersionUID = 1L;
     }; // For fast exit of delta visitor
     try {
       if (event.getDelta() != null) {
         event
             .getDelta()
             .accept(
                 new IResourceDeltaVisitor() {
                   @Override
                   public boolean visit(IResourceDelta delta) throws CoreException {
                     if (delta == null) {
                       return false;
                     }
                     switch (delta.getKind()) {
                       case IResourceDelta.CHANGED:
                         if ((delta.getFlags() & IResourceDelta.CONTENT) == 0
                             && (delta.getFlags() & IResourceDelta.ENCODING) == 0) {
                           // No actual change, skip it.
                           return true;
                         }
                         // Fall through.
                       case IResourceDelta.ADDED:
                       case IResourceDelta.REMOVED:
                         if ("egldd"
                                 .equalsIgnoreCase(
                                     delta.getFullPath().getFileExtension()) // $NON-NLS-1$
                             && config.isOnEGLPath(
                                 config.getProject(),
                                 delta.getResource().getProject(),
                                 new HashSet<IProject>())) {
                           throw new RecomputeSettings();
                         }
                         break;
                     }
                     return true;
                   }
                 });
       }
     } catch (RecomputeSettings e) {
       new Thread() {
         public void run() {
           updateDDSettingsOnServer(config);
         };
       }.start();
     }
   } catch (CoreException e) {
     TestServerPlugin.getDefault().log(e);
   }
 }
コード例 #2
0
ファイル: ServicesContribution.java プロジェクト: eclipse/edt
  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);
    }
  }