org.eclipse.mylyn.context.sdk.java_3.7.1.v20120425-0100

16:46:37.172 INFO  jd.cli.Main - Decompiling org.eclipse.mylyn.context.sdk.java_3.7.1.v20120425-0100.jar
package org.eclipse.mylyn.context.sdk.java;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.commons.core.StatusHandler;

class WorkspaceSetupHelper$1
  implements IWorkspaceRunnable
{
  WorkspaceSetupHelper$1(IResource paramIResource) {}
  
  public void run(IProgressMonitor monitor)
    throws CoreException
  {
    for (int i = 0; i < 10; i++) {
      try
      {
        val$resource.delete(true, null);
        i = 10;
      }
      catch (CoreException e)
      {
        if (i == 9)
        {
          StatusHandler.log(e.getStatus());
          throw e;
        }
        System.gc();
        try
        {
          Thread.sleep(1000L);
        }
        catch (InterruptedException localInterruptedException) {}
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.context.sdk.java.WorkspaceSetupHelper.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.context.sdk.java;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
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.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.TypeNameRequestor;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
import org.eclipse.ui.progress.IProgressService;
import org.osgi.framework.Bundle;

public class TestJavaProject
{
  public IProject project;
  public IJavaProject javaProject;
  private IPackageFragmentRoot sourceFolder;
  
  public TestJavaProject(String name)
    throws CoreException, InvocationTargetException, InterruptedException
  {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    project = root.getProject(name);
    project.create(null);
    project.open(null);
    
    javaProject = JavaCore.create(project);
    IFolder binFolder = createBinFolder();
    setJavaNature();
    javaProject.setRawClasspath(new IClasspathEntry[0], null);
    createOutputFolder(binFolder);
    addSystemLibraries();
  }
  
  public IProject getProject()
  {
    return project;
  }
  
  public IJavaProject getJavaProject()
  {
    return javaProject;
  }
  
  public void build()
    throws CoreException, InvocationTargetException, InterruptedException
  {
    WorkspaceModifyOperation op = new WorkspaceModifyOperation()
    {
      protected void execute(IProgressMonitor monitor)
        throws CoreException
      {
        project.build(6, null);
      }
    };
    IProgressService service = PlatformUI.getWorkbench().getProgressService();
    service.run(true, true, op);
  }
  
  public IPackageFragment createPackage(String name)
    throws CoreException
  {
    if (sourceFolder == null) {
      sourceFolder = createSourceFolder();
    }
    return sourceFolder.createPackageFragment(name, false, null);
  }
  
  public IType createType(IPackageFragment pack, String cuName, String source)
    throws JavaModelException
  {
    StringBuffer buf = new StringBuffer();
    buf.append("package " + pack.getElementName() + ";\n");
    buf.append("\n");
    buf.append(source);
    ICompilationUnit cu = pack.createCompilationUnit(cuName, buf.toString(), false, null);
    return cu.getTypes()[0];
  }
  
  private IFolder createBinFolder()
    throws CoreException
  {
    IFolder binFolder = project.getFolder("bin");
    binFolder.create(false, true, null);
    return binFolder;
  }
  
  private void setJavaNature()
    throws CoreException
  {
    IProjectDescription description = project.getDescription();
    description.setNatureIds(new String[] { "org.eclipse.jdt.core.javanature" });
    project.setDescription(description, null);
  }
  
  private void createOutputFolder(IFolder binFolder)
    throws JavaModelException
  {
    IPath outputLocation = binFolder.getFullPath();
    javaProject.setOutputLocation(outputLocation, null);
  }
  
  private IPackageFragmentRoot createSourceFolder()
    throws CoreException
  {
    IFolder folder = project.getFolder("src");
    folder.create(false, true, null);
    IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(folder);
    
    IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
    IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
    System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
    newEntries[oldEntries.length] = JavaCore.newSourceEntry(root.getPath());
    javaProject.setRawClasspath(newEntries, null);
    return root;
  }
  
  private void addSystemLibraries()
    throws JavaModelException
  {
    IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
    IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
    System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
    newEntries[oldEntries.length] = JavaRuntime.getDefaultJREContainerEntry();
    javaProject.setRawClasspath(newEntries, null);
  }
  
  public void addJar(Plugin plugin, String jar)
    throws MalformedURLException, IOException, JavaModelException
  {
    Path result = findFileInPlugin(plugin, jar);
    IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
    IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
    System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
    newEntries[oldEntries.length] = JavaCore.newLibraryEntry(result, null, null);
    javaProject.setRawClasspath(newEntries, null);
  }
  
  private Path findFileInPlugin(Plugin plugin, String file)
    throws MalformedURLException, IOException
  {
    URL pluginURL = plugin.getBundle().getEntry("/");
    URL jarURL = new URL(pluginURL, file);
    URL localJarURL = FileLocator.toFileURL(jarURL);
    return new Path(localJarURL.getPath());
  }
  
  public void waitForIndexer()
    throws JavaModelException
  {
    new SearchEngine().searchAllTypeNames(null, null, 0, 5, 
      SearchEngine.createJavaSearchScope(new IJavaElement[0]), new TypeNameRequestor() {}, 3, null);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.context.sdk.java.TestJavaProject
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.context.sdk.java;

import org.eclipse.core.runtime.IProgressMonitor;

public class AbstractJavaContextTest$TestProgressMonitor
  implements IProgressMonitor
{
  boolean done = false;
  
  public AbstractJavaContextTest$TestProgressMonitor(AbstractJavaContextTest paramAbstractJavaContextTest) {}
  
  public void beginTask(String name, int totalWork) {}
  
  public void done()
  {
    done = true;
  }
  
  public void internalWorked(double work) {}
  
  public boolean isCanceled()
  {
    return false;
  }
  
  public void setCanceled(boolean value) {}
  
  public void setTaskName(String name) {}
  
  public void subTask(String name) {}
  
  public void worked(int work) {}
  
  public boolean isDone()
  {
    return done;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.context.sdk.java.AbstractJavaContextTest.TestProgressMonitor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.context.sdk.java;

import java.io.File;
import java.util.List;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.mylyn.commons.sdk.util.ResourceTestUtil;
import org.eclipse.mylyn.commons.sdk.util.TestProject;
import org.eclipse.mylyn.context.sdk.util.AbstractContextTest;
import org.eclipse.mylyn.context.sdk.util.ContextTestUtil;
import org.eclipse.mylyn.internal.context.core.ContextCorePlugin;
import org.eclipse.mylyn.internal.context.core.InteractionContext;
import org.eclipse.mylyn.internal.context.core.InteractionContextManager;
import org.eclipse.mylyn.internal.context.core.InteractionContextScaling;
import org.eclipse.mylyn.internal.context.core.LocalContextStore;
import org.eclipse.mylyn.internal.context.ui.ContextUiPlugin;
import org.eclipse.mylyn.internal.context.ui.FocusedViewerManager;
import org.eclipse.mylyn.internal.java.ui.JavaEditingMonitor;
import org.eclipse.mylyn.internal.java.ui.JavaStructureBridge;
import org.eclipse.mylyn.internal.java.ui.JavaUiBridgePlugin;
import org.eclipse.mylyn.internal.resources.ui.ResourcesUiBridgePlugin;

public abstract class AbstractJavaContextTest
  extends AbstractContextTest
{
  protected InteractionContextManager manager = ContextCorePlugin.getContextManager();
  protected JavaEditingMonitor monitor = new JavaEditingMonitor();
  protected TestJavaProject project;
  protected TestProject nonJavaProject;
  protected IPackageFragment p1;
  protected IType type1;
  protected String contextId = getClass().getSimpleName();
  protected InteractionContext context;
  protected InteractionContextScaling scaling = new InteractionContextScaling();
  
  protected void setUp()
    throws Exception
  {
    super.setUp();
    
    ContextTestUtil.triggerContextUiLazyStart();
    assertNotNull(JavaPlugin.getDefault());
    assertNotNull(JavaUiBridgePlugin.getDefault());
    assertNotNull(ResourcesUiBridgePlugin.getDefault());
    String bridges = ContextCorePlugin.getDefault().getStructureBridges().toString();
    assertTrue("Expected JavaStructureBridge not available: " + bridges, 
      bridges.indexOf(JavaStructureBridge.class.getCanonicalName()) != -1);
    assertTrue("Expected initialized ResourcesUiBridge", ResourcesUiBridgePlugin.getDefault().isStarted());
    
    project = new TestJavaProject(getClass().getSimpleName());
    nonJavaProject = new TestProject(getClass().getSimpleName() + "nonJava");
    p1 = project.createPackage("p1");
    type1 = project.createType(p1, "Type1.java", "public class Type1 { }");
    
    context = new InteractionContext(contextId, scaling);
    context.reset();
    manager.internalActivateContext(context);
    
    ContextUiPlugin.getViewerManager().setSyncRefreshMode(true);
    ResourcesUiBridgePlugin.getDefault().setResourceMonitoringEnabled(false);
  }
  
  protected void tearDown()
    throws Exception
  {
    ResourcesUiBridgePlugin.getDefault().setResourceMonitoringEnabled(true);
    this.context.reset();
    assertTrue(this.context.getInteresting().isEmpty());
    manager.deactivateContext(contextId);
    manager.deleteContext(contextId);
    ContextCorePlugin.getContextStore().getFileForContext(contextId).delete();
    
    ResourceTestUtil.deleteProject(project.getProject());
    ResourceTestUtil.deleteProject(nonJavaProject.getProject());
    for (InteractionContext context : manager.getActiveContexts()) {
      manager.deactivateContext(context.getHandleIdentifier());
    }
    assertFalse(manager.isContextActive());
    waitForAutoBuild();
    super.tearDown();
  }
  
  public static void waitForAutoBuild()
  {
    boolean wasInterrupted = false;
    do
    {
      try
      {
        Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
        wasInterrupted = false;
      }
      catch (OperationCanceledException e)
      {
        e.printStackTrace();
      }
      catch (InterruptedException localInterruptedException)
      {
        wasInterrupted = true;
      }
    } while (
    
      wasInterrupted);
  }
  
  public class TestProgressMonitor
    implements IProgressMonitor
  {
    boolean done = false;
    
    public TestProgressMonitor() {}
    
    public void beginTask(String name, int totalWork) {}
    
    public void done()
    {
      done = true;
    }
    
    public void internalWorked(double work) {}
    
    public boolean isCanceled()
    {
      return false;
    }
    
    public void setCanceled(boolean value) {}
    
    public void setTaskName(String name) {}
    
    public void subTask(String name) {}
    
    public void worked(int work) {}
    
    public boolean isDone()
    {
      return done;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.context.sdk.java.AbstractJavaContextTest
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.context.sdk.java.search;

import java.io.IOException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.mylyn.context.core.ContextCore;
import org.eclipse.mylyn.context.core.IInteractionContextManager;
import org.eclipse.mylyn.context.core.IInteractionContextScaling;
import org.eclipse.mylyn.context.core.IInteractionElement;
import org.eclipse.mylyn.context.sdk.java.WorkspaceSetupHelper;
import org.eclipse.mylyn.context.sdk.util.AbstractContextTest;
import org.eclipse.mylyn.internal.context.core.CompositeInteractionContext;
import org.eclipse.mylyn.internal.context.core.ContextCorePlugin;
import org.eclipse.mylyn.internal.context.core.InteractionContext;
import org.eclipse.mylyn.internal.context.core.InteractionContextManager;
import org.eclipse.mylyn.monitor.core.InteractionEvent;
import org.eclipse.mylyn.monitor.core.InteractionEvent.Kind;

public class ActiveSearchNotifier
  extends AbstractContextTest
{
  private CompositeInteractionContext context;
  private final String source;
  
  public ActiveSearchNotifier(CompositeInteractionContext context, String source)
  {
    this.context = context;
    this.source = source;
  }
  
  public IInteractionElement mockLowerInterest(IInteractionElement node)
  {
    return context.addEvent(mockUserEvent(node.getHandleIdentifier(), node.getContentType(), source, -3.0F));
  }
  
  public IInteractionElement mockRaiseInterest(IInteractionElement node)
  {
    return context.addEvent(mockUserEvent(node.getHandleIdentifier(), node.getContentType(), source, 2.0F));
  }
  
  public IInteractionElement mockLowerInterest(String handle, String kind)
  {
    return mockLowerInterest(mockEditorSelection(handle, kind));
  }
  
  public IInteractionElement mockRaiseInterest(String handle, String kind)
  {
    return mockRaiseInterest(mockEditorSelection(handle, kind));
  }
  
  public IInteractionElement mockEditorSelection(String handle, String kind)
  {
    context.addEvent(mockSelection(handle, kind, source));
    return context.addEvent(mockSelection(handle, kind, source));
  }
  
  public IInteractionElement getElement(String handle, String kind)
  {
    IInteractionElement node = context.addEvent(mockSelection(handle, kind, source));
    ContextCorePlugin.getContextManager().processInteractionEvent(
      mockUserEvent(handle, kind, source, 1.0F / ContextCore.getCommonContextScaling().getLandmark() * -2.0F), 
      true);
    return node;
  }
  
  public void clearContext()
    throws IOException, CoreException
  {
    
    try
    {
      InteractionContext workspaceContext = WorkspaceSetupHelper.getContext();
      ContextCore.getContextManager().activateContext(workspaceContext.getHandleIdentifier());
      context = ((CompositeInteractionContext)ContextCore.getContextManager().getActiveContext());
    }
    catch (Exception localException)
    {
      fail();
    }
  }
  
  private InteractionEvent mockSelection(String handle, String kind, String origin)
  {
    return new InteractionEvent(InteractionEvent.Kind.SELECTION, kind, handle, origin);
  }
  
  private InteractionEvent mockUserEvent(String handle, String kind, String origin, float scale)
  {
    InteractionEvent e = new InteractionEvent(InteractionEvent.Kind.MANIPULATION, kind, handle, origin, scale * 
      ContextCore.getCommonContextScaling().getLandmark());
    e.getInterestContribution();
    return e;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.context.sdk.java.search.ActiveSearchNotifier
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.context.sdk.java.search;

import java.io.IOException;
import java.util.Date;
import java.util.List;
import junit.framework.TestCase;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.mylyn.context.core.IInteractionElement;
import org.eclipse.mylyn.context.sdk.util.search.ISearchPluginTest;
import org.eclipse.mylyn.internal.context.core.IActiveSearchListener;
import org.eclipse.mylyn.internal.context.core.IActiveSearchOperation;

public class SearchPluginTestHelper
  extends TestCase
{
  private final ISearchPluginTest test;
  private static final long MAXWAIT = 360L;
  
  public SearchPluginTestHelper(ISearchPluginTest test)
  {
    this.test = test;
  }
  
  public void searchResultsNotNull(ActiveSearchNotifier notifier, String handle, String kind, IInteractionElement searchNode, int dos, int expected, boolean includeOnlyJava)
    throws IOException, CoreException
  {
    notifier.mockRaiseInterest(handle, kind);
    
    List<?> results = test.search(dos, searchNode);
    int size = results.size();
    if (includeOnlyJava)
    {
      size = 0;
      for (Object o : results) {
        if ((o instanceof IJavaElement)) {
          size++;
        }
      }
    }
    assertNotNull("Results Null", results);
    assertEquals("Wrong number search results", expected, size);
    notifier.clearContext();
  }
  
  public void searchResultsNotNullInteresting(ActiveSearchNotifier notifier, String handle, String kind, IInteractionElement searchNode, int dos, int expected, boolean includeOnlyJava)
    throws IOException, CoreException
  {
    notifier.mockEditorSelection(handle, kind);
    
    List<?> results = test.search(dos, searchNode);
    
    int size = results.size();
    if (includeOnlyJava)
    {
      size = 0;
      for (Object o : results) {
        if ((o instanceof IJavaElement)) {
          size++;
        }
      }
    }
    assertNotNull("Results Null", results);
    assertEquals("Wrong number search results", expected, size);
    notifier.clearContext();
  }
  
  public void searchResultsNotNull(ActiveSearchNotifier notifier, IInteractionElement searchNode, int dos, int expected, boolean includeOnlyJava)
    throws IOException, CoreException
  {
    List<?> results = test.search(dos, searchNode);
    int size = results.size();
    if (includeOnlyJava)
    {
      size = 0;
      for (Object o : results) {
        if ((o instanceof IJavaElement)) {
          size++;
        }
      }
    }
    assertNotNull("Results Null", results);
    assertEquals("Wrong number search results", expected, size);
    notifier.clearContext();
  }
  
  public void searchResultsNull(ActiveSearchNotifier notifier, String handle, String kind, IInteractionElement searchNode, int dos)
    throws IOException, CoreException
  {
    notifier.mockRaiseInterest(handle, kind);
    
    List<?> results = test.search(dos, searchNode);
    assertNull("Results Not Null", results);
    notifier.clearContext();
  }
  
  public void searchResultsNull(ActiveSearchNotifier notifier, IInteractionElement searchNode, int dos)
    throws IOException, CoreException
  {
    List<?> results = test.search(dos, searchNode);
    assertNull("Results Not Null", results);
    notifier.clearContext();
  }
  
  public static long search(IActiveSearchOperation op, IActiveSearchListener listener)
  {
    if (op == null) {
      return -1L;
    }
    op.addListener(listener);
    
    long start = new Date().getTime();
    
    op.run(new NullProgressMonitor());
    for (int i = 0; (i < 360L) && (!listener.resultsGathered()); i++) {
      try
      {
        Thread.sleep(500L);
      }
      catch (InterruptedException localInterruptedException) {}
    }
    long time = (new Date().getTime() - start) / 1000L;
    if (!listener.resultsGathered()) {
      return -1L;
    }
    return time;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.context.sdk.java.search.SearchPluginTestHelper
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.context.sdk.java;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.actions.WorkspaceModifyOperation;

class TestJavaProject$1
  extends WorkspaceModifyOperation
{
  TestJavaProject$1(TestJavaProject paramTestJavaProject) {}
  
  protected void execute(IProgressMonitor monitor)
    throws CoreException
  {
    this$0.project.build(6, null);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.context.sdk.java.TestJavaProject.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.context.sdk.java;

import org.eclipse.jdt.core.search.TypeNameRequestor;

class TestJavaProject$2
  extends TypeNameRequestor
{
  TestJavaProject$2(TestJavaProject paramTestJavaProject) {}
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.context.sdk.java.TestJavaProject.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.context.sdk.java;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
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.NullProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;
import org.eclipse.mylyn.context.core.ContextCore;
import org.eclipse.mylyn.context.core.IInteractionContextManager;
import org.eclipse.mylyn.internal.context.core.InteractionContext;
import org.eclipse.mylyn.internal.context.core.InteractionContextScaling;
import org.eclipse.pde.internal.core.natures.PluginProject;

public class WorkspaceSetupHelper
{
  private static final int MAX_RETRY = 10;
  private static final String HELPER_CONTEXT_ID = "helper-context";
  private static boolean isSetup = false;
  private static InteractionContext taskscape;
  private static IJavaProject project1;
  private static IJavaProject project2;
  private static TestJavaProject jdtCoreDomProject;
  private static IWorkspaceRoot workspaceRoot;
  private static final IProgressMonitor NULL_MONITOR = new NullProgressMonitor();
  
  public static IJavaProject createJavaPluginProjectFromZip(Object source, String projectName, String zipFileName)
    throws CoreException, ZipException, IOException
  {
    IProject project = createProject(projectName);
    ZipFile zip = new ZipFile(CommonTestUtil.getFile(source, "testdata/projects/" + zipFileName));
    
    CommonTestUtil.unzip(zip, project.getLocation().toFile());
    
    project.refreshLocal(2, null);
    
    IJavaProject javaProject = createPluginProject(project);
    return javaProject;
  }
  
  public static IJavaProject createJavaPluginProjectFromDirectory(File sourceDirectory, String projectName)
    throws CoreException, ZipException, IOException
  {
    IProject project = createProject(projectName);
    
    CommonTestUtil.copyFolderRecursively(sourceDirectory, project.getLocation().toFile());
    
    project.refreshLocal(2, null);
    
    IJavaProject javaProject = createPluginProject(project);
    return javaProject;
  }
  
  public static IJavaProject createPluginProject(IProject project)
    throws CoreException, JavaModelException
  {
    if (project == null) {
      return null;
    }
    IJavaProject javaProject = JavaCore.create(project);
    
    IFolder binFolder = project.getFolder("bin");
    if (!binFolder.exists()) {
      binFolder.create(false, true, null);
    }
    IProjectDescription description = project.getDescription();
    description.setNatureIds(new String[] { "org.eclipse.pde.PluginNature", "org.eclipse.jdt.core.javanature" });
    project.setDescription(description, null);
    
    IPath outputLocation = binFolder.getFullPath();
    javaProject.setOutputLocation(outputLocation, null);
    
    PluginProject pluginProject = new PluginProject();
    pluginProject.setProject(project);
    pluginProject.configure();
    
    return javaProject;
  }
  
  public static IProject createProject(String projectName)
    throws CoreException
  {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    if (!project.exists()) {
      project.create(NULL_MONITOR);
    } else {
      project.refreshLocal(2, null);
    }
    if (!project.isOpen()) {
      project.open(NULL_MONITOR);
    }
    return project;
  }
  
  public static void clearWorkspace()
    throws CoreException, IOException
  {
    isSetup = false;
    ResourcesPlugin.getWorkspace().getRoot().delete(true, true, new NullProgressMonitor());
    clearDoiModel();
  }
  
  public static IWorkspaceRoot setupWorkspace()
    throws CoreException, IOException, InvocationTargetException, InterruptedException
  {
    if (isSetup)
    {
      clearDoiModel();
      return workspaceRoot;
    }
    taskscape = new InteractionContext("helper-context", new InteractionContextScaling());
    
    workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    
    project1 = createJavaPluginProjectFromZip(WorkspaceSetupHelper.class, "project1", "project1.zip");
    project2 = createJavaPluginProjectFromZip(WorkspaceSetupHelper.class, "project2", "project2.zip");
    
    jdtCoreDomProject = new TestJavaProject("workspace-helper-project");
    IPackageFragment jdtCoreDomPkg = jdtCoreDomProject.createPackage("org.eclipse.jdt.core.dom");
    IType astNodeType = jdtCoreDomProject.createType(jdtCoreDomPkg, "ASTNode.java", "public class ASTNode { }");
    astNodeType.createMethod("public final void setSourceRange(int startPosition, int length) { }", null, false, 
      null);
    isSetup = true;
    
    project1.open(new NullProgressMonitor());
    project2.open(new NullProgressMonitor());
    jdtCoreDomProject.getJavaProject().open(new NullProgressMonitor());
    
    return workspaceRoot;
  }
  
  public static void delete(IResource resource)
    throws CoreException
  {
    IWorkspaceRunnable runnable = new IWorkspaceRunnable()
    {
      public void run(IProgressMonitor monitor)
        throws CoreException
      {
        for (int i = 0; i < 10; i++) {
          try
          {
            delete(true, null);
            i = 10;
          }
          catch (CoreException e)
          {
            if (i == 9)
            {
              StatusHandler.log(e.getStatus());
              throw e;
            }
            System.gc();
            try
            {
              Thread.sleep(1000L);
            }
            catch (InterruptedException localInterruptedException) {}
          }
        }
      }
    };
    ResourcesPlugin.getWorkspace().run(runnable, null);
  }
  
  public static void deleteProject(String projectName)
    throws CoreException
  {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    if (project.exists()) {
      delete(project);
    }
  }
  
  public static void clearDoiModel()
    throws CoreException
  {
    ContextCore.getContextManager().deleteContext("helper-context");
    taskscape = new InteractionContext("helper-context", new InteractionContextScaling());
  }
  
  public static InteractionContext getContext()
    throws CoreException, IOException, InvocationTargetException, InterruptedException
  {
    if (!isSetup) {
      setupWorkspace();
    }
    return taskscape;
  }
  
  public static IJavaProject getJdtCoreDomProject()
    throws CoreException, IOException, InvocationTargetException, InterruptedException
  {
    if (!isSetup) {
      setupWorkspace();
    }
    return jdtCoreDomProject.getJavaProject();
  }
  
  public static IJavaProject getProject1()
    throws CoreException, IOException, InvocationTargetException, InterruptedException
  {
    if (!isSetup) {
      setupWorkspace();
    }
    return project1;
  }
  
  public static IJavaProject getProject2()
    throws CoreException, IOException, InvocationTargetException, InterruptedException
  {
    if (!isSetup) {
      setupWorkspace();
    }
    return project2;
  }
  
  public static IWorkspaceRoot getWorkspaceRoot()
    throws CoreException, IOException, InvocationTargetException, InterruptedException
  {
    if (!isSetup) {
      setupWorkspace();
    }
    return workspaceRoot;
  }
  
  public static IFile getFile(IJavaProject jp, String name)
    throws JavaModelException
  {
    if ((jp == null) || (name == null)) {
      return null;
    }
    Object[] files = jp.getNonJavaResources();
    Object[] arrayOfObject1;
    int j = (arrayOfObject1 = files).length;
    for (int i = 0; i < j; i++)
    {
      Object o = arrayOfObject1[i];
      if (((o instanceof IFile)) && (((IFile)o).getName().equals(name))) {
        return (IFile)o;
      }
    }
    return null;
  }
  
  public static IType getType(IJavaProject jp, String fullyQualifiedName)
    throws JavaModelException
  {
    if ((jp == null) || (fullyQualifiedName == null)) {
      return null;
    }
    IType t = jp.findType(fullyQualifiedName);
    return t;
  }
  
  public static IMethod getMethod(IType t, String methodName, String[] params)
  {
    if ((t == null) || (methodName == null) || (params == null)) {
      return null;
    }
    return t.getMethod(methodName, params);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.context.sdk.java.WorkspaceSetupHelper
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
1

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