[shrinkwrap-issues] [JBoss JIRA] (SHRINKWRAP-388) Adding an Asset to already existing ArchivePath is silently ignored

Karel Piwko (JIRA) jira-events at lists.jboss.org
Tue Feb 28 14:57:36 EST 2012


Karel Piwko created SHRINKWRAP-388:
--------------------------------------

             Summary: Adding an Asset to already existing ArchivePath is silently ignored
                 Key: SHRINKWRAP-388
                 URL: https://issues.jboss.org/browse/SHRINKWRAP-388
             Project: ShrinkWrap
          Issue Type: Bug
          Components: impl-base
    Affects Versions: 1.0.0-cr-3
            Reporter: Karel Piwko
            Priority: Critical


When trying to include a Asset to already existing Archive path simply does nothing. Also if user does merge of two archives, it makes the operation order dependent.

Solutions:

1. Trying to include an Asset to already existing path should fail. For merge, there might be an optional override property

2. Override and make this behavior documented. Probably log a warning.

Test case:

{code}
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;

import junit.framework.Assert;

import org.apache.commons.io.IOUtils;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ArchivePath;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;

public class SimpleTest {

    @Test
    // fails
    public void simple() throws Exception {
        JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
                .add(new StringAsset("foo"), ArchivePaths.create("resources/foo"))
                .add(new StringAsset("bar"), ArchivePaths.create("resources/foo"));

        // here it should either fail fast before or contain bar
        Assert.assertEquals("Expecting bar", "bar", getContent(jar, ArchivePaths.create("resources/foo")));
    }

    @Test
    // fails
    public void mergeJar1Jar2() throws Exception {
        JavaArchive jar1 = ShrinkWrap.create(JavaArchive.class).add(new StringAsset("foo"),
                ArchivePaths.create("resources/foo"));

        JavaArchive jar2 = ShrinkWrap.create(JavaArchive.class).add(new StringAsset("bar"),
                ArchivePaths.create("resources/foo"));

        JavaArchive jar = jar1.merge(jar2);

        // here it should either fail or contain bar
        Assert.assertEquals("Expecting bar", "bar", getContent(jar, ArchivePaths.create("resources/foo")));
    }

    @Test
    // passes
    public void mergeJar2Jar1() throws Exception {
        JavaArchive jar1 = ShrinkWrap.create(JavaArchive.class).add(new StringAsset("foo"),
                ArchivePaths.create("resources/foo"));

        JavaArchive jar2 = ShrinkWrap.create(JavaArchive.class).add(new StringAsset("bar"),
                ArchivePaths.create("resources/foo"));

        JavaArchive jar = jar2.merge(jar1);

        // here it should either fail or contain bar
        Assert.assertEquals("Expecting bar", "bar", getContent(jar, ArchivePaths.create("resources/foo")));
    }

    private String getContent(Archive<?> archive, ArchivePath path) throws IOException {
        InputStream is = archive.get(path).getAsset().openStream();
        StringWriter w = new StringWriter();
        IOUtils.copy(is, w);
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(w);

        return w.toString();
    }
}
{code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the shrinkwrap-issues mailing list