Example usage for org.eclipse.jdt.internal.core.builder JavaBuilder buildFinished

List of usage examples for org.eclipse.jdt.internal.core.builder JavaBuilder buildFinished

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.builder JavaBuilder buildFinished.

Prototype

public static void buildFinished() 

Source Link

Document

Hook allowing to reset some static state after a complete build iteration.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.DeltaProcessor.java

License:Open Source License

public void resourceChanged(IResourceChangeEvent event) {

    int eventType = this.overridenEventType == -1 ? event.getType() : this.overridenEventType;
    //      IResource resource = event.getResource();
    IResourceDelta delta = (IResourceDelta) event.getDelta();

    switch (eventType) {
    case IResourceChangeEvent.PRE_DELETE:
        //            try {
        //               if(resource.getType() == IResource.PROJECT
        //                  && ((IProject) resource).hasNature(JavaCore.NATURE_ID)) {
        ///*from   w ww.ja v a2  s .  com*/
        //                  deleting((IProject)resource);
        //               }
        //            } catch(CoreException e){
        //               // project doesn't exist or is not open: ignore
        //            }
        return;

    case IResourceChangeEvent.PRE_REFRESH:
        //            IProject[] projects = null;
        //            Object o = event.getSource();
        //            if (o instanceof IProject) {
        //               projects = new IProject[] { (IProject) o };
        //            } else if (o instanceof IWorkspace) {
        //               // https://bugs.eclipse.org/bugs/show_bug.cgi?id=261594. The single workspace refresh
        //               // notification we see, implies that all projects are about to be refreshed.
        //                projects = ((IWorkspace) o).getRoot().getProjects(IContainer.INCLUDE_HIDDEN);
        //            }
        //            //https://bugs.eclipse.org/bugs/show_bug.cgi?id=302295
        //            // Refresh all project references together in a single job
        //            JavaModelManager.getExternalManager().refreshReferences(projects, null);
        //
        //            IJavaProject[] javaElements = new IJavaProject[projects.length];
        //            for (int index = 0; index < projects.length; index++) {
        //               javaElements[index] = JavaCore.create(projects[index]);
        //            }
        //            try {
        //               checkExternalArchiveChanges(javaElements, true, null);
        //            } catch (JavaModelException e) {
        //                 if (!e.isDoesNotExist())
        //                    Util.log(e, "Exception while updating external archives"); //$NON-NLS-1$
        //            }
        return;

    case IResourceChangeEvent.POST_CHANGE:
        HashSet elementsToRefresh = this.state.removeExternalElementsToRefresh();
        if (isAffectedBy(delta) // avoid populating for SYNC or MARKER deltas
                || elementsToRefresh != null) {
            try {
                try {
                    stopDeltas();
                    checkProjectsAndClasspathChanges(delta);

                    // generate external archive change deltas
                    if (elementsToRefresh != null) {
                        createExternalArchiveDelta(elementsToRefresh, null);
                    }

                    // generate classpath change deltas
                    HashMap classpathChanges = this.state.removeAllClasspathChanges();
                    //                     if (classpathChanges.size() > 0) {
                    //                        boolean hasDelta = this.currentDelta != null;
                    //                        JavaElementDelta javaDelta = currentDelta();
                    //                        Iterator changes = classpathChanges.values().iterator();
                    //                        while (changes.hasNext()) {
                    //                           ClasspathChange change = (ClasspathChange) changes.next();
                    //                           int result = change.generateDelta(javaDelta, false/*don't add classpath change*/);
                    //                           if ((result & ClasspathChange.HAS_DELTA) != 0) {
                    //                              hasDelta = true;
                    //
                    //                              // need to recompute root infos
                    //                              this.state.rootsAreStale = true;
                    //
                    //                              change.requestIndexing();
                    //                              this.state.addClasspathValidation(change.project);
                    //                           }
                    //                           if ((result & ClasspathChange.HAS_PROJECT_CHANGE) != 0) {
                    //                              this.state.addProjectReferenceChange(change.project, change.oldResolvedClasspath);
                    //                           }
                    //                           if ((result & ClasspathChange.HAS_LIBRARY_CHANGE) != 0) {
                    //                              this.state.addExternalFolderChange(change.project, change.oldResolvedClasspath);
                    //                           }
                    //                        }
                    //                        // process late coming external elements to refresh (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=212769 )
                    //                        elementsToRefresh = this.state.removeExternalElementsToRefresh();
                    //                        if (elementsToRefresh != null) {
                    //                           hasDelta |= createExternalArchiveDelta(elementsToRefresh, null);
                    //                        }
                    //                        if (!hasDelta)
                    //                           this.currentDelta = null;
                    //                     }

                    // generate Java deltas from resource changes
                    IJavaElementDelta translatedDelta = processResourceDelta(delta);
                    if (translatedDelta != null) {
                        registerJavaModelDelta(translatedDelta);
                    }
                } finally {
                    this.sourceElementParserCache = null; // don't hold onto parser longer than necessary
                    startDeltas();
                }
                IElementChangedListener[] listeners;
                int listenerCount;
                synchronized (this.state) {
                    listeners = this.state.elementChangedListeners;
                    listenerCount = this.state.elementChangedListenerCount;
                }
                notifyTypeHierarchies(listeners, listenerCount);
                fire(null, ElementChangedEvent.POST_CHANGE);
            } finally {
                // workaround for bug 15168 circular errors not reported
                this.state.resetOldJavaProjectNames();
                this.oldRoots = null;
            }
        }
        return;

    case IResourceChangeEvent.PRE_BUILD:
        //            // force initialization of roots before builders run to avoid deadlock in another thread
        //            // (note this is no-op if already initialized)
        //            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=241751
        //            this.state.initializeRoots(false/*not initiAfterLoad*/);
        //
        //            boolean isAffected = isAffectedBy(delta);
        //            boolean needCycleValidation = isAffected && validateClasspaths(delta);
        //
        //            // update external folders if necessary
        //             ExternalFolderChange[] folderChanges = this.state.removeExternalFolderChanges();
        //            if (folderChanges != null) {
        //                for (int i = 0, length = folderChanges.length; i < length; i++) {
        //                    try {
        //                       folderChanges[i].updateExternalFoldersIfNecessary(false/*do not refresh since we are not in the thread that added the external folder to the classpath*/, null);
        //                    } catch (JavaModelException e) {
        //                       if (!e.isDoesNotExist())
        //                          Util.log(e, "Exception while updating external folders"); //$NON-NLS-1$
        //                    }
        //                }
        //            }
        //
        //            // create classpath markers if necessary
        //            ClasspathValidation[] validations = this.state.removeClasspathValidations();
        //            if (validations != null) {
        //               for (int i = 0, length = validations.length; i < length; i++) {
        //                  ClasspathValidation validation = validations[i];
        //                  validation.validate();
        //               }
        //            }
        //
        //            // update project references if necessary
        //             ProjectReferenceChange[] projectRefChanges = this.state.removeProjectReferenceChanges();
        //            if (projectRefChanges != null) {
        //                for (int i = 0, length = projectRefChanges.length; i < length; i++) {
        //                    try {
        //                       projectRefChanges[i].updateProjectReferencesIfNecessary();
        //                    } catch(JavaModelException e) {
        //                        // project doesn't exist any longer, continue with next one
        //                       if (!e.isDoesNotExist())
        //                          Util.log(e, "Exception while updating project references"); //$NON-NLS-1$
        //                    }
        //                }
        //            }
        //
        //            if (needCycleValidation || projectRefChanges != null) {
        //               // update all cycle markers since the project references changes may have affected cycles
        //               try {
        //                  JavaProject.validateCycles(null);
        //               } catch (JavaModelException e) {
        //                  // a project no longer exists
        //               }
        //            }
        //
        //            if (isAffected) {
        //               Object source = event.getSource();
        //               projects = null;
        //               if (source instanceof IWorkspace) {
        //                   projects = ((IWorkspace) source).getRoot().getProjects();
        //               } else if (source instanceof IProject) {
        //                  projects = new IProject[] {(IProject) source};
        //               } else {
        //                  Util.log(new Exception(),
        //                         "Expected to see a workspace or project on the PRE_BUILD resource change but was: " + source.toString()); //$NON-NLS-1$
        //               }
        //               if (projects != null) {
        //                  // If we are about to do a build and a Java project's first builder is not the Java builder,
        //                  // then it is possible that one of the earlier builders will build a jar file that is on that
        //                  // project's classpath. If we see that, then to be safe we must flush the caching of the
        //                  // JavaModelManager's external file state.
        //                  // A possible further optimization for this situation where earlier builders can affect the
        //                  // Java builder would be to add a new classpath element attribute that identifies whether
        //                  // or not a library jar is "stable" and needs to be flushed.
        //                  for (int i = 0; i < projects.length; i++) {
        //                     try {
        //                        IProject project = projects[i];
        //                        if (project.isOpen() && project.hasNature(JavaCore.NATURE_ID)) {
        //                           IBuildConfiguration[] configs = project.getBuildConfigs();
        //                           if (configs.length > 1 && !JavaCore.BUILDER_ID.equals(configs[0].getName())) {
        //                              this.manager.resetExternalFilesCache();
        //                              break;
        //                           }
        //                        }
        //                     } catch (CoreException exception) {
        //                          Util.log(exception, "Exception while checking builder configuration ordering"); //$NON-NLS-1$
        //                     }
        //                   }
        //               }
        //               JavaBuilder.buildStarting();
        //            }

        // does not fire any deltas
        return;

    case IResourceChangeEvent.POST_BUILD:
        JavaBuilder.buildFinished();
        return;
    }
}

