Thanks. I tried it, but unfortunately it resolves the transitive dependencies 
as well... So, I'm afraid I'll have to stick with my original solution.


On Tuesday 05 June 2007 21:30, Rune Flobakk wrote:
> I have recently been struggling with what I think is the same as you
> want. I am developing a plugin which in the plugin code I want to
> retrieve the plugin's, not the current project's, dependencies.
>
> I found the parameter expression I was after in this FAQ:
> http://docs.codehaus.org/display/MAVENUSER/FAQs-1#FAQs-1-HowdoIgetaplugin%2
>7sdependenciesfromaMojo%3F
>
>
> This gives me the plugin's dependencies:
>
>      /**
>       * @parameter expression="${plugin.artifacts}"
>       * @required
>       */
>      protected List<Artifact> pluginDependencyArtifacts;
>
>
> This gives me the local repository paths to each dependency:
>
>      for( Artifact artifact : pluginDependencyArtifacts )
>          getLog( artifact.getFile().getAbsolutePath() );
>
>
> Hope this is what you're after :)
>
>
> Rune
>
>
>
> --------------------------------------------------------------
> Thanks for the numerous replies.
>
>  > > > > ${project.dependencies} ?
>
> The ${project.dependencies} is not the correct one, since it gives me the
> dependencies of the project, not the plugin! Also, it resolves the
> dependencies transitively!
>
>  > ArtifactoryFactory : interface
>  > ArtifactResolver : interface
>  >
>  > Where can we find the implementations? I already have a list of
>  > dependencies, just need resolve the full path for each dependency.
>  >
>  > > Use the information in the dependency list and an ArtifactFactory to
>  > > create
>  > > an Artifact with , then use an ArtifactResolver to resolve them fully.
>  > > Afterwards, you can call getFile(), to get the File objet.
>
> When using those interfaces, add something similar to these lines in your
> MOJO:
>
>      /**
>       * @component
> role="org.apache.maven.artifact.resolver.ArtifactResolver"
>       * @required
>       * @readonly
>       */
>      private ArtifactResolver artifactResolver;
>
> Now, you can use
>
> artifactResolver.resolve(artifact)
>
> for you artifact (if it has not been resolved already), after which you can
> ask the artifact
>
> artifact.getFile()
>
> which will give you the full path to the JAR/POM/whatever file of this
> artifact.
>
>
>
> For my situation though (dependencies of the plugin), I use the following
> code:
>
> for (Object object : this.project.getPluginArtifacts()) {
>      Artifact artifact = (Artifact) object;
>      if ("my.group.id".equals(artifact.getGroupId())
> && "myArtifactId".equals(artifact.getArtifactId())) {
>          for (Object object2 :
> this.artifactMetadataSource.retrieve(artifact,
> this.localRepository,
> this.project.getRemoteArtifactRepositories()).getArtifacts()) {
>              Artifact artifact2 = (Artifact) object2;
>              this.artifactResolver.resolve(artifact2,
> this.project.getRemoteArtifactRepositories(), this.localRepository);
>              JarFile jarFile = new JarFile(artifact2.getFile());
>              JarEntry workflow = null;
>              for (Enumeration<JarEntry> jarEntries = jarFile.entries();
> workflow == null && jarEntries.hasMoreElements();) {
>                  JarEntry jarEntry = jarEntries.nextElement();
>                  if (jarEntry.getName() != null &&
> jarEntry.getName().endsWith("filename.extension")) {
>                      workflow = jarEntry;
>                  }
>              }
>              if (workflow != null) {
>                  workflowFiles.add(workflow.getName());
>              }
>          }
>      }
> }
>
> In short, this code runs through the plugins until it finds the one I'm
> looking for ("my.group.id" & "myArtifactId"). It then retrieves this
> artifact
> from the repository and gets its dependencies.
> Those are resolved (to make sure all properties have been initialized -- eg
> fileName doesn't work without it) and opened as JAR-files (atm I'm sure
> they are JARs, but need to change this code to make sure it doesn't fail if
> they're not).
> I then iterate over the JAR to look for a specific file
> ("filename.extension")
> and save the full names of the entry in a Map.
>
> This works like a charm for me, you just need to make sure you add all the
> right components in the MOJO.
>
> If anybody needs some more info/help, feel free to ask!

-- 
Roland Asmann

CFC Informationssysteme Entwicklungsgesellschaft m.b.H
Bäckerstrasse 1/2/7
A-1010 Wien
FN 266155f, Handelsgericht Wien

Tel.: +43/1/513 88 77 - 27
Fax.: +43/1/513 88 62
Email: [EMAIL PROTECTED]
Web: www.cfc.at

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to