View Javadoc
1   package org.apache.maven.plugins.dependency.utils.filters;
2   
3   /* 
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.    
20   */
21  /**
22   * 
23   */
24  
25  import java.io.File;
26  import java.io.IOException;
27  import java.util.HashSet;
28  import java.util.Set;
29  
30  import junit.framework.TestCase;
31  
32  import org.apache.commons.io.FileUtils;
33  import org.apache.maven.artifact.Artifact;
34  import org.apache.maven.plugin.MojoExecutionException;
35  import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
36  import org.apache.maven.plugins.dependency.utils.markers.SourcesFileMarkerHandler;
37  import org.apache.maven.plugin.logging.Log;
38  import org.apache.maven.plugin.testing.SilentLog;
39  import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
40  
41  /**
42   * @author brianf
43   */
44  public class TestResolveMarkerFileFilter
45      extends TestCase
46  {
47      Set<Artifact> artifacts = new HashSet<>();
48  
49      Log log = new SilentLog();
50  
51      File outputFolder;
52  
53      DependencyArtifactStubFactory fact;
54  
55      protected void setUp()
56          throws Exception
57      {
58          super.setUp();
59  
60          outputFolder = new File( "target/markers/" );
61          FileUtils.deleteDirectory( outputFolder );
62          assertFalse( outputFolder.exists() );
63  
64          this.fact = new DependencyArtifactStubFactory( outputFolder, false );
65          artifacts = fact.getReleaseAndSnapshotArtifacts();
66      }
67  
68      protected void tearDown()
69          throws IOException
70      {
71          FileUtils.deleteDirectory( outputFolder );
72      }
73  
74      public void testResolveFile()
75          throws IOException, ArtifactFilterException, MojoExecutionException
76      {
77          SourcesFileMarkerHandler handler = new SourcesFileMarkerHandler( outputFolder );
78  
79          Artifact artifact = fact.getReleaseArtifact();
80          handler.setArtifact( artifact );
81  
82          ResolveFileFilter filter = new ResolveFileFilter( handler );
83  
84          assertTrue( filter.isArtifactIncluded( artifact ) );
85          handler.setMarker();
86          assertFalse( filter.isArtifactIncluded( artifact ) );
87      }
88  
89  }