aboutsummaryrefslogtreecommitdiffstats
path: root/docs/apex/APEX-Developer-Guide.rst
blob: b247ab83c97f627cffb3d6501229d598b113864c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
.. This work is licensed under a Creative Commons Attribution 4.0 International License.
.. http://creativecommons.org/licenses/by/4.0


APEX Developer Guide
********************

.. contents::
    :depth: 3

Build APEX from Source
^^^^^^^^^^^^^^^^^^^^^^

Introduction to building APEX
-----------------------------

            .. container:: paragraph

               APEX is written 100% in Java and uses `Apache
               Maven <https://maven.apache.org/>`__ as the build system.
               The requirements for building APEX are:

            .. container:: ulist

               -  An installed Java development kit for Java version 8
                  or higher

                  .. container:: ulist

                     -  To install a Java SDK please follow these
                        guidelines `Oracle Java 8
                        SDK <https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html>`__.

               -  Maven 3

                  .. container:: ulist

                     -  To get Maven 3 running please follow the
                        guidelines for
                        `Download <https://maven.apache.org/download.cgi>`__
                        and
                        `Install <https://maven.apache.org/install.html>`__,
                        and `Run <https://maven.apache.org/run.html>`__
                        Maven

               -  A clone of the APEX source repositories

            .. container:: paragraph

               To get a clone of the APEX source repositories, please
               see the APEX Installation Guide or the APEX User manual.

            .. container:: paragraph

               Once all requirements are in place, APEX can be build.
               There are several different artifacts one can create
               building APEX, most of them defined in their own
               *profile*. APEX can also be built in a standard way with
               standard tests (``mvn clean install``) or without
               standard tests (``mvn clean install -DskipTests``).

            .. container:: paragraph

               The examples in this document assume that the APEX source
               repositories are cloned to:

            .. container:: ulist

               -  Unix, Cygwin: ``/usr/local/src/apex``

               -  Windows: ``C:\dev\apex``

               -  Cygwin: ``/cygdrive/c/dev/apex``

            .. important::
               A Build requires ONAP Nexus
               APEX has a dependency to ONAP parent projects. You might need to adjust your Maven M2 settings. The most current
               settings can be found in the ONAP oparent repo: `Settings <https://git.onap.org/oparent/plain/settings.xml>`__.

            .. important::

               A Build needs Space
               Building APEX requires approximately 2-3 GB of hard disc space, 1 GB for the actual build with full
               distribution and 1-2 GB for the downloaded dependencies

            .. important::
               A Build requires Internet (for first build to download all dependencies and plugins)
               During the build, several (a lot) of Maven dependencies will be downloaded and stored in the configured local Maven 
               repository. The first standard build (and any first specific build) requires Internet access to download those
               dependencies.

            .. important::
               Building RPM distributions
               RPM images are only built if the ``rpm`` package is installed (Unix). To install ``rpm``
               run ``sudo apt-get install rpm``, then build APEX.

Standard Build
--------------

            .. container:: paragraph

               Use Maven to for a standard build without any tests.

            +-----------------------------------+------------------------------------+
            | Unix, Cygwin                      | Windows                            |
            +===================================+====================================+
            | ::                                | ::                                 |
            |                                   |                                    |
            |    >c:                            |    # cd /usr/local/src/apex        |
            |    >cd \dev\apex                  |    # mvn clean install -DskipTests |
            |    >mvn clean install -DskipTests |                                    |
            |                                   |                                    |
            +-----------------------------------+------------------------------------+

.. container:: paragraph

   The build takes about 6 minutes on a standard development laptop. It
   should run through without errors, but with a lot of messages from
   the build process.

.. container:: paragraph

   When Maven is finished with the build, the final screen should look
   similar to this (omitting some ``success`` lines):

.. container:: listingblock

   .. code:: bash
     :number-lines:

     [INFO] tools .............................................. SUCCESS [  0.248 s]
     [INFO] tools-common ....................................... SUCCESS [  0.784 s]
     [INFO] simple-wsclient .................................... SUCCESS [  3.303 s]
     [INFO] model-generator .................................... SUCCESS [  0.644 s]
     [INFO] packages ........................................... SUCCESS [  0.336 s]
     [INFO] apex-pdp-package-full .............................. SUCCESS [01:10 min]
     [INFO] Policy APEX PDP - Docker build 2.0.0-SNAPSHOT ...... SUCCESS [ 10.307 s]
     [INFO] ------------------------------------------------------------------------
     [INFO] BUILD SUCCESS
     [INFO] ------------------------------------------------------------------------
     [INFO] Total time: 03:43 min
     [INFO] Finished at: 2018-09-03T11:56:01+01:00
     [INFO] ------------------------------------------------------------------------

.. container:: paragraph

   The build will have created all artifacts required for an APEX
   installation. The following example show how to change to the target
   directory and how it should look.

