Issue Details (XML | Word | Printable)

Key: MIDEA-102
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Dennis Lundberg
Reporter: Joern Huxhorn
Votes: 12
Watchers: 11
Operations

If you were logged in you would be able to see more operations.
Maven 2.x IDEA Plugin

Module filepath is generated incorrectly for sibling parent

Created: 26/Jul/07 05:14 PM   Updated: 31/Jul/08 04:54 PM   Resolved: 31/Jul/08 04:54 PM
Component/s: None
Affects Version/s: 2.1
Fix Version/s: 2.2

Time Tracking:
Not Specified

File Attachments: 1. Text File maven-idea-plugin-MIDEA-102-2.patch (4 kB)
2. Text File maven-idea-plugin-MIDEA-102.patch (5 kB)

Environment:
$ mvn -v
Maven version: 2.0.7
Java version: 1.5.0_11
OS name: "windows xp" version: "5.1" arch: "x86"
cygwin
Issue Links:
Duplicate


 Description  « Hide

I have a multi-module mvn project.

When I do an mvn idea:clean idea:idea, the following ProjectModuleManager snippet in the top level .ipr is generated:

<component name="ProjectModuleManager">
<modules>
<!-- module filepath="$$PROJECT_DIR$$/${pom.artifactId}.iml"/ -->
<module filepath="$PROJECT_DIR$/gateway.iml"/>
<module filepath="$PROJECT_DIR$/C:/dev/voca/gateway/domain/gateway-domain.iml"/>
<module filepath="$PROJECT_DIR$/C:/dev/voca/gateway/instruction-store/gateway-instruction-store.iml"/>
<module filepath="$PROJECT_DIR$/C:/dev/voca/gateway/parser/gateway-parser.iml"/>
<module filepath="$PROJECT_DIR$/C:/dev/voca/gateway/psrgeneration/gateway-psr-generation.iml"/>
<module filepath="$PROJECT_DIR$/C:/dev/voca/gateway/output/gateway-output.iml"/>
<module filepath="$PROJECT_DIR$/C:/dev/voca/gateway/destination-resolver/gateway-destination-resolver.iml"/>
<module filepath="$PROJECT_DIR$/C:/dev/voca/gateway/choreography/gateway-choreography.iml"/>
<module filepath="$PROJECT_DIR$/C:/dev/voca/gateway/presentation/gateway-presentation.iml"/>
<module filepath="$PROJECT_DIR$/C:/dev/voca/gateway/assembly/gateway-assembly.iml"/>
</modules>
</component>

The $PROJECT_DIR in this case is C:/dev/voca/gateway/.

But this path is being appended in a hard-coded fashion after the $PROJECT_DIR entry.

The symptom in Intellij is the following error message:

Cannot load module: File C:\dev\voca\gateway\C:\dev\voca\gateway\domain\gateway-domain.iml does not exist
Would you like to remove the module from the project?

The workaround is to delete the extra appended file path from each module entry in the above mentioned snippet.



Joern Huxhorn added a comment - 26/Jul/07 05:27 PM

the problem still exists if the master-module is at the same level as the child module, e.g. C:\foo\master and C:\foo\child.

The attached patch fixes this problem.


Joern Huxhorn added a comment - 26/Jul/07 05:31 PM

I'd also suggest to change
protected String toRelative( File basedir, String absolutePath )
to
static String toRelative( File basedir, String absolutePath )

and write some tests. I didn't want to change too much, though.


Dennis Lundberg added a comment - 26/Jul/07 05:44 PM

Which issue was this cloned from? Please create a link to it.


Dennis Lundberg added a comment - 26/Jul/07 06:26 PM

Found it.


Dennis Lundberg added a comment - 26/Jul/07 06:28 PM

The issue MIDEA-98 has been fixed and verified. It is only available in the the 2.2-SNAPSHOT version. It is not fixed in version 2.1 of this plugin.


Joern Huxhorn added a comment - 27/Jul/07 04:05 AM

My patch is against r559855 of 2.2-SNAPSHOT (trunk).

I tried the 2.2-SNAPSHOT and the same problem still exists if the master-pom is at the same level as the child-poms.

C:\Foo\parent\pom.xml
The master-pom containing a <modules> section
<modules>
<module>../child</module>
</modules>

C:\Foo\child\pom.xml
The sub-module referenced from the master-module

