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 java.util.Vector;
23  
24  import org.apache.tools.ant.BuildException;
25  import org.apache.tools.ant.types.DataType;
26  import org.apache.tools.ant.types.Reference;
27  
28  /**
29   * Version Information.
30   *
31   * This information is applied in a platform specific manner
32   * to embed version information into executable images. This
33   * behavior is new and subject to change.
34   *
35   * On the Microsoft Windows platform, a resource is generated and added
36   * to the set of files to be compiled. A resource compiler must
37   * be specified to compile the generated file.
38   *
39   * On Unix platforms, versioninfo is currently not used.
40   * Future versions may append fileversion to the output file name,
41   * use compatibility version for -soname and possibly create
42   * symbolic links.
43   */
44  public final class VersionInfo extends DataType {
45    /**
46     * if property.
47     */
48    private String ifCond;
49    /**
50     * unless property.
51     */
52    private String unlessCond;
53  
54    /**
55     * extends property.
56     */
57    private Reference extendsRef;
58  
59    /**
60     * file version.
61     *
62     */
63    private String fileVersion;
64    /**
65     * Product version.
66     *
67     */
68    private String productVersion;
69    /**
70     * file language.
71     *
72     */
73    private String language;
74  
75    /**
76     * comments.
77     *
78     */
79    private String fileComments;
80    /**
81     * Company name.
82     *
83     */
84    private String companyName;
85    /**
86     * Description.
87     *
88     */
89    private String fileDescription;
90    /**
91     * internal name.
92     */
93    private String internalName;
94    /**
95     * legal copyright.
96     *
97     */
98    private String legalCopyright;
99    /**
100    * legal trademark.
101    *
102    */
103   private String legalTrademarks;
104   /**
105    * original filename.
106    *
107    */
108   private String originalFilename;
109   /**
110    * private build.
111    *
112    */
113   private String privateBuild;
114   /**
115    * product name.
116    *
117    */
118   private String productName;
119   /**
120    * Special build
121    */
122   private String specialBuild;
123   /**
124    * compatibility version
125    *
126    */
127   private String compatibilityVersion;
128 
129   /**
130    * prerease build.
131    *
132    */
133   private Boolean prerelease;
134 
135   /**
136    * prerease build.
137    *
138    */
139   private Boolean patched;
140 
141   /**
142    * Constructor.
143    *
144    */
145   public VersionInfo() {
146   }
147 
148   /**
149    * Private constructor for merge.
150    * 
151    * @param stack
152    *          list of version infos with most significant first.
153    */
154   private VersionInfo(final Vector<VersionInfo> stack) {
155     VersionInfo source = null;
156     for (int i = stack.size() - 1; i >= 0; i--) {
157       source = stack.elementAt(i);
158       if (source.getIf() != null) {
159         this.ifCond = source.getIf();
160       }
161       if (source.getUnless() != null) {
162         this.unlessCond = source.getUnless();
163       }
164       if (source.getFileversion() != null) {
165         this.fileVersion = source.getFileversion();
166       }
167       if (source.getProductversion() != null) {
168         this.productVersion = source.getProductversion();
169       }
170       if (source.getLanguage() != null) {
171         this.language = source.getLanguage();
172       }
173       if (source.getFilecomments() != null) {
174         this.fileComments = source.getFilecomments();
175       }
176       if (source.getCompanyname() != null) {
177         this.companyName = source.getCompanyname();
178       }
179       if (source.getFiledescription() != null) {
180         this.fileDescription = source.getFiledescription();
181       }
182       if (source.getInternalname() != null) {
183         this.internalName = source.getInternalname();
184       }
185       if (source.getLegalcopyright() != null) {
186         this.legalCopyright = source.getLegalcopyright();
187       }
188       if (source.getLegaltrademarks() != null) {
189         this.legalTrademarks = source.getLegaltrademarks();
190       }
191       if (source.getOriginalfilename() != null) {
192         this.originalFilename = source.getOriginalfilename();
193       }
194       if (source.getPrivatebuild() != null) {
195         this.privateBuild = source.getPrivatebuild();
196       }
197       if (source.getProductname() != null) {
198         this.productName = source.getProductname();
199       }
200       if (source.getSpecialbuild() != null) {
201         this.specialBuild = source.getSpecialbuild();
202       }
203       if (source.getCompatibilityversion() != null) {
204         this.compatibilityVersion = source.getCompatibilityversion();
205       }
206       if (source.getPrerelease() != null) {
207         this.prerelease = source.getPrerelease();
208       }
209       if (source.getPatched() != null) {
210         this.patched = source.getPatched();
211       }
212     }
213     setProject(source.getProject());
214   }
215 
216   /**
217    * Methods is required for documentation generation, throws
218    * exception if called.
219    *
220    * @throws org.apache.tools.ant.BuildException
221    *           if called
222    */
223   public void execute() throws org.apache.tools.ant.BuildException {
224     throw new org.apache.tools.ant.BuildException("Not an actual task, but looks like one for documentation purposes");
225   }
226 
227   /**
228    * Gets Company name.
229    * 
230    * @return company name, may be null.
231    */
232   public String getCompanyname() {
233     return this.companyName;
234   }
235 
236   /**
237    * Gets compatibility version.
238    * 
239    * @return compatibility version, may be null
240    */
241   public String getCompatibilityversion() {
242     return this.compatibilityVersion;
243   }
244 
245   public Reference getExtends() {
246     return this.extendsRef;
247   }
248 
249   /**
250    * Gets comments.
251    * 
252    * @return comments, may be null.
253    */
254   public String getFilecomments() {
255     return this.fileComments;
256   }
257 
258   /**
259    * Gets Description.
260    * 
261    * @return description, may be null.
262    */
263   public String getFiledescription() {
264     return this.fileDescription;
265   }
266 
267   /**
268    * Gets file version.
269    * 
270    * @return file version, may be null.
271    *
272    */
273   public String getFileversion() {
274     return this.fileVersion;
275   }
276 
277   /**
278    * Gets if property name.
279    * 
280    * @return property name, may be null.
281    */
282   public final String getIf() {
283     return this.ifCond;
284   }
285 
286   /**
287    * Gets internal name.
288    * 
289    * @return internal name, may be null.
290    */
291   public String getInternalname() {
292     return this.internalName;
293   }
294 
295   /**
296    * Gets file language, should be an IETF RFC 3066 identifier, for example,
297    * en-US.
298    * 
299    * @return language, may be null.
300    */
301   public String getLanguage() {
302     return this.language;
303   }
304 
305   /**
306    * Gets legal copyright.
307    * 
308    * @return legal copyright, may be null.
309    */
310   public String getLegalcopyright() {
311     return this.legalCopyright;
312   }
313 
314   /**
315    * Gets legal trademark.
316    * 
317    * @return legal trademark, may be null;
318    */
319   public String getLegaltrademarks() {
320     return this.legalTrademarks;
321   }
322 
323   /**
324    * Gets original filename.
325    * 
326    * @return original filename, may be null.
327    */
328   public String getOriginalfilename() {
329     return this.originalFilename;
330   }
331 
332   /**
333    * Gets patched.
334    * 
335    * @return patched, may be null.
336    */
337   public Boolean getPatched() {
338     return this.patched;
339   }
340 
341   /**
342    * Gets prerelease.
343    * 
344    * @return prerelease, may be null.
345    */
346   public Boolean getPrerelease() {
347     return this.prerelease;
348   }
349 
350   /**
351    * Gets private build.
352    * 
353    * @return private build, may be null.
354    */
355   public String getPrivatebuild() {
356     return this.privateBuild;
357   }
358 
359   /**
360    * Gets product name.
361    * 
362    * @return product name, may be null.
363    */
364   public String getProductname() {
365     return this.productName;
366   }
367 
368   /**
369    * Gets Product version.
370    * 
371    * @return product version, may be null
372    */
373   public String getProductversion() {
374     return this.productVersion;
375   }
376 
377   /**
378    * Special build
379    * 
380    * @return special build, may be null.
381    */
382   public String getSpecialbuild() {
383     return this.specialBuild;
384   }
385 
386   /**
387    * Gets if property name.
388    * 
389    * @return property name, may be null.
390    */
391   public final String getUnless() {
392     return this.unlessCond;
393   }
394 
395   /**
396    * Returns true if the define's if and unless conditions (if any) are
397    * satisfied.
398    *
399    * @exception BuildException
400    *              throws build exception if name is not set
401    */
402   public final boolean isActive() throws BuildException {
403     return CUtil.isActive(getProject(), this.ifCond, this.unlessCond);
404   }
405 
406   /**
407    * Returns a VersionInfo that reflects any inherited version information.
408    * 
409    * @return merged version information.
410    *         \
411    */
412   public VersionInfo merge() {
413     if (isReference()) {
414       final VersionInfo refVersion = (VersionInfo) getCheckedRef(VersionInfo.class, "VersionInfo");
415       return refVersion.merge();
416     }
417     Reference currentRef = this.getExtends();
418     if (currentRef == null) {
419       return this;
420     }
421     final Vector<VersionInfo> stack = new Vector<>(5);
422     stack.addElement(this);
423     while (currentRef != null) {
424       final Object obj = currentRef.getReferencedObject(getProject());
425       if (obj instanceof VersionInfo) {
426         VersionInfo current = (VersionInfo) obj;
427         if (current.isReference()) {
428           current = (VersionInfo) current.getCheckedRef(VersionInfo.class, "VersionInfo");
429         }
430         if (stack.contains(current)) {
431           throw this.circularReference();
432         }
433         stack.addElement(current);
434         currentRef = current.getExtends();
435       } else {
436         throw new BuildException("Referenced element " + currentRef.getRefId() + " is not a versioninfo.");
437       }
438     }
439     return new VersionInfo(stack);
440   }
441 
442   /**
443    * Sets company name.
444    * 
445    * @param value
446    *          new value
447    * @throws BuildException
448    *           if specified with refid
449    */
450   public void setCompanyname(final String value) throws BuildException {
451     if (isReference()) {
452       throw tooManyAttributes();
453     }
454     this.companyName = value;
455   }
456 
457   /**
458    * Sets compatibility version.
459    * 
460    * @param value
461    *          new value
462    * @throws BuildException
463    *           if specified with refid
464    */
465   public void setCompatibilityversion(final String value) throws BuildException {
466     if (isReference()) {
467       throw tooManyAttributes();
468     }
469     this.compatibilityVersion = value;
470   }
471 
472   /**
473    * Specifies that this element extends the element with id attribute with a
474    * matching value. The configuration will be constructed from the settings
475    * of this element, element referenced by extends, and the containing cc
476    * element.
477    *
478    * @param extendsRef
479    *          Reference to the extended processor definition.
480    * @throws BuildException
481    *           if this processor definition is a reference
482    */
483   public void setExtends(final Reference extendsRef) throws BuildException {
484     if (isReference()) {
485       throw tooManyAttributes();
486     }
487     this.extendsRef = extendsRef;
488   }
489 
490   /**
491    * Sets comments.
492    * 
493    * @param value
494    *          new value
495    * @throws BuildException
496    *           if specified with refid
497    */
498   public void setFilecomments(final String value) throws BuildException {
499     if (isReference()) {
500       throw tooManyAttributes();
501     }
502     this.fileComments = value;
503   }
504 
505   /**
506    * Sets file description.
507    * 
508    * @param value
509    *          new value
510    */
511   public void setFiledescription(final String value) {
512     if (isReference()) {
513       throw tooManyAttributes();
514     }
515     this.fileDescription = value;
516   }
517 
518   /**
519    * Sets file version.
520    * 
521    * @param value
522    *          new value
523    * @throws BuildException
524    *           if specified with refid
525    */
526   public void setFileversion(final String value) throws BuildException {
527     if (isReference()) {
528       throw tooManyAttributes();
529     }
530     this.fileVersion = value;
531   }
532 
533   /**
534    * Sets an id that can be used to reference this element.
535    *
536    * @param id
537    *          id
538    */
539   public void setId(final String id) {
540     //
541     // this is actually accomplished by a different
542     // mechanism, but we can document it
543     //
544   }
545 
546   /**
547    * Sets the property name for the 'if' condition.
548    *
549    * The define will be ignored unless the property is defined.
550    *
551    * The value of the property is insignificant, but values that would imply
552    * misinterpretation ("false", "no") will throw an exception when
553    * evaluated.
554    *
555    * @param propName
556    *          property name
557    */
558   public final void setIf(final String propName) {
559     if (isReference()) {
560       throw tooManyAttributes();
561     }
562     this.ifCond = propName;
563   }
564 
565   /**
566    * Sets internal name. Internal name will automatically be
567    * specified from build step, only set this value if
568    * intentionally overriding that value.
569    *
570    * @param value
571    *          new value
572    * @throws BuildException
573    *           if specified with refid
574    */
575   public void setInternalname(final String value) throws BuildException {
576     if (isReference()) {
577       throw tooManyAttributes();
578     }
579     this.internalName = value;
580   }
581 
582   /**
583    * Sets language.
584    * 
585    * @param value
586    *          new value, should be an IETF RFC 3066 language identifier.
587    * @throws BuildException
588    *           if specified with refid
589    */
590   public void setLanguage(final String value) throws BuildException {
591     if (isReference()) {
592       throw tooManyAttributes();
593     }
594     this.language = value;
595   }
596 
597   /**
598    * Sets legal copyright.
599    * 
600    * @param value
601    *          new value
602    * @throws BuildException
603    *           if specified with refid
604    */
605   public void setLegalcopyright(final String value) throws BuildException {
606     if (isReference()) {
607       throw tooManyAttributes();
608     }
609     this.legalCopyright = value;
610   }
611 
612   /**
613    * Sets legal trademark.
614    * 
615    * @param value
616    *          new value
617    * @throws BuildException
618    *           if specified with refid
619    */
620   public void setLegaltrademarks(final String value) throws BuildException {
621     if (isReference()) {
622       throw tooManyAttributes();
623     }
624     this.legalTrademarks = value;
625   }
626 
627   /**
628    * Sets original name. Only set this value if
629    * intentionally overriding the value from the build set.
630    *
631    * @param value
632    *          new value
633    * @throws BuildException
634    *           if specified with refid
635    */
636   public void setOriginalfilename(final String value) throws BuildException {
637     if (isReference()) {
638       throw tooManyAttributes();
639     }
640     this.originalFilename = value;
641   }
642 
643   /**
644    * Sets prerelease.
645    * 
646    * @param value
647    *          new value
648    * @throws BuildException
649    *           if specified with refid
650    */
651   public void setPatched(final boolean value) throws BuildException {
652     if (isReference()) {
653       throw tooManyAttributes();
654     }
655     if (value) {
656       this.patched = Boolean.TRUE;
657     } else {
658       this.patched = Boolean.FALSE;
659     }
660   }
661 
662   /**
663    * Sets prerelease.
664    * 
665    * @param value
666    *          new value
667    * @throws BuildException
668    *           if specified with refid
669    */
670   public void setPrerelease(final boolean value) throws BuildException {
671     if (isReference()) {
672       throw tooManyAttributes();
673     }
674     if (value) {
675       this.prerelease = Boolean.TRUE;
676     } else {
677       this.prerelease = Boolean.FALSE;
678     }
679   }
680 
681   /**
682    * Sets private build.
683    * 
684    * @param value
685    *          new value
686    * @throws BuildException
687    *           if specified with refid
688    */
689   public void setPrivatebuild(final String value) throws BuildException {
690     if (isReference()) {
691       throw tooManyAttributes();
692     }
693     this.privateBuild = value;
694   }
695 
696   /**
697    * Sets product name.
698    * 
699    * @param value
700    *          new value
701    * @throws BuildException
702    *           if specified with refid
703    */
704   public void setProductname(final String value) throws BuildException {
705     if (isReference()) {
706       throw tooManyAttributes();
707     }
708     this.productName = value;
709   }
710 
711   /**
712    * Sets product version.
713    * 
714    * @param value
715    *          new value
716    * @throws BuildException
717    *           if specified with refid
718    */
719   public void setProductversion(final String value) throws BuildException {
720     if (isReference()) {
721       throw tooManyAttributes();
722     }
723     this.productVersion = value;
724   }
725 
726   /**
727    * Specifies that this element should behave as if the content of the
728    * element with the matching id attribute was inserted at this location. If
729    * specified, no other attributes should be specified.
730    *
731    */
732   @Override
733   public void setRefid(final Reference r) throws BuildException {
734     super.setRefid(r);
735   }
736 
737   /**
738    * Sets private build.
739    * 
740    * @param value
741    *          new value
742    * @throws BuildException
743    *           if specified with refid
744    */
745   public void setSpecialbuild(final String value) throws BuildException {
746     if (isReference()) {
747       throw tooManyAttributes();
748     }
749     this.specialBuild = value;
750   }
751 
752   /**
753    * Set the property name for the 'unless' condition.
754    *
755    * If named property is set, the define will be ignored.
756    *
757    * The value of the property is insignificant, but values that would imply
758    * misinterpretation ("false", "no") of the behavior will throw an
759    * exception when evaluated.
760    *
761    * @param propName
762    *          name of property
763    */
764   public final void setUnless(final String propName) {
765     if (isReference()) {
766       throw tooManyAttributes();
767     }
768     this.unlessCond = propName;
769   }
770 }