You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by re...@apache.org on 2010/08/13 07:31:04 UTC
svn commit: r985098 -
/harmony/enhanced/java/trunk/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/jar/Main.java
Author: regisxu
Date: Fri Aug 13 05:31:03 2010
New Revision: 985098
URL: http://svn.apache.org/viewvc?rev=985098&view=rev
Log:
Apply patch for HARMONY-6622: [jdktools][jar]jar command throws FileNotFoundException when creating jar file with absolute file path
Modified:
harmony/enhanced/java/trunk/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/jar/Main.java
Modified: harmony/enhanced/java/trunk/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/jar/Main.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/jar/Main.java?rev=985098&r1=985097&r2=985098&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/jar/Main.java (original)
+++ harmony/enhanced/java/trunk/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/jar/Main.java Fri Aug 13 05:31:03 2010
@@ -128,7 +128,6 @@ public class Main {
zos = new ZipOutputStream(new FileOutputStream(new File(args[1])));
}
- String workingDir = System.getProperty("user.dir");
int firstFileIndex = 0;
if (manifestFlag) {
firstFileIndex = 3;
@@ -139,11 +138,11 @@ public class Main {
// Assume that all the args following the manifest (if provided) are the name of files to add to the archive
for (int i=firstFileIndex; i < args.length; i++) {
// attempt to add the file to the output stream
- File f = new File(workingDir + File.separator + args[i]);
+ File f = new File(args[i]);
if (f.isDirectory()) {
- processDir(f, zos, workingDir, verboseFlag);
+ processDir(f, zos, verboseFlag);
} else {
- processFile(f, zos, workingDir, verboseFlag);
+ processFile(f, zos, verboseFlag);
}
}
@@ -197,7 +196,6 @@ public class Main {
// Read the zip entries - format and print their data
ZipEntry ze;
- String workingDir = System.getProperty("user.dir");
while ((ze = zis.getNextEntry()) != null) {
if (ze.isDirectory()) {
@@ -211,7 +209,7 @@ public class Main {
}
} else {
// extract the file to the appropriate directory
- File f = new File(workingDir + File.separator + ze.getName());
+ File f = new File(ze.getName());
f.createNewFile();
FileOutputStream fos = new FileOutputStream(f);
int i;
@@ -288,12 +286,12 @@ public class Main {
System.out.println("Error: Jar indexing not yet implemented");
}
- private static void processDir(File dir, ZipOutputStream zos, String workingDir, boolean verboseFlag) throws IOException {
+ private static void processDir(File dir, ZipOutputStream zos, boolean verboseFlag) throws IOException {
// First add the dir to the ZipOutputStream
- String relativePath = dir.getAbsolutePath().substring(workingDir.length() + 1);
- ZipEntry zEntry = new ZipEntry(relativePath);
+ String path = dir.getPath().replace('\\', '/') + "/";
+ ZipEntry zEntry = new ZipEntry(path);
if (verboseFlag) {
- System.out.println("adding: " + relativePath);
+ System.out.println("adding: " + path);
}
zos.putNextEntry(zEntry);
@@ -302,22 +300,22 @@ public class Main {
for (int i=0; i < filesInDir.length; i++) {
File curFile = filesInDir[i];
if (curFile.isDirectory()) {
- processDir(curFile, zos, workingDir, verboseFlag);
+ processDir(curFile, zos, verboseFlag);
} else {
- processFile(curFile, zos, workingDir, verboseFlag);
+ processFile(curFile, zos, verboseFlag);
}
}
zos.closeEntry();
}
- private static void processFile(File file, ZipOutputStream zos, String workingDir, boolean verboseFlag) throws IOException {
- String relativePath = file.getAbsolutePath().substring(workingDir.length() + 1);
+ private static void processFile(File file, ZipOutputStream zos, boolean verboseFlag) throws IOException {
+ String path = file.getPath().replace('\\', '/');
if (verboseFlag) {
- System.out.println("adding: " + relativePath);
+ System.out.println("adding: " + path);
}
- ZipEntry zEntry = new ZipEntry(relativePath);
+ ZipEntry zEntry = new ZipEntry(path);
zos.putNextEntry(zEntry);
// now write the data
FileInputStream fis = new FileInputStream(file);