public void testWorkspaceResolutionOfInterModuleDependenciesDuringImport() throws Exception {
   String oldSettings = mavenConfiguration.getUserSettingsFile();
   try {
     injectFilexWagon();
     FilexWagon.setRequestFilterPattern("test/.*", true);
     IJobChangeListener jobChangeListener =
         new JobChangeAdapter() {
           public void scheduled(IJobChangeEvent event) {
             if (event.getJob() instanceof ProjectRegistryRefreshJob) {
               // cancel all those concurrent refresh jobs, we want to monitor the main thread only
               event.getJob().cancel();
             }
           }
         };
     Job.getJobManager().addJobChangeListener(jobChangeListener);
     mavenConfiguration.setUserSettingsFile(
         new File("projects/MNGECLIPSE-1990/settings.xml").getAbsolutePath());
     List<String> requests;
     try {
       importProjects(
           "projects/MNGECLIPSE-1990",
           new String[] {"pom.xml", "dependent/pom.xml", "dependency/pom.xml", "parent/pom.xml"},
           new ResolverConfiguration());
       requests = FilexWagon.getRequests();
     } finally {
       Job.getJobManager().removeJobChangeListener(jobChangeListener);
     }
     assertTrue(
         "Dependency resolution was attempted from remote repository: " + requests,
         requests.isEmpty());
   } finally {
     mavenConfiguration.setUserSettingsFile(oldSettings);
   }
 }
 public void stop(BundleContext bundleContext) throws Exception {
   try {
     // cancel any repository load jobs started in the UI
     Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
     // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=305163
     // join the jobs so that this bundle does not stop until the jobs are
     // actually cancelled.
     Job.getJobManager().join(LoadMetadataRepositoryJob.LOAD_FAMILY, new NullProgressMonitor());
     plugin = null;
     ProvUIActivator.context = null;
     ui = null;
   } finally {
     super.stop(bundleContext);
   }
 }
Example #3
0
 private void waitForWorkspaceLock(IProgressMonitor monitor) {
   // Wait for the workspace lock to avoid starting the calculation
   // of an IndexDiff while the workspace changes (e.g. due to a
   // branch switch).
   // The index diff calculation jobs do not lock the workspace
   // during execution to avoid blocking the workspace.
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   try {
     Job.getJobManager().beginRule(root, monitor);
   } catch (OperationCanceledException e) {
     return;
   } finally {
     Job.getJobManager().endRule(root);
   }
 }
  @Test
  public void addDependencyWithRepo() throws Exception {
    // This test uses more 'controlled' parameters:
    String bootVersion = BOOT_1_3_X_RELEASE;
    IProject project =
        harness.createBootProject(
            "foo",
            bootVersion(bootVersion), // boot version fixed
            withStarters("web"));

    initializr.setInputs(
        "sample-with-fakes"); // must use 'fake' data because the situation we are after doesn't
                              // exist in the real data

    EditStartersModel wizard = createWizard(project);
    wizard.addDependency("fake-dep");
    wizard.performOk();

    Job.getJobManager().join(EditStartersModel.JOB_FAMILY, null);

    // !!! fake data may not produce a project that builds without
    // !!! problem so don't check for build errors in this test

    IDOMDocument pom = parsePom(project);

    // check the dependency got added to the pom
    assertNotNull(findDependency(pom, new MavenId("org.springframework.fake", "spring-fake-dep")));

    // check that just the expected repo got added
    assertNotNull(getRepo(pom, "spring-milestones"));
    assertNull(getRepo(pom, "spring-snapshots"));
    assertRepoCount(1, pom);
  }
 private boolean suppressAuthentication() {
   Job job = Job.getJobManager().currentJob();
   if (job != null) {
     return job.getProperty(SUPPRESS_AUTHENTICATION_JOB_MARKER) != null;
   }
   return false;
 }
  /** Tests that we are able to add a basic starter. */
  @Test
  public void addStarter() throws Exception {
    IProject project = harness.createBootProject("foo", withStarters("web"));
    final ISpringBootProject bootProject = springBootCore.project(project);
    EditStartersModel wizard = createWizard(project);
    assertEquals(bootProject.getBootVersion(), wizard.getBootVersion());
    assertStarterDeps(wizard.dependencies.getCurrentSelection(), "web");

    PopularityTracker popularities = new PopularityTracker(prefs);
    assertUsageCounts(bootProject, popularities /*none*/);

    wizard.addDependency("actuator");
    assertStarterDeps(wizard.dependencies.getCurrentSelection(), "web", "actuator");
    wizard.performOk();

    Job.getJobManager().join(EditStartersModel.JOB_FAMILY, null);

    assertUsageCounts(bootProject, popularities, "actuator:1");

    StsTestUtil.assertNoErrors(project); // force project build

    assertStarters(bootProject.getBootStarters(), "web", "actuator");

    // check that the 'scope' is not set in the pom.xml:
    IDOMDocument pom = parsePom(project);

    Element depEl = findDependency(bootProject, pom, "actuator");
    assertEquals("org.springframework.boot", getGroupId(depEl));
    assertEquals("spring-boot-starter-actuator", getArtifactId(depEl));
    assertEquals(null, getScope(depEl));
  }
