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.
*
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id$
* @goal eclipse
* @requiresDependencyResolution test
* @execute phase="generate-sources"
*
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id$
*/
public class EclipsePlugin
extends AbstractMojo
{
/**
* The project whose project files to create.
*
* @parameter expression="${project}"
* @required
*/
@ -49,12 +49,14 @@ public class EclipsePlugin
/**
* The currently executed project (can be a reactor project).
*
* @parameter expression="${executedProject}"
*/
private MavenProject executedProject;
/**
* Local maven repository.
*
* @parameter expression="${localRepository}"
* @required
* @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.
*
* @parameter expression="${reactorProjects}"
* @required
* @readonly
@ -71,6 +74,7 @@ public class EclipsePlugin
/**
* Artifact resolver, needed to download source jars for inclusion in classpath.
*
* @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
* @required
* @readonly
@ -80,6 +84,7 @@ public class EclipsePlugin
/**
* Artifact factory, needed to download source jars for inclusion in classpath.
*
* @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
* @required
* @readonly
@ -89,6 +94,7 @@ public class EclipsePlugin
/**
* Remote repositories which will be searched for source attachments.
*
* @parameter expression="${project.remoteArtifactRepositories}"
* @required
* @readonly
@ -104,6 +110,7 @@ public class EclipsePlugin
* &lt;java.lang.String>org.eclipse.wst.common.modulecore.ModuleCoreNature&lt;/java.lang.String>
* &lt;/projectnatures>
* </pre>
*
* @parameter
* @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;/buildcommands>
* </pre>
*
* @parameter
* @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;/classpathContainers>
* </pre>
*
* @parameter
* @todo default-value=empty list
*/
@ -140,19 +149,21 @@ public class EclipsePlugin
/**
* Disables the downloading of source attachments.
*
*
* @parameter expression="${eclipse.downloadSources}"
*/
private boolean downloadSources = false;
/**
* Eclipse workspace directory.
*
* @parameter expression="${eclipse.workspace}"
*/
private File outputDir;
/**
* Setter for <code>project</code>. Needed for tests.
*
* @param project The MavenProject to set.
*/
protected void setProject( MavenProject project )
@ -162,6 +173,7 @@ public class EclipsePlugin
/**
* Setter for <code>localRepository</code>. Needed for tests.
*
* @param localRepository The ArtifactRepository to set.
*/
protected void setLocalRepository( ArtifactRepository localRepository )
@ -171,6 +183,7 @@ public class EclipsePlugin
/**
* Setter for <code>artifactFactory</code>. Needed for tests.
*
* @param artifactFactory The artifactFactory to set.
*/
protected void setArtifactFactory( ArtifactFactory artifactFactory )
@ -180,6 +193,7 @@ public class EclipsePlugin
/**
* Setter for <code>artifactResolver</code>. Needed for tests.
*
* @param artifactResolver The artifactResolver to set.
*/
protected void setArtifactResolver( ArtifactResolver artifactResolver )
@ -189,6 +203,7 @@ public class EclipsePlugin
/**
* Setter for <code>remoteArtifactRepositories</code>. Needed for tests.
*
* @param remoteArtifactRepositories The remoteArtifactRepositories to set.
*/
protected void setRemoteArtifactRepositories( List remoteArtifactRepositories )
@ -198,6 +213,7 @@ public class EclipsePlugin
/**
* Setter for <code>buildcommands</code>. Needed for tests.
*
* @param buildcommands The buildcommands to set.
*/
protected void setBuildcommands( List buildcommands )
@ -207,6 +223,7 @@ public class EclipsePlugin
/**
* Setter for <code>classpathContainers</code>. Needed for tests.
*
* @param classpathContainers The classpathContainers to set.
*/
protected void setClasspathContainers( List classpathContainers )
@ -216,6 +233,7 @@ public class EclipsePlugin
/**
* Setter for <code>projectnatures</code>. Needed for tests.
*
* @param projectnatures The projectnatures to set.
*/
protected void setProjectnatures( List projectnatures )
@ -225,6 +243,7 @@ public class EclipsePlugin
/**
* Setter for <code>outputDir</code>. Needed for tests.
*
* @param outputDir The outputDir to set.
*/
public void setOutputDir( File outputDir )
@ -243,7 +262,7 @@ public class EclipsePlugin
// backwards compat with alpha-2 only
executedProject = project;
}
assertNotEmpty( executedProject.getGroupId(), "groupId" ); //$NON-NLS-1$
assertNotEmpty( executedProject.getArtifactId(), "artifactId" ); //$NON-NLS-1$
@ -286,14 +305,16 @@ public class EclipsePlugin
{
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() );
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 );
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 )
@ -335,7 +356,13 @@ public class EclipsePlugin
{
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.
*/
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.factory.ArtifactFactory;
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.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>
* @version $Id$
@ -90,11 +90,9 @@ public class EclipsePluginTest
File repo = getTestFile( "src/test/repository" );
ArtifactRepositoryLayout localRepositoryLayout = (ArtifactRepositoryLayout) lookup(
ArtifactRepositoryLayout.ROLE,
"legacy" );
ArtifactRepositoryLayout.ROLE, "legacy" );
ArtifactRepository localRepository = new DefaultArtifactRepository( "local",
"file://" + repo.getAbsolutePath(),
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", "file://" + repo.getAbsolutePath(),
localRepositoryLayout );
MavenProject project = builder
@ -145,18 +143,20 @@ public class EclipsePluginTest
plugin.setClasspathContainers( new ArrayList() );
plugin.setDownloadSources( true );
// @todo how to test injected parameters?
plugin.execute();
assertFileEquals( localRepository.getBasedir(), new File( basedir, "project" ), new File( projectOutputDir,
".project" ) );
assertFileEquals( localRepository.getBasedir(), new File( basedir, "project" ),
new File( projectOutputDir, ".project" ) );
assertFileEquals( localRepository.getBasedir(), new File( basedir, "classpath" ), new File( projectOutputDir,
".classpath" ) );
assertFileEquals( localRepository.getBasedir(), new File( basedir, "classpath" ),
new File( projectOutputDir, ".classpath" ) );
assertFileEquals( localRepository.getBasedir(), new File( basedir, "wtpmodules" ), new File( projectOutputDir,
".wtpmodules" ) );
assertFileEquals( localRepository.getBasedir(), new File( basedir, "wtpmodules" ),
new File( projectOutputDir, ".wtpmodules" ) );
if ( new File( basedir, "settings" ).exists() )
{
@ -183,8 +183,8 @@ public class EclipsePluginTest
if ( actualLines.size() <= i )
{
fail( "Too few lines in the actual file. Was " + actualLines.size() + ", expected: "
+ expectedLines.size() );
fail( "Too few lines in the actual file. Was " + actualLines.size() + ", expected: " +
expectedLines.size() );
}
String actual = actualLines.get( i ).toString();
@ -212,7 +212,8 @@ public class EclipsePluginTest
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;