Author: epunzalan
Date: Tue Apr 4 01:12:25 2006
New Revision: 391243
URL: http://svn.apache.org/viewcvs?rev=391243&view=rev
Log:
PR: MIDEA-43
Added more assertions for idea:module minimum configuration
Modified:
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/AbstractIdeaTestCase.java
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaModuleTest.java
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/IdeaArtifactStub.java
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/SimpleMavenProjectStub.java
Modified:
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/AbstractIdeaTestCase.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/AbstractIdeaTestCase.java?rev=391243&r1=391242&r2=391243&view=diff
==============================================================================
---
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/AbstractIdeaTestCase.java
(original)
+++
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/AbstractIdeaTestCase.java
Tue Apr 4 01:12:25 2006
@@ -108,4 +108,16 @@
{
return element.elements( elementName );
}
+
+ protected Element findElement( Element component, String name )
+ {
+ Element element = component.element( name );
+
+ if ( element == null )
+ {
+ fail( "Element " + name + " not found." );
+ }
+
+ return element;
+ }
}
Modified:
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaModuleTest.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaModuleTest.java?rev=391243&r1=391242&r2=391243&view=diff
==============================================================================
---
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaModuleTest.java
(original)
+++
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/IdeaModuleTest.java
Tue Apr 4 01:12:25 2006
@@ -1,6 +1,11 @@
package org.apache.maven.plugin.idea;
import org.dom4j.Document;
+import org.dom4j.Element;
+
+import java.util.List;
+import java.util.Iterator;
+import java.util.ArrayList;
/*
* Copyright 2005-2006 The Apache Software Foundation.
@@ -27,14 +32,73 @@
public void testMinConfig()
throws Exception
{
+ List expectedDeps = new ArrayList();
+ expectedDeps.add(
"jar://E:/localRepository/org.apache.maven/maven-model/2.0.1/maven-model-2.0.1.jar!/"
);
+ expectedDeps.add(
"jar://E:/localRepository/junit/junit/3.8.1/junit-3.8.1.jar!/" );
+
Document imlDocument = executeMojo(
"src/test/module-plugin-configs/min-plugin-config.xml" );
+ Element component = findComponent( imlDocument.getRootElement(),
"NewModuleRootManager" );
+
+ List orderEntryList = findElementsByName( component, "orderEntry" );
+
+ for ( Iterator orderEntries = orderEntryList.iterator();
orderEntries.hasNext(); )
+ {
+ Element orderEntry = (Element) orderEntries.next();
+
+ if ( "module-library".equals( orderEntry.attributeValue( "type" )
) )
+ {
+ Element library = (Element) orderEntry.elementIterator(
"library" ).next();
+
+ Element classes = (Element) library.elementIterator( "CLASSES"
).next();
+
+ Element root = (Element) classes.elementIterator( "root"
).next();
+
+ assertTrue( "Dependency is present", expectedDeps.contains(
root.attributeValue( "url" ) ) );
+ expectedDeps.remove( root.attributeValue( "url" ) );
+ }
+ }
+
+ assertTrue( "All dependencies are present", expectedDeps.size() == 0 );
}
protected Document executeMojo( String pluginXml )
throws Exception
{
- return super.executeMojo( "module", pluginXml, "iml" );
+ Document imlDocument = super.executeMojo( "module", pluginXml, "iml" );
+
+ Element component = findComponent( imlDocument.getRootElement(),
"NewModuleRootManager" );
+
+ Element output = findElement( component, "output" );
+ assertEquals( "Module output url created.",
"file://$MODULE_DIR$/target/classes", output.attributeValue( "url" ) );
+
+ Element outputTest = findElement( component, "output-test" );
+ assertEquals( "Module test-output url created.",
"file://$MODULE_DIR$/target/test-classes", outputTest.attributeValue( "url" ) );
+
+ Element content = findElement( component, "content" );
+ List elementList = findElementsByName( content, "sourceFolder" );
+ for ( Iterator sourceFolders = elementList.iterator();
sourceFolders.hasNext(); )
+ {
+ Element sourceFolder = (Element) sourceFolders.next();
+
+ String isTestSource = sourceFolder.attributeValue( "isTestSource"
).toLowerCase();
+ if ( "false".equals( isTestSource ) )
+ {
+ assertTrue( "Main source url",
+ sourceFolder.attributeValue( "url" ).startsWith(
"file://$MODULE_DIR$/src/main" ) );
+ }
+ else if ( "true".equals( isTestSource ) )
+ {
+ assertTrue( "Test source url",
+ sourceFolder.attributeValue( "url" ).startsWith(
"file://$MODULE_DIR$/src/test" ) );
+ }
+ else
+ {
+ fail( "Unknown sourceFolder 'isTestSource' attribute value: "
+ isTestSource );
+ }
+ }
+
+ return imlDocument;
}
}
Modified:
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/IdeaArtifactStub.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/IdeaArtifactStub.java?rev=391243&r1=391242&r2=391243&view=diff
==============================================================================
---
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/IdeaArtifactStub.java
(original)
+++
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/IdeaArtifactStub.java
Tue Apr 4 01:12:25 2006
@@ -21,6 +21,8 @@
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.plugin.testing.stubs.ArtifactStub;
+import java.io.File;
+
/**
* @author Edwin Punzalan
*/
@@ -33,6 +35,8 @@
private String version;
+ private File file;
+
public void setGroupId( String groupId )
{
@@ -64,9 +68,24 @@
return version;
}
+ public File getFile()
+ {
+ return file;
+ }
+
+ public void setFile( File file )
+ {
+ this.file = file;
+ }
+
public ArtifactVersion getSelectedVersion()
throws OverConstrainedVersionException
{
return new DefaultArtifactVersion( getVersion() );
+ }
+
+ public String getId()
+ {
+ return getGroupId() + ":" + getArtifactId() + ":" + getVersion();
}
}
Modified:
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/SimpleMavenProjectStub.java
URL:
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/SimpleMavenProjectStub.java?rev=391243&r1=391242&r2=391243&view=diff
==============================================================================
---
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/SimpleMavenProjectStub.java
(original)
+++
maven/plugins/trunk/maven-idea-plugin/src/test/java/org/apache/maven/plugin/idea/stubs/SimpleMavenProjectStub.java
Tue Apr 4 01:12:25 2006
@@ -19,6 +19,7 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Build;
+import org.apache.maven.model.Resource;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import java.io.File;
@@ -43,9 +44,19 @@
TestCounter.nextCount();
build = new Build();
- build.setDirectory( getBasedir().getAbsolutePath() + "/target" );
- build.setOutputDirectory( getBasedir().getAbsolutePath() +
"/target/classes" );
- build.setTestOutputDirectory( getBasedir().getAbsolutePath() +
"/target/test-classes" );
+ build.setDirectory( "target" );
+ build.setOutputDirectory( "target/classes" );
+ build.setTestOutputDirectory( "target/test-classes" );
+
+ Resource resource = new Resource();
+ resource.setDirectory( "src/main/resources" );
+ resource.setFiltering( false );
+ build.setResources( Collections.singletonList( resource ) );
+
+ resource = new Resource();
+ resource.setFiltering( false );
+ resource.setDirectory( "src/test/resources" );
+ build.setTestResources( Collections.singletonList( resource ) );
}
public String getGroupId()
@@ -100,6 +111,13 @@
dep.setScope( Artifact.SCOPE_COMPILE );
dependencies.add( dep );
+ dep = new Dependency();
+ dep.setGroupId( "junit" );
+ dep.setArtifactId( "junit" );
+ dep.setVersion( "3.8.1" );
+ dep.setScope( Artifact.SCOPE_TEST );
+ dependencies.add( dep );
+
return dependencies;
}
@@ -128,7 +146,11 @@
public List getCompileSourceRoots()
{
- return Collections.singletonList( getBasedir().getAbsolutePath() +
"/src/main/java" );
+ File src = new File( getBasedir().getAbsolutePath() + "/src/main/java"
);
+
+ src.mkdirs();
+
+ return Collections.singletonList( src.getAbsolutePath() );
}
public List getTestArtifacts()
@@ -137,7 +159,9 @@
{
testArtifacts = new ArrayList();
- testArtifacts.add( createArtifact( "junit", "junit", "1.0.4" ) );
+ testArtifacts.add( createArtifact( "org.apache.maven",
"maven-model", "2.0.1" ) );
+
+ testArtifacts.add( createArtifact( "junit", "junit", "3.8.1" ) );
}
return testArtifacts;
@@ -150,7 +174,11 @@
public List getTestCompileSourceRoots()
{
- return Collections.singletonList( getBasedir().getAbsolutePath() +
"/src/test/java" );
+ File src = new File( getBasedir().getAbsolutePath() + "/src/test/java"
);
+
+ src.mkdirs();
+
+ return Collections.singletonList( src.getAbsolutePath() );
}
private Artifact createArtifact( String groupId, String artifactId, String
version )
@@ -160,6 +188,8 @@
artifact.setGroupId( groupId );
artifact.setArtifactId( artifactId );
artifact.setVersion( version );
+ artifact.setFile( new File( "/localRepository/" +
artifact.getId().replace( ':', '/' ) +
+ "/" + artifact.getArtifactId() + "-" +
artifact.getVersion() + ".jar" ) );
return artifact;
}