Example #7
0
  /**
   * {@inheritDoc}
   *
   * @see org.eclim.command.Command#execute(CommandLine)
   */
  public String execute(CommandLine commandLine) throws Exception {
    Object family = getFamily(commandLine.getValue(Options.FAMILY_OPTION));
    IJobManager manager = Job.getJobManager();
    Job[] jobs = manager.find(family);

    StringBuffer buffer = new StringBuffer();
    int maxlength = 0;
    for (Job job : jobs) {
      int length = job.toString().length();
      if (length > maxlength) {
        maxlength = length;
      }
    }

    for (Job job : jobs) {
      if (buffer.length() > 0) {
        buffer.append('\n');
      }
      buffer
          .append(StringUtils.rightPad(job.toString(), maxlength))
          .append(" - ")
          .append(getStatus(job));
    }
    return buffer.toString();
  }
 /*
  * @see Wizard#performFinish
  */
 public boolean performFinish() {
   IWorkspaceRunnable op =
       new IWorkspaceRunnable() {
         public void run(IProgressMonitor monitor)
             throws CoreException, OperationCanceledException {
           try {
             finishPage(monitor);
           } catch (InterruptedException e) {
             throw new OperationCanceledException(e.getMessage());
           }
         }
       };
   try {
     ISchedulingRule rule = null;
     Job job = Job.getJobManager().currentJob();
     if (job != null) rule = job.getRule();
     IRunnableWithProgress runnable = null;
     if (rule != null) runnable = new WorkbenchRunnableAdapter(op, rule, true);
     else runnable = new WorkbenchRunnableAdapter(op, getSchedulingRule());
     getContainer().run(canRunForked(), true, runnable);
   } catch (InvocationTargetException e) {
     handleFinishException(getShell(), e);
     return false;
   } catch (InterruptedException e) {
     return false;
   }
   return true;
 }
  @Test
  public void testResetToTag() throws Exception {
    SWTBotTree tree = getOrOpenView().bot().tree();

    String initialContent = getTestFileContent();
    createTag("ResetToFirst", "The first tag");
    touchAndSubmit(null);
    String newContent = getTestFileContent();
    assertFalse("Wrong content", initialContent.equals(newContent));
    createTag("ResetToSecond", "The second tag");
    refreshAndWait();
    myRepoViewUtil.getTagsItem(tree, repositoryFile).expand().getNode("ResetToFirst").select();

    ContextMenuHelper.clickContextMenu(tree, myUtil.getPluginLocalizedValue("ResetCommand"));

    SWTBotShell resetDialog = bot.shell(UIText.ResetCommand_WizardTitle);
    resetDialog.bot().radio(UIText.ResetTargetSelectionDialog_ResetTypeHardButton).click();
    resetDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
    TestUtil.joinJobs(JobFamilies.RESET);

    bot.shell(UIText.ResetTargetSelectionDialog_ResetQuestion)
        .bot()
        .button(IDialogConstants.YES_LABEL)
        .click();

    Job.getJobManager().join(JobFamilies.RESET, null);

    ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
    assertEquals("Wrong content", initialContent, getTestFileContent());
  }
  private void disableGlobalCDTIndexer() {
    // The Job code is borrowed from CCoreInternals ...
    final Job job =
        new Job("Disable CDT Indexer") {
          @Override
          protected IStatus run(final IProgressMonitor monitor) {
            try {
              final Properties props = new Properties();
              props.setProperty(IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER);
              IndexerPreferences.setProperties(null, IndexerPreferences.SCOPE_INSTANCE, props);
              InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID).flush();
            } catch (final BackingStoreException e) {
              CCorePlugin.log(e);
            }
            return Status.OK_STATUS;
          }
        };
    job.setSystem(true);
    job.schedule();
    try {
      job.join();
    } catch (final InterruptedException e) {
      System.out.println("Exception waiting for indexer disable: " + e.getMessage());
    }

    // Join any auto builds currently running (should be none)
    try {
      Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
    } catch (final Exception e1) {
      // PASS
    }
  }
Example #11
0
 public void done(IJobChangeEvent event) {
   if (event.getJob().belongsTo(fPDomManager)) {
     if (Job.getJobManager().find(fPDomManager).length == 0) {
       fPDomManager.fireStateChange(IndexerStateEvent.STATE_IDLE);
     }
   }
 }
 @Override
 public void preStartup() {
   super.preStartup();
   // only suspend the job manager if debug is false
   if (!debug) {
     Job.getJobManager().suspend();
   }
 }
Example #13
0
 private static Job getJob(IJobMatcher matcher) {
   Job[] jobs = Job.getJobManager().find(null);
   for (Job job : jobs) {
     if (matcher.matches(job)) {
       return job;
     }
   }
   return null;
 }
 /**
  * This is called by the registry controller to tell the registry to terminate with prejudice all
  * pending TerminateJobs.
  *
  * @since 1.1.0
  */
 public static void cancelAllTerminateJobs() {
   IJobManager jobManager = Job.getJobManager();
   jobManager.cancel(TERMINATE_JOB_FAMILY);
   try {
     jobManager.join(TERMINATE_JOB_FAMILY, null);
   } catch (OperationCanceledException e) {
   } catch (InterruptedException e) {
   }
 }
  private void initialize(final IRefreshSubscriberListener listener) {
    final GotoActionWrapper actionWrapper = new GotoActionWrapper();

    IProgressMonitor group = Job.getJobManager().createProgressGroup();
    group.beginTask(taskName, 100);
    setProgressGroup(group, 80);
    handleProgressGroupSet(group, 20);
    setProperty(IProgressConstants.ICON_PROPERTY, participant.getImageDescriptor());
    setProperty(IProgressConstants.ACTION_PROPERTY, actionWrapper);
    setProperty(IProgressConstants.KEEPONE_PROPERTY, Boolean.valueOf(!isJobModal()));
    // Listener delegate
    IRefreshSubscriberListener autoListener =
        new IRefreshSubscriberListener() {
          @Override
          public void refreshStarted(IRefreshEvent event) {
            if (listener != null) {
              listener.refreshStarted(event);
            }
          }

          @Override
          public ActionFactory.IWorkbenchAction refreshDone(IRefreshEvent event) {
            if (listener != null) {
              boolean isModal = isJobModal();
              event.setIsLink(!isModal);
              final ActionFactory.IWorkbenchAction runnable = listener.refreshDone(event);
              if (runnable != null) {
                // If the job is being run modally then simply prompt the user immediately
                if (isModal) {
                  if (runnable != null) {
                    Job update = new UIJob("") { // $NON-NLS-1$
                          @Override
                          public IStatus runInUIThread(IProgressMonitor monitor) {
                            runnable.run();
                            return Status.OK_STATUS;
                          }
                        };
                    update.setSystem(true);
                    update.schedule();
                  }
                } else {
                  // If the job is being run in the background, don't interrupt the user and simply
                  // update the goto action
                  // to perform the results.
                  actionWrapper.setGotoAction(runnable);
                }
              }
              RefreshParticipantJob.removeRefreshListener(this);
            }
            return null;
          }
        };

    if (listener != null) {
      RefreshParticipantJob.addRefreshListener(autoListener);
    }
  }
 public void testRepositoryMetadataCacheUsed() throws Exception {
   String oldSettings = mavenConfiguration.getUserSettingsFile();
   try {
     injectFilexWagon();
     IJobChangeListener jobChangeListener =
         new JobChangeAdapter() {
           public void scheduled(IJobChangeEvent event) {
             if (event.getJob() instanceof ProjectRegistryRefreshJob) {
               // cancel all those concurrent refresh jobs, we want to monitor the main thread only
               event.getJob().cancel();
               System.out.println(getName() + ": ProjectRegistryRefreshJob was cancelled");
             }
           }
         };
     Job.getJobManager().addJobChangeListener(jobChangeListener);
     mavenConfiguration.setUserSettingsFile(
         new File("projects/MNGECLIPSE-1996/settings.xml").getAbsolutePath());
     waitForJobsToComplete();
     FilexWagon.setRequestFilterPattern("mngeclipse1996/.*xml", true);
     List<String> requests;
     try {
       importProjects(
           "projects/MNGECLIPSE-1996",
           new String[] {
             "pom.xml",
             "mod-a/pom.xml",
             "mod-b/pom.xml",
             "mod-c/pom.xml",
             "mod-d/pom.xml",
             "mod-e/pom.xml"
           },
           new ResolverConfiguration());
       requests = FilexWagon.getRequests();
     } finally {
       Job.getJobManager().removeJobChangeListener(jobChangeListener);
     }
     // up to 2 requests (for POM and JAR) are allowed, more would indicate an issue with the cache
     assertTrue(
         "Accessed metadata " + requests.size() + " times: " + requests,
         requests.size() == 1 || requests.size() == 2 || requests.size() == 3);
   } finally {
     mavenConfiguration.setUserSettingsFile(oldSettings);
   }
 }
