fix eclipse plugin tests

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@289359 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-16 01:37:39 +00:00
parent 139efa3bdf
commit e3899c9cbc
2 changed files with 58 additions and 30 deletions

View File

@ -30,18 +30,18 @@ import java.util.List;
/** /**
* A Maven2 plugin which integrates the use of Maven2 with Eclipse. * A Maven2 plugin which integrates the use of Maven2 with Eclipse.
* *
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id$
* @goal eclipse * @goal eclipse
* @requiresDependencyResolution test * @requiresDependencyResolution test
* @execute phase="generate-sources" * @execute phase="generate-sources"
*
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id$
*/ */
public class EclipsePlugin public class EclipsePlugin
extends AbstractMojo extends AbstractMojo
{ {
/** /**
* The project whose project files to create. * The project whose project files to create.
*
* @parameter expression="${project}" * @parameter expression="${project}"
* @required * @required
*/ */
@ -49,12 +49,14 @@ public class EclipsePlugin
/** /**
* The currently executed project (can be a reactor project). * The currently executed project (can be a reactor project).
*
* @parameter expression="${executedProject}" * @parameter expression="${executedProject}"
*/ */
private MavenProject executedProject; private MavenProject executedProject;
/** /**
* Local maven repository. * Local maven repository.
*
* @parameter expression="${localRepository}" * @parameter expression="${localRepository}"
* @required * @required
* @readonly * @readonly
@ -63,6 +65,7 @@ public class EclipsePlugin
/** /**
* If the executed project is a reactor project, this will contains the full list of projects in the reactor. * If the executed project is a reactor project, this will contains the full list of projects in the reactor.
*
* @parameter expression="${reactorProjects}" * @parameter expression="${reactorProjects}"
* @required * @required
* @readonly * @readonly
@ -71,6 +74,7 @@ public class EclipsePlugin
/** /**
* Artifact resolver, needed to download source jars for inclusion in classpath. * Artifact resolver, needed to download source jars for inclusion in classpath.
*
* @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}" * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
* @required * @required
* @readonly * @readonly
@ -80,6 +84,7 @@ public class EclipsePlugin
/** /**
* Artifact factory, needed to download source jars for inclusion in classpath. * Artifact factory, needed to download source jars for inclusion in classpath.
*
* @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}" * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
* @required * @required
* @readonly * @readonly
@ -89,6 +94,7 @@ public class EclipsePlugin
/** /**
* Remote repositories which will be searched for source attachments. * Remote repositories which will be searched for source attachments.
*
* @parameter expression="${project.remoteArtifactRepositories}" * @parameter expression="${project.remoteArtifactRepositories}"
* @required * @required
* @readonly * @readonly
@ -104,6 +110,7 @@ public class EclipsePlugin
* &lt;java.lang.String>org.eclipse.wst.common.modulecore.ModuleCoreNature&lt;/java.lang.String> * &lt;java.lang.String>org.eclipse.wst.common.modulecore.ModuleCoreNature&lt;/java.lang.String>
* &lt;/projectnatures> * &lt;/projectnatures>
* </pre> * </pre>
*
* @parameter * @parameter
* @todo default-value="<java.lang.String>org.eclipse.jdt.core.javanature</java.lang.String>" * @todo default-value="<java.lang.String>org.eclipse.jdt.core.javanature</java.lang.String>"
*/ */
@ -119,6 +126,7 @@ public class EclipsePlugin
* &lt;java.lang.String>org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver&lt;/java.lang.String> * &lt;java.lang.String>org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver&lt;/java.lang.String>
* &lt;/buildcommands> * &lt;/buildcommands>
* </pre> * </pre>
*
* @parameter * @parameter
* @todo default-value="org.eclipse.jdt.core.javabuilder" * @todo default-value="org.eclipse.jdt.core.javabuilder"
*/ */
@ -133,6 +141,7 @@ public class EclipsePlugin
* &lt;java.lang.String>org.eclipse.jst.j2ee.internal.web.container/artifact&lt;/java.lang.String> * &lt;java.lang.String>org.eclipse.jst.j2ee.internal.web.container/artifact&lt;/java.lang.String>
* &lt;/classpathContainers> * &lt;/classpathContainers>
* </pre> * </pre>
*
* @parameter * @parameter
* @todo default-value=empty list * @todo default-value=empty list
*/ */
@ -147,12 +156,14 @@ public class EclipsePlugin
/** /**
* Eclipse workspace directory. * Eclipse workspace directory.
*
* @parameter expression="${eclipse.workspace}" * @parameter expression="${eclipse.workspace}"
*/ */
private File outputDir; private File outputDir;
/** /**
* Setter for <code>project</code>. Needed for tests. * Setter for <code>project</code>. Needed for tests.
*
* @param project The MavenProject to set. * @param project The MavenProject to set.
*/ */
protected void setProject( MavenProject project ) protected void setProject( MavenProject project )
@ -162,6 +173,7 @@ public class EclipsePlugin
/** /**
* Setter for <code>localRepository</code>. Needed for tests. * Setter for <code>localRepository</code>. Needed for tests.
*
* @param localRepository The ArtifactRepository to set. * @param localRepository The ArtifactRepository to set.
*/ */
protected void setLocalRepository( ArtifactRepository localRepository ) protected void setLocalRepository( ArtifactRepository localRepository )
@ -171,6 +183,7 @@ public class EclipsePlugin
/** /**
* Setter for <code>artifactFactory</code>. Needed for tests. * Setter for <code>artifactFactory</code>. Needed for tests.
*
* @param artifactFactory The artifactFactory to set. * @param artifactFactory The artifactFactory to set.
*/ */
protected void setArtifactFactory( ArtifactFactory artifactFactory ) protected void setArtifactFactory( ArtifactFactory artifactFactory )
@ -180,6 +193,7 @@ public class EclipsePlugin
/** /**
* Setter for <code>artifactResolver</code>. Needed for tests. * Setter for <code>artifactResolver</code>. Needed for tests.
*
* @param artifactResolver The artifactResolver to set. * @param artifactResolver The artifactResolver to set.
*/ */
protected void setArtifactResolver( ArtifactResolver artifactResolver ) protected void setArtifactResolver( ArtifactResolver artifactResolver )
@ -189,6 +203,7 @@ public class EclipsePlugin
/** /**
* Setter for <code>remoteArtifactRepositories</code>. Needed for tests. * Setter for <code>remoteArtifactRepositories</code>. Needed for tests.
*
* @param remoteArtifactRepositories The remoteArtifactRepositories to set. * @param remoteArtifactRepositories The remoteArtifactRepositories to set.
*/ */
protected void setRemoteArtifactRepositories( List remoteArtifactRepositories ) protected void setRemoteArtifactRepositories( List remoteArtifactRepositories )
@ -198,6 +213,7 @@ public class EclipsePlugin
/** /**
* Setter for <code>buildcommands</code>. Needed for tests. * Setter for <code>buildcommands</code>. Needed for tests.
*
* @param buildcommands The buildcommands to set. * @param buildcommands The buildcommands to set.
*/ */
protected void setBuildcommands( List buildcommands ) protected void setBuildcommands( List buildcommands )
@ -207,6 +223,7 @@ public class EclipsePlugin
/** /**
* Setter for <code>classpathContainers</code>. Needed for tests. * Setter for <code>classpathContainers</code>. Needed for tests.
*
* @param classpathContainers The classpathContainers to set. * @param classpathContainers The classpathContainers to set.
*/ */
protected void setClasspathContainers( List classpathContainers ) protected void setClasspathContainers( List classpathContainers )
@ -216,6 +233,7 @@ public class EclipsePlugin
/** /**
* Setter for <code>projectnatures</code>. Needed for tests. * Setter for <code>projectnatures</code>. Needed for tests.
*
* @param projectnatures The projectnatures to set. * @param projectnatures The projectnatures to set.
*/ */
protected void setProjectnatures( List projectnatures ) protected void setProjectnatures( List projectnatures )
@ -225,6 +243,7 @@ public class EclipsePlugin
/** /**
* Setter for <code>outputDir</code>. Needed for tests. * Setter for <code>outputDir</code>. Needed for tests.
*
* @param outputDir The outputDir to set. * @param outputDir The outputDir to set.
*/ */
public void setOutputDir( File outputDir ) public void setOutputDir( File outputDir )
@ -286,14 +305,16 @@ public class EclipsePlugin
{ {
if ( !outputDir.isDirectory() ) if ( !outputDir.isDirectory() )
{ {
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.notadir", outputDir ) ); //$NON-NLS-1$ throw new MojoExecutionException(
Messages.getString( "EclipsePlugin.notadir", outputDir ) ); //$NON-NLS-1$
} }
outputDir = new File( outputDir, executedProject.getArtifactId() ); outputDir = new File( outputDir, executedProject.getArtifactId() );
if ( !outputDir.isDirectory() && !outputDir.mkdir() ) if ( !outputDir.isDirectory() && !outputDir.mkdir() )
{ {
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantcreatedir", outputDir ) ); //$NON-NLS-1$ throw new MojoExecutionException(
Messages.getString( "EclipsePlugin.cantcreatedir", outputDir ) ); //$NON-NLS-1$
} }
} }
@ -327,7 +348,7 @@ public class EclipsePlugin
localRepository ); localRepository );
getLog().info( Messages.getString( "EclipsePlugin.wrote", //$NON-NLS-1$ getLog().info( Messages.getString( "EclipsePlugin.wrote", //$NON-NLS-1$
new Object[] { project.getArtifactId(), outputDir.getAbsolutePath() } ) ); new Object[]{project.getArtifactId(), outputDir.getAbsolutePath()} ) );
} }
private void assertNotEmpty( String string, String elementName ) private void assertNotEmpty( String string, String elementName )
@ -335,7 +356,13 @@ public class EclipsePlugin
{ {
if ( string == null ) if ( string == null )
{ {
throw new EclipsePluginException( Messages.getString( "EclipsePlugin.missingelement", elementName ) ); //$NON-NLS-1$ throw new EclipsePluginException(
Messages.getString( "EclipsePlugin.missingelement", elementName ) ); //$NON-NLS-1$
} }
} }
public void setDownloadSources( boolean downloadSources )
{
this.downloadSources = downloadSources;
}
} }

