Java Code Examples for org.eclipse.core.runtime.jobs.Job#join()

The following examples show how to use org.eclipse.core.runtime.jobs.Job#join() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConversionTests.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void appEngineWebWithJava8Runtime_Java7()
    throws CoreException, IOException, InterruptedException, SAXException, AppEngineException {
  IFacetedProject project =
      projectCreator.withFacets(JavaFacet.VERSION_1_7).getFacetedProject();
  createAppEngineWebWithJava8Runtime(project);

  Job conversionJob = new AppEngineStandardProjectConvertJob(project);
  conversionJob.schedule();
  conversionJob.join();
  assertIsOk("conversion should never fail", conversionJob.getResult());

  assertFacetVersions(project, JavaFacet.VERSION_1_8, WebFacetUtils.WEB_31,
      AppEngineStandardFacetChangeListener.APP_ENGINE_STANDARD_JRE8);
  assertJava8Runtime(project);
}
 
Example 2
Source File: ConversionTests.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void appEngineWebWithJava8Runtime_Java8_Web25()
    throws CoreException, IOException, InterruptedException, SAXException, AppEngineException {
  IFacetedProject project = projectCreator
      .withFacets(JavaFacet.VERSION_1_8, WebFacetUtils.WEB_25).getFacetedProject();
  createAppEngineWebWithJava8Runtime(project);

  Job conversionJob = new AppEngineStandardProjectConvertJob(project);
  conversionJob.schedule();
  conversionJob.join();
  assertIsOk("conversion should never fail", conversionJob.getResult());

  assertFacetVersions(project, JavaFacet.VERSION_1_8, WebFacetUtils.WEB_25,
      AppEngineStandardFacetChangeListener.APP_ENGINE_STANDARD_JRE8);
  assertJava8Runtime(project);
}
 
Example 3
Source File: ConversionTests.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void appEngineWebWithNoRuntime_Java7_Web31()
    throws CoreException, IOException, InterruptedException, SAXException, AppEngineException {
  IFacetedProject project = projectCreator
      .withFacets(JavaFacet.VERSION_1_7, WebFacetUtils.WEB_31).getFacetedProject();
  createAppEngineWebWithNoRuntime(project);

  Job conversionJob = new AppEngineStandardProjectConvertJob(project);
  conversionJob.schedule();
  conversionJob.join();
  assertIsOk("conversion should never fail", conversionJob.getResult());

  assertFacetVersions(project, JavaFacet.VERSION_1_7, WebFacetUtils.WEB_25,
      AppEngineStandardFacet.JRE7);
  assertNoJava8Runtime(project);
}
 
Example 4
Source File: ConversionTests.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void appEngineWebWithJava8Runtime_Java7_Web31()
    throws CoreException, IOException, InterruptedException, SAXException, AppEngineException {
  IFacetedProject project = projectCreator
      .withFacets(JavaFacet.VERSION_1_7, WebFacetUtils.WEB_31).getFacetedProject();
  createAppEngineWebWithJava8Runtime(project);

  Job conversionJob = new AppEngineStandardProjectConvertJob(project);
  conversionJob.schedule();
  conversionJob.join();
  assertIsOk("conversion should never fail", conversionJob.getResult());

  assertFacetVersions(project, JavaFacet.VERSION_1_8, WebFacetUtils.WEB_31,
      AppEngineStandardFacetChangeListener.APP_ENGINE_STANDARD_JRE8);
  assertJava8Runtime(project);
}
 
Example 5
Source File: ConversionTests.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void appEngineWebWithNoRuntime_Java8_Web31()
    throws CoreException, IOException, InterruptedException, SAXException, AppEngineException {
  IFacetedProject project = projectCreator
      .withFacets(JavaFacet.VERSION_1_8, WebFacetUtils.WEB_31).getFacetedProject();
  createAppEngineWebWithNoRuntime(project);

  Job conversionJob = new AppEngineStandardProjectConvertJob(project);
  conversionJob.schedule();
  conversionJob.join();
  assertIsOk("conversion should never fail", conversionJob.getResult());

  assertFacetVersions(project, JavaFacet.VERSION_1_7, WebFacetUtils.WEB_25,
      AppEngineStandardFacet.JRE7);
  assertNoJava8Runtime(project);
}
 
