org.eclipse.equinox.p2.jarprocessor_1.0.200.v20110808-1657

16:44:13.745 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.p2.jarprocessor_1.0.200.v20110808-1657.jar
package org.eclipse.equinox.internal.p2.jarprocessor;

import java.io.File;
import java.io.PrintStream;
import java.util.List;
import java.util.Properties;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.IProcessStep;

public abstract class CommandStep
  implements IProcessStep
{
  protected String command = null;
  protected String extension = null;
  private Properties options = null;
  protected boolean verbose = false;
  
  public CommandStep(Properties options, String command, String extension, boolean verbose)
  {
    this.command = command;
    this.extension = extension;
    this.options = options;
    this.verbose = verbose;
  }
  
  protected static int execute(String[] cmd)
  {
    return execute(cmd, false);
  }
  
  protected static int execute(String[] cmd, boolean verbose)
  {
    Runtime runtime = Runtime.getRuntime();
    Process proc = null;
    try
    {
      proc = runtime.exec(cmd);
      StreamProcessor.start(proc.getErrorStream(), "STDERR", verbose);
      StreamProcessor.start(proc.getInputStream(), "STDOUT", verbose);
    }
    catch (Exception e)
    {
      if (verbose)
      {
        System.out.println("Error executing command " + Utils.concat(cmd));
        e.printStackTrace();
      }
      return -1;
    }
    try
    {
      return proc.waitFor();
    }
    catch (InterruptedException e)
    {
      if (verbose) {
        e.printStackTrace();
      }
    }
    return -1;
  }
  
  public Properties getOptions()
  {
    if (options == null) {
      options = new Properties();
    }
    return options;
  }
  
  public void adjustInf(File input, Properties inf, List containers) {}
}

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

import java.io.File;
import java.io.PrintStream;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessor;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor.Options;

public class Main
{
  private static void printUsage()
  {
    System.out.println("[-option ...]... input");
    System.out.println("The following options are supported:");
    System.out.println("-processAll     process all jars, regardless of whether they were previously normalized");
    System.out.println("                By default only normalized jars will be processed.");
    System.out.println("-repack         normalize jars ");
    System.out.println("-sign <command> sign jars using <command>");
    System.out.println("-pack           pack the jars.  pack and repack are redundant unless");
    System.out.println("                sign is also specified.");
    System.out.println("-unpack         unpack pack.gz files. Unpack is mutually exclusive");
    System.out.println("                with repack, sign and pack.");
    System.out.println();
    System.out.println("-outputDir <dir>  the output directory");
    System.out.println("-verbose        verbose mode ");
  }
  
  public static JarProcessorExecutor.Options processArguments(String[] args)
  {
    if (args.length == 0)
    {
      printUsage();
      return null;
    }
    JarProcessorExecutor.Options options = new JarProcessorExecutor.Options();
    for (int i = 0; i < args.length - 1; i++) {
      if (args[i].equals("-pack"))
      {
        pack = true;
      }
      else if (args[i].equals("-unpack"))
      {
        unpack = true;
      }
      else if ((args[i].equals("-sign")) && (i < args.length - 2))
      {
        if (args[(i + 1)].startsWith("-"))
        {
          printUsage();
          return null;
        }
        signCommand = args[(++i)];
      }
      else if (args[i].equals("-repack"))
      {
        repack = true;
      }
      else if ((args[i].equals("-outputDir")) && (i < args.length - 2))
      {
        if (args[(i + 1)].startsWith("-"))
        {
          printUsage();
          return null;
        }
        outputDir = args[(++i)];
      }
      else if (args[i].equals("-verbose"))
      {
        verbose = true;
      }
      else if (args[i].equals("-processAll"))
      {
        processAll = true;
      }
    }
    input = new File(args[i]);
    
    String problemMessage = null;
    String inputName = input.getName();
    if (unpack)
    {
      if (!JarProcessor.canPerformUnpack()) {
        problemMessage = "The unpack200 command cannot be found.";
      } else if ((input.isFile()) && (!inputName.endsWith(".zip")) && (!inputName.endsWith(".pack.gz"))) {
        problemMessage = "Input file is not a pack.gz file.";
      } else if ((pack) || (repack) || (signCommand != null)) {
        problemMessage = "Pack, repack or sign cannot be specified with unpack.";
      }
    }
    else if ((input.isFile()) && (!inputName.endsWith(".zip")) && (!inputName.endsWith(".jar"))) {
      problemMessage = "Input file is not a jar file.";
    } else if (((pack) || (repack)) && (!JarProcessor.canPerformPack())) {
      problemMessage = "The pack200 command can not be found.";
    }
    if (problemMessage != null)
    {
      System.out.println(problemMessage);
      System.out.println();
      printUsage();
      return null;
    }
    return options;
  }
  