+-----------------------------------------------------------------------------------------------------------------------------+
| Unix, Cygwin                                                                                                                |
+=============================================================================================================================+
| .. container::                                                                                                              |
|                                                                                                                             |
|    .. container:: listingblock                                                                                              |
|                                                                                                                             |
|          .. code:: bash                                                                                                     |
|            :number-lines:                                                                                                   |
|                                                                                                                             |
|            # cd packages/apex-pdp-package-full/target                                                                       |
|            # ls -l                                                                                                          |
|            -rwxrwx---+ 1 esvevan Domain Users       772 Sep  3 11:55 apex-pdp-package-full_2.0.0~SNAPSHOT_all.changes*      |
|            -rwxrwx---+ 1 esvevan Domain Users 146328082 Sep  3 11:55 apex-pdp-package-full-2.0.0-SNAPSHOT.deb*              |
|            -rwxrwx---+ 1 esvevan Domain Users     15633 Sep  3 11:54 apex-pdp-package-full-2.0.0-SNAPSHOT.jar*              |
|            -rwxrwx---+ 1 esvevan Domain Users 146296819 Sep  3 11:55 apex-pdp-package-full-2.0.0-SNAPSHOT-tarball.tar.gz*   |
|            drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 archive-tmp/                                           |
|            -rwxrwx---+ 1 esvevan Domain Users        89 Sep  3 11:54 checkstyle-cachefile*                                  |
|            -rwxrwx---+ 1 esvevan Domain Users     10621 Sep  3 11:54 checkstyle-checker.xml*                                |
|            -rwxrwx---+ 1 esvevan Domain Users       584 Sep  3 11:54 checkstyle-header.txt*                                 |
|            -rwxrwx---+ 1 esvevan Domain Users        86 Sep  3 11:54 checkstyle-result.xml*                                 |
|            drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 classes/                                               |
|            drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 dependency-maven-plugin-markers/                       |
|            drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 etc/                                                   |
|            drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 examples/                                              |
|            drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:55 install_hierarchy/                                     |
|            drwxrwx---+ 1 esvevan Domain Users         0 Sep  3 11:54 maven-archiver/                                        |
+-----------------------------------------------------------------------------------------------------------------------------+

+-----------------------------------------------------------------------------------------------------------------------------+
| Windows                                                                                                                     |
+=============================================================================================================================+
| .. container::                                                                                                              |
|                                                                                                                             |
|    .. container:: listingblock                                                                                              |
|                                                                                                                             |
|          .. code:: bash                                                                                                     |
|            :number-lines:                                                                                                   |
|                                                                                                                             |
|            >cd packages\apex-pdp-package-full\target                                                                        |
|            >dir                                                                                                             |
|                                                                                                                             |
|            03/09/2018  11:55    <DIR>          .                                                                            |
|            03/09/2018  11:55    <DIR>          ..                                                                           |
|            03/09/2018  11:55       146,296,819 apex-pdp-package-full-2.0.0-SNAPSHOT-tarball.tar.gz                          |
|            03/09/2018  11:55       146,328,082 apex-pdp-package-full-2.0.0-SNAPSHOT.deb                                     |
|            03/09/2018  11:54            15,633 apex-pdp-package-full-2.0.0-SNAPSHOT.jar                                     |
|            03/09/2018  11:55               772 apex-pdp-package-full_2.0.0~SNAPSHOT_all.changes                             |
|            03/09/2018  11:54    <DIR>          archive-tmp                                                                  |
|            03/09/2018  11:54                89 checkstyle-cachefile                                                         |
|            03/09/2018  11:54            10,621 checkstyle-checker.xml                                                       |
|            03/09/2018  11:54               584 checkstyle-header.txt                                                        |
|            03/09/2018  11:54                86 checkstyle-result.xml                                                        |
|            03/09/2018  11:54    <DIR>          classes                                                                      |
|            03/09/2018  11:54    <DIR>          dependency-maven-plugin-markers                                              |
|            03/09/2018  11:54    <DIR>          etc                                                                          |
|            03/09/2018  11:54    <DIR>          examples                                                                     |
|            03/09/2018  11:55    <DIR>          install_hierarchy                                                            |
|            03/09/2018  11:54    <DIR>          maven-archiver                                                               |
|                           8 File(s)    292,652,686 bytes                                                                    |
|                           9 Dir(s)  14,138,720,256 bytes free                                                               |
+-----------------------------------------------------------------------------------------------------------------------------+


Checkstyle with Maven
---------------------

   .. container:: paragraph

      The codestyle for all APEX java projects can be checked
      automatically. The checks include empty or non-existing Javadocs.
      Any checkstyle run should complete without any errors, some
      warnings are acceptable.

   .. container:: paragraph

      To run checkstyle on an APEX Maven project use:

   .. container:: listingblock

      .. container:: content

         .. code:: bash

            mvn checkstyle:check

   .. container:: paragraph

      To run checkstyle on all modules use:

   .. container:: listingblock

      .. container:: content

         .. code:: bash

            mvn checkstyle:checkstyle -DapexAll

Build with standard Tests
-------------------------

   .. container:: paragraph

      Use Maven for a standard build with standard tests.

   .. important::
      Some tests have specific timing Requirements
      Some of the tests have very specific timing requirements. If run on a low-powered build machine, or if the build
      machine is on high load, those tests might fail and the whole build might fail as well. If this happens, reduce the load
      on your build machine and restart the build.

   +-----------------------------------+-----------------------------------+
   | Unix, Cygwin                      | Windows                           |
   +===================================+===================================+
   | .. container::                    | .. container::                    |
   |                                   |                                   |
   |    .. container:: content         |    .. container:: content         |
   |                                   |                                   |
   |       .. code:: bash              |       .. code:: bash              |
   |         :number-lines:            |         :number-lines:            |
   |                                   |                                   |
   |         >c:                       |         # cd /usr/local/src/apex  |
   |         >cd \dev\apex             |         # mvn clean install       |
   |         >mvn clean install        |                                   |
   +-----------------------------------+-----------------------------------+


