nitc: extract common app.nit annotations from Android
[nit.git] / src / platform / android_annotations.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Additionnal annotations to gather metadata on Android projects
18 module android_annotations
19
20 intrude import app_annotations
21
22 # Metadata associated to an Android project
23 class AndroidProject
24 super AppProject
25
26 # Custom lines to add to the AndroidManifest.xml in the <manifest> node
27 var manifest_lines = new Array[String]
28
29 # Custom lines to add to the AndroidManifest.xml in the <application> node
30 var manifest_application_lines = new Array[String]
31
32 # Custom lines to add to AndroidManifest.xml as attributes inside the <activity> node
33 var manifest_activity_attributes = new Array[String]
34
35 # Minimum API level required for the application to run
36 var min_api: nullable Int = null
37
38 # Build target API level
39 var target_api: nullable Int = null
40
41 # Maximum API level on which the application will be allowed to run
42 var max_api: nullable Int = null
43
44 # Activities to declare in the manifest
45 var activities = new Array[String]
46
47 init
48 do
49 var annots = modelbuilder.collect_annotations_on_modules("min_api_version", mainmodule)
50 if not annots.is_empty then
51 var i = annots.pop.arg_as_int(modelbuilder)
52 if i == null then i = 0
53 min_api = i
54 for an in annots do
55 i = an.arg_as_int(modelbuilder)
56 if i == null then continue
57 min_api = min_api.max(i)
58 end
59 end
60
61 annots = modelbuilder.collect_annotations_on_modules("max_api_version", mainmodule)
62 if not annots.is_empty then
63 var i = annots.pop.arg_as_int(modelbuilder)
64 if i == null then i = 0
65 max_api = i
66 for an in annots do
67 i = an.arg_as_int(modelbuilder)
68 if i == null then continue
69 max_api = max_api.min(i)
70 end
71 end
72
73 var annot = modelbuilder.lookup_annotation_on_modules("target_api_version", mainmodule)
74 if annot != null then target_api = annot.arg_as_int(modelbuilder) or else 0
75
76 annots = modelbuilder.collect_annotations_on_modules("android_manifest", mainmodule)
77 for an in annots do manifest_lines.add an.arg_as_string(modelbuilder) or else ""
78
79 annots = modelbuilder.collect_annotations_on_modules("android_manifest_application", mainmodule)
80 for an in annots do manifest_application_lines.add an.arg_as_string(modelbuilder) or else ""
81
82 annots = modelbuilder.collect_annotations_on_modules("android_manifest_activity", mainmodule)
83 for an in annots do manifest_activity_attributes.add an.arg_as_string(modelbuilder) or else ""
84
85 annots = modelbuilder.collect_annotations_on_modules("android_activity", mainmodule)
86 for an in annots do
87 var activity = an.arg_as_string(modelbuilder)
88 if activity != null then activities.add activity
89 end
90 end
91 end