Return-Path: Delivered-To: apmail-maven-dev-archive@www.apache.org Received: (qmail 68452 invoked from network); 3 Mar 2008 11:51:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Mar 2008 11:51:26 -0000 Received: (qmail 70805 invoked by uid 500); 3 Mar 2008 11:51:16 -0000 Delivered-To: apmail-maven-dev-archive@maven.apache.org Received: (qmail 70722 invoked by uid 500); 3 Mar 2008 11:51:15 -0000 Mailing-List: contact dev-help@maven.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Maven Developers List" Reply-To: "Maven Developers List" Delivered-To: mailing list dev@maven.apache.org Received: (qmail 70702 invoked by uid 99); 3 Mar 2008 11:51:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Mar 2008 03:51:15 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=SPF_PASS,UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of incomingpost@yandex.ru designates 213.180.200.49 as permitted sender) Received: from [213.180.200.49] (HELO webmail10.yandex.ru) (213.180.200.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Mar 2008 11:50:28 +0000 Received: from YAMAIL (webmail10) by mail.yandex.ru id S1017054AbYCCLui for ; Mon, 3 Mar 2008 14:50:38 +0300 X-Yandex-Spam: 0 Received: from [193.93.101.253] ([193.93.101.253]) by mail.yandex.ru with HTTP; Mon, 03 Mar 2008 14:50:38 +0300 From: MadVet To: dev@maven.apache.org Subject: Maven Ant plugin: fixed absolute links on related projects MIME-Version: 1.0 Message-Id: <472061204545038@webmail10.yandex.ru> Date: Mon, 03 Mar 2008 14:50:38 +0300 X-Mailer: Yamail [ http://yandex.ru ] 5.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Virus-Checked: Checked by ClamAV on apache.org Hi I have found and fix one problem with Maven Ant plugin. I had worked with multi-module maven projects and found that Maven Ant plugin generate absolute path for referenced projects (another modules). Ant doesn't find them during compilation. So I have fix plugin - it calculates relative path to referenced projects. Patch tested on Windows XP, Java 1.5.0_11. maven-build.xml before fix: maven-build.xml after fix: Svn diff: Index: main/java/org/apache/maven/plugin/ant/AntBuildWriter.java =================================================================== --- main/java/org/apache/maven/plugin/ant/AntBuildWriter.java (revision 628820) +++ main/java/org/apache/maven/plugin/ant/AntBuildWriter.java (working copy) @@ -23,6 +23,7 @@ import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; +import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -535,7 +536,44 @@ return localRepository.getAbsolutePath(); } } + + + private String buildRelativePath(File folder, File file) + { + File parent = folder; + String path = ""; + while ( parent != null && !isContainedIn( file, parent ) ) + { + parent = parent.getParentFile(); + path += "../"; + } + if (parent == null) + return file.getAbsolutePath(); + + return path + cutPathToFolder( file, parent ); + } + + private boolean isContainedIn( File file, File folder ) + { + File parent = file.getParentFile(); + while ( parent != null && !parent.equals( folder ) ) + parent = parent.getParentFile(); + return parent != null; + } + + private String cutPathToFolder( File file, File folder ) + { + File parent = file.getParentFile(); + String path = file.getName(); + while ( parent != null && !parent.equals( folder ) ) + { + path = parent.getName() + "/" + path; + parent = parent.getParentFile(); + } + return path; + } + /** * Write path definition in the writer only for a non-POM project. * @@ -550,18 +588,26 @@ AntBuildWriterUtil.writeCommentText( writer, "Defining classpaths", 1 ); + List notRepositoryArtifacts = new ArrayList(); + writer.startElement( "path" ); writer.addAttribute( "id", "build.classpath" ); writer.startElement( "fileset" ); writer.addAttribute( "dir", "${maven.repo.local}" ); + if ( !project.getCompileArtifacts().isEmpty() ) { for ( Iterator i = project.getCompileArtifacts().iterator(); i.hasNext(); ) { Artifact artifact = (Artifact) i.next(); - writer.startElement( "include" ); - writer.addAttribute( "name", PathUtils.toRelative( localRepository, artifact.getFile().getPath() ) ); - writer.endElement(); // include + if (isContainedIn(artifact.getFile(), localRepository)) + { + writer.startElement( "include" ); + writer.addAttribute( "name", PathUtils.toRelative( localRepository, artifact.getFile().getPath() ) ); + writer.endElement(); // include + } + else + notRepositoryArtifacts.add(artifact); } } else @@ -571,8 +617,20 @@ writer.endElement(); // include } writer.endElement(); // fileset + + for ( Iterator i = notRepositoryArtifacts.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + writer.startElement( "pathelement" ); + writer.addAttribute( "location", + buildRelativePath(project.getBasedir(), artifact.getFile()) );//artifact.getFile().getAbsolutePath() ); + writer.endElement(); + } + writer.endElement(); // path + List notRepositoryTestArtifacts = new ArrayList(); + writer.startElement( "path" ); writer.addAttribute( "id", "build.test.classpath" ); writer.startElement( "fileset" ); @@ -582,9 +640,14 @@ for ( Iterator i = project.getTestArtifacts().iterator(); i.hasNext(); ) { Artifact artifact = (Artifact) i.next(); - writer.startElement( "include" ); - writer.addAttribute( "name", PathUtils.toRelative( localRepository, artifact.getFile().getPath() ) ); - writer.endElement(); // include + if (isContainedIn(artifact.getFile(), localRepository)) + { + writer.startElement( "include" ); + writer.addAttribute( "name", PathUtils.toRelative( localRepository, artifact.getFile().getPath() ) ); + writer.endElement(); // include + } + else + notRepositoryTestArtifacts.add(artifact); } } else @@ -594,6 +657,15 @@ writer.endElement(); // include } writer.endElement(); // fileset + + for ( Iterator i = notRepositoryTestArtifacts.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + writer.startElement( "pathelement" ); + writer.addAttribute( "location", buildRelativePath(project.getBasedir(), artifact.getFile()) ); + writer.endElement(); + } + writer.endElement(); // path AntBuildWriterUtil.writeLineBreak( writer ); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org For additional commands, e-mail: dev-help@maven.apache.org