Issue Details (XML | Word | Printable)

Key: MPECLIPSE-60
Type: New Feature New Feature
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Stephane Nicoll
Reporter: Krystian Nowak
Votes: 8
Watchers: 6
Operations

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

Downloading source zips

Created: 06/Dec/04 03:18 AM   Updated: 13/Jan/06 04:42 PM
Component/s: None
Affects Version/s: 1.9
Fix Version/s: 1.11

Time Tracking:
Original Estimate: 30 minutes
Original Estimate - 30 minutes
Remaining Estimate: 30 minutes
Remaining Estimate - 30 minutes
Time Spent: Not Specified
Remaining Estimate - 30 minutes

File Attachments: 1. Text File MPECLIPSE-60.patch (14 kB)
2. Text File plugin.jelly.patch (4 kB)



 Description  « Hide
I've attached plugin.jelly for maven-eclipse-plugin downloading sources from ${repo}/${groupId}/src/${artifactId}-${version}.zip and installing it as ${maven.repo.local}/${groupId}/src/${artifactId}-${version}.zip.

It does it for all jar dependencies having eclipse.source property set to true. Example project.xml:

(...)
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<url>http://www.junit.org/</url>
<properties>
<eclipse.source>true</eclipse.source>
</properties>
</dependency>
</dependencies>
(...)

What you have to do now is to call "maven eclipse" and refresh your project in Eclipse.


And here is the code of plugin.jelly - a patch made in Eclipse:

Index: plugin.jelly
===================================================================
RCS file: /home/cvspublic/maven-plugins/eclipse/plugin.jelly,v
retrieving revision 1.31
diff -u -r1.31 plugin.jelly
— plugin.jelly 16 Nov 2004 10:48:15 -0000 1.31
+++ plugin.jelly 6 Dec 2004 08:10:33 -0000
@@ -78,7 +78,8 @@
<!-- Generate Eclipse .classpath file -->
<!-==================================================================->
<goal name="eclipse:generate-classpath"
- description="Generate Eclipse .classpath file">
+ description="Generate Eclipse .classpath file"
+ prereqs="eclipse:sources:download">

<ant:echo>Creating ${basedir}/.classpath ...</ant:echo>
<j:file name="${basedir}/.classpath" prettyPrint="true" outputMode="xml" xmlns="dummy">
@@ -263,5 +264,73 @@

