View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.resolver.internal.ant.types;
20  
21  import org.apache.maven.resolver.internal.ant.AntRepoSys;
22  import org.apache.tools.ant.BuildException;
23  import org.apache.tools.ant.Project;
24  import org.apache.tools.ant.types.DataType;
25  import org.apache.tools.ant.types.Reference;
26  
27  /**
28   */
29  public class Mirror extends DataType {
30  
31      private String id;
32  
33      private String url;
34  
35      private String type;
36  
37      private String mirrorOf;
38  
39      private Authentication authentication;
40  
41      @Override
42      public void setProject(Project project) {
43          super.setProject(project);
44  
45          AntRepoSys.getInstance(project).addMirror(this);
46      }
47  
48      protected Mirror getRef() {
49          return (Mirror) getCheckedRef();
50      }
51  
52      public void setRefid(Reference ref) {
53          if (id != null || url != null || mirrorOf != null || type != null) {
54              throw tooManyAttributes();
55          }
56          super.setRefid(ref);
57      }
58  
59      public String getId() {
60          if (isReference()) {
61              return getRef().getId();
62          }
63          return id;
64      }
65  
66      public void setId(String id) {
67          this.id = id;
68      }
69  
70      public String getUrl() {
71          if (isReference()) {
72              return getRef().getUrl();
73          }
74          return url;
75      }
76  
77      public void setUrl(String url) {
78          checkAttributesAllowed();
79          this.url = url;
80      }
81  
82      public String getType() {
83          if (isReference()) {
84              return getRef().getType();
85          }
86          return (type != null) ? type : "default";
87      }
88  
89      public void setType(String type) {
90          checkAttributesAllowed();
91          this.type = type;
92      }
93  
94      public String getMirrorOf() {
95          if (isReference()) {
96              return getRef().getMirrorOf();
97          }
98          return mirrorOf;
99      }
100 
101     public void setMirrorOf(String mirrorOf) {
102         checkAttributesAllowed();
103         this.mirrorOf = mirrorOf;
104     }
105 
106     public void addAuthentication(Authentication authentication) {
107         checkChildrenAllowed();
108         if (this.authentication != null) {
109             throw new BuildException("You must not specify multiple <authentication> elements");
110         }
111         this.authentication = authentication;
112     }
113 
114     public Authentication getAuthentication() {
115         if (isReference()) {
116             getRef().getAuthentication();
117         }
118         return authentication;
119     }
120 
121     public void setAuthRef(Reference ref) {
122         if (authentication == null) {
123             authentication = new Authentication();
124             authentication.setProject(getProject());
125         }
126         authentication.setRefid(ref);
127     }
128 }