  public static void main(String[] args)
  {
    JarProcessorExecutor.Options options = processArguments(args);
    if (options == null) {
      return;
    }
    new JarProcessorExecutor().runJarProcessor(options);
  }
}

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

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;

public class PackStep
  extends CommandStep
{
  protected static String packCommand = null;
  private static Boolean canPack = null;
  private Set exclusions = Collections.EMPTY_SET;
  
  public static boolean canPack()
  {
    if (canPack != null) {
      return canPack.booleanValue();
    }
    String[] locations = Utils.getPack200Commands("pack200");
    if (locations == null)
    {
      canPack = Boolean.FALSE;
      packCommand = null;
      return false;
    }
    for (int i = 0; i < locations.length; i++) {
      if (locations[i] != null)
      {
        int result = execute(new String[] { locations[i], "-V" });
        if (result == 0)
        {
          packCommand = locations[i];
          canPack = Boolean.TRUE;
          return true;
        }
      }
    }
    canPack = Boolean.FALSE;
    return false;
  }
  
  public PackStep(Properties options)
  {
    super(options, null, null, false);
    exclusions = Utils.getPackExclusions(options);
  }
  
  public PackStep(Properties options, boolean verbose)
  {
    super(options, null, null, verbose);
    exclusions = Utils.getPackExclusions(options);
  }
  
  public String recursionEffect(String entryName)
  {
    if ((canPack()) && (entryName.endsWith(".jar")) && (!exclusions.contains(entryName))) {
      return entryName + ".pack.gz";
    }
    return null;
  }
  
  public File preProcess(File input, File workingDirectory, List containers)
  {
    return null;
  }
  
  public File postProcess(File input, File workingDirectory, List containers)
  {
    if ((canPack()) && (packCommand != null))
    {
      Properties inf = Utils.getEclipseInf(input, verbose);
      if (!shouldPack(input, containers, inf)) {
        return null;
      }
      File outputFile = new File(workingDirectory, input.getName() + ".pack.gz");
      try
      {
        String[] cmd = getCommand(input, outputFile, inf, containers);
        int result = execute(cmd, verbose);
        if ((result != 0) && (verbose)) {
          System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd));
        }
      }
      catch (IOException e)
      {
        if (verbose) {
          e.printStackTrace();
        }
        return null;
      }
      return outputFile;
    }
    return null;
  }
  
  protected boolean shouldPack(File input, List containers, Properties inf)
  {
    for (Iterator iterator = containers.iterator(); iterator.hasNext();)
    {
      Properties container = (Properties)iterator.next();
      if (container.containsKey("jarprocessor.exclude.children.pack"))
      {
        if (!Boolean.valueOf(container.getProperty("jarprocessor.exclude.children.pack")).booleanValue()) {
          break;
        }
        if (verbose) {
          System.out.println(input.getName() + " is excluded from pack200 by its containers.");
        }
        return false;
      }
    }
    if ((inf != null) && (inf.containsKey("jarprocessor.exclude.pack")) && (Boolean.valueOf(inf.getProperty("jarprocessor.exclude.pack")).booleanValue()))
    {
      if (verbose) {
        System.out.println("Excluding " + input.getName() + " from " + getStepName());
      }
      return false;
    }
    return true;
  }
  
  protected String[] getCommand(File input, File outputFile, Properties inf, List containers)
    throws IOException
  {
    String[] cmd = null;
    String arguments = getArguments(input, inf, containers);
    if ((arguments != null) && (arguments.length() > 0))
    {
      String[] args = Utils.toStringArray(arguments, ",");
      cmd = new String[3 + args.length];
      cmd[0] = packCommand;
      System.arraycopy(args, 0, cmd, 1, args.length);
      cmd[(cmd.length - 2)] = outputFile.getCanonicalPath();
      cmd[(cmd.length - 1)] = input.getCanonicalPath();
    }
    else
    {
      cmd = new String[] { packCommand, outputFile.getCanonicalPath(), input.getCanonicalPath() };
    }
    return cmd;
  }
  
  protected String getArguments(File input, Properties inf, List containers)
  {
    if ((inf != null) && (inf.containsKey("pack200.args"))) {
      return inf.getProperty("pack200.args");
    }
    for (Iterator iterator = containers.iterator(); iterator.hasNext();)
    {
      Properties container = (Properties)iterator.next();
      if (container.containsKey("pack200.default.args")) {
        return container.getProperty("pack200.default.args");
      }
    }
    Properties options = getOptions();
    String argsKey = input.getName() + ".pack.args";
    if (options.containsKey(argsKey)) {
      return options.getProperty(argsKey);
    }
    if (options.containsKey("pack200.default.args")) {
      return options.getProperty("pack200.default.args");
    }
    return "";
  }
  
  public String getStepName()
  {
    return "Pack";
  }
  
  public void adjustInf(File input, Properties inf, List containers)
  {
    if ((input == null) || (inf == null)) {
      return;
    }
    boolean v = verbose;
    verbose = false;
    if (!shouldPack(input, containers, inf))
    {
      verbose = v;
      return;
    }
    verbose = v;
    if (inf.getProperty("pack200.conditioned") == null)
    {
      inf.put("pack200.conditioned", "true");
      
      String arguments = inf.getProperty("pack200.args");
      if (arguments == null)
      {
        arguments = getArguments(input, inf, containers);
        if ((arguments != null) && (arguments.length() > 0)) {
          inf.put("pack200.args", arguments);
        }
      }
    }
  }
}

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

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.List;
import java.util.Properties;
import java.util.Set;