<ant:echo>Cleaned up eclipse generated files</ant:echo>
</goal>
+
+
+
+ <!-==================================================================->
+ <!-- Download project dependency sources -->
+ <!-==================================================================->
+
+ <goal name="eclipse:sources:download">
+ <j:forEach var="depItem" items="${pom.getDependencies()}">
+ <j:if test="${depItem.getType().equalsIgnoreCase('jar')}">
+ <j:if test="${depItem.getProperty('eclipse.source') == 'true'}">
+ <j:set var="groupId" value="${depItem.getGroupId()}"/>
+ <j:set var="artifactId" value="${depItem.getArtifactId()}"/>
+ <j:set var="version" value="${depItem.getVersion()}"/>
+ <attainGoal name="eclipse:source:download"/>
+ <j:remove var="groupId"/>
+ <j:remove var="artifactId"/>
+ <j:remove var="version"/>
+ </j:if>
+ </j:if>
+ </j:forEach>
+ </goal>
+
+
+ <!-==================================================================->
+ <!-- Download single source -->
+ <!-==================================================================->
+
+ <goal name="eclipse:source:download">
+ <!--
+ param: groupId
+ param: artifactId
+ param: version
+ -->
+ <echo>Checking sources for ${groupId}:${artifactId} ver.${version}</echo>
+ <util:file var="localSrcFile" name="${maven.repo.local}/${groupId}/src/${artifactId}-${version}.zip" />
+ <j:if test="${!localSrcFile.exists()}">
+ <mkdir dir="${maven.repo.local}/${groupId}/src" />
+ <j:set var="repoList">${maven.repo.remote}</j:set>
+ <util:tokenize var="repos" delim=",">${repoList.trim()}</util:tokenize>
+ <j:forEach var="repo" items="${repos}">
+ <echo>repo is '${repo}'</echo>
+ <j:set var="remoteFile" value="${repo}/${groupId}/src/${artifactId}-${version}.zip" />
+ <echo>trying to download ${remoteFile}</echo>
+ <j:catch var="ex">
+ <j:invokeStatic var="dummy" method="getFile" className="org.apache.maven.util.HttpUtils">
+ <j:arg type="java.lang.String" value="${remoteFile}" />
+ <j:arg type="java.io.File" value="${localSrcFile}"/>
+ <j:arg type="boolean" value="false"/>
+ <j:arg type="boolean" value="true"/>
+ <j:arg type="java.lang.String" value="${maven.proxy.host}" />
+ <j:arg type="java.lang.String" value="${maven.proxy.port}" />
+ <j:arg type="java.lang.String" value="${maven.proxy.username}" />
+ <j:arg type="java.lang.String" value="${maven.proxy.password}" />
+ <j:arg type="boolean" value="false"/>
+ </j:invokeStatic>
+ </j:catch>
+ <j:remove var="remoteFile"/>
+ <j:break test="${localSrcFile.exists()}"/>
+ </j:forEach>
+ <j:if test="${!localSrcFile.exists()}">
+ <echo>WARN: Could not download sources for ${groupId}:${artifactId} ver.${version}</echo>
+ </j:if>
+ <j:remove var="repoList"/>
+ </j:if>
+ <j:remove var="localSrcFile"/>
+ </goal>
+

</project>



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Krystian Nowak added a comment - 06/Dec/04 03:19 AM
plugin.jelly patch as a file

Stephane Nicoll added a comment - 21/Dec/04 06:42 AM
Are you planning to include this patch in 1.10?

Krystian Nowak added a comment - 21/Dec/04 07:42 AM
Hmmm... I hope that maven-plugins commiters will do that, if they found it valuable. It's only a proposal. If you want, you can use the patch yourself, but I don't know plans for maven-eclipse-plugin future.

Stephane Nicoll added a comment - 22/Dec/04 09:44 AM
I don't agree with

<j:if test="${depItem.getType().equalsIgnoreCase('jar')}">

What if I have an ejb-jar module in my dependencies? The type is ejb, not jar but still I want to include it in my eclipse sources.


Scott D. Ryan added a comment - 27/Dec/04 01:27 PM
This has proven very useful. I modified it to use the maven dist plug-in. This allows us to use the dist plug-in to generate the source code in a Maven standard way but also use this extension to download the code onto the local repository.

I hope this gets into the plugin soon.,

Scott


Krystian Nowak added a comment - 10/Jan/05 04:26 AM
to http://jira.codehaus.org/browse/MPECLIPSE-60#action_28273 (by Stephane Nicoll)

OK. EJB could be included. In my project I just didn't use any EJB dependencies. Conclusion - GOOD IDEA.


Krystian Nowak added a comment - 10/Jan/05 04:30 AM
to http://jira.codehaus.org/browse/MPECLIPSE-60#action_28350 (by Scott D. Ryan)

If you could, please, include diff/patch file in JIRA issue/comment.


Stephane Nicoll added a comment - 11/Jan/05 05:22 AM
Unfortunately, this patch does not handle SNAPSHOT dependencies. We have regular problems here with this patch.

If we depend on XXX-SNAPSHOT, the jelly code does not download the sources again.

The only solution so far is to clear our local cache and reinvoke the plugin. I think we could use maven standard dependencie's mechanism, right?

I can assist on this if necessary (Let me know)


Krystian Nowak added a comment - 11/Jan/05 07:30 AM
to http://jira.codehaus.org/browse/MPECLIPSE-60#action_28830 (by Stephane Nicoll)