Example 6
Source File: ErrorLogListenerTest.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Test that {@link NullPointerException}'s are ignored.
 *
 * @throws InterruptedException
 *           the exception that is thrown if the test job was interrupted
 */
@Test
public void testIgnoringExceptionLocations() throws InterruptedException {
  assertFalse("NullPointerException must not have been logged.", errorLogListener.isExceptionLogged(NullPointerException.class));
  errorLogListener.ignoreException(NullPointerException.class, "com.avaloq.tools.ddk.test.core.util.ErrorLogListenerTest");

  final Job job = new Job("testIgnoringExceptionLocations") {

    @Override
    @SuppressWarnings("PMD.AvoidThrowingNullPointerException")
    protected IStatus run(final IProgressMonitor monitor) {
      // We really want to thrown a null pointer exception here because we test that such exceptions are ignored.
      throw new NullPointerException();
    }
  };
  job.schedule();
  job.join();

  assertTrue("NullPointerException must have been logged.", errorLogListener.isExceptionLogged(NullPointerException.class));
  assertFalse("NullPointerException must have been ignored.", errorLogListener.getLoggedExceptions().contains(NullPointerException.class));
}
 
Example 7
Source File: GpeConversionTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private void convertGpeProject(URL zipFile)
    throws CoreException, IOException, InterruptedException {
  Map<String, IProject> projects =
      ProjectUtils.importProjects(zipFile, false /* checkBuildErrors */, null);
  assertEquals(1, projects.size());
  project = projects.values().iterator().next();
  IFacetedProject facetedProject = ProjectFacetsManager.create(project,
      true /* convert to faceted project if necessary */, null /* no monitor here */);

  Job conversionJob = new AppEngineStandardProjectConvertJob(facetedProject);
  conversionJob.schedule();
  conversionJob.join();
  assertTrue("conversion should not have failed", conversionJob.getResult().isOK());

  // ensure facet versions haven't been downgraded
  assertEquals(JavaFacet.VERSION_1_7, facetedProject.getProjectFacetVersion(JavaFacet.FACET));
  assertEquals(WebFacetUtils.WEB_25,
      facetedProject.getProjectFacetVersion(WebFacetUtils.WEB_FACET));
  assertEquals(AppEngineStandardFacet.JRE7,
      facetedProject.getProjectFacetVersion(AppEngineStandardFacet.FACET));
}
 
Example 8
Source File: ProjectSelectorSelectionChangedListenerTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testSelectionChanged_changeSelectedProject()
    throws ProjectRepositoryException, InterruptedException {
  when(projectRepository.getAppEngineApplication(any(Credential.class), eq("oldProjectId")))
      .thenThrow(new ProjectRepositoryException("testException"));
  when(projectRepository.getAppEngineApplication(any(Credential.class), eq("projectId")))
      .thenReturn(AppEngine.NO_APPENGINE_APPLICATION);

  initSelectionAndAccountSelector(new GcpProject("oldProjectName", "oldProjectId"));
  listener.selectionChanged(event);

  Job oldJob = listener.latestQueryJob;
  assertNotNull(oldJob);
  oldJob.join();

  initSelectionAndAccountSelector();
  listener.selectionChanged(event);

  Job newJob = listener.latestQueryJob;
  assertNotNull(newJob);
  assertNotEquals(oldJob, newJob);
  newJob.join();

  verify(projectRepository).getAppEngineApplication(any(Credential.class), eq("oldProjectId"));
  verify(projectRepository).getAppEngineApplication(any(Credential.class), eq("projectId"));
  verify(projectSelector).setStatusLink(EXPECTED_MESSAGE_WHEN_NO_APPLICATION, EXPECTED_LINK);
}
 
