org.eclipse.core.runtime.jobs.IJobChangeListener Java Examples

The following examples show how to use org.eclipse.core.runtime.jobs.IJobChangeListener. 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: MavenBuildSupportTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testIgnoreInnerPomChanges() throws Exception {
	IProject project = importMavenProject("archetyped");
	assertEquals("The inner pom should not have been imported", 2, WorkspaceHelper.getAllProjects().size());

	IFile innerPom = project.getFile("src/main/resources/archetype-resources/pom.xml");

	preferences.setUpdateBuildConfigurationStatus(FeatureStatus.automatic);
	boolean[] updateTriggered = new boolean[1];
	IJobChangeListener listener = new JobChangeAdapter() {
		@Override
		public void scheduled(IJobChangeEvent event) {
			if (event.getJob().getName().contains("Update project")) {
				updateTriggered[0] = true;
			}
		}
	};
	try {
		Job.getJobManager().addJobChangeListener(listener);
		projectsManager.fileChanged(innerPom.getRawLocationURI().toString(), CHANGE_TYPE.CHANGED);
		waitForBackgroundJobs();
		assertFalse("Update project should not have been triggered", updateTriggered[0]);
	} finally {
		Job.getJobManager().removeJobChangeListener(listener);
	}
}
 
Example #2
Source File: TestedWorkspaceWithJDT.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected IJobChangeListener getJobListener() {
	return listener;
}
 
Example #3
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 #4
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 #5
Source File: ModelCheckerTest.java    From tlaplus with MIT License 4 votes vote down vote up
@Test
public void testNewModel() {
	// Open specA
	SWTBotMenu fileMenu = bot.menu("File");
	SWTBotMenu openSpecMenu = fileMenu.menu("Open Spec");
	SWTBotMenu addNewSpecMenu = openSpecMenu.menu("Add New Spec...");
	addNewSpecMenu.click();

	bot.textWithLabel("Root-module file:").setText(specA);
	bot.button("Finish").click();

	final String specName = getSpecName(new File(specA));

	// specs are created in non-UI thread asynchronously which causes a
	// delay before the menu entry becomes available
	bot.waitUntil(Conditions.waitForMenu(bot.activeShell(), WithText.<MenuItem> withText(specName)));
	
	// create a new model
	final SWTBotMenu modelMenu = bot.menu("TLC Model Checker");
	final SWTBotMenu newModelMenu = modelMenu.menu("New Model...");
	newModelMenu.click();
	bot.button("OK").click();

	// wait for model editor to show up and parse
	bot.waitUntil(new ModelEditorOpenCondition("Model_"));
	
	// register job listener who listens for the model checker job
	final String modelName = UIHelper.getActiveEditor().getTitle();
	final Model model = ToolboxHandle.getCurrentSpec().getAdapter(TLCSpec.class).getModel(modelName);
	final IJobChangeListener listener = new DummyJobChangeListener(model);
	Job.getJobManager().addJobChangeListener(listener);
	
	// start model checking by clicking the menu. This is more robust
	// compared to the f11 keystroke which can get lost when fired during
	// initialization of the model editor.
	bot.menu("TLC Model Checker").menu("Run model").click();

	// make unit test wait for model checker job to finish
	bot.waitUntil((ICondition) listener, SWTBotPreferences.TIMEOUT * 3);

	// Do some unregistration prior to model deletion:
	Job.getJobManager().removeJobChangeListener(listener);
	
	// close corresponding editor if open
	final IEditorPart editorWithModelOpened = model.getAdapter(ModelEditor.class);
	if (editorWithModelOpened != null) {
		UIHelper.runUISync(new Runnable() {
			public void run() {
				UIHelper.getActivePage().closeEditor(editorWithModelOpened,
						false);
			}
		});
	}

	// Delete the newly created model again. It does not use the UI because
	// SWTBot cannot handle the modal confirmation dialog do delete the
	// model.
	// Deleting the model is necessary because repeated test execution would
	// leave huge numbers of model leftovers contributing to slowed down test
	// execution (see SizeControlContribution for reason why).
	try {
		model.delete(new NullProgressMonitor());
	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example #6
Source File: RenameSpecHandlerTest.java    From tlaplus with MIT License 4 votes vote down vote up
/**
 * @see Bug #58 in general/bugzilla/index.html
 */
@Test
public void renameSpec() throws InterruptedException {
	openSpecExplorer();

	SWTBotTreeItem treeItem = bot.tree().getTreeItem(TEST_SPEC);
	checkForModelExistenceUI(treeItem);

	SWTBotMenu contextMenu = treeItem.contextMenu("Rename");
	contextMenu.click();
	
	// rename to ..._Copy
	bot.button("OK").click();
	
	// wait for rename to be done
	bot.waitUntil(new SpecEditorOpenCondition(TEST_SPEC));

	// verify (via API)
	checkSpecAndModelExistenceAPI((TEST_SPEC + "_Copy"), TEST_MODEL);
	
	// try to find the renamed file (via UI)
	openSpecExplorer();
	treeItem = bot.tree().getTreeItem(TEST_SPEC + "_Copy [ " + TEST_SPEC + TLA_SUFFIX + " ]");
	
	/*
	 * try to launch the model
	 */
	SWTBotTreeItem modelTreeItem = checkForModelExistenceUI(treeItem);
	modelTreeItem.contextMenu("Open").click();
	Assert.assertNotNull("UI tree item (model) could not be found", modelTreeItem);
	
	// register job listener who listens for the model checker job
	final String modelName = UIHelper.getActiveEditor().getTitle();
	final Model model = ToolboxHandle.getCurrentSpec().getAdapter(TLCSpec.class).getModel(modelName);
	final IJobChangeListener listener = new DummyJobChangeListener(model);
	Job.getJobManager().addJobChangeListener(listener);
	
	// start model checking by clicking the menu. This is more robust
	// compared to the f11 keystroke which can get lost when fired during
	// initialization of the model editor.
	bot.menu("TLC Model Checker").menu("Run model").click();

	// make unit test wait for model checker job to finish
	bot.waitUntil((ICondition) listener, SWTBotPreferences.TIMEOUT * 3);

	// Do some unregistration prior to model deletion:
	Job.getJobManager().removeJobChangeListener(listener);
	
	// close corresponding editor if open
	final IEditorPart editorWithModelOpened = model.getAdapter(ModelEditor.class);
	if (editorWithModelOpened != null) {
		UIHelper.runUISync(new Runnable() {
			public void run() {
				UIHelper.getActivePage().closeEditor(editorWithModelOpened,
						false);
			}
		});
	}
}