org.eclipse.jdt.junit.core_3.7.0.v20110928-1453

16:45:08.523 INFO  jd.cli.Main - Decompiling org.eclipse.jdt.junit.core_3.7.0.v20110928-1453.jar
package org.eclipse.jdt.internal.junit;

import java.io.File;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.osgi.util.TextProcessor;

public class BasicElementLabels
{
  private static String markLTR(String string, String delimiters)
  {
    return TextProcessor.process(string, delimiters);
  }
  
  public static String getPathLabel(IPath path, boolean isOSPath)
  {
    String label;
    String label;
    if (isOSPath) {
      label = path.toOSString();
    } else {
      label = path.makeRelative().toString();
    }
    return markLTR(label, "/\\:.");
  }
  
  public static String getPathLabel(File file)
  {
    return markLTR(file.getAbsolutePath(), "/\\:.");
  }
  
  public static String getFilePattern(String name)
  {
    return markLTR(name, "*.?/\\:.");
  }
  
  public static String getURLPart(String name)
  {
    return markLTR(name, ":@?-#/\\:.");
  }
  
  public static String getResourceName(IResource resource)
  {
    return markLTR(resource.getName(), ":.");
  }
  
  public static String getResourceName(String resourceName)
  {
    return markLTR(resourceName, ":.");
  }
  
  public static String getVersionName(String name)
  {
    return markLTR(name, ":.");
  }
  