Example 9
Source File: TestedWorkspaceWithJDT.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Join on the job that updates the classpath after a manifest change. 
 * The calling thread will effectively wait for that job to finish.
 */
protected void joinUpdateClasspathJob() {
	try {
		// Pseudo fence to make sure that we see what we want to see.
		synchronized (this) {
			wait(1);
		}
		Job joinMe = updateClasspathJob;
		if (joinMe != null) {
			joinMe.join();
		}
	} catch (Exception e) {
		Exceptions.throwUncheckedException(e);
	}
}
 
Example 10
Source File: ConversionTests.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void bare_Java8_Web25()
    throws CoreException, IOException, InterruptedException, SAXException, AppEngineException {
  IFacetedProject project = projectCreator
      .withFacets(JavaFacet.VERSION_1_8, WebFacetUtils.WEB_25).getFacetedProject();
  Job conversionJob = new AppEngineStandardProjectConvertJob(project);
  conversionJob.schedule();
  conversionJob.join();
  assertIsOk("conversion should never fail", conversionJob.getResult());

  // ensure facet versions haven't been downgraded
  assertFacetVersions(project, JavaFacet.VERSION_1_8, WebFacetUtils.WEB_25,
      AppEngineStandardFacetChangeListener.APP_ENGINE_STANDARD_JRE8);
  assertJava8Runtime(project);
}
 
Example 11
Source File: AppEngineStandardProjectConvertJobTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppEngineFacetAdded() throws CoreException, InterruptedException {
  IProject project = projectCreator.getProject();
  IFacetedProject facetedProject = ProjectFacetsManager.create(project);
  Job convertJob = new AppEngineStandardProjectConvertJob(facetedProject);
  convertJob.schedule();
  convertJob.join();
  assertTrue(AppEngineStandardFacet.hasFacet(facetedProject));

  // verify App Engine standard files are present
  IFile webXml = WebProjectUtil.findInWebInf(project, new Path("web.xml"));
  assertTrue(webXml.exists());
  IFile appEngineWebXml =
      AppEngineConfigurationUtil.findConfigurationFile(project, new Path("appengine-web.xml"));
  assertTrue(appEngineWebXml.exists());

  // verify no overlap in WEB-INF and source paths
  // Java 1.7 facet sets the source path to src/ which will overlap with the
  // default src/main/webapp used in the AppEngineStandardFacet installer
  IFolder webInfFolder = (IFolder) webXml.getParent();
  assertEquals("WEB-INF", webInfFolder.getName());
  IPath webInfPath = webInfFolder.getProjectRelativePath();
  List<IPath> sourcePaths = WebProjectUtil.getJavaSourcePaths(project);
  for (IPath sourcePath : sourcePaths) {
    assertFalse(sourcePath.isPrefixOf(webInfPath));
  }
}
 
Example 12
Source File: ConversionTests.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void appEngineWebWithJava8Runtime()
    throws CoreException, IOException, InterruptedException, SAXException, AppEngineException {
  IFacetedProject project = projectCreator.getFacetedProject();
  createAppEngineWebWithJava8Runtime(project);

  Job conversionJob = new AppEngineStandardProjectConvertJob(project);
  conversionJob.schedule();
  conversionJob.join();
  assertIsOk("conversion should never fail", conversionJob.getResult());

  assertFacetVersions(project, JavaFacet.VERSION_1_8, WebFacetUtils.WEB_31,
      AppEngineStandardFacetChangeListener.APP_ENGINE_STANDARD_JRE8);
  assertJava8Runtime(project);
}
 