.. container:: paragraph

   The build takes about 10 minutes with tests on a standard development
   laptop. It should run through without errors, but with a lot of
   messages from the build process. If built with tests (i.e. without
   ``-DskipTests``), there will be error messages and stack trace prints
   from some tests. This is normal, as long as the build finishes
   successfully.

Build with all Tests
--------------------

   .. container:: paragraph

      Use Maven to for a standard build with *all* tests.

   .. important::
      Some tests have specific timing Requirements.
      Some of the tests have very specific timing requirements. If run on a low-powered build machine, or if the build
      machine is on high load, those tests might fail and the whole build might fail as well. If this happens, reduce the load
      on your build machine and restart the build.

   .. important::
      Might require specific software.
      When running all tests, some modules require specific software installed on the build machine. For instance,
      testing the full capabilities of context (with distribution and persistence) will require Hazelcast and Infinispan
      installed on the build machine.

   +----------------------------------------------+----------------------------------------------+
   | Unix, Cygwin                                 | Windows                                      |
   +==============================================+==============================================+
   | .. container::                               | .. container::                               |
   |                                              |                                              |
   |    .. container:: content                    |    .. container:: content                    |
   |                                              |                                              |
   |       .. code:: bash                         |       .. code:: bash                         |
   |         :number-lines:                       |         :number-lines:                       |
   |                                              |                                              |
   |         >c:                                  |         # cd /usr/local/src/apex             |
   |         >cd \dev\apex                        |         # mvn clean install -DallTests       |
   |         >mvn clean install -DallTests        |                                              |
   +----------------------------------------------+----------------------------------------------+

Build with all Components
-------------------------

   .. container:: paragraph

      A standard APEX build will not build all components. Some parts
      are for specific deployments, only. Use Maven for a standard
      build with *all* components.

   .. important::
      Might require specific software.
      When building all components, some modules require specific software to be installed on the build machine.

   +----------------------------------------------+----------------------------------------------+
   | Unix, Cygwin                                 | Windows                                      |
   +==============================================+==============================================+
   | .. container::                               | .. container::                               |
   |                                              |                                              |
   |    .. container:: content                    |    .. container:: content                    |
   |                                              |                                              |
   |       .. code:: bash                         |       .. code:: bash                         |
   |         :number-lines:                       |         :number-lines:                       |
   |                                              |                                              |
   |         >c:                                  |         # cd /usr/local/src/apex             |
   |         >cd \dev\apex                        |         # mvn clean install -DapexAll        |
   |         >mvn clean install -DapexAll         |                                              |
   +----------------------------------------------+----------------------------------------------+


Build the APEX Documentation
----------------------------

   .. container:: paragraph

      The APEX Maven build also includes stand-alone documentation,
      such as the HowTo documents, the Installation Guide, and the User
      Manual. Use Maven to build the APEX Documentation. The Maven
      option ``-N`` prevents Maven from going through all APEX modules,
      which is not necessary for the documentation. The final documents
      will be in ``target/generated-docs`` (Windows:
      ``target\generated-docs``). The *HTML* documents are in the
      ``html/`` folder, the *PDF* documents are in the ``pdf/`` folder.
      Once the documentation is built, copy the *HTML* and *PDF*
      documents to a folder of choice

   +-------------------------------------------------------+--------------------------------------------------------+
   | Unix, Cygwin                                          | Windows                                                |
   +=======================================================+========================================================+
   | .. container::                                        | .. container::                                         |
   |                                                       |                                                        |
   |    .. container:: content                             |    .. container:: content                              |
   |                                                       |                                                        |
   |       .. code:: bash                                  |       .. code:: bash                                   |
   |         :number-lines:                                |         :number-lines:                                 |
   |                                                       |                                                        |
   |         >c:                                           |         # cd /usr/local/src/apex                       |
   |         >cd \dev\apex                                 |         # mvn clean generate-resources -N -DapexDocs   |
   |         >mvn clean generate-resources -N -DapexDocs   |                                                        |
   +-------------------------------------------------------+--------------------------------------------------------+

