org.eclipse.mylyn.commons.sdk.util_3.7.1.v20120425-0100

16:46:31.743 INFO  jd.cli.Main - Decompiling org.eclipse.mylyn.commons.sdk.util_3.7.1.v20120425-0100.jar
package org.eclipse.mylyn.commons.sdk.util;

public enum TestConfiguration$TestKind
{
  UNIT,  COMPONENT,  INTEGRATION,  SYSTEM;
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.sdk.util.TestConfiguration.TestKind
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.sdk.util;

import java.util.ArrayList;
import java.util.List;

public class TestProxy$Message
{
  public List<String> headers = new ArrayList();
  public String request;
  private String charset;
  
  public TestProxy$Message(String request)
  {
    this.request = request;
    charset = "ISO-8859-1";
  }
  
  public String getCharset()
  {
    return charset;
  }
  
  public String getHeader(String prefix)
  {
    if (headers != null) {
      for (String header : headers) {
        if (header.startsWith(prefix)) {
          return header;
        }
      }
    }
    return null;
  }
  
  public String getHeaderValue(String prefix)
  {
    String header = getHeader(prefix);
    if (header != null)
    {
      int i = header.indexOf(": ");
      return i != -1 ? header.substring(i + 2) : "";
    }
    return null;
  }
  
  public String getMethod()
  {
    int i = request.indexOf(" ");
    return i != -1 ? request.substring(0, i) : request;
  }
  
  public void setCharset(String charset)
  {
    this.charset = charset;
  }
  
  public String getStatusLine()
  {
    int i = request.indexOf("\n");
    return i != -1 ? request.substring(0, i) : request;
  }
  
  public String toString()
  {
    StringBuilder sb = new StringBuilder();
    sb.append(request);
    sb.append("\n");
    if (headers != null) {
      for (String header : headers)
      {
        sb.append(header);
        sb.append("\n");
      }
    }
    sb.append("\n");
    return sb.toString().replaceAll("\n", TestProxy.CRLF);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.sdk.util.TestProxy.Message
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.sdk.util;

import java.util.EnumSet;
import org.eclipse.core.runtime.Assert;

public class TestConfiguration
{
  public static TestConfiguration defaultConfiguration;
  
  public static enum TestKind
  {
    UNIT,  COMPONENT,  INTEGRATION,  SYSTEM;
  }
  
  private static final String SERVER = System.getProperty("mylyn.test.server", "mylyn.org");
  private final EnumSet<TestKind> kinds;
  private boolean localOnly;
  private boolean defaultOnly;
  private boolean headless;
  
  public static TestConfiguration getDefault()
  {
    if (defaultConfiguration == null)
    {
      defaultConfiguration = new TestConfiguration(TestKind.UNIT, new TestKind[0]);
      defaultConfiguration.setDefaultOnly(CommonTestUtil.runHeartbeatTestsOnly());
    }
    return defaultConfiguration;
  }
  
  public static String getRepositoryUrl(String service)
  {
    return getDefault().getUrl(service);
  }
  
  public static String getRepositoryUrl(String service, boolean secure)
  {
    return getDefault().getUrl(service, secure);
  }
  
  public static void setDefault(TestConfiguration defaultConfiguration)
  {
    defaultConfiguration = defaultConfiguration;
  }
  
  public TestConfiguration(TestKind firstKind, TestKind... moreKinds)
  {
    Assert.isNotNull(firstKind);
    kinds = EnumSet.of(firstKind, moreKinds);
  }
  
  public String getUrl(String service)
  {
    return getUrl(service, false);
  }
  
  public String getUrl(String service, boolean secure)
  {
    return (secure ? "https://" : "http://") + SERVER + "/" + service;
  }
  
  public boolean hasKind(TestKind kind)
  {
    return kinds.contains(kind);
  }
  
  public boolean isDefaultOnly()
  {
    return defaultOnly;
  }
  
  public boolean isHeadless()
  {
    return headless;
  }
  
  public boolean isLocalOnly()
  {
    return localOnly;
  }
  
  public void setDefaultOnly(boolean heartbeat)
  {
    defaultOnly = heartbeat;
  }
  
  public void setHeadless(boolean headless)
  {
    this.headless = headless;
  }
  
  public void setLocalOnly(boolean localOnly)
  {
    this.localOnly = localOnly;
  }
}

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

import junit.framework.Test;
import junit.framework.TestResult;

class ManagedTestSuite$1
  implements Test
{
  ManagedTestSuite$1(ManagedTestSuite paramManagedTestSuite) {}
  
  public int countTestCases()
  {
    return 1;
  }
  
  public void run(TestResult result) {}
  
  public String toString()
  {
    return "ShutdownWatchdog";
  }
}

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

import java.net.Proxy;
import java.util.Arrays;
import java.util.HashSet;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.core.runtime.Assert;
import org.eclipse.mylyn.commons.core.net.NetUtil;
import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation;
import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType;
import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials;

public abstract class RepositoryTestFixture
{
  private final String connectorKind;
  private String description;
  private String repositoryName;
  private final String repositoryUrl;
  private String simpleInfo;
  private TestSuite suite;
  private boolean useCertificateAuthentication;
  private boolean useShortUserNames;
  
  private final class Activation
    extends TestCase
  {
    private final boolean activate;
    
    private Activation(String name, boolean activate)
    {
      super();
      this.activate = activate;
    }
    
    protected void runTest()
      throws Throwable
    {
      if (activate) {
        activate();
      } else {
        getDefault().activate();
      }
    }
  }
  
  public RepositoryTestFixture(String connectorKind, String repositoryUrl)
  {
    this.connectorKind = connectorKind;
    this.repositoryUrl = repositoryUrl;
    useCertificateAuthentication = repositoryUrl.contains("/secure/");
  }
  
  public void add(Class<? extends TestCase> clazz)
  {
    Assert.isNotNull(suite, "Invoke createSuite() first");
    suite.addTestSuite(clazz);
  }
  
  public TestSuite createSuite(TestSuite parentSuite)
  {
    suite = new TestSuite("Testing on " + getInfo());
    parentSuite.addTest(suite);
    suite.addTest(new Activation("repository: " + getRepositoryUrl() + " [@" + getSimpleInfo() + "]", true, null));
    return suite;
  }
  
  public void done()
  {
    Assert.isNotNull(suite, "Invoke createSuite() first");
    suite.addTest(new Activation("done", false, null));
    suite = null;
  }
  
  public String getConnectorKind()
  {
    return connectorKind;
  }
  
  public String getDescription()
  {
    return description;
  }
  
  public String getInfo()
  {
    return repositoryName + " " + simpleInfo;
  }
  
  public String getRepositoryUrl()
  {
    return repositoryUrl;
  }
  
  public String getSimpleInfo()
  {
    return simpleInfo;
  }
  
  public boolean isExcluded()
  {
    String excludeFixture = System.getProperty("mylyn.test.exclude", "");
    String[] excludeFixtureArray = excludeFixture.split(",");
    return new HashSet(Arrays.asList(excludeFixtureArray)).contains(getRepositoryUrl());
  }
  
  public boolean isUseCertificateAuthentication()
  {
    return useCertificateAuthentication;
  }
  
  public boolean isUseShortUserNames()
  {
    return useShortUserNames;
  }
  
  public RepositoryLocation location()
    throws Exception
  {
    return location(CommonTestUtil.PrivilegeLevel.USER);
  }
  
  public RepositoryLocation location(CommonTestUtil.PrivilegeLevel level)
    throws Exception
  {
    return location(level, NetUtil.getProxyForUrl(repositoryUrl));
  }
  
  public RepositoryLocation location(CommonTestUtil.PrivilegeLevel level, Proxy proxy)
    throws Exception
  {
    if (level == CommonTestUtil.PrivilegeLevel.ANONYMOUS) {
      return location(null, null, proxy);
    }
    UserCredentials credentials = CommonTestUtil.getCredentials(level);
    String userName = credentials.getUserName();
    if ((isUseShortUserNames()) && (userName.contains("@"))) {
      userName = userName.substring(0, userName.indexOf("@"));
    }
    return location(userName, credentials.getPassword(), proxy);
  }
  
  public RepositoryLocation location(String username, String password)
    throws Exception
  {
    return location(username, password, NetUtil.getProxyForUrl(repositoryUrl));
  }
  
  public RepositoryLocation location(String username, String password, Proxy proxy)
    throws Exception
  {
    RepositoryLocation location = new RepositoryLocation();
    location.setUrl(repositoryUrl);
    location.setProxy(proxy);
    if ((username != null) && (password != null)) {
      location.setCredentials(AuthenticationType.REPOSITORY, new UserCredentials(username, password));
    }
    if ((isUseCertificateAuthentication()) && (!forceDefaultKeystore(proxy))) {
      location.setCredentials(AuthenticationType.CERTIFICATE, CommonTestUtil.getCertificateCredentials());
    }
    return location;
  }
  
  private boolean forceDefaultKeystore(Proxy proxy)
  {
    if ((proxy != null) && (System.getProperty("javax.net.ssl.keyStore") != null)) {
      return true;
    }
    return false;
  }
  
  public void setUseCertificateAuthentication(boolean useCertificateAuthentication)
  {
    this.useCertificateAuthentication = useCertificateAuthentication;
  }
  
  public void setUseShortUserNames(boolean useShortUsernames)
  {
    useShortUserNames = useShortUsernames;
  }
  
  protected abstract RepositoryTestFixture activate();
  
  protected abstract RepositoryTestFixture getDefault();
  
  protected void setInfo(String repositoryName, String version, String description)
  {
    Assert.isNotNull(repositoryName);
    Assert.isNotNull(version);
    this.repositoryName = repositoryName;
    simpleInfo = version;
    this.description = description;
    if ((description != null) && (description.length() > 0)) {
      simpleInfo = (simpleInfo + "/" + description);
    }
  }
}

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

import java.io.PrintStream;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;

public class ResourceTestUtil
{
  public static void deleteProject(IProject project)
    throws CoreException
  {
    if ((project.exists()) && (!project.isOpen())) {
      project.open(null);
    }
    deleteResource(project);
  }
  
  public static void deleteResource(IResource resource)
    throws CoreException
  {
    CoreException lastException = null;
    try
    {
      resource.delete(true, null);
    }
    catch (CoreException e)
    {
      lastException = e;
      
      System.out.println("(CoreException): " + e.getMessage() + ", resource " + resource.getFullPath());
    }
    catch (IllegalArgumentException iae)
    {
      System.out.println("(IllegalArgumentException): " + iae.getMessage() + ", resource " + resource.getFullPath());
    }
    int retryCount = 60;
    do
    {
      try
      {
        Thread.sleep(1000L);
      }
      catch (InterruptedException localInterruptedException) {}
      try
      {
        resource.delete(true, null);
      }
      catch (CoreException e)
      {
        lastException = e;
        
        System.out.println("(CoreException) Retry " + retryCount + ": " + e.getMessage() + ", resource " + resource.getFullPath());
      }
      catch (IllegalArgumentException iae)
      {
        System.out.println("(IllegalArgumentException) Retry " + retryCount + ": " + iae.getMessage() + ", resource " + resource.getFullPath());
      }
      if (!resource.isAccessible()) {
        break;
      }
      retryCount--;
    } while (retryCount >= 0);
    if (!resource.isAccessible()) {
      return;
    }
    System.err.println("Failed to delete " + resource.getFullPath());
    if (lastException != null) {
      throw lastException;
    }
  }
}

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

import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;

public class TestProject
{
  public IProject project;
  
  public TestProject(String name)
    throws CoreException, InvocationTargetException, InterruptedException
  {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    project = root.getProject(name);
    project.create(null);
    project.open(null);
  }
  
  public IProject getProject()
  {
    return project;
  }
  
  public IFolder createFolder(String name)
    throws CoreException
  {
    IFolder folder = project.getFolder(name);
    folder.create(false, true, null);
    return folder;
  }
}

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

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.ProxySelector;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipFile;
import junit.framework.AssertionFailedError;
import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.mylyn.commons.core.CoreUtil;
import org.eclipse.mylyn.commons.net.WebUtil;
import org.eclipse.mylyn.commons.repositories.core.auth.CertificateCredentials;
import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials;
import org.eclipse.mylyn.internal.commons.net.CommonsNetPlugin;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;
import org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;

public class CommonTestUtil
{
  public static final String KEY_CREDENTIALS_FILE = "mylyn.credentials";
  private static final int MAX_RETRY = 5;
  
  public static enum PrivilegeLevel
  {
    ADMIN,  ANONYMOUS,  GUEST,  READ_ONLY,  USER;
  }
  
  public static String changeSeparator(String path, char oldSeparator, char newSeparator)
  {
    return path.replace(oldSeparator, newSeparator);
  }
  
  /* Error */
  public static void copy(File source, File dest)
    throws IOException
  {
    // Byte code:
    //   0: new 346	java/io/FileInputStream
    //   3: dup
    //   4: aload_0
    //   5: invokespecial 635	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   8: astore_2
    //   9: new 347	java/io/FileOutputStream
    //   12: dup
    //   13: aload_1
    //   14: invokespecial 636	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   17: astore_3
    //   18: aload_2
    //   19: aload_3
    //   20: invokestatic 715	org/eclipse/mylyn/commons/sdk/util/CommonTestUtil:transferData	(Ljava/io/InputStream;Ljava/io/OutputStream;)V
    //   23: goto +12 -> 35
    //   26: astore 4
    //   28: aload_3
    //   29: invokevirtual 641	java/io/OutputStream:close	()V
    //   32: aload 4
    //   34: athrow
    //   35: aload_3
    //   36: invokevirtual 641	java/io/OutputStream:close	()V
    //   39: goto +12 -> 51
    //   42: astore 5
    //   44: aload_2
    //   45: invokevirtual 639	java/io/InputStream:close	()V
    //   48: aload 5
    //   50: athrow
    //   51: aload_2
    //   52: invokevirtual 639	java/io/InputStream:close	()V
    //   55: return
    // Line number table:
    //   Java source line #87	-> byte code offset #0
    //   Java source line #89	-> byte code offset #9
    //   Java source line #91	-> byte code offset #18
    //   Java source line #92	-> byte code offset #26
    //   Java source line #93	-> byte code offset #28
    //   Java source line #94	-> byte code offset #32
    //   Java source line #93	-> byte code offset #35
    //   Java source line #95	-> byte code offset #42
    //   Java source line #96	-> byte code offset #44
    //   Java source line #97	-> byte code offset #48
    //   Java source line #96	-> byte code offset #51
    //   Java source line #98	-> byte code offset #55
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	56	0	source	File
    //   0	56	1	dest	File
    //   8	44	2	in	InputStream
    //   17	19	3	out	OutputStream
    //   26	7	4	localObject1	Object
    //   42	7	5	localObject2	Object
    // Exception table:
    //   from	to	target	type
    //   18	26	26	finally
    //   9	42	42	finally
  }
  
  public static void copyFolder(File sourceFolder, File targetFolder)
    throws IOException
  {
    File[] arrayOfFile;
    int j = (arrayOfFile = sourceFolder.listFiles()).length;
    for (int i = 0; i < j; i++)
    {
      File sourceFile = arrayOfFile[i];
      if (sourceFile.isFile())
      {
        File destFile = new File(targetFolder, sourceFile.getName());
        copy(sourceFile, destFile);
      }
    }
  }
  
  public static void copyFolderRecursively(File sourceFolder, File targetFolder)
    throws IOException
  {
    File[] arrayOfFile;
    int j = (arrayOfFile = sourceFolder.listFiles()).length;
    for (int i = 0; i < j; i++)
    {
      File sourceFile = arrayOfFile[i];
      if (sourceFile.isFile())
      {
        File destFile = new File(targetFolder, sourceFile.getName());
        copy(sourceFile, destFile);
      }
      else if (sourceFile.isDirectory())
      {
        File destDir = new File(targetFolder, sourceFile.getName());
        if ((!destDir.exists()) && 
          (!destDir.mkdir())) {
          throw new IOException("Unable to create destination folder: " + destDir.getAbsolutePath());
        }
        copyFolderRecursively(sourceFile, destDir);
      }
    }
  }
  
  public static File createTempFileInPlugin(Plugin plugin, IPath path)
  {
    IPath stateLocation = plugin.getStateLocation();
    stateLocation = stateLocation.append(path);
    return stateLocation.toFile();
  }
  
  public static File createTempFolder(String prefix)
    throws IOException
  {
    File location = File.createTempFile(prefix, null);
    location.delete();
    location.mkdirs();
    return location;
  }
  
  public static void delete(File file)
  {
    if (file.exists()) {
      for (int i = 0; i < 5; i++) {
        if (file.delete()) {
          i = 5;
        } else {
          try
          {
            Thread.sleep(1000L);
          }
          catch (InterruptedException localInterruptedException) {}
        }
      }
    }
  }
  
  public static void deleteFolder(File path)
  {
    if (path.isDirectory())
    {
      File[] arrayOfFile;
      int j = (arrayOfFile = path.listFiles()).length;
      for (int i = 0; i < j; i++)
      {
        File file = arrayOfFile[i];
        file.delete();
      }
      path.delete();
    }
  }
  
  public static void deleteFolderRecursively(File path)
  {
    File[] files = path.listFiles();
    if (files != null)
    {
      File[] arrayOfFile1;
      int j = (arrayOfFile1 = files).length;
      for (int i = 0; i < j; i++)
      {
        File file = arrayOfFile1[i];
        if (file.isDirectory()) {
          deleteFolderRecursively(file);
        } else {
          file.delete();
        }
      }
    }
    path.delete();
  }
  
  public static CertificateCredentials getCertificateCredentials()
  {
    try
    {
      File keyStoreFile = getFile(CommonTestUtil.class, "testdata/keystore");
      String password = getUserCredentials().getPassword();
      return new CertificateCredentials(keyStoreFile.getAbsolutePath(), password, null);
    }
    catch (IOException cause)
    {
      AssertionFailedError e = new AssertionFailedError("Failed to load keystore file");
      e.initCause(cause);
      throw e;
    }
  }
  
  public static boolean hasCredentials(PrivilegeLevel level)
  {
    try
    {
      getCredentials(level);
      return true;
    }
    catch (AssertionFailedError localAssertionFailedError) {}
    return false;
  }
  
  public static UserCredentials getCredentials(PrivilegeLevel level)
  {
    return getCredentials(level, null);
  }
  
  public static UserCredentials getCredentials(PrivilegeLevel level, String realm)
  {
    Properties properties = new Properties();
    try
    {
      String filename = System.getProperty("mylyn.credentials");
      File file;
      File file;
      if (filename != null)
      {
        file = new File(filename);
      }
      else
      {
        file = new File(new File(System.getProperty("user.home"), ".mylyn"), "credentials.properties");
        if (!file.exists()) {
          file = getFile(CommonTestUtil.class, "testdata/credentials.properties");
        }
      }
      properties.load(new FileInputStream(file));
    }
    catch (Exception e)
    {
      AssertionFailedError error = new AssertionFailedError(
        "must define credentials in $HOME/.mylyn/credentials.properties");
      error.initCause(e);
      throw error;
    }
    String defaultPassword = properties.getProperty("pass");
    
    realm = realm != null ? realm + "." : "";
    switch (level)
    {
    case ANONYMOUS: 
      return createCredentials(properties, realm + "anon.", "", "");
    case GUEST: 
      return createCredentials(properties, realm + "guest.", "guest@mylyn.eclipse.org", defaultPassword);
    case USER: 
      return createCredentials(properties, realm, "tests@mylyn.eclipse.org", defaultPassword);
    case READ_ONLY: 
      return createCredentials(properties, realm, "read-only@mylyn.eclipse.org", defaultPassword);
    case ADMIN: 
      return createCredentials(properties, realm + "admin.", "admin@mylyn.eclipse.org", null);
    }
    throw new AssertionFailedError("invalid privilege level");
  }
  
  public static File getFile(Object source, String filename)
    throws IOException
  {
    Class<?> clazz = (source instanceof Class) ? (Class)source : source.getClass();
    if (Platform.isRunning())
    {
      ClassLoader classLoader = clazz.getClassLoader();
      if ((classLoader instanceof DefaultClassLoader))
      {
        URL url = ((DefaultClassLoader)classLoader).getClasspathManager()
          .getBaseData()
          .getBundle()
          .getEntry(filename);
        if (url != null)
        {
          URL localURL = FileLocator.toFileURL(url);
          return new File(localURL.getFile());
        }
      }
    }
    else
    {
      URL localURL = clazz.getResource("");
      String path = URLDecoder.decode(localURL.getFile(), Charset.defaultCharset().name());
      int i = path.indexOf("!");
      if (i != -1)
      {
        int j = path.lastIndexOf(File.separatorChar, i);
        if (j != -1) {
          path = path.substring(0, j) + File.separator;
        } else {
          throw new AssertionFailedError("Unable to determine location for '" + filename + "' at '" + path + 
            "'");
        }
        if (path.startsWith("file:")) {
          path = path.substring(5);
        }
        return new File(path + filename);
      }
      String directory = clazz.getName().replaceAll("[^.]", "");
      directory = directory.replaceAll(".", "../");
      if (path.contains("/bin/")) {
        directory = directory + "../";
      } else if (path.contains("/target/classes/")) {
        directory = directory + "../../";
      }
      filename = path + new StringBuilder(String.valueOf(directory)).append(filename).toString().replaceAll("/", Matcher.quoteReplacement(File.separator));
      return new File(filename).getCanonicalFile();
    }
    throw new AssertionFailedError("Could not locate " + filename);
  }
  
  public static InputStream getResource(Object source, String filename)
    throws IOException
  {
    Class<?> clazz = (source instanceof Class) ? (Class)source : source.getClass();
    ClassLoader classLoader = clazz.getClassLoader();
    InputStream in = classLoader.getResourceAsStream(filename);
    if (in == null)
    {
      File file = getFile(source, filename);
      if (file != null) {
        return new FileInputStream(file);
      }
    }
    if (in == null) {
      throw new IOException(NLS.bind("Failed to locate ''{0}'' for ''{1}''", filename, clazz.getName()));
    }
    return in;
  }
  
  public static UserCredentials getUserCredentials()
  {
    return getCredentials(PrivilegeLevel.USER, null);
  }
  
  public static String read(File source)
    throws IOException
  {
    InputStream in = new FileInputStream(source);
    try
    {
      StringBuilder sb = new StringBuilder();
      byte[] buf = new byte['?'];
      int len;
      while ((len = in.read(buf)) > 0)
      {
        int len;
        sb.append(new String(buf, 0, len));
      }
      return sb.toString();
    }
    finally
    {
      in.close();
    }
  }
  
  public static boolean runHeartbeatTestsOnly()
  {
    return !Boolean.parseBoolean(System.getProperty("org.eclipse.mylyn.tests.all"));
  }
  
  public static void unzip(ZipFile zipFile, File dstDir)
    throws IOException
  {
    unzip(zipFile, dstDir, dstDir, 0);
  }
  
  /* Error */
  public static void write(String fileName, StringBuffer content)
    throws IOException
  {
    // Byte code:
    //   0: new 348	java/io/FileWriter
    //   3: dup
    //   4: aload_0
    //   5: invokespecial 637	java/io/FileWriter:<init>	(Ljava/lang/String;)V
    //   8: astore_2
    //   9: aload_2
    //   10: aload_1
    //   11: invokevirtual 667	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   14: invokevirtual 647	java/io/Writer:write	(Ljava/lang/String;)V
    //   17: goto +14 -> 31
    //   20: astore_3
    //   21: aload_2
    //   22: invokevirtual 646	java/io/Writer:close	()V
    //   25: goto +4 -> 29
    //   28: pop
    //   29: aload_3
    //   30: athrow
    //   31: aload_2
    //   32: invokevirtual 646	java/io/Writer:close	()V
    //   35: goto +4 -> 39
    //   38: pop
    //   39: return
    // Line number table:
    //   Java source line #362	-> byte code offset #0
    //   Java source line #364	-> byte code offset #9
    //   Java source line #365	-> byte code offset #20
    //   Java source line #367	-> byte code offset #21
    //   Java source line #368	-> byte code offset #28
    //   Java source line #371	-> byte code offset #29
    //   Java source line #367	-> byte code offset #31
    //   Java source line #368	-> byte code offset #38
    //   Java source line #372	-> byte code offset #39
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	40	0	fileName	String
    //   0	40	1	content	StringBuffer
    //   8	24	2	writer	java.io.Writer
    //   20	10	3	localObject	Object
    //   28	1	4	localIOException1	IOException
    //   38	1	5	localIOException2	IOException
    // Exception table:
    //   from	to	target	type
    //   9	20	20	finally
    //   21	25	28	java/io/IOException
    //   31	35	38	java/io/IOException
  }
  
  private static UserCredentials createCredentials(Properties properties, String prefix, String defaultUsername, String defaultPassword)
  {
    String username = properties.getProperty(prefix + "user");
    String password = properties.getProperty(prefix + "pass");
    if (username == null) {
      username = defaultUsername;
    }
    if (password == null) {
      password = defaultPassword;
    }
    if ((username == null) || (password == null)) {
      throw new AssertionFailedError("username or password not found for " + prefix + 
        " in <plug-in dir>/credentials.properties, make sure file is valid");
    }
    return new UserCredentials(username, password);
  }
  
  private static void transferData(InputStream in, OutputStream out)
    throws IOException
  {
    byte[] buf = new byte['?'];
    int len;
    while ((len = in.read(buf)) > 0)
    {
      int len;
      out.write(buf, 0, len);
    }
  }
  
  /* Error */
  private static void unzip(ZipFile zipFile, File rootDstDir, File dstDir, int depth)
    throws IOException
  {
    // Byte code:
    //   0: aload_0
    //   1: invokevirtual 693	java/util/zip/ZipFile:entries	()Ljava/util/Enumeration;
    //   4: astore 4
    //   6: goto +158 -> 164
    //   9: aload 4
    //   11: invokeinterface 732 1 0
    //   16: checkcast 380	java/util/zip/ZipEntry
    //   19: astore 5
    //   21: aload 5
    //   23: invokevirtual 690	java/util/zip/ZipEntry:isDirectory	()Z
    //   26: ifeq +6 -> 32
    //   29: goto +135 -> 164
    //   32: aload 5
    //   34: invokevirtual 691	java/util/zip/ZipEntry:getName	()Ljava/lang/String;
    //   37: astore 6
    //   39: new 345	java/io/File
    //   42: dup
    //   43: aload_2
    //   44: aload 6
    //   46: bipush 47
    //   48: getstatic 611	java/io/File:separatorChar	C
    //   51: invokestatic 716	org/eclipse/mylyn/commons/sdk/util/CommonTestUtil:changeSeparator	(Ljava/lang/String;CC)Ljava/lang/String;
    //   54: invokespecial 632	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   57: astore 7
    //   59: aload 7
    //   61: invokevirtual 627	java/io/File:getParentFile	()Ljava/io/File;
    //   64: invokevirtual 625	java/io/File:mkdirs	()Z
    //   67: pop
    //   68: aconst_null
    //   69: astore 8
    //   71: aconst_null
    //   72: astore 9
    //   74: aload_0
    //   75: aload 5
    //   77: invokevirtual 694	java/util/zip/ZipFile:getInputStream	(Ljava/util/zip/ZipEntry;)Ljava/io/InputStream;
    //   80: astore 8
    //   82: new 347	java/io/FileOutputStream
    //   85: dup
    //   86: aload 7
    //   88: invokespecial 636	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   91: astore 9
    //   93: aload 8
    //   95: aload 9
    //   97: invokestatic 715	org/eclipse/mylyn/commons/sdk/util/CommonTestUtil:transferData	(Ljava/io/InputStream;Ljava/io/OutputStream;)V
    //   100: goto +36 -> 136
    //   103: astore 10
    //   105: aload 9
    //   107: ifnull +12 -> 119
    //   110: aload 9
    //   112: invokevirtual 641	java/io/OutputStream:close	()V
    //   115: goto +4 -> 119
    //   118: pop
    //   119: aload 8
    //   121: ifnull +12 -> 133
    //   124: aload 8
    //   126: invokevirtual 639	java/io/InputStream:close	()V
    //   129: goto +4 -> 133
    //   132: pop
    //   133: aload 10
    //   135: athrow
    //   136: aload 9
    //   138: ifnull +12 -> 150
    //   141: aload 9
    //   143: invokevirtual 641	java/io/OutputStream:close	()V
    //   146: goto +4 -> 150
    //   149: pop
    //   150: aload 8
    //   152: ifnull +12 -> 164
    //   155: aload 8
    //   157: invokevirtual 639	java/io/InputStream:close	()V
    //   160: goto +4 -> 164
    //   163: pop
    //   164: aload 4
    //   166: invokeinterface 731 1 0
    //   171: ifne -162 -> 9
    //   174: goto +16 -> 190
    //   177: astore 11
    //   179: aload_0
    //   180: invokevirtual 692	java/util/zip/ZipFile:close	()V
    //   183: goto +4 -> 187
    //   186: pop
    //   187: aload 11
    //   189: athrow
    //   190: aload_0
    //   191: invokevirtual 692	java/util/zip/ZipFile:close	()V
    //   194: goto +4 -> 198
    //   197: pop
    //   198: return
    // Line number table:
    //   Java source line #415	-> byte code offset #0
    //   Java source line #418	-> byte code offset #6
    //   Java source line #419	-> byte code offset #9
    //   Java source line #420	-> byte code offset #21
    //   Java source line #421	-> byte code offset #29
    //   Java source line #423	-> byte code offset #32
    //   Java source line #424	-> byte code offset #39
    //   Java source line #425	-> byte code offset #59
    //   Java source line #426	-> byte code offset #68
    //   Java source line #427	-> byte code offset #71
    //   Java source line #429	-> byte code offset #74
    //   Java source line #430	-> byte code offset #82
    //   Java source line #431	-> byte code offset #93
    //   Java source line #432	-> byte code offset #103
    //   Java source line #433	-> byte code offset #105
    //   Java source line #435	-> byte code offset #110
    //   Java source line #436	-> byte code offset #118
    //   Java source line #440	-> byte code offset #119
    //   Java source line #442	-> byte code offset #124
    //   Java source line #443	-> byte code offset #132
    //   Java source line #447	-> byte code offset #133
    //   Java source line #433	-> byte code offset #136
    //   Java source line #435	-> byte code offset #141
    //   Java source line #436	-> byte code offset #149
    //   Java source line #440	-> byte code offset #150
    //   Java source line #442	-> byte code offset #155
    //   Java source line #443	-> byte code offset #163
    //   Java source line #418	-> byte code offset #164
    //   Java source line #449	-> byte code offset #177
    //   Java source line #451	-> byte code offset #179
    //   Java source line #452	-> byte code offset #186
    //   Java source line #455	-> byte code offset #187
    //   Java source line #451	-> byte code offset #190
    //   Java source line #452	-> byte code offset #197
    //   Java source line #456	-> byte code offset #198
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	199	0	zipFile	ZipFile
    //   0	199	1	rootDstDir	File
    //   0	199	2	dstDir	File
    //   0	199	3	depth	int
    //   4	161	4	entries	java.util.Enumeration<? extends java.util.zip.ZipEntry>
    //   19	57	5	entry	java.util.zip.ZipEntry
    //   37	8	6	entryName	String
    //   57	30	7	file	File
    //   69	87	8	src	InputStream
    //   72	70	9	dst	OutputStream
    //   103	31	10	localObject1	Object
    //   177	11	11	localObject2	Object
    //   118	1	12	localIOException1	IOException
    //   132	1	13	localIOException2	IOException
    //   149	1	14	localIOException3	IOException
    //   163	1	15	localIOException4	IOException
    //   186	1	16	localIOException5	IOException
    //   197	1	17	localIOException6	IOException
    // Exception table:
    //   from	to	target	type
    //   74	103	103	finally
    //   110	115	118	java/io/IOException
    //   124	129	132	java/io/IOException
    //   141	146	149	java/io/IOException
    //   155	160	163	java/io/IOException
    //   6	177	177	finally
    //   179	183	186	java/io/IOException
    //   190	194	197	java/io/IOException
  }
  
  public static boolean isCertificateAuthBroken()
  {
    return new VersionRange("[0.0.0,1.6.0.25]").isIncluded(CoreUtil.getRuntimeVersion());
  }
  
  public static boolean hasCertificateCredentials()
  {
    try
    {
      getCertificateCredentials();
      return true;
    }
    catch (AssertionFailedError localAssertionFailedError) {}
    return false;
  }
  
  public static String getShortUserName(UserCredentials credentials)
  {
    String username = credentials.getUserName();
    if (username.contains("@")) {
      return username.substring(0, username.indexOf("@"));
    }
    return username;
  }
  
  public static boolean fixProxyConfiguration()
  {
    if ((Platform.isRunning()) && (CommonsNetPlugin.getProxyService() != null) && 
      (CommonsNetPlugin.getProxyService().isSystemProxiesEnabled()) && 
      (!CommonsNetPlugin.getProxyService().hasSystemProxies()))
    {
      System.err.println("Forcing manual proxy configuration");
      CommonsNetPlugin.getProxyService().setSystemProxiesEnabled(false);
      CommonsNetPlugin.getProxyService().setProxiesEnabled(true);
      return true;
    }
    return false;
  }
  
  public static void dumpSystemInfo(PrintStream out)
  {
    Properties p = System.getProperties();
    if (Platform.isRunning()) {
      p.put("build.system", Platform.getOS() + "-" + Platform.getOSArch() + "-" + Platform.getWS());
    } else {
      p.put("build.system", "standalone");
    }
    String info = "System: ${os.name} ${os.version} (${os.arch}) / ${build.system} / ${java.vendor} ${java.vm.name} ${java.version}";
    for (Map.Entry<Object, Object> entry : p.entrySet()) {
      info = info.replaceFirst(Pattern.quote("${" + entry.getKey() + "}"), entry.getValue().toString());
    }
    out.println(info);
    out.print("Proxy : " + WebUtil.getProxyForUrl("http://mylyn.eclipse.org") + " (Platform)");
    try
    {
      out.print(" / " + ProxySelector.getDefault().select(new URI("http://mylyn.eclipse.org")) + " (Java)");
    }
    catch (URISyntaxException localURISyntaxException) {}
    out.println();
    out.println();
  }
}

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

public enum CommonTestUtil$PrivilegeLevel
{
  ADMIN,  ANONYMOUS,  GUEST,  READ_ONLY,  USER;
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.PrivilegeLevel
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.sdk.util;

import java.io.PrintStream;
import java.text.MessageFormat;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TimerTask;
import junit.framework.Test;

class ManagedTestSuite$DumpThreadTask
  extends TimerTask
{
  private final Test test;
  private final Thread testThread;
  
  public ManagedTestSuite$DumpThreadTask(ManagedTestSuite paramManagedTestSuite, Test test)
  {
    this.test = test;
    testThread = Thread.currentThread();
  }
  
  public void run()
  {
    StringBuffer sb = new StringBuffer();
    sb.append(MessageFormat.format("Test {0} is taking too long:\n", new Object[] { test.toString() }));
    Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces();
    for (Map.Entry<Thread, StackTraceElement[]> entry : traces.entrySet())
    {
      sb.append(((Thread)entry.getKey()).toString());
      sb.append("\n");
      StackTraceElement[] arrayOfStackTraceElement;
      int j = (arrayOfStackTraceElement = (StackTraceElement[])entry.getValue()).length;
      for (int i = 0; i < j; i++)
      {
        StackTraceElement element = arrayOfStackTraceElement[i];
        sb.append("  ");
        sb.append(element.toString());
        sb.append("\n");
      }
      sb.append("\n");
    }
    System.err.println(sb.toString());
    
    System.err.println("Sending interrupt to thread: " + testThread.toString());
    testThread.interrupt();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.sdk.util.ManagedTestSuite.DumpThreadTask
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.sdk.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.util.ArrayList;
i
1 2

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