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.model;
20
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.types.DataType;
23
24 /**
25 * Represents an enabled/disabled state in a configuration used in Releases and Snapshots sections of a repository
26 * section.
27 */
28 public class Enabled extends DataType {
29
30 private boolean enabled;
31
32 /**
33 * Default constructor.
34 */
35 public Enabled() {}
36
37 /**
38 * Set the value for the enabled state.
39 *
40 * @param enabled the enabled state to set, true for enabled, false for disabled
41 */
42 public void setEnabled(boolean enabled) {
43 this.enabled = enabled;
44 }
45
46 /**
47 * Adds text to the enabled element. The text should be "true" or "false".
48 *
49 * @param text the text to add, which should be either "true" or "false"
50 * @throws BuildException if the text is not valid
51 */
52 public void addText(String text) {
53 String trimmed = getProject().replaceProperties(text).trim();
54 if ("true".equalsIgnoreCase(trimmed)) {
55 this.enabled = true;
56 } else if ("false".equalsIgnoreCase(trimmed)) {
57 this.enabled = false;
58 } else {
59 throw new BuildException("Invalid value for <enabled>: " + text);
60 }
61 }
62
63 /**
64 * Gets the enabled state.
65 *
66 * @return true if enabled, false otherwise
67 */
68 public boolean isEnabled() {
69 return enabled;
70 }
71 }