Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
generate_pom_file.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2#
3# Copyright 2019 The Flutter Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7import argparse
8import datetime
9import os
10import sys
11import json
12
13THIS_DIR = os.path.abspath(os.path.dirname(__file__))
14
15# The template for the POM file.
16POM_FILE_CONTENT = '''<?xml version="1.0" encoding="UTF-8"?>
17<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
18 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
19 <modelVersion>4.0.0</modelVersion>
20 <groupId>io.flutter</groupId>
21 <artifactId>{0}</artifactId>
22 <version>{1}</version>
23 <packaging>jar</packaging>
24 <dependencies>
25 {2}
26 </dependencies>
27</project>
28'''
29
30POM_DEPENDENCY = '''
31 <dependency>
32 <groupId>{0}</groupId>
33 <artifactId>{1}</artifactId>
34 <version>{2}</version>
35 <scope>compile</scope>
36 </dependency>
37'''
38
39MAVEN_METADATA_CONTENT = '''
40<metadata xmlns="http://maven.apache.org/METADATA/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/METADATA/1.1.0 http://maven.apache.org/xsd/metadata-1.1.0.xsd" modelVersion="1.1.0">
41 <groupId>io.flutter</groupId>
42 <artifactId>{0}</artifactId>
43 <version>{1}</version>
44 <versioning>
45 <versions>
46 <version>{1}</version>
47 </versions>
48 <snapshot>
49 <timestamp>{2}</timestamp>
50 <buildNumber>0</buildNumber>
51 </snapshot>
52 <snapshotVersions>
53 <snapshotVersion>
54 <extension>jar</extension>
55 <value>{1}</value>
56 </snapshotVersion>
57 <snapshotVersion>
58 <extension>pom</extension>
59 <value>{1}</value>
60 </snapshotVersion>
61 </snapshotVersions>
62 </versioning>
63</metadata>
64'''
65
66
67def utf8(s):
68 return str(s, 'utf-8') if isinstance(s, (bytes, bytearray)) else s
69
70
71def main():
72 with open(os.path.join(THIS_DIR, 'files.json')) as f:
73 dependencies = json.load(f)
74
75 parser = argparse.ArgumentParser(description='Generate the POM file for the engine artifacts')
76 parser.add_argument(
77 '--engine-artifact-id',
78 type=utf8,
79 required=True,
80 help='The artifact id. e.g. android_arm_release'
81 )
82 parser.add_argument('--engine-version', type=utf8, required=True, help='The engine commit hash')
83 parser.add_argument(
84 '--destination', type=utf8, required=True, help='The destination directory absolute path'
85 )
86 parser.add_argument(
87 '--include-embedding-dependencies',
88 type=bool,
89 help='Include the dependencies for the embedding'
90 )
91
92 args = parser.parse_args()
93 engine_artifact_id = args.engine_artifact_id
94 engine_version = args.engine_version
95 artifact_version = '1.0.0-' + engine_version
96 out_file_name = '%s.pom' % engine_artifact_id
97
98 pom_dependencies = ''
99 if args.include_embedding_dependencies:
100 for dependency in dependencies:
101 if not dependency['provides']:
102 # Don't include transitive dependencies since they aren't used by the embedding.
103 continue
104 group_id, artifact_id, version = dependency['maven_dependency'].split(':')
105 pom_dependencies += POM_DEPENDENCY.format(group_id, artifact_id, version)
106
107 # Write the POM file.
108 with open(os.path.join(args.destination, out_file_name), 'w') as f:
109 f.write(POM_FILE_CONTENT.format(engine_artifact_id, artifact_version, pom_dependencies))
110
111 # Write the Maven metadata file.
112 with open(os.path.join(args.destination, '%s.maven-metadata.xml' % engine_artifact_id), 'w') as f:
113 timestamp = datetime.datetime.utcnow().strftime("%Y%m%d.%H%M%S")
114 f.write(MAVEN_METADATA_CONTENT.format(engine_artifact_id, artifact_version, timestamp))
115
116
117if __name__ == '__main__':
118 sys.exit(main())
Definition main.py:1