aboutsummaryrefslogtreecommitdiff
path: root/gnu/packages/patches/maven-generate-component-xml.patch
blob: 289556fbef82dfa9f433dce54079914382850ac5 (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
From da9e282d834f0e2128501a8154128dc95b4c599d Mon Sep 17 00:00:00 2001
From: Julien Lepiller <julien@lepiller.eu>
Date: Sat, 9 Sep 2017 20:34:38 +0200
Subject: [PATCH] Add a script to generate component.xml files.

plexus-component-metadata is normally used for this task, but it
depends on maven-core, which depends on maven-model-builder, which needs
plexus-component-metadata. This script is meant to break this dependency
cycle.
---
 components.sh | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 132 insertions(+)
 create mode 100755 components.sh

diff --git a/components.sh b/components.sh
new file mode 100755
index 0000000..c6748bd
--- /dev/null
+++ b/components.sh
@@ -0,0 +1,149 @@
+#!/bin/sh
+## This script generates a rough plexus/components.xml file. It is meant to
+## replace plexus-component-metadata as it eventually has a recursive dependency
+## on itself.
+##
+## This script must be run in the source directory (usually src/main/java).
+
+# Finds the complete name from a class name.
+function find_role() {
+    role=$1
+    # Find role
+    case $role in
+      "SettingsWriter" | "SettingsReader")
+        role=org.apache.maven.settings.io.$role
+        ;;
+      "SecDispatcher")
+        role=org.sonatype.plexus.components.sec.dispatcher.$role
+        ;;
+      "SettingsDecrypter")
+        role=org.apache.maven.settings.crypto.$role
+        ;;
+      "SettingsBuilder")
+        role=org.apache.maven.settings.building.$role
+        ;;
+      "SettingsValidator")
+        role=org.apache.maven.settings.validation.$role
+        ;;
+      "LoggerFactory")
+        role=org.eclipse.aether.spi.log.$role
+        ;;
+      "RemoteRepositoryManager" | "VersionResolver" | "VersionRangeResolver" \
+      | "ArtifactResolver" | "RepositoryEventDispatcher" | "MetadataResolver" \
+      | "SyncContextFactory" | "MetadataGeneratorFactory" | "MetadatResolver" \
+      | "ArtifactDescriptorReader")
+        role=org.eclipse.aether.impl.$role
+        ;;
+      "ModelBuilder" | "ModelProcessor")
+        role=org.apache.maven.model.building.$role
+        ;;
+      "ModelValidator")
+        role=org.apache.maven.model.validation.$role
+        ;;
+      "ProfileInjector" | "ProfileSelector")
+        role=org.apache.maven.model.profile.$role
+        ;;
+      "ProfileActivator")
+        role=org.apache.maven.model.profile.activation.$role
+        ;;
+      "SuperPomProvider")
+        role=org.apache.maven.model.superpom.$role
+        ;;
+      "ReportConfigurationExpander" | "PluginConfigurationExpander" \
+      | "ReportingConverter" | "LifecycleBindingsInjector")
+        role=org.apache.maven.model.plugin.$role
+        ;;
+      "ModelLocator")
+        role=org.apache.maven.model.locator.$role
+        ;;
+      "ModelPathTranslator" | "PathTranslator" | "UrlNormalizer" | "ModelUrlNormalizer")
+        role=org.apache.maven.model.path.$role
+        ;;
+      "DependencyManagementInjector" | "PluginManagementInjector")
+        role=org.apache.maven.model.management.$role
+        ;;
+      "ModelWriter" | "ModelReader")
+        role=org.apache.maven.model.io.$role
+        ;;
+      "DependencyManagementImporter")
+        role=org.apache.maven.model.composition.$role
+        ;;
+      "ModelNormalizer")
+        role=org.apache.maven.model.normalization.$role
+        ;;
+      "ModelInterpolator")
+        role=org.apache.maven.model.interpolation.$role
+        ;;
+      "InheritanceAssembler")
+        role=org.apache.maven.model.inheritance.$role
+        ;;
+      *)
+        role=$role
+        ;;
+    esac
+    echo $role
+}
+
+function generate_xml() {
+echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+echo "<component-set>"
+echo "<components>"
+
+for file in `find -name '*.java'`; do
+  annot=`grep "@Component" $file`
+  if [ "$?" == "0" ]; then
+    # We have a component!
+    role=$(echo $annot | sed 's|.*role = \(.*\).class.*|\1|')
+    role_hint=$(echo $annot | sed 's|.*hint = "\(.*\)" .*|\1|')
+    if [ "$role_hint" = "$annot" ]; then
+      role_hint=default
+    fi
+    implem=$(echo $file | sed -e 's|^\./||' -e 's|\.java||' -e 's|/|.|g')
+    role=$(find_role $role)
+
+    echo "<component>"
+    echo "  <role>$role</role>"
+    echo "  <role-hint>$role_hint</role-hint>"
+    echo "  <implementation>$implem</implementation>"
+    echo "  <description />"
+    echo "  <isolated-realm>false</isolated-realm>"
+    echo "  <requirements>"
+    reqn=1
+    cont=true
+    while [ "$cont" = "true" ]; do
+      requirement=$(grep "@Requirement" $file -A1 | head -n ${reqn} | tail -1)
+      ((reqn++))
+      property=$(grep "@Requirement" $file -A1 | head -n ${reqn} | tail -1)
+      if (echo $requirement | grep "@Requirement" >/dev/null); then
+        ((reqn++))
+        ((reqn++))
+        optional=$(echo $requirement | sed 's|.*optional = \(.*\) .*|\1|')
+        req_role=$(echo $requirement | sed 's|.*role = \(.*\).class .*|\1|')
+        if (echo $req_role | grep "@Requirement" >/dev/null); then
+          req_role=$(echo $property | sed 's|.*private \(.*\) .*|\1|')
+        fi
+        req_role=$(find_role $req_role)
+        req_name=$(echo $property | sed 's|[^ ]* [^ ]* \([^ ;]*\).*|\1|')
+        echo "    <requirement>"
+        echo "      <role>$req_role</role>"
+        echo "      <field-name>$req_name</field-name>"
+        if (echo $optional | grep "@Requirement" >/dev/null); then
+          :
+        else
+          echo "      <optional>$optional</optional>"
+        fi
+        echo "    </requirement>"
+      else
+        cont=false
+      fi
+    done
+    echo "  </requirements>"
+    echo "</component>"
+  fi
+done
+
+echo "</components>"
+echo "</component-set>"
+}
+
+(cd $1; generate_xml) > $2
-- 
2.14.1