ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alex...@apache.org
Subject svn commit: r329234 - in /ant/core/trunk/src: etc/testcases/taskdefs/optional/ etc/testcases/taskdefs/optional/dotnet/ main/org/apache/tools/ant/taskdefs/optional/dotnet/ testcases/org/apache/tools/ant/taskdefs/optional/
Date Fri, 28 Oct 2005 16:06:30 GMT
Author: alexeys
Date: Fri Oct 28 09:06:03 2005
New Revision: 329234

URL: http://svn.apache.org/viewcvs?rev=329234&view=rev
Log:
Bugzilla 28773
* added support for nested filesets into DotnetResource
* fixed problem when compiling with several references

Added:
    ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet/example3.cs
    ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet/res.resources   (with props)
Modified:
    ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet.xml
    ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet/example.cs
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetCompile.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetResource.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/JSharp.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/VisualBasicCompile.java
    ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/optional/DotnetTest.java

Modified: ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet.xml
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet.xml?rev=329234&r1=329233&r2=329234&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet.xml (original)
+++ ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet.xml Fri Oct 28 09:06:03 2005
@@ -97,15 +97,15 @@
    </condition>
    <property name="mono.executable" value="mint"/>
 
-   <!-- now set a prop of the compiler name to whatever we found --> 
+   <!-- now set a prop of the compiler name to whatever we found -->
    <condition property="cs.compiler" value="csc">
       <isset property="csc.found"/>
-   </condition>   
+   </condition>
 
    <condition property="cs.compiler" value="mcs">
       <isset property="mcs.found"/>
-   </condition>   
-   
+   </condition>
+
   </target>
 
   <target name="init" depends="probe_for_apps">
@@ -164,6 +164,56 @@
     <delete file="${testCSC.exe}"/>
   </target>
 
+  <target name="testCSCResources" depends="testCSCResources-Mono,testCSCResources-MS"/>
+
+  <target name="testCSCResources-MS" depends="validate_csc" if="csc.found">
+    <property name="testCSCRes.exe"
+      location="${build.dir}/ExampleCscRes.exe" />
+    <csc
+      destFile="${testCSCRes.exe}"
+      targetType="exe"
+      srcDir="${src.dir}"
+      >
+      <resource file="${src.dir}/res.resources"/>
+    </csc>
+    <available property="app-res.created" file="${testCSCRes.exe}"/>
+    <fail unless="app-res.created">No app ${testCSC.exe} created</fail>
+    <exec executable="${testCSCRes.exe}" failonerror="true" />
+    <delete file="${testCSCRes.exe}"/>
+    <csc
+      destFile="${testCSCRes.exe}"
+      targetType="exe"
+      srcDir="${src.dir}"
+      >
+      <resource namespace="some.namespace" embed="true">
+        <fileset file="${src.dir}/res.resources"/>
+      </resource>
+    </csc>
+    <available property="app-res-2.created" file="${testCSCRes.exe}"/>
+    <fail unless="app-res-2.created">No app ${testCSC.exe} created</fail>
+    <exec executable="${testCSCRes.exe}" failonerror="true" />
+    <delete file="${testCSCRes.exe}"/>
+  </target>
+
+  <target name="testCSCResources-Mono" depends="validate_csc" if="mcs.found">
+    <property name="testCSCRes.exe"
+      location="${build.dir}/ExampleCscRes.exe" />
+    <csc
+      destFile="${testCSCRes.exe}"
+      targetType="exe"
+      includedefaultreferences="true"
+      srcDir="${src.dir}"
+      >
+      <resource file="${src.dir}/res.resources"/>
+    </csc>
+    <available property="app-res.created" file="${testCSCRes.exe}"/>
+    <fail unless="app-res.created">No app ${testCSC.exe} created</fail>
+    <exec executable="${mono.executable}" failonerror="true">
+      <arg value="${testCSCRes.exe}"/>
+    </exec>
+    <delete file="${testCSCRes.exe}"/>
+  </target>
+
   <target name="testCSCintrinsicFileset"
           depends="testCSCintrinsicFileset-MS,testCSCintrinsicFileset-Mono"/>
 
@@ -216,6 +266,18 @@
     </csc>
     <available property="dll.created" file="${testCSC.dll}"/>
     <fail unless="dll.created">No file ${testCSC.dll} created</fail>
+    <property name="testCSC2.dll"
+      location="${build.dir}/folder  with dir/Example3.dll" />
+    <mkdir dir="${build.dir}/folder  with dir"/>
+    <csc
+      destFile="${testCSC2.dll}"
+      targetType="library"
+      executable="csc"
+      >
+      <src dir="${src.dir}" includes="example3.cs"/>
+    </csc>
+    <available property="dll2.created" file="${testCSC2.dll}"/>
+    <fail unless="dll2.created">No file ${testCSC2.dll} created</fail>
   </target>
 
   <target name="testCSCdll-Mono" depends="validate_csc" if="mcs.found">
@@ -245,12 +307,14 @@
       >
       <src file="${src.dir}/example.cs"/>
       <reference file="${testCSC.dll}" />
+      <reference file="${testCSC2.dll}" />
       <define name="RELEASE" />
       <define name="DEBUG" if="undefined.property"/>
       <define name="def3" unless="undefined.property"/>
     </csc>
     <available property="refapp.created" file="${testCscReferences.exe}"/>
     <fail unless="refapp.created">No app ${testCscReferences.exe} created</fail>
+    <copy file="${testCSC2.dll}" todir="${build.dir}"/>
     <exec executable="${testCscReferences.exe}" failonerror="true" />
   </target>
 
@@ -280,7 +344,7 @@
     depends="testILASM-Mono,testILASM-MS"
     if="ilasm.found"/>
 
-  <target name="ilasm" depends="validate_ilasm" 
+  <target name="ilasm" depends="validate_ilasm"
       if="ilasm.found">
     <property name="testILASM.exe"
       location="${build.dir}/ExampleIlasm.exe" />
@@ -294,13 +358,13 @@
     <fail unless="ilasm.created">No app ${testILASM.exe} created</fail>
   </target>
 
-    <target name="testILASM-MS" depends="ilasm" 
+    <target name="testILASM-MS" depends="ilasm"
       if="ilasm.found" unless="mono.ilasm.found">
       <exec executable="${testILASM.exe}"
         failonerror="true"/>
     </target>
 
-    <target name="testILASM-Mono" depends="ilasm" 
+    <target name="testILASM-Mono" depends="ilasm"
       if="mono.ilasm.found">
       <exec executable="${mono.executable}"
         failonerror="true">
@@ -371,7 +435,7 @@
     <available property="app.created" file="${testCSCresponseFile.exe}"/>
     <fail unless="app.created">No app ${testCSCresponseFile.exe} created</fail>
     <delete file="${testCSCresponseFile.exe}"/>
-  </target>  
+  </target>
 
 
 </project>

Modified: ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet/example.cs
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet/example.cs?rev=329234&r1=329233&r2=329234&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet/example.cs (original)
+++ ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet/example.cs Fri Oct 28 09:06:03
2005
@@ -14,12 +14,13 @@
  *  limitations under the License.
  *
  */
- 
+
 using System;
 
 public class Example {
 
     public static void Main(String[] args) {
             Example2.echo();
+            Example3.echo();
     }
 }

Added: ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet/example3.cs
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet/example3.cs?rev=329234&view=auto
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet/example3.cs (added)
+++ ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet/example3.cs Fri Oct 28 09:06:03
2005
@@ -0,0 +1,29 @@
+/*
+ * Copyright  2003-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ *
+ */
+
+using System;
+
+/**
+ * this is just here to create confusion
+ */
+public class Example3 {
+
+    public static void echo() {
+        Console.WriteLine("hello, I look like Java, but I'm really .NET");
+    }
+
+}

Added: ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet/res.resources
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet/res.resources?rev=329234&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ant/core/trunk/src/etc/testcases/taskdefs/optional/dotnet/res.resources
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java?rev=329234&r1=329233&r2=329234&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java Fri
Oct 28 09:06:03 2005
@@ -386,8 +386,8 @@
      * @return a string containing the resource param, or a null string
      * to conditionally exclude a resource.
      */
-    protected String createResourceParameter(DotnetResource resource) {
-        return resource.getCSharpStyleParameter();
+    protected void createResourceParameter(NetCommand command, DotnetResource resource) {
+        resource.getParameters(getProject(), command, true);
     }
 
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetCompile.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetCompile.java?rev=329234&r1=329233&r2=329234&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetCompile.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetCompile.java
Fri Oct 28 09:06:03 2005
@@ -220,7 +220,7 @@
         //bail on no references
         if (notEmpty(references)) {
             if (isWindows) {
-                return REFERENCE_OPTION + '\"' + references + '\"';
+                return '\"' + REFERENCE_OPTION + references + '\"';
             } else {
                 return REFERENCE_OPTION + references;
             }
@@ -871,7 +871,7 @@
         Enumeration e = resources.elements();
         while (e.hasMoreElements()) {
             DotnetResource resource = (DotnetResource) e.nextElement();
-            command.addArgument(createResourceParameter(resource));
+            createResourceParameter(command, resource);
         }
     }
 
@@ -881,7 +881,7 @@
      * @return a string containing the resource param, or a null string
      * to conditionally exclude a resource.
      */
-    protected abstract String createResourceParameter(DotnetResource resource);
+    protected abstract void createResourceParameter(NetCommand command, DotnetResource resource);
 
 
     /**
@@ -904,37 +904,20 @@
         if (filesToBuild.size() == 0) {
             return 0;
         }
-        StringBuffer referenceList = new StringBuffer(REFERENCE_OPTION);
         //now scan the hashtable and add the files
         Enumeration files = filesToBuild.elements();
-        boolean firstEntry = true;
         while (files.hasMoreElements()) {
             File file = (File) files.nextElement();
             if (isFileManagedBinary(file)) {
-                if (!firstEntry) {
-                    referenceList.append(getReferenceDelimiter());
-                } else if (isWindows) {
-                    referenceList.append('\"');
-                }
-                referenceList.append(file.toString());
-                firstEntry = false;
+                if (isWindows) command.addArgument('"'+REFERENCE_OPTION+file.toString()+'"');
+                else command.addArgument(REFERENCE_OPTION+file.toString());
             } else {
                 log("ignoring " + file + " as it is not a managed executable",
                         Project.MSG_VERBOSE);
             }
 
         }
-        // hack: This means we've added at least one reference that's
-        // a managed binary
-        if (!firstEntry) {
-            //add it all to an argument
-            if (isWindows) {
-                command.addArgument(referenceList.toString() + '\"');
-            } else {
-                command.addArgument(referenceList.toString());
-            }
-        }
-        
+
         return filesOutOfDate;
     }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetResource.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetResource.java?rev=329234&r1=329233&r2=329234&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetResource.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetResource.java
Fri Oct 28 09:06:03 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright  2000-2004 The Apache Software Foundation
+ * Copyright  2000-2005 The Apache Software Foundation
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -19,6 +19,10 @@
 import org.apache.tools.ant.BuildException;
 
 import java.io.File;
+import java.util.ArrayList;
+import org.apache.tools.ant.types.FileSet;
+import java.util.Iterator;
+import org.apache.tools.ant.*;
 
 /**
  * class used by DotnetCompile to name resources, could be upgraded to a datatype
@@ -48,6 +52,16 @@
      */
     private String name = null;
 
+    /**
+     * A list of filesets with resources.
+     */
+    private ArrayList fileSets=new ArrayList();
+
+    /**
+     * a namespace to be used with <filesets>
+     */
+    private String namespace = null;
+
     public boolean isEmbed() {
         return embed;
     }
@@ -97,47 +111,103 @@
     }
 
     /**
+     * Filesets root namespace. The value always ends with '.' .
+     * @return String namespace name
+     */
+    public String getNamespace() {
+        return namespace;
+    }
+
+    /**
+     * Sets filesets root namespace.
+     * @param namespace String root namespace
+     */
+    public void setNamespace(String namespace) {
+        if (namespace==null) this.namespace=null;
+        else this.namespace=(namespace.length()==0 || namespace.endsWith(".") ? namespace
: namespace+'.');
+    }
+
+    private void checkParameters() {
+        if (hasFilesets()) {
+            if (getName()!=null) throw new BuildException(
+                "Cannot use <resource name=\"...\"> attribute with filesets");
+            if (getFile()!=null) throw new BuildException(
+                "Cannot use <resource file=\"...\"> attribute with filesets");
+        }
+        else {
+            if (getNamespace()!=null) throw new BuildException(
+                "Cannot use <resource namespace=\"...\"> attribute without filesets");
+        }
+    }
+    /**
      * build the C# style parameter (which has no public/private option)
      * @return the built C# style parameter
      */