  public static String getJavaElementName(String name)
  {
    return markLTR(name, "<>()?,{}.:");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jdt.internal.junit.BasicElementLabels
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jdt.internal.junit;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.internal.junit.model.JUnitModel;
import org.eclipse.jdt.junit.ITestRunListener;
import org.eclipse.jdt.junit.TestRunListener;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.packageadmin.PackageAdmin;

public class JUnitCorePlugin
  extends Plugin
{
  private static JUnitCorePlugin fgPlugin = null;
  public static final String CORE_PLUGIN_ID = "org.eclipse.jdt.junit.core";
  public static final String PLUGIN_ID = "org.eclipse.jdt.junit";
  public static final String ID_EXTENSION_POINT_TESTRUN_LISTENERS = "org.eclipse.jdt.junit.testRunListeners";
  public static final String ID_EXTENSION_POINT_TEST_KINDS = "org.eclipse.jdt.junit.internal_testKinds";
  public static final String TEST_SUPERCLASS_NAME = "junit.framework.TestCase";
  public static final String TEST_INTERFACE_NAME = "junit.framework.Test";
  public static final String JUNIT4_ANNOTATION_NAME = "org.junit.Test";
  public static final String SIMPLE_TEST_INTERFACE_NAME = "Test";
  public static final String JUNIT_HOME = "JUNIT_HOME";
  public static final String JUNIT_SRC_HOME = "JUNIT_SRC_HOME";
  private static final String HISTORY_DIR_NAME = "history";
  private final JUnitModel fJUnitModel = new JUnitModel();
  private List fLegacyTestRunListeners;
  private ListenerList fNewTestRunListeners;
  private BundleContext fBundleContext;
  private static boolean fIsStopped = false;
  
  public JUnitCorePlugin()
  {
    fgPlugin = this;
    fNewTestRunListeners = new ListenerList();
  }
  
  public static JUnitCorePlugin getDefault()
  {
    return fgPlugin;
  }
  
  public static String getPluginId()
  {
    return "org.eclipse.jdt.junit.core";
  }
  
  public static void log(Throwable e)
  {
    log(new Status(4, getPluginId(), 4, "Error", e));
  }
  
  public static void log(IStatus status)
  {
    getDefault().getLog().log(status);
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
    fBundleContext = context;
    fJUnitModel.start();
  }
  
  /* Error */
  public void stop(BundleContext context)
    throws Exception
  {
    // Byte code:
    //   0: iconst_1
    //   1: putstatic 281	org/eclipse/jdt/internal/junit/JUnitCorePlugin:fIsStopped	Z
    //   4: getstatic 280	org/eclipse/core/runtime/preferences/InstanceScope:INSTANCE	Lorg/eclipse/core/runtime/preferences/IScopeContext;
    //   7: ldc 5
    //   9: invokeinterface 331 2 0
    //   14: invokeinterface 330 1 0
    //   19: aload_0
    //   20: getfield 286	org/eclipse/jdt/internal/junit/JUnitCorePlugin:fJUnitModel	Lorg/eclipse/jdt/internal/junit/model/JUnitModel;
    //   23: invokevirtual 316	org/eclipse/jdt/internal/junit/model/JUnitModel:stop	()V
    //   26: goto +11 -> 37
    //   29: astore_2
    //   30: aload_0
    //   31: aload_1
    //   32: invokespecial 305	org/eclipse/core/runtime/Plugin:stop	(Lorg/osgi/framework/BundleContext;)V
    //   35: aload_2
    //   36: athrow
    //   37: aload_0
    //   38: aload_1
    //   39: invokespecial 305	org/eclipse/core/runtime/Plugin:stop	(Lorg/osgi/framework/BundleContext;)V
    //   42: aload_0
    //   43: aconst_null
    //   44: putfield 287	org/eclipse/jdt/internal/junit/JUnitCorePlugin:fBundleContext	Lorg/osgi/framework/BundleContext;
    //   47: return
    // Line number table:
    //   Java source line #132	-> byte code offset #0
    //   Java source line #134	-> byte code offset #4
    //   Java source line #135	-> byte code offset #19
    //   Java source line #136	-> byte code offset #29
    //   Java source line #137	-> byte code offset #30
    //   Java source line #138	-> byte code offset #35
    //   Java source line #137	-> byte code offset #37
    //   Java source line #139	-> byte code offset #42
    //   Java source line #140	-> byte code offset #47
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	48	0	this	JUnitCorePlugin
    //   0	48	1	context	BundleContext
    //   29	7	2	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   4	29	29	finally
  }
  
  public Object getService(String serviceName)
  {
    ServiceReference reference = fBundleContext.getServiceReference(serviceName);
    if (reference == null) {
      return null;
    }
    return fBundleContext.getService(reference);
  }
  
  public static JUnitModel getModel()
  {
    return getDefaultfJUnitModel;
  }
  
  /**
   * @deprecated
   */
  private synchronized void loadTestRunListeners()
  {
    if (fLegacyTestRunListeners != null) {
      return;
    }
    fLegacyTestRunListeners = new ArrayList();
    IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.jdt.junit.testRunListeners");
    if (extensionPoint == null) {
      return;
    }
    IConfigurationElement[] configs = extensionPoint.getConfigurationElements();
    MultiStatus status = new MultiStatus("org.eclipse.jdt.junit.core", 0, "Could not load some testRunner extension points", null);
    for (int i = 0; i < configs.length; i++) {
      try
      {
        Object testRunListener = configs[i].createExecutableExtension("class");
        if ((testRunListener instanceof TestRunListener)) {
          fNewTestRunListeners.add(testRunListener);
        } else if ((testRunListener instanceof ITestRunListener)) {
          fLegacyTestRunListeners.add(testRunListener);
        }
      }
      catch (CoreException e)
      {
        status.add(e.getStatus());
      }
    }
    if (!status.isOK()) {
      log(status);
    }
  }
  
  /**
   * @deprecated
   */
  public ITestRunListener[] getTestRunListeners()
  {
    loadTestRunListeners();
    return (ITestRunListener[])fLegacyTestRunListeners.toArray(new ITestRunListener[fLegacyTestRunListeners.size()]);
  }
  
  public Bundle getBundle(String bundleName)
  {
    Bundle[] bundles = getBundles(bundleName, null);
    if ((bundles != null) && (bundles.length > 0)) {
      return bundles[0];
    }
    return null;
  }
  
  public Bundle[] getBundles(String bundleName, String version)
  {
    Bundle[] bundles = Platform.getBundles(bundleName, version);
    if (bundles != null) {
      return bundles;
    }
    ServiceReference serviceRef = fBundleContext.getServiceReference(PackageAdmin.class.getName());
    PackageAdmin admin = (PackageAdmin)fBundleContext.getService(serviceRef);
    bundles = admin.getBundles(bundleName, version);
    if ((bundles != null) && (bundles.length > 0)) {
      return bundles;
    }
    return null;
  }
  
  /**
   * @deprecated
   */
  public void addTestRunListener(ITestRunListener newListener)
  {
    loadTestRunListeners();
    for (Iterator iter = fLegacyTestRunListeners.iterator(); iter.hasNext();)
    {
      Object o = iter.next();
      if (o == newListener) {
        return;
      }
    }
    fLegacyTestRunListeners.add(newListener);
  }
  
  /**
   * @deprecated
   */
  public void removeTestRunListener(ITestRunListener newListener)
  {
    if (fLegacyTestRunListeners != null) {
      fLegacyTestRunListeners.remove(newListener);
    }
  }
  
  public ListenerList getNewTestRunListeners()
  {
    loadTestRunListeners();
    
    return fNewTestRunListeners;
  }
  
  public static boolean isStopped()
  {
    return fIsStopped;
  }
  
  public static File getHistoryDirectory()
    throws IllegalStateException
  {
    File historyDir = getDefault().getStateLocation().append("history").toFile();
    if (!historyDir.isDirectory()) {
      historyDir.mkdir();
    }
    return historyDir;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jdt.internal.junit.JUnitCorePlugin
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jdt.internal.junit;

import org.eclipse.osgi.util.NLS;

public final class JUnitMessages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.jdt.internal.junit.JUnitMessages";
  public static String JUnit4TestFinder_searching_description;
  public static String JUnitContainerInitializer_description_initializer_junit3;
  public static String JUnitContainerInitializer_description_initializer_junit4;
  public static String JUnitContainerInitializer_description_initializer_unresolved;
  public static String JUnitContainerInitializer_description_junit3;
  public static String JUnitContainerInitializer_description_junit4;
  public static String JUnitLaunchConfigurationDelegate_create_source_locator_description;
  public static String JUnitLaunchConfigurationDelegate_error_input_element_deosn_not_exist;
  public static String JUnitLaunchConfigurationDelegate_error_invalidproject;
  public static String JUnitLaunchConfigurationDelegate_error_junit4notonpath;
  public static String JUnitLaunchConfigurationDelegate_error_junitnotonpath;
  public static String JUnitLaunchConfigurationDelegate_error_no_socket;
  public static String JUnitLaunchConfigurationDelegate_error_notests_kind;
  public static String JUnitLaunchConfigurationDelegate_error_wrong_input;
  public static String JUnitLaunchConfigurationDelegate_input_type_does_not_exist;
  public static String JUnitLaunchConfigurationDelegate_verifying_attriburtes_description;
  public static String TestRunnerViewPart_configName;
  public static String TestRunSession_unrootedTests;
  public static String TestSearchEngine_message_searching;
  
  static
  {
    NLS.initializeMessages("org.eclipse.jdt.internal.junit.JUnitMessages", JUnitMessages.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jdt.internal.junit.JUnitMessages
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jdt.internal.junit;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;

public class JUnitPreferencesConstants
{
  public static final String DO_FILTER_STACK = "org.eclipse.jdt.junit.do_filter_stack";
  public static final String SHOW_ON_ERROR_ONLY = "org.eclipse.jdt.junit.show_on_error";
  public static final String ENABLE_ASSERTIONS = "org.eclipse.jdt.junit.enable_assertions";
  public static final String PREF_ACTIVE_FILTERS_LIST = "org.eclipse.jdt.junit.active_filters";
  public static final String PREF_INACTIVE_FILTERS_LIST = "org.eclipse.jdt.junit.inactive_filters";
  public static final String MAX_TEST_RUNS = "org.eclipse.jdt.junit.max_test_runs";
  public static final String JUNIT3_JAVADOC = "org.eclipse.jdt.junit.junit3.javadoclocation";
  public static final String JUNIT4_JAVADOC = "org.eclipse.jdt.junit.junit4.javadoclocation";
  public static final String HAMCREST_CORE_JAVADOC = "org.eclipse.jdt.junit.junit4.hamcrest.core.javadoclocation";
  private static final String[] fgDefaultFilterPatterns = {
    "org.eclipse.jdt.internal.junit.runner.*", 
    "org.eclipse.jdt.internal.junit4.runner.*", 
    "org.eclipse.jdt.internal.junit.ui.*", 
    "junit.framework.TestCase", 
    "junit.framework.TestResult", 
    "junit.framework.TestResult$1", 
    "junit.framework.TestSuite", 
    "junit.framework.Assert", 
    "org.junit.*", 
    "java.lang.reflect.Method.invoke", 
    "sun.reflect.*" };
  
  public static List createDefaultStackFiltersList()
  {
    return Arrays.asList(fgDefaultFilterPatterns);
  }
  
  public static String serializeList(String[] list)
  {
    if (list == null) {
      return "";
    }
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < list.length; i++)
    {
      if (i > 0) {
        buffer.append(',');
      }
      buffer.append(list[i]);
    }
    return buffer.toString();
  }
  
  public static String[] parseList(String listString)
  {
    List list = new ArrayList(10);
    StringTokenizer tokenizer = new StringTokenizer(listString, ",");
    while (tokenizer.hasMoreTokens()) {
      list.add(tokenizer.nextToken());
    }
    return (String[])list.toArray(new String[list.size()]);
  }
  
  public static String[] getFilterPatterns()
  {
    return parseList(Platform.getPreferencesService().getString("org.eclipse.jdt.junit.core", "org.eclipse.jdt.junit.active_filters", null, null));
  }
  
  public static boolean getFilterStack()
  {
    return Platform.getPreferencesService().getBoolean("org.eclipse.jdt.junit.core", "org.eclipse.jdt.junit.do_filter_stack", true, null);
  }
  
  public static void setFilterStack(boolean filter)
  {
    InstanceScope.INSTANCE.getNode("org.eclipse.jdt.junit.core").putBoolean("org.eclipse.jdt.junit.do_filter_stack", filter);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jdt.internal.junit.JUnitPreferencesConstants
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jdt.internal.junit;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
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.jdt.internal.junit.util.CoreTestSearchEngine;

public class JUnitPropertyTester
  extends PropertyTester
{
  private static final String PROPERTY_IS_TEST = "isTest";
  private static final String PROPERTY_CAN_LAUNCH_AS_JUNIT_TEST = "canLaunchAsJUnit";
  
  public boolean test(Object receiver, String property, Object[] args, Object expectedValue)
  {
    if (!(receiver instanceof IAdaptable)) {
      throw new IllegalArgumentException("Element must be of type 'IAdaptable', is " + receiver == null ? "null" : receiver.getClass().getName());
    }
    IJavaElement element;
    IJavaElement element;
    if ((receiver instanceof IJavaElement))
    {
      element = (IJavaElement)receiver;
    }
    else if ((receiver instanceof IResource))
    {
      IJavaElement element = JavaCore.create((IResource)receiver);
      if (element == null) {
        return false;
      }
    }
    else
    {
      element = (IJavaElement)((IAdaptable)receiver).getAdapter(IJavaElement.class);
      if (element == null)
      {
        IResource resource = (IResource)((IAdaptable)receiver).getAdapter(IResource.class);
        element = JavaCore.create(resource);
        if (element == null) {
          return false;
        }
      }
    }
    if ("isTest".equals(property)) {
      return isJUnitTest(element);
    }
    if ("canLaunchAsJUnit".equals(property)) {
      return canLaunchAsJUnitTest(element);
    }
    throw new IllegalArgumentException("Unknown test property '" + property + "'");
  }
  
  private boolean canLaunchAsJUnitTest(IJavaElement element)
  {
    try
    {
      switch (element.getElementType())
      {
      case 2: 
      case 3: 
        return true;
      case 4: 
        return ((IPackageFragment)element).hasChildren();
      case 5: 
      case 6: 
      case 7: 
      case 9: 
        return isJUnitTest(element);
      }
      return false;
    }
    catch (JavaModelException localJavaModelException) {}
    return false;
  }
  
  private boolean isJUnitTest(IJavaElement element)
  {
    try
    {
      IType testType = null;
      if ((element instanceof ICompilationUnit)) {
        testType = ((ICompilationUnit)element).findPrimaryType();
      } else if ((element instanceof IClassFile)) {
        testType = ((IClassFile)element).getType();
      } else if ((element instanceof IType)) {
        testType = (IType)element;
      } else if ((element instanceof IMember)) {
        testType = ((IMember)element).getDeclaringType();
      }
      if ((testType != null) && (testType.exists())) {
        return CoreTestSearchEngine.isTestOrTestSuite(testType);
      }
    }
    catch (CoreException localCoreException) {}
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jdt.internal.junit.JUnitPropertyTester
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jdt.internal.junit;

import java.util.List;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.service.prefs.BackingStoreException;

public class JunitPreferenceInitializer
  extends AbstractPreferenceInitializer
{
  public void initializeDefaultPreferences()
  {
    IEclipsePreferences prefs = DefaultScope.INSTANCE.getNode("org.eclipse.jdt.junit.core");
    
    prefs.putBoolean("org.eclipse.jdt.junit.do_filter_stack", true);
    
    prefs.putBoolean("org.eclipse.jdt.junit.show_on_error", false);
    prefs.putBoolean("org.eclipse.jdt.junit.enable_assertions", false);
    
    List defaults = JUnitPreferencesConstants.createDefaultStackFiltersList();
    String[] filters = (String[])defaults.toArray(new String[defaults.size()]);
    String active = JUnitPreferencesConstants.serializeList(filters);
    prefs.put("org.eclipse.jdt.junit.active_filters", active);
    prefs.put("org.eclipse.jdt.junit.inactive_filters", "");
    prefs.putInt("org.eclipse.jdt.junit.max_test_runs", 10);
    
    prefs.put("org.eclipse.jdt.junit.junit3.javadoclocation", "http://www.junit.org/junit/javadoc/3.8.1");
    prefs.put("org.eclipse.jdt.junit.junit4.javadoclocation", "http://www.junit.org/junit/javadoc/4.5");
    try
    {
      IEclipsePreferences newInstancePrefs = InstanceScope.INSTANCE.getNode("org.eclipse.jdt.junit.core");
      if (newInstancePrefs.keys().length == 0)
      {
        IEclipsePreferences oldInstancePrefs = InstanceScope.INSTANCE.getNode("org.eclipse.jdt.junit");
        
        String[] oldKeys = oldInstancePrefs.keys();
        for (int i = 0; i < oldKeys.length; i++)
        {
          String key = oldKeys[i];
          newInstancePrefs.put(key, oldInstancePrefs.get(key, null));
          oldInstancePrefs.remove(key);
        }
        newInstancePrefs.flush();
        oldInstancePrefs.flush();
      }
    }
    catch (BackingStoreException e)
    {
      JUnitCorePlugin.log(e);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jdt.internal.junit.JunitPreferenceInitializer
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jdt.internal.junit;

import java.text.MessageFormat;

public class Messages
{
  public static String format(String message, Object object)
  {
    return MessageFormat.format(message, new Object[] { object });
  }
  
  public static String format(String message, Object[] objects)
  {
    return MessageFormat.format(message, objects);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jdt.internal.junit.Messages
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jdt.internal.junit.buildpath;

import java.io.File;
import java.io.FilenameFilter;

class BuildPathSupport$1
  implements FilenameFilter
{
  private String pre;
  private String post;
  final BuildPathSupport.JUnitPluginDescription this$1;
  
  BuildPathSupport$1(BuildPathSupport.JUnitPluginDescription paramJUnitPluginDescription, String paramString, int paramInt)
  {
    this$1 = paramJUnitPluginDescription;
    pre = paramString.substring(0, paramInt);
    post = paramString.substring(paramInt + 1);
  }
  
  public boolean accept(File dir, String name)
  {
    return (name.startsWith(pre)) && (name.endsWith(post));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jdt.internal.junit.buildpath.BuildPathSupport.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jdt.internal.junit.buildpath;

import java.io.File;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.equinox.frameworkadmin.BundleInfo;
import org.eclipse.jdt.core.IAccessRule;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.osgi.framework.Version;

public class BuildPathSupport$JUnitPluginDescription
{
  private final String bundleId;
  private final VersionRange versionRange;
  private final String bundleRoot;
  private final String binaryImportedRoot;
  private final String sourceBundleId;
  private final String repositorySource;
  private final String javadocPreferenceKey;
  
  public BuildPathSupport$JUnitPluginDescription(String bundleId, VersionRange versionRange, String bundleRoot, String binaryImportedRoot, String sourceBundleId, String repositorySource, String javadocPreferenceKey)
  {
    this.bundleId = bundleId;
    this.versionRange = versionRange;
    this.bundleRoot = bundleRoot;
    this.binaryImportedRoot = binaryImportedRoot;
    this.sourceBundleId = sourceBundleId;
    this.repositorySource = repositorySource;
    this.javadocPreferenceKey = javadocPreferenceKey;
  }
  
  public IPath getBundleLocation()
  {
    return P2Utils.getBundleLocationPath(P2Utils.findBundle(bundleId, versionRange, false));
  }
  
  public IPath getSourceBundleLocation()
  {
    return getSourceLocation(P2Utils.findBundle(bundleId, versionRange, false));
  }
  
  public IClasspathEntry getLibraryEntry()
  {
    BundleInfo bundleInfo = P2Utils.findBundle(bundleId, versionRange, false);
    IPath bundleLocation = P2Utils.getBundleLocationPath(bundleInfo);
    if (bundleLocation != null)
    {
      IPath bundleRootLocation = getLibraryLocation(bundleInfo, bundleLocation);
      IPath srcLocation = getSourceLocation(bundleInfo);
      
      IAccessRule[] accessRules = new IAccessRule[0];
      
      String javadocLocation = Platform.getPreferencesService().getString("org.eclipse.jdt.junit.core", javadocPreferenceKey, "", null);
      IClasspathAttribute[] attributes;
      IClasspathAttribute[] attributes;
      if (javadocLocation.length() == 0) {
        attributes = new IClasspathAttribute[0];
      } else {
        attributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute("javadoc_location", javadocLocation) };
      }
      return JavaCore.newLibraryEntry(bundleRootLocation, srcLocation, null, accessRules, attributes, false);
    }
    return null;
  }
  
  private IPath getLibraryLocation(BundleInfo bundleInfo, IPath bundleLocation)
  {
    IPath bundleRootLocation = null;
    if (bundleRoot != null) {
      bundleRootLocation = getLocationIfExists(bundleInfo, bundleRoot);
    }
    if ((bundleRootLocation == null) && (binaryImportedRoot != null)) {
      bundleRootLocation = getLocationIfExists(bundleInfo, binaryImportedRoot);
    }
    if (bundleRootLocation == null) {
      bundleRootLocation = bundleLocation;
    }
    return bundleRootLocation;
  }
  
  private IPath getSourceLocation(BundleInfo bundleInfo)
  {
    IPath srcLocation = null;
    if (repositorySource != null) {
      srcLocation = getLocationIfExists(bundleInfo, repositorySource);
    }
    if (srcLocation == null)
    {
      BundleInfo sourceBundleInfo = P2Utils.findBundle(sourceBundleId, new Version(bundleInfo.getVersion()), true);
      if (sourceBundleInfo == null) {
        sourceBundleInfo = P2Utils.findBundle(sourceBundleId, versionRange, true);
      }
      srcLocation = P2Utils.getBundleLocationPath(sourceBundleInfo);
    }
    return srcLocation;
  }
  
  private IPath getLocationIfExists(BundleInfo bundleInfo, String entryInBundle)
  {
    IPath srcLocation = null;
    IPath bundleLocationPath = P2Utils.getBundleLocationPath(bundleInfo);
    if (bundleLocationPath != null)
    {
      File bundleFile = bundleLocationPath.toFile();
      if (bundleFile.isDirectory())
      {
        File srcFile = null;
        int starIdx = entryInBundle.indexOf('*');
        if (starIdx != -1)
        {
          File[] files = bundleFile.listFiles(new BuildPathSupport.1(this, entryInBundle, starIdx));
          if (files.length > 0) {
            srcFile = files[0];
          }
        }
        if (srcFile == null) {
          srcFile = new File(bundleFile, entryInBundle);
        }
        if (srcFile.exists())
        {
          srcLocation = new Path(srcFile.getPath());
          if (srcFile.isDirectory()) {
            srcLocation = srcLocation.addTrailingSeparator();
          }
        }
      }
    }
    return srcLocation;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jdt.internal.junit.buildpath.BuildPathSupport.JUnitPluginDescription
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jdt.internal.junit.buildpath;

import java.io.File;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.equinox.frameworkadmin.BundleInfo;
import org.eclipse.jdt.core.IAccessRule;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.junit.JUnitCore;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.osgi.framework.Version;

public class BuildPathSupport
{
  public static class JUnitPluginDescription
  {
    private final String bundleId;
    private final VersionRange versionRange;
    private final String bundleRoot;
    private final String binaryImportedRoot;
    private final String sourceBundleId;
    private final String repositorySource;
    private final String javadocPreferenceKey;
    
    public JUnitPluginDescription(String bundleId, VersionRange versionRange, String bundleRoot, String binaryImportedRoot, String sourceBundleId, String repositorySource, String javadocPreferenceKey)
    {
      this.bundleId = bundleId;
      this.versionRange = versionRange;
      this.bundleRoot = bundleRoot;
      this.binaryImportedRoot = binaryImportedRoot;
      this.sourceBundleId = sourceBundleId;
      this.repositorySource = repositorySource;
      this.javadocPreferenceKey = javadocPreferenceKey;
    }
    
    public IPath getBundleLocation()
    {
      return P2Utils.getBundleLocationPath(P2Utils.findBundle(bundleId, versionRange, false));
    }
    
    public IPath getSourceBundleLocation()
    {
      return getSourceLocation(P2Utils.findBundle(bundleId, versionRange, false));
    }
    
    public IClasspathEntry getLibraryEntry()
    {
      BundleInfo bundleInfo = P2Utils.findBundle(bundleId, versionRange, false);
      IPath bundleLocation = P2Utils.getBundleLocationPath(bundleInfo);
      if (bundleLocation != null)
      {
        IPath bundleRootLocation = getLibraryLocation(bundleInfo, bundleLocation);
        IPath srcLocation = getSourceLocation(bundleInfo);
        
        IAccessRule[] accessRules = new IAccessRule[0];
        
        String javadocLocation = Platform.getPreferencesService().getString("org.eclipse.jdt.junit.core", javadocPreferenceKey, "", null);
        IClasspathAttribute[] attributes;
        IClasspathAttribute[] attributes;
        if (javadocLocation.length() == 0) {
          attributes = new IClasspathAttribute[0];
        } else {
          attributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute("javadoc_location", javadocLocation) };
        }
        return JavaCore.newLibraryEntry(bundleRootLocation, srcLocation, null, accessRules, attributes, false);
      }
      return null;
    }
    
    private IPath getLibraryLocation(BundleInfo bundleInfo, IPath bundleLocation)
    {
      IPath bundleRootLocation = null;
      if (bundleRoot != null) {
        bundleRootLocation = getLocationIfExists(bundleInfo, bundleRoot);
      }
      if ((bundleRootLocation == null) && (binaryImportedRoot != null)) {
        bundleRootLocation = getLocationIfExists(bundleInfo, binaryImportedRoot);
      }
      if (bundleRootLocation == null) {
        bundleRootLocation = bundleLocation;
      }
      return bundleRootLocation;
    }
    
    private IPath getSourceLocation(BundleInfo bundleInfo)
    {
      IPath srcLocation = null;
      if (repositorySource != null) {
        srcLocation = getLocationIfExists(bundleInfo, repositorySource);
      }
      if (srcLocation == null)
      {
        BundleInfo sourceBundleInfo = P2Utils.findBundle(sourceBundleId, new Version(bundleInfo.getVersion()), true);
        if (sourceBundleInfo == null) {
          sourceBundleInfo = P2Utils.findBundle(sourceBundleId, versionRange, true);
        }
        srcLocation = P2Utils.getBundleLocationPath(sourceBundleInfo);
      }
      return srcLocation;
    }
    
    private IPath getLocationIfExists(BundleInfo bundleInfo, String entryInBundle)
    {
      IPath srcLocation = null;
      IPath bundleLocationPath = P2Utils.getBundleLocationPath(bundleInfo);
      if (bundleLocationPath != null)
      {
        File bundleFile = bundleLocationPath.toFile();
        if (bundleFile.isDirectory())
        {
          File srcFile = null;
          int starIdx = entryInBundle.indexOf('*');
          if (starIdx != -1)
          {
            File[] files = bundleFile.listFiles(new BuildPathSupport.1(this, entryInBundle, starIdx));
            if (files.length > 0) {
              srcFile = files[0];
            }
          }
          if (srcFile == null) {
            srcFile = new File(bundleFile, entryInBundle);
          }
          if (srcFile.exists())
          {
            srcLocation = new Path(srcFile.getPath());
            if (srcFile.isDirectory()) {
              srcLocation = srcLocation.addTrailingSeparator();
            }
          }
        }
      }
      return srcLocation;
    }
  }
  
  public static final JUnitPluginDescription JUNIT3_PLUGIN = new JUnitPluginDescription(
    "org.junit", new VersionRange("[3.8.2,3.9)"), "junit.jar", "junit.jar", "org.junit.source", "source-bundle/", "org.eclipse.jdt.junit.junit3.javadoclocation");
  private static final JUnitPluginDescription JUNIT4_PLUGIN = new JUnitPluginDescription(
    "org.junit", new VersionRange("[4.7.0,5.0.0)"), "junit.jar", "junit.jar", "org.junit.source", "source-bundle/", "org.eclipse.jdt.junit.junit4.javadoclocation");
  private static final JUnitPluginDescription HAMCREST_CORE_PLUGIN = new JUnitPluginDescription(
    "org.hamcrest.core", new VersionRange("[1.1.0,2.0.0)"), null, "org.hamcrest.core_1.*.jar", "org.hamcrest.core.source", "source-bundle/", "org.eclipse.jdt.junit.junit4.hamcrest.core.javadoclocation");
  
  public static IClasspathEntry getJUnit3ClasspathEntry()
  {
    return JavaCore.newContainerEntry(JUnitCore.JUNIT3_CONTAINER_PATH);
  }
  
  public static IClasspathEntry getJUnit4ClasspathEntry()
  {
    return JavaCore.newContainerEntry(JUnitCore.JUNIT4_CONTAINER_PATH);
  }
  
  public static IClasspathEntry getJUnit3LibraryEntry()
  {
    return JUNIT3_PLUGIN.getLibraryEntry();
  }
  
  public static IClasspathEntry getJUnit4LibraryEntry()
  {
    return JUNIT4_PLUGIN.getLibraryEntry();
  }
  
  public static IClasspathEntry getHamcrestCoreLibraryEntry()
  {
    return HAMCREST_CORE_PLUGIN.getLibraryEntry();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jdt.internal.junit.buildpath.BuildPathSupport
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jdt.internal.junit.buildpath;

import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.internal.junit.JUnitMessages;
import org.eclipse.jdt.junit.JUnitCore;

class JUnitContainerInitializer$JUnitContainer
  implements IClasspathContainer
{
  private final IClasspathEntry[] fEntries;
  private final IPath fPath;
  
  public JUnitContainerInitializer$JUnitContainer(IPath path, IClasspathEntry[] entries)
  {
    fPath = path;
    fEntries = entries;
  }
  
  public IClasspathEntry[] getClasspathEntries()
  {
    return fEntries;
  }
  
  public String getDescription()
  {
    if (JUnitCore.JUNIT4_CONTAINER_PATH.equals(fPath)) {
      return JUnitMessages.JUnitContainerInitializer_description_junit4;
    }
    return JUnitMessages.JUnitContainerInitializer_description_junit3;
  }
  
  public int getKind()
  {
    return 1;
  }
  
  public IPath getPath()
  {
    return fPath;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jdt.internal.junit.buildpath.JUnitContainerInitializer.JUnitContainer
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jdt.internal.junit.buildpath;

import java.util.ArrayList;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jdt.core.ClasspathContainerInitializer;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaModel;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.junit.JUnitMessages;
import org.eclipse.jdt.junit.JUnitCore;

public class JUnitContainerInitializer
  extends ClasspathContainerInitializer
{
  private static final IStatus NOT_SUPPORTED = new Status(4, "org.eclipse.jdt.junit.core", 1, new String(), null);
  private static final IStatus READ_ONLY = new Status(4, "org.eclipse.jdt.junit.core", 2, new String(), null);
  /**
   * @deprecated
   */
  private static final String JUNIT3_8_1 = "3.8.1";
  private static final String JUNIT3 = "3";
  private static final String JUNIT4 = "4";
  
  private static class JUnitContainer
    implements IClasspathContainer
  {
    private final IClasspathEntry[] fEntries;
    private final IPath fPath;
    
    public JUnitContainer(IPath path, IClasspathEntry[] entries)
    {
      fPath = path;
      fEntries = entries;
    }
    
    public IClasspathEntry[] getClasspathEntries()
    {
      return fEntries;
    }
    
    public String getDescription()
    {
      if (JUnitCore.JUNIT4_CONTAINER_PATH.equals(fPath)) {
        return JUnitMessages.JUnitContainerInitializer_description_junit4;
      }
      return JUnitMessages.JUnitContainerInitializer_description_junit3;
    }
    
    public int getKind()
    {
      return 1;
    }
    
    public IPath getPath()
    {
      return fPath;
    }
  }
  
  public void initialize(IPath containerPath, IJavaProject project)
    throws CoreException
  {
    if (isValidJUnitContainerPath(containerPath))
    {
      JUnitContainer container = getNewContainer(containerPath);
      JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { container }, null);
    }
  }
  
  private static JUnitContainer getNewContainer(IPath containerPath)
  {
    IClasspathEntry entry = null;
    IClasspathEntry entry2 = null;
    String version = containerPath.segment(1);
    if (("3.8.1".equals(version)) || ("3".equals(version)))
    {
      entry = BuildPathSupport.getJUnit3LibraryEntry();
    }
    else if ("4".equals(version))
    {
      entry = BuildPathSupport.getJUnit4LibraryEntry();
      entry2 = BuildPathSupport.getHamcrestCoreLibraryEntry();
    }
    IClasspathEntry[] entries;
    IClasspathEntry[] entries;
    if (entry == null)
    {
      entries = new IClasspathEntry[0];
    }
    else
    {
      IClasspathEntry[] entries;
      if (entry2 == null) {
        entries = new IClasspathEntry[] { entry };
      } else {
        entries = new IClasspathEntry[] { entry, entry2 };
      }
    }
    return new JUnitContainer(containerPath, entries);
  }
  
  private static boolean isValidJUnitContainerPath(IPath path)
  {
    return (path != null) && (path.segmentCount() == 2) && ("org.eclipse.jdt.junit.JUNIT_CONTAINER".equals(path.segment(0)));
  }
  
  public boolean canUpdateClasspathContainer(IPath containerPath, IJavaProject project)
  {
    return true;
  }
  
  public IStatus getAccessRulesStatus(IPath containerPath, IJavaProject project)
  {
    return NOT_SUPPORTED;
  }
  
  public IStatus getSourceAttachmentStatus(IPath containerPath, IJavaProject project)
  {
    return READ_ONLY;
  }
  
  public IStatus getAttributeStatus(IPath containerPath, IJavaProject project, String attributeKey)
  {
    if (attributeKey.equals("javadoc_location")) {
      return Status.OK_STATUS;
    }
    return NOT_SUPPORTED;
  }
  
  public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion)
    throws CoreException
  {
    IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode("org.eclipse.jdt.junit.core");
    
    IClasspathEntry[] entries = containerSuggestion.getClasspathEntries();
    if ((entries.length >= 1) && (isValidJUnitContainerPath(containerPath)))
    {
      String version = containerPath
1 2 3 4 5 6 7

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