Build APEX Site
---------------

   .. container:: paragraph

      The APEX Maven build comes with full support to build a web site
      using Maven Site. Use Maven to build the APEX Site. Stage the APEX
      web site. The target folder for the staged site is

   .. container:: ulist

      -  Unix: ``/usr/local/src/apex/target/ad-site``

      -  Windows: ``C:\dev\apex\target\ad-site``

      -  Cygwin: ``/cygdrive/c/dev/apex/target/ad-site``

   .. container:: paragraph

      Once the web site is staged, copy the full site to a folder of
      choice or into a web server.

   .. important::
      Building a Site takes Time.
      Building and staging the APEX web site can take very long. The stand-alone documentation will take about 2 minutes. The
      sites for all modules and projects and the main APEX site can take between 10-30 minutes depending on your build machine (~10 minutes
      without generating source and test-source reports, closer to 30 minutes with all reports).

   .. container:: paragraph

      Start the build deleting the staging directory that might have
      been created by a previous site build. Then go to the APEX
      packaging directory.

   +--------------------------------+-----------------------------------+----------------------------------+
   | Unix                           | Windows                           | Cygwin                           |
   +================================+===================================+==================================+
   | .. container::                 | .. container::                    | .. container::                   |
   |                                |                                   |                                  |
   |    .. container:: content      |    .. container:: content         |    .. container:: content        |
   |                                |                                   |                                  |
   |       .. code:: bash           |       .. code:: bash              |       .. code:: bash             |
   |         :number-lines:         |         :number-lines:            |         :number-lines:           |
   |                                |                                   |                                  |
   |         cd /usr/local/src/apex |         c:                        |         cd /cygdrive/c/dev/apex  |
   |         rm -fr target/ad-site  |         cd \dev\apex              |         rm -fr target/ad-site    |
   |                                |         rmdir /s/q target\ad-site |                                  |
   +--------------------------------+-----------------------------------+----------------------------------+

   .. container:: paragraph

      the workflow for building a complete site then is as follows:

   .. container:: listingblock

      .. container:: content

         .. code:: bash

            mvn clean -DapexAll (1)
            mvn install -DskipTests (2)
            mvn generate-resources -N -DapexDocs (3)
            mvn initialize site:attach-descriptor site site:stage -DapexSite (4)

   .. container:: olist arabic

      #. First clean all modules to remove any site artifacts, use the
         *apexXtext* profile to make sure these modules are processed as
         well

      #. Next run a simple install without tests

      #. Now generate the APEX stand-alone documentation, they are in
         the local package only so we can use the *-N* switch

      #. Last build the actual sites and stage (copy to the staging
         directory) with the profile *apexSite* (do not forget the
         initialize goal, otherwise the staging directory will not be
         correctly set and sites are staged in every model in a
         directory called ``docs``).

   .. container:: paragraph

      If you want to build the site for a particular project for
      testing, the Maven command is simpler. Since only the main project
      has APEX documentation (stand-alone), you can use Maven as follow.

   .. container:: listingblock

      .. container:: content

         .. code:: bash

            mvn clean site -DapexSite

   .. container:: paragraph

      If you want to stage the tested site, then use

   .. container:: listingblock

      .. container:: content

         .. code:: bash

            mvn clean initialize site:attach-descriptor site site:stage -DapexSite

APEX Codestyle
^^^^^^^^^^^^^^

Introduction: APEX Codestyle
----------------------------

         .. container:: paragraph

            This page describes how to apply a code style to the APEX
            Java projects. The provided code templates are guidelines
            and are provided for references and as examples. We will not
            engage in "holy war" on style for coding. As long as the
            style of a particular block of code is understandable,
            consistent, and readable, please feel free to adapt or
            modify these guides or use other guides as you see fit.

         .. container:: paragraph

            The JAutoDoc and Checkstyle Eclipse Plugins and tools are
            useful and remove a lot of the tedium from code
            documentation. Use them to check your code and please fix
            any issues they identify with your code.

         .. container:: paragraph

            Since APEX is part of ONAP, the general ONAP rules and
            guideliness for development do apply. Please see `ONAP
            Wiki <https://wiki.onap.org/display/DW/Developing+ONAP>`__
            for details.

Java coding Rules
-----------------

         .. container:: ulist

            -  APEX is (in large parts) a platform (or middleware), so
               `Software Design
               Patterns <https://en.wikipedia.org/wiki/Software_design_pattern>`__
               are a good thing

            -  The `Solid
               Principles <https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)>`__
               apply

            -  Avoid class fields scoped as ``protected``

               .. container:: ulist

                  -  They break a lot of good design rules, e.g. most
                     SOLID rules

                  -  For a discussion see this `Stackoverflow
                     Question <https://softwareengineering.stackexchange.com/questions/162643/why-is-clean-code-suggesting-avoiding-protected-variables>`__

            -  If you absolutely need ``protected`` class fields they
               should be ``final``

            -  Avoid ``default`` scope for class fields and methods

               .. container:: ulist

                  -  For fields: use ``public`` or ``private`` (see also
                     above)

                  -  For methods: use ``public`` for general use,
                     ``protected`` for specialization using inheritance
                     (ideally ``final``), ``private`` for everything
                     else

            -  Method parameters that are not changed in the method
               should be marked ``final``

            -  Every package must have a ``package-info.java`` file with
               an appropriate description, minimum a descriptive one
               liner

            -  Every class must have

               .. container:: ulist

                  -  The common header (copyright, file, date)

                  -  Javadoc header for the class with description of
                     the class and author

                  -  Javadoc for *all public\_* fields

                  -  If possible, Javadoc for *private* fields, at least
                     some documentation for private fields

                  -  Javadoc for *all* methods

            -  All projects must build with all tests on Unix, Windows,
               *and* Cygwin

               .. container:: ulist

                  -  Support all line endings in files, e.g. ``\n`` and
                     ``\r\n``

                  -  Be aware of potential differences in exception
                     messages, if testing against a message

                  -  Support all types of paths: Unix with ``/``,
                     Windows with an optinal drive ``C:\`` and ``\``,
                     Cygwin with mixed paths

Eclipse Plugin: JAutodoc
------------------------

         .. container:: paragraph

            This plugin is a helper plugin for writing Javadoc. It will
            automatically create standard headers on files, create
            package-info.java files and will put in remarkably good stub
            Javadoc comments in your code, using class names and method
            names as hints.

         .. container:: paragraph

            Available from the Eclipse Marketplace. In Eclipse
            Help→Eclipse Marketplace…​ and type ``JAutodoc``. Select
            JAutodoc when the search returns and install it.

         .. container:: paragraph

            You must configure JAutoDoc in order to get the most out of
            it. Ideally JAutoDoc should be configured with templates
            that cooperate with the inbuilt Eclipse Code Formatter for
            best results.