Of course you are welcome to assist on the plugin version/diff development!

In my project I do not use SNAPSHOT dependencies, so I guess that is why I had none of the problems you descibed. Conclusion: Please help if you have some time and ideas.


Joerg Schaible added a comment - 06/May/05 09:22 AM
Just wonder, if the property should really be named "eclipse.source", since IDEA has the same functionality. "sourceCode" or "IDE.source" might be more appropriate.

Krystian Nowak added a comment - 09/May/05 04:12 AM
to http://jira.codehaus.org/browse/MPECLIPSE-60#action_38644 (by Joerg Schaible)

Hmmm... since it is a eclipse plugin, and there was already a property called eclipse.dependency I've just added eclipse.source. There is nothing more general e.g. IDE.dependency, so there is neither IDE.source. It's an architectural issue. If there would be a general plugin core and more specific plugins to this plugin () for given IDEs there we could change the name to IDE.* and then filter it in (where?) some specific configuration file for given IDE (e.g. idea.properties or eclipse.properties). But for simplicity let's let it as it is - just eclipse.*


Joerg Schaible added a comment - 09/May/05 05:53 AM
Its not just IDEs. Think about the javadoc URL. That can be used by eclipse plugin, but also by the javadoc plugin, that has nothing to do with IDEs. At our location, we have people working with different IDEs for the same project. So it seems quite silly to add the same information twice.

Milos Kleint added a comment - 09/May/05 06:10 AM

I've added an enhancement to maven-dist-plugin for creation and upload of source file distributions that are similar to javadoc distributions - MPDIST-21.
it allows to upload the source artifact to repository/${groupId}/src.jars/${artifactid}-{$version}.src.jar which is consistent with the javadoc plugin.
It allows me to check for the src jar in mevenide and download it if it exists. The repository/${groupId}/src/<name>.zip location seems lessconsistent and doesn't have a countepart on the upload side.

I don't think a dependency property is necessary, this can be trasparently checked for any dependency. Once we have a standard location and format of the source artifact.


Stephane Nicoll added a comment - 09/May/05 06:14 AM
> I don't think a dependency property is necessary, this can be trasparently checked for any dependency. Once we have a standard location and format of the source artifact.

Well, it could be. However, I think you might need to disable the behavior somehow (if I am not interested, the plugin should not check the repository for something I don't want).


Milos Kleint added a comment - 09/May/05 02:04 PM
maybe a separate goal or a goal parameter property could do?

do you have a usecase when you want to check for one dependency and not for another one? (if yes, a dependency property is probably necessary but I can't imagine the usecase)


Stephane Nicoll added a comment - 10/Nov/05 06:31 AM
No, I don't have such use case. If it could be disabled globally (property) that's fine with me.

Stephane Nicoll added a comment - 28/Dec/05 03:26 AM
Guys,

We need to include this in 1.11 I think. I don't think that M1 has a "java source" artifact right? Even if the patch sounds like a workaround, it's really needed. Without it, the source inclusion does not make much sense.


Stephane Nicoll added a comment - 08/Jan/06 03:22 AM
OK. So maven one has now a source plugin which is currently available in the plugins-sandbox.

The plugin deploys/installs the source archive in a location with maven2 legacy mode (i.e. java-sources/${artifactId}-${version}-sources.jar).

We now need to include download of such artifact. Milos Kleint has a solution for the mevenide plugin which I am gonna mimic.


Stephane Nicoll added a comment - 09/Jan/06 01:18 PM
A patch which allows to download java source archives from the repository. Only support the location handled by the maven source plugin.

handles SNAPSHOT artifacts.


Stephane Nicoll added a comment - 13/Jan/06 04:42 PM
OK ; It is resolved (finally!).

The plugin downloads source archives from the remote repository. This could be disabled, see the doc for more details.