View Javadoc
1   package org.apache.maven.resolver.internal.ant.types;
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.resolver.internal.ant.AntRepoSys;
23  import org.apache.tools.ant.BuildException;
24  import org.apache.tools.ant.Project;
25  import org.apache.tools.ant.types.DataType;
26  import org.apache.tools.ant.types.Reference;
27  
28  /**
29   */
30  public class Mirror
31      extends DataType
32  {
33  
34      private String id;
35  
36      private String url;
37  
38      private String type;
39  
40      private String mirrorOf;
41  
42      private Authentication authentication;
43  
44      @Override
45      public void setProject( Project project )
46      {
47          super.setProject( project );
48  
49          AntRepoSys.getInstance( project ).addMirror( this );
50      }
51  
52      protected Mirror getRef()
53      {
54          return (Mirror) getCheckedRef();
55      }
56  
57      public void setRefid( Reference ref )
58      {
59          if ( id != null || url != null || mirrorOf != null || type != null )
60          {
61              throw tooManyAttributes();
62          }
63          super.setRefid( ref );
64      }
65  
66      public String getId()
67      {
68          if ( isReference() )
69          {
70              return getRef().getId();
71          }
72          return id;
73      }
74  
75      public void setId( String id )
76      {
77          this.id = id;
78      }
79  
80      public String getUrl()
81      {
82          if ( isReference() )
83          {
84              return getRef().getUrl();
85          }
86          return url;
87      }
88  
89      public void setUrl( String url )
90      {
91          checkAttributesAllowed();
92          this.url = url;
93      }
94  
95      public String getType()
96      {
97          if ( isReference() )
98          {
99              return getRef().getType();
100         }
101         return ( type != null ) ? type : "default";
102     }
103 
104     public void setType( String type )
105     {
106         checkAttributesAllowed();
107         this.type = type;
108     }
109 
110     public String getMirrorOf()
111     {
112         if ( isReference() )
113         {
114             return getRef().getMirrorOf();
115         }
116         return mirrorOf;
117     }
118 
119     public void setMirrorOf( String mirrorOf )
120     {
121         checkAttributesAllowed();
122         this.mirrorOf = mirrorOf;
123     }
124 
125     public void addAuthentication( Authentication authentication )
126     {
127         checkChildrenAllowed();
128         if ( this.authentication != null )
129         {
130             throw new BuildException( "You must not specify multiple <authentication> elements" );
131         }
132         this.authentication = authentication;
133     }
134 
135     public Authentication getAuthentication()
136     {
137         if ( isReference() )
138         {
139             getRef().getAuthentication();
140         }
141         return authentication;
142     }
143 
144     public void setAuthRef( Reference ref )
145     {
146         if ( authentication == null )
147         {
148             authentication = new Authentication();
149             authentication.setProject( getProject() );
150         }
151         authentication.setRefid( ref );
152     }
153 
154 }