Eclipse Plugin: Checkstyle
--------------------------

         .. container:: paragraph

            This plugin integrates
            `Checkstyle <http://checkstyle.sourceforge.net/>`__ into
            Eclipse. It will check your code and flag any checkstyle
            issues as warnings in the code.

         .. container:: paragraph

            Available from the Eclipse Marketplace. In Eclipse
            Help→Eclipse Marketplace…​ and type "Checkstyle". Select
            "Checkstyle Plug-in" when the search returns and install it.
            Note that "Checkstyle Plug-in" may not be the first result
            in the list of items returned.

         .. container:: paragraph

            For APEX, the ONAP checkstyle rules do apply. The
            configuration is part of the ONAP parent. See `ONAP
            Git <https://git.onap.org/oparent/plain/checkstyle/src/main/resources/onap-checkstyle/>`__
            for details and updates. All settings for checkstyle are
            already part of the code (POM files).

Configure Eclipse
-----------------

         .. container:: ulist

            -  Set the template for Eclipse code clean up

               .. container:: olist arabic

                  #. Eclipse  Window  Preferences  Java  Code Style
                     Clean Up → Import…​

                  #. Select your template file
                     (``ApexCleanUpTemplate.xml``) and apply it

            -  Set the Eclipse code templates

               .. container:: olist arabic

                  #. Eclipse  Window  Preferences  Java  Code Style
                     Code Templates → Import…​

                  #. Select your templates file
                     (``ApexCodeTemplates.xml``) and apply it

                     .. container:: ulist

                        -  Make sure to set your email address in
                           generated comments by selecting
                           "Comments→Types" in the "Configure generated
                           code and comments:" pane, then change the
                           email address on the @author tag to be your
                           email address

            -  Set the Eclipse Formatter profile

               .. container:: olist arabic

                  #. Eclipse  Window  Preferences  Java  Code Style
                     Formatter → Import…​

                  #. Select your formatter profile file
                     (``ApexFormatterProfile.xml``) and apply it

         .. container:: paragraph

            The templates mentioned above can be found in
            ``apex-model/apex-model.build-tools/src/main/resources/eclipse``

Configure JAutodoc (Eclipse)
----------------------------

         .. container:: paragraph

            Import the settings for JAutodoc:

         .. container:: olist arabic

            #. Eclipse  Window  Preferences  Java  JAutodoc → Import
               All…​ (at bottom of the JAutodoc preferences window)

            #. Leave all the preferences ticked to import all
               preferences, browse to the JAutodoc setting file
               (``ApexJautodocSettings.xml``) and press OK

            #. Set your email address in the package Javadoc template

               .. container:: ulist

                  -  Press Edit Template…​ in the Package Javadoc area
                     of the JAutodoc preferences window, and change the
                     email address on the ``@author`` tag to be your
                     email address

            #. Now, apply the JAutodoc settings

         .. container:: paragraph

            The templates mentioned above can be found in
            ``apex-model/apex-model.build-tools/src/main/resources/eclipse``

Configure Checkstyle (Maven)
----------------------------

         .. container:: paragraph

            When using a custom style configuration with Checkstyle, the
            definition of that style must of course be available to
            Checkstyle. In order not to have to distribute style files
            for checkstyle into all Maven modules, it is recommended
            that a special Maven module be built that contains the
            checkstyle style definition. That module is then used as a
            dependency in the *POM* for all other modules that wish to
            use that checkstyle style. For a full explanation see `the
            explanation of Checkstyle multi-module
            configuration <https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/multi-module-config.html>`__.

         .. container:: paragraph

            For APEX, the ONAP checkstyle rules do apply. The
            configuration is part of the ONAP parent. See `ONAP
            Git <https://git.onap.org/oparent/plain/checkstyle/src/main/resources/onap-checkstyle/>`__
            for details and updates.

Run Checkstyle (Maven)
----------------------

         .. container:: paragraph

            Run Checkstyle using Maven on the command line with the
            command:

         .. container:: listingblock

            .. container:: content

               .. code:: bash

                  mvn checkstyle:check

         .. container:: paragraph

            On the main APEX project, run a full checkstyle check as:

         .. container:: listingblock

            .. container:: content

               .. code:: bash

                  mvn checkstyle:checkstyle -DapexAll

Configure Checkstyle (Eclipse, globally)
----------------------------------------

         .. container:: olist arabic

            #. Set up a module with the Checkstyle style files (see
               above)

            #. In Eclipse  Window  Preferences go to Checkstyle

            #. Import the settings for Checkstyle

               .. container:: ulist

                  -  Press New…​ to create a new *Global Check
                     Configurations* entry

                  -  Give the configuration a name such as *Apex
                     Checkstyle Configuration* and select the *External
                     Configuration File* form in the *Type* drop down
                     menu

                  -  Browse to the Checckstyle setting file
                     (``ApexCheckstyleSettings.xml``) and press OK

            #. Press OK

               .. container:: ulist

                  -  You may now get an *Unresolved Properties found*
                     dialogue

                  -  This is because there is a second Checkstyle
                     configuration file required to check file headers

            #. Press Edit Properties…​ and press Find unresolved
               properties on the next dialogue window

            #. The plugin will find the ``${checkstyle.header.file}``
               property is unresolved and will ask should it be added to
               the properties, click yes

            #. Now, select the row on the dialogue for the
               ``checkstyle.header.file property`` and click Edit…​

            #. Set the value of the ``checkstyle.header.file property``
               to
               ``<your-apex-git-location>/apex-model/apex-model.build-tools/src/main/resources/checkstyle/apex_header.txt``

               .. container:: ulist

                  -  Of course replacing the tag
                     ``<your-apex-git-location>`` with the location of
                     your Apex GIT repository

            #. Press OK, OK, OK to back out to the main Checkstyle
               properties window

            #. Select the *Apex Checkstyle Configuration* as your
               default configuration by selecting its line in the
               *Global Check Configuraitons* list and clicking Set as
               Default

            #. Press Apply and Close to finish Checkstyle global
               configuration

         .. container:: paragraph

            The templates mentioned above can be found in
            ``apex-model/apex-model.build-tools/src/main/resources/eclipse``

