1 11 package org.eclipse.update.internal.jarprocessor; 12 13 import java.io.File ; 14 import java.io.IOException ; 15 import java.util.List ; 16 import java.util.Properties ; 17 18 22 public class UnpackStep extends CommandStep { 23 public static final String UNPACKER_PROPERTY = "org.eclipse.update.jarprocessor.Unpacker"; private static Boolean canUnpack = null; 25 private static String unpackCommand = null; 26 27 public static boolean canUnpack() { 28 if (canUnpack != null) 29 return canUnpack.booleanValue(); 30 31 String [] locations = Utils.getPack200Commands("unpack200"); if (locations == null) { 33 canUnpack = Boolean.FALSE; 34 unpackCommand = null; 35 return false; 36 } 37 38 int result; 39 for (int i = 0; i < locations.length; i++) { 40 if (locations[i] == null) 41 continue; 42 result = execute(new String [] {locations[i], "-V"}); if (result == 0) { 44 unpackCommand = locations[i]; 45 canUnpack = Boolean.TRUE; 46 return true; 47 } 48 } 49 50 canUnpack = Boolean.FALSE; 51 return false; 52 } 53 54 public UnpackStep(Properties options) { 55 super(options, null, null, false); 56 } 57 58 public UnpackStep(Properties options, boolean verbose) { 59 super(options, null, null, verbose); 60 } 61 62 65 public String recursionEffect(String entryName) { 66 if (canUnpack() && entryName.endsWith(Utils.PACKED_SUFFIX)) { 67 return entryName.substring(0, entryName.length() - Utils.PACKED_SUFFIX.length()); 68 } 69 return null; 70 } 71 72 75 public File preProcess(File input, File workingDirectory, List containers) { 76 if (canUnpack() && unpackCommand != null) { 77 String name = input.getName(); 78 if (name.endsWith(Utils.PACKED_SUFFIX)) { 79 name = name.substring(0, name.length() - Utils.PACKED_SUFFIX.length()); 80 81 File unpacked = new File (workingDirectory, name); 82 File parent = unpacked.getParentFile(); 83 if (!parent.exists()) 84 parent.mkdirs(); 85 try { 86 String options = getOptions().getProperty(input.getName() + ".unpack.args"); String [] cmd = null; 88 if (options != null) { 89 cmd = new String [] {unpackCommand, options, input.getCanonicalPath(), unpacked.getCanonicalPath()}; 90 } else { 91 cmd = new String [] {unpackCommand, input.getCanonicalPath(), unpacked.getCanonicalPath()}; 92 } 93 int result = execute(cmd, verbose); 94 if (result != 0 && verbose) 95 System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd)); } catch (IOException e) { 97 if (verbose) 98 e.printStackTrace(); 99 return null; 100 } 101 return unpacked; 102 } 103 } 104 return null; 105 } 106 107 110 public File postProcess(File input, File workingDirectory, List containers) { 111 return null; 112 } 113 114 public String getStepName() { 115 return "Unpack"; } 117 } 118 | Popular Tags |