public class PackUnpackStep
  extends PackStep
{
  private Set exclusions = null;
  
  public PackUnpackStep(Properties options)
  {
    super(options);
    exclusions = Utils.getPackExclusions(options);
  }
  
  public PackUnpackStep(Properties options, boolean verbose)
  {
    super(options, verbose);
    exclusions = Utils.getPackExclusions(options);
  }
  
  public String recursionEffect(String entryName)
  {
    if ((canPack()) && (entryName.endsWith(".jar")) && (!exclusions.contains(entryName))) {
      return entryName;
    }
    return null;
  }
  
  public File postProcess(File input, File workingDirectory, List containers)
  {
    if ((canPack()) && (packCommand != null) && (input != null))
    {
      Properties inf = Utils.getEclipseInf(input, verbose);
      if (!shouldPack(input, containers, inf)) {
        return null;
      }
      File tempFile = new File(workingDirectory, "temp_" + input.getName());
      try
      {
        String[] tmp = getCommand(input, tempFile, inf, containers);
        String[] cmd = new String[tmp.length + 1];
        cmd[0] = tmp[0];
        cmd[1] = "-r";
        System.arraycopy(tmp, 1, cmd, 2, tmp.length - 1);
        
        int result = execute(cmd, verbose);
        if ((result == 0) && (tempFile.exists()))
        {
          File finalFile = new File(workingDirectory, input.getName());
          if (finalFile.exists()) {
            finalFile.delete();
          }
          tempFile.renameTo(finalFile);
          return finalFile;
        }
        if (verbose) {
          System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd));
        }
      }
      catch (IOException e)
      {
        if (verbose) {
          e.printStackTrace();
        }
        return null;
      }
    }
    return null;
  }
  
  public File preProcess(File input, File workingDirectory, List containers)
  {
    return null;
  }
  
  public String getStepName()
  {
    return "Repack";
  }
}

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

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;

public class SignCommandStep
  extends CommandStep
{
  private Set exclusions = null;
  
  public SignCommandStep(Properties options, String command)
  {
    super(options, command, ".jar", false);
    exclusions = Utils.getSignExclusions(options);
  }
  
  public SignCommandStep(Properties options, String command, boolean verbose)
  {
    super(options, command, ".jar", verbose);
    exclusions = Utils.getSignExclusions(options);
  }
  
  public String recursionEffect(String entryName)
  {
    if ((entryName.endsWith(extension)) && (!exclusions.contains(entryName))) {
      return entryName;
    }
    return null;
  }
  
  public File preProcess(File input, File workingDirectory, List containers)
  {
    return null;
  }
  
  public File postProcess(File input, File workingDirectory, List containers)
  {
    if ((command != null) && (input != null) && (shouldSign(input, containers))) {
      try
      {
        String[] cmd = { command, input.getCanonicalPath() };
        int result = execute(cmd, verbose);
        if (result == 0) {
          return input;
        }
        if (verbose) {
          System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd));
        }
      }
      catch (IOException e)
      {
        if (verbose) {
          e.printStackTrace();
        }
      }
    }
    return null;
  }
  
  public boolean shouldSign(File input, List containers)
  {
    Properties inf = null;
    for (Iterator iterator = containers.iterator(); iterator.hasNext();)
    {
      inf = (Properties)iterator.next();
      if (inf.containsKey("jarprocessor.exclude.children.sign"))
      {
        if (!Boolean.valueOf(inf.getProperty("jarprocessor.exclude.children.sign")).booleanValue()) {
          break;
        }
        if (verbose) {
          System.out.println(input.getName() + "is excluded from signing by its containers.");
        }
        return false;
      }
    }
    inf = Utils.getEclipseInf(input, verbose);
    if ((inf != null) && (inf.containsKey("jarprocessor.exclude.sign")) && (Boolean.valueOf(inf.getProperty("jarprocessor.exclude.sign")).booleanValue()))
    {
      if (verbose) {
        System.out.println("Excluding " + input.getName() + " from signing.");
      }
      return false;
    }
    return true;
  }
  
  public String getStepName()
  {
    return "Sign";
  }
}

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

import java.io.InputStream;

class StreamProcessor$1
  extends Thread
{
  private final InputStream val$is;
  private final String val$name;
  private final boolean val$verbose;
  
  StreamProcessor$1(String $anonymous0, InputStream paramInputStream, String paramString1, boolean paramBoolean)
  {
    super($anonymous0);val$is = paramInputStream;val$name = paramString1;val$verbose = paramBoolean;
  }
  
  public void run()
  {
    StreamProcessor.run(val$is, val$name, val$verbose);
  }
}

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

public class StreamProcessor
{
  private static final String JOBS = "org.eclipse.core.runtime.jobs.Job";
  public static final String STREAM_PROCESSOR = "Stream Processor";
  public static final String STDERR = "STDERR";
  public static final String STDOUT = "STDOUT";
  private static boolean haveJobs = false;
  
  static
  {
    try
    {
      haveJobs = Class.forName("org.eclipse.core.runtime.jobs.Job") != null;
    }
    catch (ClassNotFoundException localClassNotFoundException) {}
  }
  
  public static void start(InputStream is, String name, boolean verbose)
  {
    if (haveJobs)
    {
      new StreamProcessorJob(is, name, verbose).schedule();
    }
    else
    {
      Thread job = new Thread("Stream Processor")
      {
        private final InputStream val$is;
        private final String val$name;
        private final boolean val$verbose;
        
        public void run()
        {
          StreamProcessor.run(val$is, val$name, val$verbose);
        }
      };
      job.start();
    }
  }
  
