I had a similar problem and have modified TestSourceProcessorMojo and
SourceProcessorMojo to read the excludes and testExcludes XML nodes from the
POM. Please find my version attached to this email. The behavior is to use
the hard coded excludes in the class and add any excludes defined in the
POM.
The usage is similar to the maven-compiler-plugin. POM snippet below
<snip>
<plugins>
<plugin>
<groupId>org.apache.maven.dotnet.plugins</groupId>
<artifactId>maven-compile-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<excludes>
<exclude>**/*.xml</exclude>
<exclude>**/*.vspscc</exclude>
<exclude>**/*.config</exclude>
<exclude>**/*.bat</exclude>
<exclude>**/*.csproj*</exclude>
</excludes>
<testExcludes>
<exclude>**/*.xml</exclude>
<exclude>**/*.vspscc</exclude>
<exclude>**/*.config</exclude>
<exclude>**/*.bat</exclude>
<exclude>**/*.csproj*</exclude>
</testExcludes>
</configuration>
</plugin>
</plugins>
</snip>
Amol
On 6/29/07, Shane Isbell <[EMAIL PROTECTED]> wrote:
As a work-around, you can add the modify the TestSourceProcessorMojo
(maven-compile-plugin) by adding the pattern to the exclude list.
excludeList.add( "*.suo" );
excludeList.add( "*.csproj" );
excludeList.add( "*.sln" );
excludeList.add( "obj/**" );
On 6/28/07, Evan Worley <[EMAIL PROTECTED]> wrote:
>
> Hi Brian,
>
> There is a JIRA, http://jira.codehaus.org/browse/NMAVEN-78 which is
> related. Essentially the test-plugin grabs everything as a build test
> source instead of looking for only "test sources"
>
> -Evan
>
> On 6/28/07, Deacon, Brian <[EMAIL PROTECTED]> wrote:
> >
> > > So I've got this in build/plugins:
> > > <plugin>
> > > <groupId>org.apache.maven.dotnet.plugins</groupId>
> > > <artifactId>maven-test-plugin</artifactId>
> > > <version>0.14-SNAPSHOT</version>
> > > <extensions>true</extensions>
> > > <configuration>
> > >
> > > <reportsDirectory>${basedir}/target/nunit-log</reportsDirectory>
> > > <compilerArgument>/debug:full</compilerArgument>
> > > </configuration>
> > > </plugin>
> > >
> > > But the csc call that gets made as a result when trying to generate
> > > the test assembly has:
> > > /recurse:c:\blah\blah\target\build-test-sources\**
> > >
> > > So it's spitting out all kinds of syntax errors because the test
> > > assembly contains .resx and other things that it is trying to
compile
> > > as c# content, which of course it isn't.
> > >
> > > Oh, and my only other settings in the <build> element are:
> > >
> > > <finalName>${artifactId}</finalName>
> > > <sourceDirectory>../src/dotnet</sourceDirectory>
> > > <testSourceDirectory>../test/dotnet</testSourceDirectory>
> > >
> > > So, firstly, I need it to stop treating the resources like source
> > > code, then secondly, I need it to actually compile those resources
> > > into the assembly. Anybody have the answer in their back pocket?
> > >
> > > Brian
> >
>
/*
* 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.maven.dotnet.plugin.compile;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.dotnet.assembler.AssemblerContext;
import org.apache.maven.dotnet.PlatformUnsupportedException;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.DirectoryScanner;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
/**
* Copies source files to target directory.
*
* @author Shane Isbell
* @goal process-sources
* @phase process-sources
*/
public class SourceProcessorMojo
extends AbstractMojo
{
/**
* Source directory
*
* @parameter expression = "${sourceDirectory}" default-value="${project.build.sourceDirectory}"
* @required
*/
private String sourceDirectory;
/**
* Output directory
*
* @parameter expression = "${outputDirectory}" default-value="${project.build.directory}/build-sources"
* @required
*/
private String outputDirectory;
/**
* @parameter expression = "${includes}"
*/
private String[] includes;
/**
* @parameter expression = "${excludes}"
*/
private String[] excludes;
/**
* .NET Language. The default value is <code>C_SHARP</code>. Not case or white-space sensitive.
*
* @parameter expression="${language}" default-value = "C_SHARP"
* @required
*/
private String language;
/**
* @component
*/
private AssemblerContext assemblerContext;
public void execute()
throws MojoExecutionException
{
long startTime = System.currentTimeMillis();
if ( !new File( sourceDirectory ).exists() )
{
getLog().info( "NMAVEN-904-001: No source files to copy" );
return;
}
DirectoryScanner directoryScanner = new DirectoryScanner();
directoryScanner.setBasedir( sourceDirectory );
List<String> excludeList = new ArrayList<String>();
//target files
excludeList.add( "obj/**" );
excludeList.add( "bin/**" );
excludeList.add( "target/**" );
//Misc
excludeList.add( "Resources/**" );
excludeList.add( "Test/**" );
List<String> includeList = new ArrayList<String>();
try
{
includeList.add( "**/*." + assemblerContext.getClassExtensionFor( language ) );
}
catch ( PlatformUnsupportedException e )
{
throw new MojoExecutionException( "NMAVEN-904-003: Language is not supported: Language = " + language, e );
}
for (int i = 0; i < includes.length; ++i)
{
includeList.add(includes[i]);
}
directoryScanner.setIncludes( includeList.toArray( includes ) );
for (int i = 0; i < excludes.length; ++i)
{
excludeList.add(excludes[i]);
}
directoryScanner.setExcludes( excludeList.toArray( excludes ) );
directoryScanner.addDefaultExcludes();
directoryScanner.scan();
String[] files = directoryScanner.getIncludedFiles();
getLog().info( "NMAVEN-904-002: Copying source files: From = " + sourceDirectory + ", To = " +
outputDirectory + ", File Count = " + files.length );
super.getPluginContext().put( "SOURCE_FILES_UP_TO_DATE", Boolean.TRUE );
for ( String file : files )
{
try
{
File sourceFile = new File( sourceDirectory + File.separator + file );
File targetFile = new File( outputDirectory + File.separator + file );
if ( sourceFile.lastModified() > targetFile.lastModified() )
{
super.getPluginContext().put( "SOURCE_FILES_UP_TO_DATE", Boolean.FALSE );
FileUtils.copyFile( sourceFile, targetFile );
targetFile.setLastModified( System.currentTimeMillis() );
}
}
catch ( IOException e )
{
throw new MojoExecutionException( "NMAVEN-904-000: Unable to process sources", e );
}
}
}
}
/*
* 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.maven.dotnet.plugin.compile;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
/**
* Copies source files to target directory.
*
* @author Shane Isbell
* @goal process-test-sources
* @phase process-sources
*/
public class TestSourceProcessorMojo
extends AbstractMojo
{
/**
* Source directory
*
* @parameter expression = "${sourceDirectory}" default-value="${project.build.testSourceDirectory}"
* @required
*/
private String sourceDirectory;
/**
* Output directory
*
* @parameter expression = "${outputDirectory}" default-value="${project.build.directory}/build-test-sources"
* @required
*/
private String outputDirectory;
/**
* @parameter expression = "${testExcludes}"
*/
private String[] testExcludes;
public void execute()
throws MojoExecutionException
{
long startTime = System.currentTimeMillis();
if ( !new File( sourceDirectory ).exists() )
{
getLog().info( "NMAVEN-905-001: No test source files to copy" );
return;
}
DirectoryScanner directoryScanner = new DirectoryScanner();
directoryScanner.setBasedir( sourceDirectory );
List<String> excludeList = new ArrayList<String>();
excludeList.add( "*.suo" );
excludeList.add( "*.csproj" );
excludeList.add( "*.sln" );
excludeList.add( "obj/**" );
for (int i = 0; i < testExcludes.length; ++i)
{
excludeList.add(testExcludes[i]);
}
directoryScanner.setExcludes( excludeList.toArray( new String[excludeList.size()] ) );
directoryScanner.addDefaultExcludes();
directoryScanner.scan();
String[] files = directoryScanner.getIncludedFiles();
getLog().info(
"NMAVEN-905-002: Copying test source files: From = " + sourceDirectory + ", To = " + outputDirectory );
for ( String file : files )
{
try
{
File sourceFile = new File( sourceDirectory + File.separator + file );
File targetFile = new File( outputDirectory + File.separator + file );
if ( sourceFile.lastModified() > targetFile.lastModified() )
{
FileUtils.copyFile( sourceFile, targetFile );
}
}
catch ( IOException e )
{
throw new MojoExecutionException( "NMAVEN-905-000: Unable to process test sources", e );
}
}
long endTime = System.currentTimeMillis();
getLog().info( "Mojo Execution Time = " + (endTime - startTime));
}
}