org.eclipse.ant.core_3.2.401.v20121204-162022

16:41:20.980 INFO  jd.cli.Main - Decompiling org.eclipse.ant.core_3.2.401.v20121204-162022.jar
package org.eclipse.ant.core;

import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.List;
import org.eclipse.ant.internal.core.AntClassLoader;
import org.eclipse.ant.internal.core.AntCoreUtil;
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.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleContext;

public class AntCorePlugin
  extends Plugin
{
  public static final int INTERNAL_ERROR = 120;
  private static AntCorePlugin plugin;
  private AntCorePreferences preferences;
  public static final String PI_ANTCORE = "org.eclipse.ant.core";
  public static final String PT_TASKS = "antTasks";
  public static final String PT_EXTRA_CLASSPATH = "extraClasspathEntries";
  public static final String PT_TYPES = "antTypes";
  public static final String PT_PROPERTIES = "antProperties";
  public static final String ANT_BUILDFILE_CONTENT_TYPE = "org.eclipse.ant.core.antBuildFile";
  public static final String CLASS = "class";
  public static final String NAME = "name";
  public static final String LIBRARY = "library";
  public static final String HEADLESS = "headless";
  public static final String ECLIPSE_RUNTIME = "eclipseRuntime";
  public static final String URI = "uri";
  public static final String VALUE = "value";
  public static final String ECLIPSE_PROGRESS_MONITOR = "eclipse.progress.monitor";
  public static final int ERROR_RUNNING_BUILD = 1;
  public static final int ERROR_MALFORMED_URL = 2;
  public static final int ERROR_LIBRARY_NOT_SPECIFIED = 3;
  
  public AntCorePlugin()
  {
    plugin = this;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    super.stop(context);
    AntCoreUtil.setBundleContext(null);
    if (preferences != null) {
      savePluginPreferences();
    }
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
    AntCoreUtil.setBundleContext(context);
  }
  
  private List extractExtensions(String pointName)
  {
    IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.ant.core", pointName);
    if (extensionPoint == null) {
      return null;
    }
    IConfigurationElement[] extensions = extensionPoint.getConfigurationElements();
    return Arrays.asList(extensions);
  }
  
  public AntCorePreferences getPreferences()
  {
    if (preferences == null) {
      preferences = new AntCorePreferences(extractExtensions("antTasks"), extractExtensions("extraClasspathEntries"), extractExtensions("antTypes"), extractExtensions("antProperties"), false);
    }
    return preferences;
  }
  
  public void setRunningHeadless(boolean headless)
  {
    preferences = new AntCorePreferences(extractExtensions("antTasks"), extractExtensions("extraClasspathEntries"), extractExtensions("antTypes"), extractExtensions("antProperties"), headless);
  }
  
  public static AntCorePlugin getPlugin()
  {
    return plugin;
  }
  
  public ClassLoader getNewClassLoader()
  {
    AntCorePreferences corePreferences = getPreferences();
    return getNewClassLoader(false, corePreferences.getURLs());
  }
  
  public URLClassLoader getNewClassLoader(URL[] urls)
  {
    return getNewClassLoader(false, urls);
  }
  
  public ClassLoader getNewClassLoader(boolean allowLoading)
  {
    AntCorePreferences corePreferences = getPreferences();
    URL[] urls = corePreferences.getURLs();
    return getNewClassLoader(allowLoading, urls);
  }
  
  public URLClassLoader getNewClassLoader(boolean allowLoading, URL[] urls)
  {
    AntCorePreferences corePreferences = getPreferences();
    ClassLoader[] pluginLoaders = corePreferences.getPluginClassLoaders();
    AntClassLoader loader = new AntClassLoader(urls, pluginLoaders);
    loader.allowPluginClassLoadersToLoadAnt(allowLoading);
    return loader;
  }
  
  public static void log(Throwable t)
  {
    IStatus status = new Status(4, "org.eclipse.ant.core", 120, "Error logged from Ant Core: ", t);
    getPlugin().getLog().log(status);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ant.core.AntCorePlugin
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ant.core;

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

class AntCorePreferences$1
  implements FilenameFilter
{
  final AntCorePreferences this$0;
  
  AntCorePreferences$1(AntCorePreferences paramAntCorePreferences)
  {
    this$0 = paramAntCorePreferences;
  }
  
  public boolean accept(File dir, String name)
  {
    return name.toLowerCase().endsWith(".jar");
  }
}

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

class AntCorePreferences$Relation
{
  Object from;
  Object to;
  
  AntCorePreferences$Relation(Object from, Object to)
  {
    this.from = from;
    this.to = to;
  }
  
  public String toString()
  {
    return from.toString() + "->" + (to == null ? "" : to.toString());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ant.core.AntCorePreferences.Relation
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ant.core;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import org.osgi.framework.Bundle;

class AntCorePreferences$WrappedClassLoader
  extends ClassLoader
{
  private Bundle bundle;
  final AntCorePreferences this$0;
  
  public AntCorePreferences$WrappedClassLoader(AntCorePreferences paramAntCorePreferences, Bundle bundle)
  {
    this$0 = paramAntCorePreferences;
    this.bundle = bundle;
  }
  
  public Class findClass(String name)
    throws ClassNotFoundException
  {
    return bundle.loadClass(name);
  }
  
  public URL findResource(String name)
  {
    return bundle.getResource(name);
  }
  
  protected Enumeration findResources(String name)
    throws IOException
  {
    return bundle.getResources(name);
  }
  
  public boolean equals(Object obj)
  {
    if (!(obj instanceof WrappedClassLoader)) {
      return false;
    }
    return bundle == bundle;
  }
  
  public int hashCode()
  {
    return bundle.hashCode();
  }
  
  public String toString()
  {
    return "WrappedClassLoader(" + bundle.toString() + ")";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ant.core.AntCorePreferences.WrappedClassLoader
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ant.core;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import org.eclipse.ant.internal.core.AntClasspathEntry;
import org.eclipse.ant.internal.core.AntObject;
import org.eclipse.ant.internal.core.InternalCoreAntMessages;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.variables.IDynamicVariable;
import org.eclipse.core.variables.IStringVariableManager;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
import org.eclipse.osgi.service.resolver.HostSpecification;
import org.eclipse.osgi.service.resolver.PlatformAdmin;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Version;
import org.osgi.service.packageadmin.ExportedPackage;

public class AntCorePreferences
  implements Preferences.IPropertyChangeListener
{
  private List defaultTasks;
  private List defaultTypes;
  private List extraClasspathURLs;
  private List defaultProperties;
  private IAntClasspathEntry[] defaultAntHomeEntries;
  private Task[] customTasks;
  private Task[] oldCustomTasks;
  private Type[] customTypes;
  private Type[] oldCustomTypes;
  private IAntClasspathEntry[] antHomeEntries;
  private IAntClasspathEntry[] additionalEntries;
  private Property[] customProperties;
  private Property[] oldCustomProperties;
  private String[] customPropertyFiles;
  private List pluginClassLoaders;
  private ClassLoader[] orderedPluginClassLoaders;
  private String antHome;
  private boolean runningHeadless = false;
  static Class class$0;
  
  private static class Relation
  {
    Object from;
    Object to;
    
    Relation(Object from, Object to)
    {
      this.from = from;
      this.to = to;
    }
    
    public String toString()
    {
      return from.toString() + "->" + (to == null ? "" : to.toString());
    }
  }
  
  class WrappedClassLoader
    extends ClassLoader
  {
    private Bundle bundle;
    
    public WrappedClassLoader(Bundle bundle)
    {
      this.bundle = bundle;
    }
    
    public Class findClass(String name)
      throws ClassNotFoundException
    {
      return bundle.loadClass(name);
    }
    
    public URL findResource(String name)
    {
      return bundle.getResource(name);
    }
    
    protected Enumeration findResources(String name)
      throws IOException
    {
      return bundle.getResources(name);
    }
    
    public boolean equals(Object obj)
    {
      if (!(obj instanceof WrappedClassLoader)) {
        return false;
      }
      return bundle == bundle;
    }
    
    public int hashCode()
    {
      return bundle.hashCode();
    }
    
    public String toString()
    {
      return "WrappedClassLoader(" + bundle.toString() + ")";
    }
  }
  
  protected AntCorePreferences(List defaultTasks, List defaultExtraClasspath, List defaultTypes, boolean headless)
  {
    this(defaultTasks, defaultExtraClasspath, defaultTypes, Collections.EMPTY_LIST, headless);
  }
  
  protected AntCorePreferences(List defaultTasks, List defaultExtraClasspath, List defaultTypes, List defaultProperties, boolean headless)
  {
    runningHeadless = headless;
    initializePluginClassLoaders();
    extraClasspathURLs = new ArrayList(20);
    this.defaultTasks = computeDefaultTasks(defaultTasks);
    this.defaultTypes = computeDefaultTypes(defaultTypes);
    computeDefaultExtraClasspathEntries(defaultExtraClasspath);
    computeDefaultProperties(defaultProperties);
    restoreCustomObjects();
  }
  
  public void propertyChange(Preferences.PropertyChangeEvent event)
  {
    Preferences prefs = AntCorePlugin.getPlugin().getPluginPreferences();
    String property = event.getProperty();
    if ((property.equals("tasks")) || (property.startsWith("task."))) {
      restoreTasks(prefs);
    } else if ((property.equals("types")) || (property.startsWith("type."))) {
      restoreTypes(prefs);
    } else if (property.equals("ant_home_entries")) {
      restoreAntHomeEntries(prefs);
    } else if (property.equals("additional_entries")) {
      restoreAdditionalEntries(prefs);
    } else if (property.equals("ant_home")) {
      restoreAntHome(prefs);
    } else if ((property.equals("properties")) || (property.startsWith("property."))) {
      restoreCustomProperties(prefs);
    } else if (property.equals("propertyfiles")) {
      restoreCustomPropertyFiles(prefs);
    }
  }
  
  private void restoreCustomObjects()
  {
    Preferences prefs = AntCorePlugin.getPlugin().getPluginPreferences();
    restoreAntHome(prefs);
    restoreTasks(prefs);
    restoreTypes(prefs);
    restoreAntHomeEntries(prefs);
    restoreAdditionalEntries(prefs);
    restoreCustomProperties(prefs);
    restoreCustomPropertyFiles(prefs);
    prefs.addPropertyChangeListener(this);
  }
  
  private void restoreTasks(Preferences prefs)
  {
    String tasks = prefs.getString("tasks");
    if (tasks.equals("")) {
      customTasks = new Task[0];
    } else {
      customTasks = extractTasks(prefs, getArrayFromString(tasks));
    }
  }
  
  private void restoreTypes(Preferences prefs)
  {
    String types = prefs.getString("types");
    if (types.equals("")) {
      customTypes = new Type[0];
    } else {
      customTypes = extractTypes(prefs, getArrayFromString(types));
    }
  }
  
  private void restoreAntHomeEntries(Preferences prefs)
  {
    String entries = prefs.getString("ant_urls");
    if (entries.equals(""))
    {
      entries = prefs.getString("ant_home_entries");
    }
    else
    {
      prefs.setToDefault("ant_urls");
      antHomeEntries = migrateURLEntries(getArrayFromString(entries));
      return;
    }
    if (entries.equals("")) {
      antHomeEntries = getDefaultAntHomeEntries();
    } else {
      antHomeEntries = extractEntries(getArrayFromString(entries));
    }
  }
  
  private void restoreAdditionalEntries(Preferences prefs)
  {
    String entries = prefs.getString("urls");
    if (entries.equals(""))
    {
      entries = prefs.getString("additional_entries");
    }
    else
    {
      prefs.setToDefault("urls");
      additionalEntries = migrateURLEntries(getArrayFromString(entries));
      return;
    }
    if (entries.equals(""))
    {
      IAntClasspathEntry toolsJarEntry = getToolsJarEntry();
      List userLibs = getUserLibraries();
      if (toolsJarEntry == null)
      {
        if (userLibs == null) {
          additionalEntries = new IAntClasspathEntry[0];
        } else {
          additionalEntries = ((IAntClasspathEntry[])userLibs.toArray(new IAntClasspathEntry[userLibs.size()]));
        }
      }
      else if (userLibs == null)
      {
        additionalEntries = new IAntClasspathEntry[] { toolsJarEntry };
      }
      else
      {
        userLibs.add(toolsJarEntry);
        additionalEntries = ((IAntClasspathEntry[])userLibs.toArray(new IAntClasspathEntry[userLibs.size()]));
      }
    }
    else
    {
      additionalEntries = extractEntries(getArrayFromString(entries));
    }
  }
  
  private IAntClasspathEntry[] migrateURLEntries(String[] urlEntries)
  {
    List result = new ArrayList(urlEntries.length);
    for (int i = 0; i < urlEntries.length; i++)
    {
      try
      {
        url = new URL(urlEntries[i]);
      }
      catch (MalformedURLException localMalformedURLException)
      {
        URL url;
        continue;
      }
      URL url;
      result.add(new AntClasspathEntry(url));
    }
    return (IAntClasspathEntry[])result.toArray(new IAntClasspathEntry[result.size()]);
  }
  
  private void restoreAntHome(Preferences prefs)
  {
    antHome = prefs.getString("ant_home");
    if ((antHome == null) || (antHome.length() == 0)) {
      antHome = getDefaultAntHome();
    }
  }
  
  public String getDefaultAntHome()
  {
    IAntClasspathEntry[] entries = getDefaultAntHomeEntries();
    if (entries.length > 0)
    {
      URL antjar = entries[0].getEntryURL();
      IPath antHomePath = new Path(antjar.getFile());
      
      antHomePath = antHomePath.removeLastSegments(2);
      return antHomePath.toFile().getAbsolutePath();
    }
    return null;
  }
  
  private void restoreCustomProperties(Preferences prefs)
  {
    String properties = prefs.getString("properties");
    if (properties.equals("")) {
      customProperties = new Property[0];
    } else {
      customProperties = extractProperties(prefs, getArrayFromString(properties));
    }
  }
  
  private void restoreCustomPropertyFiles(Preferences prefs)
  {
    String propertyFiles = prefs.getString("propertyfiles");
    if (propertyFiles.equals("")) {
      customPropertyFiles = new String[0];
    } else {
      customPropertyFiles = getArrayFromString(propertyFiles);
    }
  }
  
  protected Task[] extractTasks(Preferences prefs, String[] tasks)
  {
    List result = new ArrayList(tasks.length);
    for (int i = 0; i < tasks.length; i++)
    {
      String taskName = tasks[i];
      String[] values = getArrayFromString(prefs.getString("task." + taskName));
      if (values.length >= 2)
      {
        Task task = new Task();
        task.setTaskName(taskName);
        task.setClassName(values[0]);
        String library = values[1];
        if (library.startsWith("file:")) {
          library = library.substring(5);
        }
        task.setLibraryEntry(new AntClasspathEntry(library));
        result.add(task);
      }
    }
    return (Task[])result.toArray(new Task[result.size()]);
  }
  
  protected Type[] extractTypes(Preferences prefs, String[] types)
  {
    List result = new ArrayList(types.length);
    for (int i = 0; i < types.length; i++)
    {
      String typeName = types[i];
      String[] values = getArrayFromString(prefs.getString("type." + typeName));
      if (values.length >= 2)
      {
        Type type = new Type();
        type.setTypeName(typeName);
        type.setClassName(values[0]);
        String library = values[1];
        if (library.startsWith("file:")) {
          library = library.substring(5);
        }
        type.setLibraryEntry(new AntClasspathEntry(library));
        result.add(type);
      }
    }
    return (Type[])result.toArray(new Type[result.size()]);
  }
  
  protected Property[] extractProperties(Preferences prefs, String[] properties)
  {
    Property[] result = new Property[properties.length];
    for (int i = 0; i < properties.length; i++)
    {
      String propertyName = properties[i];
      String[] values = getArrayFromString(prefs.getString("property." + propertyName));
      if (values.length >= 1)
      {
        Property property = new Property();
        property.setName(propertyName);
        property.setValue(values[0]);
        result[i] = property;
      }
    }
    return result;
  }
  
  private IAntClasspathEntry[] extractEntries(String[] entries)
  {
    IAntClasspathEntry[] result = new IAntClasspathEntry[entries.length];
    for (int i = 0; i < entries.length; i++) {
      result[i] = new AntClasspathEntry(entries[i]);
    }
    return result;
  }
  
  /**
   * @deprecated
   */
  public URL[] getDefaultAntURLs()
  {
    IAntClasspathEntry[] entries = getDefaultAntHomeEntries();
    List result = new ArrayList(3);
    for (int i = 0; i < entries.length; i++)
    {
      IAntClasspathEntry entry = entries[i];
      result.add(entry.getEntryURL());
    }
    URL toolsURL = getToolsJarURL();
    if (toolsURL != null) {
      result.add(toolsURL);
    }
    return (URL[])result.toArray(new URL[result.size()]);
  }
  
  /* Error */
  public synchronized IAntClasspathEntry[] getDefaultAntHomeEntries()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 930	org/eclipse/ant/core/AntCorePreferences:defaultAntHomeEntries	[Lorg/eclipse/ant/core/IAntClasspathEntry;
    //   4: ifnonnull +236 -> 240
    //   7: new 556	org/osgi/util/tracker/ServiceTracker
    //   10: dup
    //   11: invokestatic 1002	org/eclipse/ant/core/AntCorePlugin:getPlugin	()Lorg/eclipse/ant/core/AntCorePlugin;
    //   14: invokevirtual 1005	org/eclipse/ant/core/AntCorePlugin:getBundle	()Lorg/osgi/framework/Bundle;
    //   17: invokeinterface 1161 1 0
    //   22: getstatic 919	org/eclipse/ant/core/AntCorePreferences:class$0	Ljava/lang/Class;
    //   25: dup
    //   26: ifnonnull +29 -> 55
    //   29: pop
    //   30: ldc_w 479
    //   33: invokestatic 958	java/lang/Class:forName	(Ljava/lang/String;)Ljava/lang/Class;
    //   36: dup
    //   37: putstatic 919	org/eclipse/ant/core/AntCorePreferences:class$0	Ljava/lang/Class;
    //   40: goto +15 -> 55
    //   43: new 498	java/lang/NoClassDefFoundError
    //   46: dup_x1
    //   47: swap
    //   48: invokevirtual 980	java/lang/Throwable:getMessage	()Ljava/lang/String;
    //   51: invokespecial 961	java/lang/NoClassDefFoundError:<init>	(Ljava/lang/String;)V
    //   54: athrow
    //   55: invokevirtual 957	java/lang/Class:getName	()Ljava/lang/String;
    //   58: aconst_null
    //   59: invokespecial 1116	org/osgi/util/tracker/ServiceTracker:<init>	(Lorg/osgi/framework/BundleContext;Ljava/lang/String;Lorg/osgi/util/tracker/ServiceTrackerCustomizer;)V
    //   62: astore_1
    //   63: aload_1
    //   64: invokevirtual 1114	org/osgi/util/tracker/ServiceTracker:open	()V
    //   67: new 506	java/util/ArrayList
    //   70: dup
    //   71: bipush 29
    //   73: invokespecial 987	java/util/ArrayList:<init>	(I)V
    //   76: astore_2
    //   77: aload_1
    //   78: invokevirtual 1115	org/osgi/util/tracker/ServiceTracker:getService	()Ljava/lang/Object;
    //   81: checkcast 555	org/osgi/service/packageadmin/PackageAdmin
    //   84: astore_3
    //   85: aload_3
    //   86: ifnull +116 -> 202
    //   89: aload_3
    //   90: ldc_w 477
    //   93: invokeinterface 1166 2 0
    //   98: astore 4
    //   100: aload_0
    //   101: aload 4
    //   103: invokevirtual 1048	org/eclipse/ant/core/AntCorePreferences:findHighestAntVersion	([Lorg/osgi/service/packageadmin/ExportedPackage;)Lorg/osgi/framework/Bundle;
    //   106: astore 5
    //   108: aload 5
    //   110: ifnonnull +75 -> 185
    //   113: iconst_0
    //   114: istore 6
    //   116: goto +58 -> 174
    //   119: aload 4
    //   121: iload 6
    //   123: aaload
    //   124: invokeinterface 1165 1 0
    //   129: astore 5
    //   131: aload 5
    //   133: ifnonnull +6 -> 139
    //   136: goto +35 -> 171
    //   139: aload_0
    //   140: aload 5
    //   142: aload_2
    //   143: invokespecial 1038	org/eclipse/ant/core/AntCorePreferences:addLibraries	(Lorg/osgi/framework/Bundle;Ljava/util/List;)V
    //   146: aload_2
    //   147: invokeinterface 1119 1 0
    //   152: ifle +19 -> 171
    //   155: goto +47 -> 202
    //   158: astore 7
    //   160: aload 7
    //   162: invokestatic 1001	org/eclipse/ant/core/AntCorePlugin:log	(Ljava/lang/Throwable;)V
    //   165: aload_2
    //   166: invokeinterface 1120 1 0
    //   171: iinc 6 1
    //   174: iload 6
    //   176: aload 4
    //   178: arraylength
    //   179: if_icmplt -60 -> 119
    //   182: goto +20 -> 202
    //   185: aload_0
    //   186: aload 5
    //   188: aload_2
    //   189: invokespecial 1038	org/eclipse/ant/core/AntCorePreferences:addLibraries	(Lorg/osgi/framework/Bundle;Ljava/util/List;)V
    //   192: goto +10 -> 202
    //   195: astore 6
    //   197: aload 6
    //   199: invokestatic 1001	org/eclipse/ant/core/AntCorePlugin:log	(Ljava/lang/Throwable;)V
    //   202: aload_0
    //   203: aload_2
    //   204: aload_2
    //   205: invokeinterface 1119 1 0
    //   210: anewarray 522	org/eclipse/ant/core/IAntClasspathEntry
    //   213: invokeinterface 1127 2 0
    //   218: checkcast 487	[Lorg/eclipse/ant/core/IAntClasspathEntry;
    //   221: putfield 930	org/eclipse/ant/core/AntCorePreferences:defaultAntHomeEntries	[Lorg/eclipse/ant/core/IAntClasspathEntry;
    //   224: goto +12 -> 236
    //   227: astore 8
    //   229: aload_1
    //   230: invokevirtual 1113	org/osgi/util/tracker/ServiceTracker:close	()V
    //   233: aload 8
    //   235: athrow
    //   236: aload_1
    //   237: invokevirtual 1113	org/osgi/util/tracker/ServiceTracker:close	()V
    //   240: aload_0
    //   241: getfield 930	org/eclipse/ant/core/AntCorePreferences:defaultAntHomeEntries	[Lorg/eclipse/ant/core/IAntClasspathEntry;
    //   244: areturn
    // Line number table:
    //   Java source line #432	-> byte code offset #0
    //   Java source line #433	-> byte code offset #7
    //   Java source line #434	-> byte code offset #63
    //   Java source line #436	-> byte code offset #67
    //   Java source line #437	-> byte code offset #77
    //   Java source line #438	-> byte code offset #85
    //   Java source line #439	-> byte code offset #89
    //   Java source line #440	-> byte code offset #100
    //   Java source line #441	-> byte code offset #108
    //   Java source line #442	-> byte code offset #113
    //   Java source line #443	-> byte code offset #119
    //   Java source line #444	-> byte code offset #131
    //   Java source line #445	-> byte code offset #136
    //   Java source line #448	-> byte code offset #139
    //   Java source line #449	-> byte code offset #146
    //   Java source line #450	-> byte code offset #155
    //   Java source line #453	-> byte code offset #158
    //   Java source line #454	-> byte code offset #160
    //   Java source line #455	-> byte code offset #165
    //   Java source line #442	-> byte code offset #171
    //   Java source line #459	-> byte code offset #182
    //   Java source line #462	-> byte code offset #185
    //   Java source line #463	-> byte code offset #192
    //   Java source line #464	-> byte code offset #197
    //   Java source line #468	-> byte code offset #202
    //   Java source line #469	-> byte code offset #224
    //   Java source line #470	-> byte code offset #229
    //   Java source line #471	-> byte code offset #233
    //   Java source line #470	-> byte code offset #236
    //   Java source line #473	-> byte code offset #240
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	245	0	this	AntCorePreferences
    //   62	175	1	tracker	org.osgi.util.tracker.ServiceTracker
    //   76	129	2	result	List
    //   84	6	3	packageAdmin	org.osgi.service.packageadmin.PackageAdmin
    //   98	79	4	packages	ExportedPackage[]
    //   106	81	5	bundle	Bundle
    //   114	61	6	i	int
    //   195	3	6	ioe	IOException
    //   158	3	7	ioe	IOException
    //   227	7	8	localObject	Object
    //   43	1	10	localClassNotFoundException	ClassNotFoundException
    // Exception table:
    //   from	to	target	type
    //   30	36	43	java/lang/ClassNotFoundException
    //   139	155	158	java/io/IOException
    //   185	192	195	java/io/IOException
    //   67	227	227	finally
  }
  
  Bundle findHighestAntVersion(ExportedPackage[] packages)
  {
    Bundle bundle = null;
    HashSet bundles = new HashSet();
    for (int i = 0; i < packages.length; i++)
    {
      bundle = packages[i].getExportingBundle();
      if (bundle != null) {
        if ("org.apache.ant".equals(bundle.getSymbolicName())) {
          bundles.add(bundle);
        }
      }
    }
    Bundle highest = null;
    Bundle temp = null;
    for (Iterator iter = bundles.iterator(); iter.hasNext();)
    {
      temp = (Bundle)iter.next();
      if (highest == null) {
        highest = temp;
      } else if (highest.getVersion().compareTo(temp.getVersion()) < 0) {
        highest = temp;
      }
    }
    return highest;
  }
  
  /**
   * @deprecated
   */
  public URL[] getAntURLs()
  {
    int extra = 0;
    IAntClasspathEntry entry = getToolsJarEntry();
    if (entry != null) {
      extra++;
    }
    URL[] urls = new URL[antHomeEntries.length + extra];
    for (int i = 0; i < antHomeEntries.length; i++)
    {
      URL url = antHomeEntries[i].getEntryURL();
      if (url != null) {
        urls[i] = url;
      }
    }
    if (entry != null) {
      urls[i] = entry.getEntryURL();
    }
    return urls;
  }
  
  protected List computeDefaultTasks(List tasks)
  {
    List result = new ArrayList(tasks.size());
    for (Iterator iterator = tasks.iterator(); iterator.hasNext();)
    {
      IConfigurationElement element = (IConfigurationElement)iterator.next();
      if (relevantRunningHeadless(element))
      {
        Task task = new Task();
        task.setTaskName(element.getAttribute("name"));
        task.setClassName(element.getAttribute("class"));
        
        configureAntObject(result, element, task, task.getTaskName(), InternalCoreAntMessages.AntCorePreferences_No_library_for_task);
      }
    }
    return result;
  }
  
  private void addURLToExtraClasspathEntries(URL url, IConfigurationElement element)
  {
    String eclipseRuntime = element.getAttribute("eclipseRuntime");
    boolean eclipseRuntimeRequired = true;
    if (eclipseRuntime != null) {
      eclipseRuntimeRequired = Boolean.valueOf(eclipseRuntime).booleanValue();
    }
    Iterator itr = extraClasspathURLs.iterator();
    while (itr.hasNext())
    {
      IAntClasspathEntry entry = (IAntClasspathEntry)itr.next();
      if (entry.getEntryURL().equals(url)) {
        return;
      }
    }
    AntClasspathEntry entry = new AntClasspathEntry(url);
    entry.setEclipseRuntimeRequired(eclipseRuntimeRequired);
    extraClasspathURLs.add(entry);
  }
  
  protected List computeDefaultTypes(List types)
  {
    List result = new ArrayList(types.size());
    for (Iterator iterator = types.iterator(); iterator.hasNext();)
    {
      IConfigurationElement element = (IConfigurationElement)iterator.next();
      if (relevantRunningHeadless(element))
      {
        Type type = new Type();
        type.setTypeName(element.getAttribute("name"));
        type.setClassName(element.getAttribute("class"));
        
        configureAntObject(result, element, type, type.getTypeName(), InternalCoreAntMessages.AntCorePreferences_No_library_for_type);
      }
    }
    return result;
  }
  
  private URL getClasspathEntryURL(Bundle bundle, String library)
    throws IOException
  {
    File urlFile;
    File urlFile;
    if (library.equals("/")) {
      urlFile = FileLocator.getBundleFile(bundle);
    } else {
      urlFile = new File(FileLocator.toFileURL(bundle.getEntry(library)).getPath());
    }
    if (!urlFile.exists()) {
      return null;
    }
    String path = urlFile.getAbsolutePath();
    return new URL("file:" + (urlFile.isDirectory() ? path + "/" : path));
  }
  
  private void configureAntObject(List result, IConfigurationElement element, AntObject antObject, String objectName, String errorMessage)
  {
    String runtime = element.getAttribute("eclipseRuntime");
    if (runtime != null) {
      antObject.setEclipseRuntimeRequired(Boolean.valueOf(runtime).booleanValue());
    }
    String uri = element.getAttribute("uri");
    if (uri != null) {
      antObject.setURI(uri);
    }
    String library = element.getAttribute("library");
    if (library == null)
    {
      IStatus status = new Status(4, "org.eclipse.ant.core", 3, NLS.bind(InternalCoreAntMessages.AntCorePreferences_Library_not_specified_for___0__4, new String[] { objectName }), null);
      AntCorePlugin.getPlugin().getLog().log(status);
      return;
    }
    try
    {
      IContributor contributor = element.getContributor();
      antObject.setPluginLabel(contributor.getName());
      Bundle bundle = Platform.getBundle(contributor.getName());
      URL url = getClasspathEntryURL(bundle, library);
      if (url != null)
      {
        addURLToExtraClasspathEntries(url, element);
        result.add(antObject);
        addPluginClassLoader(bundle);
        antObject.setLibraryEntry(new AntClasspathEntry(url));
        return;
      }
      IStatus status = new Status(4, "org.eclipse.ant.core", 3, NLS.bind(errorMessage, new String[] { library, element.getContributor().getName() }), null);
      AntCorePlugin.getPlugin().getLog().log(status);
      return;
    }
    catch (MalformedURLException e)
    {
      IStatus status = new Status(4, "org.eclipse.ant.core", 2, InternalCoreAntMessages.AntCorePreferences_Malformed_URL__1, e);
      AntCorePlugin.getPlugin().getLog().log(status);
      return;
    }
    catch (Exception localException)
    {
      IStatus status = new Status(4, "org.eclipse.ant.core", 3, NLS.bind(InternalCoreAntMessages.AntCorePreferences_8, new String[] { library, element.getContributor().getName() }), null);
      AntCorePlugin.getPlugin().getLog().log(status);
    }
  }
  
  protected void computeDefaultExtraClasspathEntries(List entries)
  {
    for (Iterator iterator = entries.iterator(); iterator.hasNext();)
    {
      IConfigurationElement element = (IConfigurationElement)iterator.next();
      if (relevantRunningHeadless(element))
      {
        String library = element.getAttribute("library");
        Bundle bundle = Platform.getBundle(element.getContributor().getName());
        try
        {
          URL url = getClasspathEntryURL(bundle, library);
          if (url != null)
          {
            addURLToExtraClasspathEntries(url, element);
            addPluginClassLoader(bundle);
          }
          else
          {
            IStatus status = new Status(4, "org.eclipse.ant.core", 3, NLS.bind(InternalCoreAntMessages.AntCorePreferences_6, new String[] { library, element.getContributor().getName() }), null);
            AntCorePlugin.getPlugin().getLog().log(status);
          }
        }
        catch (MalformedURLException e)
        {
          IStatus status = new Status(4, "org.eclipse.ant.core", 2, InternalCoreAntMessages.AntCorePreferences_Malformed_URL__1, e);
          AntCorePlugin.getPlugin().getLog().log(status);
        }
        catch (Exception localException)
        {
          IStatus status = new Status(4, "org.eclipse.ant.core", 3, NLS.bind(InternalCoreAntMessages.AntCorePreferences_6, new String[] { library, element.getContributor().getName() }), null);
          AntCorePlugin.getPlugin().getLog().log(status);
        }
      }
    }
  }
  
  private boolean relevantRunningHeadless(IConfigurationElement element)
  {
    if (runningHeadless)
    {
      String headless = element.getAttribute("headless");
      if (headless != null)
      {
        boolean headlessProperty = Boolean.valueOf(headless).booleanValue();
        if (!headlessProperty) {
          return false;
        }
      }
    }
    return true;
  }
  
  private void computeDefaultProperties(List properties)
  {
    defaultProperties = new ArrayList(properties.size());
    for (Iterator iterator = properties.iterator(); iterator.hasNext();)
    {
      IConfigurationElement element = (IConfigurationElement)iterator.next();
      if (relevantRunningHeadless(element))
      {
        String name = element.getAttribute("name");
        if (name != null)
        {
          String value = element.getAttribute("value");
          Property property = null;
          if (value != null)
          {
            property = new Property(name, value);
            property.setPluginLabel(element.getContributor().getName());
          }
          else
          {
            Bundle bundle = Platform.getBundle(element.getContributor().getName());
            if (bundle == null) {
              continue;
            }
            property = new Property();
            property.setName(name);
            property.setPluginLabel(element.getContributor().getName());
            String className = element.getAttribute("class");
            property.setValueProvider(className, new WrappedClassLoader(bundle));
          }
          defaultProperties.add(property);
          String runtime = element.getAttribute("eclipseRuntime");
          if (runtime != null) {
            property.setEclipseRuntimeRequired(Boolean.valueOf(runtime).booleanValue());
          }
        }
      }
    }
  }
  
  public IAntClasspathEntry getToolsJarEntry(IPath javaHomePath)
  {
    IPath newjh = javaHomePath;
    if ("jre".equalsIgnoreCase(newjh.lastSegment())) {
      newjh = newjh.removeLastSegments(1);
    }
    newjh = newjh.append("lib").append("tools.jar");
    File tools = newjh.toFile();
    if (!tools.exists())
    {
      newjh = newjh.removeLastSegments(1);
      newjh = newjh.append("classes.zip");
      tools = newjh.toFile();
      if (!tools.exists()) {
        return null;
      }
    }
    return new AntClasspathEntry(tools.getAbsolutePath());
  }
  
  /**
   * @deprecated
   */
  public URL getToolsJarURL()
  {
    IPath path = new Path(System.getProperty("java.home"));
    IAntClasspathEntry entry = getToolsJarEntry(path);
    if (entry == null)
    {
      IDynamicVariable variable = VariablesPlugin.getDefault().getStringVariableManager().getDynamicVariable("env_var");
      String javaHome = null;
      try
      {
        if (variable != null) {
          javaHome = variable.getValue("JAVA_HOME");
        }
        if (javaHome != null)
        {
          path = new Path(javaHome);
          entry = getToolsJarEntry(path);
        }
      }
      catch (CoreException localCoreException) {}
    }
    if (entry != null) {
      return entry.getEntryURL();
    }
    return null;
  }
  
  public IAntClasspathEntry getToolsJarEntry()
  {
    IPath path = new Path(System.getProperty("java.home"));
    IAntClasspathEntry entry = getToolsJarEntry(path);
    if (entry == null)
    {
      IDynamicVariable variable = VariablesPlugin.getDefault().getStringVariableManager().getDynamicVariable("env_var");
      String javaHome = null;
      try
      {
        if (variable != null) {
          javaHome = variable.getValue("JAVA_HOME");
        }
        if (javaHome != null)
        {
          path = new Path(javaHome);
          entry = getToolsJarEntry(path);
        }
      }
      catch (CoreException localCoreException) {}
    }
    return entry;
  }
  
  private List getUserLibraries()
  {
    File libDir = new File(System.getProperty("user.home"), ".ant" + File.separatorChar + "lib");
    URL[] urls = null;
    try
    {
      urls = getLocationURLs(libDir);
    }
    catch (MalformedURLException localMalformedURLException) {}
    if (urls == null) {
      return null;
    }
    List entries = new ArrayList(urls.length);
    for (int i = 0; i < urls.length; i++)
    {
      AntClasspathEntry entry = new AntClasspathEntry(urls[i]);
      entries.add(entry);
    }
    return entries;
  }
  
  private URL[] getLocationURLs(File location)
    throws MalformedURLException
  {
    URL[] urls = null;
    if (!location.exists()) {
      return urls;
    }
    if (!location.isDirectory())
    {
      urls = new URL[1];
      String path = location.getPath();
      if (path.toLowerCase().endsWith(".jar")) {
        urls[0] = location.toURL();
      }
      return urls;
    }
    File[] matches = location.listFiles(
      new FilenameFilter()
      {
        public boolean accept(File dir, String name)
        {
          return name.toLowerCase().endsWith(".jar");
        }
      });
    urls = new URL[matches.length];
    for (int i = 0; i < matches.length; i++) {
      urls[i] = matches[i].toURL();
    }
    return urls;
  }
  
  private void addLibraries(Bundle source, List destination)
    throws IOException, MalformedURLException
  {
    ManifestElement[] libraries = null;
    try
    {
      libraries = ManifestElement.parseHeader("Bundle-ClassPath", (String)source.getHeaders("").get("Bundle-ClassPath"));
    }
    catch (BundleException e)
    {
      IStatus status = new Status(4, "org.eclipse.ant.core", 2, InternalCoreAntMessages.AntCorePreferences_0, e);
      AntCorePlugin.getPlugin().getLog().log(status);
      return;
    }
    if (libraries == null) {
      return;
    }
    URL url = null;
    for (int i = 0; i < libraries.length; i++)
    {
      url = source.getEntry(libraries[i].getValue());
      if (url != null) {
        destination.add(new AntClasspathEntry(FileLocator.toFileURL(url)));
      }
    }
  }
  
  protected void addPluginClassLoader(Bundle bundle)
  {
    WrappedClassLoader loader = new WrappedClassLoader(bundle);
    if (!pluginClassLoaders.contains(loader)) {
      plugi
1 2 3 4

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