  public static void run(InputStream inputStream, String name, boolean verbose)
  {
    try
    {
      InputStreamReader isr = new InputStreamReader(inputStream);
      BufferedReader br = new BufferedReader(isr);
      for (;;)
      {
        String s = br.readLine();
        if (s == null) {
          break;
        }
        if (verbose) {
          if ("STDERR".equals(name)) {
            System.err.println(name + ": " + s);
          } else {
            System.out.println(name + ": " + s);
          }
        }
      }
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
  }
}

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

import java.io.InputStream;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

public class StreamProcessorJob
  extends Job
{
  private InputStream inputStream = null;
  private String name = null;
  private boolean verbose = false;
  
  public StreamProcessorJob(InputStream stream, String name, boolean verbose)
  {
    super("Stream Processor : " + name);
    setPriority(20);
    setSystem(true);
    inputStream = stream;
    this.name = name;
    this.verbose = verbose;
  }
  
  protected IStatus run(IProgressMonitor monitor)
  {
    StreamProcessor.run(inputStream, name, verbose);
    inputStream = null;
    return Status.OK_STATUS;
  }
}

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

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.List;
import java.util.Properties;

public class UnpackStep
  extends CommandStep
{
  public static final String UNPACKER_PROPERTY = "org.eclipse.update.jarprocessor.Unpacker";
  private static Boolean canUnpack = null;
  private static String unpackCommand = null;
  
  public static boolean canUnpack()
  {
    if (canUnpack != null) {
      return canUnpack.booleanValue();
    }
    String[] locations = Utils.getPack200Commands("unpack200");
    if (locations == null)
    {
      canUnpack = Boolean.FALSE;
      unpackCommand = null;
      return false;
    }
    for (int i = 0; i < locations.length; i++) {
      if (locations[i] != null)
      {
        int result = execute(new String[] { locations[i], "-V" });
        if (result == 0)
        {
          unpackCommand = locations[i];
          canUnpack = Boolean.TRUE;
          return true;
        }
      }
    }
    canUnpack = Boolean.FALSE;
    return false;
  }
  
  public UnpackStep(Properties options)
  {
    super(options, null, null, false);
  }
  
  public UnpackStep(Properties options, boolean verbose)
  {
    super(options, null, null, verbose);
  }
  
  public String recursionEffect(String entryName)
  {
    if ((canUnpack()) && (entryName.endsWith(".pack.gz"))) {
      return entryName.substring(0, entryName.length() - ".pack.gz".length());
    }
    return null;
  }
  
  public File preProcess(File input, File workingDirectory, List containers)
  {
    if ((canUnpack()) && (unpackCommand != null))
    {
      String name = input.getName();
      if (name.endsWith(".pack.gz"))
      {
        name = name.substring(0, name.length() - ".pack.gz".length());
        
        File unpacked = new File(workingDirectory, name);
        File parent = unpacked.getParentFile();
        if (!parent.exists()) {
          parent.mkdirs();
        }
        try
        {
          String options = getOptions().getProperty(input.getName() + ".unpack.args");
          String[] cmd = null;
          if (options != null) {
            cmd = new String[] { unpackCommand, options, input.getCanonicalPath(), unpacked.getCanonicalPath() };
          } else {
            cmd = new String[] { unpackCommand, input.getCanonicalPath(), unpacked.getCanonicalPath() };
          }
          int result = execute(cmd, verbose);
          if ((result != 0) && (verbose)) {
            System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd));
          }
        }
        catch (IOException e)
        {
          if (verbose) {
            e.printStackTrace();
          }
          return null;
        }
        return unpacked;
      }
    }
    return null;
  }
  
  public File postProcess(File input, File workingDirectory, List containers)
  {
    return null;
  }
  
  public String getStepName()
  {
    return "Unpack";
  }
}

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

import java.io.File;
import java.io.FileFilter;

class Utils$1
  implements FileFilter
{
  public boolean accept(File pathname)
  {
    return (pathname.isFile()) && (pathname.getName().endsWith(".jar"));
  }
}

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

import java.io.File;
import java.io.FileFilter;

class Utils$2
  implements FileFilter
{
  public boolean accept(File pathname)
  {
    return (pathname.isFile()) && (pathname.getName().endsWith("pack.gz"));
  }
}

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

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import java.util.SortedMap;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipException;

public class Utils
{
  public static final String MARK_FILE_NAME = "META-INF/eclipse.inf";
  public static final String SIGN_EXCLUDES = "sign.excludes";
  public static final String PACK_EXCLUDES = "pack.excludes";
  public static final String PACK_ARGS_SUFFIX = ".pack.args";
  public static final String DEFAULT_PACK_ARGS = "pack200.default.args";
  public static final String MARK_PROPERTY = "pack200.conditioned";
  public static final String MARK_EXCLUDE = "jarprocessor.exclude";
  public static final String MARK_EXCLUDE_PACK = "jarprocessor.exclude.pack";
  public static final String MARK_EXCLUDE_SIGN = "jarprocessor.exclude.sign";
  public static final String MARK_EXCLUDE_CHILDREN = "jarprocessor.exclude.children";
  public static final String MARK_EXCLUDE_CHILDREN_PACK = "jarprocessor.exclude.children.pack";
  public static final String MARK_EXCLUDE_CHILDREN_SIGN = "jarprocessor.exclude.children.sign";
  public static final String PACK_ARGS = "pack200.args";
  public static final String PACK200_PROPERTY = "org.eclipse.update.jarprocessor.pack200";
  public static final String JRE = "@jre";
  public static final String PATH = "@path";
  public static final String NONE = "@none";
  public static final String PACKED_SUFFIX = ".pack.gz";
  public static final String JAR_SUFFIX = ".jar";
  public static final FileFilter JAR_FILTER = new FileFilter()
  {
    public boolean accept(File pathname)
    {
      return (pathname.isFile()) && (pathname.getName().endsWith(".jar"));
    }
  };
  public static final FileFilter PACK_GZ_FILTER = new FileFilter()
  {
    public boolean accept(File pathname)
    {
      return (pathname.isFile()) && (pathname.getName().endsWith("pack.gz"));
    }
  };
  
