Author: xavier
Date: Tue Nov 13 04:51:28 2007
New Revision: 594518

URL: http://svn.apache.org/viewvc?rev=594518&view=rev
Log:
NEW: Add a task/code to create M2 POM files from Ivy configurations (IVY-416)

Added:
    incubator/ivy/core/trunk/doc/use/makepom.html   (with props)
    incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java   
(with props)
    
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
   (with props)
    
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java
   (with props)
    
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/license.xml 
  (with props)
    
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-dependencies-optional.xml
   (with props)
    
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-dependencies-with-scope.xml
   (with props)
    
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-simple-dependencies.xml
   (with props)
    
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-simple.xml
   (with props)
Modified:
    incubator/ivy/core/trunk/CHANGES.txt
    incubator/ivy/core/trunk/build.xml
    incubator/ivy/core/trunk/doc/toc.json
    incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/antlib.xml

Modified: incubator/ivy/core/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/CHANGES.txt?rev=594518&r1=594517&r2=594518&view=diff
==============================================================================
--- incubator/ivy/core/trunk/CHANGES.txt (original)
+++ incubator/ivy/core/trunk/CHANGES.txt Tue Nov 13 04:51:28 2007
@@ -77,6 +77,8 @@
 - IMPROVEMENT: Improvements on hello ivy example (IVY-626) (with contribution 
from Jacob Grydholt Jensen)
 - IMPROVEMENT: Make the root attribute in the ivyrep resolver mandatory 
(IVY-625)
 
+- NEW: Add a task/code to create M2 POM files from Ivy configurations (IVY-416)
+
 - REFACTORING: Extract a settings interface for the different engines
 
 

Modified: incubator/ivy/core/trunk/build.xml
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/build.xml?rev=594518&r1=594517&r2=594518&view=diff
==============================================================================
--- incubator/ivy/core/trunk/build.xml (original)
+++ incubator/ivy/core/trunk/build.xml Tue Nov 13 04:51:28 2007
@@ -322,6 +322,14 @@
         <!-- clean generated module properties file -->
         <delete file="${core.classes.build.dir}/module.properties" />
     </target>
+       
+       <target name="makepom" depends="init-ivy">
+        <!-- TODO: use this to prepare a deployment to maven 2 repository -->
+               <ivy:makepom ivyfile="${basedir}/ivy.xml" 
pomfile="${basedir}/ivy.pom">
+                       <mapping conf="core" scope="compile"/>
+                       <mapping conf="test" scope="test"/>
+               </ivy:makepom>
+       </target>
 
     <!-- =================================================================
          PUBLISH LOCAL

Modified: incubator/ivy/core/trunk/doc/toc.json
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/doc/toc.json?rev=594518&r1=594517&r2=594518&view=diff
==============================================================================
--- incubator/ivy/core/trunk/doc/toc.json (original)
+++ incubator/ivy/core/trunk/doc/toc.json Tue Nov 13 04:51:28 2007
@@ -634,6 +634,13 @@
                             ]
                         },
                         {
+                          "id":"use/makepom",
+                          "title":"makepom",
+                          "children": [
+
+                            ]
+                        },
+                        {
                           "id":"use/postresolvetask",
                           "title":"post resolve tasks",
                           "children": [

Added: incubator/ivy/core/trunk/doc/use/makepom.html
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/doc/use/makepom.html?rev=594518&view=auto
==============================================================================
--- incubator/ivy/core/trunk/doc/use/makepom.html (added)
+++ incubator/ivy/core/trunk/doc/use/makepom.html Tue Nov 13 04:51:28 2007
@@ -0,0 +1,72 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
"http://www.w3.org/TR/html4/strict.dtd";>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "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.    
+-->
+<html>
+<head>
+       <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
+       <script type="text/javascript">var xookiConfig = {level: 1};</script>   
+       <script type="text/javascript" src="../xooki/xooki.js"></script>
+</head>
+<body>
+       <textarea id="xooki-source">
+<span class="since">since 2.0</span>
+The makepom task allows to convert an ivy file to a pom file.
+
+An example of use is to publish an Ivy managed module to a maven 2 repository.
+
+<em>Note that all Ivy features are not supported by maven poms, so the 
converted pom may not resolve to the exact same dependencies as the original 
ivy file.</em>
+
+<h1>Attributes</h1>
+<table class="ant">
+<thead>
+    <tr><th class="ant-att">Attribute</th><th 
class="ant-desc">Description</th><th class="ant-req">Required</th></tr>
+</thead>
+<tbody>
+    <tr><td>ivyfile</td><td>the source ivy file to convert</td>
+        <td>Yes</td></tr>
+    <tr><td>pomfile</td><td>the destination pom file to write</td>
+        <td>Yes</td></tr>
+<tr><td>settingsRef</td><td>A reference to the ivy settings that must be used 
by this task</td><td>No, 'ivy.instance' is taken by default.</td></tr>
+</tbody>
+</table>
+<h1>Child elements</h1>
+<table class="ivy-children">
+<thead>
+    <tr><th class="ivy-chld">Element</th><th 
class="ivy-chld-desc">Description</th><th 
class="ivy-chld-card">Cardinality</th></tr>
+</thead>
+<tbody>
+    <tr><td>mapping</td>
+        <td>describes the mapping from an Ivy configuration to a POM 
scope.<br/>These elements takes two attributes: <ul><li>conf</li> the 
configuration to map<li>scope</li>the scope to which it should be 
mapped</ul></td>
+        <td>0..n</td></tr>
+</tbody>
+</table>
+
+<h1>Examples</h1>
+<code type="xml">
+<ivy:makepom ivyfile="${basedir}/path/to/ivy.xml" 
pomfile="${basedir}/path/to/module.pom">
+   <mapping conf="default" scope="compile"/>
+   <mapping conf="runtime" scope="runtime"/>
+</ivy:makepom>
+</code>
+Converts ${basedir}/path/to/ivy.xml to a pom and writes the result to 
${basedir}/path/to/module.pom. The configuration 'default' in the parsed ivy 
file will be mapped to the scope 'compile', the configuration 'runtime' will be 
mapped to 'runtime', and other configurations will be considered optional.
+
+       </textarea>
+<script type="text/javascript">xooki.postProcess();</script>
+</body>
+</html>

Propchange: incubator/ivy/core/trunk/doc/use/makepom.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java?rev=594518&view=auto
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java (added)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java Tue 
Nov 13 04:51:28 2007
@@ -0,0 +1,120 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "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.
+ *
+ */
+package org.apache.ivy.ant;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
+import org.apache.ivy.core.settings.IvySettings;
+import org.apache.ivy.plugins.parser.m2.PomModuleDescriptorWriter;
+import 
org.apache.ivy.plugins.parser.m2.PomModuleDescriptorWriter.ConfigurationScopeMapping;
+import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+
+/**
+ * Convert an ivy file to a pom
+ */
+public class IvyMakePom extends IvyTask {
+    public class Mapping {
+        private String conf;
+        private String scope;
+        public String getConf() {
+            return conf;
+        }
+        public void setConf(String conf) {
+            this.conf = conf;
+        }
+        public String getScope() {
+            return scope;
+        }
+        public void setScope(String scope) {
+            this.scope = scope;
+        }
+    }
+
+    private File pomFile = null;
+
+    private File ivyFile = null;
+
+    private Collection mappings = new ArrayList();
+
+    public File getPomFile() {
+        return pomFile;
+    }
+
+    public void setPomFile(File file) {
+        pomFile = file;
+    }
+
+    public File getIvyFile() {
+        return ivyFile;
+    }
+
+    public void setIvyFile(File ivyFile) {
+        this.ivyFile = ivyFile;
+    }
+    
+    public Mapping createMapping() {
+        Mapping mapping = new Mapping();
+        this.mappings.add(mapping);
+        return mapping;
+    }
+    
+    public void doExecute() throws BuildException {
+        try {
+            if (ivyFile == null) {
+                throw new BuildException("source ivy file is required for 
makepom task");
+            }
+            if (pomFile == null) {
+                throw new BuildException("destination pom file is required for 
makepom task");
+            }
+            ModuleDescriptor md = 
XmlModuleDescriptorParser.getInstance().parseDescriptor(
+                new IvySettings(), ivyFile.toURL(), false);
+            PomModuleDescriptorWriter.write(md, 
+                mappings.isEmpty() 
+                    ? PomModuleDescriptorWriter.DEFAULT_MAPPING
+                    : new ConfigurationScopeMapping(getMappingsMap()), 
pomFile);
+        } catch (MalformedURLException e) {
+            throw new BuildException("unable to convert given ivy file to url: 
" + ivyFile + ": "
+                    + e, e);
+        } catch (ParseException e) {
+            log(e.getMessage(), Project.MSG_ERR);
+            throw new BuildException("syntax errors in ivy file " + ivyFile + 
": " + e, e);
+        } catch (Exception e) {
+            throw new BuildException("impossible convert given ivy file to pom 
file: " + e
+                    + " from=" + ivyFile + " to=" + pomFile, e);
+        }
+    }
+
+    private Map getMappingsMap() {
+        Map mappingsMap = new HashMap();
+        for (Iterator iter = mappings.iterator(); iter.hasNext();) {
+            Mapping mapping = (Mapping) iter.next();
+            mappingsMap.put(mapping.getConf(), mapping.getScope());
+        }
+        return mappingsMap;
+    }
+}

Propchange: incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/antlib.xml
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/antlib.xml?rev=594518&r1=594517&r2=594518&view=diff
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/antlib.xml (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/antlib.xml Tue Nov 13 
04:51:28 2007
@@ -35,6 +35,7 @@
        <taskdef name="buildlist" classname="org.apache.ivy.ant.IvyBuildList"/>
        <taskdef name="install" classname="org.apache.ivy.ant.IvyInstall"/>
        <taskdef name="convertpom" 
classname="org.apache.ivy.ant.IvyConvertPom"/>
+       <taskdef name="makepom" classname="org.apache.ivy.ant.IvyMakePom"/>
        <taskdef name="artifactreport" 
classname="org.apache.ivy.ant.IvyArtifactReport"/>
        <taskdef name="info" classname="org.apache.ivy.ant.IvyInfo"/>
        <taskdef name="addpath" classname="org.apache.ivy.ant.AddPathTask"/>

Added: 
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java?rev=594518&view=auto
==============================================================================
--- 
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
 (added)
+++ 
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
 Tue Nov 13 04:51:28 2007
@@ -0,0 +1,136 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "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.
+ *
+ */
+package org.apache.ivy.plugins.parser.m2;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
+import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.util.StringUtils;
+
+public final class PomModuleDescriptorWriter {
+    private PomModuleDescriptorWriter() {
+    }
+    
+    public static void write(ModuleDescriptor md, 
+            ConfigurationScopeMapping mapping, File output) throws IOException 
{
+        write(md, null, mapping, output);
+    }
+
+    public static void write(ModuleDescriptor md, 
+            String licenseHeader, ConfigurationScopeMapping mapping, File 
output)
+            throws IOException {
+        if (output.getParentFile() != null) {
+            output.getParentFile().mkdirs();
+        }
+        PrintWriter out = new PrintWriter(new OutputStreamWriter(new 
FileOutputStream(output),
+                "UTF-8"));
+        try {
+            out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+            if (licenseHeader != null) {
+                out.print(licenseHeader);
+            }
+            out.println("<project xmlns=\"http://maven.apache.org/POM/4.0.0\"; "
+                    + 
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";);
+            out.println("    
xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 "
+                    + "http://maven.apache.org/maven-v4_0_0.xsd\";>\n");
+            out.println("  <modelVersion>4.0.0</modelVersion>");
+            printModuleId(md, out);
+            printDependencies(md, mapping, out);
+            out.println("</project>");
+        } finally {
+            out.close();
+        }
+    }
+
+    private static void printModuleId(ModuleDescriptor md, PrintWriter out) {
+        ModuleRevisionId mrid = md.getModuleRevisionId();
+        out.println("  <groupId>" + mrid.getOrganisation() + "</groupId>");
+        out.println("  <artifactId>" + mrid.getName() + "</artifactId>");
+        out.println("  <packaging>jar</packaging>");
+        if (mrid.getRevision() != null) {
+            out.println("  <version>" + mrid.getRevision() + "</version>");
+        }
+        if (md.getHomePage() != null) {
+            out.println("  <url>" + md.getHomePage() + "</url>");
+        }
+    }
+
+    private static void printDependencies(
+            ModuleDescriptor md, ConfigurationScopeMapping mapping, 
PrintWriter out) {
+        DependencyDescriptor[] dds = md.getDependencies();
+        if (dds.length > 0) {
+            out.println("  <dependencies>");
+            for (int i = 0; i < dds.length; i++) {
+                ModuleRevisionId mrid = dds[i].getDependencyRevisionId();
+                out.println("    <dependency>");
+                out.println("      <groupId>" + mrid.getOrganisation() + 
"</groupId>");
+                out.println("      <artifactId>" + mrid.getName() + 
"</artifactId>");
+                out.println("      <version>" + mrid.getRevision() + 
"</version>");
+                String scope = 
mapping.getScope(dds[i].getModuleConfigurations());
+                if (scope != null) {
+                    out.println("      <scope>" + scope + "</scope>");
+                }
+                if (mapping.isOptional(dds[i].getModuleConfigurations())) {
+                    out.println("      <optional/>");
+                }
+                out.println("    </dependency>");
+            }
+            out.println("  </dependencies>");
+        }
+    }
+    
+    public static final ConfigurationScopeMapping DEFAULT_MAPPING 
+        = new ConfigurationScopeMapping(new HashMap() {
+            {
+                put("compile, runtime", "compile");
+                put("runtime", "runtime");
+                put("provided", "provided");
+                put("test", "test");
+                put("system", "system");
+            }
+        });
+
+    public static class ConfigurationScopeMapping {
+        private Map/*<String,String>*/ scopes;
+        
+        public ConfigurationScopeMapping(Map/*<String,String>*/ scopesMapping) 
{
+            this.scopes = new HashMap(scopesMapping);
+        }
+
+        /**
+         * Returns the scope mapped to the given configuration array.
+         * 
+         * @param confs the configurations for which the scope should be 
returned
+         * @return the scope to which the conf is mapped
+         */
+        public String getScope(String[] confs) {
+            return (String) scopes.get(StringUtils.join(confs, ", "));
+        }
+        public boolean isOptional(String[] confs) {
+            return getScope(confs) == null;
+        }
+    }
+}

Propchange: 
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java?rev=594518&view=auto
==============================================================================
--- 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java
 (added)
+++ 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java
 Tue Nov 13 04:51:28 2007
@@ -0,0 +1,115 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "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.
+ *
+ */
+package org.apache.ivy.plugins.parser.m2;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
+import org.apache.ivy.core.settings.IvySettings;
+import org.apache.ivy.util.FileUtil;
+
+public class PomModuleDescriptorWriterTest extends TestCase {
+    private static String LICENSE;
+    static {
+        try {
+            LICENSE = FileUtil.readEntirely(new BufferedReader(new 
InputStreamReader(
+                
PomModuleDescriptorWriterTest.class.getResourceAsStream("license.xml"))));
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+    private File _dest = new File("build/test/test-write.xml");
+
+    public void testSimple() throws Exception {
+        ModuleDescriptor md = 
PomModuleDescriptorParser.getInstance().parseDescriptor(
+            new IvySettings(), getClass().getResource("test-simple.pom"), 
false);
+        PomModuleDescriptorWriter.write(md, LICENSE, 
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
+        assertTrue(_dest.exists());
+
+        String wrote = FileUtil.readEntirely(new BufferedReader(new 
FileReader(_dest))).replaceAll(
+            "\r\n", "\n").replace('\r', '\n');
+        String expected = 
readEntirely("test-write-simple.xml").replaceAll("\r\n", "\n").replace(
+            '\r', '\n');
+        assertEquals(expected, wrote);
+    }
+    
+    public void testSimpleDependencies() throws Exception {
+        ModuleDescriptor md = 
PomModuleDescriptorParser.getInstance().parseDescriptor(
+            new IvySettings(), 
getClass().getResource("test-dependencies.pom"), false);
+        PomModuleDescriptorWriter.write(md, LICENSE, 
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
+        assertTrue(_dest.exists());
+
+        String wrote = FileUtil.readEntirely(new BufferedReader(new 
FileReader(_dest))).replaceAll(
+            "\r\n", "\n").replace('\r', '\n');
+        String expected = readEntirely("test-write-simple-dependencies.xml")
+            .replaceAll("\r\n", "\n").replace('\r', '\n');
+        assertEquals(expected, wrote);
+    }
+    
+    public void testDependenciesWithScope() throws Exception {
+        ModuleDescriptor md = 
PomModuleDescriptorParser.getInstance().parseDescriptor(
+            new IvySettings(), 
getClass().getResource("test-dependencies-with-scope.pom"), false);
+        PomModuleDescriptorWriter.write(md, LICENSE, 
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
+        assertTrue(_dest.exists());
+
+        String wrote = FileUtil.readEntirely(new BufferedReader(new 
FileReader(_dest))).replaceAll(
+            "\r\n", "\n").replace('\r', '\n');
+        String expected = 
readEntirely("test-write-dependencies-with-scope.xml")
+            .replaceAll("\r\n", "\n").replace('\r', '\n');
+        assertEquals(expected, wrote);
+    }
+    
+    public void testOptional() throws Exception {
+        ModuleDescriptor md = 
PomModuleDescriptorParser.getInstance().parseDescriptor(
+            new IvySettings(), getClass().getResource("test-optional.pom"), 
false);
+        PomModuleDescriptorWriter.write(md, LICENSE, 
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
+        assertTrue(_dest.exists());
+
+        String wrote = FileUtil.readEntirely(new BufferedReader(new 
FileReader(_dest))).replaceAll(
+            "\r\n", "\n").replace('\r', '\n');
+        String expected = readEntirely("test-write-dependencies-optional.xml")
+            .replaceAll("\r\n", "\n").replace('\r', '\n');
+        assertEquals(expected, wrote);
+    }
+    
+    private String readEntirely(String resource) throws IOException {
+        return FileUtil.readEntirely(new BufferedReader(new InputStreamReader(
+            
PomModuleDescriptorWriterTest.class.getResource(resource).openStream())));
+    }
+
+    public void setUp() {
+        if (_dest.exists()) {
+            _dest.delete();
+        }
+        if (!_dest.getParentFile().exists()) {
+            _dest.getParentFile().mkdirs();
+        }
+    }
+
+    protected void tearDown() throws Exception {
+        if (_dest.exists()) {
+            _dest.delete();
+        }
+    }
+}

Propchange: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/license.xml
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/license.xml?rev=594518&view=auto
==============================================================================
--- 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/license.xml 
(added)
+++ 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/license.xml 
Tue Nov 13 04:51:28 2007
@@ -0,0 +1,18 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "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.    
+-->

Propchange: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/license.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-dependencies-optional.xml
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-dependencies-optional.xml?rev=594518&view=auto
==============================================================================
--- 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-dependencies-optional.xml
 (added)
+++ 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-dependencies-optional.xml
 Tue Nov 13 04:51:28 2007
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "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.    
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache</groupId>
+  <artifactId>test</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0</version>
+  <dependencies>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.0.4</version>
+      <optional/>
+    </dependency>
+    <dependency>
+      <groupId>cglib</groupId>
+      <artifactId>cglib</artifactId>
+      <version>2.0.2</version>
+      <scope>compile</scope>
+    </dependency>
+  </dependencies>
+</project>

Propchange: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-dependencies-optional.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-dependencies-with-scope.xml
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-dependencies-with-scope.xml?rev=594518&view=auto
==============================================================================
--- 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-dependencies-with-scope.xml
 (added)
+++ 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-dependencies-with-scope.xml
 Tue Nov 13 04:51:28 2007
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "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.    
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache</groupId>
+  <artifactId>test</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0</version>
+  <dependencies>
+    <dependency>
+      <groupId>odmg</groupId>
+      <artifactId>odmg</artifactId>
+      <version>3.0</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.0.4</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>cglib</groupId>
+      <artifactId>cglib</artifactId>
+      <version>2.0.2</version>
+      <scope>compile</scope>
+    </dependency>
+  </dependencies>
+</project>

Propchange: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-dependencies-with-scope.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-simple-dependencies.xml
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-simple-dependencies.xml?rev=594518&view=auto
==============================================================================
--- 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-simple-dependencies.xml
 (added)
+++ 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-simple-dependencies.xml
 Tue Nov 13 04:51:28 2007
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "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.    
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache</groupId>
+  <artifactId>test</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0</version>
+  <dependencies>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.0.4</version>
+      <scope>compile</scope>
+    </dependency>
+  </dependencies>
+</project>

Propchange: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-simple-dependencies.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-simple.xml
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-simple.xml?rev=594518&view=auto
==============================================================================
--- 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-simple.xml
 (added)
+++ 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-simple.xml
 Tue Nov 13 04:51:28 2007
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "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.    
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache</groupId>
+  <artifactId>test</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0</version>
+</project>

Propchange: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-simple.xml
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to