Example #17
0
 private void waitJobsToFinish(final Object family) {
   final IJobManager jobMan = Job.getJobManager();
   final Job[] build = jobMan.find(family);
   if (build.length == 1) {
     try {
       build[0].join();
     } catch (final InterruptedException e) {
     }
   }
 }
Example #18
0
 private static void waitForProjectRefreshToFinish() {
   try {
     // CDT opens the Project with BACKGROUND_REFRESH enabled which causes the
     // refresh manager to refresh the project 200ms later.  This Job interferes
     // with the resource change handler firing see: bug 271264
     Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, null);
   } catch (Exception e) {
     // Ignore
   }
 }
Example #19
0
  public static void waitForJobsToComplete(IProgressMonitor monitor)
      throws InterruptedException, CoreException {
    waitForBuildJobs();

    /*
     * First, make sure refresh job gets all resource change events
     *
     * Resource change events are delivered after WorkspaceJob#runInWorkspace returns
     * and during IWorkspace#run. Each change notification is delivered by
     * only one thread/job, so we make sure no other workspaceJob is running then
     * call IWorkspace#run from this thread.
     *
     * Unfortunately, this does not catch other jobs and threads that call IWorkspace#run
     * so we have to hard-code workarounds
     *
     * See http://www.eclipse.org/articles/Article-Resource-deltas/resource-deltas.html
     */
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IJobManager jobManager = Job.getJobManager();
    jobManager.suspend();
    try {
      Job[] jobs = jobManager.find(null);
      for (int i = 0; i < jobs.length; i++) {
        if (jobs[i] instanceof WorkspaceJob
            || jobs[i].getClass().getName().endsWith("JREUpdateJob")) {
          jobs[i].join();
        }
      }
      workspace.run(
          new IWorkspaceRunnable() {
            public void run(IProgressMonitor monitor) {}
          },
          workspace.getRoot(),
          0,
          monitor);

      // Now we flush all background processing queues
      boolean processed = flushProcessingQueues(jobManager, monitor);
      for (int i = 0; i < 10 && processed; i++) {
        processed = flushProcessingQueues(jobManager, monitor);
        try {
          Thread.sleep(10);
        } catch (InterruptedException e) {
        }
      }

      Assert.assertFalse(
          "Could not flush background processing queues: " + getProcessingQueues(jobManager),
          processed);
    } finally {
      jobManager.resume();
    }

    waitForBuildJobs();
  }
 private boolean isJobInFamilyRunning(Object family) {
   Job[] jobs = Job.getJobManager().find(family);
   if (jobs != null && jobs.length > 0) {
     for (int i = 0; i < jobs.length; i++) {
       Job job = jobs[i];
       if (job.getState() != Job.NONE) {
         return true;
       }
     }
   }
   return false;
 }