  public static void close(Object stream)
  {
    if (stream != null) {
      try
      {
        if ((stream instanceof InputStream)) {
          ((InputStream)stream).close();
        } else if ((stream instanceof OutputStream)) {
          ((OutputStream)stream).close();
        } else if ((stream instanceof JarFile)) {
          ((JarFile)stream).close();
        }
      }
      catch (IOException localIOException) {}
    }
  }
  
  public static String[] getPack200Commands(String cmd)
  {
    String[] locations = null;
    String prop = System.getProperty("org.eclipse.update.jarprocessor.pack200");
    String javaHome = System.getProperty("java.home");
    if ("@none".equals(prop)) {
      return null;
    }
    if ("@jre".equals(prop)) {
      locations = new String[] { javaHome + "/bin/" + cmd };
    } else if ("@path".equals(prop)) {
      locations = new String[] { cmd };
    } else if (prop == null) {
      locations = new String[] { javaHome + "/bin/" + cmd, cmd };
    } else {
      locations = new String[] { prop + "/" + cmd };
    }
    return locations;
  }
  
  /* Error */
  public static void transferStreams(InputStream source, OutputStream destination, boolean close)
    throws IOException
  {
    // Byte code:
    //   0: new 195	java/io/BufferedInputStream
    //   3: dup
    //   4: aload_0
    //   5: invokespecial 325	java/io/BufferedInputStream:<init>	(Ljava/io/InputStream;)V
    //   8: astore_0
    //   9: new 196	java/io/BufferedOutputStream
    //   12: dup
    //   13: aload_1
    //   14: invokespecial 326	java/io/BufferedOutputStream:<init>	(Ljava/io/OutputStream;)V
    //   17: astore_1
    //   18: sipush 8192
    //   21: newarray <illegal type>
    //   23: astore_3
    //   24: iconst_m1
    //   25: istore 4
    //   27: aload_0
    //   28: aload_3
    //   29: invokevirtual 334	java/io/InputStream:read	([B)I
    //   32: dup
    //   33: istore 4
    //   35: iconst_m1
    //   36: if_icmpne +6 -> 42
    //   39: goto +38 -> 77
    //   42: aload_1
    //   43: aload_3
    //   44: iconst_0
    //   45: iload 4
    //   47: invokevirtual 337	java/io/OutputStream:write	([BII)V
    //   50: goto -26 -> 24
    //   53: astore 5
    //   55: iload_2
    //   56: ifeq +14 -> 70
    //   59: aload_0
    //   60: invokestatic 371	org/eclipse/equinox/internal/p2/jarprocessor/Utils:close	(Ljava/lang/Object;)V
    //   63: aload_1
    //   64: invokestatic 371	org/eclipse/equinox/internal/p2/jarprocessor/Utils:close	(Ljava/lang/Object;)V
    //   67: goto +7 -> 74
    //   70: aload_1
    //   71: invokevirtual 336	java/io/OutputStream:flush	()V
    //   74: aload 5
    //   76: athrow
    //   77: iload_2
    //   78: ifeq +14 -> 92
    //   81: aload_0
    //   82: invokestatic 371	org/eclipse/equinox/internal/p2/jarprocessor/Utils:close	(Ljava/lang/Object;)V
    //   85: aload_1
    //   86: invokestatic 371	org/eclipse/equinox/internal/p2/jarprocessor/Utils:close	(Ljava/lang/Object;)V
    //   89: goto +7 -> 96
    //   92: aload_1
    //   93: invokevirtual 336	java/io/OutputStream:flush	()V
    //   96: return
    // Line number table:
    //   Java source line #133	-> byte code offset #0
    //   Java source line #134	-> byte code offset #9
    //   Java source line #136	-> byte code offset #18
    //   Java source line #138	-> byte code offset #24
    //   Java source line #139	-> byte code offset #27
    //   Java source line #140	-> byte code offset #39
    //   Java source line #141	-> byte code offset #42
    //   Java source line #137	-> byte code offset #50
    //   Java source line #143	-> byte code offset #53
    //   Java source line #144	-> byte code offset #55
    //   Java source line #145	-> byte code offset #59
    //   Java source line #146	-> byte code offset #63
    //   Java source line #148	-> byte code offset #70
    //   Java source line #150	-> byte code offset #74
    //   Java source line #144	-> byte code offset #77
    //   Java source line #145	-> byte code offset #81
    //   Java source line #146	-> byte code offset #85
    //   Java source line #148	-> byte code offset #92
    //   Java source line #151	-> byte code offset #96
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	97	0	source	InputStream
    //   0	97	1	destination	OutputStream
    //   0	97	2	close	boolean
    //   23	21	3	buffer	byte[]
    //   25	21	4	bytesRead	int
    //   53	22	5	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   18	53	53	finally
  }
  
