View Javadoc
1   package org.apache.maven.report.projectinfo.stubs;
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  import java.io.File;
23  import java.io.IOException;
24  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.artifact.ArtifactUtils;
27  import org.apache.maven.artifact.versioning.VersionRange;
28  import org.apache.maven.plugin.testing.ArtifactStubFactory;
29  
30  public class DependencyArtifactStubFactory
31      extends ArtifactStubFactory
32  {
33      private boolean flattenedPath = true;
34  
35      public DependencyArtifactStubFactory( File theWorkingDir, boolean theCreateFiles, boolean flattenedPath )
36      {
37          this( theWorkingDir, theCreateFiles );
38          this.flattenedPath = flattenedPath;
39      }
40  
41      public DependencyArtifactStubFactory( File theWorkingDir, boolean theCreateFiles )
42      {
43          super( theWorkingDir, theCreateFiles );
44      }
45  
46      @Override
47      public Artifact createArtifact( String groupId, String artifactId, VersionRange versionRange, String scope,
48                                      String type, String classifier, boolean optional )
49          throws IOException
50      {
51          File workingDir = getWorkingDir();
52  
53          if ( !flattenedPath )
54          {
55              // don't use flatten directories, won't happen at runtime
56              String path = groupId.replace( '.', '/' ) + '/' +
57                      artifactId + '/' +
58                      ArtifactUtils.toSnapshotVersion( versionRange.getRecommendedVersion().toString() );
59              setWorkingDir( new File( workingDir, path ) );
60          }
61  
62          Artifact artifact =
63              super.createArtifact( groupId, artifactId, versionRange, scope, type, classifier, optional );
64  
65          setWorkingDir( workingDir );
66  
67          return artifact;
68      }
69  }