pdepublishing

16:50:56.369 INFO  jd.cli.Main - Decompiling pdepublishing.jar
package org.eclipse.equinox.internal.p2.publisher.compatibility;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.publisher.Activator;
import org.osgi.service.application.ApplicationDescriptor;
import org.osgi.service.application.ApplicationException;
import org.osgi.service.application.ApplicationHandle;

public class GeneratorApplication
  implements IApplication
{
  protected static final String APP_ID = "app.id";
  public static final String UPDATE_SITE_APPLICATION = "org.eclipse.equinox.p2.publisher.UpdateSitePublisher";
  public static final String INSTALL_APPLICATION = "org.eclipse.equinox.p2.publisher.InstallPublisher";
  public static final String FEATURES_BUNDLES_APPLICATION = "org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher";
  
  public Object start(IApplicationContext context)
    throws Exception
  {
    return run((String[])context.getArguments().get("application.args"));
  }
  
  public void stop() {}
  
  public Object run(String[] arguments)
  {
    Map<String, Object> argumentMap = parseArguments(arguments);
    return launchApplication(argumentMap);
  }
  
  protected Object launchApplication(Map<String, Object> applicationMap)
  {
    String applicationId = (String)applicationMap.get("app.id");
    String filter = "(service.pid=" + applicationId + ")";
    ApplicationDescriptor descriptor = (ApplicationDescriptor)ServiceHelper.getService(Activator.getContext(), ApplicationDescriptor.class.getName(), filter);
    try
    {
      ApplicationHandle handle = descriptor.launch(applicationMap);
      return handle.getExitValue(0L);
    }
    catch (ApplicationException e)
    {
      e.printStackTrace();
    }
    catch (InterruptedException e)
    {
      e.printStackTrace();
    }
    return null;
  }
  
  private Map<String, Object> parseArguments(String[] arguments)
  {
    Map<String, Object> applicationMap = new HashMap();
    Map<String, String> args = new HashMap(arguments.length);
    for (int i = 0; i < arguments.length; i++) {
      if ((i == arguments.length - 1) || (arguments[(i + 1)].startsWith("-"))) {
        args.put(arguments[i], null);
      } else {
        args.put(arguments[i], arguments[(++i)]);
      }
    }
    if (args.containsKey("-ar")) {
      args.put("-artifactRepository", (String)args.remove("-ar"));
    }
    if (args.containsKey("-mr")) {
      args.put("-metadataRepository", (String)args.remove("-mr"));
    }
    if (args.containsKey("-pa")) {
      args.put("-publishArtifacts", (String)args.remove("-pa"));
    }
    if (args.containsKey("-par")) {
      args.put("-publishArtifactRepository", (String)args.remove("-par"));
    }
    if (args.containsKey("-root"))
    {
      String rootId = (String)args.remove("-root");
      args.put("-iu", rootId);
      args.put("-id", rootId);
    }
    if (args.containsKey("-rootVersion")) {
      args.put("-version", (String)args.remove("-rootVersion"));
    }
    String source = null;
    if (args.containsKey("-updateSite")) {
      source = (String)args.remove("-updateSite");
    }
    if (args.containsKey("-inplace")) {
      source = (String)args.remove("-inplace");
    }
    if (source != null)
    {
      args.put("-source", source);
      args.put("-append", null);
      
      String repoLocation = URIUtil.toUnencodedString(new File(source).toURI());
      if (!args.containsKey("-artifactRepository")) {
        args.put("-artifactRepository", repoLocation);
      }
      if (!args.containsKey("-metadataRepository")) {
        args.put("-metadataRepository", repoLocation);
      }
    }
    File base = new File((String)args.get("-source"));
    File configuration = new File(base, "configuration");
    if (configuration.exists()) {
      applicationMap.put("app.id", "org.eclipse.equinox.p2.publisher.InstallPublisher");
    } else if (args.containsKey("-site")) {
      applicationMap.put("app.id", "org.eclipse.equinox.p2.publisher.UpdateSitePublisher");
    } else if (args.containsKey("-config")) {
      applicationMap.put("app.id", "org.eclipse.equinox.p2.publisher.InstallPublisher");
    } else {
      applicationMap.put("app.id", "org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher");
    }
    applicationMap.put("application.args", flattenMap(args));
    return applicationMap;
  }
  
  private String[] flattenMap(Map<String, String> map)
  {
    ArrayList<String> list = new ArrayList(map.size());
    for (Iterator<String> iterator = map.keySet().iterator(); iterator.hasNext();)
    {
      String key = (String)iterator.next();
      String value = (String)map.get(key);
      list.add(key);
      if (value != null) {
        list.add(value);
      }
    }
    return (String[])list.toArray(new String[list.size()]);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.publisher.compatibility.GeneratorApplication
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.publisher.compatibility;

public abstract interface IGeneratorConstants
{
  public static final String DASH = "-";
  public static final String PUBLISH_ARTIFACTS = "-publishArtifacts";
  public static final String PA = "-pa";
  public static final String PUBLISH_ATIFACT_REPOSITORY = "-publishArtifactRepository";
  public static final String PAR = "-par";
  public static final String APPEND = "-append";
  public static final String NO_DEFAULT_IUS = "-noDefaultIUs";
  public static final String COMPRESS = "-compress";
  public static final String REUSE_PACK200 = "-reusePack200Files";
  public static final String SOURCE = "-source";
  public static final String INPLACE = "-inplace";
  public static final String CONFIG = "-config";
  public static final String UPDATE_SITE = "-updateSite";
  public static final String EXE = "-exe";
  public static final String LAUNCHER_CONFIG = "-launcherConfig";
  public static final String METADATA_REPO_NAME = "-metadataRepositoryName";
  public static final String METADATA_REPO = "-metadataRepository";
  public static final String MR = "-mr";
  public static final String ARTIFACT_REPO = "-artifactRepository";
  public static final String AR = "-ar";
  public static final String ARTIFACT_REPO_NAME = "-artifactRepositoryName";
  public static final String FLAVOR = "-flavor";
  public static final String PRODUCT_FILE = "-productFile";
  public static final String FEATURES = "-features";
  public static final String BUNDLES = "-bundles";
  public static final String BASE = "-base";
  public static final String ROOT = "-root";
  public static final String ROOT_VERSION = "-rootVersion";
  public static final String P2_OS = "-p2.os";
  public static final String SITE = "-site";
  public static final String IU = "-iu";
  public static final String ID = "-id";
  public static final String VERSION = "-version";
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.publisher.compatibility.IGeneratorConstants
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.publisher.eclipse;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.pde.internal.swt.tools.IconExe;

public class BrandingIron
{
  private static final String MARKER_NAME = "%EXECUTABLE_NAME%";
  private static final String BUNDLE_NAME = "%BUNDLE_NAME%";
  private static final String ICON_NAME = "%ICON_NAME%";
  private static final String MARKER_KEY = "<key>CFBundleExecutable</key>";
  private static final String BUNDLE_KEY = "<key>CFBundleName</key>";
  private static final String BUNDLE_ID_KEY = "<key>CFBundleIdentifier</key>";
  private static final String BUNDLE_INFO_KEY = "<key>CFBundleGetInfoString</key>";
  private static final String BUNDLE_VERSION_KEY = "<key>CFBundleVersion</key>";
  private static final String BUNDLE_SHORT_VERSION_KEY = "<key>CFBundleShortVersionString</key>";
  private static final String ICON_KEY = "<key>CFBundleIconFile</key>";
  private static final String STRING_START = "<string>";
  private static final String STRING_END = "</string>";
  private static final String XDOC_ICON = "-Xdock:icon=../Resources/Eclipse.icns";
  private static final String XDOC_ICON_PREFIX = "-Xdock:icon=../Resources/";
  private String[] icons = null;
  private String name;
  private String description;
  private String os = "win32";
  private boolean brandIcons = true;
  private String id;
  private Version version;
  
  public void setName(String value)
  {
    name = value;
  }
  
  public void setIcons(String[] value)
  {
    icons = ((value == null) || (value.length == 0) ? null : value);
  }
  
  public void setIcons(String value)
  {
    icons = org.eclipse.equinox.internal.frameworkadmin.utils.Utils.getTokens(value, ",");
    if (icons[0].startsWith("${")) {
      if (icons.length > 1)
      {
        String[] temp = new String[icons.length - 1];
        System.arraycopy(icons, 1, temp, 0, temp.length);
        icons = temp;
      }
      else
      {
        icons = null;
      }
    }
    if (icons != null) {
      for (int i = 0; i < icons.length; i++) {
        icons[i] = icons[i].trim();
      }
    }
  }
  
  public void brand(ExecutablesDescriptor descriptor)
    throws Exception
  {
    if (name.startsWith("${")) {
      return;
    }
    if ((icons == null) || (icons[0].startsWith("${"))) {
      brandIcons = false;
    }
    File root = descriptor.getLocation();
    
    String testName = os.equals("win32") ? name + ".exe" : name;
    if ((!root.exists()) || ((!brandIcons) && (new File(root, testName).exists()))) {
      return;
    }
    try
    {
      root = root.getCanonicalFile();
    }
    catch (IOException localIOException)
    {
      root = root.getAbsoluteFile();
    }
    descriptor.setLocation(root);
    if ("win32".equals(os)) {
      brandWindows(descriptor);
    } else if ("linux".equals(os)) {
      brandLinux(descriptor);
    } else if ("solaris".equals(os)) {
      brandSolaris(descriptor);
    } else if ("macosx".equals(os)) {
      brandMac(descriptor);
    } else if ("aix".equals(os)) {
      brandAIX(descriptor);
    } else if ("hpux".equals(os)) {
      brandHPUX(descriptor);
    } else {
      renameLauncher(descriptor);
    }
    descriptor.setExecutableName(name, true);
  }
  
  private void brandAIX(ExecutablesDescriptor descriptor)
  {
    renameLauncher(descriptor);
  }
  
  private void brandHPUX(ExecutablesDescriptor descriptor)
  {
    renameLauncher(descriptor);
  }
  
  private void brandLinux(ExecutablesDescriptor descriptor)
    throws Exception
  {
    renameLauncher(descriptor);
    if (brandIcons)
    {
      File icon = null;
      if (icons.length > 0) {
        for (int i = 0; i < icons.length; i++) {
          if (icons[i].toLowerCase().endsWith(".xpm"))
          {
            icon = new File(icons[i]);
            break;
          }
        }
      }
      if (icon != null)
      {
        File targetIcon = new File(descriptor.getLocation(), "icon.xpm");
        org.eclipse.pde.internal.publishing.Utils.copy(icon, targetIcon);
        descriptor.addFile(targetIcon);
      }
    }
  }
  
  private void brandSolaris(ExecutablesDescriptor descriptor)
    throws Exception
  {
    renameLauncher(descriptor);
    if (!brandIcons) {
      return;
    }
    File root = descriptor.getLocation();
    for (int i = 0; i < icons.length; i++)
    {
      String icon = icons[i];
      
      int iconNameLength = icon.length();
      if (iconNameLength >= 5)
      {
        String extension = icon.substring(iconNameLength - 5);
        if ((extension.charAt(0) == '.') && (extension.endsWith(".pm")) && ("lmst".indexOf(extension.charAt(1)) >= 0))
        {
          File targetIcon = new File(root, name + extension);
          org.eclipse.pde.internal.publishing.Utils.copy(new File(icon), targetIcon);
          descriptor.addFile(targetIcon);
        }
      }
    }
  }
  
  private void brandMac(ExecutablesDescriptor descriptor)
    throws Exception
  {
    String appName = name;
    if (appName.equals("eclipse")) {
      appName = "Eclipse";
    } else if (appName.equals("launcher")) {
      appName = "Launcher";
    }
    File root = descriptor.getLocation();
    
    File target = new File(root, appName + ".app/Contents");
    target.mkdirs();
    new File(target, "MacOS").mkdirs();
    new File(target, "Resources").mkdirs();
    
    File initialRoot = new File(root, "Launcher.app/Contents");
    if (!initialRoot.exists()) {
      initialRoot = new File(root, "launcher.app/Contents");
    }
    if (!initialRoot.exists()) {
      initialRoot = new File(root, "Eclipse.app/Contents");
    }
    if (!initialRoot.exists()) {
      initialRoot = new File(root, "eclipse.app/Contents");
    }
    if (!initialRoot.exists()) {
      throw new FileNotFoundException("cannot find launcher root (Eclipse.app or Launcher.app)");
    }
    initialRoot = initialRoot.getCanonicalFile();
    copyMacLauncher(descriptor, initialRoot, target);
    String iconName = "";
    if (brandIcons)
    {
      File icon = null;
      for (int i = 0; i < icons.length; i++) {
        if (icons[i].toLowerCase().endsWith(".icns"))
        {
          icon = new File(icons[i]);
          if (icon.exists()) {
            break;
          }
        }
      }
      if (icon != null)
      {
        iconName = icon.getName();
        File initialIcon = new File(initialRoot, "Resources/Eclipse.icns");
        try
        {
          initialIcon = initialIcon.getCanonicalFile();
        }
        catch (IOException localIOException) {}
        File targetIcon = new File(target, "Resources/" + iconName);
        
        initialIcon.delete();
        descriptor.removeFile(initialIcon);
        org.eclipse.pde.internal.publishing.Utils.copy(icon, targetIcon);
        descriptor.addFile(targetIcon);
      }
    }
    copyMacIni(descriptor, initialRoot, target, iconName);
    modifyInfoPListFile(descriptor, initialRoot, target, iconName);
    File splashApp = new File(initialRoot, "Resources/Splash.app");
    if (splashApp.exists()) {
      brandMacSplash(descriptor, initialRoot, target, iconName);
    }
    moveContents(descriptor, initialRoot, target);
    initialRoot.getParentFile().delete();
  }
  
  private void brandMacSplash(ExecutablesDescriptor descriptor, File initialRoot, File target, String iconName)
  {
    String splashContents = "Resources/Splash.app/Contents";
    modifyInfoPListFile(descriptor, new File(initialRoot, splashContents), new File(target, splashContents), iconName);
    
    String splashMacOS = splashContents + "/MacOS";
    File macOSDir = new File(target, "MacOS");
    File splashMacOSDir = new File(target, splashMacOS);
    
    splashMacOSDir.mkdirs();
    
    File targetLauncher = new File(splashMacOSDir, name);
    
    int result = -1;
    String osName = System.getProperty("os.name");
    if ((osName != null) && (!osName.startsWith("Windows"))) {
      try
      {
        String[] command = { "ln", "-sf", "../../../MacOS/" + name, name };
        Process proc = Runtime.getRuntime().exec(command, null, splashMacOSDir);
        result = proc.waitFor();
      }
      catch (IOException localIOException1) {}catch (InterruptedException localInterruptedException) {}
    }
    if (result != 0) {
      try
      {
        org.eclipse.pde.internal.publishing.Utils.copy(new File(macOSDir, name), targetLauncher);
        try
        {
          Runtime.getRuntime().exec(new String[] { "chmod", "755", targetLauncher.getAbsolutePath() });
        }
        catch (IOException localIOException2) {}
        initialLauncher = findLauncher(new File(initialRoot, splashMacOS));
      }
      catch (IOException localIOException3)
      {
        System.out.println("Could not copy macosx splash launcher");
      }
    }
    File initialLauncher;
    if (initialLauncher != null)
    {
      try
      {
        if (!initialLauncher.getCanonicalFile().equals(targetLauncher.getCanonicalFile())) {
          initialLauncher.delete();
        }
      }
      catch (IOException localIOException4) {}
      descriptor.removeFile(initialLauncher);
    }
    descriptor.addFile(targetLauncher);
  }
  
  private File findLauncher(File root)
  {
    String[] arrayOfString;
    int j = (arrayOfString = new String[] { "launcher", "eclipse" }).length;
    for (int i = 0; i < j; i++)
    {
      String launcherName = arrayOfString[i];
      File launcher = new File(root, launcherName);
      if (launcher.exists()) {
        return launcher;
      }
    }
    return null;
  }
  
  private void moveContents(ExecutablesDescriptor descriptor, File source, File target)
  {
    if (!source.exists()) {
      return;
    }
    try
    {
      source = source.getCanonicalFile();
      target = target.getCanonicalFile();
    }
    catch (IOException localIOException)
    {
      System.out.println("Could not copy macosx resources.");
      return;
    }
    if (source.equals(target)) {
      return;
    }
    target.getParentFile().mkdirs();
    if (source.isDirectory())
    {
      target.mkdirs();
      File[] contents = source.listFiles();
      for (int i = 0; i < contents.length; i++)
      {
        File dest = new File(target, contents[i].getName());
        if (contents[i].isFile())
        {
          contents[i].renameTo(dest);
          descriptor.replace(contents[i], dest);
        }
        else
        {
          moveContents(descriptor, contents[i], dest);
        }
      }
      source.delete();
    }
    else
    {
      source.renameTo(target);
      descriptor.replace(source, target);
    }
  }
  
  private void brandWindows(ExecutablesDescriptor descriptor)
    throws Exception
  {
    File root = descriptor.getLocation();
    File templateLauncher = new File(root, name + ".exe");
    if (!templateLauncher.exists()) {
      templateLauncher = new File(root, "launcher.exe");
    }
    if (!templateLauncher.exists()) {
      templateLauncher = new File(root, "eclipse.exe");
    }
    if (brandIcons) {
      if (templateLauncher.exists())
      {
        String[] args = new String[icons.length + 1];
        args[0] = templateLauncher.getAbsolutePath();
        System.arraycopy(icons, 0, args, 1, icons.length);
        IconExe.main(args);
      }
      else
      {
        System.out.println("Could not find executable to brand");
      }
    }
    File targetLauncher = new File(root, name + ".exe");
    if ((templateLauncher.exists()) && (!templateLauncher.getName().equals(name + ".exe")))
    {
      templateLauncher.renameTo(targetLauncher);
      descriptor.replace(templateLauncher, targetLauncher);
    }
    descriptor.setExecutableName(name, true);
  }
  
  private void renameLauncher(ExecutablesDescriptor descriptor)
  {
    File root = descriptor.getLocation();
    File launcher = findLauncher(root);
    if (launcher == null) {
      return;
    }
    File targetLauncher = new File(root, name);
    launcher.renameTo(targetLauncher);
    descriptor.replace(launcher, targetLauncher);
    descriptor.setExecutableName(name, true);
  }
  
  private void copyMacLauncher(ExecutablesDescriptor descriptor, File initialRoot, File target)
  {
    File launcher = getCanonicalFile(new File(initialRoot, "MacOS/launcher"));
    File eclipseLauncher = getCanonicalFile(new File(initialRoot, "MacOS/eclipse"));
    File targetFile = getCanonicalFile(new File(target, "MacOS/" + name));
    if (!launcher.exists())
    {
      launcher = eclipseLauncher;
    }
    else if ((eclipseLauncher.exists()) && (!targetFile.equals(eclipseLauncher)))
    {
      eclipseLauncher.delete();
      descriptor.removeFile(eclipseLauncher);
    }
    if (!targetFile.equals(launcher))
    {
      try
      {
        org.eclipse.pde.internal.publishing.Utils.copy(launcher, targetFile);
      }
      catch (IOException localIOException1)
      {
        System.out.println("Could not copy macosx launcher");
        return;
      }
      launcher.delete();
      launcher.getParentFile().delete();
      descriptor.replace(launcher, targetFile);
    }
    try
    {
      Runtime.getRuntime().exec(new String[] { "chmod", "755", targetFile.getAbsolutePath() });
    }
    catch (IOException localIOException2) {}
    descriptor.setExecutableName(name, false);
  }
  
  private File getCanonicalFile(File file)
  {
    try
    {
      return file.getCanonicalFile();
    }
    catch (IOException localIOException) {}
    return file;
  }
  
  private void copyMacIni(ExecutablesDescriptor descriptor, File initialRoot, File target, String iconName)
  {
    String brandedIniName = "MacOS/" + name + ".ini";
    
    File targetFile = getCanonicalFile(new File(target, brandedIniName));
    File brandedIni = getCanonicalFile(new File(initialRoot, brandedIniName));
    File ini = getCanonicalFile(new File(initialRoot, "MacOS/eclipse.ini"));
    File ini2 = getCanonicalFile(new File(initialRoot, "MacOS/Eclipse.ini"));
    if (targetFile.exists())
    {
      if ((brandedIni.exists()) && (!brandedIni.equals(targetFile)))
      {
        brandedIni.delete();
        descriptor.removeFile(brandedIni);
      }
      if ((ini.exists()) && (!ini.equals(targetFile)))
      {
        ini.delete();
        descriptor.removeFile(ini);
      }
      if ((ini2.exists()) && (!ini2.equals(targetFile)))
      {
        ini2.delete();
        descriptor.removeFile(ini2);
      }
      ini = targetFile;
    }
    else if (brandedIni.exists())
    {
      if ((ini.exists()) && (!ini.equals(brandedIni)))
      {
        ini.delete();
        descriptor.removeFile(ini);
      }
      if ((ini2.exists()) && (!ini2.equals(brandedIni)))
      {
        ini2.delete();
        descriptor.removeFile(ini2);
      }
      ini = brandedIni;
    }
    else if (ini.exists())
    {
      if ((ini2.exists()) && (!ini2.equals(ini)))
      {
        System.out.printf("Found both %s and %s - discarding the latter", new Object[] { ini.getAbsolutePath(), ini2.getAbsolutePath() });
        ini2.delete();
        descriptor.removeFile(ini2);
      }
    }
    else if (ini2.exists())
    {
      ini = ini2;
    }
    else
    {
      return;
    }
    try
    {
      buffer = readFile(ini);
    }
    catch (IOException localIOException1)
    {
      StringBuffer buffer;
      System.out.println("Impossible to brand ini file"); return;
    }
    StringBuffer buffer;
    if (iconName.length() > 0)
    {
      int xdoc = scan(buffer, 0, "-Xdock:icon=../Resources/Eclipse.icns");
      if (xdoc != -1)
      {
        String icns = "-Xdock:icon=../Resources/" + iconName;
        buffer.replace(xdoc, xdoc + "-Xdock:icon=../Resources/Eclipse.icns".length(), icns);
      }
    }
    try
    {
      transferStreams(new ByteArrayInputStream(buffer.toString().getBytes()), new FileOutputStream(targetFile));
      if (!ini.equals(targetFile))
      {
        ini.delete();
        descriptor.replace(ini, targetFile);
      }
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      System.out.println("Impossible to brand ini file");
      return;
    }
    catch (IOException localIOException2)
    {
      System.out.println("Impossible to brand ini file");
      return;
    }
  }
  
  private void modifyInfoPListFile(ExecutablesDescriptor descriptor, File initialRoot, File targetRoot, String iconName)
  {
    File infoPList = new File(initialRoot, "Info.plist");
    try
    {
      buffer = readFile(infoPList);
    }
    catch (IOException localIOException1)
    {
      StringBuffer buffer;
      System.out.println("Impossible to brand info.plist file"); return;
    }
    StringBuffer buffer;
    int exePos = scan(buffer, 0, "%EXECUTABLE_NAME%");
    if (exePos != -1) {
      buffer.replace(exePos, exePos + "%EXECUTABLE_NAME%".length(), name);
    } else {
      replacePlistValue(buffer, "<key>CFBundleExecutable</key>", name);
    }
    int bundlePos = scan(buffer, 0, "%BUNDLE_NAME%");
    if (bundlePos != -1) {
      buffer.replace(bundlePos, bundlePos + "%BUNDLE_NAME%".length(), name);
    } else {
      replacePlistValue(buffer, "<key>CFBundleName</key>", name);
    }
    replacePlistValue(buffer, "<key>CFBundleIdentifier</key>", id);
    replacePlistValue(buffer, "<key>CFBundleGetInfoString</key>", description);
    if (version != null)
    {
      StringBuffer sv = new StringBuffer(version.getSegment(0).toString());
      sv.append('.');
      sv.append(version.getSegmentCount() > 1 ? version.getSegment(1).toString() : "0");
      sv.append('.');
      sv.append(version.getSegmentCount() > 2 ? version.getSegment(2).toString() : "0");
      replacePlistValue(buffer, "<key>CFBundleVersion</key>", version.toString());
      replacePlistValue(buffer, "<key>CFBundleShortVersionString</key>", sv.toString());
    }
    int iconPos = scan(buffer, 0, "%ICON_NAME%");
    if (iconPos != -1) {
      buffer.replace(iconPos, iconPos + "%ICON_NAME%".length(), iconName);
    } else {
      replacePlistValue(buffer, "<key>CFBundleIconFile</key>", iconName);
    }
    File target = new File(targetRoot, "Info.plist");
    try
    {
      target.getParentFile().mkdirs();
      transferStreams(new ByteArrayInputStream(buffer.toString().getBytes()), new FileOutputStream(target));
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      System.out.println("Impossible to brand info.plist file");
      return;
    }
    catch (IOException localIOException2)
    {
      System.out.println("Impossible to brand info.plist file");
      return;
    }
    try
    {
      if (!infoPList.getCanonicalFile().equals(target.getCanonicalFile())) {
        infoPList.delete();
      }
    }
    catch (IOException localIOException3) {}
    descriptor.replace(infoPList, target);
  }
  
  private void replacePlistValue(StringBuffer buffer, String key, String value)
  {
    if (value == null) {
      return;
    }
    int exePos = scan(buffer, 0, key);
    if (exePos != -1)
    {
      int start = scan(buffer, exePos + key.length(), "<string>");
      int end = scan(buffer, start + "<string>".length(), "</string>");
      if ((start > -1) && (end > start)) {
        buffer.replace(start + "<string>".length(), end, value);
      }
    }
  }
  
  private int scan(StringBuffer buf, int start, String targetName)
  {
    return scan(buf, start, new String[] { targetName });
  }
  
  private int scan(StringBuffer buf, int start, String[] targets)
  {
    for (int i = start; i < buf.length(); i++) {
      for (int j = 0; j < targets.length; j++) {
        if (i < buf.length() - targets[j].length())
        {
          String match = buf.substring(i, i + targets[j].length());
          if (targets[j].equalsIgnoreCase(match)) {
            return i;
          }
        }
      }
    }
    return -1;
  }
  
  /* Error */
  private StringBuffer readFile(File targetName)
    throws IOException
  {
    // Byte code:
    //   0: new 347	java/io/InputStreamReader
    //   3: dup
    //   4: new 338	java/io/BufferedInputStream
    //   7: dup
    //   8: new 342	java/io/FileInputStream
    //   11: dup
    //   12: aload_1
    //   13: invokespecial 527	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   16: invokespecial 509	java/io/BufferedInputStream:<init>	(Ljava/io/InputStream;)V
    //   19: invokespecial 534	java/io/InputStreamReader:<init>	(Ljava/io/InputStream;)V
    //   22: astore_2
    //   23: new 356	java/lang/StringBuffer
    //   26: dup
    //   27: invokespecial 558	java/lang/StringBuffer:<init>	()V
    //   30: astore_3
    //   31: sipush 4096
    //   34: newarray <illegal type>
    //   36: astore 4
    //   38: aload_2
    //   39: aload 4
    //   41: iconst_0
    //   42: aload 4
    //   44: arraylength
    //   45: invokevirtual 533	java/io/InputStreamReader:read	([CII)I
    //   48: istore 5
    //   50: goto +25 -> 75
    //   53: aload_3
    //   54: aload 4
    //   56: iconst_0
    //   57: iload 5
    //   59: invokevirtual 563	java/lang/StringBuffer:append	([CII)Ljava/lang/StringBuffer;
    //   62: pop
    //   63: aload_2
    //   64: aload 4
    //   66: iconst_0
    //   67: aload 4
    //   69: arraylength
    //   70: invokevirtual 533	java/io/InputStreamReader:read	([CII)I
    //   73: istore 5
    //   75: iload 5
    //   77: iconst_m1
    //   78: if_icmpne -25 -> 53
    //   81: goto +16 -> 97
    //   84: astore 6
    //   86: aload_2
    //   87: invokevirtual 532	java/io/InputStreamReader:close	()V
    //   90: goto +4 -> 94
    //   93: pop
    //   94: aload 6
    //   96: athrow
    //   97: aload_2
    //   98: invokevirtual 532	java/io/InputStreamReader:close	()V
    //   101: goto +4 -> 105
    //   104: pop
    //   105: aload_3
    //   106: areturn
    // Line number table:
    //   Java source line #596	-> byte code offset #0
    //   Java source line #597	-> byte code offset #23
    //   Java source line #598	-> byte code offset #31
    //   Java source line #601	-> byte code offset #38
    //   Java source line #602	-> byte code offset #50
    //   Java source line #603	-> byte code offset #53
    //   Java source line #604	-> byte code offset #63
    //   Java source line #602	-> byte code offset #75
    //   Java source line #606	-> byte code offset #84
    //   Java source line #608	-> byte code offset #86
    //   Java source line #609	-> byte code offset #93
    //   Java source line #612	-> byte code offset #94
    //   Java source line #608	-> byte code offset #97
    //   Java source line #609	-> byte code offset #104
    //   Java source line #613	-> byte code offset #105
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	107	0	this	BrandingIron
    //   0	107	1	targetName	File
    //   22	76	2	reader	java.io.InputStreamReader
    //   30	76	3	result	StringBuffer
    //   36	32	4	buf	char[]
    //   48	28	5	count	int
    //   97	1	5	count	int
    //   105	1	5	count	int
    //   84	11	6	localObject	Object
    //   93	1	9	localIOException1	IOException
    //   104	1	10	localIOException2	IOException
    // Exception table:
    //   from	to	target	type
    //   38	84	84	finally
    //   86	90	93	java/io/IOException
    //   97	101	104	java/io/IOException
  }
  
  /* Error */
  private void transferStreams(java.io.InputStream source, java.io.OutputStream destination)
    throws IOException
  {
    // Byte code:
    //   0: new 338	java/io/BufferedInputStream
    //   3: dup
    //   4: aload_1
    //   5: invokespecial 509	java/io/BufferedInputStream:<init>	(Ljava/io/InputStream;)V
    //   8: astore_1
    //   9: new 339	java/io/BufferedOutputStream
    //   12: dup
    //   13: aload_2
    //   14: invokespecial 510	java/io/BufferedOutputStream:<init>	(Ljava/io/OutputStream;)V
    //   17: astore_2
    //   18: sipush 8192
    //   21: newarray <illegal type>
    //   23: astore_3
    //   24: iconst_m1
    //   25: istore 4
    //   27: aload_1
    //   28: aload_3
    //   29: invokevirtual 531	java/io/InputStream:read	([B)I
    //   32: dup
    //   33: istore 4
    //   35: iconst_m1
    //   36: if_icmpne +6 -> 42
    //   39: goto +35 -> 74
    //   42: aload_2
    //   43: aload_3
    //   44: iconst_0
    //   45: iload 4
    //   47: invokevirtual 536	java/io/OutputStream:write	([BII)V
    //   50: goto -26 -> 24
    //   53: astore 5
    //   55: aload_1
    //   56: invokevirtual 530	java/io/InputStream:close	()V
    //   59: goto +4 -> 63
    //   62: pop
    //   63: aload_2
    //   64: invokevirtual 535	java/io/OutputStream:close	()V
    //   67: goto +4 -> 71
    //   70: pop
    //   71: aload 5
    //   73: athrow
    //   74: aload_1
    //   75: invokevirtual 530	java/io/InputStream:close	()V
    //   78: goto +4 -> 82
    //   81: pop
    //   82: aload_2
    //   83: invokevirtual 535	java/io/OutputStream:close	()V
    //   86: goto +4 -> 90
    //   89: pop
    //   90: return
    // Line number table:
    //   Java source line #617	-> byte code offset #0
    //   Java source line #618	-> byte code offset #9
    //   Java source line #620	-> byte code offset #18
    //   Java source line #622	-> byte code offset #24
    //   Java source line #623	-> byte code offset #27
    //   Java source line #624	-> byte code offset #39
    //   Java source line #625	-> byte code offset #42
    //   Java source line #621	-> byte code offset #50
    //   Java source line #627	-> byte code offset #53
    //   Java source line #629	-> byte code offset #55
    //   Java source line #630	-> byte code offset #62
    //   Java source line #634	-> byte code offset #63
    //   Java source line #635	-> byte code offset #70
    //   Java source line #638	-> byte code offset #71
    //   Java source line #629	-> byte code offset #74
    //   Java source line #630	-> byte code offset #81
    //   Java source line #634	-> byte code offset #82
    //   Java source line #635	-> byte code offset #89
    //   Java source line #639	-> byte code offset #90
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	91	0	this	BrandingIron
    //   0	91	1	source	java.io.InputStream
    //   0	91	2	destination	java.io.OutputStream
    //   23	21	3	buffer	byte[]
    //   25	21	4	bytesRead	int
    //   53	19	5	localObject	Object
    //   62	1	6	localIOException1	IOException
    //   70	1	7	localIOException2	IOException
    //   81	1	8	localIOException3	IOException
    //   89	1	9	localIOException4	IOException
    // Exception table:
    //   from	to	target	type
    //   18	53	53	finally
    //   55	59	62	java/io/IOException
    //   63	67	70	java/io/IOException
    //   74	78	81	java/io/IOException
    //   82	86	89	java/io/IOException
  }
  
  public void setOS(String value)
  {
    os = value;
  }
  
  public void setId(String id)
  {
    this.id = id;
  }
  
  public void setVersion(Version version)
  {
    this.version = version;
  }
  
  public void setDescription(String description)
  {
    this.description = description;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.publisher.eclipse.BrandingIron
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.publisher.eclipse;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.frameworkadmin.BundleInfo;
import org.eclipse.equinox.internal.frameworkadmin.equinox.EquinoxFwConfigFileParser;
import org.eclipse.equinox.internal.frameworkadmin.equinox.EquinoxManipulatorImpl;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.provisional.frameworkadmin.ConfigData;
import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdmin;
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.equinox.simpleconfigurator.manipulator.SimpleConfiguratorManipulator;
import org.eclipse.pde.internal.publishing.Activator;

public class DataLoader
{
  private static final String FILTER_OBJECTCLASS = "(objectClass=" + FrameworkAdmin.class.getName() + ")";
  private static final String filterFwName = "(org.eclipse.equinox.frameworkhandler.framework.name=Equinox)";
  private static final String filterLauncherName = "(org.eclipse.equinox.frameworkhandler.launcher.name=Eclipse.exe)";
  private static final String frameworkAdminFillter = "(&" + FILTER_OBJECTCLASS + "(org.eclipse.equinox.frameworkhandler.framework.name=Equinox)" + "(org.eclipse.equinox.frameworkhandler.launcher.name=Eclipse.exe)" + ")";
  private static final String ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL = "org.eclipse.equinox.simpleconfigurator.configUrl";
  private Manipulator manipulator;
  private final File configurationLocation;
  
  public DataLoader(File configurationLocation, File executableLocation)
  {
    this.configurationLocation = configurationLocation;
    initializeFrameworkManipulator(configurationLocation.getParentFile(), executableLocation);
  }
  
  private void initializeFrameworkManipulator(File config, File executable)
  {
    getFrameworkManipulator();
    
    LauncherData launcherData = manipulator.getLauncherData();
    launcherData.setFwPersistentDataLocation(config, true);
    launcherData.setLauncher(executable);
    if (executable == null) {
      launcherData.setHome(config.getParentFile());
    }
    try
    {
      manipulator.load();
    }
    catch (IllegalStateException e2)
    {
      e2.printStackTrace();
    }
    catch (FrameworkAdminRuntimeException e2)
    {
      e2.printStackTrace();
    }
    catch (IOException e2)
    {
      e2.printStackTrace();
    }
  }
  
  public ConfigData getConfigData()
  {
    if (manipulator == null) {
      return null;
    }
    EquinoxFwConfigFileParser parser = new EquinoxFwConfigFileParser(Activator.getContext());
    try
    {
      if ((configurationLocation != null) && (configurationLocation.exists())) {
        parser.readFwConfig(manipulator, configurationLocation);
      }
    }
    catch (IOException e)
    {
      LogHelper.log(new Status(4, Activator.ID, "Error loading config.", e));
    }
    catch (URISyntaxException e)
    {
      LogHelper.log(new Status(4, Activator.ID, "Error loading config.", e));
    }
    ConfigData data = manipulator.getConfigData();
    String value = data.getProperty("org.eclipse.equinox.simpleconfigurator.configUrl");
    if (value != null)
    {
      try
      {
        SimpleConfiguratorManipulator simpleManipulator = (SimpleConfiguratorManipulator)ServiceHelper.getService(Activator.getContext(), SimpleConfiguratorManipulator.class.getName());
        
        BundleInfo[] bundleInfos = simpleManipulator.loadConfiguration(new URL(value).openStream(), null);
        data.setBundles(bundleInfos);
      }
      catch (MalformedURLException localMalformedURLException1) {}catch (IOException localIOException1) {}
      try
      {
        data.setProperty("org.eclipse.equinox.simpleconfigurator.configUrl", EquinoxManipulatorImpl.makeRelative(value, configurationLocation.toURL()));
      }
      catch (MalformedURLException localMalformedURLException2) {}
    }
    return data;
  }
  
  public LauncherData getLauncherData()
  {
    return manipulator == null ? null : manipulator.getLauncherData();
  }
  
  private void getFrameworkManipulator()
  {
    FrameworkAdmin admin = getFrameworkAdmin();
    if (admin == null) {
      throw new RuntimeException("Framework admin service not found");
    }
    manipulator = admin.getManipulator();
    if (manipulator == null) {
      throw new RuntimeException("Framework manipulator not found");
    }
  }
  
  private FrameworkAdmin getFrameworkAdmin()
  {
    return (FrameworkAdmin)ServiceHelper.getService(Activator.getContext(), FrameworkAdmin.class.getName(), frameworkAdminFillter);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.publisher.eclipse.DataLoader
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.publisher.eclipse;

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

class ExecutablesDescriptor$1
  impleme
1 2 3 4 5 6 7 8 9 10 11 12

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