2.10. Configure Checkstyle Blueprint
------------------------------------

         .. container:: paragraph

            As well as being configured globally, Checkstyle must be
            configured and activated for each project in Eclipse. In
            order to make this process less tedious, set up the first
            project you apply Checkstye to as a blueprint project and
            then use this blueprint for all other projects.

         .. container:: olist arabic

            #. Select the project you want to use as a blueprint

               .. container:: ulist

                  -  For example, ``apex-model.basic-model`` in ``apex``
                     and enter the project properties by right clicking
                     and selecting **Properties**

            #. Click *Checkstyle* on the properties to get the
               Checkstyle project configuration window

            #. Click the box *Checkstyle active for this project* and in
               the *Exclude from checking…​* list check the boxes:

               .. container:: ulist checklist

                  -   *files outside source directories*

                  -   *derived (generated) files*

                  -   *files from packages:*

            #. Now, in order to turn off checking on resource
               directories and on JUnit tests

               .. container:: ulist

                  -  Select the line *files from packages:* in the
                     *Exclude from checking…​* list and click Change…​

            #. On the *Filter packages* dialogue

               .. container:: ulist

                  -  Check all the boxes except the top box, which is
                     the box for *src/main/java*

                  -  Ensure that the *recursively exclude sub-packages*
                     check box is ticked

                     .. container:: ulist checklist

                        -   *recursively exclude sub-packages*

                  -  Press OK

            #. Press Apply and Close to apply the changes

Use Eclipse Source Operations
-----------------------------

         .. container:: paragraph

            Eclipse Source Operations can be carried out on individual
            files or on all the files in a package but do not recurse
            into sub-packages. They are available as a menu in Eclipse
            by selecting a file or package and right clicking on
            *Source*. Note that running *Clean Up…​* with the Apex clean
            up profile will run *Format* and *Organize Imports*. So if
            you run a clean up on a file or package, you need not run
            *Format* or *Organize Imports*.

         .. container:: paragraph

            We recommend you use the following Eclipse Source
            Operations:

         .. container:: olist arabic

            #. *Format* applies the current format definition to the
               file or all files in a package

            #. *Organize Imports* sorts the imports on each file in
               standard order

            #. *Clean Up* runs a number of cleaning operations on each
               file. The Apex clean up template

               .. container:: ulist

                  -  Remove ``this`` qualifier for non static field
                     accesses

                  -  Change non static accesses to static members using
                     declaring type

                  -  Change indirect accesses to static members to
                     direct accesses (accesses through subtypes)

                  -  Convert control statement bodies to block

                  -  Convert ``for`` loops to enhanced ``for`` loops

                  -  Add final modifier to private fields

                  -  Add final modifier to local variables

                  -  Remove unused imports

                  -  Remove unused private methods

                  -  Remove unused private constructors

                  -  Remove unused private types

                  -  Remove unused private fields

                  -  Remove unused local variables

                  -  Add missing ``@Override`` annotations

                  -  Add missing ``@Override`` annotations to
                     implementations of interface methods

                  -  Add missing ``@Deprecated`` annotations

                  -  Add missing serial version ID (generated)

                  -  Remove unnecessary casts

                  -  Remove unnecessary ``$NON-NLS$`` tags

                  -  Organize imports

                  -  Format source code

                  -  Remove trailing white spaces on all lines

                  -  Correct indentation

                  -  Remove redundant type arguments

                  -  Add file header (JAutodoc)

Using JAutodoc
--------------

         .. container:: paragraph

            Similar to Eclipse Source Operations, JAutodoc operations
            can be carried out on individual files or on all the files
            in a package but do not recurse into sub-packages. The
            JAutodoc operations are available by selecting a file or
            package and right clicking on *JAutodoc*:

         .. container:: olist arabic

            #. To add a ``package-info.java`` file to a package, select
               the package and right-click Jautodoc  Add Package Javadoc

            #. To add headers to files select on a file (or on the
               package to do all files) and right click JAutodoc  Add
               Header

            #. To add JAutodoc stubs to files, select on a file (or on
               the package to do all files) and right click JAutodoc
               Add Javadoc