  public static boolean clear(File root)
  {
    boolean result = clearChildren(root);
    try
    {
      if (root.exists()) {
        result &= root.delete();
      }
    }
    catch (Exception localException)
    {
      result = false;
    }
    return result;
  }
  
  public static boolean clearChildren(File root)
  {
    boolean result = true;
    if (root.isDirectory())
    {
      String[] list = root.list();
      if (list != null) {
        for (int i = 0; i < list.length; i++) {
          result &= clear(new File(root, list[i]));
        }
      }
    }
    return result;
  }
  
  public static Set getPackExclusions(Properties properties)
  {
    if (properties == null) {
      return Collections.EMPTY_SET;
    }
    String packExcludes = properties.getProperty("pack.excludes");
    if (packExcludes != null)
    {
      String[] excludes = toStringArray(packExcludes, ",");
      Set packExclusions = new HashSet();
      for (int i = 0; i < excludes.length; i++) {
        packExclusions.add(excludes[i]);
      }
      return packExclusions;
    }
    return Collections.EMPTY_SET;
  }
  
  public static Set getSignExclusions(Properties properties)
  {
    if (properties == null) {
      return Collections.EMPTY_SET;
    }
    String signExcludes = properties.getProperty("sign.excludes");
    if (signExcludes != null)
    {
      String[] excludes = toStringArray(signExcludes, ",");
      Set signExclusions = new HashSet();
      for (int i = 0; i < excludes.length; i++) {
        signExclusions.add(excludes[i]);
      }
      return signExclusions;
    }
    return Collections.EMPTY_SET;
  }
  
  public static String concat(String[] array)
  {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < array.length; i++)
    {
      if (i > 0) {
        buffer.append(' ');
      }
      buffer.append(array[i]);
    }
    return buffer.toString();
  }
  
  public static String[] toStringArray(String input, String separator)
  {
    StringTokenizer tokenizer = new StringTokenizer(input, separator);
    int count = tokenizer.countTokens();
    String[] result = new String[count];
    for (int i = 0; i < count; i++) {
      result[i] = tokenizer.nextToken().trim();
    }
    return result;
  }
  
  public static Properties getEclipseInf(File jarFile, boolean verbose)
  {
    if ((jarFile == null) || (!jarFile.exists()))
    {
      if (verbose) {
        System.out.println("Failed to obtain eclipse.inf due to missing jar file: " + jarFile);
      }
      return null;
    }
    JarFile jar = null;
    try
    {
      jar = new JarFile(jarFile, false);
    }
    catch (ZipException localZipException)
    {
      return null;
    }
    catch (IOException e)
    {
      if (verbose)
      {
        System.out.println("Failed to obtain eclipse.inf due to IOException: " + jarFile);
        e.printStackTrace();
      }
      return null;
    }
    try
    {
      JarEntry mark = jar.getJarEntry("META-INF/eclipse.inf");
      Properties localProperties1;
      if (mark != null)
      {
        InputStream in = jar.getInputStream(mark);
        Properties props = new Properties();
        props.load(in);
        in.close();
        return props;
      }
      return new Properties();
    }
    catch (IOException e)
    {
      if (verbose)
      {
        System.out.println("Failed to obtain eclipse.inf due to IOException: " + jarFile);
        e.printStackTrace();
      }
      return null;
    }
    finally
    {
      close(jar);
    }
  }
  
  public static boolean shouldSkipJar(File input, boolean processAll, boolean verbose)
  {
    Properties inf = getEclipseInf(input, verbose);
    if (inf == null) {
      return false;
    }
    String exclude = inf.getProperty("jarprocessor.exclude");
    if ((exclude != null) && (Boolean.valueOf(exclude).booleanValue())) {
      return true;
    }
    if (processAll) {
      return false;
    }
    String marked = inf.getProperty("pack200.conditioned");
    return !Boolean.valueOf(marked).booleanValue();
  }
  
  public static void storeProperties(Properties props, OutputStream stream)
  {
    PrintStream printStream = new PrintStream(stream);
    printStream.print("#Processed using Jarprocessor\n");
    SortedMap sorted = new TreeMap(props);
    for (Iterator iter = sorted.keySet().iterator(); iter.hasNext();)
    {
      String key = (String)iter.next();
      printStream.print(key);
      printStream.print(" = ");
      printStream.print(sorted.get(key));
      printStream.print("\n");
    }
    printStream.flush();
  }
}

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

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessor;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor.Options;

