src/main/java/ru/indvdum/maven/plugin/wd/TreeMojo.java
author indvdum
Fri, 13 May 2011 17:32:05 +0400
changeset 2 231c4b87c6e7
parent 1 940c8f9a9fbc
permissions -rw-r--r--
+ code from dependency:tree
indvdum@1
     1
package ru.indvdum.maven.plugin.wd;
indvdum@1
     2
indvdum@2
     3
import java.io.File;
indvdum@2
     4
import java.io.IOException;
indvdum@2
     5
import java.io.StringWriter;
indvdum@2
     6
import java.io.Writer;
indvdum@2
     7
import java.util.ArrayList;
indvdum@2
     8
import java.util.Arrays;
indvdum@2
     9
import java.util.Iterator;
indvdum@2
    10
import java.util.List;
indvdum@2
    11
indvdum@2
    12
import org.apache.maven.artifact.factory.ArtifactFactory;
indvdum@2
    13
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
indvdum@2
    14
import org.apache.maven.artifact.repository.ArtifactRepository;
indvdum@2
    15
import org.apache.maven.artifact.resolver.ArtifactCollector;
indvdum@2
    16
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
indvdum@2
    17
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
indvdum@2
    18
import org.apache.maven.artifact.versioning.ArtifactVersion;
indvdum@2
    19
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
indvdum@2
    20
import org.apache.maven.artifact.versioning.Restriction;
indvdum@2
    21
import org.apache.maven.artifact.versioning.VersionRange;
indvdum@2
    22
import org.apache.maven.execution.RuntimeInformation;
indvdum@2
    23
import org.apache.maven.plugin.AbstractMojo;
indvdum@2
    24
import org.apache.maven.plugin.MojoExecutionException;
indvdum@2
    25
import org.apache.maven.plugin.MojoFailureException;
indvdum@2
    26
import org.apache.maven.plugin.dependency.treeSerializers.DOTDependencyNodeVisitor;
indvdum@2
    27
import org.apache.maven.plugin.dependency.treeSerializers.GraphmlDependencyNodeVisitor;
indvdum@2
    28
import org.apache.maven.plugin.dependency.treeSerializers.TGFDependencyNodeVisitor;
indvdum@2
    29
import org.apache.maven.plugin.dependency.utils.DependencyUtil;
indvdum@2
    30
import org.apache.maven.project.MavenProject;
indvdum@2
    31
import org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter;
indvdum@2
    32
import org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter;
indvdum@2
    33
import org.apache.maven.shared.dependency.tree.DependencyNode;
indvdum@2
    34
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
indvdum@2
    35
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
indvdum@2
    36
import org.apache.maven.shared.dependency.tree.filter.AncestorOrSelfDependencyNodeFilter;
indvdum@2
    37
import org.apache.maven.shared.dependency.tree.filter.AndDependencyNodeFilter;
indvdum@2
    38
import org.apache.maven.shared.dependency.tree.filter.ArtifactDependencyNodeFilter;
indvdum@2
    39
import org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter;
indvdum@2
    40
import org.apache.maven.shared.dependency.tree.filter.StateDependencyNodeFilter;
indvdum@2
    41
import org.apache.maven.shared.dependency.tree.traversal.BuildingDependencyNodeVisitor;
indvdum@2
    42
import org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor;
indvdum@2
    43
import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor;
indvdum@2
    44
import org.apache.maven.shared.dependency.tree.traversal.FilteringDependencyNodeVisitor;
indvdum@2
    45
import org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor;
indvdum@2
    46
import org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor.TreeTokens;
indvdum@2
    47
indvdum@1
    48
/**
indvdum@1
    49
 * Displays the dependency tree with node id's for this project.
indvdum@2
    50
 * Based on {@link org.apache.maven.plugin.dependency.TreeMojo}.
indvdum@2
    51
 * 
indvdum@2
    52
 * @author indvdum
indvdum@2
    53
 * 13.05.2011 17:26:50
indvdum@1
    54
 * 
indvdum@1
    55
 * @goal tree
indvdum@1
    56
 */
