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 getCheckedRef(Mirror.class);
50      }
51  
52      @Override
53      public void setRefid(Reference ref) {
54          if (id != null || url != null || mirrorOf != null || type != null) {
55              throw tooManyAttributes();
56          }
57          super.setRefid(ref);
58      }
59  
60      public String getId() {
61          if (isReference()) {
62              return getRef().getId();
63          }
64          return id;
65      }
66  
67      public void setId(String id) {
68          this.id = id;
69      }
70  
71      public String getUrl() {
72          if (isReference()) {
73              return getRef().getUrl();
74          }
75          return url;
76      }
77  
78      public void setUrl(String url) {
79          checkAttributesAllowed();
80          this.url = url;
81      }
82  
83      public String getType() {
84          if (isReference()) {
85              return getRef().getType();
86          }
87          return (type != null) ? type : "default";
88      }
89  
90      public void setType(String type) {
91          checkAttributesAllowed();
92          this.type = type;
93      }
94  
95      public String getMirrorOf() {
96          if (isReference()) {
97              return getRef().getMirrorOf();
98          }
99          return mirrorOf;
100     }
101 
102     public void setMirrorOf(String mirrorOf) {
103         checkAttributesAllowed();
104         this.mirrorOf = mirrorOf;
105     }
106 
107     public void addAuthentication(Authentication authentication) {
108         checkChildrenAllowed();
109         if (this.authentication != null) {
110             throw new BuildException("You must not specify multiple <authentication> elements");
111         }
112         this.authentication = authentication;
113     }
114 
115     public Authentication getAuthentication() {
116         if (isReference()) {
117             getRef().getAuthentication();
118         }
119         return authentication;
120     }
121 
122     public void setAuthRef(Reference ref) {
123         if (authentication == null) {
124             authentication = new Authentication();
125             authentication.setProject(getProject());
126         }
127         authentication.setRefid(ref);
128     }
129 }