Andreas -

Thanks - this works for me with one huge caveat (perhaps not
experienced by you since you're using scala?).

When the DefaultMavenPluginManager is loaded, it's loaded as part of
an org.apache.maven:maven-core specific classloader.  One of the
classes loaded in the PlexusConfiguration.  When my plugin is loaded,
it uses it's own classloader (as all plugins do I believe).  This
class loader also gets PlexusConfiguration loaded because I'm
referencing it via the getMojoConfiguration call.

What I end up with is the dreaded java.lang.LinkageError.  Not sure
how to move forward.  Seems like PlexusConfiguration would have to be
loaded into a parent classloader instead....

Caused by: java.lang.LinkageError: loader constraints violated when
linking org/codehaus/plexus/configuration/PlexusConfiguration class

On Sat, Oct 23, 2010 at 7:49 AM, Andreas Gies <[email protected]> wrote:
> Hi there
>
> i *think* the key point was to call getMojoConfiguration on the
> Mojodescriptor
> I had resolved. In my case that gives me all the default configurations as I
> would have
> expected. I need only to set configs that differ from the default settings.
>
> I am attaching the latest code for my "play" plugin again. It is in scala,
> but you should get
> the idea of using the API's.
>
> Best regards
> Andreas
>
>
>
> Am 10/22/10 6:24 PM, schrieb Mike Lenner:
>>
>> Thanks very much for this thread.  I'm trying to write a plugin with
>> maven 3.0 (simply in Java) that executes another plugin as well - this
>> has been very helpful.
>>
>> Just to clear up what you've discovered, were you able to use
>> mojoDescriptor.getMojoConfiguration to build the default configuration
>> for the called plugin or do you still need to manually set all the
>> default configs yourself?  Right now I'm only able to get it working
>> doing the later.
>>
>> Thanks,
>> Mike
>>
>> On Thu, Oct 21, 2010 at 2:52 AM, Andreas Gies<[email protected]>
>>  wrote:
>>>
>>> Hi all,
>>>
>>> just to finish up the thread, I have fixed this by adding a
>>> @RequiresDependencyResolution("test")
>>> to the mojo calling the dependency plugin.
>>>
>>> Thanks and best regards
>>> Andreas
>>>
>>> Am 10/21/10 3:10 AM, schrieb Andreas Gies:
>>>>
>>>>  Hello,
>>>>
>>>> a last update for today. I have compared a debug session of
>>>>
>>>> mvn dependency:resolve
>>>>
>>>> with what happens in my code. It seems, that when calling the plugin
>>>> from
>>>> the command line, at the end of the day
>>>> a class named
>>>>
>>>> org.apache.maven.lifecycle.internal.MojoExecutor
>>>>
>>>> kind of controlls he execution and also takes initiates the desired
>>>> dependency resolution before the plugin code is called.
>>>> Therefore the dependency plugin finds the dependencies and all is good.
>>>>
>>>> However, when i invoke
>>>>
>>>> BuildPluginManager.executeMojo
>>>>
>>>> the dependency resolution does not happen and the dependency plugin
>>>> doesnt
>>>> find them.
>>>>
>>>>
>>>> I have now the options to use a non-public API and reuse the
>>>> MojoExecutor
>>>> code or kinfd of Mimick that behavior.
>>>> I kind of have the feeling that I am missing something very obvious in
>>>> the
>>>> API. A pointer to a correct call triggering
>>>> dependency resolution would be great. Perhaps I have selected the wrong
>>>> entrypoint into the API ?
>>>>
>>>> Thanks and best regards
>>>> Andreas
>>>>
>>>> Am 10/21/10 2:12 AM, schrieb Andreas Gies:
>>>>>
>>>>>  Hello,
>>>>>
>>>>> another update on this. From studying the source code I was under the
>>>>> impression that mojoDescriptor.getConfiguration
>>>>> would give me the default configuration, but it is
>>>>> mojoDescriptor.getMojoConfiguration.
>>>>>
>>>>> A debug session has shown, that the dependency plugin actually
>>>>> executes,
>>>>> but somehow doesn't recognize the dependencies
>>>>> of the project.
>>>>>
>>>>> Best regards
>>>>> Andreas
>>>>>
>>>>> Am 10/20/10 8:28 PM, schrieb Andreas Gies:
>>>>>>
>>>>>>  Hello,
>>>>>>
>>>>>> I forgot to mention that the output from the scala plugin is embedded
>>>>>> in
>>>>>> the build.log produced by the mavan invoker plugin.
>>>>>>
>>>>>> Best regards
>>>>>> Andreas
>>>>>>
>>>>>> Am 10/20/10 8:22 PM, schrieb Andreas Gies:
>>>>>>>
>>>>>>>  Hello,
>>>>>>>
>>>>>>> I am still banging my head on this problem, though I got a bit
>>>>>>> farther.
>>>>>>> I found a link via Google pointing to the maven site plugin and there
>>>>>>> to the
>>>>>>> DefaultMavenReportExecutor. I have tried to mimick the behavior in my
>>>>>>> special
>>>>>>> case and for testing I want to invoke the maven dependency plugin,
>>>>>>> namely
>>>>>>> the unpack dependencies goal.
>>>>>>>
>>>>>>> It seems to work if I provide all the missing paramters (like project
>>>>>>> etc.) into
>>>>>>> the configuration as expressions as follows
>>>>>>>
>>>>>>>    val config : Xpp3Dom = Xpp3DomUtils.mergeXpp3Dom(
>>>>>>>       buildConfiguration(
>>>>>>>         Map(
>>>>>>>          "outputDirectory" ->  "test",
>>>>>>>          "project" ->  "${project}",
>>>>>>>          "local" ->  "${localRepository}",
>>>>>>>          "reactorProjects" ->  "${reactorProjects}" ,
>>>>>>>          "remoteRepos" ->  "${project.remoteArtifactRepositories}"
>>>>>>>         )
>>>>>>>       ),
>>>>>>>      convert(md)
>>>>>>>    )
>>>>>>>
>>>>>>> That approach doesn't give me any Exceptions. I would have expected
>>>>>>> that all parameters except the non-default output directory
>>>>>>> would be resolved as the dependency plugin gives default expressions
>>>>>>> for them.
>>>>>>>
>>>>>>>
>>>>>>> However, this approach removes the parameter exceptions from before,
>>>>>>> but calling it doesn't unpack the dependencies (nothing happens
>>>>>>> really).
>>>>>>>
>>>>>>> I have tried to use the
>>>>>>>
>>>>>>>  LifecycleExecutor.executeForkedExecutions
>>>>>>>  BuildPluginManager.executeMojo
>>>>>>>
>>>>>>> and even tried to call execute on the configured Mojo (which I
>>>>>>> probably
>>>>>>> shouldn't do ?)
>>>>>>>
>>>>>>> I have attached a sample build output and also the code of my scala
>>>>>>> based mojo.
>>>>>>>
>>>>>>> Apart from studying the source code of the API and some sample
>>>>>>> plugins,
>>>>>>> is there documentation how the
>>>>>>> new plugin API is supposed to work ?
>>>>>>>
>>>>>>> Am I trying to do something out of the ordinary here ? (I know I
>>>>>>> could
>>>>>>> configure the dependency plugin in the
>>>>>>> pom but as this is *such* an essential step in the final mojo I don't
>>>>>>> want to give the user the option of leaving it
>>>>>>> out ... and I wanted to learn some more maven internals).
>>>>>>>
>>>>>>> Has anyone an example of initializing and calling a mojo from within
>>>>>>> a
>>>>>>> mojo using the new API ? - Java is fine as
>>>>>>> well, I can adopt it to scala as a learning exercise.
>>>>>>>
>>>>>>> I think I might be missing something in terms of hooking up or
>>>>>>> registering the project with the dependency plugin
>>>>>>> though the build output indicates that the project is referenced
>>>>>>> correctly.
>>>>>>>
>>>>>>>
>>>>>>> Any hints would be really appreciated; if I am hitting the wrong
>>>>>>> list,
>>>>>>> please let me know.
>>>>>>>
>>>>>>> Thanks in advance
>>>>>>> Andreas
>>>>>>>
>>>>>>> Am 10/13/10 9:27 AM, schrieb Andreas Gies:
>>>>>>>>
>>>>>>>>  Hello Maveners ,
>>>>>>>>
>>>>>>>> mainly for self learning purposes I am trying to build some plugins
>>>>>>>> for Maven 3 using the Scala language.
>>>>>>>> One of the things I had going before (Maven 2&  Java based) is to
>>>>>>>> invoke another plugin programmatically.
>>>>>>>>
>>>>>>>> Now I am trying to invoke the dependency plugin, namely the
>>>>>>>> unpack-dependencies goal and am running
>>>>>>>> into a rather cryptic error message:
>>>>>>>>
>>>>>>>> [ERROR] Failed to execute goal
>>>>>>>> com.progress.maven.plugins:plugin-sandbox:8.0-SNAPSHOT:echo
>>>>>>>> (default-cli) on
>>>>>>>> project test-plugin: The parameters 'proje
>>>>>>>> ct', 'local', 'remoteRepos', 'reactorProjects' for goal
>>>>>>>>
>>>>>>>> org.apache.maven.plugins:maven-dependency-plugin:2.1:unpack-dependencies
>>>>>>>>  are
>>>>>>>> missing or invali
>>>>>>>> d ->  [Help 1]
>>>>>>>>
>>>>>>>> org.apache.maven.lifecycle.LifecycleExecutionException: Failed to
>>>>>>>> execute goal
>>>>>>>> com.progress.maven.plugins:plugin-sandbox:8.0-SNAPSHOT:echo
>>>>>>>> (default-cl
>>>>>>>> i) on project test-plugin: The parameters 'project', 'local',
>>>>>>>> 'remoteRepos', 'reactorProjects' for goal
>>>>>>>>
>>>>>>>> org.apache.maven.plugins:maven-dependency-plugin:2.1:unpack-dependencies
>>>>>>>>  are
>>>>>>>> missing or invalid
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:157)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:88)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:80)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:87)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
>>>>>>>>        at
>>>>>>>> org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:315)
>>>>>>>>        at
>>>>>>>> org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
>>>>>>>>        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:445)
>>>>>>>>        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:168)
>>>>>>>>        at org.apache.maven.cli.MavenCli.main(MavenCli.java:132)
>>>>>>>>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
>>>>>>>> Method)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>>>>>        at java.lang.reflect.Method.invoke(Method.java:597)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
>>>>>>>> Caused by: org.apache.maven.plugin.PluginParameterException: The
>>>>>>>> parameters 'project', 'local', 'remoteRepos', 'reactorProjects' for
>>>>>>>> goal
>>>>>>>>
>>>>>>>> org.apache.maven.plugins:maven-dependency-plugin:2.1:unpack-dependencies
>>>>>>>>  are
>>>>>>>> missing or invalid
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePluginFields(DefaultMavenPluginManager.java:514)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:467)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:96)
>>>>>>>>        at de.woq.maven.plugins.TestMojo.execute(TestMojo.scala:109)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
>>>>>>>>        at
>>>>>>>>
>>>>>>>> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
>>>>>>>>        ... 19 more
>>>>>>>>
>>>>>>>> It seems that the current project is not passed correctly to the
>>>>>>>> plugin. I have noticed that the API for invoking plugins has
>>>>>>>> slightly
>>>>>>>> changed, but was unable to get more information.
>>>>>>>> Any hints where to dig deeper would be greatly appreciated.
>>>>>>>>
>>>>>>>> For completeness here is the code of my plugin so far .... (As I
>>>>>>>> said
>>>>>>>> its a learning exercise :))
>>>>>>>>
>>>>>>>> /*
>>>>>>>>  * Copyright (C) 2010, Way of Quality
>>>>>>>>  * All rights reserved.
>>>>>>>>  *
>>>>>>>>  * Licensed under the Apache License, Version 2.0 (the "License");
>>>>>>>>  * you may not use this file except in compliance with the License.
>>>>>>>>  * You may obtain a copy of the License at
>>>>>>>>  *
>>>>>>>>  * http://www.apache.org/licenses/LICENSE-2.0
>>>>>>>>  *
>>>>>>>>  * Unless required by applicable law or agreed to in writing,
>>>>>>>> software
>>>>>>>>  * distributed under the License is distributed on an "AS IS" BASIS,
>>>>>>>>  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
>>>>>>>> implied.
>>>>>>>>  * See the License for the specific language governing permissions
>>>>>>>> and
>>>>>>>>  * limitations under the License.
>>>>>>>>  */
>>>>>>>>
>>>>>>>> package de.woq.maven.plugins
>>>>>>>>
>>>>>>>> import org.apache.maven.plugin._
>>>>>>>> import descriptor.MojoDescriptor
>>>>>>>> import org.scala_tools.maven.mojo.annotations._
>>>>>>>> import org.apache.maven.project.MavenProject
>>>>>>>> import org.apache.maven.execution.MavenSession
>>>>>>>> import org.apache.maven.model.Plugin
>>>>>>>>
>>>>>>>> import scala.collection.JavaConversions._
>>>>>>>> import org.codehaus.plexus.component.annotations.Requirement
>>>>>>>> import org.codehaus.plexus.util.xml.Xpp3Dom
>>>>>>>>
>>>>>>>> @goal("echo")
>>>>>>>> @phase("process-sources")
>>>>>>>> @requiresProject
>>>>>>>> class TestMojo extends AbstractMojo {
>>>>>>>>
>>>>>>>> �...@readonly @parameter @expression("${project}")
>>>>>>>>  var project : MavenProject = _
>>>>>>>>
>>>>>>>> �...@readonly @parameter @expression("${session}")
>>>>>>>>  var session : MavenSession = _
>>>>>>>>
>>>>>>>> �...@requirement
>>>>>>>>  var pluginManager: BuildPluginManager = _
>>>>>>>>
>>>>>>>>  private def getBuildPlugin(groupId: String, artifactId: String,
>>>>>>>> version: Option[String]) = {
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>  List.fromIterator(project.getBuildPlugins.iterator).asInstanceOf[List[Plugin]]
>>>>>>>>      .filter(
>>>>>>>>         p =>  (p.getGroupId.equals(groupId))&&
>>>>>>>> (p.getArtifactId.equals(artifactId)&&  (version == None ||
>>>>>>>> p.getVersion.equals(version)))
>>>>>>>>      )
>>>>>>>>  }
>>>>>>>>
>>>>>>>>  def resolvePluginManager = {
>>>>>>>>
>>>>>>>>
>>>>>>>>  session.getContainer.lookup("org.apache.maven.plugin.BuildPluginManager").asInstanceOf[BuildPluginManager]
>>>>>>>>  }
>>>>>>>>
>>>>>>>>  def buildConfiguration(params: Map[String, String]): Xpp3Dom = {
>>>>>>>>    var config = new Xpp3Dom("configuration")
>>>>>>>>
>>>>>>>>    for{
>>>>>>>>      key<- params.keys
>>>>>>>>      value = params.get(key)
>>>>>>>>    } {
>>>>>>>>      var child = new Xpp3Dom(key)
>>>>>>>>      child.setValue(
>>>>>>>>        params.get(key) match {
>>>>>>>>          case Some(v) =>  v
>>>>>>>>          case None =>  ""
>>>>>>>>        }
>>>>>>>>      )
>>>>>>>>      config.addChild(child)
>>>>>>>>    }
>>>>>>>>
>>>>>>>>    println(config.toUnescapedString)
>>>>>>>>    config
>>>>>>>>  }
>>>>>>>>
>>>>>>>>  override def execute = {
>>>>>>>>
>>>>>>>>    val plugins = getBuildPlugin("org.apache.maven.plugins",
>>>>>>>> "maven-dependency-plugin", None)
>>>>>>>>    assert(plugins.length == 1, "Found " + plugins.length + " plugins
>>>>>>>> for dependdency resolution, expected 1")
>>>>>>>>
>>>>>>>>    val dep: Plugin = plugins.head
>>>>>>>>
>>>>>>>>    getLog.info("==============================")
>>>>>>>>
>>>>>>>>    // needed as component injection seems to be broken in scala
>>>>>>>> plugins ...
>>>>>>>>    pluginManager = resolvePluginManager
>>>>>>>>
>>>>>>>>    assert(project != null)
>>>>>>>>    assert(session != null)
>>>>>>>>    assert(pluginManager != null)
>>>>>>>>
>>>>>>>>    var config : Xpp3Dom = buildConfiguration(Map("outputDirectory"
>>>>>>>> ->
>>>>>>>> "test"))
>>>>>>>>
>>>>>>>>    var md : MojoDescriptor = pluginManager.getMojoDescriptor(
>>>>>>>>      dep, "unpack-dependencies",
>>>>>>>> project.getRemotePluginRepositories,
>>>>>>>> session.getRepositorySession
>>>>>>>>    )
>>>>>>>>
>>>>>>>>    var execution : MojoExecution = new MojoExecution(md, config)
>>>>>>>>
>>>>>>>>    assert(md != null)
>>>>>>>>
>>>>>>>>    pluginManager.executeMojo(session, execution)    //<==== fails
>>>>>>>> here ....
>>>>>>>>
>>>>>>>>    getLog.info("==============================")
>>>>>>>>  }
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>> Thanks and best regards
>>>>>>>> Andreas
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: [email protected]
>>>>>>> For additional commands, e-mail: [email protected]
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [email protected]
>>>>> For additional commands, e-mail: [email protected]
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [email protected]
>>>> For additional commands, e-mail: [email protected]
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to