public class ZipProcessor
{
  private JarProcessorExecutor executor = null;
  private JarProcessorExecutor.Options options = null;
  private String workingDirectory = null;
  private Properties properties = null;
  private Set packExclusions = null;
  private Set signExclusions = null;
  
  public void setExecutor(JarProcessorExecutor executor)
  {
    this.executor = executor;
  }
  
  public void setOptions(JarProcessorExecutor.Options options)
  {
    this.options = options;
  }
  
  public void setWorkingDirectory(String dir)
  {
    workingDirectory = dir;
  }
  
  public String getWorkingDirectory()
  {
    if (workingDirectory == null) {
      workingDirectory = ".";
    }
    return workingDirectory;
  }
  
  private boolean repacking()
  {
    return (options.repack) || ((options.pack) && (options.signCommand != null));
  }
  
  public void processZip(File zipFile)
    throws ZipException, IOException
  {
    if (options.verbose) {
      System.out.println("Processing " + zipFile.getPath());
    }
    ZipFile zip = new ZipFile(zipFile);
    initialize(zip);
    
    String extension = options.unpack ? "pack.gz" : ".jar";
    File tempDir = new File(getWorkingDirectory(), "temp_" + zipFile.getName());
    JarProcessor processor = new JarProcessor();
    processor.setVerbose(options.verbose);
    processor.setProcessAll(options.processAll);
    processor.setWorkingDirectory(tempDir.getCanonicalPath());
    if (options.unpack) {
      executor.addPackUnpackStep(processor, properties, options);
    }
    File outputFile = new File(getWorkingDirectory(), zipFile.getName() + ".temp");
    File parent = outputFile.getParentFile();
    if (!parent.exists()) {
      parent.mkdirs();
    }
    ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(outputFile));
    Enumeration entries = zip.entries();
    if (entries.hasMoreElements()) {
      for (ZipEntry entry = (ZipEntry)entries.nextElement(); entry != null; entry = entries.hasMoreElements() ? (ZipEntry)entries.nextElement() : null)
      {
        String name = entry.getName();
        
        InputStream entryStream = zip.getInputStream(entry);
        
        boolean pack = (options.pack) && (!packExclusions.contains(name));
        boolean sign = (options.signCommand != null) && (!signExclusions.contains(name));
        boolean repack = (repacking()) && (!packExclusions.contains(name));
        
        File extractedFile = null;
        if ((entry.getName().endsWith(extension)) && ((pack) || (sign) || (repack) || (options.unpack)))
        {
          extractedFile = new File(tempDir, name);
          parent = extractedFile.getParentFile();
          if (!parent.exists()) {
            parent.mkdirs();
          }
          if (options.verbose) {
            System.out.println("Extracting " + entry.getName());
          }
          FileOutputStream extracted = new FileOutputStream(extractedFile);
          Utils.transferStreams(entryStream, extracted, true);
          entryStream = null;
          
          boolean skip = Utils.shouldSkipJar(extractedFile, options.processAll, options.verbose);
          if (skip)
          {
            entryStream = new File
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