From source file:org.eclipse.che.jdt.internal.core.DeltaProcessor.java

License:Open Source License

public void resourceChanged(IResourceChangeEvent event) {

    int eventType = this.overridenEventType == -1 ? event.getType() : this.overridenEventType;
    //      IResource resource = event.getResource();
    IResourceDelta delta = (IResourceDelta) event.getDelta();

    switch (eventType) {
    case IResourceChangeEvent.PRE_DELETE:
        //            try {
        //               if(resource.getType() == IResource.PROJECT
        //                  && ((IProject) resource).hasNature(JavaCore.NATURE_ID)) {
        ///*w  w  w .  j a v  a2 s . c  o  m*/
        //                  deleting((IProject)resource);
        //               }
        //            } catch(CoreException e){
        //               // project doesn't exist or is not open: ignore
        //            }
        return;

    case IResourceChangeEvent.PRE_REFRESH:
        //            IProject[] projects = null;
        //            Object o = event.getSource();
        //            if (o instanceof IProject) {
        //               projects = new IProject[] { (IProject) o };
        //            } else if (o instanceof IWorkspace) {
        //               // https://bugs.eclipse.org/bugs/show_bug.cgi?id=261594. The single workspace refresh
        //               // notification we see, implies that all projects are about to be refreshed.
        //                projects = ((IWorkspace) o).getRoot().getProjects(IContainer.INCLUDE_HIDDEN);
        //            }
        //            //https://bugs.eclipse.org/bugs/show_bug.cgi?id=302295
        //            // Refresh all project references together in a single job
        //            JavaModelManager.getExternalManager().refreshReferences(projects, null);
        //
        //            IJavaProject[] javaElements = new IJavaProject[projects.length];
        //            for (int index = 0; index < projects.length; index++) {
        //               javaElements[index] = JavaCore.create(projects[index]);
        //            }
        //            try {
        //               checkExternalArchiveChanges(javaElements, true, null);
        //            } catch (JavaModelException e) {
        //                 if (!e.isDoesNotExist())
        //                    Util.log(e, "Exception while updating external archives"); //$NON-NLS-1$
        //            }
        return;

    case IResourceChangeEvent.POST_CHANGE:
        HashSet elementsToRefresh = this.state.removeExternalElementsToRefresh();
        if (isAffectedBy(delta) // avoid populating for SYNC or MARKER deltas
                || elementsToRefresh != null) {
            try {
                try {
                    stopDeltas();
                    checkProjectsAndClasspathChanges(delta);

                    // generate external archive change deltas
                    if (elementsToRefresh != null) {
                        createExternalArchiveDelta(elementsToRefresh, null);
                    }

                    // generate classpath change deltas
                    HashMap classpathChanges = this.state.removeAllClasspathChanges();
                    //                     if (classpathChanges.size() > 0) {
                    //                        boolean hasDelta = this.currentDelta != null;
                    //                        JavaElementDelta javaDelta = currentDelta();
                    //                        Iterator changes = classpathChanges.values().iterator();
                    //                        while (changes.hasNext()) {
                    //                           ClasspathChange change = (ClasspathChange) changes.next();
                    //                           int result = change.generateDelta(javaDelta, false/*don't add classpath change*/);
                    //                           if ((result & ClasspathChange.HAS_DELTA) != 0) {
                    //                              hasDelta = true;
                    //
                    //                              // need to recompute root infos
                    //                              this.state.rootsAreStale = true;
                    //
                    //                              change.requestIndexing();
                    //                              this.state.addClasspathValidation(change.project);
                    //                           }
                    //                           if ((result & ClasspathChange.HAS_PROJECT_CHANGE) != 0) {
                    //                              this.state.addProjectReferenceChange(change.project, change.oldResolvedClasspath);
                    //                           }
                    //                           if ((result & ClasspathChange.HAS_LIBRARY_CHANGE) != 0) {
                    //                              this.state.addExternalFolderChange(change.project, change.oldResolvedClasspath);
                    //                           }
                    //                        }
                    //                        // process late coming external elements to refresh (see https://bugs.eclipse.org/bugs/show_bug
                    // .cgi?id=212769 )
                    //                        elementsToRefresh = this.state.removeExternalElementsToRefresh();
                    //                        if (elementsToRefresh != null) {
                    //                           hasDelta |= createExternalArchiveDelta(elementsToRefresh, null);
                    //                        }
                    //                        if (!hasDelta)
                    //                           this.currentDelta = null;
                    //                     }

                    // generate Java deltas from resource changes
                    IJavaElementDelta translatedDelta = processResourceDelta(delta);
                    if (translatedDelta != null) {
                        registerJavaModelDelta(translatedDelta);
                    }
                } finally {
                    this.sourceElementParserCache = null; // don't hold onto parser longer than necessary
                    startDeltas();
                }
                IElementChangedListener[] listeners;
                int listenerCount;
                synchronized (this.state) {
                    listeners = this.state.elementChangedListeners;
                    listenerCount = this.state.elementChangedListenerCount;
                }
                notifyTypeHierarchies(listeners, listenerCount);
                fire(null, ElementChangedEvent.POST_CHANGE);
            } finally {
                // workaround for bug 15168 circular errors not reported
                this.state.resetOldJavaProjectNames();
                this.oldRoots = null;
            }
        }
        return;

    case IResourceChangeEvent.PRE_BUILD:
        //            // force initialization of roots before builders run to avoid deadlock in another thread
        //            // (note this is no-op if already initialized)
        //            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=241751
        //            this.state.initializeRoots(false/*not initiAfterLoad*/);
        //
        //            boolean isAffected = isAffectedBy(delta);
        //            boolean needCycleValidation = isAffected && validateClasspaths(delta);
        //
        //            // update external folders if necessary
        //             ExternalFolderChange[] folderChanges = this.state.removeExternalFolderChanges();
        //            if (folderChanges != null) {
        //                for (int i = 0, length = folderChanges.length; i < length; i++) {
        //                    try {
        //                       folderChanges[i].updateExternalFoldersIfNecessary(false/*do not refresh since we are not in the thread that
        // added the external folder to the classpath*/, null);
        //                    } catch (JavaModelException e) {
        //                       if (!e.isDoesNotExist())
        //                          Util.log(e, "Exception while updating external folders"); //$NON-NLS-1$
        //                    }
        //                }
        //            }
        //
        //            // create classpath markers if necessary
        //            ClasspathValidation[] validations = this.state.removeClasspathValidations();
        //            if (validations != null) {
        //               for (int i = 0, length = validations.length; i < length; i++) {
        //                  ClasspathValidation validation = validations[i];
        //                  validation.validate();
        //               }
        //            }
        //
        //            // update project references if necessary
        //             ProjectReferenceChange[] projectRefChanges = this.state.removeProjectReferenceChanges();
        //            if (projectRefChanges != null) {
        //                for (int i = 0, length = projectRefChanges.length; i < length; i++) {
        //                    try {
        //                       projectRefChanges[i].updateProjectReferencesIfNecessary();
        //                    } catch(JavaModelException e) {
        //                        // project doesn't exist any longer, continue with next one
        //                       if (!e.isDoesNotExist())
        //                          Util.log(e, "Exception while updating project references"); //$NON-NLS-1$
        //                    }
        //                }
        //            }
        //
        //            if (needCycleValidation || projectRefChanges != null) {
        //               // update all cycle markers since the project references changes may have affected cycles
        //               try {
        //                  JavaProject.validateCycles(null);
        //               } catch (JavaModelException e) {
        //                  // a project no longer exists
        //               }
        //            }
        //
        //            if (isAffected) {
        //               Object source = event.getSource();
        //               projects = null;
        //               if (source instanceof IWorkspace) {
        //                   projects = ((IWorkspace) source).getRoot().getProjects();
        //               } else if (source instanceof IProject) {
        //                  projects = new IProject[] {(IProject) source};
        //               } else {
        //                  Util.log(new Exception(),
        //                         "Expected to see a workspace or project on the PRE_BUILD resource change but was: " + source.toString());
        // $NON-NLS-1$
        //               }
        //               if (projects != null) {
        //                  // If we are about to do a build and a Java project's first builder is not the Java builder,
        //                  // then it is possible that one of the earlier builders will build a jar file that is on that
        //                  // project's classpath. If we see that, then to be safe we must flush the caching of the
        //                  // JavaModelManager's external file state.
        //                  // A possible further optimization for this situation where earlier builders can affect the
        //                  // Java builder would be to add a new classpath element attribute that identifies whether
        //                  // or not a library jar is "stable" and needs to be flushed.
        //                  for (int i = 0; i < projects.length; i++) {
        //                     try {
        //                        IProject project = projects[i];
        //                        if (project.isOpen() && project.hasNature(JavaCore.NATURE_ID)) {
        //                           IBuildConfiguration[] configs = project.getBuildConfigs();
        //                           if (configs.length > 1 && !JavaCore.BUILDER_ID.equals(configs[0].getName())) {
        //                              this.manager.resetExternalFilesCache();
        //                              break;
        //                           }
        //                        }
        //                     } catch (CoreException exception) {
        //                          Util.log(exception, "Exception while checking builder configuration ordering"); //$NON-NLS-1$
        //                     }
        //                   }
        //               }
        //               JavaBuilder.buildStarting();
        //            }

        // does not fire any deltas
        return;

    case IResourceChangeEvent.POST_BUILD:
        JavaBuilder.buildFinished();
        return;
    }
}