Author: epunzalan
Date: Thu Mar  2 00:52:37 2006
New Revision: 382321

URL: http://svn.apache.org/viewcvs?rev=382321&view=rev
Log:
Fixed a bug on web projects not being processed properly and applied an 
enhancement as presented by a portion of a duplicated patch on MIDEA-25

Modified:
    
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java

Modified: 
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java?rev=382321&r1=382320&r2=382321&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java
 Thu Mar  2 00:52:37 2006
@@ -238,65 +238,27 @@
     }
 
     private void doDependencyResolution()
-        throws InvalidDependencyVersionException, ProjectBuildingException, 
ArtifactNotFoundException,
-        ArtifactResolutionException
+        throws InvalidDependencyVersionException, ProjectBuildingException
     {
         if ( project.getDependencies() != null )
         {
-            List missingArtifacts = new ArrayList();
-
             Map managedVersions = createManagedVersionMap( project.getId(), 
project.getDependencyManagement() );
 
-            ArtifactResolutionResult result = 
artifactResolver.resolveTransitively( project.createArtifacts( artifactFactory, 
Artifact.SCOPE_TEST, null ), project.getArtifact(), managedVersions,
-                                                  localRepo, 
project.getRemoteArtifactRepositories(),
-                                                  artifactMetadataSource );
-
-            //project.setArtifacts( project.createArtifacts( artifactFactory, 
Artifact.SCOPE_TEST, null ) );
-            project.setArtifacts( result.getArtifacts() );
-
-            for ( Iterator artifacts = project.getTestArtifacts().iterator(); 
artifacts.hasNext(); )
+            try
             {
-                Artifact artifact = (Artifact) artifacts.next();
-
-                artifact.setFile( new File( localRepo.getBasedir(), 
localRepo.pathOf( artifact ) ) );
-
-                if ( !artifact.getFile().exists() )
-                {
-                    try
-                    {
-                        wagonManager.getArtifact( artifact, 
project.getRemoteArtifactRepositories() );
-                    }
-                    catch ( ResourceDoesNotExistException e )
-                    {
-                        getLog().debug( "Unable to resolve a project 
dependency: " + artifact.getId(), e  );
-
-                        missingArtifacts.add( artifact );
-                    }
-                    catch ( TransferFailedException e )
-                    {
-                        getLog().debug( "Unable to resolve a project 
dependency: " + artifact.getId(), e );
+                ArtifactResolutionResult result = 
artifactResolver.resolveTransitively(
+                    project.createArtifacts( artifactFactory, 
Artifact.SCOPE_TEST, null ), project.getArtifact(), managedVersions,
+                    localRepo, project.getRemoteArtifactRepositories(), 
artifactMetadataSource );
 
-                        missingArtifacts.add( artifact );
-                    }
-                }
+                project.setArtifacts( result.getArtifacts() );
             }
-
-            if ( missingArtifacts.size() > 0 )
+            catch ( ArtifactNotFoundException e )
             {
-                StringBuffer warnMsg = new StringBuffer();
-
-                warnMsg.append( "The following artifacts failed to 
resolve\n\n" );
-
-                for( Iterator artifacts = missingArtifacts.iterator(); 
artifacts.hasNext(); )
-                {
-                    Artifact artifact = (Artifact) artifacts.next();
-
-                    warnMsg.append( "    " + artifact.getId() + "\n" );
-                }
-
-                warnMsg.append( "\nfor the project " + project.getId() + "\n" 
);
-
-                getLog().warn( warnMsg );
+                e.printStackTrace();
+            }
+            catch ( ArtifactResolutionException e )
+            {
+                e.printStackTrace();
             }
         }
     }
@@ -577,22 +539,19 @@
                 Artifact a = (Artifact) i.next();
                 Xpp3Dom dep = createElement( component, "orderEntry" );
 
-                boolean found = false;
-                if ( reactorProjects != null && linkModules )
+                boolean isIdeaModule = false;
+                if ( linkModules )
                 {
-                    for ( Iterator j = reactorProjects.iterator(); j.hasNext() 
&& !found; )
+                    isIdeaModule = isReactorProject( a.getGroupId(), 
a.getArtifactId() );
+
+                    if ( isIdeaModule )
                     {
-                        MavenProject p = (MavenProject) j.next();
-                        if ( p.getGroupId().equals( a.getGroupId() ) && 
p.getArtifactId().equals( a.getArtifactId() ) )
-                        {
-                            dep.setAttribute( "type", "module" );
-                            dep.setAttribute( "module-name", a.getArtifactId() 
);
-                            found = true;
-                        }
+                        dep.setAttribute( "type", "module" );
+                        dep.setAttribute( "module-name", a.getArtifactId() );
                     }
                 }
 
-                if ( a.getFile() != null && !found )
+                if ( a.getFile() != null && !isIdeaModule )
                 {
                     dep.setAttribute( "type", "module-library" );
                     dep = createElement( dep, "library" );
@@ -650,6 +609,22 @@
         }
     }
 
