Author: brett Date: Sat Sep 3 18:13:15 2005 New Revision: 267532 URL: http://svn.apache.org/viewcvs?rev=267532&view=rev Log: PR: MNG-833 Submitted by: Christoph Sturm Reviewed by: Brett Porter o fix NPE o allow linking of projects in the reactor as modules
Modified: maven/components/trunk/maven-plugins/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java Modified: maven/components/trunk/maven-plugins/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java?rev=267532&r1=267531&r2=267532&view=diff ============================================================================== --- maven/components/trunk/maven-plugins/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java (original) +++ maven/components/trunk/maven-plugins/maven-idea-plugin/src/main/java/org/apache/maven/plugin/idea/IdeaMojo.java Sat Sep 3 18:13:15 2005 @@ -110,9 +110,9 @@ private void rewriteProject() throws MojoExecutionException { + File projectFile = new File( project.getBasedir(), project.getArtifactId() + ".ipr" ); try { - File projectFile = new File( project.getBasedir(), project.getArtifactId() + ".ipr" ); Reader reader; if ( projectFile.exists() ) { @@ -162,7 +162,8 @@ else { Xpp3Dom m = createElement( modules, "module" ); - String modulePath = new File( project.getBasedir(), project.getArtifactId() + ".iml" ).getAbsolutePath(); + String modulePath = new File( project.getBasedir(), + project.getArtifactId() + ".iml" ).getAbsolutePath(); m.setAttribute( "filepath", "$PROJECT_DIR$/" + toRelative( project.getBasedir(), modulePath ) ); } @@ -178,20 +179,20 @@ } catch ( XmlPullParserException e ) { - throw new MojoExecutionException( "Error parsing existing IML file", e ); + throw new MojoExecutionException( "Error parsing existing IPR file: " + projectFile.getAbsolutePath(), e ); } catch ( IOException e ) { - throw new MojoExecutionException( "Error parsing existing IML file", e ); + throw new MojoExecutionException( "Error parsing existing IPR file: " + projectFile.getAbsolutePath(), e ); } } private void rewriteModule() throws MojoExecutionException { + File moduleFile = new File( project.getBasedir(), project.getArtifactId() + ".iml" ); try { - File moduleFile = new File( project.getBasedir(), project.getArtifactId() + ".iml" ); Reader reader; if ( moduleFile.exists() ) { @@ -214,11 +215,11 @@ // TODO: how can we let the WAR/EJBs plugin hook in and provide this? // TODO: merge in ejb-module, etc. - if ( project.getPackaging().equals( "war" ) ) + if ( "war".equals( project.getPackaging() ) ) { addWebModule( module ); } - else if ( project.getPackaging().equals( "ejb" ) ) + else if ( "ejb".equals( project.getPackaging() ) ) { module.setAttribute( "type", "J2EE_EJB_MODULE" ); } @@ -264,20 +265,27 @@ for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); ) { Artifact a = (Artifact) i.next(); - // TODO: resolve projects in reactor as references - Xpp3Dom dep = createElement( component, "orderEntry" ); - dep.setAttribute( "type", "module-library" ); - - dep = createElement( dep, "library" ); - dep.setAttribute( "name", a.getArtifactId() ); - Xpp3Dom el = createElement( dep, "CLASSES" ); - el = createElement( el, "root" ); - el.setAttribute( "url", "jar://" + a.getFile().getAbsolutePath().replace( '\\', '/' ) + "!/" ); + if ( a.getFile() != null ) + { + dep.setAttribute( "type", "module-library" ); + dep = createElement( dep, "library" ); + dep.setAttribute( "name", a.getArtifactId() ); + + Xpp3Dom el = createElement( dep, "CLASSES" ); + el = createElement( el, "root" ); + File file = a.getFile(); + el.setAttribute( "url", "jar://" + file.getAbsolutePath().replace( '\\', '/' ) + "!/" ); - createElement( dep, "JAVADOC" ); - createElement( dep, "SOURCES" ); + createElement( dep, "JAVADOC" ); + createElement( dep, "SOURCES" ); + } + else + { + dep.setAttribute( "type", "module" ); + dep.setAttribute( "module-name", a.getArtifactId() ); + } } FileWriter writer = new FileWriter( moduleFile ); @@ -292,11 +300,11 @@ } catch ( XmlPullParserException e ) { - throw new MojoExecutionException( "Error parsing existing IML file", e ); + throw new MojoExecutionException( "Error parsing existing IML file " + moduleFile.getAbsolutePath(), e ); } catch ( IOException e ) { - throw new MojoExecutionException( "Error parsing existing IML file", e ); + throw new MojoExecutionException( "Error parsing existing IML file " + moduleFile.getAbsolutePath(), e ); } } @@ -419,7 +427,7 @@ for ( int i = children.length - 1; i >= 0; i-- ) { Xpp3Dom child = children[i]; - if ( child.getName().equals( "orderEntry" ) && child.getAttribute( "type" ).equals( "module-library" ) ) + if ( "orderEntry".equals( child.getName() ) && "module-library".equals( child.getAttribute( "type" ) ) ) { component.removeChild( i ); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]