Example 13
Source File: CloudSdkModifyJobTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testRun_unlocksAfterReturn() throws InterruptedException {
  Job installJob = new FakeModifyJob(false /* blockOnStart */);
  installJob.schedule();
  installJob.join();

  assertTrue(installJob.getResult().isOK());

  assertTrue(readWriteLock.writeLock().tryLock());
  readWriteLock.writeLock().unlock();
}
 
Example 14
Source File: CloudSdkManagerTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testPreventModifyingSdk_blocksRunInstallJob() throws InterruptedException {
  fixture.preventModifyingSdk();
  boolean prevented = true;

  try {
    final CloudSdkModifyJob installJob = new FakeModifyJob(Status.OK_STATUS);

    Job concurrentLauncher =
        new Job("concurrent thread attempting runInstallJob()") {
          @Override
          public IStatus run(IProgressMonitor monitor) {
            // Should block until we allow SDK modification below.
            CloudSdkManager.runInstallJob(null, installJob, monitor);
            return Status.OK_STATUS;
          }
        };
    concurrentLauncher.schedule();

    while (installJob.getState() != Job.RUNNING) {
      Thread.sleep(50);
    }
    // Incomplete test, but if it ever fails, something is surely broken.
    assertEquals(Job.RUNNING, concurrentLauncher.getState());

    fixture.allowModifyingSdk();
    prevented = false;
    concurrentLauncher.join();

    // Incomplete test, but if it ever fails, something is surely broken.
    assertTrue(installJob.getResult().isOK());
    assertTrue(concurrentLauncher.getResult().isOK());
  } finally {
    if (prevented) {
      fixture.allowModifyingSdk();
    }
  }
}
 
Example 15
Source File: GcpProjectQueryJobTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testRun_abandonStaleJob() throws InterruptedException, ProjectRepositoryException {
  // Prepare another concurrent query job.
  Credential staleCredential = mock(Credential.class);

  List<GcpProject> anotherProjectList = new ArrayList<>();
  anotherProjectList.add(null); // so not equals to projects
  
  ProjectRepository projectRepository2 = mock(ProjectRepository.class);
  when(projectRepository2.getProjects(staleCredential)).thenReturn(anotherProjectList);

  // This second job is stale, i.e., it was fired, but user has selected another credential.
  Predicate<Job> notLatest = job -> false;
  Job staleJob = new GcpProjectQueryJob(staleCredential, projectRepository2,
      projectSelector, dataBindingContext, notLatest);

  queryJob.schedule();
  queryJob.join();
  // Make the stale job complete even after "queryJob" finishes.
  staleJob.schedule();
  staleJob.join();

  verify(projectRepository).getProjects(credential);
  verify(projectRepository2).getProjects(staleCredential);

  verify(projectSelector).setProjects(projects);
  verify(projectSelector, never()).setProjects(anotherProjectList);
}
 
Example 16
Source File: JobManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Stop background processing, and wait until the current job is completed before returning
 */
public void shutdown() {

	if (VERBOSE)
		Util.verbose("Shutdown"); //$NON-NLS-1$

	disable();
	discardJobs(null); // will wait until current executing job has completed
	Thread thread = this.processingThread;
	try {
		if (thread != null) { // see http://bugs.eclipse.org/bugs/show_bug.cgi?id=31858
			synchronized (this) {
				this.processingThread = null; // mark the job manager as shutting down so that the thread will stop by itself
				notifyAll(); // ensure its awake so it can be shutdown
			}
			// in case processing thread is handling a job
			thread.join();
		}
		Job job = this.progressJob;
		if (job != null) {
			job.cancel();
			job.join();
		}
	} catch (InterruptedException e) {
		// ignore
	}
}
 