+    private boolean isReactorProject( String groupId, String artifactId )
+    {
+        if ( reactorProjects != null )
+        {
+            for ( Iterator j = reactorProjects.iterator(); j.hasNext(); )
+            {
+                MavenProject p = (MavenProject) j.next();
+                if ( p.getGroupId().equals( groupId ) && 
p.getArtifactId().equals( artifactId ) )
+                {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
     private void addResources( Xpp3Dom component, String directory )
     {
         Xpp3Dom dep = createElement( component, "orderEntry" );
@@ -777,47 +752,37 @@
         for ( Iterator i = artifacts.iterator(); i.hasNext(); )
         {
             Artifact artifact = (Artifact) i.next();
-            if ( artifact.getScope().equals( "compile" ) || 
artifact.getScope().equals( "runtime" ) )
-            {
-                Xpp3Dom containerElement = createElement( component, 
"containerElement" );
 
-                boolean linkAsModule = false;
-                if ( reactorProjects != null && linkModules )
-                {
-                    for ( Iterator j = reactorProjects.iterator(); j.hasNext() 
&& !linkAsModule; )
-                    {
-                        MavenProject p = (MavenProject) j.next();
-                        if ( p.getGroupId().equals( artifact.getGroupId() ) &&
-                            p.getArtifactId().equals( artifact.getArtifactId() 
) )
-                        {
-                            linkAsModule = true;
-                        }
-                    }
-                }
+            Xpp3Dom containerElement = createElement( component, 
"containerElement" );
 
-                if ( linkAsModule )
-                {
-                    containerElement.setAttribute( "type", "module" );
-                    containerElement.setAttribute( "name", 
artifact.getArtifactId() );
-                    Xpp3Dom methodAttribute = createElement( containerElement, 
"attribute" );
-                    methodAttribute.setAttribute( "name", "method" );
-                    methodAttribute.setAttribute( "value", "1" );
-                    Xpp3Dom uriAttribute = createElement( containerElement, 
"attribute" );
-                    uriAttribute.setAttribute( "name", "URI" );
-                    uriAttribute.setAttribute( "value", "/WEB-INF/classes" );
-                }
-                else if ( artifact.getFile() != null )
-                {
-                    containerElement.setAttribute( "type", "library" );
-                    containerElement.setAttribute( "level", "module" );
-                    containerElement.setAttribute( "name", 
artifact.getArtifactId() );
-                    Xpp3Dom methodAttribute = createElement( containerElement, 
"attribute" );
-                    methodAttribute.setAttribute( "name", "method" );
-                    methodAttribute.setAttribute( "value", "1" ); // IntelliJ 
5.0.2 is bugged and doesn't read it
-                    Xpp3Dom uriAttribute = createElement( containerElement, 
"attribute" );
-                    uriAttribute.setAttribute( "name", "URI" );
-                    uriAttribute.setAttribute( "value", "/WEB-INF/lib/" + 
artifact.getFile().getName() );
-                }
+            boolean linkAsModule = false;
+            if ( linkModules )
+            {
+                linkAsModule = isReactorProject( artifact.getGroupId(), 
artifact.getArtifactId() );
+            }
+
+            if ( linkAsModule )
+            {
+                containerElement.setAttribute( "type", "module" );
+                containerElement.setAttribute( "name", 
artifact.getArtifactId() );
+                Xpp3Dom methodAttribute = createElement( containerElement, 
"attribute" );
+                methodAttribute.setAttribute( "name", "method" );
+                methodAttribute.setAttribute( "value", "5" );
+                Xpp3Dom uriAttribute = createElement( containerElement, 
"attribute" );
+                uriAttribute.setAttribute( "name", "URI" );
+                uriAttribute.setAttribute( "value", "/WEB-INF/classes" );
+            }
+            else if ( artifact.getFile() != null )
+            {
+                containerElement.setAttribute( "type", "library" );
+                containerElement.setAttribute( "level", "module" );
+                containerElement.setAttribute( "name", 
artifact.getArtifactId() );
+                Xpp3Dom methodAttribute = createElement( containerElement, 
"attribute" );
+                methodAttribute.setAttribute( "name", "method" );
+                methodAttribute.setAttribute( "value", "1" ); // IntelliJ 
5.0.2 is bugged and doesn't read it
+                Xpp3Dom uriAttribute = createElement( containerElement, 
"attribute" );
+                uriAttribute.setAttribute( "name", "URI" );
+                uriAttribute.setAttribute( "value", "/WEB-INF/lib/" + 
artifact.getFile().getName() );
             }
         }
 


Reply via email to