Using Checkstyle
----------------

         .. container:: paragraph

            In order to use Checkstyle, you must configure it per
            project and then activate it per project. The easiest way to
            do this is to set up one project as a blueprint and use that
            blueprint for other projects (see above). Once you have a
            blueprint project, you can use Checkstyle on other projects
            as follows

         .. container:: olist arabic

            #. Set up Checkstyle on projects by selecting one or more
               projects

               .. container:: ulist

                  -  Right clicking and selecting Checkstyle  Configure
                     project(s) from *blueprint…​* and then selecting
                     your blueprint project

                  -  (for example ``apex-model.basic-model``) from the
                     list of projects and pressing OK

            #. Activate Checkstyle on projects by selecting one or more
               projects

               .. container:: ulist

                  -  Right clicking and selecting Checkstyle  Activate
                     Checkstyle

                  -  Now Checkstyle warnings will appear on the selected
                     projects if they have warnings

            #. You can disable Checkstyle checking on a file or a
               package (recursively) by selecting a file or package

               .. container:: ulist

                  -  Right clicking and selecting Checkstyle  Clear
                     Checkstyle violations

            #. You can enable Checkstyle checking on a file or a package
               (recursively) by selecting a file or package

               .. container:: ulist

                  -  Right clicking and selecting Checkstyle  Check Code
                     with Checkstyle

            #. On individual files, you can apply fixes that clear some
               Checkstyle warnings

               .. container:: ulist

                  -  Select the file, right click and select **Apply
                     Checkstyle fixes**

Disable Eclipse Formatting (partially)
--------------------------------------

         .. container:: paragraph

            Sometimes, the Eclipse code formatting results in correct
            but untidy indentation, for example when Java Persistence
            annotations or long sequences of lined-up assignments are
            formatted. You can disable formatting for sections of code.

         .. container:: olist arabic

            #. Ensure that Off/On Tags are enabled in Eclipse

            #. In Eclipse  Window  Preferences  Java  Code Style
               Formatter window press Edit…​

            #. Click on the *Off/On Tags* tab

            #. Ensure that the *Enable Off/On Tags* checkbox is checked

            #. Surround the section of code that you do not want the
               formatter to act on with comments containing the Off/On
               tags

         .. container:: listingblock

            .. container:: content

               .. code:: java
                 :number-lines:

                 // @formatter:off
                 // Plugin Parameters
                 private DistributorParameters distributorParameters = new DistributorParameters();
                 private SchemaParameters      schemaParameters      = new SchemaParameters();
                 private LockManagerParameters lockManagerParameters = new LockManagerParameters();
                 private PersistorParameters   persistorParameters   = new PersistorParameters();
                 // @formatter:on

Supress Checkstyle (partially)
------------------------------

   .. container:: paragraph

      Sometimes Checkstyle checks identify code that does not comply
      with Checkstyle rules. In limited cases Checkstyle rules can be
      suppressed, for example where it is impossible to design the code
      in a way that complies with Checkstyle or where the Checkstyle
      rule is impossible to apply. Checkstyle rules are suppressed as is
      explained in this `Stackoverflow
      post <https://stackoverflow.com/questions/4023185/how-to-disable-a-particular-checkstyle-rule-for-a-particular-line-of-code>`__.

   .. container:: paragraph

      The example below illustrates how to suppress a Checkstyle rule
      that specifies all methods must have seven parameters or less.

   .. container:: listingblock

      .. container:: content

         .. code:: java
            :number-lines:

            // CHECKSTYLE:OFF: checkstyle:ParameterNumber
            public myMethod(final int par1, final int par2, final int par3, final int par4,
              final int par5, final int par6, final int par7, final int par8) {
            }
            // CHECKSTYLE:ON: checkstyle:ParameterNumber

apex-apps.utilities
^^^^^^^^^^^^^^^^^^^

CLI Example
-----------

         .. container:: paragraph

            Using the APEX CLI utilities can be done as follows. First,
            add the dependency of the utility project to your POM file.

         .. container:: listingblock

            .. container:: content

               .. code:: bash

                  <dependency>
                    <groupId>org.onap.policy.apex-pdp.tools</groupId>
                    <artifactId>tools-common</artifactId>
                    <version>2.0.0-SNAPSHOT</version>
                  </dependency>

         .. container:: paragraph

            Now, create a new application project, for instance
            ``MyApp``. In this project, create a new main application
            class as ``Application.java``. In this class, create a new
            main method as ``public static void main(String[] args)``.

         .. container:: paragraph

            Now use the provided ``CliOptions`` and ``CliParser``.
            Manually importing means to add the following lines to the
            start of your application (in Eclipse this import will be
            done automatically):

         .. container:: listingblock

            .. container:: content

               .. code:: java
                  :number-lines:

                  import org.onap.policy.apex.tools.common.CliOptions;
                  import org.onap.policy.apex.tools.common.CliParser;

.. container:: paragraph

   Now, inside your ``main()`` method, start setting some general
   application properties. Important are the application name and some
   description of your application. For instance:

.. container:: listingblock

   .. container:: content

      .. code:: java
         :number-lines:

         String appName = "test-app";
         final String appDescription = "a test app for documenting how to use the CLI utilities";

.. container:: paragraph

   Next, create a new CLI Parser and add a few CLI options from the
   standard ``CliOptions``. The following example adds options for help,
   version, and a model file:

.. container:: listingblock

   .. container:: content

      .. code:: java
         :number-lines:

         final CliParser cli = new CliParser();
         cli.addOption(CliOptions.HELP);
         cli.addOption(CliOptions.VERSION);
         cli.addOption(CliOptions.MODELFILE);

.. container:: paragraph

   Next, parse the given CLI arguments:

.. container:: listingblock

   .. container:: content

      .. code:: java
         :number-lines:

         final CommandLine cmd = cli.parseCli(args);

