Search in sources :

Example 81 with IJobChangeEvent

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();
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 82 with IJobChangeEvent

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);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IJobChangeListener(org.eclipse.core.runtime.jobs.IJobChangeListener) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 83 with IJobChangeEvent

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);
    }
}
Also used : ReferencedLibraries(org.eclipse.jdt.ls.core.internal.preferences.Preferences.ReferencedLibraries) IJavaProject(org.eclipse.jdt.core.IJavaProject) Optional(java.util.Optional) IJobChangeListener(org.eclipse.core.runtime.jobs.IJobChangeListener) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IMarker(org.eclipse.core.resources.IMarker) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) File(java.io.File) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test) HoverHandlerTest(org.eclipse.jdt.ls.core.internal.handlers.HoverHandlerTest)

Example 84 with IJobChangeEvent

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());
    }
}
Also used : HashMap(java.util.HashMap) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) IJobChangeListener(org.eclipse.core.runtime.jobs.IJobChangeListener) IMarker(org.eclipse.core.resources.IMarker) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test) HoverHandlerTest(org.eclipse.jdt.ls.core.internal.handlers.HoverHandlerTest)

Example 85 with IJobChangeEvent

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;
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) IAuthorizationDetails(com.openshift.restclient.authorization.IAuthorizationDetails)

Aggregations

IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)172 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)163 Job (org.eclipse.core.runtime.jobs.Job)46 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)45 IStatus (org.eclipse.core.runtime.IStatus)36 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)30 ArrayList (java.util.ArrayList)13 IFile (org.eclipse.core.resources.IFile)13 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 CoreException (org.eclipse.core.runtime.CoreException)12 DataSourceJob (org.jkiss.dbeaver.runtime.jobs.DataSourceJob)12 Status (org.eclipse.core.runtime.Status)11 IJobChangeListener (org.eclipse.core.runtime.jobs.IJobChangeListener)11 IOException (java.io.IOException)10 DBException (org.jkiss.dbeaver.DBException)10 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)10 IProject (org.eclipse.core.resources.IProject)9 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 Composite (org.eclipse.swt.widgets.Composite)7