org.eclipse.equinox.frameworkadmin.equinox_1.0.300.v20110815-1438

16:43:52.985 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.frameworkadmin.equinox_1.0.300.v20110815-1438.jar
package org.eclipse.equinox.internal.frameworkadmin.equinox;

import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.equinox.internal.frameworkadmin.utils.SimpleBundlesState;
import org.eclipse.equinox.internal.frameworkadmin.utils.Utils;
import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdminRuntimeException;
import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData;
import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator;

public class EclipseLauncherImpl
{
  static String getStringOfCmd(String[] cmdarray)
  {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < cmdarray.length; i++)
    {
      sb.append(cmdarray[i]);
      sb.append(" ");
    }
    return sb.toString();
  }
  
  EquinoxFwAdminImpl fwAdmin = null;
  
  EclipseLauncherImpl(EquinoxFwAdminImpl fwAdmin)
  {
    this.fwAdmin = fwAdmin;
  }
  
  public Process launch(Manipulator manipulator, File cwd)
    throws IllegalArgumentException, IOException, FrameworkAdminRuntimeException
  {
    SimpleBundlesState.checkAvailability(fwAdmin);
    Log.log(4, this, "launch(Manipulator , File )", "");
    LauncherData launcherData = manipulator.getLauncherData();
    if (launcherData.getLauncher() == null) {
      return launchInMemory(manipulator, cwd);
    }
    return launchByLauncher(manipulator, cwd);
  }
  
  private Process launchByLauncher(Manipulator manipulator, File cwd)
    throws IOException
  {
    LauncherData launcherData = manipulator.getLauncherData();
    if (launcherData.getLauncher() == null) {
      throw new IllegalStateException(Messages.exception_launcherLocationNotSet);
    }
    String[] cmdarray = { launcherData.getLauncher().getAbsolutePath() };
    if (cwd == null) {
      cwd = launcherData.getLauncher().getParentFile();
    }
    Process process = Runtime.getRuntime().exec(cmdarray, null, cwd);
    Log.log(4, "\t" + getStringOfCmd(cmdarray));
    return process;
  }
  
  private Process launchInMemory(Manipulator manipulator, File cwd)
    throws IOException
  {
    LauncherData launcherData = manipulator.getLauncherData();
    Utils.checkAbsoluteFile(launcherData.getFwJar(), "fwJar");
    Utils.checkAbsoluteDir(cwd, "cwd");
    
    List cmdList = new LinkedList();
    if (launcherData.getJvm() != null) {
      cmdList.add(launcherData.getJvm().getAbsolutePath());
    } else {
      cmdList.add("java");
    }
    if (launcherData.getJvmArgs() != null) {
      for (int i = 0; i < launcherData.getJvmArgs().length; i++) {
        cmdList.add(launcherData.getJvmArgs()[i]);
      }
    }
    cmdList.add("-jar");
    cmdList.add(Utils.getRelativePath(launcherData.getFwJar(), cwd));
    
    EquinoxManipulatorImpl.checkConsistencyOfFwConfigLocAndFwPersistentDataLoc(launcherData);
    cmdList.add("-configuration");
    cmdList.add(Utils.getRelativePath(launcherData.getFwPersistentDataLocation(), cwd));
    if (launcherData.isClean()) {
      cmdList.add("-clean");
    }
    String[] cmdarray = new String[cmdList.size()];
    cmdList.toArray(cmdarray);
    Log.log(4, "In CWD = " + cwd + "\n\t" + getStringOfCmd(cmdarray));
    Process process = Runtime.getRuntime().exec(cmdarray, null, cwd);
    return process;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.frameworkadmin.equinox.EclipseLauncherImpl
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.frameworkadmin.equinox;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.internal.frameworkadmin.equinox.utils.FileUtils;
import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdminRuntimeException;
import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData;
import org.eclipse.osgi.util.NLS;

public class EclipseLauncherParser
{
  private static final String MAC_OS_APP_FOLDER = ".app/Contents/MacOS";
  private static final String CONFIGURATION_FOLDER = "configuration";
  
  private URI getOSGiInstallArea(List lines, URI base, LauncherData launcherData)
  {
    File osgiInstallArea = ParserUtils.getOSGiInstallArea(lines, null, base);
    if (osgiInstallArea == null) {
      osgiInstallArea = ParserUtils.getOSGiInstallArea(lines, null, launcherData);
    }
    if (osgiInstallArea != null) {
      return URIUtil.makeAbsolute(osgiInstallArea.toURI(), base);
    }
    return null;
  }
  
  private void setInstall(List lines, LauncherData launcherData, File launcherFolder)
  {
    if ((launcherData.getFwConfigLocation() == null) || (launcherData.getFwJar() == null))
    {
      ParserUtils.removeArgument("-install", lines);
      return;
    }
    String launcherString = launcherFolder.getAbsolutePath().replace('\\', '/');
    if (launcherString.endsWith(".app/Contents/MacOS")) {
      launcherFolder = launcherFolder.getParentFile().getParentFile().getParentFile();
    }
    if (!ParserUtils.fromOSGiJarToOSGiInstallArea(launcherData.getFwJar().getAbsolutePath()).equals(launcherFolder)) {
      ParserUtils.setValueForArgument("-install", launcherFolder.getAbsolutePath().replace('\\', '/'), lines);
    }
  }
  
  void read(File launcherConfigFile, LauncherData launcherData)
    throws IOException
  {
    if (!launcherConfigFile.exists()) {
      return;
    }
    List lines = FileUtils.loadFile(launcherConfigFile);
    
    URI launcherFolder = launcherData.getLauncher().getParentFile().toURI();
    getStartup(lines, launcherFolder);
    getFrameworkJar(lines, launcherFolder, launcherData);
    URI osgiInstallArea = getOSGiInstallArea(lines, launcherFolder, launcherData);
    if (osgiInstallArea == null) {
      osgiInstallArea = launcherData.getFwJar() != null ? ParserUtils.fromOSGiJarToOSGiInstallArea(launcherData.getFwJar().getAbsolutePath()).toURI() : launcherFolder;
    }
    URI configArea = getConfigurationLocation(lines, osgiInstallArea, launcherData);
    if (configArea == null) {
      throw new FrameworkAdminRuntimeException(Messages.exception_nullConfigArea, "");
    }
    getPersistentDataLocation(lines, osgiInstallArea, configArea, launcherData);
    getLauncherLibrary(lines, launcherFolder);
    getJVMArgs(lines, launcherData);
    getProgramArgs(lines, launcherData);
    getVM(lines, launcherFolder, launcherData);
    
    Log.log(3, NLS.bind(Messages.log_configFile, launcherConfigFile.getAbsolutePath()));
  }
  
  private void getFrameworkJar(List lines, URI launcherFolder, LauncherData launcherData)
  {
    File fwJar = launcherData.getFwJar();
    if (fwJar != null) {
      return;
    }
    URI location = ParserUtils.getFrameworkJar(lines, launcherFolder);
    if (location != null) {
      launcherData.setFwJar(URIUtil.toFile(location));
    }
  }
  
  private void getPersistentDataLocation(List lines, URI osgiInstallArea, URI configArea, LauncherData launcherData)
  {
    if (launcherData.getFwPersistentDataLocation() == null) {
      launcherData.setFwPersistentDataLocation(URIUtil.toFile(configArea), ParserUtils.isArgumentSet("-clean", lines));
    }
  }
  
  private void getVM(List lines, URI launcherFolder, LauncherData launcherData)
  {
    String vm = ParserUtils.getValueForArgument("-vm", lines);
    if (vm == null) {
      return;
    }
    try
    {
      URI VMFullPath = URIUtil.makeAbsolute(FileUtils.fromPath(vm), launcherFolder);
      launcherData.setJvm(URIUtil.toFile(VMFullPath));
      ParserUtils.setValueForArgument("-vm", VMFullPath.toString(), lines);
    }
    catch (URISyntaxException localURISyntaxException)
    {
      Log.log(1, NLS.bind(Messages.log_failed_make_absolute, vm)); return;
    }
    URI VMFullPath;
  }
  
  private void setVM(List lines, File vm, URI launcherFolder)
  {
    if (vm == null)
    {
      if (ParserUtils.getValueForArgument("-vm", lines) != null) {
        return;
      }
      ParserUtils.removeArgument("-vm", lines);
      return;
    }
    URI vmRelativePath = null;
    if (vm.isAbsolute())
    {
      vmRelativePath = launcherFolder.relativize(vm.toURI());
    }
    else
    {
      String path = vm.getPath().replace('\\', '/');
      try
      {
        vmRelativePath = URIUtil.fromString(path);
      }
      catch (URISyntaxException localURISyntaxException)
      {
        vmRelativePath = launcherFolder.relativize(vm.toURI());
      }
    }
    ParserUtils.setValueForArgument("-vm", FileUtils.toPath(vmRelativePath).replace('\\', '/'), lines);
  }
  
  private void getJVMArgs(List lines, LauncherData launcherData)
  {
    ArrayList vmargs = new ArrayList(lines.size());
    boolean foundVmArgs = false;
    for (Iterator iterator = lines.iterator(); iterator.hasNext();)
    {
      String line = (String)iterator.next();
      if (!foundVmArgs)
      {
        if ("-vmargs".equals(line)) {
          foundVmArgs = true;
        }
      }
      else {
        vmargs.add(line);
      }
    }
    launcherData.setJvmArgs(null);
    launcherData.setJvmArgs((String[])vmargs.toArray(new String[vmargs.size()]));
  }
  
  private void setJVMArgs(List lines, LauncherData launcherData)
  {
    ParserUtils.removeArgument("-vmargs", lines);
    if ((launcherData.getJvmArgs() == null) || (launcherData.getJvmArgs().length == 0)) {
      return;
    }
    String[] args = launcherData.getJvmArgs();
    lines.add("-vmargs");
    for (int i = 0; i < args.length; i++) {
      lines.add(args[i]);
    }
  }
  
  private void getProgramArgs(List lines, LauncherData launcherData)
  {
    ArrayList args = new ArrayList(lines.size());
    for (Iterator iterator = lines.iterator(); iterator.hasNext();)
    {
      String line = (String)iterator.next();
      if ("-vmargs".equals(line)) {
        break;
      }
      args.add(line);
    }
    launcherData.setProgramArgs(null);
    launcherData.setProgramArgs((String[])args.toArray(new String[args.size()]));
  }
  
  private URI getLauncherLibrary(List lines, URI launcherFolder)
  {
    String launcherLibrary = ParserUtils.getValueForArgument("--launcher.library", lines);
    if (launcherLibrary == null) {
      return null;
    }
    URI result = null;
    try
    {
      result = URIUtil.makeAbsolute(FileUtils.fromPath(launcherLibrary), launcherFolder);
      ParserUtils.setValueForArgument("--launcher.library", result.toString(), lines);
    }
    catch (URISyntaxException localURISyntaxException)
    {
      Log.log(1, NLS.bind(Messages.log_failed_make_absolute, launcherLibrary));
      return null;
    }
    return result;
  }
  
  private void setLauncherLibrary(List lines, URI launcherFolder)
  {
    String launcherLibrary = ParserUtils.getValueForArgument("--launcher.library", lines);
    if (launcherLibrary == null) {
      return;
    }
    try
    {
      URI result = URIUtil.makeRelative(FileUtils.fromPath(launcherLibrary), launcherFolder);
      ParserUtils.setValueForArgument("--launcher.library", FileUtils.toPath(result).replace('\\', '/'), lines);
    }
    catch (URISyntaxException localURISyntaxException)
    {
      Log.log(1, NLS.bind(Messages.log_failed_make_absolute, launcherLibrary));
      return;
    }
  }
  
  private URI getConfigurationLocation(List lines, URI osgiInstallArea, LauncherData data)
  {
    String configuration = ParserUtils.getValueForArgument("-configuration", lines);
    if (configuration == null) {
      try
      {
        return URIUtil.makeAbsolute(new URI("configuration"), osgiInstallArea);
      }
      catch (URISyntaxException localURISyntaxException1) {}
    }
    URI result = null;
    try
    {
      result = URIUtil.makeAbsolute(FileUtils.fromPath(configuration), osgiInstallArea);
      ParserUtils.setValueForArgument("-configuration", result.toString(), lines);
      data.setFwConfigLocation(URIUtil.toFile(result));
    }
    catch (URISyntaxException localURISyntaxException2)
    {
      Log.log(1, NLS.bind(Messages.log_failed_make_absolute, configuration));
      return null;
    }
    return result;
  }
  
  private void setConfigurationLocation(List lines, URI osgiInstallArea, LauncherData data)
  {
    String result = FileUtils.toPath(URIUtil.makeRelative(data.getFwConfigLocation().toURI(), osgiInstallArea));
    if ("configuration".equals(result))
    {
      if (ParserUtils.getValueForArgument("-configuration", lines) != null) {
        ParserUtils.removeArgument("-configuration", lines);
      }
      return;
    }
    if (ParserUtils.getValueForArgument("-configuration", lines) == null) {
      ParserUtils.setValueForArgument("-configuration", result.replace('\\', '/'), lines);
    }
  }
  
  private URI getStartup(List lines, URI launcherFolder)
  {
    String startup = ParserUtils.getValueForArgument("-startup", lines);
    if (startup == null) {
      return null;
    }
    URI result = null;
    try
    {
      result = URIUtil.makeAbsolute(FileUtils.fromPath(startup), launcherFolder);
      ParserUtils.setValueForArgument("-startup", result.toString(), lines);
    }
    catch (URISyntaxException localURISyntaxException)
    {
      Log.log(1, NLS.bind(Messages.log_failed_make_absolute, startup));
      return null;
    }
    return result;
  }
  
  private void setStartup(List lines, URI launcherFolder)
  {
    String startup = ParserUtils.getValueForArgument("-startup", lines);
    if (startup == null) {
      return;
    }
    try
    {
      URI result = URIUtil.makeRelative(FileUtils.fromPath(startup), launcherFolder);
      ParserUtils.setValueForArgument("-startup", FileUtils.toPath(result).replace('\\', '/'), lines);
    }
    catch (URISyntaxException localURISyntaxException)
    {
      Log.log(1, NLS.bind(Messages.log_failed_make_relative, startup));
      return;
    }
  }
  
  /* Error */
  void save(EquinoxLauncherData launcherData, boolean backup)
    throws IOException
  {
    // Byte code:
    //   0: aload_1
    //   1: invokestatic 413	org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl:getLauncherConfigLocation	(Lorg/eclipse/equinox/internal/provisional/frameworkadmin/LauncherData;)Ljava/io/File;
    //   4: astore_3
    //   5: aload_3
    //   6: ifnonnull +14 -> 20
    //   9: new 177	java/lang/IllegalStateException
    //   12: dup
    //   13: getstatic 351	org/eclipse/equinox/internal/frameworkadmin/equinox/Messages:exception_launcherLocationNotSet	Ljava/lang/String;
    //   16: invokespecial 374	java/lang/IllegalStateException:<init>	(Ljava/lang/String;)V
    //   19: athrow
    //   20: aload_3
    //   21: invokestatic 427	org/eclipse/equinox/internal/frameworkadmin/utils/Utils:createParentDir	(Ljava/io/File;)Z
    //   24: ifne +14 -> 38
    //   27: new 177	java/lang/IllegalStateException
    //   30: dup
    //   31: getstatic 349	org/eclipse/equinox/internal/frameworkadmin/equinox/Messages:exception_failedToCreateDir	Ljava/lang/String;
    //   34: invokespecial 374	java/lang/IllegalStateException:<init>	(Ljava/lang/String;)V
    //   37: athrow
    //   38: aload_1
    //   39: invokevirtual 408	org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxLauncherData:getLauncher	()Ljava/io/File;
    //   42: invokevirtual 366	java/io/File:getParentFile	()Ljava/io/File;
    //   45: astore 4
    //   47: new 182	java/util/ArrayList
    //   50: dup
    //   51: invokespecial 383	java/util/ArrayList:<init>	()V
    //   54: astore 5
    //   56: aload 5
    //   58: aload_1
    //   59: invokevirtual 411	org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxLauncherData:getProgramArgs	()[Ljava/lang/String;
    //   62: invokestatic 387	java/util/Arrays:asList	([Ljava/lang/Object;)Ljava/util/List;
    //   65: invokeinterface 448 2 0
    //   70: pop
    //   71: aload_0
    //   72: aload 5
    //   74: aload 4
    //   76: invokevirtual 371	java/io/File:toURI	()Ljava/net/URI;
    //   79: invokespecial 393	org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser:setStartup	(Ljava/util/List;Ljava/net/URI;)V
    //   82: aload_0
    //   83: aload 5
    //   85: aload_1
    //   86: aload 4
    //   88: invokespecial 397	org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser:setInstall	(Ljava/util/List;Lorg/eclipse/equinox/internal/provisional/frameworkadmin/LauncherData;Ljava/io/File;)V
    //   91: aload 5
    //   93: aconst_null
    //   94: aload_1
    //   95: invokestatic 423	org/eclipse/equinox/internal/frameworkadmin/equinox/ParserUtils:getOSGiInstallArea	(Ljava/util/List;Ljava/util/Properties;Lorg/eclipse/equinox/internal/provisional/frameworkadmin/LauncherData;)Ljava/io/File;
    //   98: astore 6
    //   100: aload_0
    //   101: aload 5
    //   103: aload 6
    //   105: invokevirtual 371	java/io/File:toURI	()Ljava/net/URI;
    //   108: aload_1
    //   109: invokespecial 403	org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser:setConfigurationLocation	(Ljava/util/List;Ljava/net/URI;Lorg/eclipse/equinox/internal/provisional/frameworkadmin/LauncherData;)V
    //   112: aload_0
    //   113: aload 5
    //   115: aload 4
    //   117: invokevirtual 371	java/io/File:toURI	()Ljava/net/URI;
    //   120: invokespecial 392	org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser:setLauncherLibrary	(Ljava/util/List;Ljava/net/URI;)V
    //   123: aload_0
    //   124: aload 5
    //   126: aload_1
    //   127: invokevirtual 407	org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxLauncherData:getJvm	()Ljava/io/File;
    //   130: aload 4
    //   132: invokevirtual 371	java/io/File:toURI	()Ljava/net/URI;
    //   135: invokespecial 398	org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser:setVM	(Ljava/util/List;Ljava/io/File;Ljava/net/URI;)V
    //   138: aload_1
    //   139: aconst_null
    //   140: invokevirtual 412	org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxLauncherData:setProgramArgs	([Ljava/lang/String;)V
    //   143: aload_1
    //   144: aload 5
    //   146: aload 5
    //   148: invokeinterface 445 1 0
    //   153: anewarray 179	java/lang/String
    //   156: invokeinterface 450 2 0
    //   161: checkcast 172	[Ljava/lang/String;
    //   164: invokevirtual 412	org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxLauncherData:setProgramArgs	([Ljava/lang/String;)V
    //   167: aload_0
    //   168: aload 5
    //   170: aload_1
    //   171: invokespecial 396	org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser:setJVMArgs	(Ljava/util/List;Lorg/eclipse/equinox/internal/provisional/frameworkadmin/LauncherData;)V
    //   174: iload_2
    //   175: ifeq +59 -> 234
    //   178: aload_3
    //   179: invokevirtual 364	java/io/File:exists	()Z
    //   182: ifeq +52 -> 234
    //   185: aload_3
    //   186: invokestatic 428	org/eclipse/equinox/internal/frameworkadmin/utils/Utils:getSimpleDataFormattedFile	(Ljava/io/File;)Ljava/io/File;
    //   189: astore 7
    //   191: aload_3
    //   192: aload 7
    //   194: invokevirtual 367	java/io/File:renameTo	(Ljava/io/File;)Z
    //   197: ifne +20 -> 217
    //   200: new 176	java/io/IOException
    //   203: dup
    //   204: getstatic 350	org/eclipse/equinox/internal/frameworkadmin/equinox/Messages:exception_failedToRename	Ljava/lang/String;
    //   207: aload_3
    //   208: aload 7
    //   210: invokestatic 442	org/eclipse/osgi/util/NLS:bind	(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/String;
    //   213: invokespecial 373	java/io/IOException:<init>	(Ljava/lang/String;)V
    //   216: athrow
    //   217: iconst_3
    //   218: aload_0
    //   219: ldc_w 171
    //   222: getstatic 357	org/eclipse/equinox/internal/frameworkadmin/equinox/Messages:log_renameSuccessful	Ljava/lang/String;
    //   225: aload_3
    //   226: aload 7
    //   228: invokestatic 442	org/eclipse/osgi/util/NLS:bind	(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/String;
    //   231: invokestatic 415	org/eclipse/equinox/internal/frameworkadmin/equinox/Log:log	(ILjava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V
    //   234: aload 5
    //   236: invokeinterface 445 1 0
    //   241: ifle +122 -> 363
    //   244: aconst_null
    //   245: astore 7
    //   247: new 173	java/io/BufferedWriter
    //   250: dup
    //   251: new 175	java/io/FileWriter
    //   254: dup
    //   255: aload_3
    //   256: invokespecial 372	java/io/FileWriter:<init>	(Ljava/io/File;)V
    //   259: invokespecial 361	java/io/BufferedWriter:<init>	(Ljava/io/Writer;)V
    //   262: astore 7
    //   264: iconst_0
    //   265: istore 8
    //   267: goto +40 -> 307
    //   270: aload 5
    //   272: iload 8
    //   274: invokeinterface 446 2 0
    //   279: checkcast 179	java/lang/String
    //   282: astore 9
    //   284: aload 9
    //   286: ifnonnull +6 -> 292
    //   289: goto +15 -> 304
    //   292: aload 7
    //   294: aload 9
    //   296: invokevirtual 362	java/io/BufferedWriter:write	(Ljava/lang/String;)V
    //   299: aload 7
    //   301: invokevirtual 360	java/io/BufferedWriter:newLine	()V
    //   304: iinc 8 1
    //   307: iload 8
    //   309: aload 5
    //   311: invokeinterface 445 1 0
    //   316: if_icmplt -46 -> 270
    //   319: aload 7
    //   321: invokevirtual 359	java/io/BufferedWriter:flush	()V
    //   324: iconst_3
    //   325: getstatic 356	org/eclipse/equinox/internal/frameworkadmin/equinox/Messages:log_launcherConfigSave	Ljava/lang/String;
    //   328: aload_3
    //   329: invokestatic 441	org/eclipse/osgi/util/NLS:bind	(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
    //   332: invokestatic 414	org/eclipse/equinox/internal/frameworkadmin/equinox/Log:log	(ILjava/lang/String;)V
    //   335: goto +18 -> 353
    //   338: astore 10
    //   340: aload 7
    //   342: ifnull +8 -> 350
    //   345: aload 7
    //   347: invokevirtual 358	java/io/BufferedWriter:close	()V
    //   350: aload 10
    //   352: athrow
    //   353: aload 7
    //   355: ifnull +8 -> 363
    //   358: aload 7
    //   360: invokevirtual 358	java/io/BufferedWriter:close	()V
    //   363: aload_1
    //   364: invokevirtual 409	org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxLauncherData:getPreviousLauncherIni	()Ljava/io/File;
    //   367: astore 7
    //   369: aload 7
    //   371: ifnull +18 -> 389
    //   374: aload 7
    //   376: aload_3
    //   377: invokevirtual 368	java/io/File:equals	(Ljava/lang/Object;)Z
    //   380: ifne +9 -> 389
    //   383: aload 7
    //   385: invokevirtual 363	java/io/File:delete	()Z
    //   388: pop
    //   389: aload_1
    //   390: aload_3
    //   391: invokevirtual 410	org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxLauncherData:setLauncherConfigLocation	(Ljava/io/File;)V
    //   394: return
    // Line number table:
    //   Java source line #275	-> byte code offset #0
    //   Java source line #277	-> byte code offset #5
    //   Java source line #278	-> byte code offset #9
    //   Java source line #279	-> byte code offset #20
    //   Java source line #280	-> byte code offset #27
    //   Java source line #283	-> byte code offset #38
    //   Java source line #284	-> byte code offset #47
    //   Java source line #285	-> byte code offset #56
    //   Java source line #287	-> byte code offset #71
    //   Java source line #288	-> byte code offset #82
    //   Java source line #290	-> byte code offset #91
    //   Java source line #292	-> byte code offset #100
    //   Java source line #293	-> byte code offset #112
    //   Java source line #295	-> byte code offset #123
    //   Java source line #298	-> byte code offset #138
    //   Java source line #299	-> byte code offset #143
    //   Java source line #302	-> byte code offset #167
    //   Java source line #305	-> byte code offset #174
    //   Java source line #306	-> byte code offset #178
    //   Java source line #307	-> byte code offset #185
    //   Java source line #308	-> byte code offset #191
    //   Java source line #309	-> byte code offset #200
    //   Java source line #310	-> byte code offset #217
    //   Java source line #314	-> byte code offset #234
    //   Java source line #315	-> byte code offset #244
    //   Java source line #317	-> byte code offset #247
    //   Java source line #318	-> byte code offset #264
    //   Java source line #319	-> byte code offset #270
    //   Java source line #320	-> byte code offset #284
    //   Java source line #321	-> byte code offset #289
    //   Java source line #322	-> byte code offset #292
    //   Java source line #323	-> byte code offset #299
    //   Java source line #318	-> byte code offset #304
    //   Java source line #325	-> byte code offset #319
    //   Java source line #326	-> byte code offset #324
    //   Java source line #327	-> byte code offset #338
    //   Java source line #328	-> byte code offset #340
    //   Java source line #329	-> byte code offset #345
    //   Java source line #330	-> byte code offset #350
    //   Java source line #328	-> byte code offset #353
    //   Java source line #329	-> byte code offset #358
    //   Java source line #332	-> byte code offset #363
    //   Java source line #333	-> byte code offset #369
    //   Java source line #334	-> byte code offset #383
    //   Java source line #335	-> byte code offset #389
    //   Java source line #336	-> byte code offset #394
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	395	0	this	EclipseLauncherParser
    //   0	395	1	launcherData	EquinoxLauncherData
    //   0	395	2	backup	boolean
    //   4	387	3	launcherConfigFile	File
    //   45	86	4	launcherFolder	File
    //   54	256	5	newlines	List
    //   98	6	6	osgiInstallArea	File
    //   189	38	7	dest	File
    //   245	114	7	bw	java.io.BufferedWriter
    //   367	17	7	previousLauncherIni	File
    //   265	43	8	j	int
    //   282	13	9	arg	String
    //   338	13	10	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   247	338	338	finally
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.frameworkadmin.equinox.EclipseLauncherParser
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.frameworkadmin.equinox;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.eclipse.core.runtime.internal.adaptor.EclipseEnvironmentInfo;
import org.eclipse.equinox.frameworkadmin.BundleInfo;
import org.eclipse.equinox.internal.frameworkadmin.equinox.utils.FileUtils;
import org.eclipse.equinox.internal.frameworkadmin.utils.SimpleBundlesState;
import org.eclipse.equinox.internal.frameworkadmin.utils.Utils;
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundlesState;
import org.eclipse.equinox.internal.provisional.frameworkadmin.ConfigData;
import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdminRuntimeException;
import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData;
import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator;
import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
import org.eclipse.osgi.service.resolver.BaseDescription;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
import org.eclipse.osgi.service.resolver.PlatformAdmin;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.osgi.service.resolver.StateHelper;
import org.eclipse.osgi.service.resolver.StateObjectFactory;
import org.eclipse.osgi.service.resolver.VersionConstraint;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Version;

public class EquinoxBundlesState
  implements BundlesState
{
  static final long DEFAULT_TIMESTAMP = 0L;
  private static final boolean DEBUG = false;
  private static final String INTERNAL_AMD64 = "amd64";
  private static final String INTERNAL_ARCH_I386 = "i386";
  public static final String[] PROPS = { "osgi.os", "osgi.ws", "osgi.nl", "osgi.arch", "org.osgi.framework.system.packages", "osgi.resolverMode", "org.osgi.framework.executionenvironment", "osgi.resolveOptional", "osgi.genericAliases" };
  
  static boolean checkFullySupported()
  {
    return true;
  }
  
  static File getFwJar(LauncherData launcherData, ConfigData configData)
  {
    return getFwJar(launcherData, configData, true);
  }
  
  private static File getFwJar(LauncherData launcherData, ConfigData configData, boolean checkBundleInfos)
  {
    if (launcherData.getFwJar() != null) {
      return launcherData.getFwJar();
    }
    String[] jvmArgs = launcherData.getJvmArgs();
    String location = null;
    for (int i = 0; i < jvmArgs.length; i++) {
      if (jvmArgs[i].endsWith("-Dosgi.framework=")) {
        location = jvmArgs[i].substring("-Dosgi.framework=".length());
      }
    }
    if (location != null) {
      return new File(location);
    }
    if (checkBundleInfos)
    {
      File ret = getSystemBundleFromBundleInfos(configData);
      if (ret != null) {
        return ret;
      }
    }
    return null;
  }
  
  private static long getMaxId(State state)
  {
    BundleDescription[] bundleDescriptions = state.getBundles();
    long maxId = 0L;
    for (int i = 0; i < bundleDescriptions.length; i++) {
      if (maxId < bundleDescriptions[i].getBundleId()) {
        maxId = bundleDescriptions[i].getBundleId();
      }
    }
    return maxId;
  }
  
  private static File getSystemBundleFromBundleInfos(BundleInfo[] bundleInfos)
  {
    for (int i = 0; i < bundleInfos.length; i++)
    {
      File match = isSystemBundle(bundleInfos[i]);
      if (match != null) {
        return match;
      }
    }
    return null;
  }
  
  protected static File getSystemBundleFromBundleInfos(ConfigData configData)
  {
    BundleInfo[] bundleInfos = configData.getBundles();
    return getSystemBundleFromBundleInfos(bundleInfos);
  }
  
  static long getTimeStamp(File fwPersistentDataLocation)
  {
    if (fwPersistentDataLocation == null) {
      return 0L;
    }
    File file = new File(fwPersistentDataLocation, "org.eclipse.osgi");
    if ((!file.exists()) || (!file.isDirectory())) {
      return 0L;
    }
    long ret = file.lastModified();
    File[] lists = file.listFiles();
    if (lists == null) {
      return ret;
    }
    for (int i = 0; i < lists.length; i++) {
      if (ret < lists[i].lastModified()) {
        ret = lists[i].lastModified();
      }
    }
    return ret;
  }
  
  public static File isSystemBundle(BundleInfo bundleInfo)
  {
    if ((bundleInfo == null) || (bundleInfo.getLocation() == null)) {
      return null;
    }
    URI bundleLocation = bundleInfo.getLocation();
    try
    {
      String[] clauses = Utils.getClausesManifestMainAttributes(bundleLocation, "Bundle-SymbolicName");
      if ((bundleLocation.getPath().indexOf("org.eclipse.osgi") > 0) && 
        ("org.eclipse.osgi".equals(Utils.getPathFromClause(clauses[0])))) {
        return new File(bundleLocation);
      }
    }
    catch (RuntimeException e)
    {
      e.printStackTrace();
    }
    return null;
  }
  
  static Properties setDefaultPlatformProperties()
  {
    Properties platformProperties = new Properties();
    
    String nl = Locale.getDefault().toString();
    platformProperties.setProperty("osgi.nl", nl);
    
    String os = EclipseEnvironmentInfo.guessOS(System.getProperty("os.name"));
    platformProperties.setProperty("osgi.os", os);
    
    String ws = EclipseEnvironmentInfo.guessWS(os);
    platformProperties.setProperty("osgi.ws", ws);
    
    String arch = null;
    String name = FrameworkProperties.getProperty("os.arch");
    if (name.equalsIgnoreCase("i386")) {
      arch = "x86";
    } else if (name.equalsIgnoreCase("amd64")) {
      arch = "x86_64";
    } else {
      arch = name;
    }
    platformProperties.setProperty("osgi.arch", arch);
    
    platformProperties.setProperty("org.osgi.framework.system.packages", FrameworkProperties.getProperty("org.osgi.framework.system.packages"));
    platformProperties.setProperty("org.osgi.framework.executionenvironment", FrameworkProperties.getProperty("org.osgi.framework.executionenvironment"));
    platformProperties.setProperty("osgi.resolveOptional", "true".equals(FrameworkProperties.getProperty("osgi.resolveOptional")));
    return platformProperties;
  }
  
  EquinoxFwAdminImpl fwAdmin = null;
  BundleContext context;
  Manipulator manipulator = null;
  Properties platfromProperties = new Properties();
  long maxId = 0L;
  StateObjectFactory soFactory = null;
  State state = null;
  private HashMap locationStateIndex = new HashMap();
  private HashMap nameVersionStateIndex = new HashMap();
  private final PlatformAdmin platformAdmin;
  
  EquinoxBundlesState(BundleContext context, EquinoxFwAdminImpl fwAdmin, Manipulator manipulator, PlatformAdmin admin, boolean useFwPersistentData)
  {
    this.context = context;
    this.fwAdmin = fwAdmin;
    platformAdmin = admin;
    
    this.manipulator = fwAdmin.getManipulator();
    this.manipulator.setConfigData(manipulator.getConfigData());
    this.manipulator.setLauncherData(manipulator.getLauncherData());
    initialize(useFwPersistentData);
  }
  
  EquinoxBundlesState(BundleContext context, EquinoxFwAdminImpl fwAdmin, Manipulator manipulator, PlatformAdmin admin, Properties platformProperties)
  {
    this.context = context;
    this.fwAdmin = fwAdmin;
    platformAdmin = admin;
    
    this.manipulator = fwAdmin.getManipulator();
    this.manipulator.setConfigData(manipulator.getConfigData());
    this.manipulator.setLauncherData(manipulator.getLauncherData());
    LauncherData launcherData = manipulator.getLauncherData();
    ConfigData configData = manipulator.getConfigData();
    BundleInfo[] bInfos = configData.getBundles();
    composeNewState(launcherData, configData, platformProperties, bInfos);
  }
  
  private void composeNewState(LauncherData launcherData, ConfigData configData, BundleInfo[] bInfos)
  {
    composeNewState(launcherData, configData, configData.getProperties(), bInfos);
  }
  
  private void composeNewState(LauncherData launcherData, ConfigData configData, Properties properties, BundleInfo[] bInfos)
  {
    File fwJar = getSystemBundleFromBundleInfos(configData);
    launcherData.setFwJar(fwJar);
    setFwJar(fwJar);
    composeState(configData.getBundles(), properties, null);
    resolve(true);
  }
  
  private boolean composeState(BundleInfo[] bInfos, Dictionary props, File fwPersistentDataLocation)
    throws IllegalArgumentException, FrameworkAdminRuntimeException
  {
    BundleInfo[] infos = manipulator.getConfigData().getBundles();
    manipulator.getConfigData().setBundles(null);
    SimpleBundlesState.checkAvailability(fwAdmin);
    setStateObjectFactory();
    state = null;
    boolean flagNewState = false;
    if (fwPersistentDataLocation != null)
    {
      manipulator.getConfigData().setBundles(infos);
      return false;
    }
    state = soFactory.createState(true);
    createStateIndexes();
    flagNewState = true;
    if (props == null)
    {
      manipulator.getConfigData().setBundles(infos);
      return false;
    }
    setPlatformPropertiesToState(props);
    setPlatformProperties(state);
    try
    {
      maxId = state.getHighestBundleId();
    }
    catch (NoSuchMethodError localNoSuchMethodError)
    {
      maxId = getMaxId(state);
    }
    if (flagNewState)
    {
      int indexSystemBundle = -1;
      for (int j = 0; j < bInfos.length; j++) {
        if (isSystemBundle(bInfos[j]) != null)
        {
          indexSystemBundle = j;
          break;
        }
      }
      if (indexSystemBundle > 0)
      {
        BundleInfo[] newBundleInfos = new BundleInfo[bInfos.length];
        newBundleInfos[0] = bInfos[indexSystemBundle];
        System.arraycopy(bInfos, 0, newBundleInfos, 1, indexSystemBundle);
        if (indexSystemBundle < bInfos.length - 1) {
          System.arraycopy(bInfos, indexSystemBundle + 1, newBundleInfos, indexSystemBundle + 1, bInfos.length - indexSystemBundle - 1);
        }
        bInfos = newBundleInfos;
      }
    }
    for (int j = 0; j < bInfos.length; j++) {
      try
      {
        installBundle(bInfos[j]);
      }
      catch (RuntimeException e)
      {
        Log.log(1, this, "composeExpectedState()", "BundleInfo:" + bInfos[j], e);
      }
    }
    return true;
  }
  
  private BundleInfo convertSystemBundle(BundleDescription toConvert)
  {
    boolean markedAsStarted = false;
    int sl = -1;
    
    URI location = null;
    String symbolicNameTarget = toConvert.getSymbolicName();
    Version versionTarget = toConvert.getVersion();
    try
    {
      File fwJar = manipulator.getLauncherData().getFwJar();
      if (fwJar != null)
      {
        URI fwJarLocation = fwJar.toURI();
        String[] clauses = Utils.getClausesManifestMainAttributes(fwJarLocation, "Bundle-SymbolicName");
        String fwJarSymbolicName = Utils.getPathFromClause(clauses[0]);
        String fwJarVersionSt = Utils.getManifestMainAttributes(fwJarLocation, "Bundle-Version");
        if ((fwJarSymbolicName.equals(symbolicNameTarget)) && (fwJarVersionSt.equals(versionTarget.toString())))
        {
          location = fwJarLocation;
          markedAsStarted = true;
        }
      }
    }
    catch (FrameworkAdminRuntimeException e1)
    {
      Log.log(1, "", e1);
    }
    return createBundleInfo(toConvert, markedAsStarted, sl, location, null);
  }
  
  private BundleInfo createBundleInfo(BundleDescription toConvert, boolean markedAsStarted, int sl, URI location, String fragmentHost)
  {
    BundleInfo result = new BundleInfo();
    result.setSymbolicName(toConvert.getSymbolicName());
    result.setVersion(toConvert.getVersion().toString());
    result.setLocation(location);
    result.setResolved(toConvert.isResolved());
    result.setMarkedAsStarted(markedAsStarted);
    result.setStartLevel(sl);
    result.setBundleId(toConvert.getBundleId());
    result.setFragmentHost(fragmentHost);
    return result;
  }
  
  public BundleInfo[] convertState(BundleDescription[] bundles)
  {
    BundleInfo[] originalBInfos = manipulator.getConfigData().getBundles();
    Map bundleInfoMap = new HashMap();
    for (int i = 0; i < originalBInfos.length; i++) {
      bundleInfoMap.put(originalBInfos[i].getLocation(), originalBInfos[i]);
    }
    BundleInfo[] result = new BundleInfo[bundles.length];
    for (int i = 0; i < bundles.length; i++) {
      if ((bundles[i].getBundleId() == 0L) && ("org.eclipse.osgi".equals(bundles[i].getSymbolicName())))
      {
        result[i] = convertSystemBundle(bundles[i]);
      }
      else
      {
        boolean markedAsStarted = false;
        int sl = -1;
        try
        {
          location = new URI(bundles[i].getLocation());
        }
        catch (URISyntaxException e)
        {
          URI location;
          e.printStackTrace();
          throw new IllegalStateException("BundleDescription conversion problem" + e.getMessage());
        }
        URI location;
        String fragmentHost = null;
        BundleInfo original = (BundleInfo)bundleInfoMap.get(location);
        if (original != null)
        {
          markedAsStarted = original.isMarkedAsStarted();
          sl = getStartLevel(original.getStartLevel());
          fragmentHost = original.getFragmentHost();
        }
        result[i] = createBundleInfo(bundles[i], markedAsStarted, sl
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