IMHO nestacilo by Set deps = project.getArtifacts(); ?
Tim by ziskal vsechny tranzitivni dependencies, pokud by je potreboval
filtrovat, staci vyuzit
triduorg.apache.maven.shared.artifact.filter.collection.FilterArtifacts.
Petr Prochazka

On Fri, Jul 31, 2009 at 1:49 PM, Petr Ferschmann <[email protected]>wrote:

> Zkuste vyjít z tohoto:
> import java.io.ByteArrayOutputStream;
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.FileWriter;
> import java.io.IOException;
> import java.util.HashSet;
> import java.util.Set;
>
> import org.apache.commons.codec.digest.DigestUtils;
> import org.apache.commons.io.IOUtils;
> import org.apache.maven.artifact.Artifact;
> import org.apache.maven.artifact.factory.ArtifactFactory;
> import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
> import org.apache.maven.artifact.repository.ArtifactRepository;
> import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
> import org.apache.maven.artifact.resolver.ArtifactResolver;
> import org.apache.maven.plugin.AbstractMojo;
> import org.apache.maven.plugin.MojoExecutionException;
> import org.apache.maven.project.MavenProject;
> import org.apache.maven.project.MavenProjectBuilder;
>
> /**
> * Goal which touches a timestamp file.
> *
> * @goal write
> *
> * @phase package
> */
> public class MyMojo extends AbstractMojo {
>
>   /**
>    * @parameter expression="${localRepository}"
>    * @required
>    * @readonly
>    */
>   private ArtifactRepository        localRepository;
>
>   /**
>    * @component role="org.apache.maven.artifact.resolver.ArtifactResolver"
>    * @required
>    * @readonly
>    */
>   private ArtifactResolver        artifactResolver;
>
>   /**
>    * @parameter expression="${project.remoteArtifactRepositories}"
>    * @required
>    * @readonly
>    */
>   private java.util.List            remoteRepositories;
>
>   /**
>    * @component role="org.apache.maven.artifact.factory.ArtifactFactory"
>    * @required
>    * @readonly
>    */
>   private ArtifactFactory            artifactFactory;
>
>   /**
>    * @parameter expression="${project.version}"
>    * @readonly
>    */
>   private String                    version;
>
>   /**
>    * @component
>    * @required
>    * @readonly
>    */
>   private ArtifactMetadataSource    artifactMetadataSource;
>
>   /**
>    * @component role="org.apache.maven.project.MavenProjectBuilder"
>    * @required
>    */
>   private MavenProjectBuilder        mavenProjectBuilder;
>
>   /**
>    * @parameter expression="${project.groupId}"
>    * @required
>    */
>   public String                    groupId;
>
>   /**
>    * @parameter expression=""
>    */
>   public String                    filePrefix;
>
>   /**
>    * @parameter expression=""
>    */
>   public String                    linePrefix;
>
>   /**
>    * @parameter
>    * @required
>    */
>   public String[]                    artifactIds;
>
>   /**
>    * @parameter
>    */
>   public String[]                    excludeIds;
>
>   /**
>    * Location of the file.
>    *
>    * @parameter
>    * @required
>    */
>   private File                    outputFile;
>
>   /**
>    * Location of the file.
>    *
>    * @parameter expression="true"
>    * @required
>    */
>   private final Boolean            writeFull    = true;
>
>   public void execute() throws MojoExecutionException {
>       Set<Artifact> artifacts = new HashSet<Artifact>();
>
>       for (String artifact : artifactIds) {
>           Artifact art =
> artifactFactory.createArtifactWithClassifier(groupId, artifact, version,
> "jar", null);
>
>           artifacts.addAll(getDependencyArtifacts(art));
>           artifacts.add(art);
>       }
>
>       Set<Artifact> artifactsToExclude = new HashSet<Artifact>();
>       if (excludeIds != null) {
>           for (String artifact : excludeIds) {
>               Artifact art =
> artifactFactory.createArtifactWithClassifier(groupId, artifact, version,
> "jar", null);
>                 artifacts.removeAll(getDependencyArtifacts(art));
>               artifacts.remove(art);
>           }
>       }
>
>             outputFile.getParentFile().mkdirs();
>
>       FileWriter w = null;
>       try {
>           w = new FileWriter(outputFile);
>           if (filePrefix != null && !filePrefix.isEmpty()) {
>               w.append(filePrefix);
>               w.append("\n");
>           }
>
>           for (Artifact artifact : artifacts) {
>               long size = artifact.getFile().length();
>
>               FileInputStream fd = new FileInputStream(artifact.getFile());
>               ByteArrayOutputStream out = new ByteArrayOutputStream();
>               IOUtils.copy(fd, out);
>               fd.close();
>
>               String sha1 = DigestUtils.shaHex(out.toByteArray());
>
>               if (linePrefix != null && !linePrefix.isEmpty()) {
>                   w.append(linePrefix);
>               }
>                             if (writeFull) {
>                   w.append(artifact.getFile().getName() + "\t" + size +
> "\tsha1:" + sha1 + "\n");
>               } else {
>                   w.append(artifact.getFile().getName() + "\n");
>               }
>           }
>       } catch (IOException e) {
>           throw new MojoExecutionException("Error creating file " +
> outputFile, e);
>       } finally {
>           if (w != null) {
>               try {
>                   w.close();
>               } catch (IOException e) {
>                   // ignore
>               }
>           }
>       }
>   }
>
>   private Set<Artifact> getDependencyArtifacts(Artifact artifact) throws
> MojoExecutionException {
>
>       try {
>           // Make sure the artifact is resolved before we do anything with
> it
>           getArtifactResolver().resolve(artifact, getRemoteRepositories(),
> getLocalRepository());
>
>           MavenProject subProject =
> getMavenProjectBuilder().buildFromRepository(artifact,
> getRemoteRepositories(),
>                   getLocalRepository());
>
>
>           Set<Artifact> artifacts =
> subProject.createArtifacts(getArtifactFactory(), null, null);
>           ArtifactResolutionResult arr =
> getArtifactResolver().resolveTransitively(artifacts, artifact,
>                   getLocalRepository(), getRemoteRepositories(),
> getArtifactMetadataSource(), null);
>           Set<Artifact> result = arr.getArtifacts();
>
>           return result;
>       } catch (Exception ex) {
>           throw new MojoExecutionException("Failed to get dependencies",
> ex);
>       }
>   }
>
>   private ArtifactRepository getLocalRepository() {
>       return localRepository;
>   }
>
>   private ArtifactResolver getArtifactResolver() {
>       return artifactResolver;
>   }
>
>   private java.util.List getRemoteRepositories() {
>       return remoteRepositories;
>   }
>
>   private ArtifactFactory getArtifactFactory() {
>       return artifactFactory;
>   }
>
>   private ArtifactMetadataSource getArtifactMetadataSource() {
>       return artifactMetadataSource;
>   }
>
>   private MavenProjectBuilder getMavenProjectBuilder() {
>       return mavenProjectBuilder;
>   }
>
> }
>
> Tichý Miroslav napsal(a):
>
>> Abych to upresnil, programove sem myslel s vyuzitim maven API ci API
>> jakekoliv maven pluginy...predpokladam, ze mi nezbude nic jineho, nez zacit
>> zkoumat zdrojaky dependency tree pluginy, protože ta to nejakym zpusobem
>> zvlada...
>>
>> Mirek ________________________________________
>> From: [email protected] [mailto:[email protected]] On
>> Behalf Of Jakub Stonavsky
>> Sent: Thursday, July 30, 2009 4:14 PM
>> To: Java
>> Subject: Re: maven - jak programove ziskat zavislost artefaktu
>>
>> Ahoj,
>>
>> pokud ti nestaci vypis, ktery poskytuje mvn dependency:build-classpath
>> (ten vypise umisteni dependencies v repository, mel by to zvladnout bundle (
>> http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html)).
>>
>> K.
>> 2009/7/30 Tichý Miroslav <[email protected]>
>>
>> Ahoj,
>> v maven-war-pluginu potrebuji programove ziskat zavislosti pro každý
>> artefakt (war), na kterem je aktualni projekt (tedy také war) zavisly.
>> Netusite, jak na to?
>>
>> Diky
>>
>> Mirek Tichý
>>
>>
>>
>>
>>
>
> --
> Petr Ferschmann
>
> --
> SoftEU s.r.o.
> Lochotínská 18, 301 00 Plzeň, Česká republika
> Phone: +420 371 124 300, +420 371 124 384
> E-mail: [email protected]  http://www.softeu.com/
>
>

Odpovedet emailem