Java Code Examples for org.eclipse.core.runtime.jobs.IJobChangeEvent#getJob()

The following examples show how to use org.eclipse.core.runtime.jobs.IJobChangeEvent#getJob() . 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: TestedWorkspaceWithJDT.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void scheduled(IJobChangeEvent event) {
	if (updateClasspathJob == null) {
		Class<? extends Job> jobType = event.getJob().getClass();
		if (PluginModelManager.class.equals(jobType.getEnclosingClass())) {
			updateClasspathJob = event.getJob();
		}
	}
}
 
Example 2
Source File: JobMatcher.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public synchronized void scheduled(final IJobChangeEvent event) {
  Job job = event.getJob();
  if (finder.apply(job)) {
    newJobs.add(job);
  }
}
 
Example 3
Source File: JobMatcher.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public synchronized void done(final IJobChangeEvent event) {
  Job job = event.getJob();
  if (finder.apply(job)) {
    jobQueue.add(job);
  }
}
 
Example 4
Source File: DummyJobChangeListener.java    From tlaplus with MIT License 5 votes vote down vote up
public void done(IJobChangeEvent event) {
	final Job j = event.getJob();
	if(j.belongsTo(ToolboxJob.FAMILY)) {
		final String jobName = j.getName();
		if(jobName.endsWith(model.getName())) {
			job = j;
		}
	}
}
 
Example 5
Source File: UpdateMetaFileReaderJobListener.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
@Override
public void done(IJobChangeEvent event) {

	if (event.getResult().isOK()) {
		UpdateMetaFileReaderJob = ((UpdateMetaFileReaderJob) event.getJob());
		final int count = UpdateMetaFileReaderJob.getUpdateCount();
		Display.getDefault().syncExec(new Runnable() {
			@Override
			public void run() {
				try {
					String displayMsg = String.valueOf(count)
							+ " update(s) available for developer studio. List them now ?";
					int userPref = getUserPreference(UPDATER_DIALOG_TITLE, displayMsg);
					if (userPref == 0 || userPref == USER_SCHEDULED_AUTOMATIC_INSTALL) {
						executeUpdateJob();
					} 
				} catch (Exception e) {
					log.error(Messages.UpdatemetaFileReaderJobListener_0, e);
				}
			}

			private void executeUpdateJob() {
				Job updateJob = new UpdateCheckerJob(updateManager);
				updateJob.schedule();
				updateJob.addJobChangeListener(
						new UpdateCheckerJobListener(updateManager, ActiveTab.UPDATE_FEATURES, true));
			}
		});
	}
}
 
Example 6
Source File: BonitaProjectExplorer.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void done(IJobChangeEvent event) {
    Job job = event.getJob();
    if (Objects.equals(job.getName(), getTitle())) {
        PlatformUtil.openIntroIfNoOtherEditorOpen();
    }
}
 
Example 7
Source File: InvisibleProjectBuildSupportTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testDebounceJarDetection() throws Exception {
	File projectFolder = createSourceFolderWithMissingLibs("dynamicLibDetection");
	IProject project = importRootFolder(projectFolder, "Test.java");
	List<IMarker> errors = ResourceUtils.getErrorMarkers(project);
	assertEquals("Unexpected errors " + ResourceUtils.toString(errors), 2, errors.size());

	//Add jars to fix compilation errors
	addLibs(projectFolder.toPath());

	Path libPath = projectFolder.toPath().resolve(InvisibleProjectBuildSupport.LIB_FOLDER);

	int[] jobInvocations = new int[1];
	IJobChangeListener listener = new JobChangeAdapter() {
		@Override
		public void scheduled(IJobChangeEvent event) {
			if (event.getJob() instanceof UpdateClasspathJob) {
				jobInvocations[0] = jobInvocations[0] + 1;
			}
		}
	};
	try {
		Job.getJobManager().addJobChangeListener(listener);
		//Spam the service
		for (int i = 0; i < 50; i++) {
			projectsManager.fileChanged(libPath.resolve("foo.jar").toUri().toString(), CHANGE_TYPE.CREATED);
			projectsManager.fileChanged(libPath.resolve("foo-sources.jar").toUri().toString(), CHANGE_TYPE.CREATED);
			Thread.sleep(5);
		}
		waitForBackgroundJobs();
		assertEquals("Update classpath job should have been invoked once", 1, jobInvocations[0]);
	} finally {
		Job.getJobManager().removeJobChangeListener(listener);
	}

	{
		IJavaProject javaProject = JavaCore.create(project);
		IClasspathEntry[] classpath = javaProject.getRawClasspath();
		assertEquals("Unexpected classpath:\n" + JavaProjectHelper.toString(classpath), 3, classpath.length);
		assertEquals("foo.jar", classpath[2].getPath().lastSegment());
		assertEquals("foo-sources.jar", classpath[2].getSourceAttachmentPath().lastSegment());
	}

}
 
Example 8
Source File: InvisibleProjectBuildSupportTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testManuallyReferenceLibraries() throws Exception {
	File projectFolder = createSourceFolderWithMissingLibs("dynamicLibDetection");
	IProject project = importRootFolder(projectFolder, "Test.java");
	List<IMarker> errors = ResourceUtils.getErrorMarkers(project);
	assertEquals("Unexpected errors " + ResourceUtils.toString(errors), 2, errors.size());

	File originBinary = new File(getSourceProjectDirectory(), "eclipse/source-attachment/foo.jar");
	File originSource = new File(getSourceProjectDirectory(), "eclipse/source-attachment/foo-sources.jar");

	Set<String> include = new HashSet<>();
	Set<String> exclude = new HashSet<>();
	Map<String, String> sources = new HashMap<>();

	// Include following jars (by lib/** detection)
	// - /lib/foo.jar
	// - /lib/foo-sources.jar
	File libFolder = Files.createDirectories(projectFolder.toPath().resolve(InvisibleProjectBuildSupport.LIB_FOLDER)).toFile();
	File fooBinary = new File(libFolder, "foo.jar");
	File fooSource = new File(libFolder, "foo-sources.jar");
	FileUtils.copyFile(originBinary, fooBinary);
	FileUtils.copyFile(originSource, fooSource);

	// Include following jars (by manually add include)
	// - /bar.jar
	// - /library/bar-src.jar
	File libraryFolder = Files.createDirectories(projectFolder.toPath().resolve("library")).toFile();
	File barBinary = new File(projectFolder, "bar.jar");
	File barSource = new File(libraryFolder, "bar-src.jar");
	FileUtils.copyFile(originBinary, barBinary);
	FileUtils.copyFile(originSource, barSource);
	include.add(barBinary.toString());
	sources.put(barBinary.toString(), barSource.toString());

	// Exclude following jars (by manually add exclude)
	// - /lib/foo.jar
	exclude.add(fooBinary.toString());

	// Before sending requests
	IJavaProject javaProject = JavaCore.create(project);
	int[] jobInvocations = new int[1];
	IJobChangeListener listener = new JobChangeAdapter() {
		@Override
		public void scheduled(IJobChangeEvent event) {
			if (event.getJob() instanceof UpdateClasspathJob) {
				jobInvocations[0] = jobInvocations[0] + 1;
			}
		}
	};

	try { // Send two update request concurrently
		Job.getJobManager().addJobChangeListener(listener);
		projectsManager.fileChanged(fooBinary.toURI().toString(), CHANGE_TYPE.CREATED); // Request sent by jdt.ls's lib detection
		UpdateClasspathJob.getInstance().updateClasspath(javaProject, include, exclude, sources); // Request sent by third-party client
		waitForBackgroundJobs();
		assertEquals("Update classpath job should have been invoked once", 1, jobInvocations[0]);
	} finally {
		Job.getJobManager().removeJobChangeListener(listener);
	}

	{
		// The requests sent by `fileChanged` and `updateClasspath` is merged in queue,
		// So latter's `exclude: lib/foo.jar` comes into effect to block former's `include: lib/foo.jar`
		IClasspathEntry[] classpath = javaProject.getRawClasspath();
		// Check only one jar file is added to classpath (foo.jar is excluded)
		assertEquals("Unexpected classpath:\n" + JavaProjectHelper.toString(classpath), 3, classpath.length);
		// Check the only added jar is bar.jar
		assertEquals("bar.jar", classpath[2].getPath().lastSegment());
		assertEquals("bar-src.jar", classpath[2].getSourceAttachmentPath().lastSegment());
		// Check the source of bar.jar is in /library folder
		assertEquals("library", classpath[2].getSourceAttachmentPath().removeLastSegments(1).lastSegment());
	}
}
 
Example 9
Source File: OpenTraceStressTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Main test case to test opening and closing of traces concurrently.
 */
@Test
public void testOpenAndCloseConcurrency() {
    SWTBotUtils.createProject(TRACE_PROJECT_NAME);

    File fTestFile = new File(CtfTmfTestTraceUtils.getTrace(CTF_TRACE).getPath());
    CtfTmfTestTraceUtils.dispose(CTF_TRACE);

    String path = fTestFile.getAbsolutePath();

    assertNotNull(fTestFile);
    assumeTrue(fTestFile.exists());

    /*
     *  This opening and closing of traces will trigger several threads for analysis which
     *  will be closed concurrently. There used to be a concurrency bug (447434) which should
     *  be fixed by now and this test should run without any exceptions.
     *
     *  Since the failure depends on timing it only happened sometimes before the bug fix
     *  using this test.
     */
    final MultiStatus status = new MultiStatus("lttn2.kernel.ui.swtbot.tests", IStatus.OK, null, null);
    IJobManager mgr = Job.getJobManager();
    JobChangeAdapter changeListener = new JobChangeAdapter() {
        @Override
        public void done(IJobChangeEvent event) {
            Job job = event.getJob();
            // Check for analysis failure
            String jobNamePrefix = NLS.bind(Messages.TmfAbstractAnalysisModule_RunningAnalysis, "");
            if ((job.getName().startsWith(jobNamePrefix)) && (job.getResult().getSeverity() == IStatus.ERROR)) {
                status.add(job.getResult());
            }
        }
    };
    mgr.addJobChangeListener(changeListener);
    for (int i = 0; i < 10; i++) {
        SWTBotUtils.openTrace(TRACE_PROJECT_NAME, path, TRACE_TYPE, false);
        SWTBotUtils.openTrace(TRACE_PROJECT_NAME, path, TRACE_TYPE, false);
        SWTBotUtils.openTrace(TRACE_PROJECT_NAME, path, TRACE_TYPE, false);
        SWTBotUtils.openTrace(TRACE_PROJECT_NAME, path, TRACE_TYPE, false);
        SWTBotUtils.openTrace(TRACE_PROJECT_NAME, path, TRACE_TYPE, false);
        // Wait for editor so that threads have a chance to start
        workbenchbot.editorByTitle(fTestFile.getName());
        workbenchbot.closeAllEditors();

        if (!status.isOK()) {
            SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, workbenchbot);
            fail(handleErrorStatus(status));
        }
    }
    SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, workbenchbot);
}
 
Example 10
Source File: TerminateLaunchesActionPDETest.java    From eclipse-extras with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void done( IJobChangeEvent event ) {
  if( event.getJob() instanceof TerminateLaunchesJob ) {
    jobDone.set( true );
  }
}