Example #21
0
 /** Wait for autobuild notification to occur */
 public static void waitForAutoBuild() {
   boolean wasInterrupted = false;
   do {
     try {
       Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
       wasInterrupted = false;
     } catch (OperationCanceledException e) {
       e.printStackTrace();
     } catch (InterruptedException e) {
       wasInterrupted = true;
     }
   } while (wasInterrupted);
 }
Example #22
0
 public static void waitForManualRefresh() {
   boolean wasInterrupted = false;
   do {
     try {
       Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_REFRESH, null);
       wasInterrupted = false;
     } catch (OperationCanceledException e) {
       e.printStackTrace();
     } catch (InterruptedException e) {
       wasInterrupted = true;
     }
   } while (wasInterrupted);
 }
  /**
   * For IDE-1085. Test that disposing the object doesn't call releaseObject() if it has no ILaunch.
   *
   * @see #testDisposeWithILaunch()
   * @throws CoreException
   */
  public void testDisposeWithoutILaunch() throws CoreException {
    // Ensure the local sandbox initializes fully
    ScaDebugPlugin.getInstance().getLocalSca(new NullProgressMonitor());

    // Listen to the job manager for changes
    ReleaseJobListener jobListener = new ReleaseJobListener();
    Job.getJobManager().addJobChangeListener(jobListener);

    try {
      // Setup the LocalScaWaveform object
      FakeApplication resource = new FakeApplication();
      fixture.setObj(resource);

      // Call dispose
      fixture.dispose();

      // Ensure the job to call releaseObject() is NOT scheduled
      assertFalse(jobListener.jobScheduled);
    } finally {
      Job.getJobManager().removeJobChangeListener(jobListener);
    }
  }
 public static void assertJobManagerIdle() {
   final IJobManager jm = Job.getJobManager();
   if (jm.isIdle()) {
     return; // OK!
   }
   // Make a nice message listing all the jobs and their present state.
   Job[] allJobs = jm.find(null);
   StringBuffer msg = new StringBuffer("JobManager not idle: \n");
   for (Job job : allJobs) {
     msg.append("   Job: " + job.getName() + " State: " + stateString(job) + "\n");
   }
   throw new AssertionFailedError(msg.toString());
 }
Example #25
0
 void dispose() {
   if (es != null) {
     es.shutdown();
   }
   if (refreshJob != null) {
     refreshJob.cancel();
     refreshJob = null;
   }
   // Cancel any jobs we're running in the index!
   IJobManager jobManager = Job.getJobManager();
   if (jobManager != null) {
     jobManager.cancel(this);
   }
 }