View File

@ -16,14 +16,6 @@ package org.apache.maven.plugin.eclipse;
* limitations under the License. * limitations under the License.
*/ */
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
@ -35,6 +27,14 @@ import org.apache.maven.project.MavenProjectBuilder;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/** /**
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a> * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id$ * @version $Id$
@ -90,11 +90,9 @@ public class EclipsePluginTest
File repo = getTestFile( "src/test/repository" ); File repo = getTestFile( "src/test/repository" );
ArtifactRepositoryLayout localRepositoryLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout localRepositoryLayout = (ArtifactRepositoryLayout) lookup(
ArtifactRepositoryLayout.ROLE, ArtifactRepositoryLayout.ROLE, "legacy" );
"legacy" );
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", ArtifactRepository localRepository = new DefaultArtifactRepository( "local", "file://" + repo.getAbsolutePath(),
"file://" + repo.getAbsolutePath(),
localRepositoryLayout ); localRepositoryLayout );
MavenProject project = builder MavenProject project = builder
@ -145,18 +143,20 @@ public class EclipsePluginTest
plugin.setClasspathContainers( new ArrayList() ); plugin.setClasspathContainers( new ArrayList() );
plugin.setDownloadSources( true );
// @todo how to test injected parameters? // @todo how to test injected parameters?
plugin.execute(); plugin.execute();
assertFileEquals( localRepository.getBasedir(), new File( basedir, "project" ), new File( projectOutputDir, assertFileEquals( localRepository.getBasedir(), new File( basedir, "project" ),
".project" ) ); new File( projectOutputDir, ".project" ) );
assertFileEquals( localRepository.getBasedir(), new File( basedir, "classpath" ), new File( projectOutputDir, assertFileEquals( localRepository.getBasedir(), new File( basedir, "classpath" ),
".classpath" ) ); new File( projectOutputDir, ".classpath" ) );
assertFileEquals( localRepository.getBasedir(), new File( basedir, "wtpmodules" ), new File( projectOutputDir, assertFileEquals( localRepository.getBasedir(), new File( basedir, "wtpmodules" ),
".wtpmodules" ) ); new File( projectOutputDir, ".wtpmodules" ) );
if ( new File( basedir, "settings" ).exists() ) if ( new File( basedir, "settings" ).exists() )
{ {
@ -183,8 +183,8 @@ public class EclipsePluginTest
if ( actualLines.size() <= i ) if ( actualLines.size() <= i )
{ {
fail( "Too few lines in the actual file. Was " + actualLines.size() + ", expected: " fail( "Too few lines in the actual file. Was " + actualLines.size() + ", expected: " +
+ expectedLines.size() ); expectedLines.size() );
} }
String actual = actualLines.get( i ).toString(); String actual = actualLines.get( i ).toString();
@ -212,7 +212,8 @@ public class EclipsePluginTest
while ( ( line = reader.readLine() ) != null ) while ( ( line = reader.readLine() ) != null )
{ {
lines.add( line );//StringUtils.replace( line, "#ArtifactRepositoryPath#", mavenRepo.replace( '\\', '/' ) ) ); lines.add(
line );//StringUtils.replace( line, "#ArtifactRepositoryPath#", mavenRepo.replace( '\\', '/' ) ) );
} }
return lines; return lines;