* added support for nested filesets into DotnetResource * fixed problem when compiling with several references git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@329234 13f79535-47bb-0310-9956-ffa450edef68master
@@ -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> | |||
@@ -14,12 +14,13 @@ | |||
* limitations under the License. | |||
* | |||
*/ | |||
using System; | |||
public class Example { | |||
public static void Main(String[] args) { | |||
Example2.echo(); | |||
Example3.echo(); | |||
} | |||
} |
@@ -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"); | |||
} | |||
} |
@@ -386,8 +386,8 @@ public class CSharp extends DotnetCompile { | |||
* @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); | |||
} | |||
} | |||
@@ -220,7 +220,7 @@ public abstract class DotnetCompile | |||
//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 @@ public abstract class DotnetCompile | |||
Enumeration e = resources.elements(); | |||
while (e.hasMoreElements()) { | |||
DotnetResource resource = (DotnetResource) e.nextElement(); | |||
command.addArgument(createResourceParameter(resource)); | |||
createResourceParameter(command, resource); | |||
} | |||
} | |||
@@ -881,7 +881,7 @@ public abstract class DotnetCompile | |||
* @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 @@ public abstract class DotnetCompile | |||
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; | |||
} | |||
@@ -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 @@ package org.apache.tools.ant.taskdefs.optional.dotnet; | |||
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 @@ public class DotnetResource { | |||
*/ | |||
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; | |||
} | |||
@@ -96,48 +110,104 @@ public class DotnetResource { | |||
this.name = name; | |||
} | |||
/** | |||
* 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; | |||
} | |||
} |
@@ -119,8 +119,8 @@ public class JSharp extends DotnetCompile { | |||
* @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); | |||
} | |||
/** | |||
@@ -352,8 +352,8 @@ public class VisualBasicCompile extends DotnetCompile { | |||
* @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); | |||
} | |||
/** | |||
@@ -90,6 +90,13 @@ public class DotnetTest extends BuildFileTest { | |||
executeTarget("testCscReferences"); | |||
} | |||
/** | |||
* A unit test for JUnit | |||
*/ | |||
public void testCscResources() throws Exception { | |||
executeTarget("testCSCResources"); | |||
} | |||
/** | |||
* test we can assemble | |||
*/ | |||