use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by dbeaver.
the class ObjectEditorPageControl method runService.
public synchronized <OBJECT_TYPE> void runService(LoadingJob<OBJECT_TYPE> service) {
curService = service;
service.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
synchronized (ObjectEditorPageControl.this) {
curService = null;
}
}
});
service.schedule();
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project eclipse.jdt.ls by eclipse.
the class MavenBuildSupportTest method testIgnoreInnerPomChanges.
@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);
}
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project eclipse.jdt.ls by eclipse.
the class InvisibleProjectBuildSupportTest method testDynamicReferenceLibraries.
@Test
public void testDynamicReferenceLibraries() 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());
ReferencedLibraries libraries = new ReferencedLibraries();
libraries.getInclude().add("lib/foo.jar");
libraries.getInclude().add("library/**/*.jar");
libraries.getExclude().add("library/sources/**");
libraries.getSources().put("library/bar.jar", "library/sources/bar-src.jar");
preferenceManager.getPreferences().setReferencedLibraries(libraries);
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;
}
}
};
File originBinary = new File(getSourceProjectDirectory(), "eclipse/source-attachment/foo.jar");
File originSource = new File(getSourceProjectDirectory(), "eclipse/source-attachment/foo-sources.jar");
File libFolder = Files.createDirectories(projectFolder.toPath().resolve("lib")).toFile();
File libraryFolder = Files.createDirectories(projectFolder.toPath().resolve("library")).toFile();
File sourcesFolder = Files.createDirectories(libraryFolder.toPath().resolve("sources")).toFile();
try {
Job.getJobManager().addJobChangeListener(listener);
{
// Include following jars (with detected source jar)
// - /lib/foo.jar
// - /lib/foo-sources.jar
File fooBinary = new File(libFolder, "foo.jar");
File fooSource = new File(libFolder, "foo-sources.jar");
FileUtils.copyFile(originBinary, fooBinary);
FileUtils.copyFile(originSource, fooSource);
projectsManager.fileChanged(fooBinary.toURI().toString(), CHANGE_TYPE.CREATED);
waitForBackgroundJobs();
IClasspathEntry[] classpath = javaProject.getRawClasspath();
Optional<IClasspathEntry> fooEntry = Arrays.stream(classpath).filter(c -> c.getPath().lastSegment().equals("foo.jar")).findFirst();
assertTrue("Cannot find foo binary", fooEntry.isPresent());
assertEquals("Update classpath job should have been invoked 1 times", 1, jobInvocations[0]);
assertEquals("Unexpected classpath:\n" + JavaProjectHelper.toString(classpath), 3, classpath.length);
assertEquals("foo.jar", fooEntry.get().getPath().lastSegment());
assertEquals("foo-sources.jar", fooEntry.get().getSourceAttachmentPath().lastSegment());
}
{
// Include following jars (with manually addding source map):
// - /library/bar.jar
// - /library/sources/bar-src.jar
File barBinary = new File(libraryFolder, "bar.jar");
File barSource = new File(sourcesFolder, "bar-src.jar");
FileUtils.copyFile(originBinary, barBinary);
FileUtils.copyFile(originSource, barSource);
projectsManager.fileChanged(barBinary.toURI().toString(), CHANGE_TYPE.CREATED);
waitForBackgroundJobs();
IClasspathEntry[] classpath = javaProject.getRawClasspath();
Optional<IClasspathEntry> barEntry = Arrays.stream(classpath).filter(c -> c.getPath().lastSegment().equals("bar.jar")).findFirst();
assertTrue("Cannot find bar binary", barEntry.isPresent());
assertEquals("Update classpath job should have been invoked 2 times", 2, jobInvocations[0]);
assertEquals("Unexpected classpath:\n" + JavaProjectHelper.toString(classpath), 4, classpath.length);
assertEquals("bar.jar", barEntry.get().getPath().lastSegment());
assertEquals("bar-src.jar", barEntry.get().getSourceAttachmentPath().lastSegment());
}
{
// Include following jars (will be excluded):
// - /library/sources/exclude.jar
// - /library/sources/exclude-sources.jar
File excludeBinary = new File(sourcesFolder, "exclude.jar");
File excludeSource = new File(sourcesFolder, "exclude-sources.jar");
FileUtils.copyFile(originBinary, excludeBinary);
FileUtils.copyFile(originSource, excludeSource);
// won't send update request
projectsManager.fileChanged(excludeBinary.toURI().toString(), CHANGE_TYPE.CREATED);
waitForBackgroundJobs();
assertEquals("Update classpath job should still have been invoked 2 times", 2, jobInvocations[0]);
assertEquals("Classpath length should still be 4", 4, javaProject.getRawClasspath().length);
}
} finally {
Job.getJobManager().removeJobChangeListener(listener);
}
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project eclipse.jdt.ls by eclipse.
the class InvisibleProjectBuildSupportTest method testManuallyReferenceLibraries.
@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);
// Request sent by jdt.ls's lib detection
projectsManager.fileChanged(fooBinary.toURI().toString(), CHANGE_TYPE.CREATED);
// Request sent by third-party client
UpdateClasspathJob.getInstance().updateClasspath(javaProject, include, exclude, sources);
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());
}
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project jbosstools-openshift by jbosstools.
the class OAuthDetailView method createAuthDetailsJob.
protected Job createAuthDetailsJob(Shell shell) {
Job job = new AuthDetailsJob(pageModel.getHost());
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(final IJobChangeEvent event) {
if (event.getJob() instanceof AuthDetailsJob) {
shell.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
AuthDetailsJob job = (AuthDetailsJob) event.getJob();
final IAuthorizationDetails details = job.getDetails();
if (details != null) {
// TODO fix this to handle other authschemes
if (IAuthorizationContext.AUTHSCHEME_BASIC.equals(details.getScheme())) {
MessageDialog.openError(shell, "Authorization Information", NLS.bind("This server utilizes {0} authorization protocol", details.getScheme()));
authSchemeObservable.setValue(details.getScheme());
} else {
OAuthDialog dialog = new OAuthDialog(shell, details.getRequestTokenLink());
dialog.open();
String token = dialog.getToken();
if (StringUtils.isNotBlank(token)) {
tokenObservable.setValue(token);
}
}
}
}
});
}
}
});
return job;
}
Aggregations