View Javadoc
1   package org.apache.maven.plugins.deploy.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 org.apache.maven.artifact.Artifact;
23  import org.apache.maven.artifact.metadata.ArtifactMetadata;
24  import org.apache.maven.artifact.repository.ArtifactRepository;
25  import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
26  import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
27  import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
28  import org.apache.maven.plugin.testing.stubs.StubArtifactRepository;
29  
30  public class ArtifactRepositoryStub
31      extends StubArtifactRepository
32  {
33      private boolean blacklisted;
34      
35      private ArtifactRepositoryLayout layout;
36      
37      private String url;
38      
39      private String basedir = System.getProperty( "basedir" );
40      
41      public ArtifactRepositoryStub()
42      {
43          super( null );
44      }
45      
46      public ArtifactRepositoryStub( String dir )
47      {
48          super( dir );
49      }
50  
51      public String pathOf( Artifact artifact )
52      {
53          return getLayout().pathOf( artifact );
54      }
55      
56      public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata )
57      {
58          return getLayout().pathOfRemoteRepositoryMetadata( artifactMetadata );
59      }
60      
61      public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
62      {
63          return getLayout().pathOfLocalRepositoryMetadata( metadata, repository );
64      }
65      
66      public String getUrl()
67      {
68          return url;
69      }
70      
71      public void setAppendToUrl( String dir )
72      {
73          this.url = "file://" + basedir + "/target/remote-repo/" + dir;
74      }
75      
76      public String getBasedir()
77      {
78          return basedir;
79      }
80      
81      public String getProtocol()
82      {
83          return "file";
84      }
85      
86      public String getId()
87      {
88          return "deploy-test";
89      }
90      
91      public ArtifactRepositoryPolicy getSnapshots()
92      {
93          return new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
94                                               ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
95      }
96      
97      public ArtifactRepositoryPolicy getReleases()
98      {
99          return new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
100                                              ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
101     }
102     
103     public ArtifactRepositoryLayout getLayout()
104     {
105         if( layout != null )
106         {
107             return layout;
108         }
109         else
110         {
111             return new DefaultRepositoryLayout();
112         }
113     }
114     
115     public String getKey()
116     {
117         return getId();
118     }
119 
120     public boolean isUniqueVersion()
121     {
122         return false;
123     }
124    
125     public void setBlacklisted( boolean blackListed )
126     {
127         this.blacklisted = blackListed;
128     }
129 
130     public boolean isBlacklisted()
131     {
132         return blacklisted;
133     }
134 }