-    public String getCSharpStyleParameter() {
-        StringBuffer buffer = new StringBuffer();
-        buffer.append(isEmbed() ? "/resource" : "/linkresource");
-        buffer.append(':');
-        buffer.append(getFile().toString());
-        if (getName() != null) {
-            buffer.append(',');
-            buffer.append(getName());
+    public void getParameters(Project p, NetCommand command, boolean csharpStyle) {
+        checkParameters();
+        if (hasFilesets()) {
+            for (Iterator listIter=fileSets.iterator(); listIter.hasNext();) {
+                FileSet fs=(FileSet)listIter.next();;
+                String baseDirectory=fs.getDir(p).toString();
+                String namespace=getNamespace(); // ends with '.' or null
+                DirectoryScanner ds = fs.getDirectoryScanner(p);
+                String[] files = ds.getIncludedFiles();
+                for (int i=0; i<files.length; i++) {
+                    String file=files[i];
+                    command.addArgument(getParameter(baseDirectory+File.separatorChar+file,
(namespace==null ? null : namespace+file.replace(File.separatorChar, '.')), csharpStyle));
+                }
+            }
         }
-        if (getPublic() != null) {
-            throw new BuildException("This compiler does not support the "
-                    + "public/private option.");
+        else {
+            command.addArgument(getParameter(getFile().toString(), getName(),
+                                             csharpStyle));
         }
-        return buffer.toString();
     }
 
-    /**
-     * This method gets the style of param used by VB and javascript
-     * @return The style VB parameter being used.
-     */
-    public String getVbStyleParameter() {
-        StringBuffer buffer = new StringBuffer();
-        buffer.append(isEmbed() ? "/resource" : "/linkresource");
+    private String getParameter(String fileName, String name, boolean csharpStyle) {
+        StringBuffer buffer=new StringBuffer();
+        buffer.append(isEmbed()?"/resource":"/linkresource");
         buffer.append(':');
-        buffer.append(getFile().toString());
-        if (getName() != null) {
+        buffer.append(fileName);
+        if (name!=null) {
             buffer.append(',');
-            buffer.append(getName());
-            if (getPublic() != null) {
-                buffer.append(',');
-                buffer.append(getPublic().booleanValue()
-                        ? "public" : "private");
+            buffer.append(name);
+            if (csharpStyle) {
+                if (getPublic()!=null) {
+                    throw new BuildException(
+                        "This compiler does not support the "
+                        +"public/private option.");
+                }
+                else {
+                    if (getPublic()!=null) {
+                        buffer.append(',');
+                        buffer.append(getPublic().booleanValue()
+                                      ?"public":"private");
 
+                    }
+                }
+            }
+            else if (getPublic()!=null) {
+                throw new BuildException("You cannot have a public or private "
+                                         +"option without naming the resource");
             }
-        } else if (getPublic() != null) {
-            throw new BuildException("You cannot have a public or private "
-                    + "option without naming the resource");
         }
         return buffer.toString();
+    }
+
+    /**
+     * Adds a resource file set.
+     * @param fileset FileSet
+     */
+    public void addFileset(FileSet fileset) {
+        fileSets.add(fileset);
+    }
+
+    /**
+     * Checks that <resource> node has embedded <filesets>
+     * @return boolean
+     */
+    public boolean hasFilesets() {
+        return fileSets.size()>0;
     }
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/JSharp.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/JSharp.java?rev=329234&r1=329233&r2=329234&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/JSharp.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/JSharp.java Fri
Oct 28 09:06:03 2005
@@ -119,8 +119,8 @@
      * @return a string containing the resource param, or a null string
      * to conditionally exclude a resource.
      */
-    protected String createResourceParameter(DotnetResource resource) {
-        return resource.getCSharpStyleParameter();
+    protected void createResourceParameter(NetCommand command, DotnetResource resource) {
+        resource.getParameters(getProject(), command, true);
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/VisualBasicCompile.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/VisualBasicCompile.java?rev=329234&r1=329233&r2=329234&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/VisualBasicCompile.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/VisualBasicCompile.java
Fri Oct 28 09:06:03 2005
@@ -352,8 +352,8 @@
      * @return a string containing the resource param, or a null string
      * to conditionally exclude a resource.
      */
-    protected String createResourceParameter(DotnetResource resource) {
-        return resource.getVbStyleParameter();
+    protected void createResourceParameter(NetCommand command, DotnetResource resource) {
+        resource.getParameters(getProject(), command, false);
     }
 
     /**

Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/optional/DotnetTest.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/optional/DotnetTest.java?rev=329234&r1=329233&r2=329234&view=diff
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/optional/DotnetTest.java (original)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/optional/DotnetTest.java Fri
Oct 28 09:06:03 2005
@@ -91,6 +91,13 @@
     }
 
     /**
+     * A unit test for JUnit
+     */
+    public void testCscResources() throws Exception {
+        executeTarget("testCSCResources");
+    }
+
+    /**
      * test we can assemble
      */
     public void testILASM() throws Exception {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message