Browse Source

add the ability to set the executable used in .net tasks. Why do this

(a) so you can refer to versions off the path (useful for multiple versions)
(b) so you can use other implementations than the windows one.

Specifically, Mono Csharp compiler, msc, apparently uses the same syntax as csc if desired. We will have to test this... I suppose we could test Rotor too, but I cant be bothered


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275000 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 22 years ago
parent
commit
45cfe2ada1
7 changed files with 68 additions and 37 deletions
  1. +20
    -5
      src/etc/testcases/taskdefs/optional/dotnet.xml
  2. +2
    -8
      src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java
  3. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetBaseMatchingTask.java
  4. +30
    -7
      src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetCompile.java
  5. +5
    -7
      src/main/org/apache/tools/ant/taskdefs/optional/dotnet/JSharp.java
  6. +2
    -9
      src/main/org/apache/tools/ant/taskdefs/optional/dotnet/VisualBasicCompile.java
  7. +8
    -0
      src/testcases/org/apache/tools/ant/taskdefs/optional/DotnetTest.java

+ 20
- 5
src/etc/testcases/taskdefs/optional/dotnet.xml View File

@@ -67,20 +67,35 @@
destFile="${testCSC.exe}"
targetType="exe"
>
<src dir="${src.dir}" includes="**/*.cs"/>
</csc>
<available property="app.created" file="${testCSC.exe}"/>
<fail unless="app.created">No app ${testCSC.exe} created</fail>
<exec executable="${testCSC.exe}" failonerror="true" />
<delete file="${testCSC.exe}"/>
</target>

<target name="testCSCintrinsicFileset" depends="init">
<property name="testCSC.exe"
location="${build.dir}/ExampleCsc.exe"/>
<csc
destFile="${testCSC.exe}"
targetType="exe"
srcDir="."
>
</csc>
<available property="app.created" file="${testCSC.exe}"/>
<fail unless="app.created">No app ${testCSC.exe} created</fail>
<exec executable="${testCSC.exe}" failonerror="true"/>
<delete file="${testCSC.exe}"/>
</target>

<target name="testCSCdll" depends="init">
<property name="testCSC.dll"
<property name="testCSC.dll"
location="${build.dir}/Example2.dll" />
<csc
destFile="${testCSC.dll}"
targetType="library"
targetType="library"
executable="csc"
>
<src dir="${src.dir}" includes="example2.cs"/>
</csc>


+ 2
- 8
src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java View File

@@ -199,6 +199,7 @@ public class CSharp extends DotnetCompile {
*/

public CSharp() {
clear();
}

/**
@@ -213,7 +214,7 @@ public class CSharp extends DotnetCompile {
unsafe = false;
noconfig = false;
definitions = null;
setExecutable("csc");
}


@@ -426,13 +427,6 @@ public class CSharp extends DotnetCompile {
return ";";
}

/**
* compiler is 'csc'
* @return
*/
public String getCompilerExeName() {
return "csc";
}

/**
* extension is '.cs'


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetBaseMatchingTask.java View File

@@ -137,7 +137,7 @@ public class DotnetBaseMatchingTask extends MatchingTask {
= getSrcDir() != null || filesets.size() == 0;
if (scanImplicitFileset) {
//scan for an implicit fileset if there was a srcdir set
//or there was no srcDir set but the @
//or there was no srcDir set but there was no contained classes
if (getSrcDir() == null) {
//if there is no src dir here, set it
setSrcDir(getProject().resolveFile("."));


+ 30
- 7
src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetCompile.java View File

@@ -154,6 +154,12 @@ public abstract class DotnetCompile
*/
protected Vector resources = new Vector();

/**
* executable
*/

protected String executable;

/**
* Fix .NET reference inclusion. .NET is really dumb in how it handles
* inclusion. You have to list every 'assembly' -read DLL that is imported.
@@ -790,6 +796,26 @@ public abstract class DotnetCompile
resources.add(resource);
}

/**
* what is the executable?
* @return
*/
protected String getExecutable() {
return executable;
}

/**
* set the name of the program, overriding the defaults.
* Can be used to set the full path to a program, or to switch
* to an alternate implementation of the command, such as the Mono or Rotor
* versions -provided they use the same command line arguments as the
* .NET framework edition
* @param executable
*/
public void setExecutable(String executable) {
this.executable = executable;
}

/**
* test for a string containing something useful
*
@@ -809,6 +835,9 @@ public abstract class DotnetCompile
if (outputFile != null && outputFile.isDirectory()) {
throw new BuildException("destFile cannot be a directory");
}
if(getExecutable()==null) {
throw new BuildException("There is no executable defined for this task");
}
}

/**
@@ -862,12 +891,6 @@ public abstract class DotnetCompile
*/
public abstract String getReferenceDelimiter();

/**
* Get the name of the compiler executable.
* @return The name of the compiler executable.
*/
public abstract String getCompilerExeName() ;

/**
* Get the extension of filenames to compile.
* @return The string extension of files to compile.
@@ -963,7 +986,7 @@ public abstract class DotnetCompile
* @return a command prefilled with the exe name and task name
*/
protected NetCommand createNetCommand() {
NetCommand command = new NetCommand(this, getTaskName(), getCompilerExeName());
NetCommand command = new NetCommand(this, getTaskName(), getExecutable());
return command;
}



+ 5
- 7
src/main/org/apache/tools/ant/taskdefs/optional/dotnet/JSharp.java View File

@@ -84,7 +84,11 @@ public class JSharp extends DotnetCompile {
*/
boolean secureScoping = false;

public JSharp() {
setExecutable("vjc");
}

public void setBaseAddress(String baseAddress) {
this.baseAddress = baseAddress;
}
@@ -116,13 +120,7 @@ public class JSharp extends DotnetCompile {
return ";";
}

/**
* Get the name of the compiler executable.
* @return The name of the compiler executable.
*/
public String getCompilerExeName() {
return "vjc";
}


/**
* Get the extension of filenames to compile.


+ 2
- 9
src/main/org/apache/tools/ant/taskdefs/optional/dotnet/VisualBasicCompile.java View File

@@ -107,7 +107,7 @@ public class VisualBasicCompile extends DotnetCompile {
* Constructor for VisualBasicCompile.
*/
public VisualBasicCompile() {
super();
clear();
}

/**
@@ -121,6 +121,7 @@ public class VisualBasicCompile extends DotnetCompile {
optionExplicit = false;
optionStrict = false;
removeIntChecks = false;
setExecutable("vbc");
}

/**
@@ -349,14 +350,6 @@ public class VisualBasicCompile extends DotnetCompile {
return resource.getVbStyleParameter();
}

/**
* Get the name of the compiler executable.
* @return The name of the compiler executable.
*/
public String getCompilerExeName() {
return "vbc";
}

/**
* validation code
* @throws BuildException if validation failed


+ 8
- 0
src/testcases/org/apache/tools/ant/taskdefs/optional/DotnetTest.java View File

@@ -106,6 +106,14 @@ public class DotnetTest extends BuildFileTest {
}


/**
* A unit test for JUnit
*/
public void testCSCintrinsicFileset() throws Exception {
executeTarget("testCSCintrinsicFileset");
}


/**
* A unit test for JUnit
*/


Loading…
Cancel
Save