Example 17
Source File: ProjectUtils.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
/** Wait for any spawned jobs and builds to complete (e.g., validation jobs). */
public static void waitForProjects(Runnable delayTactic, IProject... projects) {
  if (projects.length == 0) {
    projects = getWorkspace().getRoot().getProjects();
  }
  Stopwatch timer = Stopwatch.createStarted();
  try {
    Collection<Job> jobs = Collections.emptyList();
    Set<String> previousBuildErrors = Collections.emptySet();
    boolean buildErrorsChanging;
    do {
      // wait a little bit to give the builders a chance
      delayTactic.run();

      // wait for any previously-identified build jobs
      for (Job job : jobs) {
        job.join();
      }

      // identify any pending build-related jobs
      jobs = findPendingBuildJobs(projects);

      // track whether we've reached a fixpoint in the build errors
      Set<String> currentBuildErrors = getAllBuildErrors(projects);
      buildErrorsChanging = !previousBuildErrors.equals(currentBuildErrors);
      previousBuildErrors = currentBuildErrors;

      if (DEBUG || timer.elapsed(TimeUnit.SECONDS) > 10) {
        if (!jobs.isEmpty()) {
          System.err.printf("ProjectUtils#waitForProjects[%s]: waiting for %d jobs: %s\n", timer,
              jobs.size(), jobs);
        }
        if (buildErrorsChanging) {
          System.err.printf("ProjectUtils#waitForProjects[%s]: waiting for %d build errors\n",
              timer, currentBuildErrors.size());
        }
        // Uncomment if tests are failing to identify any other build-related jobs.
        // Job[] otherJobs = Job.getJobManager().find(null);
        // if (otherJobs.length > 0) {
        // System.err.printf("Ignoring %d unrelated jobs:\n", otherJobs.length);
        // for (Job job : otherJobs) {
        // System.err.printf(" %s: %s\n", job.getClass().getName(), job);
        // }
        // }
      }
    } while (!jobs.isEmpty() || buildErrorsChanging);
  } catch (CoreException | InterruptedException ex) {
    throw new RuntimeException(ex);
  }
}
 
Example 18
Source File: TargetPlatformUtil.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Sets the target platform for tests (to be used in tycho mainly)
 * @param context any class of the test bundle to be able to determine the test bundle
 * @since 2.14
 */
public static void setTargetPlatform(Class<?> context) throws Exception {
	if (isPdeLaunch()) {
		return;
	}
	Bundle currentBundle = FrameworkUtil.getBundle(context);
	ITargetPlatformService tpService = TargetPlatformService.getDefault();
	ITargetDefinition targetDef = tpService.newTarget();
	targetDef.setName("Tycho platform");
	Bundle[] bundles = Platform.getBundle("org.eclipse.core.runtime").getBundleContext().getBundles();
	List<ITargetLocation> bundleContainers = new ArrayList<ITargetLocation>();
	Set<File> dirs = new HashSet<File>();
	for (Bundle bundle : bundles) {
		if (bundle.equals(currentBundle)) {
			// we skip the current bundle, otherwise the folder for the target platform
			// will include the absolute directory of the maven parent project
			// since the projects are nested in the parent project the result
			// would be that Java packages of our project will be available twice
			// and Java won't be able to find our classes leading in compilation
			// errors during our tests.
			continue;
		}
		EquinoxBundle bundleImpl = (EquinoxBundle) bundle;
		Generation generation = (Generation) bundleImpl.getModule().getCurrentRevision().getRevisionInfo();
		File file = generation.getBundleFile().getBaseFile();
		File folder = file.getParentFile();
		if ((file.isFile() || Platform.inDevelopmentMode()) && !dirs.contains(folder)) {
			dirs.add(folder);
			bundleContainers.add(tpService.newDirectoryLocation(folder.getAbsolutePath()));
		}
	}
	targetDef.setTargetLocations(bundleContainers.toArray(new ITargetLocation[bundleContainers.size()]));
	targetDef.setArch(Platform.getOSArch());
	targetDef.setOS(Platform.getOS());
	targetDef.setWS(Platform.getWS());
	targetDef.setNL(Platform.getNL());
	// targetDef.setJREContainer()
	tpService.saveTargetDefinition(targetDef);

	Job job = new LoadTargetDefinitionJob(targetDef);
	job.schedule();
	job.join();
}
 
