Author: vsiveton Date: Sun Jun 3 03:43:21 2007 New Revision: 543876 URL: http://svn.apache.org/viewvc?view=rev&rev=543876 Log: JXR-52: Dont generate xref report if project has pom packaging and src/main exists
o check if the project packaging is a pom o added a test case o bumped to maven-plugin-testing-harness:1.0 and used it in the test scope o bumped to maven-reporting-api:2.0.2 to be consistent with the impl version Added: maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/stubs/PomMavenProjectStub.java (with props) maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/ maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/pom-test-plugin-config.xml (with props) maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/ maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/main/ maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/main/java/ maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/main/java/maven/ maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/main/java/maven/App.java (with props) maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/test/ maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/test/java/ maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/test/java/maven/ maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/test/java/maven/AppTest.java (with props) Modified: maven/jxr/trunk/maven-jxr-plugin/pom.xml maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReport.java maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrTestReport.java maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/JxrReportTest.java Modified: maven/jxr/trunk/maven-jxr-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/pom.xml?view=diff&rev=543876&r1=543875&r2=543876 ============================================================================== --- maven/jxr/trunk/maven-jxr-plugin/pom.xml (original) +++ maven/jxr/trunk/maven-jxr-plugin/pom.xml Sun Jun 3 03:43:21 2007 @@ -48,7 +48,7 @@ <dependency> <groupId>org.apache.maven.reporting</groupId> <artifactId>maven-reporting-api</artifactId> - <version>2.0</version> + <version>2.0.2</version> </dependency> <dependency> <groupId>org.apache.maven</groupId> @@ -63,7 +63,8 @@ <dependency> <groupId>org.apache.maven.shared</groupId> <artifactId>maven-plugin-testing-harness</artifactId> - <version>1.0-beta-1</version> + <version>1.0</version> + <scope>test</scope> </dependency> </dependencies> <reporting> Modified: maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReport.java URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReport.java?view=diff&rev=543876&r1=543875&r2=543876 ============================================================================== --- maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReport.java (original) +++ maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReport.java Sun Jun 3 03:43:21 2007 @@ -23,6 +23,7 @@ import org.apache.maven.project.MavenProject; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; @@ -46,7 +47,7 @@ * @readonly */ private List sourceDirs; - + /** * Specifies the source path where the java files are located. * The paths are separated by '<code>;</code>'. @@ -98,7 +99,23 @@ return Arrays.asList( sourcePathArray ); } } - return sourceDirs; + + List l = new ArrayList(); + + if ( !"pom".equals( getProject().getPackaging().toLowerCase() ) ) + { + l.addAll( sourceDirs ); + } + + if ( getProject().getExecutionProject() != null ) + { + if ( !"pom".equals( getProject().getExecutionProject().getPackaging().toLowerCase() ) ) + { + l.addAll( getProject().getExecutionProject().getCompileSourceRoots() ); + } + } + + return l; } /** @@ -106,7 +123,22 @@ */ protected List getSourceRoots( MavenProject project ) { - return project.getCompileSourceRoots(); + List l = new ArrayList(); + + if ( !"pom".equals( project.getPackaging().toLowerCase() ) ) + { + l.addAll( project.getCompileSourceRoots() ); + } + + if ( project.getExecutionProject() != null ) + { + if ( !"pom".equals( project.getExecutionProject().getPackaging().toLowerCase() ) ) + { + l.addAll( project.getExecutionProject().getCompileSourceRoots() ); + } + } + + return l; } /** Modified: maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrTestReport.java URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrTestReport.java?view=diff&rev=543876&r1=543875&r2=543876 ============================================================================== --- maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrTestReport.java (original) +++ maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrTestReport.java Sun Jun 3 03:43:21 2007 @@ -22,6 +22,7 @@ import org.apache.maven.project.MavenProject; import java.io.File; +import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -57,7 +58,22 @@ */ protected List getSourceRoots() { - return this.sourceDirs; + List l = new ArrayList(); + + if ( !"pom".equals( getProject().getPackaging().toLowerCase() ) ) + { + l.addAll( sourceDirs ); + } + + if ( getProject().getExecutionProject() != null ) + { + if ( !"pom".equals( getProject().getExecutionProject().getPackaging().toLowerCase() ) ) + { + l.addAll( getProject().getExecutionProject().getTestCompileSourceRoots() ); + } + } + + return l; } /** @@ -65,7 +81,22 @@ */ protected List getSourceRoots( MavenProject project ) { - return project.getTestCompileSourceRoots(); + List l = new ArrayList(); + + if ( !"pom".equals( project.getPackaging().toLowerCase() ) ) + { + l.addAll( project.getExecutionProject().getCompileSourceRoots() ); + } + + if ( project.getExecutionProject() != null ) + { + if ( !"pom".equals( project.getExecutionProject().getPackaging().toLowerCase() ) ) + { + l.addAll( project.getExecutionProject().getTestCompileSourceRoots() ); + } + } + + return l; } /** Modified: maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/JxrReportTest.java URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/JxrReportTest.java?view=diff&rev=543876&r1=543875&r2=543876 ============================================================================== --- maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/JxrReportTest.java (original) +++ maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/JxrReportTest.java Sun Jun 3 03:43:21 2007 @@ -35,6 +35,9 @@ extends AbstractMojoTestCase { + /** + * @see org.apache.maven.plugin.testing.AbstractMojoTestCase#setUp() + */ protected void setUp() throws Exception { @@ -42,6 +45,15 @@ } /** + * @see org.codehaus.plexus.PlexusTestCase#tearDown() + */ + protected void tearDown() + throws Exception + { + // nop + } + + /** * Test the plugin with default configuration * * @throws Exception @@ -323,10 +335,20 @@ } } - protected void tearDown() + /** + * Test the jxr for a POM project. + * + * @throws Exception + */ + public void testPom() throws Exception { + File testPom = new File( getBasedir(), + "src/test/resources/unit/pom-test/pom-test-plugin-config.xml" ); + JxrReport mojo = (JxrReport) lookupMojo( "jxr", testPom ); + mojo.execute(); + assertFalse( new File( getBasedir(), "target/test/unit/pom-test" ).exists() ); } /** @@ -336,7 +358,7 @@ * @param destDir * @throws IOException */ - private void copyFilesFromDirectory( File srcDir, File destDir ) + private static void copyFilesFromDirectory( File srcDir, File destDir ) throws IOException { FileUtils.copyDirectoryStructure( srcDir, destDir ); @@ -349,7 +371,7 @@ * @return a String object that contains the contents of the file * @throws IOException */ - private String readFile( File file ) + private static String readFile( File file ) throws IOException { String str = "", strTmp = ""; @@ -363,5 +385,4 @@ return str; } - } Added: maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/stubs/PomMavenProjectStub.java URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/stubs/PomMavenProjectStub.java?view=auto&rev=543876 ============================================================================== --- maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/stubs/PomMavenProjectStub.java (added) +++ maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/stubs/PomMavenProjectStub.java Sun Jun 3 03:43:21 2007 @@ -0,0 +1,103 @@ +package org.apache.maven.plugin.jxr.stubs; + +/* + * 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. + */ + +import java.io.File; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.model.Build; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.plugin.testing.stubs.MavenProjectStub; + +/** + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a> + */ +public class PomMavenProjectStub + extends MavenProjectStub +{ + private Build build; + + public PomMavenProjectStub() + { + MavenXpp3Reader pomReader = new MavenXpp3Reader(); + Model model = null; + + try + { + model = pomReader.read( new FileReader( new File( getBasedir(), "pom-test-plugin-config.xml" ) ) ); + setModel( model ); + } + catch ( Exception e ) + { + throw new RuntimeException( e ); + } + + setGroupId( model.getGroupId() ); + setArtifactId( model.getArtifactId() ); + setVersion( model.getVersion() ); + setName( model.getName() ); + setUrl( model.getUrl() ); + setPackaging( model.getPackaging() ); + + Build build = new Build(); + build.setFinalName( model.getArtifactId() ); + build.setDirectory( super.getBasedir() + "/target/test/unit/pom-test/target" ); + build.setSourceDirectory( getBasedir() + "/src/main/java" ); + build.setOutputDirectory( super.getBasedir() + "/target/test/unit/pom-test/target/classes" ); + build.setTestSourceDirectory( getBasedir() + "/src/test/java" ); + build.setTestOutputDirectory( super.getBasedir() + "/target/test/unit/pom-test/target/test-classes" ); + setBuild( build ); + + List compileSourceRoots = new ArrayList(); + compileSourceRoots.add( getBasedir() + "/src/main/java" ); + setCompileSourceRoots( compileSourceRoots ); + + List testCompileSourceRoots = new ArrayList(); + testCompileSourceRoots.add( getBasedir() + "/src/test/java" ); + setTestCompileSourceRoots( testCompileSourceRoots ); + } + + /** + * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getBuild() + */ + public Build getBuild() + { + return build; + } + + /** + * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#setBuild(org.apache.maven.model.Build) + */ + public void setBuild( Build build ) + { + this.build = build; + } + + /** + * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getBasedir() + */ + public File getBasedir() + { + return new File( super.getBasedir() + "/src/test/resources/unit/pom-test" ); + } +} Propchange: maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/stubs/PomMavenProjectStub.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/stubs/PomMavenProjectStub.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/pom-test-plugin-config.xml URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/pom-test-plugin-config.xml?view=auto&rev=543876 ============================================================================== --- maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/pom-test-plugin-config.xml (added) +++ maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/pom-test-plugin-config.xml Sun Jun 3 03:43:21 2007 @@ -0,0 +1,48 @@ +<!-- +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. +--> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>test.jxr.pom</groupId> + <artifactId>pom</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>pom</packaging> + <name>project1</name> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jxr-plugin</artifactId> + <configuration> + <project implementation="org.apache.maven.plugin.jxr.stubs.PomMavenProjectStub"/> + <outputDirectory>${basedir}/target/test/unit/pom-test/target/site/</outputDirectory> + </configuration> + </plugin> + </plugins> + </build> +</project> Propchange: maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/pom-test-plugin-config.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/pom-test-plugin-config.xml ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/main/java/maven/App.java URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/main/java/maven/App.java?view=auto&rev=543876 ============================================================================== --- maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/main/java/maven/App.java (added) +++ maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/main/java/maven/App.java Sun Jun 3 03:43:21 2007 @@ -0,0 +1,13 @@ +package maven; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} Propchange: maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/main/java/maven/App.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/main/java/maven/App.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/test/java/maven/AppTest.java URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/test/java/maven/AppTest.java?view=auto&rev=543876 ============================================================================== --- maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/test/java/maven/AppTest.java (added) +++ maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/test/java/maven/AppTest.java Sun Jun 3 03:43:21 2007 @@ -0,0 +1,38 @@ +package maven; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} Propchange: maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/test/java/maven/AppTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/jxr/trunk/maven-jxr-plugin/src/test/resources/unit/pom-test/src/test/java/maven/AppTest.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision"