You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by nicolas de loof <ni...@apache.org> on 2008/11/06 10:47:56 UTC

m2eclipse checkstyle support

Hi,
I'm trying to contribute the checkstyle eclipse plugin to support m2eclipse
configuration.

(
https://platina.svn.sourceforge.net/svnroot/platina/eclipse/checkstyle/trunk
)

As a proof of concept, I'd like to support as a basic configuration the
simplier use case :

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <configuration>
          <configLocation>checkstyle.xml</configLocation>
        </configuration>
      </plugin>


To configure the eclipse plugin from the m2eclispe extension, I need
to get the absolute path of the configLocation parameter.

Is there any way using the MavenBmbedder / MavenProject APIs to
retrieve a plugin ClassLoader, so I can use cl.getResource() ?


Thanks

Nicolas.

Re: m2eclipse checkstyle support

Posted by nicolas de loof <ni...@apache.org>.
This one was my code sample to bootsrap my plugin (as I have no experience
in eclipse development). Thanks for the link anyway ;)

I'll announce here any significant progress.


>
>   I suppose you could get resolved dependencies from MavenProject instance
> passed to you from configurator, so you could create your own
> URLClassLoader
> from those jars.
>  Also, Peter Hayes implemented project configurator for m2eclipse and its
> source code is attached to jira issue at
> http://jira.codehaus.org/browse/MNGECLIPSE-900
>
>  regards,
>  Eugene
>
>
> --
> View this message in context:
> http://www.nabble.com/m2eclipse-checkstyle-support-tp20357992p20363420.html
> Sent from the Maven Developers mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>

Re: m2eclipse checkstyle support

Posted by nicolas de loof <ni...@apache.org>.
Maybe I could use the embedder to prepare a "mvn checkstyle: checkstyle"
execution and then get the configured ClassLoader ?
I'm not used with maven embedder so have no idea if this is possible and how
...

2008/11/6 nicolas de loof <ni...@apache.org>

>
>>   I suppose you could get resolved dependencies from MavenProject instance
>> passed to you from configurator, so you could create your own
>> URLClassLoader
>> from those jars.
>
>
> I need to get the PLUGIN dependencies, not the project one. AFAIK the
> MavenProject API doesn't give me access to plugins
> ClassRealm/ClassPath/artifacts
>

Re: m2eclipse checkstyle support

Posted by Eugene Kuleshov <eu...@md.pp.ru>.

nicolas de loof-3 wrote:
> 
> I can build the plugin artifact :Artifact pluginArtifact =
>                     embedder.createArtifact( plugin.getGroupId(),
> plugin.getArtifactId(), plugin.getVersion(),
>                         Artifact.SCOPE_RUNTIME, "maven-plugin" );
> 
> then get the declared dependencies :
> List dependencies = plugin.getDependencies();
> 
> Then build a URLClassLoader to get the resource URL
>  URL[] urls = new URL[] { ... };
>  ClassLoader classLoader = new URLClassLoader( urls );
>  URL url = classLoader.getResource( configLocation.getValue() );
> 

That is not right.First of all createArtifact() does not download any jars.
You need to use MavenEmbedder.resolve() method to get jars downloaded.

However it is not going to help you with dependencies, because
plugin.getDependencies(); will return model dependencies (stuff that is
declared in pom.xml where plugin is used, but it does not include
dependencies declared in plugin's own pom (and its parent).


nicolas de loof-3 wrote:
> 
> But as you suggested, this code allready exists somewhere in maven !
> 
> I also don't know how to get dependencies from pluginArtifact : how to
> build
> a mavenProject from it to get mavenProject.getArtifacts() ?
> 

You can use MavenEmbedder.readProjectWithDependencies() to get MavenProject
for the plugin's pom. But even that won't handle artifacts declared in
plugin/dependencies (including stuff decalred somewhere else in
plugin/dependencyManagement).

  regards,
  Eugene


-- 
View this message in context: http://www.nabble.com/m2eclipse-checkstyle-support-tp20357992p20364918.html
Sent from the Maven Developers mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: m2eclipse checkstyle support

Posted by nicolas de loof <ni...@apache.org>.
I can build the plugin artifact :Artifact pluginArtifact =
                    embedder.createArtifact( plugin.getGroupId(),
plugin.getArtifactId(), plugin.getVersion(),
                        Artifact.SCOPE_RUNTIME, "maven-plugin" );

then get the declared dependencies :
List dependencies = plugin.getDependencies();

Then build a URLClassLoader to get the resource URL
 URL[] urls = new URL[] { ... };
 ClassLoader classLoader = new URLClassLoader( urls );
 URL url = classLoader.getResource( configLocation.getValue() );

But as you suggested, this code allready exists somewhere in maven !

I also don't know how to get dependencies from pluginArtifact : how to build
a mavenProject from it to get mavenProject.getArtifacts() ?


2008/11/6 Eugene Kuleshov <eu...@md.pp.ru>

>
>
> nicolas de loof-3 wrote:
> >
> >>   I suppose you could get resolved dependencies from MavenProject
> >> instance
> >> passed to you from configurator, so you could create your own
> >> URLClassLoader
> >> from those jars.
> >
> > I need to get the PLUGIN dependencies, not the project one. AFAIK the
> > MavenProject API doesn't give me access to plugins
> > ClassRealm/ClassPath/artifacts
> >
>
>   Right. You can still read MavenProject for prugin artifact to get its
> dependencies. Though that won't give you dependencies declared in
> plugin/dependencies element. Maybe Shane, John or Jason can point you to
> the
> Maven classes that already implementing all this logic.
>
>  regards,
>  Eugene
>
>
> --
> View this message in context:
> http://www.nabble.com/m2eclipse-checkstyle-support-tp20357992p20364498.html
> Sent from the Maven Developers mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>

Re: m2eclipse checkstyle support

Posted by Eugene Kuleshov <eu...@md.pp.ru>.

nicolas de loof-3 wrote:
> 
>>   I suppose you could get resolved dependencies from MavenProject
>> instance
>> passed to you from configurator, so you could create your own
>> URLClassLoader
>> from those jars.
> 
> I need to get the PLUGIN dependencies, not the project one. AFAIK the
> MavenProject API doesn't give me access to plugins
> ClassRealm/ClassPath/artifacts
> 

  Right. You can still read MavenProject for prugin artifact to get its
dependencies. Though that won't give you dependencies declared in
plugin/dependencies element. Maybe Shane, John or Jason can point you to the
Maven classes that already implementing all this logic.

  regards,
  Eugene


-- 
View this message in context: http://www.nabble.com/m2eclipse-checkstyle-support-tp20357992p20364498.html
Sent from the Maven Developers mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: m2eclipse checkstyle support

Posted by nicolas de loof <ni...@apache.org>.
>
>
>   I suppose you could get resolved dependencies from MavenProject instance
> passed to you from configurator, so you could create your own
> URLClassLoader
> from those jars.


I need to get the PLUGIN dependencies, not the project one. AFAIK the
MavenProject API doesn't give me access to plugins
ClassRealm/ClassPath/artifacts

Re: m2eclipse checkstyle support

Posted by Eugene Kuleshov <eu...@md.pp.ru>.

nicolas de loof-3 wrote:
> 
> I'm trying to contribute the checkstyle eclipse plugin to support
> m2eclipse
> configuration.
> https://platina.svn.sourceforge.net/svnroot/platina/eclipse/checkstyle/trunk
> 

  That sounds cool. Please keep us posted.


nicolas de loof-3 wrote:
> 
> As a proof of concept, I'd like to support as a basic configuration the
> simplier use case :
> 
>       <plugin>
>         <groupId>org.apache.maven.plugins</groupId>
>         <artifactId>maven-checkstyle-plugin</artifactId>
>         <configuration>
>           <configLocation>checkstyle.xml</configLocation>
>         </configuration>
>       </plugin>
> 
> 
> To configure the eclipse plugin from the m2eclispe extension, I need
> to get the absolute path of the configLocation parameter.
> 
> Is there any way using the MavenBmbedder / MavenProject APIs to
> retrieve a plugin ClassLoader, so I can use cl.getResource() ?
> 

  I suppose you could get resolved dependencies from MavenProject instance
passed to you from configurator, so you could create your own URLClassLoader
from those jars.
  Also, Peter Hayes implemented project configurator for m2eclipse and its
source code is attached to jira issue at
http://jira.codehaus.org/browse/MNGECLIPSE-900

  regards,
  Eugene


-- 
View this message in context: http://www.nabble.com/m2eclipse-checkstyle-support-tp20357992p20363420.html
Sent from the Maven Developers mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org