You are viewing a plain text version of this content. The canonical link for it is here.
Posted to nmaven-commits@incubator.apache.org by ew...@apache.org on 2008/01/04 07:11:29 UTC
svn commit: r608765 - in
/incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler:
AbstractSourceProcessorMojo.java SourceProcessorMojo.java
TestSourceProcessorMojo.java
Author: eworley
Date: Thu Jan 3 23:11:25 2008
New Revision: 608765
URL: http://svn.apache.org/viewvc?rev=608765&view=rev
Log:
Refactored source processors to have a common abstract base class
Added:
incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java
Modified:
incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java
incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java
Added: incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java?rev=608765&view=auto
==============================================================================
--- incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java (added)
+++ incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java Thu Jan 3 23:11:25 2008
@@ -0,0 +1,153 @@
+/*
+ * 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.compiler;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.maven.dotnet.ProgrammingLanguage;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.FileUtils;
+
+public abstract class AbstractSourceProcessorMojo
+ extends AbstractMojo
+{
+ /**
+ * The maven project.
+ *
+ * @parameter expression="${project}"
+ * @required
+ */
+ protected MavenProject project;
+
+ /**
+ * @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;
+
+ /**
+ * @return <code>File</code> The source directory to process
+ */
+ protected abstract File getSourceDirectory();
+
+ /**
+ * @return <code>File</code> The output directory where the processed source
+ * will be placed
+ */
+ protected abstract File getOutputDirectory();
+
+ protected void processSources()
+ throws MojoExecutionException
+ {
+ File sourceDirectory = getSourceDirectory();
+
+ if ( !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>(Arrays.asList(excludes));
+ //target files
+ excludeList.add( "obj/**" );
+ excludeList.add( "bin/**" );
+ excludeList.add( "target/**" );
+ //Misc
+ excludeList.add( "Resources/**" );
+ excludeList.add( "Test/**" );
+
+ List<String> includeList = new ArrayList<String>(Arrays.asList(includes));
+ includeList.add( "**/*." + ProgrammingLanguage.valueOf( language ).getClassFileExtension() );
+
+ directoryScanner.setIncludes( includeList.toArray( includes ) );
+ directoryScanner.setExcludes( excludeList.toArray( excludes ) );
+ directoryScanner.addDefaultExcludes();
+
+ File outputDirectory = getOutputDirectory();
+ 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 );
+ File targetFile = new File( outputDirectory, 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 );
+ }
+ }
+
+ // Update the scanner to scan the output directory, and rescan
+ List<String> outputDirExcludes = new ArrayList<String>(excludeList);
+ // Ignore meta-inf, including assembly info
+ outputDirExcludes.add( "META-INF/**" );
+ directoryScanner.setExcludes( outputDirExcludes.toArray( new String[0] ) );
+ directoryScanner.setBasedir( outputDirectory );
+ directoryScanner.scan();
+
+ // Synchronize the target folder with the source. Specifically delete the targetFile if
+ // the source file no longer exists
+ for ( String file : directoryScanner.getIncludedFiles() )
+ {
+ File sourceFile = new File( sourceDirectory, file );
+ File targetFile = new File( outputDirectory, file );
+
+ if ( !sourceFile.exists() && targetFile.exists() )
+ {
+ if ( !targetFile.delete() )
+ {
+ getLog().warn( "Unable to delete stale target file " + targetFile.getPath() );
+ }
+ }
+ }
+ }
+}
Modified: incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java?rev=608765&r1=608764&r2=608765&view=diff
==============================================================================
--- incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java (original)
+++ incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java Thu Jan 3 23:11:25 2008
@@ -18,20 +18,10 @@
*/
package org.apache.maven.dotnet.plugin.compiler;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.dotnet.ProgrammingLanguage;
-import org.apache.maven.dotnet.BuildDirectories;
-import org.apache.maven.project.MavenProject;
-
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.codehaus.plexus.util.FileUtils;
-
import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.ArrayList;
+
+import org.apache.maven.dotnet.BuildDirectories;
+import org.apache.maven.plugin.MojoExecutionException;
/**
* Copies source files to target directory.
@@ -42,113 +32,25 @@
*/
public class SourceProcessorMojo
- extends AbstractMojo
+ extends AbstractSourceProcessorMojo
{
- /**
- * The maven project.
- *
- * @parameter expression="${project}"
- * @required
- */
- private MavenProject project;
-
- /**
- * @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;
-
public void execute()
throws MojoExecutionException
{
- File sourceDirectory = new File( project.getBuild().getSourceDirectory() );
- File outputDirectory =
- new File( project.getBuild().getDirectory(), BuildDirectories.BUILD_SOURCES.getBuildDirectoryName() );
-
- if ( !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>(Arrays.asList(excludes));
- //target files
- excludeList.add( "obj/**" );
- excludeList.add( "bin/**" );
- excludeList.add( "target/**" );
- //Misc
- excludeList.add( "Resources/**" );
- excludeList.add( "Test/**" );
-
- List<String> includeList = new ArrayList<String>(Arrays.asList(includes));
- includeList.add( "**/*." + ProgrammingLanguage.valueOf( language ).getClassFileExtension() );
-
- directoryScanner.setIncludes( includeList.toArray( includes ) );
- 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 );
- File targetFile = new File( outputDirectory, 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 );
- }
- }
-
- // Update the scanner to scan the output directory, and rescan
- List<String> outputDirExcludes = new ArrayList<String>(excludeList);
- // Ignore meta-inf, including assembly info
- outputDirExcludes.add( "META-INF/**" );
- directoryScanner.setExcludes( outputDirExcludes.toArray( new String[0] ) );
- directoryScanner.setBasedir( outputDirectory );
- directoryScanner.scan();
-
- // Synchronize the target folder with the source. Specifically delete the targetFile if
- // the source file no longer exists
- for ( String file : directoryScanner.getIncludedFiles() )
- {
- File sourceFile = new File( sourceDirectory, file );
- File targetFile = new File( outputDirectory, file );
-
- if ( !sourceFile.exists() && targetFile.exists() )
- {
- if ( !targetFile.delete() )
- {
- getLog().warn( "Unable to delete stale target file " + targetFile.getPath() );
- }
- }
- }
+ processSources();
+ }
+
+ @Override
+ protected File getOutputDirectory()
+ {
+ return new File( project.getBuild().getDirectory(),
+ BuildDirectories.BUILD_SOURCES.getBuildDirectoryName() );
+ }
+
+ @Override
+ protected File getSourceDirectory()
+ {
+ return new File( project.getBuild().getSourceDirectory() );
}
}
Modified: incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java?rev=608765&r1=608764&r2=608765&view=diff
==============================================================================
--- incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java (original)
+++ incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java Thu Jan 3 23:11:25 2008
@@ -18,20 +18,10 @@
*/
package org.apache.maven.dotnet.plugin.compiler;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.dotnet.ProgrammingLanguage;
-import org.apache.maven.dotnet.BuildDirectories;
-import org.apache.maven.project.MavenProject;
-
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.codehaus.plexus.util.FileUtils;
-
import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.ArrayList;
+
+import org.apache.maven.dotnet.BuildDirectories;
+import org.apache.maven.plugin.MojoExecutionException;
/**
* Copies test source files to target directory.
@@ -40,36 +30,10 @@
* @phase process-test-sources
* @description Copies source files to target directory.
*/
-
public class TestSourceProcessorMojo
- extends AbstractMojo
+ extends AbstractSourceProcessorMojo
{
- /**
- * The maven project.
- *
- * @parameter expression="${project}"
- * @required
- */
- private MavenProject project;
-
- /**
- * @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;
-
+
public void execute()
throws MojoExecutionException
{
@@ -80,75 +44,19 @@
return;
}
- File testSourceDirectory = new File( project.getBuild().getTestSourceDirectory() );
- File outputDirectory =
- new File( project.getBuild().getDirectory(), BuildDirectories.TEST_SOURCES.getBuildDirectoryName() );
+ processSources();
+ }
- if ( !testSourceDirectory.exists() )
- {
- getLog().info( "NMAVEN-904-001: No test source files to copy" );
- return;
- }
- DirectoryScanner directoryScanner = new DirectoryScanner();
- directoryScanner.setBasedir( testSourceDirectory );
-
- List<String> excludeList = new ArrayList<String>(Arrays.asList(excludes));
- List<String> includeList = new ArrayList<String>(Arrays.asList(includes));
- includeList.add( "**/*." + ProgrammingLanguage.valueOf( language ).getClassFileExtension() );
-
- directoryScanner.setIncludes( includeList.toArray( includes ) );
- directoryScanner.setExcludes( excludeList.toArray( excludes ) );
-
- directoryScanner.addDefaultExcludes();
-
- directoryScanner.scan();
- String[] files = directoryScanner.getIncludedFiles();
- getLog().info( "NMAVEN-904-002: Copying test source files: From = " + testSourceDirectory + ", To = " +
- outputDirectory + ", File Count = " + files.length );
+ @Override
+ protected File getOutputDirectory()
+ {
+ return new File( project.getBuild().getDirectory(),
+ BuildDirectories.TEST_SOURCES.getBuildDirectoryName() );
+ }
- super.getPluginContext().put( "TEST SOURCE_FILES_UP_TO_DATE", Boolean.TRUE );
- for ( String file : files )
- {
- try
- {
- File sourceFile = new File( testSourceDirectory, file );
- File targetFile = new File( outputDirectory, file );
- if ( sourceFile.lastModified() > targetFile.lastModified() )
- {
- super.getPluginContext().put( "TEST 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 test sources", e );
- }
- }
-
- // Update the scanner to scan the output directory, and rescan
- directoryScanner.setBasedir(outputDirectory);
- List<String> outputDirExcludes = new ArrayList<String>(excludeList);
- // Ignore meta-inf, including assembly info
- outputDirExcludes.add( "META-INF/**" );
- directoryScanner.setExcludes( outputDirExcludes.toArray( new String[0] ) );
- directoryScanner.setBasedir( outputDirectory );
- directoryScanner.scan();
-
- // Synchronize the target folder with the source. Specifically delete the targetFile if
- // the source file no longer exists
- for ( String file : directoryScanner.getIncludedFiles() )
- {
- File sourceFile = new File( testSourceDirectory, file );
- File targetFile = new File( outputDirectory, file );
-
- if ( !sourceFile.exists() && targetFile.exists() )
- {
- if ( !targetFile.delete() )
- {
- getLog().warn( "Unable to delete stale target file " + targetFile.getPath() );
- }
- }
- }
+ @Override
+ protected File getSourceDirectory()
+ {
+ return new File( project.getBuild().getTestSourceDirectory() );
}
}
Re: svn commit: r608765 - in /incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler: AbstractSourceProcessorMojo.java SourceProcessorMojo.java TestSourceProcessorMojo.java
Posted by Evan Worley <ev...@gmail.com>.
Yes, you're right. We need to do this differently for each type of source
we process, e.g. TEST_SOURCE_FILES_UP_TO_DATE, etc.
-Evan
On Jan 9, 2008 7:05 PM, Shane Isbell <sh...@gmail.com> wrote:
> Introducing the AbstractSourceProcessorMojo breaks the ability to
> determine
> if the source files are up-to-date. The SOURCE_FILES_UP_TO_DATE is meant
> to
> tell the compiler mojo whether it should execute a compile, but since you
> are reusing this field for both test and main classes, the main compiler
> mojo can't use it.
>
>
> On Jan 3, 2008 11:11 PM, <ew...@apache.org> wrote:
>
> > Author: eworley
> > Date: Thu Jan 3 23:11:25 2008
> > New Revision: 608765
> >
> > URL: http://svn.apache.org/viewvc?rev=608765&view=rev
> > Log:
> > Refactored source processors to have a common abstract base class
> >
> > Added:
> >
> >
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java
> > Modified:
> >
> >
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java
> >
> >
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java
> >
> > Added:
> >
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java
> > URL:
> >
> http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java?rev=608765&view=auto
> >
> >
> ==============================================================================
> > ---
> >
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java
> > (added)
> > +++
> >
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java
> > Thu Jan 3 23:11:25 2008
> > @@ -0,0 +1,153 @@
> > +/*
> > + * 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.compiler;
> > +
> > +import java.io.File;
> > +import java.io.IOException;
> > +import java.util.ArrayList;
> > +import java.util.Arrays;
> > +import java.util.List;
> > +
> > +import org.apache.maven.dotnet.ProgrammingLanguage;
> > +import org.apache.maven.plugin.AbstractMojo;
> > +import org.apache.maven.plugin.MojoExecutionException;
> > +import org.apache.maven.project.MavenProject;
> > +import org.codehaus.plexus.util.DirectoryScanner;
> > +import org.codehaus.plexus.util.FileUtils;
> > +
> > +public abstract class AbstractSourceProcessorMojo
> > + extends AbstractMojo
> > +{
> > + /**
> > + * The maven project.
> > + *
> > + * @parameter expression="${project}"
> > + * @required
> > + */
> > + protected MavenProject project;
> > +
> > + /**
> > + * @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;
> > +
> > + /**
> > + * @return <code>File</code> The source directory to process
> > + */
> > + protected abstract File getSourceDirectory();
> > +
> > + /**
> > + * @return <code>File</code> The output directory where the
> processed
> > source
> > + * will be placed
> > + */
> > + protected abstract File getOutputDirectory();
> > +
> > + protected void processSources()
> > + throws MojoExecutionException
> > + {
> > + File sourceDirectory = getSourceDirectory();
> > +
> > + if ( !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>(Arrays.asList
> > (excludes));
> > + //target files
> > + excludeList.add( "obj/**" );
> > + excludeList.add( "bin/**" );
> > + excludeList.add( "target/**" );
> > + //Misc
> > + excludeList.add( "Resources/**" );
> > + excludeList.add( "Test/**" );
> > +
> > + List<String> includeList = new ArrayList<String>(Arrays.asList
> > (includes));
> > + includeList.add( "**/*." + ProgrammingLanguage.valueOf(
> language
> > ).getClassFileExtension() );
> > +
> > + directoryScanner.setIncludes( includeList.toArray( includes )
> );
> > + directoryScanner.setExcludes( excludeList.toArray( excludes )
> );
> > + directoryScanner.addDefaultExcludes();
> > +
> > + File outputDirectory = getOutputDirectory();
> > + 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 );
> > + File targetFile = new File( outputDirectory, 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 );
> > + }
> > + }
> > +
> > + // Update the scanner to scan the output directory, and rescan
> > + List<String> outputDirExcludes = new
> > ArrayList<String>(excludeList);
> > + // Ignore meta-inf, including assembly info
> > + outputDirExcludes.add( "META-INF/**" );
> > + directoryScanner.setExcludes( outputDirExcludes.toArray( new
> > String[0] ) );
> > + directoryScanner.setBasedir( outputDirectory );
> > + directoryScanner.scan();
> > +
> > + // Synchronize the target folder with the source. Specifically
> > delete the targetFile if
> > + // the source file no longer exists
> > + for ( String file : directoryScanner.getIncludedFiles() )
> > + {
> > + File sourceFile = new File( sourceDirectory, file );
> > + File targetFile = new File( outputDirectory, file );
> > +
> > + if ( !sourceFile.exists() && targetFile.exists() )
> > + {
> > + if ( !targetFile.delete() )
> > + {
> > + getLog().warn( "Unable to delete stale target
> file
> > " + targetFile.getPath() );
> > + }
> > + }
> > + }
> > + }
> > +}
> >
> > Modified:
> >
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java
> > URL:
> >
> http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java?rev=608765&r1=608764&r2=608765&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java
> > (original)
> > +++
> >
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java
> > Thu Jan 3 23:11:25 2008
> > @@ -18,20 +18,10 @@
> > */
> > package org.apache.maven.dotnet.plugin.compiler;
> >
> > -import org.apache.maven.plugin.AbstractMojo;
> > -import org.apache.maven.plugin.MojoExecutionException;
> > -import org.apache.maven.dotnet.ProgrammingLanguage;
> > -import org.apache.maven.dotnet.BuildDirectories;
> > -import org.apache.maven.project.MavenProject;
> > -
> > -import org.codehaus.plexus.util.DirectoryScanner;
> > -import org.codehaus.plexus.util.FileUtils;
> > -
> > import java.io.File;
> > -import java.io.IOException;
> > -import java.util.Arrays;
> > -import java.util.List;
> > -import java.util.ArrayList;
> > +
> > +import org.apache.maven.dotnet.BuildDirectories;
> > +import org.apache.maven.plugin.MojoExecutionException;
> >
> > /**
> > * Copies source files to target directory.
> > @@ -42,113 +32,25 @@
> > */
> >
> > public class SourceProcessorMojo
> > - extends AbstractMojo
> > + extends AbstractSourceProcessorMojo
> > {
> >
> > - /**
> > - * The maven project.
> > - *
> > - * @parameter expression="${project}"
> > - * @required
> > - */
> > - private MavenProject project;
> > -
> > - /**
> > - * @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;
> > -
> > public void execute()
> > throws MojoExecutionException
> > {
> > - File sourceDirectory = new File( project.getBuild
> ().getSourceDirectory()
> > );
> > - File outputDirectory =
> > - new File( project.getBuild().getDirectory(),
> > BuildDirectories.BUILD_SOURCES.getBuildDirectoryName() );
> > -
> > - if ( !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>(Arrays.asList
> > (excludes));
> > - //target files
> > - excludeList.add( "obj/**" );
> > - excludeList.add( "bin/**" );
> > - excludeList.add( "target/**" );
> > - //Misc
> > - excludeList.add( "Resources/**" );
> > - excludeList.add( "Test/**" );
> > -
> > - List<String> includeList = new ArrayList<String>(Arrays.asList
> > (includes));
> > - includeList.add( "**/*." + ProgrammingLanguage.valueOf(
> language
> > ).getClassFileExtension() );
> > -
> > - directoryScanner.setIncludes( includeList.toArray( includes )
> );
> > - 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 );
> > - File targetFile = new File( outputDirectory, 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 );
> > - }
> > - }
> > -
> > - // Update the scanner to scan the output directory, and rescan
> > - List<String> outputDirExcludes = new
> > ArrayList<String>(excludeList);
> > - // Ignore meta-inf, including assembly info
> > - outputDirExcludes.add( "META-INF/**" );
> > - directoryScanner.setExcludes( outputDirExcludes.toArray( new
> > String[0] ) );
> > - directoryScanner.setBasedir( outputDirectory );
> > - directoryScanner.scan();
> > -
> > - // Synchronize the target folder with the source. Specifically
> > delete the targetFile if
> > - // the source file no longer exists
> > - for ( String file : directoryScanner.getIncludedFiles() )
> > - {
> > - File sourceFile = new File( sourceDirectory, file );
> > - File targetFile = new File( outputDirectory, file );
> > -
> > - if ( !sourceFile.exists() && targetFile.exists() )
> > - {
> > - if ( !targetFile.delete() )
> > - {
> > - getLog().warn( "Unable to delete stale target
> file
> > " + targetFile.getPath() );
> > - }
> > - }
> > - }
> > + processSources();
> > + }
> > +
> > + @Override
> > + protected File getOutputDirectory()
> > + {
> > + return new File( project.getBuild().getDirectory(),
> > +
> > BuildDirectories.BUILD_SOURCES.getBuildDirectoryName() );
> > + }
> > +
> > + @Override
> > + protected File getSourceDirectory()
> > + {
> > + return new File( project.getBuild().getSourceDirectory() );
> > }
> > }
> >
> > Modified:
> >
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java
> > URL:
> >
> http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java?rev=608765&r1=608764&r2=608765&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java
> > (original)
> > +++
> >
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java
> > Thu Jan 3 23:11:25 2008
> > @@ -18,20 +18,10 @@
> > */
> > package org.apache.maven.dotnet.plugin.compiler;
> >
> > -import org.apache.maven.plugin.AbstractMojo;
> > -import org.apache.maven.plugin.MojoExecutionException;
> > -import org.apache.maven.dotnet.ProgrammingLanguage;
> > -import org.apache.maven.dotnet.BuildDirectories;
> > -import org.apache.maven.project.MavenProject;
> > -
> > -import org.codehaus.plexus.util.DirectoryScanner;
> > -import org.codehaus.plexus.util.FileUtils;
> > -
> > import java.io.File;
> > -import java.io.IOException;
> > -import java.util.Arrays;
> > -import java.util.List;
> > -import java.util.ArrayList;
> > +
> > +import org.apache.maven.dotnet.BuildDirectories;
> > +import org.apache.maven.plugin.MojoExecutionException;
> >
> > /**
> > * Copies test source files to target directory.
> > @@ -40,36 +30,10 @@
> > * @phase process-test-sources
> > * @description Copies source files to target directory.
> > */
> > -
> > public class TestSourceProcessorMojo
> > - extends AbstractMojo
> > + extends AbstractSourceProcessorMojo
> > {
> > - /**
> > - * The maven project.
> > - *
> > - * @parameter expression="${project}"
> > - * @required
> > - */
> > - private MavenProject project;
> > -
> > - /**
> > - * @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;
> > -
> > +
> > public void execute()
> > throws MojoExecutionException
> > {
> > @@ -80,75 +44,19 @@
> > return;
> > }
> >
> > - File testSourceDirectory = new File( project.getBuild
> ().getTestSourceDirectory()
> > );
> > - File outputDirectory =
> > - new File( project.getBuild().getDirectory(),
> > BuildDirectories.TEST_SOURCES.getBuildDirectoryName() );
> > + processSources();
> > + }
> >
> > - if ( !testSourceDirectory.exists() )
> > - {
> > - getLog().info( "NMAVEN-904-001: No test source files to
> copy"
> > );
> > - return;
> > - }
> > - DirectoryScanner directoryScanner = new DirectoryScanner();
> > - directoryScanner.setBasedir( testSourceDirectory );
> > -
> > - List<String> excludeList = new ArrayList<String>(Arrays.asList
> > (excludes));
> > - List<String> includeList = new ArrayList<String>(Arrays.asList
> > (includes));
> > - includeList.add( "**/*." + ProgrammingLanguage.valueOf(
> language
> > ).getClassFileExtension() );
> > -
> > - directoryScanner.setIncludes( includeList.toArray( includes )
> );
> > - directoryScanner.setExcludes( excludeList.toArray( excludes )
> );
> > -
> > - directoryScanner.addDefaultExcludes();
> > -
> > - directoryScanner.scan();
> > - String[] files = directoryScanner.getIncludedFiles();
> > - getLog().info( "NMAVEN-904-002: Copying test source files: From
> =
> > " + testSourceDirectory + ", To = " +
> > - outputDirectory + ", File Count = " + files.length );
> > + @Override
> > + protected File getOutputDirectory()
> > + {
> > + return new File( project.getBuild().getDirectory(),
> > +
> > BuildDirectories.TEST_SOURCES.getBuildDirectoryName() );
> > + }
> >
> > - super.getPluginContext().put( "TEST SOURCE_FILES_UP_TO_DATE",
> > Boolean.TRUE );
> > - for ( String file : files )
> > - {
> > - try
> > - {
> > - File sourceFile = new File( testSourceDirectory, file
> );
> > - File targetFile = new File( outputDirectory, file );
> > - if ( sourceFile.lastModified() >
> targetFile.lastModified()
> > )
> > - {
> > - super.getPluginContext().put( "TEST
> > 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 test sources", e );
> > - }
> > - }
> > -
> > - // Update the scanner to scan the output directory, and rescan
> > - directoryScanner.setBasedir(outputDirectory);
> > - List<String> outputDirExcludes = new
> > ArrayList<String>(excludeList);
> > - // Ignore meta-inf, including assembly info
> > - outputDirExcludes.add( "META-INF/**" );
> > - directoryScanner.setExcludes( outputDirExcludes.toArray( new
> > String[0] ) );
> > - directoryScanner.setBasedir( outputDirectory );
> > - directoryScanner.scan();
> > -
> > - // Synchronize the target folder with the source. Specifically
> > delete the targetFile if
> > - // the source file no longer exists
> > - for ( String file : directoryScanner.getIncludedFiles() )
> > - {
> > - File sourceFile = new File( testSourceDirectory, file );
> > - File targetFile = new File( outputDirectory, file );
> > -
> > - if ( !sourceFile.exists() && targetFile.exists() )
> > - {
> > - if ( !targetFile.delete() )
> > - {
> > - getLog().warn( "Unable to delete stale target
> file
> > " + targetFile.getPath() );
> > - }
> > - }
> > - }
> > + @Override
> > + protected File getSourceDirectory()
> > + {
> > + return new File( project.getBuild().getTestSourceDirectory() );
> > }
> > }
> >
> >
> >
>
Re: svn commit: r608765 - in /incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler: AbstractSourceProcessorMojo.java SourceProcessorMojo.java TestSourceProcessorMojo.java
Posted by Shane Isbell <sh...@gmail.com>.
Introducing the AbstractSourceProcessorMojo breaks the ability to determine
if the source files are up-to-date. The SOURCE_FILES_UP_TO_DATE is meant to
tell the compiler mojo whether it should execute a compile, but since you
are reusing this field for both test and main classes, the main compiler
mojo can't use it.
On Jan 3, 2008 11:11 PM, <ew...@apache.org> wrote:
> Author: eworley
> Date: Thu Jan 3 23:11:25 2008
> New Revision: 608765
>
> URL: http://svn.apache.org/viewvc?rev=608765&view=rev
> Log:
> Refactored source processors to have a common abstract base class
>
> Added:
>
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java
> Modified:
>
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java
>
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java
>
> Added:
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java
> URL:
> http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java?rev=608765&view=auto
>
> ==============================================================================
> ---
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java
> (added)
> +++
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractSourceProcessorMojo.java
> Thu Jan 3 23:11:25 2008
> @@ -0,0 +1,153 @@
> +/*
> + * 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.compiler;
> +
> +import java.io.File;
> +import java.io.IOException;
> +import java.util.ArrayList;
> +import java.util.Arrays;
> +import java.util.List;
> +
> +import org.apache.maven.dotnet.ProgrammingLanguage;
> +import org.apache.maven.plugin.AbstractMojo;
> +import org.apache.maven.plugin.MojoExecutionException;
> +import org.apache.maven.project.MavenProject;
> +import org.codehaus.plexus.util.DirectoryScanner;
> +import org.codehaus.plexus.util.FileUtils;
> +
> +public abstract class AbstractSourceProcessorMojo
> + extends AbstractMojo
> +{
> + /**
> + * The maven project.
> + *
> + * @parameter expression="${project}"
> + * @required
> + */
> + protected MavenProject project;
> +
> + /**
> + * @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;
> +
> + /**
> + * @return <code>File</code> The source directory to process
> + */
> + protected abstract File getSourceDirectory();
> +
> + /**
> + * @return <code>File</code> The output directory where the processed
> source
> + * will be placed
> + */
> + protected abstract File getOutputDirectory();
> +
> + protected void processSources()
> + throws MojoExecutionException
> + {
> + File sourceDirectory = getSourceDirectory();
> +
> + if ( !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>(Arrays.asList
> (excludes));
> + //target files
> + excludeList.add( "obj/**" );
> + excludeList.add( "bin/**" );
> + excludeList.add( "target/**" );
> + //Misc
> + excludeList.add( "Resources/**" );
> + excludeList.add( "Test/**" );
> +
> + List<String> includeList = new ArrayList<String>(Arrays.asList
> (includes));
> + includeList.add( "**/*." + ProgrammingLanguage.valueOf( language
> ).getClassFileExtension() );
> +
> + directoryScanner.setIncludes( includeList.toArray( includes ) );
> + directoryScanner.setExcludes( excludeList.toArray( excludes ) );
> + directoryScanner.addDefaultExcludes();
> +
> + File outputDirectory = getOutputDirectory();
> + 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 );
> + File targetFile = new File( outputDirectory, 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 );
> + }
> + }
> +
> + // Update the scanner to scan the output directory, and rescan
> + List<String> outputDirExcludes = new
> ArrayList<String>(excludeList);
> + // Ignore meta-inf, including assembly info
> + outputDirExcludes.add( "META-INF/**" );
> + directoryScanner.setExcludes( outputDirExcludes.toArray( new
> String[0] ) );
> + directoryScanner.setBasedir( outputDirectory );
> + directoryScanner.scan();
> +
> + // Synchronize the target folder with the source. Specifically
> delete the targetFile if
> + // the source file no longer exists
> + for ( String file : directoryScanner.getIncludedFiles() )
> + {
> + File sourceFile = new File( sourceDirectory, file );
> + File targetFile = new File( outputDirectory, file );
> +
> + if ( !sourceFile.exists() && targetFile.exists() )
> + {
> + if ( !targetFile.delete() )
> + {
> + getLog().warn( "Unable to delete stale target file
> " + targetFile.getPath() );
> + }
> + }
> + }
> + }
> +}
>
> Modified:
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java
> URL:
> http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java?rev=608765&r1=608764&r2=608765&view=diff
>
> ==============================================================================
> ---
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java
> (original)
> +++
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/SourceProcessorMojo.java
> Thu Jan 3 23:11:25 2008
> @@ -18,20 +18,10 @@
> */
> package org.apache.maven.dotnet.plugin.compiler;
>
> -import org.apache.maven.plugin.AbstractMojo;
> -import org.apache.maven.plugin.MojoExecutionException;
> -import org.apache.maven.dotnet.ProgrammingLanguage;
> -import org.apache.maven.dotnet.BuildDirectories;
> -import org.apache.maven.project.MavenProject;
> -
> -import org.codehaus.plexus.util.DirectoryScanner;
> -import org.codehaus.plexus.util.FileUtils;
> -
> import java.io.File;
> -import java.io.IOException;
> -import java.util.Arrays;
> -import java.util.List;
> -import java.util.ArrayList;
> +
> +import org.apache.maven.dotnet.BuildDirectories;
> +import org.apache.maven.plugin.MojoExecutionException;
>
> /**
> * Copies source files to target directory.
> @@ -42,113 +32,25 @@
> */
>
> public class SourceProcessorMojo
> - extends AbstractMojo
> + extends AbstractSourceProcessorMojo
> {
>
> - /**
> - * The maven project.
> - *
> - * @parameter expression="${project}"
> - * @required
> - */
> - private MavenProject project;
> -
> - /**
> - * @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;
> -
> public void execute()
> throws MojoExecutionException
> {
> - File sourceDirectory = new File( project.getBuild().getSourceDirectory()
> );
> - File outputDirectory =
> - new File( project.getBuild().getDirectory(),
> BuildDirectories.BUILD_SOURCES.getBuildDirectoryName() );
> -
> - if ( !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>(Arrays.asList
> (excludes));
> - //target files
> - excludeList.add( "obj/**" );
> - excludeList.add( "bin/**" );
> - excludeList.add( "target/**" );
> - //Misc
> - excludeList.add( "Resources/**" );
> - excludeList.add( "Test/**" );
> -
> - List<String> includeList = new ArrayList<String>(Arrays.asList
> (includes));
> - includeList.add( "**/*." + ProgrammingLanguage.valueOf( language
> ).getClassFileExtension() );
> -
> - directoryScanner.setIncludes( includeList.toArray( includes ) );
> - 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 );
> - File targetFile = new File( outputDirectory, 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 );
> - }
> - }
> -
> - // Update the scanner to scan the output directory, and rescan
> - List<String> outputDirExcludes = new
> ArrayList<String>(excludeList);
> - // Ignore meta-inf, including assembly info
> - outputDirExcludes.add( "META-INF/**" );
> - directoryScanner.setExcludes( outputDirExcludes.toArray( new
> String[0] ) );
> - directoryScanner.setBasedir( outputDirectory );
> - directoryScanner.scan();
> -
> - // Synchronize the target folder with the source. Specifically
> delete the targetFile if
> - // the source file no longer exists
> - for ( String file : directoryScanner.getIncludedFiles() )
> - {
> - File sourceFile = new File( sourceDirectory, file );
> - File targetFile = new File( outputDirectory, file );
> -
> - if ( !sourceFile.exists() && targetFile.exists() )
> - {
> - if ( !targetFile.delete() )
> - {
> - getLog().warn( "Unable to delete stale target file
> " + targetFile.getPath() );
> - }
> - }
> - }
> + processSources();
> + }
> +
> + @Override
> + protected File getOutputDirectory()
> + {
> + return new File( project.getBuild().getDirectory(),
> +
> BuildDirectories.BUILD_SOURCES.getBuildDirectoryName() );
> + }
> +
> + @Override
> + protected File getSourceDirectory()
> + {
> + return new File( project.getBuild().getSourceDirectory() );
> }
> }
>
> Modified:
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java
> URL:
> http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java?rev=608765&r1=608764&r2=608765&view=diff
>
> ==============================================================================
> ---
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java
> (original)
> +++
> incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestSourceProcessorMojo.java
> Thu Jan 3 23:11:25 2008
> @@ -18,20 +18,10 @@
> */
> package org.apache.maven.dotnet.plugin.compiler;
>
> -import org.apache.maven.plugin.AbstractMojo;
> -import org.apache.maven.plugin.MojoExecutionException;
> -import org.apache.maven.dotnet.ProgrammingLanguage;
> -import org.apache.maven.dotnet.BuildDirectories;
> -import org.apache.maven.project.MavenProject;
> -
> -import org.codehaus.plexus.util.DirectoryScanner;
> -import org.codehaus.plexus.util.FileUtils;
> -
> import java.io.File;
> -import java.io.IOException;
> -import java.util.Arrays;
> -import java.util.List;
> -import java.util.ArrayList;
> +
> +import org.apache.maven.dotnet.BuildDirectories;
> +import org.apache.maven.plugin.MojoExecutionException;
>
> /**
> * Copies test source files to target directory.
> @@ -40,36 +30,10 @@
> * @phase process-test-sources
> * @description Copies source files to target directory.
> */
> -
> public class TestSourceProcessorMojo
> - extends AbstractMojo
> + extends AbstractSourceProcessorMojo
> {
> - /**
> - * The maven project.
> - *
> - * @parameter expression="${project}"
> - * @required
> - */
> - private MavenProject project;
> -
> - /**
> - * @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;
> -
> +
> public void execute()
> throws MojoExecutionException
> {
> @@ -80,75 +44,19 @@
> return;
> }
>
> - File testSourceDirectory = new File( project.getBuild().getTestSourceDirectory()
> );
> - File outputDirectory =
> - new File( project.getBuild().getDirectory(),
> BuildDirectories.TEST_SOURCES.getBuildDirectoryName() );
> + processSources();
> + }
>
> - if ( !testSourceDirectory.exists() )
> - {
> - getLog().info( "NMAVEN-904-001: No test source files to copy"
> );
> - return;
> - }
> - DirectoryScanner directoryScanner = new DirectoryScanner();
> - directoryScanner.setBasedir( testSourceDirectory );
> -
> - List<String> excludeList = new ArrayList<String>(Arrays.asList
> (excludes));
> - List<String> includeList = new ArrayList<String>(Arrays.asList
> (includes));
> - includeList.add( "**/*." + ProgrammingLanguage.valueOf( language
> ).getClassFileExtension() );
> -
> - directoryScanner.setIncludes( includeList.toArray( includes ) );
> - directoryScanner.setExcludes( excludeList.toArray( excludes ) );
> -
> - directoryScanner.addDefaultExcludes();
> -
> - directoryScanner.scan();
> - String[] files = directoryScanner.getIncludedFiles();
> - getLog().info( "NMAVEN-904-002: Copying test source files: From =
> " + testSourceDirectory + ", To = " +
> - outputDirectory + ", File Count = " + files.length );
> + @Override
> + protected File getOutputDirectory()
> + {
> + return new File( project.getBuild().getDirectory(),
> +
> BuildDirectories.TEST_SOURCES.getBuildDirectoryName() );
> + }
>
> - super.getPluginContext().put( "TEST SOURCE_FILES_UP_TO_DATE",
> Boolean.TRUE );
> - for ( String file : files )
> - {
> - try
> - {
> - File sourceFile = new File( testSourceDirectory, file );
> - File targetFile = new File( outputDirectory, file );
> - if ( sourceFile.lastModified() > targetFile.lastModified()
> )
> - {
> - super.getPluginContext().put( "TEST
> 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 test sources", e );
> - }
> - }
> -
> - // Update the scanner to scan the output directory, and rescan
> - directoryScanner.setBasedir(outputDirectory);
> - List<String> outputDirExcludes = new
> ArrayList<String>(excludeList);
> - // Ignore meta-inf, including assembly info
> - outputDirExcludes.add( "META-INF/**" );
> - directoryScanner.setExcludes( outputDirExcludes.toArray( new
> String[0] ) );
> - directoryScanner.setBasedir( outputDirectory );
> - directoryScanner.scan();
> -
> - // Synchronize the target folder with the source. Specifically
> delete the targetFile if
> - // the source file no longer exists
> - for ( String file : directoryScanner.getIncludedFiles() )
> - {
> - File sourceFile = new File( testSourceDirectory, file );
> - File targetFile = new File( outputDirectory, file );
> -
> - if ( !sourceFile.exists() && targetFile.exists() )
> - {
> - if ( !targetFile.delete() )
> - {
> - getLog().warn( "Unable to delete stale target file
> " + targetFile.getPath() );
> - }
> - }
> - }
> + @Override
> + protected File getSourceDirectory()
> + {
> + return new File( project.getBuild().getTestSourceDirectory() );
> }
> }
>
>
>