Example 19
Source File: PDETargetPlatformUtils.java    From xsemantics with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Sets a target platform in the test platform to get workspace builds OK
 * with PDE.
 * 
 * @throws Exception
 */
public static void setTargetPlatform() throws Exception {
	if (System.getProperty("buildingWithTycho") != null) {
		if (targetPlatformAlreadySet) {
			System.out.println("Target platform already set");
			return;
		}
		targetPlatformAlreadySet = true;
		System.out.println("Generating a target platform");
	} else {
		System.out.println("Using the Workbench's target platform");
		return;
	}
	
	ITargetPlatformService tpService = TargetPlatformService.getDefault();
	ITargetDefinition targetDef = tpService.newTarget();
	targetDef.setName("Tycho platform");
	Bundle[] bundles = Platform.getBundle("org.eclipse.core.runtime").getBundleContext().getBundles();
	List<ITargetLocation> bundleContainers = new ArrayList<ITargetLocation>();
	Set<File> dirs = new HashSet<File>();
	System.out.println("Bundles for the target platform:");
	for (Bundle bundle : bundles) {
		System.out.print(bundle);
		EquinoxBundle bundleImpl = (EquinoxBundle) bundle;
		Generation generation = (Generation) bundleImpl.getModule().getCurrentRevision().getRevisionInfo();
		File file = generation.getBundleFile().getBaseFile();
		File folder = file.getParentFile();
		if (!dirs.contains(folder)) {
			dirs.add(folder);
			bundleContainers.add(tpService.newDirectoryLocation(folder.getAbsolutePath()));
		}
	}
	System.out.println("");
	System.out.println("Bundles added the target platform.");
	targetDef.setTargetLocations(bundleContainers.toArray(new ITargetLocation[bundleContainers.size()]));
	targetDef.setArch(Platform.getOSArch());
	targetDef.setOS(Platform.getOS());
	targetDef.setWS(Platform.getWS());
	targetDef.setNL(Platform.getNL());
	// targetDef.setJREContainer()
	tpService.saveTargetDefinition(targetDef);

	System.out.print("Loading target platform... ");
	Job job = new LoadTargetDefinitionJob(targetDef);
	job.schedule();
	job.join();
	System.out.println("DONE.");
}
 
Example 20
Source File: TexlipseBuilder.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
    * Build the project.
    * 
 * @see IncrementalProjectBuilder.build
 */
   @Override
protected IProject[] build(int kind, Map args,
        IProgressMonitor monitor) throws CoreException {

       final IProject project = getProject();
       final ProjectFileTracking fileTracking = new ProjectFileTracking(project);
       final OutputFileManager fileManager = new OutputFileManager(project, fileTracking);

       Object rebuild = TexlipseProperties.getSessionProperty(project,
               TexlipseProperties.FORCED_REBUILD);

       // Wait for all scheduled parser jobs, since they could change relevant
       // session properties
       for (Job parser : Job.getJobManager().find(TexDocumentModel.PARSER_FAMILY)) {
           int state = parser.getState();
           if (state == Job.WAITING || state == Job.SLEEPING) {
               // If waiting, run immediately
               parser.cancel();
               parser.schedule();
           }
           try {
               parser.join();
           } catch (InterruptedException e) {
           }
       }

       if (rebuild == null && fileManager.isUpToDate()) {
           return null;
       }

       BuilderRegistry.clearConsole();

       Object s = TexlipseProperties.getProjectProperty(project,
               TexlipseProperties.PARTIAL_BUILD_PROPERTY);
	if (s != null) {
		partialBuild(project, fileManager, monitor);
	} else {
		buildFile(project, null, fileManager, monitor);
	}

	TexlipseProperties.setSessionProperty(project,
	        TexlipseProperties.FORCED_REBUILD, null);

	return null;
}