.. container:: paragraph

   Once the command line is parsed, we can look into the individual
   options, check if they are set, and then act accordingly. We start
   with the option for *help*. If the option is present, we print a help
   screen and return:

.. container:: listingblock

   .. container:: content

      .. code:: java
         :number-lines:

         // help is an exit option, print usage and exit
         if (cmd.hasOption('h') || cmd.hasOption("help")) {
             final HelpFormatter formatter = new HelpFormatter();
             LOGGER.info(appName + " v" + cli.getAppVersion() + " - " + appDescription);
             formatter.printHelp(appName, cli.getOptions());
             return;
         }

.. container:: paragraph

   Next, we process the option for *version*. Here, we want to print a
   version for our application and return. The CLI Parser already
   provides a method to obtain the correct version for an APEX build, so
   we use that:

.. container:: listingblock

   .. container:: content

      .. code:: java
         :number-lines:

         // version is an exit option, print version and exit
         if (cmd.hasOption('v') || cmd.hasOption("version")) {
             LOGGER.info(appName + " " + cli.getAppVersion());
             return;
         }

.. container:: paragraph

   Once help and version arguments are processed, we can proceed to look
   at all other options. We have added an option for a model file, so
   check this option and test if we can actually load a model file with
   the given argument. If we can load a model, everything is ok. If we
   cannot load a model, we print an error and return.

.. container:: listingblock

   .. container:: content

      .. code:: java
         :number-lines:

         String modelFile = cmd.getOptionValue('m');
         if (modelFile == null) {
             modelFile = cmd.getOptionValue("model");
         }
         if (modelFile == null) {
             LOGGER.error(appName + ": no model file given, cannot proceed (try -h for help)");
             return;
         }

.. container:: paragraph

   With a model file being loadable, we finish parsing command line
   arguments. We also print some status messages to note that the
   application now is ready to start:

.. container:: listingblock

   .. container:: content

      .. code:: java
         :number-lines:

         LOGGER.info(appName + ": starting");
         LOGGER.info(" --> model file: " + modelFile);

.. container:: paragraph

   The last action now is to run the actual application. The example
   below is taken from a version of the ``Model2Cli`` application, which
   creates a new object and runs it in a ``try`` block, since exceptions
   might be thrown by the object:

.. container:: listingblock

   .. container:: content

      .. code:: java
         :number-lines:

         // your code for the application here
         // e.g.
         // try {
         // Model2Cli app = new Model2Cli(modelFile, !cmd.hasOption("sv"), appName);
         // app.runApp();
         // }
         // catch(ApexException aex) {
         // LOGGER.error(appName + ": caught APEX exception with message: " + aex.getMessage());
         // }

.. container:: paragraph

   If this new application is now called with the command line ``-h`` or
   ``--help`` it will print the following help screen:

.. container:: listingblock

   .. container:: content

      .. code:: bash

         test-app v2.0.0-SNAPSHOT - a test app for documenting how to use the CLI utilities
         usage: test-app
          -h,--help                 prints this help and usage screen
          -m,--model <MODEL-FILE>   set the input policy model file
          -v,--version              prints the application version

.. container:: paragraph

   If this new application is called with the option ``-v`` or
   ``--version`` it will print its version information as:

.. container:: listingblock

   .. container:: content

      .. code:: bash

         test-app 2.0.0-SNAPSHOT

Autoversioning an Application
-----------------------------

   .. container:: paragraph

      The APEX utilities project provides a means to version an
      application automatically towards the APEX version for which it is
      written. This is realized by generating a file called
      ``app-version.txt`` that includes the Maven project version. This
      file is then automatically deployed in the folder ``etc`` of a
      full APEX distribution. The CLI Parser here provides a method to
      access this version for an application.

   .. container:: paragraph

      First, create a new CLI Parser object, add some options (in the
      example an option for version, but any options will do), then
      parse the command line:

   .. container:: listingblock

      .. container:: content

         .. code:: java
            :number-lines:

            final CliParser cli = new CliParser();
            cli.addOption(CliOptions.VERSION);
            final CommandLine cmd = cli.parseCli(args);

.. container:: paragraph

   Next, we check if the version option was used in the command line and
   print application name and version if it was used:

.. container:: listingblock

   .. container:: content

      .. code:: java
         :number-lines:

         // version is an exit option, print version and exit
         if (cmd.hasOption('v') || cmd.hasOption("version")) {
             LOGGER.info("myApp" + " " + cli.getAppVersion());
             return;
         }

.. container:: paragraph

   The output will be:

.. container:: listingblock

   .. container:: content

      .. code:: bash

         myApp 2.0.0-SNAPSHOT

.. container:: paragraph

   The auto-version information comes from the method call
   ``cli.getAppVersion()`` in line 2 in the example above. The method is
   defined in the ``CliParser`` class as:

.. container:: listingblock

   .. container:: content

      .. code:: java
         :number-lines:

         public String getAppVersion() {
             return new Scanner(CliParser.class.getResourceAsStream("/app-version.txt"), "UTF-8").useDelimiter("\\A").next();
         }

.. container:: paragraph

   The file ``app-version.txt`` is automatically added to an APEX full
   distribution, as described above (for details on this see the POM
   files in the APEX application packaging projects).

.. container::
   :name: footer

   .. container::
      :name: footer-text

      2.0.0-SNAPSHOT
      Last updated 2018-09-04 16:04:24 IST