[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ivy-commits
Subject:    Re: svn commit: r551867 - in /incubator/ivy/core/trunk: src/java/org/apache/ivy/core/ src/java/org/a
From:       "Gilles Scokart" <gscokart () gmail ! com>
Date:       2007-06-29 12:22:11
Message-ID: e9d8a2610706290522l3c50b9eat752f1a4c1af94e80 () mail ! gmail ! com
[Download RAW message or body]

I think I fixed the test.  But still, we might have a problem when the
file coming from a repository are updated because the Ressource
currently doesn't support relative url.

I can't go further for the moment, sorry.  (I have some baguage to prepare ;-) )

If you detect some other issues with my changes, don't hesitate to roll back.

Gilles

2007/6/29, gscokart@apache.org <gscokart@apache.org>:
> Author: gscokart
> Date: Fri Jun 29 05:16:12 2007
> New Revision: 551867
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=551867
> Log:
> refactoring to prepare support of relative url in XmlModuleDescriptorUpdater
> 
> Modified:
> incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java
> incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
>  incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java
>  incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs3.xml
>  incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-update.xml
>  
> Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java
>                 
> URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java?view=diff&rev=551867&r1=551866&r2=551867
>  ==============================================================================
> --- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java \
>                 (original)
> +++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java \
> Fri Jun 29 05:16:12 2007 @@ -26,8 +26,23 @@
> */
> public abstract class RelativeUrlResolver {
> 
> +    /**
> +     * Resolve the url in the context of context.
> +     * @param context The URL of the ressource containing the reference url
> +     * @param url a relative or absolution url string
> +     * @throws MalformedURLException
> +     */
> public abstract URL getURL(URL context , String url) throws MalformedURLException;
> 
> +    /**
> +     * Relsovle file or url path relatively to a context.  file is considered \
> first. +     * If file is not defined, url will be considered.
> +     * @param context The URL of the ressource containing the reference file or \
> url +     * @param file a relative or absolute path
> +     * @param url a relative or absolution url string
> +     * @return the resulting url or null if faile and url are null.
> +     * @throws MalformedURLException
> +     */
> public URL getURL(URL context, String file, String url) throws \
> MalformedURLException { if (file != null) {
> File f = new File(file);
> 
> Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
>                 
> URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/p \
> lugins/parser/xml/XmlModuleDescriptorUpdater.java?view=diff&rev=551867&r1=551866&r2=551867
>  ==============================================================================
> --- incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java \
>                 (original)
> +++ incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java \
> Fri Jun 29 05:16:12 2007 @@ -59,6 +59,7 @@
> * possible the original syntax
> */
> public class XmlModuleDescriptorUpdater {
> +    private static final int MAX_HEADER_LENGTH = 10000;
> public static String LINE_SEPARATOR = System.getProperty("line.separator");
> 
> /**
> @@ -87,10 +88,46 @@
> final Map resolvedRevisions, final String status, final String revision,
> final Date pubdate, final Namespace ns, final boolean replaceInclude,
> String[] confsToExclude) throws IOException, SAXException {
> -        update(settings, srcURL.openStream(), destFile, resolvedRevisions, status, \
>                 revision,
> -            pubdate, ns, replaceInclude, confsToExclude);
> +        if (destFile.getParentFile() != null) {
> +            destFile.getParentFile().mkdirs();
> +        }
> +        OutputStream destStream = new FileOutputStream(destFile);
> +        try {
> +            update(settings, srcURL, destStream, resolvedRevisions, status, \
> revision, +                pubdate, ns, replaceInclude, confsToExclude);
> +        } finally {
> +            try {
> +                destStream.close();
> +            } catch (IOException e) {
> +                Message.warn("failed to close a stream : " + e.toString());
> +            }
> +        }
> }
> 
> +    public static void update(final IvySettings settings, URL srcURL, OutputStream \
> destFile, +            final Map resolvedRevisions, final String status, final \
> String revision, +            final Date pubdate, final Namespace ns, final boolean \
> replaceInclude, +            String[] confsToExclude) throws IOException, \
> SAXException { +        InputStream in = srcURL.openStream();
> +        try {
> +            update(settings, srcURL, in, destFile, resolvedRevisions, status, \
> revision, +                pubdate, ns, replaceInclude, confsToExclude);
> +        } finally {
> +            try {
> +                in.close();
> +            } catch (IOException e) {
> +                Message.warn("failed to close a stream : " + e.toString());
> +            }
> +            try {
> +                destFile.close();
> +            } catch (IOException e) {
> +                Message.warn("failed to close a stream : " + e.toString());
> +            }
> +        }
> +
> +    }
> +
> +
> public static void update(final IvySettings settings, InputStream in, File \
> destFile, final Map resolvedRevisions, final String status, final String revision,
> final Date pubdate, final Namespace ns, final boolean replaceInclude,
> @@ -100,16 +137,19 @@
> }
> OutputStream fos = new FileOutputStream(destFile);
> try {
> -            update(settings, in, fos, resolvedRevisions, status, revision, \
> pubdate, ns, +            //TODO : the inputStream context should be given.
> +            update(settings, null, in, fos, resolvedRevisions, status, revision, \
> pubdate, ns, replaceInclude, confsToExclude);
> } finally {
> try {
> in.close();
> } catch (IOException e) {
> +                Message.warn("failed to close a stream : " + e.toString());
> }
> try {
> fos.close();
> } catch (IOException e) {
> +                Message.warn("failed to close a stream : " + e.toString());
> }
> }
> }
> @@ -136,10 +176,12 @@
> 
> private final List confs;
> 
> +        private final URL relativePathCtx;
> +
> public UpdaterHandler(final IvySettings settings, final PrintWriter out,
> final Map resolvedRevisions, final String status, final String revision,
> final Date pubdate, final Namespace ns, final boolean replaceInclude,
> -                final String[] confs) {
> +                final String[] confs, final URL relativePathCtx) {
> this.settings = settings;
> this.out = out;
> this.resolvedRevisions = resolvedRevisions;
> @@ -148,6 +190,7 @@
> this.pubdate = pubdate;
> this.ns = ns;
> this.replaceInclude = replaceInclude;
> +            this.relativePathCtx = relativePathCtx;
> if (confs != null) {
> this.confs = Arrays.asList(confs);
> } else {
> @@ -228,16 +271,26 @@
> }
> } else if (replaceInclude && "include".equals(qName)
> && _context.contains("configurations")) {
> +                //TODO, in the case of !replaceInclude, we should still replace \
> the relative path +                //by an absolute path.
> final ExtendedBuffer buffer = new ExtendedBuffer(getContext());
> _buffers.push(buffer);
> try {
> URL url;
> -                    String fileName = substitute(settings, \
>                 attributes.getValue("file"));
> -                    if (fileName == null) {
> -                        String urlStr = substitute(settings, \
>                 attributes.getValue("url"));
> -                        url = new URL(urlStr);
> +                    if (settings != null) {
> +                        url = \
> settings.getRelativeUrlResolver().getURL(relativePathCtx, +                         \
> settings.substitute(attributes.getValue("file")), +                            \
> settings.substitute(attributes.getValue("url"))); } else {
> -                        url = new File(fileName).toURL();
> +                        //TODO : settings can be null, but I don't why.
> +                        //Check if the next code is correct in that case
> +                        String fileName = attributes.getValue("file");
> +                        if (fileName == null) {
> +                            String urlStr = attributes.getValue("url");
> +                            url = new URL(urlStr);
> +                        } else {
> +                            url = new File(fileName).toURL();
> +                        }
> }
> XMLHelper.parse(url, null, new DefaultHandler() {
> boolean _insideConfigurations = false;
> @@ -606,28 +659,21 @@
> 
> }
> 
> -    public static void update(final IvySettings settings, InputStream inStream,
> -            OutputStream outStream, final Map resolvedRevisions, final String \
>                 status,
> -            final String revision, final Date pubdate, final Namespace ns,
> -            final boolean replaceInclude) throws IOException, SAXException {
> -        update(settings, inStream, outStream, resolvedRevisions, status, revision, \
>                 pubdate, ns,
> -            replaceInclude, null);
> -    }
> -
> -    public static void update(final IvySettings settings, InputStream inStream,
> +    public static void update(final IvySettings settings, URL inStreamCtx, \
> InputStream inStream, OutputStream outStream, final Map resolvedRevisions, final \
> String status, final String revision, final Date pubdate, final Namespace ns,
> -            final boolean replaceInclude, String[] confsToExclude) throws \
> IOException, SAXException { +            final boolean replaceInclude, String[] \
> confsToExclude) +            throws IOException, SAXException {
> final PrintWriter out = new PrintWriter(new OutputStreamWriter(outStream, \
> "UTF-8")); final BufferedInputStream in = new BufferedInputStream(inStream);
> 
> -        in.mark(10000); // assume the header is never larger than 10000 bytes.
> +        in.mark(MAX_HEADER_LENGTH); // assume the header is never larger than \
> 10000 bytes. copyHeader(in, out);
> in.reset(); // reposition the stream at the beginning
> 
> try {
> UpdaterHandler updaterHandler = new UpdaterHandler(settings, out, \
>                 resolvedRevisions,
> -                    status, revision, pubdate, ns, replaceInclude, \
> confsToExclude); +                    status, revision, pubdate, ns, \
> replaceInclude, confsToExclude, inStreamCtx); XMLHelper.parse(in, null, \
> updaterHandler, updaterHandler); } catch (ParserConfigurationException e) {
> IllegalStateException ise = new IllegalStateException(
> 
> Modified: incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java
>                 
> URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/ \
> plugins/parser/xml/XmlModuleUpdaterTest.java?view=diff&rev=551867&r1=551866&r2=551867
>  ==============================================================================
> --- incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java \
>                 (original)
> +++ incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java \
> Fri Jun 29 05:16:12 2007 @@ -23,6 +23,7 @@
> import java.io.File;
> import java.io.FileReader;
> import java.io.InputStreamReader;
> +import java.net.URL;
> import java.util.Arrays;
> import java.util.Date;
> import java.util.GregorianCalendar;
> @@ -82,9 +83,11 @@
> //file to test-configurations-import6.xml in order to use a path relative to
> //the execution directory.
> //But that may hidde a bug!
> -        XmlModuleDescriptorUpdater.update(new IvySettings(), \
>                 XmlModuleUpdaterTest.class
> -                .getResourceAsStream("test-configurations-import6.xml"), buffer, \
>                 new HashMap(),
> -            "release", "mynewrev", new Date(), null, true);
> +        URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/"
> +            + "test-configurations-import4.xml").toURL();
> +        XmlModuleDescriptorUpdater.update(new IvySettings(), settingsUrl, buffer, \
> new HashMap(), +            "release", "mynewrev", new Date(), null,
> +        true, null);
> 
> String updatedXml = buffer.toString();
> 
> @@ -95,9 +98,11 @@
> 
> public void testUpdateWithExcludeConfigurations1() throws Exception {
> ByteArrayOutputStream buffer = new ByteArrayOutputStream();
> -        XmlModuleDescriptorUpdater.update(new IvySettings(), \
>                 XmlModuleUpdaterTest.class
> -                .getResourceAsStream("test-update-excludedconfs1.xml"), buffer, \
>                 new HashMap(),
> -            "release", "mynewrev", new Date(), null, true, new String[] \
> {"myconf2"}); +        URL settingsUrl = new \
> File("test/java/org/apache/ivy/plugins/parser/xml/" +                + \
> "test-update-excludedconfs1.xml").toURL(); +        \
> XmlModuleDescriptorUpdater.update(new IvySettings(), settingsUrl, +            \
> buffer, new HashMap(), "release", "mynewrev", new Date(), null, true, +            \
> new String[] {"myconf2"}); 
> XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
> ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(),
> @@ -120,10 +125,12 @@
> 
> public void testUpdateWithExcludeConfigurations2() throws Exception {
> ByteArrayOutputStream buffer = new ByteArrayOutputStream();
> +        URL settingFile = new File("test/java/org/apache/ivy/plugins/parser/xml/"
> +            + "test-update-excludedconfs2.xml").toURL();
> try {
> -            XmlModuleDescriptorUpdater.update(new IvySettings(), \
>                 XmlModuleUpdaterTest.class
> -                    .getResourceAsStream("test-update-excludedconfs2.xml"), \
>                 buffer, new HashMap(),
> -                "release", "mynewrev", new Date(), null, true, new String[] \
> {"myconf2"}); +            XmlModuleDescriptorUpdater.update(new IvySettings(), \
> settingFile, buffer, +                new HashMap(), "release", "mynewrev", new \
> Date(), null, true, +                new String[] {"myconf2"});
> fail("IllegalArgumentException hasn't been thrown");
> } catch (IllegalArgumentException e) {
> // this is ok
> @@ -134,8 +141,10 @@
> 
> public void testUpdateWithExcludeConfigurations3() throws Exception {
> ByteArrayOutputStream buffer = new ByteArrayOutputStream();
> -        XmlModuleDescriptorUpdater.update(new IvySettings(), \
>                 XmlModuleUpdaterTest.class
> -                .getResourceAsStream("test-update-excludedconfs3.xml"), buffer, \
> new HashMap(), +        URL settingsUrl = new \
> File("test/java/org/apache/ivy/plugins/parser/xml/" +            + \
> "test-update-excludedconfs3.xml").toURL(); +
> +        XmlModuleDescriptorUpdater.update(new IvySettings(), settingsUrl, buffer, \
> new HashMap(), "release", "mynewrev", new Date(), null, true, new String[] \
> {"myconf2", "conf2"}); 
> XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
> @@ -161,8 +170,9 @@
> 
> public void testUpdateWithExcludeConfigurations4() throws Exception {
> ByteArrayOutputStream buffer = new ByteArrayOutputStream();
> -        XmlModuleDescriptorUpdater.update(new IvySettings(), \
>                 XmlModuleUpdaterTest.class
> -                .getResourceAsStream("test-update-excludedconfs4.xml"), buffer, \
> new HashMap(), +        URL settingsUrl = new \
> File("test/java/org/apache/ivy/plugins/parser/xml/" +            + \
> "test-update-excludedconfs4.xml").toURL(); +        \
> XmlModuleDescriptorUpdater.update(new IvySettings(), settingsUrl, buffer, new \
> HashMap(), "release", "mynewrev", new Date(), null, true, new String[] \
> {"myconf2"}); 
> XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
> @@ -186,8 +196,9 @@
> 
> public void testUpdateWithExcludeConfigurations5() throws Exception {
> ByteArrayOutputStream buffer = new ByteArrayOutputStream();
> -        XmlModuleDescriptorUpdater.update(new IvySettings(), \
>                 XmlModuleUpdaterTest.class
> -                .getResourceAsStream("test-update-excludedconfs5.xml"), buffer, \
> new HashMap(), +        URL settingsUrl = new \
> File("test/java/org/apache/ivy/plugins/parser/xml/" +            + \
> "test-update-excludedconfs5.xml").toURL(); +        \
> XmlModuleDescriptorUpdater.update(new IvySettings(), settingsUrl, buffer, new \
> HashMap(), "release", "mynewrev", new Date(), null, true, new String[] \
> {"myconf2"}); 
> XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
> 
> Modified: incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs3.xml
>                 
> URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/ \
> plugins/parser/xml/test-update-excludedconfs3.xml?view=diff&rev=551867&r1=551866&r2=551867
>  ==============================================================================
> --- incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs3.xml \
>                 (original)
> +++ incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs3.xml \
> Fri Jun 29 05:16:12 2007 @@ -25,7 +25,7 @@
> status="integration"
> publication="20041101110000" />
> <configurations>
> -               <include \
> file="test/java/org/apache/ivy/plugins/parser/xml/imported-configurations.xml"/> +  \
> <include file="imported-configurations.xml"/> <conf name="myconf1" \
> description="desc 1"/> <conf name="myconf2" description="desc 2" \
> visibility="public"/> <conf name="myconf3" description="desc 3" \
> visibility="private"/> 
> Modified: incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-update.xml
>                 
> URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-update.xml?view=diff&rev=551867&r1=551866&r2=551867
>  ==============================================================================
> --- incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-update.xml \
>                 (original)
> +++ incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-update.xml \
> Fri Jun 29 05:16:12 2007 @@ -40,7 +40,7 @@
> </description>
> </info>
> <configurations>
> -               <include \
> file="test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-mapping.xml"/>
>  +               <include file="imported-configurations-with-mapping.xml"/>
> <conf name="${myvar}" description="desc 1"/>
> <conf name="myconf2" description="desc 2" visibility="public"/>
> <conf name="myconf3" description="desc 3" visibility="private"/>
> 
> 
> 


-- 
Gilles SCOKART


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic