Thanks Martin,
I have committed your patch and credited you with the change in the
index.apt so it will appear in the new on the project site home page.
Thanks again,
Doug
Martin Kalén wrote:
> Greetings,
>
> Martin Kalén wrote:
>> [...] StatSCM cannot handle POM overrides of the default build- and
>> reporting output directories.
>>
>> (Ie ${project.build.directory} and ${project.reporting.outputDirectory})
>
> Attached is the patch as per request.
>
> Tested/verified with a POM that overrides both build- and reporting
> output directories (the "target" directory is not at all present).
>
> You might want to check coding conventions, run some additional tests
> etc and tweak the patch to your liking.
>
> Best regards,
> Martin
>
> P.S. If you need it: permission to use the attached code under the
> Apache License Version 2.0 is hereby granted by me, Martin Kalén, the
> sole author.
> ------------------------------------------------------------------------
>
> Index: src/test/java/net/sf/statscm/StatConfTest.java
> ===================================================================
> --- src/test/java/net/sf/statscm/StatConfTest.java (revision 165)
> +++ src/test/java/net/sf/statscm/StatConfTest.java (working copy)
> @@ -16,6 +16,7 @@
> * limitations under the License.
> */
>
> +import java.lang.reflect.Method;
> import java.util.ArrayList;
> import java.util.List;
> import java.util.Locale;
> @@ -25,6 +26,7 @@
> import org.apache.maven.model.Build;
> import org.apache.maven.model.Developer;
> import org.apache.maven.model.Model;
> +import org.apache.maven.model.Reporting;
> import org.apache.maven.model.Scm;
> import org.apache.maven.model.IssueManagement;
> import org.apache.maven.project.MavenProject;
> @@ -77,7 +79,7 @@
> assertEquals( StatConf.CONNECTION_TYPE_SVN,
> StatConf.extractConnectionType( "svn:https://svn.sourceforge.net/svnroot/stat-scm/trunk" ) );
> }
> -
> +
> /**
> * Test to make sure that null pointers are handled, and errors are throwen corectly.
> *
> @@ -142,7 +144,53 @@
> }
> }
>
> +
> /**
> + * Regression test custom build- and report output paths in POM.
> + */
> + public void testConfigureFromPOMWithCustomPaths() throws Exception
> + {
> + MavenProject project = new MavenProject( new Model() );
> + StatScmMojo statScmMojo = new StatScmMojo();
> + statScmMojo.setProject( project );
> + StatConf statConf = statScmMojo.getStatConf();
> + Scm scm = new Scm();
> + project.setScm( scm );
> + scm.setDeveloperConnection( "svn:https://svn.sourceforge.net/svnroot/stat-scm/trunk" );
> + statConf.configure( project, Locale.ENGLISH );
> +
> + // Make protected method accessible for test purposes
> + String getReportingTargetDirectoryMethodName = "getReportingTargetDirectory";
> + Method getReportingTargetDirectory = statScmMojo.getClass().getDeclaredMethod( getReportingTargetDirectoryMethodName, (Class []) null );
> + assertNotNull( "Test case must be updated with refactored method name in " + statScmMojo.getClass().getName(),
> + getReportingTargetDirectory );
> + getReportingTargetDirectory.setAccessible( true );
> +
> + assertNotNull( StatConf.getOutputDir() );
> + assertTrue( "Fall back behaviour failed", StatConf.getOutputDir().indexOf("target") != -1 );
> +
> + String reportingTargetDirectory = (String) getReportingTargetDirectory.invoke( statScmMojo, (Object []) null );
> + assertNotNull( reportingTargetDirectory );
> + assertTrue( "Fall back behaviour failed", reportingTargetDirectory.indexOf("target") != -1 );
> +
> + String customBuildDirectory = "build";
> + Build build = new Build();
> + build.setDirectory( customBuildDirectory );
> + project.setBuild( build );
> + statConf.configure( project, Locale.ENGLISH );
> + assertEquals( "Custom build directory configuration ignored", -1, StatConf.getOutputDir().indexOf("target") );
> + assertTrue( "Custom build directory configuration ignored", StatConf.getOutputDir().indexOf(customBuildDirectory) != -1 );
> +
> + String customReportOutputDirectory = customBuildDirectory + System.getProperty( "file.separator" ) + "site";
> + Reporting reporting = new Reporting();
> + reporting.setOutputDirectory(customReportOutputDirectory);
> + project.setReporting( reporting );
> + reportingTargetDirectory = (String) getReportingTargetDirectory.invoke( statScmMojo, (Object []) null );
> + assertEquals( "Custom report output directory configuration ignored", -1, reportingTargetDirectory.indexOf("target") );
> + assertTrue( "Custom report output directory configuration ignored", reportingTargetDirectory.indexOf(customReportOutputDirectory) != -1 );
> + }
> +
> + /**
> *
> * @throws ConfigurationException
> */
> Index: src/main/java/net/sf/statscm/StatConf.java
> ===================================================================
> --- src/main/java/net/sf/statscm/StatConf.java (revision 165)
> +++ src/main/java/net/sf/statscm/StatConf.java (working copy)
> @@ -22,6 +22,7 @@
> import net.sf.statcvs.output.ConfigurationException;
> import net.sf.statcvs.output.ConfigurationOptions;
>
> +import org.apache.maven.model.Build;
> import org.apache.maven.model.Developer;
> import org.apache.maven.project.MavenProject;
>
> @@ -104,7 +105,17 @@
> // Set output parameters.
> setOutputFormat( "xdoc" );
> // ? setDefaultCssFile("maven2-xdoc.css");
> - setOutputDir( baseDirectory.getAbsolutePath() + FILE_SEPARATOR + "target" + FILE_SEPARATOR + "generated-site"
> + String buildBaseDirectory = null;
> + Build build = project.getBuild();
> + if ( build != null )
> + {
> + buildBaseDirectory = build.getDirectory();
> + }
> + if ( buildBaseDirectory == null )
> + {
> + buildBaseDirectory = baseDirectory.getAbsolutePath() + FILE_SEPARATOR + "target";
> + }
> + setOutputDir( buildBaseDirectory + FILE_SEPARATOR + "generated-site"
> + FILE_SEPARATOR + "xdoc" + FILE_SEPARATOR + STATSCM_DIR_NAME );
>
> // Set up connection type
> Index: src/main/java/net/sf/statscm/StatScmMojo.java
> ===================================================================
> --- src/main/java/net/sf/statscm/StatScmMojo.java (revision 165)
> +++ src/main/java/net/sf/statscm/StatScmMojo.java (working copy)
> @@ -37,6 +37,7 @@
> import java.util.Locale;
> import java.util.ResourceBundle;
>
> +import org.apache.maven.model.Reporting;
> import org.apache.maven.project.MavenProject;
>
> /**
> @@ -223,8 +224,7 @@
> doCvsStats();
> }
> doGenerateReport( getSink() );
> - copyResourceFiles( getOutputDirectory(), project.getBasedir() + statConf.FILE_SEPARATOR + "target"
> - + statConf.FILE_SEPARATOR + "site" + statConf.FILE_SEPARATOR + StatConf.STATSCM_DIR_NAME );
> + copyResourceFiles( getOutputDirectory(), getReportingTargetDirectory() );
> }
> else
> {
> @@ -542,6 +542,28 @@
> }
>
> /**
> + * Returns the StatSCM report target directory.
> + *
> + * @return Absolute path to the directory with final HTML result.
> + */
> + protected String getReportingTargetDirectory()
> + {
> + String targetBaseDirectory = null;
> + Reporting reporting = getProject().getReporting();
> + if ( reporting != null)
> + {
> + targetBaseDirectory = reporting.getOutputDirectory();
> + }
> + if ( targetBaseDirectory == null)
> + {
> + targetBaseDirectory = getStatConf().getBaseDirectory().getAbsolutePath()
> + + statConf.FILE_SEPARATOR + "target"
> + + statConf.FILE_SEPARATOR + "site";
> + }
> + return targetBaseDirectory + statConf.FILE_SEPARATOR + StatConf.STATSCM_DIR_NAME;
> + }
> +
> + /**
> * String name of the html file that the Reporting Menu uses for a link.
> *
> * @return Name of Html file to link to.
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> ------------------------------------------------------------------------
>
> _______________________________________________
> Stat-scm-developer mailing list
> Sta...@li...
> https://lists.sourceforge.net/lists/listinfo/stat-scm-developer
>
|