In cases like that, i.e. if the path of the submodule must contain ".." the behavior is still like in the original bug-report. That's why I cloned it instead of creating a new one which was probably wrong on my side. I thought this would be wise since the previous fix only fixed a special-case of the problem.


Joern Huxhorn added a comment - 27/Jul/07 04:10 AM

To clarify my point a little more: calling toRelative("C:\Foo\bar1", "C:\Foo\bar2") must return "../bar2" but currently returns "C:/Foo/bar2".


Lars Duvaas added a comment - 31/Jul/07 04:58 AM

It appears that the bug only occurs in maven 2.0.7.. When I run the goal in maven 2.0.6 it works fine.


Kristian Nordal added a comment - 07/Aug/07 05:01 AM

I'm experiencing the same. It works with 2.0.6, not with 2.0.7. It does works in os x though (with 2.0.7), but not in Windows (cmd and cygwin).


Geoffrey De Smet added a comment - 25/Aug/07 12:47 PM

same here: win xp + idea 6 + maven 2.0.7 + maven-idea-plugin 2.1 (and 2.0 too I believe) = wrong iml paths in the ipr of a multimodule project.


Geoffrey De Smet added a comment - 24/Sep/07 04:47 AM

Confirming it doesn't work for idea 2.0 or 2.1. It's maven 2.0.7 and win xp combination that is breaking.

Workaround
==========

Make sure you still have maven 2.0.6 still installed.
Do this in your cygwin shell:

export M2_HOME=/cygdrive/c/develop/build/maven-2.0.6
mvn idea:idea

or if you're using cmd:
set M2_HOME=C:\develop\build\maven-2.0.6
mvn idea:idea

Afterwards throw away that shell instance, as it won't be using maven 2.0.7.


Roman Platonov added a comment - 01/Dec/07 07:10 PM

Hello!
My fix is more simple, but it's works...

class AbstractIdeaMojo:

protected String toRelative( File basedir, String absolutePath )
{
String relative = null;
String convertedBasedirAbsolutePath = convertDriveLetter( basedir.getAbsolutePath() );
String convertedAbsolutePath = convertDriveLetter( absolutePath );

String fileSeparator = System.getProperty("file.separator");
String upPrefix = "";
while (convertedBasedirAbsolutePath.indexOf(fileSeparator) > 0) {
if (convertedAbsolutePath.startsWith(convertedBasedirAbsolutePath)
&& convertedAbsolutePath.length() > convertedBasedirAbsolutePath.length()) { relative = upPrefix + convertedAbsolutePath.substring(convertedBasedirAbsolutePath.length() + 1); break; } else { convertedBasedirAbsolutePath = convertedBasedirAbsolutePath.substring(0, convertedBasedirAbsolutePath.lastIndexOf(fileSeparator)); upPrefix += "../"; }
}
if (relative == null) { relative = convertedAbsolutePath; }

relative = StringUtils.replace( relative, "
", "/" );

if ( getLog().isDebugEnabled() )

{ getLog().debug( "toRelative(" + basedir + ", " + absolutePath + ") => " + relative ); }

return relative;
}


Daniel Frey added a comment - 02/Feb/08 03:43 PM - edited

Hi there

I just tested it with the 2.2-SNAPSHOT and got a wrong result! My project structure is:

ch.ki.ras/
ch.ki.ras.monitor/
ch.ki.ras.om/

where the first directory contains the master POM. What I get in the project file ch.ki.ras/ch.ki.ras.ipr is

<module filepath="$PROJECT_DIR$/ch.ki.ras.iml"/>
<module filepath="$PROJECT_DIR$/monitor/ch.ki.ras.monitor.iml"/>
<module filepath="$PROJECT_DIR$/om/ch.ki.ras.om.iml"/>

So not only the path is not relative to the main POM, but also the path information is trucated. Instead it should be

<module filepath="$PROJECT_DIR$/../ch.ki.ras/ch.ki.ras.iml"/>
<!-- or <module filepath="$PROJECT_DIR$/ch.ki.ras.iml"/>-->
<module filepath="$PROJECT_DIR$/../ch.ki.ras.monitor/ch.ki.ras.monitor.iml"/>
<module filepath="$PROJECT_DIR$/../ch.ki.ras.om/ch.ki.ras.om.iml"/>

Would be wunderful to get a new SNAPSHOT soon!

Thanks
Daniel Frey


gotama added a comment - 06/Mar/08 01:12 AM

I am running XP, Maven 2.0.8, Maven IDEA plugin 2.1 and Cygwin. When I issue 'mvn idea:idea' on the XP command line my IDEA project file is fine. When I issue the same command in Cygwin, the paths are incorrect.

Using the 2.2-SNAPSHOT it works fine, except for the above noted conditions where the parent and module dirs are at the same level. This is a different bug.

This issue is working on over 8 months without a release, yet there is a fix for one of the show stopping bugs which prevents you from using the plugin. 2.2 should be released as is now and a new fresh jira issue should be created to address the bug about the paths being incorrect for when the parents and modules are at the same level. This plugin is broken without releasing 2.2.


gotama added a comment - 06/Mar/08 03:21 AM

Actually, I just tested Roman's code above - adding it to the latest 2.2-SNAPSHOT and the paths are correct for an idea project with the parent and modules at the same level. The modules paths are correctly relative using "../".

Someone should throw that code in there, close this out and release 2.2. WFM.


Geoffrey De Smet added a comment - 06/Mar/08 12:20 PM

Someone should throw that code in there, close this out and release 2.2.

I couldn't agree more


gotama added a comment - 06/Mar/08 01:41 PM

I would add it - but I'm new to this project so I don't know how to get permissions to check in code and what the official release process is. How do you become a committer?

Also, someone should check out the ClassWorlds dependency for the tests. The tests fail because they are missing the ClassWorlds dependency.

<dependency>
<groupId>classworlds</groupId>
<artifactId>classworlds</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>


Dennis Lundberg added a comment - 06/Mar/08 01:53 PM

Thanks for trying the patch. As I don't have a cygwin environment I have not been able to verify the patch. I'll have a look at the patch.


gotama added a comment - 07/Mar/08 03:33 PM

http://cygwin.com/setup.exe

... just click through 'next' on everything and get the basic install. quick easy setup... beats the windows prompt for those on the corporate XP system!


Dennis Lundberg added a comment - 08/Mar/08 02:35 PM

I have committed the patch, with modifications. I also added a small test case.

A new SNAPSHOT has been deployed, please verify that it solves this issue.


Joern Huxhorn added a comment - 10/Mar/08 04:44 AM

I had to build using

mvn clean install -Dmaven.test.skip=true

because otherwise the build would fail with the following messages:

Running org.apache.maven.plugin.idea.IdeaModuleTest
[WARNING] An error occurred during dependency resolution of the following artifact:

org.apache.maven.plugin.test:plugin-test-1919

Caused by: required artifacts missing:
javax.sql:jdbc-stdext:jar:2.0

for the artifact:
org.apache.maven.plugin.test:plugin-test-19:jar:19

from the specified remote repositories:
test-repo (file://P:\misc\maven-idea-plugin\src\test\remote-repo)

[WARNING] An error occurred during dependency resolution of the following artifact:

org.apache.maven.plugin.test:plugin-test-2222

Caused by: required artifacts missing:
javax.sql:jdbc-stdext:jar:2.0

for the artifact:
org.apache.maven.plugin.test:plugin-test-22:jar:22

from the specified remote repositories:
test-repo (file://P:\misc\maven-idea-plugin\src\test\remote-repo)

[WARNING] Unable to get resource from repository test-repo (file://P:\misc\maven-idea-plugin\src\test\remote-repo)
[INFO] artifact junit:junit: checking for updates from test-repo
Tests run: 15, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 4.484 sec <<< FAILURE!
Running org.apache.maven.plugin.idea.LibraryTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running org.apache.maven.plugin.idea.IdeaMojoTestCase
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec

Results :

Failed tests:
testEjbProjectWithModulesConfigurations(org.apache.maven.plugin.idea.IdeaModuleTest)

Tests run: 37, Failures: 1, Errors: 0, Skipped: 0

But beside that, the current version works as expected for me.


Daniel Frey added a comment - 14/Mar/08 05:39 PM

Just tested it with maven-idea-plugin-2.2-20080308.204124-6. For me, this issue (http://jira.codehaus.org/browse/MIDEA-102#action_122161) stays open. Nothing has changed. I get exactly the same result as with 2.1.


Dennis Lundberg added a comment - 14/Mar/08 06:11 PM

Daniel, please open another issue for that. It is a different issue than this one.

Also attach a small test project that can be used to reproduce the issue.


gotama added a comment - 20/Mar/08 04:11 PM

Dennis, the patch you applied is highly unnecessarily complex. Take a look at the patch that Roman lists above. This is the one that should be applied. Its 3 times smaller and easy to follow. If Roman's patch does not work, please explain why your patch works better.

However, Daniel, I have tested both Roman's patch and Dennis' patch, and they both work. I did not pull the snapshot though, I complied the patches myself. You may want to delete the .m2\repository\org\apache\maven\plugins\maven-idea-plugin directory to ensure you are in fact using the 2.2-SNAPSHOT. If it still does not work, please elaborate using the test pom's below.

Example:

<module filepath="$PROJECT_DIR$/parent.iml"/>
<module filepath="$PROJECT_DIR$/../child/child.iml"/>

Is the result of running mvn idea:idea on:

c:\foo\parent\pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>parent</artifactId>
<name>stubhub.com</name>
<packaging>pom</packaging>
<version>3.0.6</version>
<description>Parent POM</description>
<inceptionYear>2008</inceptionYear>
<modules>
<module>../child</module>
</modules>

</project>

c:\foo\child\pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.test</groupId>
<artifactId>parent</artifactId>
<version>3.0.6</version>
</parent>
<artifactId>child</artifactId>
<name>test</name>
<packaging>pom</packaging>
<version>3.0.6</version>
<description>child of test</description>
<inceptionYear>2008</inceptionYear>

</project>

So, again, lets throw Roman's patch in 2.2 and release this puppy. Nothing else is open for 2.2.

Thanks.


gotama added a comment - 20/Mar/08 04:13 PM

Also, this issue should not be closed until its agreed its fixed. Please reopen.


Dennis Lundberg added a comment - 21/Mar/08 05:37 AM

gotama,

There is no patch from Roman - it's just a piece of code embedded in a comment. That won't show up on my radar when I'm looking for patches to apply. Contributors should alway supply a patch-file and attach it to the issue.

The patch I applied wasn't mine , but came from Joern who was the person who filed this issue.

That being said, I'll probably throw the whole toRelative() method out and use a method from doxia tools instead. That code includes lots unit tests and has been extracted from already tried and tested components. We still need to get a release of it out the door. In the meantime I'll push out another SNAPSHOT using that code. Stay tuned.


gotama added a comment - 16/Apr/08 02:28 PM

What is the status of this issue?

I'm willing to forgo the whole implementation style argument for simply getting "A" fixed version of 2.2 out the door.

The current SNAPSHOT works, so I vote for releasing it, then later on revisiting the 3 different ways the paths can be corrected. The important thing is that it is fixed.

In the mean time, there are people out there trying to use Maven for the first time, and they will not be impressed when 'mvn idea:idea' does not work. This is one of the cool selling points of Maven to a team of developers and its been busted for a year.

Release 2.2...

Thanks.


Dennis Lundberg added a comment - 16/Apr/08 03:28 PM

The tests currently fail in Linux/Unix environments. I need to try and fix that before I can make the release.


gotama added a comment - 03/May/08 04:53 PM

Dennis,

Have you made any headway on this? I'm sure a lot of people would appreciate this fix and a working 2.2 IDEA Maven2 plugin.

How can we help?

When you say the tests fail, are those checked in 2.2 junit tests? We should be able to do something like create a test project and a junit test, check them in, and then test it in all environments (XP/Cygwin, XP, Linux, OSX) until it passes. Is this already checked in? If it is, then contributors could try to fix it and we'd all agree on exactly what has to pass. Can we try to outline this?

Thanks,
Blaine


Daniel Frey added a comment - 25/Jun/08 06:07 AM

For me this issue is open for the described file structure (see comments above). However, a slightly altered patch works fine. Please find it attached.


Dennis Lundberg added a comment - 19/Jul/08 11:53 AM

I've managed to make the test pass on both Windows and Ubuntu now.

It would be great if people could test the new maven-idea-plugin 2.2-20080719.165010-7 SNAPSHOT that I have deployed.

Also I would appreciate if someone with Cygwin installed could run 'mvn test' on the SVN trunk, to make sure the tests pass there as well.


Dennis Lundberg added a comment - 31/Jul/08 04:54 PM

OK, I'm closing this as fixed now. I got one response in private that it works.