maven-generate-component-xml.patch
1 | From da9e282d834f0e2128501a8154128dc95b4c599d Mon Sep 17 00:00:00 2001 |
2 | From: Julien Lepiller <julien@lepiller.eu> |
3 | Date: Sat, 9 Sep 2017 20:34:38 +0200 |
4 | Subject: [PATCH] Add a script to generate component.xml files. |
5 | |
6 | plexus-component-metadata is normally used for this task, but it |
7 | depends on maven-core, which depends on maven-model-builder, which needs |
8 | plexus-component-metadata. This script is meant to break this dependency |
9 | cycle. |
10 | --- |
11 | components.sh | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
12 | 1 file changed, 132 insertions(+) |
13 | create mode 100755 components.sh |
14 | |
15 | diff --git a/components.sh b/components.sh |
16 | new file mode 100755 |
17 | index 0000000..c6748bd |
18 | --- /dev/null |
19 | +++ b/components.sh |
20 | @@ -0,0 +1,148 @@ |
21 | +## This script generates a rough plexus/components.xml file. It is meant to |
22 | +## replace plexus-component-metadata as it eventually has a recursive dependency |
23 | +## on itself. |
24 | +## |
25 | +## This script must be run in the source directory (usually src/main/java). |
26 | + |
27 | +# Finds the complete name from a class name. |
28 | +function find_role() { |
29 | + role=$1 |
30 | + # Find role |
31 | + case $role in |
32 | + "SettingsWriter" | "SettingsReader") |
33 | + role=org.apache.maven.settings.io.$role |
34 | + ;; |
35 | + "SecDispatcher") |
36 | + role=org.sonatype.plexus.components.sec.dispatcher.$role |
37 | + ;; |
38 | + "SettingsDecrypter") |
39 | + role=org.apache.maven.settings.crypto.$role |
40 | + ;; |
41 | + "SettingsBuilder") |
42 | + role=org.apache.maven.settings.building.$role |
43 | + ;; |
44 | + "SettingsValidator") |
45 | + role=org.apache.maven.settings.validation.$role |
46 | + ;; |
47 | + "LoggerFactory") |
48 | + role=org.eclipse.aether.spi.log.$role |
49 | + ;; |
50 | + "RemoteRepositoryManager" | "VersionResolver" | "VersionRangeResolver" \ |
51 | + | "ArtifactResolver" | "RepositoryEventDispatcher" | "MetadataResolver" \ |
52 | + | "SyncContextFactory" | "MetadataGeneratorFactory" | "MetadatResolver" \ |
53 | + | "ArtifactDescriptorReader") |
54 | + role=org.eclipse.aether.impl.$role |
55 | + ;; |
56 | + "ModelBuilder" | "ModelProcessor") |
57 | + role=org.apache.maven.model.building.$role |
58 | + ;; |
59 | + "ModelValidator") |
60 | + role=org.apache.maven.model.validation.$role |
61 | + ;; |
62 | + "ProfileInjector" | "ProfileSelector") |
63 | + role=org.apache.maven.model.profile.$role |
64 | + ;; |
65 | + "ProfileActivator") |
66 | + role=org.apache.maven.model.profile.activation.$role |
67 | + ;; |
68 | + "SuperPomProvider") |
69 | + role=org.apache.maven.model.superpom.$role |
70 | + ;; |
71 | + "ReportConfigurationExpander" | "PluginConfigurationExpander" \ |
72 | + | "ReportingConverter" | "LifecycleBindingsInjector") |
73 | + role=org.apache.maven.model.plugin.$role |
74 | + ;; |
75 | + "ModelLocator") |
76 | + role=org.apache.maven.model.locator.$role |
77 | + ;; |
78 | + "ModelPathTranslator" | "PathTranslator" | "UrlNormalizer" | "ModelUrlNormalizer") |
79 | + role=org.apache.maven.model.path.$role |
80 | + ;; |
81 | + "DependencyManagementInjector" | "PluginManagementInjector") |
82 | + role=org.apache.maven.model.management.$role |
83 | + ;; |
84 | + "ModelWriter" | "ModelReader") |
85 | + role=org.apache.maven.model.io.$role |
86 | + ;; |
87 | + "DependencyManagementImporter") |
88 | + role=org.apache.maven.model.composition.$role |
89 | + ;; |
90 | + "ModelNormalizer") |
91 | + role=org.apache.maven.model.normalization.$role |
92 | + ;; |
93 | + "ModelInterpolator") |
94 | + role=org.apache.maven.model.interpolation.$role |
95 | + ;; |
96 | + "InheritanceAssembler") |
97 | + role=org.apache.maven.model.inheritance.$role |
98 | + ;; |
99 | + *) |
100 | + role=$role |
101 | + ;; |
102 | + esac |
103 | + echo $role |
104 | +} |
105 | + |
106 | +function generate_xml() { |
107 | +echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
108 | +echo "<component-set>" |
109 | +echo "<components>" |
110 | + |
111 | +for file in `find -name '*.java'`; do |
112 | + annot=`grep "@Component" $file` |
113 | + if [ "$?" == "0" ]; then |
114 | + # We have a component! |
115 | + role=$(echo $annot | sed 's|.*role = \(.*\).class.*|\1|') |
116 | + role_hint=$(echo $annot | sed 's|.*hint = "\(.*\)" .*|\1|') |
117 | + if [ "$role_hint" = "$annot" ]; then |
118 | + role_hint=default |
119 | + fi |
120 | + implem=$(echo $file | sed -e 's|^\./||' -e 's|\.java||' -e 's|/|.|g') |
121 | + role=$(find_role $role) |
122 | + |
123 | + echo "<component>" |
124 | + echo " <role>$role</role>" |
125 | + echo " <role-hint>$role_hint</role-hint>" |
126 | + echo " <implementation>$implem</implementation>" |
127 | + echo " <description />" |
128 | + echo " <isolated-realm>false</isolated-realm>" |
129 | + echo " <requirements>" |
130 | + reqn=1 |
131 | + cont=true |
132 | + while [ "$cont" = "true" ]; do |
133 | + requirement=$(grep "@Requirement" $file -A1 | head -n ${reqn} | tail -1) |
134 | + ((reqn++)) |
135 | + property=$(grep "@Requirement" $file -A1 | head -n ${reqn} | tail -1) |
136 | + if (echo $requirement | grep "@Requirement" >/dev/null); then |
137 | + ((reqn++)) |
138 | + ((reqn++)) |
139 | + optional=$(echo $requirement | sed 's|.*optional = \(.*\) .*|\1|') |
140 | + req_role=$(echo $requirement | sed 's|.*role = \(.*\).class .*|\1|') |
141 | + if (echo $req_role | grep "@Requirement" >/dev/null); then |
142 | + req_role=$(echo $property | sed 's|.*private \(.*\) .*|\1|') |
143 | + fi |
144 | + req_role=$(find_role $req_role) |
145 | + req_name=$(echo $property | sed 's|[^ ]* [^ ]* \([^ ;]*\).*|\1|') |
146 | + echo " <requirement>" |
147 | + echo " <role>$req_role</role>" |
148 | + echo " <field-name>$req_name</field-name>" |
149 | + if (echo $optional | grep "@Requirement" >/dev/null); then |
150 | + : |
151 | + else |
152 | + echo " <optional>$optional</optional>" |
153 | + fi |
154 | + echo " </requirement>" |
155 | + else |
156 | + cont=false |
157 | + fi |
158 | + done |
159 | + echo " </requirements>" |
160 | + echo "</component>" |
161 | + fi |
162 | +done |
163 | + |
164 | +echo "</components>" |
165 | +echo "</component-set>" |
166 | +} |
167 | + |
168 | +(cd $1; generate_xml) > $2 |
169 | -- |
170 | 2.14.1 |
171 | |
172 |