Skip to content

Commit

Permalink
0000660: Created war file has bogus ../war directory entry that cause…
Browse files Browse the repository at this point in the history
…s errors in Tomcat 7.0
  • Loading branch information
chenson42 committed Jun 21, 2012
1 parent 2f01731 commit c86cf44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
Expand Up @@ -16,7 +16,8 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License. */
* under the License.
*/

package org.jumpmind.symmetric.util;

Expand Down Expand Up @@ -63,8 +64,16 @@ public void build() throws IOException {

private String massageJarEntryName(File source) {
String name = source.getPath();
if (baseDir != null && name.startsWith(baseDir.getPath()) && name.length() > baseDir.getPath().length()) {
name = name.substring(baseDir.getPath().length()+1);
if (baseDir != null && name.startsWith(baseDir.getPath())) {
if (name.length() > baseDir.getPath().length()) {
name = name.substring(baseDir.getPath().length() + 1);
} else {
name = "";
}
}

if (name.equals("META-INF/MANIFEST.MF")) {
name = "";
}
return name.replace("\\", "/");
}
Expand Down
Expand Up @@ -29,9 +29,6 @@
import org.apache.commons.io.FileUtils;
import org.junit.Test;

/**
*
*/
public class JarBuilderUnitTest {

@Test
Expand All @@ -42,23 +39,27 @@ public void testJarCreation() throws Exception {
Assert.assertFalse(outputFile.exists());

FileUtils.deleteDirectory(new File(TEST_JAR_DIR));

mkdir(TEST_JAR_DIR + "/subdir");
mkdir(TEST_JAR_DIR + "/META-INF");
emptyFile(TEST_JAR_DIR + "/META-INF/MANIFEST.MF");
emptyFile(TEST_JAR_DIR + "/subdir/file2.txt");
emptyFile(TEST_JAR_DIR + "/file2.txt");
emptyFile("target/file1.txt");
emptyFile(TEST_JAR_DIR + "/file3.txt");

JarBuilder jarFile = new JarBuilder(new File("target"), outputFile, new File[] { new File(TEST_JAR_DIR), new File("target/file1.txt") });
JarBuilder jarFile = new JarBuilder(new File(TEST_JAR_DIR), outputFile, new File[] { new File(TEST_JAR_DIR), new File("target/file1.txt") });
jarFile.build();

Assert.assertTrue(outputFile.exists());

JarFile finalJar = new JarFile(outputFile);
Assert.assertNotNull(finalJar.getEntry("test.jar.dir/subdir/file2.txt"));
Assert.assertNotNull(finalJar.getEntry("test.jar.dir/file2.txt"));
Assert.assertNotNull(finalJar.getEntry("test.jar.dir/file2.txt"));
Assert.assertNotNull(finalJar.getEntry("file1.txt"));
Assert.assertNotNull(finalJar.getEntry("file1.txt"));
Assert.assertNotNull(finalJar.getEntry("subdir/file2.txt"));
Assert.assertNotNull(finalJar.getEntry("file2.txt"));
Assert.assertNull(finalJar.getEntry("target/test.jar.dir"));
Assert.assertNull(finalJar.getEntry("test.jar.dir"));
Assert.assertNull(finalJar.getEntry("file1.txt"));
Assert.assertNotNull(finalJar.getEntry("file3.txt"));
}

private void mkdir(String dir) {
Expand Down

0 comments on commit c86cf44

Please sign in to comment.