View Javadoc

1   /*
2    * #%L
3    * Native ARchive plugin for Maven
4    * %%
5    * Copyright (C) 2002 - 2014 NAR Maven Plugin developers.
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   * http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package com.github.maven_nar.cpptasks;
21  
22  import org.apache.tools.ant.types.DataType;
23  import org.apache.tools.ant.types.Reference;
24  
25  /**
26   * Information on the execution platforms for the generated code.
27   * (Non-functional prototype)
28   *
29   */
30  public final class TargetDef extends DataType {
31    /**
32     * if property.
33     */
34    private String ifCond;
35  
36    /**
37     * unless property.
38     */
39    private String unlessCond;
40  
41    /**
42     * cpu.
43     *
44     */
45    private CPUEnum cpu;
46  
47    /**
48     * architecture.
49     *
50     */
51    private ArchEnum arch;
52  
53    /**
54     * OS Family.
55     *
56     */
57    private OSFamilyEnum osFamily;
58  
59    /**
60     * Constructor.
61     *
62     */
63    public TargetDef() {
64    }
65  
66    /**
67     * Bogus method required for documentation generation.
68     */
69    public void execute() {
70      throw new org.apache.tools.ant.BuildException("Not an actual task, but looks like one for documentation purposes");
71    }
72  
73    /**
74     * Gets arch.
75     * 
76     * @return arch, may be null.
77     *
78     */
79    public ArchEnum getArch() {
80      if (isReference()) {
81        final TargetDef refPlatform = (TargetDef) getCheckedRef(TargetDef.class, "TargetDef");
82        return refPlatform.getArch();
83      }
84      return this.arch;
85    }
86  
87    /**
88     * Gets cpu.
89     * 
90     * @return cpu, may be null.
91     *
92     */
93    public CPUEnum getCpu() {
94      if (isReference()) {
95        final TargetDef refPlatform = (TargetDef) getCheckedRef(TargetDef.class, "TargetDef");
96        return refPlatform.getCpu();
97      }
98      return this.cpu;
99    }
100 
101   /**
102    * Gets operating system family.
103    * 
104    * @return os family, may be null.
105    *
106    */
107   public OSFamilyEnum getOsfamily() {
108     if (isReference()) {
109       final TargetDef refPlatform = (TargetDef) getCheckedRef(TargetDef.class, "TargetDef");
110       return refPlatform.getOsfamily();
111     }
112     return this.osFamily;
113   }
114 
115   /**
116    * Returns true if the define's if and unless conditions (if any) are
117    * satisfied.
118    * 
119    * @return true if active
120    */
121   public boolean isActive() {
122     return CUtil.isActive(getProject(), this.ifCond, this.unlessCond);
123   }
124 
125   /**
126    * Sets cpu architecture, compiler may use cpu specific instructions.
127    * 
128    * @param value
129    *          new value
130    */
131   public void setArch(final ArchEnum value) {
132     if (isReference()) {
133       throw tooManyAttributes();
134     }
135     if (this.cpu != null) {
136       throw tooManyAttributes();
137     }
138     this.arch = value;
139   }
140 
141   /**
142    * Sets preferred cpu, but does not use cpu specific instructions.
143    * 
144    * @param value
145    *          new value
146    */
147   public void setCpu(final CPUEnum value) {
148     if (isReference()) {
149       throw tooManyAttributes();
150     }
151     this.cpu = value;
152   }
153 
154   /**
155    * Sets a description of the current data type.
156    * 
157    * @param desc
158    *          description
159    */
160   @Override
161   public void setDescription(final String desc) {
162     super.setDescription(desc);
163   }
164 
165   /**
166    * Sets an id that can be used to reference this element.
167    *
168    * @param id
169    *          id
170    */
171   public void setId(final String id) {
172     //
173     // this is actually accomplished by a different
174     // mechanism, but we can document it
175     //
176   }
177 
178   /**
179    * Sets the property name for the 'if' condition.
180    *
181    * The define will be ignored unless the property is defined.
182    *
183    * The value of the property is insignificant, but values that would imply
184    * misinterpretation ("false", "no") will throw an exception when
185    * evaluated.
186    *
187    * @param propName
188    *          property name
189    */
190   public void setIf(final String propName) {
191     this.ifCond = propName;
192   }
193 
194   /**
195    * Sets operating system family.
196    * 
197    * @param value
198    *          new value
199    */
200   public void setOsfamily(final OSFamilyEnum value) {
201     if (isReference()) {
202       throw tooManyAttributes();
203     }
204     if (this.cpu != null) {
205       throw tooManyAttributes();
206     }
207     this.osFamily = value;
208   }
209 
210   /**
211    * Specifies that this element should behave as if the content of the
212    * element with the matching id attribute was inserted at this location. If
213    * specified, no other attributes should be specified.
214    * 
215    * @param r
216    *          id of referenced target
217    */
218   @Override
219   public void setRefid(final Reference r) {
220     super.setRefid(r);
221   }
222 
223   /**
224    * Set the property name for the 'unless' condition.
225    *
226    * If named property is set, the define will be ignored.
227    *
228    * The value of the property is insignificant, but values that would imply
229    * misinterpretation ("false", "no") of the behavior will throw an
230    * exception when evaluated.
231    *
232    * @param propName
233    *          name of property
234    */
235   public void setUnless(final String propName) {
236     this.unlessCond = propName;
237   }
238 
239 }