FileDocCategorySizeDatePackage
JarTest.javaAPI DocApache Ant 1.709133Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs

JarTest

public class JarTest extends org.apache.tools.ant.BuildFileTest

Fields Summary
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
Utilities used for file operations
private static String
tempJar
private static String
tempDir
private Reader
r1
private Reader
r2
Constructors Summary
public JarTest(String name)


       
        super(name);
    
Methods Summary
public voidsetUp()

        configureProject("src/etc/testcases/taskdefs/jar.xml");
    
public voidtearDown()

        if (r1 != null) {
            try {
                r1.close();
            } catch (IOException e) {
            }
        }
        if (r2 != null) {
            try {
                r2.close();
            } catch (IOException e) {
            }
        }

        executeTarget("cleanup");
    
public voidtest1()

        expectBuildException("test1", "required argument not specified");
    
public voidtest2()

        expectBuildException("test2", "manifest file does not exist");
    
public voidtest3()

        expectBuildException("test3", "Unrecognized whenempty attribute: format C: /y");
    
public voidtest4()

        executeTarget("test4");
        File jarFile = new File(getProjectDir(), tempJar);
        assertTrue(jarFile.exists());
    
public voidtestCreateWithEmptyFileset()

        executeTarget("testCreateWithEmptyFilesetSetUp");
        executeTarget("testCreateWithEmptyFileset");
        executeTarget("testCreateWithEmptyFileset");
    
public voidtestIndexJarsPlusJarMarker()

        executeTarget("testIndexJarsPlusJarMarker");
    
public voidtestManifestOnlyJar()

        expectLogContaining("testManifestOnlyJar", "Building MANIFEST-only jar: ");
        File manifestFile = getProject().resolveFile(tempDir + "META-INF" + File.separator + "MANIFEST.MF");
        assertTrue(manifestFile.exists());
    
public voidtestManifestStaysIntact()

        executeTarget("testManifestStaysIntact");

        r1 = new FileReader(getProject()
                            .resolveFile(tempDir + "manifest"));
        r2 = new FileReader(getProject()
                            .resolveFile(tempDir + "META-INF/MANIFEST.MF"));
        Manifest mf1 = new Manifest(r1);
        Manifest mf2 = new Manifest(r2);
        assertEquals(mf1, mf2);
    
public voidtestNoDuplicateIndex()

        ZipFile archive = null;
        try {
            executeTarget("testIndexTests");
            archive = new ZipFile(getProject().resolveFile(tempJar));
            Enumeration e = archive.entries();
            int numberOfIndexLists = 0;
            while (e.hasMoreElements()) {
                ZipEntry ze = (ZipEntry) e.nextElement();
                if (ze.getName().equals("META-INF/INDEX.LIST")) {
                    numberOfIndexLists++;
                }
            }
            assertEquals(1, numberOfIndexLists);
        } finally {
            if (archive != null) {
                archive.close();
            }
        }
    
private voidtestNoRecreate(java.lang.String secondTarget)

        executeTarget("test4");
        File jarFile = new File(getProjectDir(), tempJar);
        long jarModifiedDate = jarFile.lastModified();
        try {
            Thread.sleep(2500);
        } catch (InterruptedException e) {
        } // end of try-catch
        executeTarget(secondTarget);
        assertEquals("jar has not been recreated in " + secondTarget,
                     jarModifiedDate, jarFile.lastModified());
    
public voidtestNoRecreateBasedirExcludesWithUpdate()

        testNoRecreate("testNoRecreateBasedirExcludesWithUpdate");
    
public voidtestNoRecreateBasedirExcludesWithoutUpdate()

        testNoRecreate("testNoRecreateBasedirExcludesWithoutUpdate");
    
public voidtestNoRecreateWithUpdate()

        testNoRecreate("testNoRecreateWithUpdate");
    
public voidtestNoRecreateWithoutUpdate()

        testNoRecreate("test4");
    
public voidtestNoRecreateZipfilesetExcludesWithUpdate()

        testNoRecreate("testNoRecreateZipfilesetExcludesWithUpdate");
    
public voidtestNoRecreateZipfilesetExcludesWithoutUpdate()

        testNoRecreate("testNoRecreateZipfilesetExcludesWithoutUpdate");
    
private voidtestRecreate(java.lang.String firstTarget, java.lang.String secondTarget)

        executeTarget(firstTarget);
        long sleeptime = 3000
            + FILE_UTILS.getFileTimestampGranularity();
        try {
            Thread.sleep(sleeptime);
        } catch (InterruptedException e) {
        } // end of try-catch
        File jarFile = new File(getProjectDir(), tempJar);
        long jarModifiedDate = jarFile.lastModified();
        executeTarget(secondTarget);
        jarFile = new File(getProjectDir(), tempJar);
        assertTrue("jar has been recreated in " + secondTarget,
                   jarModifiedDate < jarFile.lastModified());
    
public voidtestRecreateWithUpdateAdditionalFiles()

        testRecreate("test4", "testRecreateWithUpdateAdditionalFiles");
    
public voidtestRecreateWithUpdateNewerFile()

        testRecreate("testRecreateNewerFileSetup",
                     "testRecreateWithUpdateNewerFile");
    
public voidtestRecreateWithoutUpdateAdditionalFiles()

        testRecreate("test4", "testRecreateWithoutUpdateAdditionalFiles");
    
public voidtestRecreateWithoutUpdateNewerFile()

        testRecreate("testRecreateNewerFileSetup",
                     "testRecreateWithoutUpdateNewerFile");
    
public voidtestRecreateZipfilesetWithUpdateAdditionalFiles()

        testRecreate("test4",
                     "testRecreateZipfilesetWithUpdateAdditionalFiles");
    
public voidtestRecreateZipfilesetWithUpdateNewerFile()

        testRecreate("testRecreateNewerFileSetup",
                     "testRecreateZipfilesetWithUpdateNewerFile");
    
public voidtestRecreateZipfilesetWithoutUpdateAdditionalFiles()

        testRecreate("test4",
                     "testRecreateZipfilesetWithoutUpdateAdditionalFiles");
    
public voidtestRecreateZipfilesetWithoutUpdateNewerFile()

        testRecreate("testRecreateNewerFileSetup",
                     "testRecreateZipfilesetWithoutUpdateNewerFile");
    
public voidtestRootFilesInIndex()

        ZipFile archive = null;
        try {
            executeTarget("testIndexTests");
            archive = new ZipFile(getProject().resolveFile(tempJar));
            ZipEntry ze = archive.getEntry("META-INF/INDEX.LIST");
            InputStream is = archive.getInputStream(ze);
            BufferedReader r = new BufferedReader(new InputStreamReader(is,
                                                                        "UTF8"));
            boolean foundSub = false;
            boolean foundSubFoo = false;
            boolean foundFoo = false;

            String line = r.readLine();
            while (line != null) {
                if (line.equals("foo")) {
                    foundFoo = true;
                } else if (line.equals("sub")) {
                    foundSub = true;
                } else if (line.equals("sub/foo")) {
                    foundSubFoo = true;
                }
                line = r.readLine();
            }

            assertTrue(foundSub);
            assertTrue(!foundSubFoo);
            assertTrue(foundFoo);
        } finally {
            if (archive != null) {
                archive.close();
            }
        }
    
public voidtestUpdateIfOnlyManifestHasChanged()

        executeTarget("testUpdateIfOnlyManifestHasChanged");
        File jarXml = getProject().resolveFile(tempDir + "jar.xml");
        assertTrue(jarXml.exists());