org.eclipse.wst.sse.core_1.1.602.v201112071516

16:49:25.690 INFO  jd.cli.Main - Decompiling org.eclipse.wst.sse.core_1.1.602.v201112071516.jar
package org.eclipse.wst.sse.core;

import org.eclipse.core.runtime.Platform;
import org.eclipse.wst.sse.core.internal.model.ModelManagerImpl;
import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
import org.osgi.framework.Bundle;

public final class StructuredModelManager
{
  public static IModelManager getModelManager()
  {
    boolean isReady = false;
    IModelManager modelManager = null;
    boolean interrupted = false;
    try
    {
      while (!isReady)
      {
        Bundle localBundle = Platform.getBundle("org.eclipse.wst.sse.core");
        int state = localBundle.getState();
        if (state == 32)
        {
          isReady = true;
          
          modelManager = ModelManagerImpl.getInstance();
        }
        else if (state == 8)
        {
          try
          {
            Thread.sleep(100L);
          }
          catch (InterruptedException localInterruptedException)
          {
            interrupted = true;
          }
        }
        else if ((state == 16) || (state == 1))
        {
          isReady = true;
          modelManager = null;
        }
        else
        {
          isReady = true;
          modelManager = null;
        }
      }
    }
    finally
    {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
    return modelManager;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.sse.core.StructuredModelManager
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.sse.core.indexing;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.wst.sse.core.internal.Logger;

class AbstractIndexManager$1
  implements ISafeRunnable
{
  final AbstractIndexManager.ResourceEventProcessingJob this$1;
  private final byte val$source;
  private final byte val$action;
  private final IResource val$finResource;
  private final IPath val$movePath;
  
  AbstractIndexManager$1(AbstractIndexManager.ResourceEventProcessingJob paramResourceEventProcessingJob, byte paramByte1, byte paramByte2, IResource paramIResource, IPath paramIPath)
  {
    this$1 = paramResourceEventProcessingJob;val$source = paramByte1;val$action = paramByte2;val$finResource = paramIResource;val$movePath = paramIPath;
  }
  
  public void run()
    throws Exception
  {
    AbstractIndexManager.ResourceEventProcessingJob.access$0(this$1).performAction(val$source, val$action, val$finResource, val$movePath);
  }
  
  public void handleException(Throwable e)
  {
    Logger.logException("Error while performing an update to the index. Index may become invalid, incomplete, or enter some other inconsistent state.", 
      e);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.sse.core.indexing.AbstractIndexManager.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.sse.core.indexing;

import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.wst.sse.core.internal.Logger;

class AbstractIndexManager$ResourceChangeListener
  implements IResourceChangeListener
{
  private volatile int fEventsBeingProcessed;
  private final Object fEventsBeingProcessedLock;
  private volatile byte fState;
  final AbstractIndexManager this$0;
  
  protected AbstractIndexManager$ResourceChangeListener(AbstractIndexManager paramAbstractIndexManager)
  {
    this$0 = paramAbstractIndexManager;fEventsBeingProcessedLock = new Object();
    fState = 0;
    fEventsBeingProcessed = 0;
  }
  
  protected void start()
  {
    fState = 1;
    ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
  }
  
  protected void stop()
    throws InterruptedException
  {
    ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
    
    waitForCurrentEvent(0);
    
    fState = 0;
  }
  
  protected void waitForCurrentEvent(int timeout)
    throws InterruptedException
  {
    synchronized (fEventsBeingProcessedLock)
    {
      if (fEventsBeingProcessed != 0) {
        fEventsBeingProcessedLock.wait(timeout);
      }
    }
  }
  
  protected boolean isProcessingEvents()
  {
    return fEventsBeingProcessed != 0;
  }
  
  public void resourceChanged(IResourceChangeEvent event)
  {
    try
    {
      synchronized (fEventsBeingProcessedLock)
      {
        fEventsBeingProcessed += 1;
      }
      if (fState == 1) {
        switch (event.getType())
        {
        case 2: 
        case 4: 
          AbstractIndexManager.access$0(this$0).pause();
          break;
        case 1: 
        case 16: 
          AbstractIndexManager.access$0(this$0).unPause();
          
          IResourceDelta delta = event.getDelta();
          if ((delta == null) || (!delta.getFullPath().toString().equals("/"))) {
            break;
          }
          try
          {
            AbstractIndexManager.ResourceDeltaVisitor visitor = new AbstractIndexManager.ResourceDeltaVisitor(this$0, (byte)0);
            delta.accept(visitor, false);
            
            visitor.processBatchedResourceEvents();
          }
          catch (CoreException e)
          {
            Logger.logException(AbstractIndexManager.access$1(this$0) + ": Failed visiting resource change delta. " + "Index may become invalid, incomplete, or enter some other inconsistent state.", e);
          }
        }
      } else {
        Logger.log(4, "A resource change event came in after " + 
          AbstractIndexManager.access$1(this$0) + " shut down. This should never " + 
          "ever happen, but if it does the index may now be inconsistant.");
      }
    }
    finally
    {
      synchronized (fEventsBeingProcessedLock)
      {
        fEventsBeingProcessed -= 1;
        if (fEventsBeingProcessed == 0) {
          fEventsBeingProcessedLock.notifyAll();
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.sse.core.indexing.AbstractIndexManager.ResourceChangeListener
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.sse.core.indexing;

import java.util.LinkedHashMap;
import java.util.Map;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.sse.core.internal.SSECoreMessages;

class AbstractIndexManager$ResourceDeltaVisitor
  implements IResourceDeltaVisitor
{
  private SubMonitor fProgress;
  private byte fSource;
  private int fPredictedWorkRemaining;
  private Map fBatchedResourceEvents;
  final AbstractIndexManager this$0;
  
  protected AbstractIndexManager$ResourceDeltaVisitor(AbstractIndexManager paramAbstractIndexManager, byte source)
  {
    this(paramAbstractIndexManager, SubMonitor.convert(null), source);
  }
  
  protected AbstractIndexManager$ResourceDeltaVisitor(AbstractIndexManager paramAbstractIndexManager, SubMonitor progress, byte source)
  {
    this$0 = paramAbstractIndexManager;
    fProgress = progress;
    fSource = source;
    fBatchedResourceEvents = new LinkedHashMap(100);
    fPredictedWorkRemaining = 1;
  }
  
  public boolean visit(IResourceDelta delta)
    throws CoreException
  {
    fProgress.subTask(NLS.bind(SSECoreMessages.IndexManager_0_resources_to_go_1, new Object[] { fPredictedWorkRemaining, delta.getFullPath().toString() }));
    
    boolean visitChildren = false;
    if (delta.getResource().isDerived())
    {
      visitChildren = false;
    }
    else if (delta.getFullPath().isRoot())
    {
      visitChildren = true;
    }
    else
    {
      IResource resource = delta.getResource();
      if (this$0.isResourceToIndex(resource.getType(), resource.getFullPath()))
      {
        if (resource.getType() == 1) {
          switch (delta.getKind())
          {
          case 4: 
            if (((delta.getFlags() & 0x100) == 0) && ((delta.getFlags() & 0x40000) == 0) && ((delta.getFlags() & 0x8000) == 0) && ((delta.getFlags() & 0x1000) == 0)) {
              break;
            }
          case 1: 
            if ((delta.getFlags() & 0x1000) != 0) {
              fBatchedResourceEvents.put(resource, new AbstractIndexManager.ResourceEvent(fSource, (byte)2, delta.getMovedFromPath()));
            } else {
              fBatchedResourceEvents.put(resource, new AbstractIndexManager.ResourceEvent(fSource, (byte)0, null));
            }
            break;
          case 2: 
            if ((delta.getFlags() & 0x2000) != 0) {
              fBatchedResourceEvents.put(resource, new AbstractIndexManager.ResourceEvent(fSource, (byte)3, delta.getMovedToPath()));
            } else {
              fBatchedResourceEvents.put(resource, new AbstractIndexManager.ResourceEvent(fSource, (byte)1, null));
            }
            break;
          }
        }
        visitChildren = true;
      }
      else
      {
        visitChildren = false;
      }
      if (visitChildren) {
        fPredictedWorkRemaining += delta.getAffectedChildren().length;
      }
      fProgress.setWorkRemaining(fPredictedWorkRemaining);
      fProgress.worked(1);
      fPredictedWorkRemaining -= 1;
      if (fBatchedResourceEvents.size() >= 100) {
        processBatchedResourceEvents();
      }
    }
    return visitChildren;
  }
  
  protected void processBatchedResourceEvents()
  {
    AbstractIndexManager.access$0(this$0).addResourceEvents(fBatchedResourceEvents);
    fBatchedResourceEvents.clear();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.sse.core.indexing.AbstractIndexManager.ResourceDeltaVisitor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.sse.core.indexing;

import org.eclipse.core.runtime.IPath;

class AbstractIndexManager$ResourceEvent
{
  protected byte fSource;
  protected byte fAction;
  protected IPath fMovePath;
  
  protected AbstractIndexManager$ResourceEvent(byte source, byte action, IPath movePath)
  {
    fSource = source;
    fAction = action;
    fMovePath = movePath;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.sse.core.indexing.AbstractIndexManager.ResourceEvent
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.sse.core.indexing;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.sse.core.internal.Logger;
import org.eclipse.wst.sse.core.internal.SSECoreMessages;

class AbstractIndexManager$ResourceEventProcessingJob
  extends Job
{
  private static final int DELAY = 500;
  private static final String PRESERVED_RESOURCE_EVENTS_TO_PROCESS_FILE_NAME = ".preservedResourceEvents";
  private static final long serialVersionUID = 1L;
  private volatile boolean fIsPaused;
  private Map fResourceEvents;
  private final Object fResourceEventsLock;
  private final Object fToNotifyLock;
  final AbstractIndexManager this$0;
  
  protected AbstractIndexManager$ResourceEventProcessingJob(AbstractIndexManager paramAbstractIndexManager)
  {
    super(NLS.bind(SSECoreMessages.IndexManager_0_Processing_resource_events, AbstractIndexManager.access$1(paramAbstractIndexManager)));this$0 = paramAbstractIndexManager;fResourceEventsLock = new Object();fToNotifyLock = new Object();
    
    setUser(false);
    setSystem(true);
    setPriority(30);
    
    fIsPaused = false;
    fResourceEvents = new LinkedHashMap();
  }
  
  protected synchronized boolean start(boolean loadPreservedResourceEvents, SubMonitor progress)
  {
    boolean successLoadingPreserved = true;
    if (!loadPreservedResourceEvents)
    {
      File preservedResourceEventsFile = getPreservedResourceEventsFile();
      preservedResourceEventsFile.delete();
    }
    else
    {
      successLoadingPreserved = loadPreservedReceivedResourceEvents(progress);
    }
    schedule();
    
    return successLoadingPreserved;
  }
  
  protected synchronized boolean stop(boolean preserveResourceEvents)
    throws InterruptedException
  {
    cancel();
    join();
    
    boolean success = true;
    if ((preserveResourceEvents) && (hasResourceEventsToProcess())) {
      success = preserveReceivedResourceEvents();
    } else {
      getPreservedResourceEventsFile().delete();
    }
    return success;
  }
  
  protected synchronized boolean isProcessing()
  {
    return (getState() != 0) || (fIsPaused);
  }
  
  protected synchronized void unPause()
  {
    fIsPaused = false;
    if (getState() == 1) {
      wakeUp(500L);
    } else {
      schedule(500L);
    }
  }
  
  protected synchronized void pause()
  {
    fIsPaused = true;
    
    sleep();
  }
  
  protected void addResourceEvents(Map resourceEvents)
  {
    Iterator iter = resourceEvents.keySet().iterator();
    while (iter.hasNext())
    {
      IResource resource = (IResource)iter.next();
      AbstractIndexManager.ResourceEvent resourceEvent = (AbstractIndexManager.ResourceEvent)resourceEvents.get(resource);
      addResourceEvent(resource, resourceEvent);
    }
    if (!isProcessing()) {
      unPause();
    }
  }
  
  protected int getNumResourceEventsToProcess()
  {
    return fResourceEvents.size();
  }
  
  protected void waitForConsistant(int timeout)
    throws InterruptedException
  {
    if ((hasResourceEventsToProcess()) || (isProcessing())) {
      synchronized (fToNotifyLock)
      {
        fToNotifyLock.wait(timeout);
      }
    }
  }
  
  protected IStatus run(IProgressMonitor monitor)
  {
    try
    {
      SubMonitor progress = SubMonitor.convert(monitor);
      while ((!fIsPaused) && (!monitor.isCanceled()) && (hasResourceEventsToProcess()))
      {
        progress.setTaskName(NLS.bind(SSECoreMessages.IndexManager_0_Indexing_1_Files, new Object[] { AbstractIndexManager.access$1(this$0), getNumResourceEventsToProcess() }));
        progress.setWorkRemaining(getNumResourceEventsToProcess());
        
        AbstractIndexManager.ResourceEvent resourceEvent = null;
        IResource resource = null;
        synchronized (fResourceEventsLock)
        {
          resource = (IResource)fResourceEvents.keySet().iterator().next();
          resourceEvent = (AbstractIndexManager.ResourceEvent)fResourceEvents.remove(resource);
        }
        monitor.subTask(resource.getName());
        
        byte source = fSource;
        byte action = fAction;
        IResource finResource = resource;
        IPath movePath = fMovePath;
        SafeRunner.run(new AbstractIndexManager.1(this, source, action, finResource, movePath));
        
        progress.worked(1);
        
        Job.getJobManager().currentJob().yieldRule(monitor);
      }
      monitor.done();
    }
    finally
    {
      notifyIfConsistant();
    }
    IStatus exitStatus;
    IStatus exitStatus;
    if (monitor.isCanceled()) {
      exitStatus = Status.CANCEL_STATUS;
    } else {
      exitStatus = Status.OK_STATUS;
    }
    return exitStatus;
  }
  
  private void addResourceEvent(IResource resource, AbstractIndexManager.ResourceEvent resourceEvent)
  {
    synchronized (fResourceEventsLock)
    {
      if (!fResourceEvents.containsKey(resource)) {
        fResourceEvents.put(resource, resourceEvent);
      } else if (fSource == 0) {
        fResourceEvents.get(resource)).fAction = fAction;
      }
    }
  }
  
  private boolean hasResourceEventsToProcess()
  {
    return !fResourceEvents.isEmpty();
  }
  
  private boolean preserveReceivedResourceEvents()
  {
    File preservedResourceEventsFile = getPreservedResourceEventsFile();
    boolean success = true;
    synchronized (fResourceEventsLock)
    {
      DataOutputStream dos = null;
      try
      {
        if (preservedResourceEventsFile.exists())
        {
          preservedResourceEventsFile.delete();
          preservedResourceEventsFile.createNewFile();
        }
        FileOutputStream fos = new FileOutputStream(preservedResourceEventsFile);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        dos = new DataOutputStream(bos);
        
        dos.writeLong(1L);
        
        dos.writeInt(getNumResourceEventsToProcess());
        
        Iterator iter = fResourceEvents.keySet().iterator();
        while (iter.hasNext())
        {
          IResource resource = (IResource)iter.next();
          AbstractIndexManager.ResourceEvent resourceEvent = (AbstractIndexManager.ResourceEvent)fResourceEvents.get(resource);
          if (fSource != 1)
          {
            dos.writeByte(fAction);
            dos.writeByte(resource.getType());
            byte[] pathBytes = resource.getFullPath().toString().getBytes("utf16");
            dos.write(pathBytes);
            dos.writeByte(0);
            if (fMovePath != null) {
              dos.writeBytes(fMovePath.toPortableString());
            }
            dos.writeByte(0);
          }
        }
        fResourceEvents.clear();
        
        dos.flush();
      }
      catch (FileNotFoundException e)
      {
        Logger.logException(AbstractIndexManager.access$1(this$0) + ": Exception while opening file to preserve resources to index.", 
          e);
        success = false;
      }
      catch (IOException e)
      {
        Logger.logException(AbstractIndexManager.access$1(this$0) + ": Exception while writing to file to preserve resources to index.", 
          e);
        success = false;
      }
      finally
      {
        if (dos != null) {
          try
          {
            dos.close();
          }
          catch (IOException e)
          {
            Logger.logException(AbstractIndexManager.access$1(this$0) + ": Exception while closing file with preserved resources to index.", 
              e);
            success = false;
          }
        }
      }
      if (!success) {
        preservedResourceEventsFile.delete();
      }
    }
    return success;
  }
  
  private boolean loadPreservedReceivedResourceEvents(SubMonitor progress)
  {
    progress.subTask(SSECoreMessages.IndexManager_processing_deferred_resource_changes);
    
    boolean success = true;
    File preservedResourceEventsFile = getPreservedResourceEventsFile();
    if (preservedResourceEventsFile.exists())
    {
      Map preservedResourceEvents = null;
      
      DataInputStream dis = null;
      try
      {
        FileInputStream fis = new FileInputStream(preservedResourceEventsFile);
        BufferedInputStream bis = new BufferedInputStream(fis);
        dis = new DataInputStream(bis);
        
        long preservedSerialVersionUID = dis.readLong();
        if (preservedSerialVersionUID == 1L)
        {
          int numberOfRecords = dis.readInt();
          preservedResourceEvents = new LinkedHashMap(numberOfRecords);
          progress.setWorkRemaining(numberOfRecords);
          for (int i = 0; i < numberOfRecords; i++)
          {
            byte action = dis.readByte();
            
            byte fileType = dis.readByte();
            
            ByteArrayOutputStream resourceLocationStream = new ByteArrayOutputStream();
            byte b = dis.readByte();
            while (b != 0)
            {
              resourceLocationStream.write(b);
              b = dis.readByte();
            }
            ByteArrayOutputStream movePathBOS = new ByteArrayOutputStream();
            b = dis.readByte();
            while (b != 0)
            {
              movePathBOS.write(b);
              b = dis.readByte();
            }
            IResource resource = null;
            IPath resourcePath = new Path(new String(resourceLocationStream.toByteArray(), "utf16"));
            if ((!resourcePath.isRoot()) && (resourcePath.segmentCount() > 1))
            {
              if (fileType == 1) {
                resource = ResourcesPlugin.getWorkspace().getRoot().getFile(resourcePath);
              } else {
                resource = ResourcesPlugin.getWorkspace().getRoot().getFolder(resourcePath);
              }
            }
            else {
              Logger.log(2, "The AbstractIndexManager " + AbstractIndexManager.access$1(this$0) + " attempted to load an invlaid preserved resource event:\n" + "(" + resourcePath + ")");
            }
            IPath movePath = null;
            if (movePathBOS.size() != 0) {
              movePath = new Path(new String(movePathBOS.toByteArray(), "utf16"));
            }
            preservedResourceEvents.put(resource, new AbstractIndexManager.ResourceEvent((byte)3, action, movePath));
            
            progress.worked(1);
          }
        }
        else
        {
          success = false;
        }
      }
      catch (FileNotFoundException e)
      {
        Logger.logException(AbstractIndexManager.access$1(this$0) + ": Exception while opening file to read preserved resources to index. Index manager will recover by re-indexing workspace.", 
          e);
        success = false;
      }
      catch (IOException e)
      {
        Logger.logException(AbstractIndexManager.access$1(this$0) + ": Exception while reading from file of preserved resources to index. Index manager will recover by re-indexing workspace.", 
          e);
        success = false;
      }
      catch (Exception e)
      {
        Logger.logException(AbstractIndexManager.access$1(this$0) + ": Unexpected exception while reading from file of preserved resources to index. Index manager will recover by re-indexing workspace.", 
          e);
        success = false;
      }
      finally
      {
        if (dis != null) {
          try
          {
            dis.close();
          }
          catch (IOException e)
          {
            Logger.logException(
            
              AbstractIndexManager.access$1(this$0) + ": Exception while closing file of preserved resources" + " to index that was just read.  This should have no" + " effect on the consistency of the index.", 
              e);
          }
        }
      }
      if ((success) && (preservedResourceEvents != null)) {
        synchronized (fResourceEventsLock)
        {
          Iterator iter = preservedResourceEvents.keySet().iterator();
          while (iter.hasNext())
          {
            IResource resource = (IResource)iter.next();
            AbstractIndexManager.ResourceEvent event = (AbstractIndexManager.ResourceEvent)preservedResourceEvents.get(resource);
            fResourceEvents.put(resource, event);
          }
        }
      }
      preservedResourceEventsFile.delete();
    }
    progress.done();
    return success;
  }
  
  private File getPreservedResourceEventsFile()
  {
    IPath preservedResourcesToIndexPath = this$0.getWorkingLocation().append(".preservedResourceEvents");
    return new File(preservedResourcesToIndexPath.toOSString());
  }
  
  private void notifyIfConsistant()
  {
    if (!hasResourceEventsToProcess()) {
      synchronized (fToNotifyLock)
      {
        fToNotifyLock.notifyAll();
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.sse.core.indexing.AbstractIndexManager.ResourceEventProcessingJob
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.sse.core.indexing;

import java.util.LinkedHashMap;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;

class AbstractIndexManager$WorkspaceVisitorJob$WorkspaceVisitor
  implements IResourceProxyVisitor
{
  private SubMonitor fProgress;
  private Map fBatchedResourceEvents;
  final AbstractIndexManager.WorkspaceVisitorJob this$1;
  
  protected AbstractIndexManager$WorkspaceVisitorJob$WorkspaceVisitor(AbstractIndexManager.WorkspaceVisitorJob paramWorkspaceVisitorJob, IProgressMonitor monitor)
  {
    this$1 = paramWorkspaceVisitorJob;
    fProgress = SubMonitor.convert(monitor);
    fBatchedResourceEvents = new LinkedHashMap(100);
  }
  
  public boolean visit(IResourceProxy proxy)
    throws CoreException
  {
    fProgress.subTask(proxy.getName());
    
    boolean visitChildren = false;
    if (!fProgress.isCanceled()) {
      if (proxy.isDerived())
      {
        visitChildren = false;
      }
      else if (proxy.requestFullPath().isRoot())
      {
        visitChildren = true;
      }
      else if (AbstractIndexManager.WorkspaceVisitorJob.access$0(this$1).isResourceToIndex(proxy.getType(), proxy.requestFullPath()))
      {
        if (proxy.getType() == 1)
        {
          IFile file = (IFile)proxy.requestResource();
          if (file.exists()) {
            fBatchedResourceEvents.put(file, new AbstractIndexManager.ResourceEvent((byte)1, (byte)0, null));
          }
        }
        visitChildren = true;
      }
    }
    if (fBatchedResourceEvents.size() >= 100) {
      processBatchedResourceEvents();
    }
    return visitChildren;
  }
  
  protected void processBatchedResourceEvents()
  {
    AbstractIndexManager.access$0(AbstractIndexManager.WorkspaceVisitorJob.access$0(this$1)).addResourceEvents(fBatchedResourceEvents);
    fBatchedResourceEvents.clear();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.sse.core.indexing.AbstractIndexManager.WorkspaceVisitorJob.WorkspaceVisitor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.sse.core.indexing;

import java.util.LinkedHashMap;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.sse.core.internal.Logger;
import org.eclipse.wst.sse.core.internal.SSECoreMessages;

class AbstractIndexManager$WorkspaceVisitorJob
  extends Job
{
  final AbstractIndexManager this$0;
  
  protected AbstractIndexManager$WorkspaceVisitorJob(AbstractIndexManager paramAbstractIndexManager)
  {
    super(NLS.bind(SSECoreMessages.IndexManager_0_Processing_entire_workspace_for_the_first_time, AbstractIndexManager.access$1(paramAbstractIndexManager)));this$0 = paramAbstractIndexManager;
    
    setUser(false);
    setSystem(true);
    setPriority(30);
  }
  
  protected IStatus run(IProgressMonitor monitor)
  {
    try
    {
      monitor.beginTask(NLS.bind(SSECoreMessages.IndexManager_0_Processing_entire_workspace_for_the_first_time, AbstractIndexManager.access$1(this$0)), -1);
      
      WorkspaceVisitor visitor = new WorkspaceVisitor(monitor);
      ResourcesPlugin.getWorkspace().getRoot().accept(visitor, 0);
      
      visitor.processBatchedResourceEvents();
    }
    catch (CoreException e)
    {
      Logger.logException(AbstractIndexManager.access$1(this$0) + ": Failed visiting entire workspace for initial index. " + "Index may become invalid, incomplete, or enter some other inconsistent state.", e);
    }
    IStatus status;
    IStatus status;
    if (monitor.isCanceled()) {
      status = Status.CANCEL_STATUS;
    } else {
      status = Status.OK_STATUS;
    }
    monitor.done();
    return status;
  }
  
  private class WorkspaceVisitor
    implements IResourceProxyVisitor
  {
    private SubMonitor fProgress;
    private Map fBatchedResourceEvents;
    
    protected WorkspaceVisitor(IProgressMonitor monitor)
    {
      fProgress = SubMonitor.convert(monitor);
      fBatchedResourceEvents = new LinkedHashMap(100);
    }
    
    public boolean visit(IResourceProxy proxy)
      throws CoreException
    {
      fProgress.subTask(proxy.getName());
      
      boolean visitChildren = false;
      if (!fProgress.isCanceled()) {
        if (proxy.isDerived())
        {
          visitChildren = false;
        }
        else if (proxy.requestFullPath().isRoot())
        {
          visitChildren = true;
        }
        else if (this$0.isResourceToIndex(proxy.getType(), proxy.requestFullPath()))
        {
          if (proxy.getType() == 1)
          {
            IFile file = (IFile)proxy.requestResource();
            if (file.exists()) {
              fBatchedResourceEvents.put(file, new AbstractIndexManager.ResourceEvent((byte)1, (byte)0, null));
            }
          }
          visitChildren = true;
        }
      }
      if (fBatchedResourceEvents.size() >= 100) {
        processBatchedResourceEvents();
      }
      return visitChildren;
    }
    
    protected void processBatchedResourceEvents()
    {
      AbstractIndexManager.access$0(this$0).addResourceEvents(fBatchedResourceEvents);
      fBatchedResourceEvents.clear();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.sse.core.indexing.AbstractIndexManager.WorkspaceVisitorJob
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.sse.core.indexing;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.sse.core.internal.Logger;
import org.eclipse.wst.sse.core.internal.SSECoreMessages;

public abstract class AbstractIndexManager
{
  private static final String ENCODING_UTF16 = "utf16";
  private static final int WAIT_TIME = 300;
  private static final int UNKNOWN_WORK = 100;
  private static final int BATCH_UP_AMOUNT = 100;
  private static final String RE_PROCESS_FILE_NAME = ".re-process";
  private static final String LOG_ERROR_INDEX_INVALID = "Index may become invalid, incomplete, or enter some other inconsistent state.";
  private static final byte STATE_DISABLED = 0;
  private static final byte STATE_ENABLED = 1;
  protected static final byte ACTION_ADD = 0;
  protected static final byte ACTION_REMOVE = 1;
  protected static final byte ACTION_ADD_MOVE_FROM = 2;
  protected static final byte ACTION_REMOVE_MOVE_TO = 3;
  protected static final byte SOURCE_RESOURCE_CHANGE = 0;
  protected static final byte SOURCE_WORKSPACE_SCAN = 1;
  protected static final byte SOURCE_SAVED_STATE = 2;
  protected static final byte SOURCE_PRESERVED_RESOURCES_TO_INDEX = 3;
  private String fName;
  private ResourceChangeListener fResourceChangeListener;
  private ResourceEventProcessingJob fResourceEventProcessingJob;
  private Job fWorkspaceVisitorJob;
  private volatile byte fState;
  private Object fStartStopLock = new Object();
  private boolean fStarting;
  
  protected AbstractIndexManager(String name)
  {
    fName = name;
    fState = 0;
    fResourceChangeListener = new ResourceChangeListener();
    fResourceEventProcessingJob = new ResourceEventProcessingJob();
    fStarting = false;
  }
  
  /**
   * @deprecated
   */
  protected AbstractIndexManager(String name, String messageRunning, String messageInitializing, String messageProcessingFiles)
  {
    this(name);
  }
  
  public final void start(IResourceDelta savedStateDelta, IProgressMonitor monitor)
  {
    SubMonitor progress = SubMonitor.convert(monitor);
    synchronized (fStartStopLock)
    {
      fStarting = true;
      try
      {
        if (fState == 0)
        {
          progress.beginTask(NLS.bind(SSECoreMessages.IndexManager_0_starting, fName), 2);
          
          fResourceChangeListener.start();
          
          boolean forcedFullReIndexNeeded = isForcedFullReIndexNeeded();
          
          forcedFullReIndexNeeded = !fResourceEventProcessingJob.start(!forcedFullReIndexNeeded, progress.newChild(1));
          progress.setWorkRemaining(1);
          if (!forcedFullReIndexNeeded) {
            if (savedStateDelta != null)
            {
              forcedFullReIndexNeeded = false;
              try
              {
                SubMonitor savedStateProgress = progress.newChild(1, 0);
                
                savedStateProgress.setTaskName(NLS.bind(SSECoreMessages.IndexManager_0_starting_1, new String[] { fName, SSECoreMessages.IndexManager_processing_deferred_resource_changes }));
                
                ResourceDeltaVisitor visitor = new ResourceDeltaVisitor(savedStateProgress, (byte)2);
                savedStateDelta.accept(visitor);
                
                visitor.processBatchedResourceEvents();
              }
              catch (CoreException e)
              {
                forcedFullReIndexNeeded = true;
                Logger.logException(fName + ": Could not process saved state. " + 
                  "Forced to do a full workspace re-index.", e);
              }
            }
            else
            {
              forcedFullReIndexNeeded = true;
            }
          }
          progress.worked(1);
          if (forcedFullReIndexNeeded)
          {
            fWorkspaceVisitorJob = new WorkspaceVisitorJob();
            fWorkspaceVisitorJob.schedule();
          }
          fState = 1;
        }
      }
      finally
      {
        fStarting = false;
        progress.done();
      }
    }
  }
  
  public final void stop()
    throws InterruptedException
  {
    synchronized (fStartStopLock)
    {
      if (fState != 0)
      {
        fResourceChangeListener.stop();
        
        boolean forceFullReIndexNextStart = false;
        if ((fWorkspaceVisitorJob != null) && 
          (fWorkspaceVisitorJob.getState() != 0))
        {
          fWorkspaceVisitorJob.cancel();
          
          forceFullReIndexNextStart();
          forceFullReIndexNextStart = true;
        }
        forceFullReIndexNextStart = !fResourceEventProcessingJob.stop(!forceFullReIndexNextStart);
        if (forceFullReIndexNextStart) {
          forceFullReIndexNextStart();
        }
        fState = 0;
      }
    }
  }
  
  protected String getName()
  {
    return fName;
  }
  
  public final boolean waitForConsistent(IProgressMonitor monitor)
  {
    boolean success = true;
    boolean interupted = false;
    SubMonitor progress = SubMonitor.convert(monitor);
    
    int remainingWork = 4;
    progress.beginTask(NLS.bind(SSECoreMessages.IndexManager_Waiting_for_0, fName), remainingWork);
    if ((fStarting) && (!monitor.isCanceled()))
    {
      SubMonitor startingProgress = progress.newChild(1);
      startingProgress.subTask(NLS.bind(SSECoreMessages.IndexManager_0_starting, fName));
      while ((fStarting) && (!monitor.isCanceled()))
      {
        startingProgress.setWorkRemaining(100);
        startingProgress.newChild(1).worked(1);
        try
        {
          Thread.sleep(300L);
        }
        catch (InterruptedException localInterruptedException1)
        {
          interupted = true;
        }
      }
    }
    progress.setWorkRemaining(--remainingWork);
    if ((fWorkspaceVisitorJob != null) && (fWorkspaceVisitorJob.getState() != 0) && (!monitor.isCanceled()))
    {
      SubMonitor workspaceVisitorProgress = progress.newChild(1);
      workspaceVisitorProgress.subTask(SSECoreMessages.IndexManager_Processing_entire_workspace_for_the_first_time);
      while ((fWorkspaceVisitorJob.getState() != 0) && (!monitor.isCanceled()))
      {
        workspaceVisitorProgress.setWorkRemaining(100);
        workspaceVisitorProgress.newChild(1).worked(1);
        try
        {
          Thread.sleep(300L);
        }
        catch (InterruptedException localInterruptedException2)
        {
          interupted = true;
        }
      }
    }
    progress.setWorkRemaining(--remainingWork);
    if ((fResourceChangeListener.isProcessingEvents()) && (!monitor.isCanceled()))
    {
      SubMonitor workspaceVisitorProgress = progress.newChild(1);
      workspaceVisitorProgress.subTask(SSECoreMessages.IndexManager_processing_recent_resource_changes);
      while ((fResourceChangeListener.isProcessingEvents()) && (!monitor.isCanceled()))
      {
        workspaceVisitorProgress.setWorkRemaining(100);
        workspaceVisitorProgress.newChild(1).worked(1);
        try
        {
          fResourceChangeListener.waitForCurrentEvent(300);
        }
        catch (InterruptedException localInterruptedException3)
        {
          interupted = true;
        }
      }
    }
    progress.setWorkRemaining(--remainingWork);
    if ((fResourceEventProcessingJob.getNumResourceEventsToProcess() != 0) && (!monitor.isCanceled()))
    {
      SubMonitor indexingProgress = progress.newChild(1);
      
      int numResources = fResourceEventProcessingJob.getNumResourceEventsToProcess();
      while ((numResources != 0) && (!monitor.isCanceled()))
      {
        indexingProgress.subTask(NLS.bind(SSECoreMessages.IndexManager_0_Indexing_1_Files, new Object[] { fName, numResources }));
        indexingProgress.setWorkRemaining(numResources);
        int prevNumResources = numResources;
        numResources = fResourceEventProcessingJob.getNumResourceEventsToProcess();
        int numProcessed = prevNumResources - numResources;
        indexingProgress.w
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd