private static void saveRestartFile(File file, Annotation annotation) {
   try {
     Resource resource =
         SetupCoreUtil.createResourceSet().createResource(URI.createFileURI(file.toString()));
     resource.getContents().add(annotation);
     resource.save(null);
   } catch (Exception ex) {
     // Ignore
   }
 }
Пример #2
0
 protected void init() {
   ResourceSet resourceSet = SetupCoreUtil.createResourceSet();
   resource = resourceSet.createResource(URI.createURI("*.setup"));
 }
  private static void performStartup(final IWorkbench workbench, IProgressMonitor monitor) {
    monitor.beginTask("", 105);
    Trigger trigger = Trigger.STARTUP;
    boolean restarting = false;
    Set<URI> neededRestartTasks = new HashSet<URI>();

    try {
      File restartingFile = getRestartingFile();
      if (restartingFile.exists()) {
        monitor.setTaskName("Loading restart tasks " + restartingFile);
        Resource resource =
            SetupCoreUtil.createResourceSet()
                .getResource(URI.createFileURI(restartingFile.toString()), true);

        Annotation annotation =
            (Annotation)
                EcoreUtil.getObjectByType(resource.getContents(), BasePackage.Literals.ANNOTATION);
        resource.getContents().remove(annotation);

        if (ANNOTATION_SOURCE_INITIAL.equals(annotation.getSource())) {
          if ("true".equals(annotation.getDetails().get(ANNOTATION_DETAILS_KEY_OFFLINE))) {
            System.setProperty(SetupProperties.PROP_SETUP_OFFLINE_STARTUP, "true");
          }

          if ("true".equals(annotation.getDetails().get(ANNOTATION_DETAILS_KEY_MIRRORS))) {
            System.setProperty(SetupProperties.PROP_SETUP_MIRRORS_STARTUP, "true");
          }
        } else {
          for (EObject eObject : annotation.getReferences()) {
            neededRestartTasks.add(EcoreUtil.getURI(eObject));
          }

          trigger = Trigger.get(annotation.getSource());
          restarting = true;
        }

        IOUtil.deleteBestEffort(restartingFile);
      }
    } catch (Exception ex) {
      // Ignore
    }

    monitor.worked(1);

    // Disabled for bug 459486:
    // if (!QUESTIONNAIRE_SKIP)
    // {
    // Questionnaire.perform(UIUtil.getShell(), false);
    // }

    // This performer is only used to detect a need to update or to open the setup wizard.
    SetupTaskPerformer performer = null;
    final ResourceSet resourceSet = SetupCoreUtil.createResourceSet();

    SynchronizationController synchronizationController = null;

    try {
      synchronizationController = SynchronizerManager.INSTANCE.startSynchronization(false);
    } catch (Exception ex) {
      INSTANCE.log(ex);
    }

    monitor.setTaskName("Creating a setup task performer");

    try {
      // Ensure that the demand created resources for the installation, workspace, and user are
      // loaded and created.
      // Load the resource set quickly without doing ETag checking.
      resourceSet
          .getLoadOptions()
          .put(ECFURIHandlerImpl.OPTION_CACHE_HANDLING, CacheHandling.CACHE_WITHOUT_ETAG_CHECKING);
      mirror(resourceSet, monitor, 25);

      // Check the installation and workspace resources for cross references.
      // This unloads the cross referenced resources and returns the container objects of the root
      // object(s) of those resources.
      Set<EObject> eContainers = new HashSet<EObject>();
      eContainers.addAll(checkCrossReferences(resourceSet, SetupContext.INSTALLATION_SETUP_URI));
      eContainers.addAll(checkCrossReferences(resourceSet, SetupContext.WORKSPACE_SETUP_URI));

      if (!eContainers.isEmpty()) {
        // Reload any resources that have been unloaded, this time with ETag checking.
        resourceSet
            .getLoadOptions()
            .put(ECFURIHandlerImpl.OPTION_CACHE_HANDLING, CacheHandling.CACHE_WITH_ETAG_CHECKING);
        mirror(resourceSet, monitor, 75);

        // Resolve the containment proxies of the containers.
        for (EObject eContainer : eContainers) {
          for (@SuppressWarnings("unused") EObject eObject : eContainer.eContents()) {
            // Resolve all containment proxies.
          }
        }
      } else {
        monitor.worked(75);
      }

      try {
        if (synchronizationController != null) {
          Synchronization synchronization = synchronizationController.await();
          if (synchronization != null) {
            SynchronizerManager.INSTANCE.performSynchronization(synchronization, true, true);
          }
        }
      } catch (Exception ex) {
        INSTANCE.log(ex);
      }

      // Create the performer with a fully populated resource set.
      performer = SetupTaskPerformer.createForIDE(resourceSet, SetupPrompter.CANCEL, trigger);
    } catch (OperationCanceledException ex) {
      // $FALL-THROUGH$
    } catch (Throwable ex) {
      INSTANCE.log(ex);
      return;
    } finally {
      SetupContext.setSelf(SetupContext.createSelf(resourceSet));
    }

    monitor.worked(1);

    if (performer != null) {
      monitor.setTaskName("Initializing the setup task performer");

      try {
        // At this point we know that no prompt was needed.
        EList<SetupTask> neededTasks =
            performer.initNeededSetupTasks(new SubProgressMonitor(monitor, 2));
        if (restarting) {
          for (Iterator<SetupTask> it = neededTasks.iterator(); it.hasNext(); ) {
            SetupTask setupTask = it.next();
            if (setupTask.getPriority() == SetupTask.PRIORITY_INSTALLATION
                || !neededRestartTasks.contains(EcoreUtil.getURI(setupTask))) {
              it.remove();
            }
          }
        }

        if (neededTasks.isEmpty()) {
          // No tasks are needed, either. Nothing to do.
          return;
        }

        performer.setSkipConfirmation(true);
      } catch (Throwable ex) {
        INSTANCE.log(ex);
        return;
      }
    } else {
      monitor.worked(2);
    }

    monitor.worked(1);
    monitor.setTaskName("Launching the setup wizard");

    final SetupTaskPerformer finalPerfomer = performer;
    UIUtil.asyncExec(
        new Runnable() {
          public void run() {
            if (finalPerfomer != null) {
              resourceSet.getResources().add(finalPerfomer.getUser().eResource());
            }

            IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
            if (workbenchWindow == null) {
              workbenchWindow = workbench.getWorkbenchWindows()[0];
            }

            SetupWizard updater =
                finalPerfomer != null
                    ? new SetupWizard.Updater(finalPerfomer)
                    : new SetupWizard.Updater(
                        SetupContext.createInstallationWorkspaceAndUser(resourceSet));
            updater.openDialog(workbenchWindow.getShell());
          }
        });

    monitor.worked(1);
  }