indvdum@2
    57
public class TreeMojo extends AbstractMojo {
indvdum@2
    58
    // fields -----------------------------------------------------------------
indvdum@1
    59
indvdum@2
    60
    /**
indvdum@2
    61
     * The Maven project.
indvdum@2
    62
     *
indvdum@2
    63
     * @parameter expression="${project}"
indvdum@2
    64
     * @required
indvdum@2
    65
     * @readonly
indvdum@2
    66
     */
indvdum@2
    67
    private MavenProject project;
indvdum@2
    68
indvdum@2
    69
    /**
indvdum@2
    70
     * The artifact repository to use.
indvdum@2
    71
     *
indvdum@2
    72
     * @parameter expression="${localRepository}"
indvdum@2
    73
     * @required
indvdum@2
    74
     * @readonly
indvdum@2
    75
     */
indvdum@2
    76
    private ArtifactRepository localRepository;
indvdum@2
    77
indvdum@2
    78
    /**
indvdum@2
    79
     * The artifact factory to use.
indvdum@2
    80
     *
indvdum@2
    81
     * @component
indvdum@2
    82
     * @required
indvdum@2
    83
     * @readonly
indvdum@2
    84
     */
indvdum@2
    85
    private ArtifactFactory artifactFactory;
indvdum@2
    86
indvdum@2
    87
    /**
indvdum@2
    88
     * The artifact metadata source to use.
indvdum@2
    89
     *
indvdum@2
    90
     * @component
indvdum@2
    91
     * @required
indvdum@2
    92
     * @readonly
indvdum@2
    93
     */
indvdum@2
    94
    private ArtifactMetadataSource artifactMetadataSource;
indvdum@2
    95
indvdum@2
    96
    /**
indvdum@2
    97
     * The artifact collector to use.
indvdum@2
    98
     *
indvdum@2
    99
     * @component
indvdum@2
   100
     * @required
indvdum@2
   101
     * @readonly
indvdum@2
   102
     */
indvdum@2
   103
    private ArtifactCollector artifactCollector;
indvdum@2
   104
indvdum@2
   105
    /**
indvdum@2
   106
     * The dependency tree builder to use.
indvdum@2
   107
     *
indvdum@2
   108
     * @component
indvdum@2
   109
     * @required
indvdum@2
   110
     * @readonly
indvdum@2
   111
     */
indvdum@2
   112
    private DependencyTreeBuilder dependencyTreeBuilder;
indvdum@2
   113
indvdum@2
   114
    /**
indvdum@2
   115
     * If specified, this parameter will cause the dependency tree to be written to the path specified, instead of
indvdum@2
   116
     * writing to the console.
indvdum@2
   117
     * @deprecated use outputFile instead.
indvdum@2
   118
     * @parameter expression="${output}"
indvdum@2
   119
     */
indvdum@2
   120
    private File output;
indvdum@2
   121
indvdum@2
   122
    /**
indvdum@2
   123
     * If specified, this parameter will cause the dependency tree to be written to the path specified, instead of
indvdum@2
   124
     * writing to the console.
indvdum@2
   125
     * @parameter expression="${outputFile}"
indvdum@2
   126
     * @since 2.0-alpha-5
indvdum@2
   127
     */
indvdum@2
   128
    private File outputFile;
indvdum@2
   129
indvdum@2
   130
    /**
indvdum@2
   131
     * If specified, this parameter will cause the dependency tree to be written using the specified format. Currently
indvdum@2
   132
     * supported format are text, dot, graphml and tgf.
indvdum@2
   133
     *
indvdum@2
   134
     * These formats can be plotted to image files. An example of how to plot a dot file using
indvdum@2
   135
     * pygraphviz can be found <a href="http://networkx.lanl.gov/pygraphviz/tutorial.html#layout-and-drawing">here</a>
indvdum@2
   136
     *
indvdum@2
   137
     * @parameter expression="${outputType}" default-value="text"
indvdum@2
   138
     * @since 2.1
indvdum@2
   139
     */
indvdum@2
   140
    private String outputType;
indvdum@2
   141
indvdum@2
   142
    /**
indvdum@2
   143
     * The scope to filter by when resolving the dependency tree, or <code>null</code> to include dependencies from
indvdum@2
   144
     * all scopes. Note that this feature does not currently work due to MNG-3236.
indvdum@2
   145
     *
indvdum@2
   146
     * @since 2.0-alpha-5
indvdum@2
   147
     * @see <a href="http://jira.codehaus.org/browse/MNG-3236">MNG-3236</a>
indvdum@2
   148
     *
indvdum@2
   149
     * @parameter expression="${scope}"
indvdum@2
   150
     */
indvdum@2
   151
    private String scope;
indvdum@2
   152
indvdum@2
   153
    /**
indvdum@2
   154
     * Whether to include omitted nodes in the serialized dependency tree.
indvdum@2
   155
     *
indvdum@2
   156
     * @since 2.0-alpha-6
indvdum@2
   157
     *
indvdum@2
   158
     * @parameter expression="${verbose}" default-value="false"
indvdum@2
   159
     */
indvdum@2
   160
    private boolean verbose;
indvdum@2
   161
indvdum@2
   162
    /**
indvdum@2
   163
     * The token set name to use when outputting the dependency tree. Possible values are <code>whitespace</code>,
indvdum@2
   164
     * <code>standard</code> or <code>extended</code>, which use whitespace, standard or extended ASCII sets
indvdum@2
   165
     * respectively.
indvdum@2
   166
     *
indvdum@2
   167
     * @since 2.0-alpha-6
indvdum@2
   168
     *
indvdum@2
   169
     * @parameter expression="${tokens}" default-value="standard"
indvdum@2
   170
     */
indvdum@2
   171
    private String tokens;
indvdum@2
   172
indvdum@2
   173
    /**
indvdum@2
   174
     * A comma-separated list of artifacts to filter the serialized dependency tree by, or <code>null</code> not to
indvdum@2
   175
     * filter the dependency tree. The artifact syntax is defined by <code>StrictPatternIncludesArtifactFilter</code>.
indvdum@2
   176
     *
indvdum@2
   177
     * @see StrictPatternIncludesArtifactFilter
indvdum@2
   178
     * @since 2.0-alpha-6
indvdum@2
   179
     *
indvdum@2
   180
     * @parameter expression="${includes}"
indvdum@2
   181
     */
indvdum@2
   182
    private String includes;
indvdum@2
   183
indvdum@2
   184
    /**
indvdum@2
   185
     * A comma-separated list of artifacts to filter from the serialized dependency tree, or <code>null</code> not to
indvdum@2
   186
     * filter any artifacts from the dependency tree. The artifact syntax is defined by
indvdum@2
   187
     * <code>StrictPatternExcludesArtifactFilter</code>.
indvdum@2
   188
     *
indvdum@2
   189
     * @see StrictPatternExcludesArtifactFilter
indvdum@2
   190
     * @since 2.0-alpha-6
indvdum@2
   191
     *
indvdum@2
   192
     * @parameter expression="${excludes}"
indvdum@2
   193
     */
indvdum@2
   194
    private String excludes;
indvdum@2
   195
indvdum@2
   196
    /**
indvdum@2
   197
     * Runtime Information used to check the Maven version
indvdum@2
   198
     * @since 2.0
indvdum@2
   199
     * @component role="org.apache.maven.execution.RuntimeInformation"
indvdum@2
   200
     */
indvdum@2
   201
    private RuntimeInformation rti;
indvdum@2
   202
indvdum@2
   203
    /**
indvdum@2
   204
     * The computed dependency tree root node of the Maven project.
indvdum@2
   205
     */
indvdum@2
   206
    private DependencyNode rootNode;
indvdum@2
   207
    
indvdum@2
   208
       /**
indvdum@2
   209
        * Whether to append outputs into the output file or overwrite it.
indvdum@2
   210
        * 
indvdum@2
   211
        * @parameter expression="${appendOutput}" default-value="false"
indvdum@2
   212
        * @since 2.2
indvdum@2
   213
        */
indvdum@2
   214
       private boolean appendOutput;
indvdum@2
   215
    
indvdum@2
   216
    // Mojo methods -----------------------------------------------------------
indvdum@2
   217
indvdum@2
   218
    /*
indvdum@2
   219
     * @see org.apache.maven.plugin.Mojo#execute()
indvdum@2
   220
     */
indvdum@2
   221
    public void execute() throws MojoExecutionException, MojoFailureException
indvdum@2
   222
    {
indvdum@2
   223
indvdum@2
   224
        ArtifactVersion detectedMavenVersion = rti.getApplicationVersion();
indvdum@2
   225
        VersionRange vr;
indvdum@2
   226
        try
indvdum@2
   227
        {
indvdum@2
   228
            vr = VersionRange.createFromVersionSpec( "[2.0.8,)" );
indvdum@2
   229
            if ( !containsVersion( vr, detectedMavenVersion ) )
indvdum@2
   230
            {
indvdum@2
   231
                getLog().warn(
indvdum@2
   232
                               "The tree mojo requires at least Maven 2.0.8 to function properly. You may get eroneous results on earlier versions" );
indvdum@2
   233
            }
indvdum@2
   234
        }
indvdum@2
   235
        catch ( InvalidVersionSpecificationException e )
indvdum@2
   236
        {
indvdum@2
   237
            throw new MojoExecutionException( e.getLocalizedMessage() );
indvdum@2
   238
        }
indvdum@2
   239
indvdum@2
   240
indvdum@2
   241
        if ( output != null )
indvdum@2
   242
        {
indvdum@2
   243
            getLog().warn( "The parameter output is deprecated. Use outputFile instead." );
indvdum@2
   244
            this.outputFile = output;
indvdum@2
   245
        }
indvdum@2
   246
indvdum@2
   247
        ArtifactFilter artifactFilter = createResolvingArtifactFilter();
indvdum@2
   248
indvdum@2
   249
        try
indvdum@2
   250
        {
indvdum@2
   251
            // TODO: note that filter does not get applied due to MNG-3236
indvdum@2
   252
indvdum@2
   253
            rootNode =
indvdum@2
   254
                dependencyTreeBuilder.buildDependencyTree( project, localRepository, artifactFactory,
indvdum@2
   255
                                                           artifactMetadataSource, artifactFilter, artifactCollector );
indvdum@2
   256
indvdum@2
   257
            String dependencyTreeString = serializeDependencyTree( rootNode );
indvdum@2
   258
indvdum@2
   259
            if ( outputFile != null )
indvdum@2
   260
            {
indvdum@2
   261
                DependencyUtil.write( dependencyTreeString, outputFile, this.appendOutput ,getLog() );
indvdum@2
   262
indvdum@2
   263
                getLog().info( "Wrote dependency tree to: " + outputFile );
indvdum@2
   264
            }
indvdum@2
   265
            else
indvdum@2
   266
            {
indvdum@2
   267
                DependencyUtil.log( dependencyTreeString, getLog() );
indvdum@2
   268
            }
indvdum@2
   269
        }
indvdum@2
   270
        catch ( DependencyTreeBuilderException exception )
indvdum@2
   271
        {
indvdum@2
   272
            throw new MojoExecutionException( "Cannot build project dependency tree", exception );
indvdum@2
   273
        }
indvdum@2
   274
        catch ( IOException exception )
indvdum@2
   275
        {
indvdum@2
   276
            throw new MojoExecutionException( "Cannot serialise project dependency tree", exception );
indvdum@2
   277
        }
indvdum@2
   278
    }
indvdum@2
   279
indvdum@2
   280
    // public methods ---------------------------------------------------------
indvdum@2
   281
indvdum@2
   282
    /**
indvdum@2
   283
     * Gets the Maven project used by this mojo.
indvdum@2
   284
     *
indvdum@2
   285
     * @return the Maven project
indvdum@2
   286
     */
indvdum@2
   287
    public MavenProject getProject()
indvdum@2
   288
    {
indvdum@2
   289
        return project;
indvdum@2
   290
    }
indvdum@2
   291
indvdum@2
   292
    /**
indvdum@2
   293
     * Gets the computed dependency tree root node for the Maven project.
indvdum@2
   294
     *
indvdum@2
   295
     * @return the dependency tree root node
indvdum@2
   296
     */
indvdum@2
   297
    public DependencyNode getDependencyTree()
indvdum@2
   298
    {
indvdum@2
   299
        return rootNode;
indvdum@2
   300
    }
indvdum@2
   301
indvdum@2
   302
    // private methods --------------------------------------------------------
indvdum@2
   303
indvdum@2
   304
    /**
indvdum@2
   305
     * Gets the artifact filter to use when resolving the dependency tree.
indvdum@2
   306
     *
indvdum@2
   307
     * @return the artifact filter
indvdum@2
   308
     */
indvdum@2
   309
    private ArtifactFilter createResolvingArtifactFilter()
indvdum@2
   310
    {
indvdum@2
   311
        ArtifactFilter filter;
indvdum@2
   312
indvdum@2
   313
        // filter scope
indvdum@2
   314
        if ( scope != null )
indvdum@2
   315
        {
indvdum@2
   316
            getLog().debug( "+ Resolving dependency tree for scope '" + scope + "'" );
indvdum@2
   317
indvdum@2
   318
            filter = new ScopeArtifactFilter( scope );
indvdum@2
   319
        }
indvdum@2
   320
        else
indvdum@2
   321
        {
indvdum@2
   322
            filter = null;
indvdum@2
   323
        }
indvdum@2
   324
indvdum@2
   325
        return filter;
indvdum@2
   326
    }
indvdum@2
   327
indvdum@2
   328
    /**
indvdum@2
   329
     * Serializes the specified dependency tree to a string.
indvdum@2
   330
     *
indvdum@2
   331
     * @param rootNode
indvdum@2
   332
     *            the dependency tree root node to serialize
indvdum@2
   333
     * @return the serialized dependency tree
indvdum@2
   334
     */
indvdum@2
   335
    private String serializeDependencyTree( DependencyNode rootNode )
indvdum@2
   336
    {
indvdum@2
   337
        StringWriter writer = new StringWriter();
indvdum@2
   338
indvdum@2
   339
        DependencyNodeVisitor visitor = getSerializingDependencyNodeVisitor( writer );
indvdum@2
   340
indvdum@2
   341
        // TODO: remove the need for this when the serializer can calculate last nodes from visitor calls only
indvdum@2
   342
        visitor = new BuildingDependencyNodeVisitor( visitor );
indvdum@2
   343
indvdum@2
   344
        DependencyNodeFilter filter = createDependencyNodeFilter();
indvdum@2
   345
indvdum@2
   346
        if ( filter != null )
indvdum@2
   347
        {
indvdum@2
   348
            CollectingDependencyNodeVisitor collectingVisitor = new CollectingDependencyNodeVisitor();
indvdum@2
   349
            DependencyNodeVisitor firstPassVisitor = new FilteringDependencyNodeVisitor( collectingVisitor, filter );
indvdum@2
   350
            rootNode.accept( firstPassVisitor );
indvdum@2
   351
indvdum@2
   352
            DependencyNodeFilter secondPassFilter = new AncestorOrSelfDependencyNodeFilter( collectingVisitor.getNodes() );
indvdum@2
   353
            visitor = new FilteringDependencyNodeVisitor( visitor, secondPassFilter );
indvdum@2
   354
        }
indvdum@2
   355
indvdum@2
   356
        rootNode.accept( visitor );
indvdum@2
   357
indvdum@2
   358
        return writer.toString();
indvdum@2
   359
    }
indvdum@2
   360
indvdum@2
   361
    public DependencyNodeVisitor getSerializingDependencyNodeVisitor( Writer writer )
indvdum@2
   362
    {
indvdum@2
   363
        if ( "graphml".equals( outputType ) )
indvdum@2
   364
        {
indvdum@2
   365
            return new GraphmlDependencyNodeVisitor( writer );
indvdum@2
   366
        }
indvdum@2
   367
        else if ( "tgf".equals( outputType ) )
indvdum@2
   368
        {
indvdum@2
   369
            return new TGFDependencyNodeVisitor( writer );
indvdum@2
   370
        }
indvdum@2
   371
        else if ( "dot".equals( outputType ) )
indvdum@2
   372
        {
indvdum@2
   373
            return new DOTDependencyNodeVisitor( writer ) ;
indvdum@2
   374
        }
indvdum@2
   375
        else
indvdum@2
   376
        {
indvdum@2
   377
            return new SerializingDependencyNodeVisitor( writer, toTreeTokens( tokens ) );
indvdum@2
   378
        }
indvdum@2
   379
    }
indvdum@2
   380
indvdum@2
   381
    /**
indvdum@2
   382
     * Gets the tree tokens instance for the specified name.
indvdum@2
   383
     *
indvdum@2
   384
     * @param tokens
indvdum@2
   385
     *            the tree tokens name
indvdum@2
   386
     * @return the <code>TreeTokens</code> instance
indvdum@2
   387
     */
indvdum@2
   388
    private TreeTokens toTreeTokens( String tokens )
indvdum@2
   389
    {
indvdum@2
   390
        TreeTokens treeTokens;
indvdum@2
   391
indvdum@2
   392
        if ( "whitespace".equals( tokens ) )
indvdum@2
   393
        {
indvdum@2
   394
            getLog().debug( "+ Using whitespace tree tokens" );
indvdum@2
   395
indvdum@2
   396
            treeTokens = SerializingDependencyNodeVisitor.WHITESPACE_TOKENS;
indvdum@2
   397
        }
indvdum@2
   398
        else if ( "extended".equals( tokens ) )
indvdum@2
   399
        {
indvdum@2
   400
            getLog().debug( "+ Using extended tree tokens" );
indvdum@2
   401
indvdum@2
   402
            treeTokens = SerializingDependencyNodeVisitor.EXTENDED_TOKENS;
indvdum@2
   403
        }
indvdum@2
   404
        else
indvdum@2
   405
        {
indvdum@2
   406
            treeTokens = SerializingDependencyNodeVisitor.STANDARD_TOKENS;
indvdum@2
   407
        }
indvdum@2
   408
indvdum@2
   409
        return treeTokens;
indvdum@2
   410
    }
indvdum@2
   411
indvdum@2
   412
    /**
indvdum@2
   413
     * Gets the dependency node filter to use when serializing the dependency tree.
indvdum@2
   414
     *
indvdum@2
   415
     * @return the dependency node filter, or <code>null</code> if none required
indvdum@2
   416
     */
indvdum@2
   417
    private DependencyNodeFilter createDependencyNodeFilter()
indvdum@2
   418
    {
indvdum@2
   419
        List filters = new ArrayList();
indvdum@2
   420
indvdum@2
   421
        // filter node states
indvdum@2
   422
        if ( !verbose )
indvdum@2
   423
        {
indvdum@2
   424
            getLog().debug( "+ Filtering omitted nodes from dependency tree" );
indvdum@2
   425
indvdum@2
   426
            filters.add( StateDependencyNodeFilter.INCLUDED );
indvdum@2
   427
        }
indvdum@2
   428
indvdum@2
   429
        // filter includes
indvdum@2
   430
        if ( includes != null )
indvdum@2
   431
        {
indvdum@2
   432
            List patterns = Arrays.asList( includes.split( "," ) );
indvdum@2
   433
indvdum@2
   434
            getLog().debug( "+ Filtering dependency tree by artifact include patterns: " + patterns );
indvdum@2
   435
indvdum@2
   436
            ArtifactFilter artifactFilter = new StrictPatternIncludesArtifactFilter( patterns );
indvdum@2
   437
            filters.add( new ArtifactDependencyNodeFilter( artifactFilter ) );
indvdum@2
   438
        }
indvdum@2
   439
indvdum@2
   440
        // filter excludes
indvdum@2
   441
        if ( excludes != null )
indvdum@2
   442
        {
indvdum@2
   443
            List patterns = Arrays.asList( excludes.split( "," ) );
indvdum@2
   444
indvdum@2
   445
            getLog().debug( "+ Filtering dependency tree by artifact exclude patterns: " + patterns );
indvdum@2
   446
indvdum@2
   447
            ArtifactFilter artifactFilter = new StrictPatternExcludesArtifactFilter( patterns );
indvdum@2
   448
            filters.add( new ArtifactDependencyNodeFilter( artifactFilter ) );
indvdum@2
   449
        }
indvdum@2
   450
indvdum@2
   451
        return filters.isEmpty() ? null : new AndDependencyNodeFilter( filters );
indvdum@2
   452
    }
indvdum@2
   453
indvdum@2
   454
    //following is required because the version handling in maven code
indvdum@2
   455
    //doesn't work properly. I ripped it out of the enforcer rules.
indvdum@2
   456
indvdum@2
   457
indvdum@2
   458
indvdum@2
   459
    /**
indvdum@2
   460
     * Copied from Artifact.VersionRange. This is tweaked to handle singular ranges properly. Currently the default
indvdum@2
   461
     * containsVersion method assumes a singular version means allow everything. This method assumes that "2.0.4" ==
indvdum@2
   462
     * "[2.0.4,)"
indvdum@2
   463
     *
indvdum@2
   464
     * @param allowedRange range of allowed versions.
indvdum@2
   465
     * @param theVersion the version to be checked.
indvdum@2
   466
     * @return true if the version is contained by the range.
indvdum@2
   467
     */
indvdum@2
   468
    public static boolean containsVersion( VersionRange allowedRange, ArtifactVersion theVersion )
indvdum@2
   469
    {
indvdum@2
   470
        boolean matched = false;
indvdum@2
   471
        ArtifactVersion recommendedVersion = allowedRange.getRecommendedVersion();
indvdum@2
   472
        if ( recommendedVersion == null )
indvdum@2
   473
        {
indvdum@2
   474
indvdum@2
   475
            for ( Iterator i = allowedRange.getRestrictions().iterator(); i.hasNext() && !matched; )
indvdum@2
   476
            {
indvdum@2
   477
                Restriction restriction = (Restriction) i.next();
indvdum@2
   478
                if ( restriction.containsVersion( theVersion ) )
indvdum@2
   479
                {
indvdum@2
   480
                    matched = true;
indvdum@2
   481
                }
indvdum@2
   482
            }
indvdum@2
   483
        }
indvdum@2
   484
        else
indvdum@2
   485
        {
indvdum@2
   486
            // only singular versions ever have a recommendedVersion
indvdum@2
   487
            int compareTo = recommendedVersion.compareTo( theVersion );
indvdum@2
   488
            matched = ( compareTo <= 0 );
indvdum@2
   489
        }
indvdum@2
   490
        return matched;
indvdum@2
   491
    }
indvdum@1
   492
}