KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > jarprocessor > PackUnpackStep


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.internal.jarprocessor;
12
13 import java.io.File JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Properties JavaDoc;
17 import java.util.Set JavaDoc;
18
19 /**
20  * @author aniefer@ca.ibm.com
21  *
22  */

23 public class PackUnpackStep extends PackStep {
24     private Set JavaDoc exclusions = null;
25
26     public PackUnpackStep(Properties JavaDoc options) {
27         super(options);
28         exclusions = Utils.getPackExclusions(options);
29     }
30
31     public PackUnpackStep(Properties JavaDoc options, boolean verbose) {
32         super(options, verbose);
33         exclusions = Utils.getPackExclusions(options);
34     }
35
36     public String JavaDoc recursionEffect(String JavaDoc entryName) {
37         if (canPack() && entryName.endsWith(".jar") && !exclusions.contains(entryName)) { //$NON-NLS-1$
38
return entryName;
39         }
40         return null;
41     }
42
43     /* (non-Javadoc)
44      * @see org.eclipse.update.internal.jarprocessor.PackStep#postProcess(java.io.File, java.io.File, java.util.LinkedList)
45      */

46     public File JavaDoc postProcess(File JavaDoc input, File JavaDoc workingDirectory, List JavaDoc containers) {
47         if (canPack() && packCommand != null && input != null) {
48             Properties JavaDoc inf = Utils.getEclipseInf(input, verbose);
49             if (!shouldPack(input, containers, inf))
50                 return null;
51             File JavaDoc tempFile = new File JavaDoc(workingDirectory, "temp_" + input.getName()); //$NON-NLS-1$
52
try {
53                 String JavaDoc[] tmp = getCommand(input, tempFile, inf, containers);
54                 String JavaDoc[] cmd = new String JavaDoc[tmp.length + 1];
55                 cmd[0] = tmp[0];
56                 cmd[1] = "-r"; //$NON-NLS-1$
57
System.arraycopy(tmp, 1, cmd, 2, tmp.length - 1);
58
59                 int result = execute(cmd, verbose);
60                 if (result == 0 && tempFile.exists()) {
61                     File JavaDoc finalFile = new File JavaDoc(workingDirectory, input.getName());
62                     if (finalFile.exists())
63                         finalFile.delete();
64                     tempFile.renameTo(finalFile);
65                     return finalFile;
66                 } else if (verbose) {
67                     System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd)); //$NON-NLS-1$ //$NON-NLS-2$
68
}
69             } catch (IOException JavaDoc e) {
70                 if (verbose)
71                     e.printStackTrace();
72                 return null;
73             }
74         }
75         return null;
76     }
77
78     /* (non-Javadoc)
79      * @see org.eclipse.update.internal.jarprocessor.PackStep#preProcess(java.io.File, java.io.File, java.util.LinkedList)
80      */

81     public File JavaDoc preProcess(File JavaDoc input, File JavaDoc workingDirectory, List JavaDoc containers) {
82         return null;
83     }
84
85     public String JavaDoc getStepName() {
86         return "Repack"; //$NON-NLS-1$
87
}
88 }
89
Popular Tags