Example #26
0
 private void removeCanceledJobs() {
   synchronized (jobs) {
     for (JobInfo job : jobs.values()) {
       if (JobsManager.getInstance().isCanceled(job.job)) {
         job.cancel();
       }
     }
     List<Job> find = Arrays.asList(Job.getJobManager().find(null));
     for (Job job : jobs.keySet()) {
       if (!find.contains(job)) {
         getOrCreateJobInfo(job).cancel();
       }
     }
   }
 }
 public void checkConsistency(IProgressMonitor monitor) throws OperationCanceledException {
   if (!fNeedsConsistencyCheck) return;
   if (fUpdateJob.getState() == Job.RUNNING) {
     try {
       Job.getJobManager().join(UpdateJob.FAMILY, monitor);
     } catch (OperationCanceledException e) {
       // Ignore and do the consistency check without
       // waiting for the update job.
     } catch (InterruptedException e) {
       // Ignore and do the consistency check without
       // waiting for the update job.
     }
   }
   if (!fNeedsConsistencyCheck) return;
   internalCheckConsistency(monitor);
 }
 /**
  * This method is called when the user hits the "Finish" button.<br>
  * It runs a job downloading libraries to a given folder.
  *
  * @return true, if perform finish
  * @see org.eclipse.jface.wizard.Wizard#performFinish()
  */
 @Override
 public boolean performFinish() {
   IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
   IProject selectedProject = workspaceRoot.getProject(page1.getChosenProjectName());
   IFolder selectedFolder =
       selectedProject.getFolder(
           page2.getChosenFolder() == null
               ? AggregatedProperties.getDefaultLibFolder(selectedProject)
               : page2.getChosenFolder());
   IProgressMonitor pm = Job.getJobManager().createProgressGroup();
   pm.beginTask(WizardsMessages.PomJavaFolderSynchronizationWizard_monitor_task_name, 100);
   Job job =
       new DownloadAndAddToFolderJob(
           selectedProject, selectedFolder, page1.getSelectedLibraries());
   job.setProgressGroup(pm, 100);
   job.schedule();
   return true;
 }
  @Test
  public void addStarterWithTestScope() throws Exception {
    IProject project = harness.createBootProject("foo", withStarters("web"));
    final ISpringBootProject bootProject = springBootCore.project(project);
    EditStartersModel wizard = createWizard(project);
    wizard.addDependency("restdocs");
    wizard.performOk();

    Job.getJobManager().join(EditStartersModel.JOB_FAMILY, null);

    StsTestUtil.assertNoErrors(project); // force project build

    assertStarters(bootProject.getBootStarters(), "web", "restdocs");

    // check that the 'scope' is set properly
    IDOMDocument pom = parsePom(project);
    Element depEl = findDependency(bootProject, pom, "restdocs");
    assertEquals("spring-restdocs-mockmvc", getArtifactId(depEl));
    assertEquals("test", getScope(depEl));
  }
  @Test
  public void addStarterWithBom() throws Exception {
    // We'll be adding this starter:
    //	      "id": "cloud-eureka",
    //	      "groupId": "org.springframework.cloud",
    //	      "artifactId": "spring-cloud-starter-eureka",
    //	      "scope": "compile",
    //	      "bom": "cloud-bom"

    IProject project = harness.createBootProject("foo", withStarters("web"));
    final ISpringBootProject bootProject = springBootCore.project(project);
    EditStartersModel wizard = createWizard(project);
    wizard.addDependency("cloud-eureka");
    wizard.performOk();

    Job.getJobManager().join(EditStartersModel.JOB_FAMILY, null);
    StsTestUtil.assertNoErrors(project); // force project build

    assertStarters(bootProject.getBootStarters(), "web", "cloud-eureka");
  }