|
Lines 12-24
Link Here
|
| 12 |
|
12 |
|
| 13 |
import java.io.File; |
13 |
import java.io.File; |
| 14 |
import java.io.IOException; |
14 |
import java.io.IOException; |
| 15 |
import java.util.*; |
15 |
import java.util.Collections; |
|
|
16 |
import java.util.Iterator; |
| 17 |
import java.util.List; |
| 18 |
import java.util.Properties; |
| 19 |
import java.util.Set; |
| 16 |
|
20 |
|
| 17 |
public class PackStep extends CommandStep { |
21 |
public class PackStep extends CommandStep { |
| 18 |
|
22 |
|
| 19 |
protected static String packCommand = null; |
23 |
protected static String packCommand = null; |
| 20 |
private static Boolean canPack = null; |
24 |
private static Boolean canPack = null; |
| 21 |
|
25 |
|
|
|
26 |
private String arguments = null; |
| 22 |
private Set exclusions = Collections.EMPTY_SET; |
27 |
private Set exclusions = Collections.EMPTY_SET; |
| 23 |
|
28 |
|
| 24 |
public static boolean canPack() { |
29 |
public static boolean canPack() { |
|
Lines 65-85
Link Here
|
| 65 |
return null; |
70 |
return null; |
| 66 |
} |
71 |
} |
| 67 |
|
72 |
|
| 68 |
public File preProcess(File input, File workingDirectory) { |
73 |
public File preProcess(File input, File workingDirectory, List containers) { |
| 69 |
return null; |
74 |
return null; |
| 70 |
} |
75 |
} |
| 71 |
|
76 |
|
| 72 |
public File postProcess(File input, File workingDirectory) { |
77 |
public File postProcess(File input, File workingDirectory, List containers) { |
| 73 |
if (canPack() && packCommand != null) { |
78 |
if (canPack() && packCommand != null) { |
| 74 |
Properties inf = Utils.getEclipseInf(input); |
79 |
Properties inf = Utils.getEclipseInf(input, verbose); |
| 75 |
if (inf != null && inf.containsKey(Utils.MARK_EXCLUDE_PACK) && Boolean.valueOf(inf.getProperty(Utils.MARK_EXCLUDE_PACK)).booleanValue()) { |
80 |
if (!shouldPack(input, containers, inf)) |
| 76 |
if(verbose) |
|
|
| 77 |
System.out.println("Excluding " + input.getName() + " from " + getStepName()); //$NON-NLS-1$ //$NON-NLS-2$ |
| 78 |
return null; |
81 |
return null; |
| 79 |
} |
|
|
| 80 |
File outputFile = new File(workingDirectory, input.getName() + Utils.PACKED_SUFFIX); |
82 |
File outputFile = new File(workingDirectory, input.getName() + Utils.PACKED_SUFFIX); |
| 81 |
try { |
83 |
try { |
| 82 |
String[] cmd = getCommand(input, outputFile, inf); |
84 |
String[] cmd = getCommand(input, outputFile, inf, containers); |
| 83 |
int result = execute(cmd, verbose); |
85 |
int result = execute(cmd, verbose); |
| 84 |
if (result != 0 && verbose) |
86 |
if (result != 0 && verbose) |
| 85 |
System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd)); //$NON-NLS-1$ //$NON-NLS-2$ |
87 |
System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd)); //$NON-NLS-1$ //$NON-NLS-2$ |
|
Lines 93-106
Link Here
|
| 93 |
return null; |
95 |
return null; |
| 94 |
} |
96 |
} |
| 95 |
|
97 |
|
| 96 |
protected String[] getCommand(File input, File outputFile, Properties inf) throws IOException { |
98 |
protected boolean shouldPack(File input, List containers, Properties inf) { |
| 97 |
String[] cmd = null; |
99 |
//1: exclude by containers |
| 98 |
String arguments = null; |
100 |
// innermost jar is first on the list, it can override outer jars |
| 99 |
if (inf != null && inf.containsKey(Utils.PACK_ARGS)) { |
101 |
for (Iterator iterator = containers.iterator(); iterator.hasNext();) { |
| 100 |
arguments = inf.getProperty(Utils.PACK_ARGS); |
102 |
Properties container = (Properties) iterator.next(); |
| 101 |
} else { |
103 |
if (container.containsKey(Utils.MARK_EXCLUDE_CHILDREN_PACK)) { |
| 102 |
arguments = getOptions().getProperty(input.getName() + ".pack.args"); //$NON-NLS-1$ |
104 |
if (Boolean.valueOf(container.getProperty(Utils.MARK_EXCLUDE_CHILDREN_PACK)).booleanValue()) { |
|
|
105 |
if (verbose) |
| 106 |
System.out.println(input.getName() + "is excluded from pack200 by its containers."); |
| 107 |
return false; |
| 108 |
} |
| 109 |
break; |
| 110 |
} |
| 103 |
} |
111 |
} |
|
|
112 |
|
| 113 |
//2: excluded by self |
| 114 |
if (inf != null && inf.containsKey(Utils.MARK_EXCLUDE_PACK) && Boolean.valueOf(inf.getProperty(Utils.MARK_EXCLUDE_PACK)).booleanValue()) { |
| 115 |
if (verbose) |
| 116 |
System.out.println("Excluding " + input.getName() + " from " + getStepName()); //$NON-NLS-1$ //$NON-NLS-2$ |
| 117 |
return false; |
| 118 |
} |
| 119 |
|
| 120 |
return true; |
| 121 |
} |
| 122 |
|
| 123 |
protected String[] getCommand(File input, File outputFile, Properties inf, List containers) throws IOException { |
| 124 |
String[] cmd = null; |
| 125 |
String arguments = getArguments(input, inf, containers); |
| 104 |
if (arguments != null && arguments.length() > 0) { |
126 |
if (arguments != null && arguments.length() > 0) { |
| 105 |
String[] args = Utils.toStringArray(arguments, ","); //$NON-NLS-1$ |
127 |
String[] args = Utils.toStringArray(arguments, ","); //$NON-NLS-1$ |
| 106 |
cmd = new String[3 + args.length]; |
128 |
cmd = new String[3 + args.length]; |
|
Lines 114-136
Link Here
|
| 114 |
return cmd; |
136 |
return cmd; |
| 115 |
} |
137 |
} |
| 116 |
|
138 |
|
|
|
139 |
protected String getArguments(File input, Properties inf, List containers) { |
| 140 |
if (arguments != null) |
| 141 |
return arguments; |
| 142 |
//1: Explicitly marked in our .inf file |
| 143 |
if (inf != null && inf.containsKey(Utils.PACK_ARGS)) { |
| 144 |
arguments = inf.getProperty(Utils.PACK_ARGS); |
| 145 |
return arguments; |
| 146 |
} |
| 147 |
|
| 148 |
//2: Defaults set in one of our containing jars |
| 149 |
for (Iterator iterator = containers.iterator(); iterator.hasNext();) { |
| 150 |
Properties container = (Properties) iterator.next(); |
| 151 |
if (container.containsKey(Utils.DEFAULT_PACK_ARGS)) { |
| 152 |
arguments = container.getProperty(Utils.DEFAULT_PACK_ARGS); |
| 153 |
return arguments; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
//3: Set by name in outside pack.properties file |
| 158 |
Properties options = getOptions(); |
| 159 |
String argsKey = input.getName() + Utils.PACK_ARGS_SUFFIX; |
| 160 |
if (options.containsKey(argsKey)) { |
| 161 |
arguments = options.getProperty(argsKey); |
| 162 |
return arguments; |
| 163 |
} |
| 164 |
|
| 165 |
//4: Set by default in outside pack.properties file |
| 166 |
if (options.containsKey(Utils.DEFAULT_PACK_ARGS)) { |
| 167 |
arguments = options.getProperty(Utils.DEFAULT_PACK_ARGS); |
| 168 |
return arguments; |
| 169 |
} |
| 170 |
|
| 171 |
if (arguments == null) |
| 172 |
arguments = ""; |
| 173 |
return arguments; |
| 174 |
} |
| 175 |
|
| 117 |
public String getStepName() { |
176 |
public String getStepName() { |
| 118 |
return "Pack"; //$NON-NLS-1$ |
177 |
return "Pack"; //$NON-NLS-1$ |
| 119 |
} |
178 |
} |
| 120 |
|
179 |
|
| 121 |
public void adjustInf(File input, Properties inf) { |
180 |
public void adjustInf(File input, Properties inf, List containers) { |
| 122 |
if (input == null || inf == null) |
181 |
if (input == null || inf == null) |
| 123 |
return; |
182 |
return; |
| 124 |
|
183 |
|
| 125 |
if (inf.containsKey(Utils.MARK_EXCLUDE_PACK) && Boolean.valueOf(inf.getProperty(Utils.MARK_EXCLUDE_PACK)).booleanValue()) { |
184 |
//don't be verbose to check if we should mark the inf |
|
|
185 |
boolean v = verbose; |
| 186 |
verbose = false; |
| 187 |
if (!shouldPack(input, containers, inf)) { |
| 188 |
verbose = v; |
| 126 |
return; |
189 |
return; |
| 127 |
} |
190 |
} |
| 128 |
|
191 |
|
|
|
192 |
//mark as conditioned |
| 129 |
inf.put(Utils.MARK_PROPERTY, "true"); //$NON-NLS-1$ |
193 |
inf.put(Utils.MARK_PROPERTY, "true"); //$NON-NLS-1$ |
|
|
194 |
|
| 195 |
//record arguments used |
| 130 |
String arguments = inf.getProperty(Utils.PACK_ARGS); |
196 |
String arguments = inf.getProperty(Utils.PACK_ARGS); |
| 131 |
if (arguments == null) { |
197 |
if (arguments == null) { |
| 132 |
arguments = getOptions().getProperty(input.getName() + ".pack.args"); //$NON-NLS-1$ |
198 |
arguments = getArguments(input, inf, containers); |
| 133 |
if (arguments != null) |
199 |
if (arguments != null && arguments.length() > 0) |
| 134 |
inf.put(Utils.PACK_ARGS, arguments); |
200 |
inf.put(Utils.PACK_ARGS, arguments); |
| 135 |
} |
201 |
} |
| 136 |
} |
202 |
} |