Skip to content

Commit f5fd480

Browse files
committed
Adjust build for Maven bundles to stricter rules
Sonatype enforce more specific requirements for the contents of a bundle file. We also switch to using a ZIP containing JARs.
1 parent 18c4d31 commit f5fd480

1 file changed

Lines changed: 61 additions & 31 deletions

File tree

maven/build.xml

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -134,34 +134,38 @@
134134
<attribute name="version" />
135135
<attribute name="fromDir" default="${dist.dir}" />
136136
<attribute name="stageDir" default="${build.maven}" />
137+
<attribute name="artifact" default="@{stageDir}/${m2.groupDir}/@{artifactId}/@{version}" />
137138
<attribute name="basename" default="@{artifactId}-@{version}" />
138139
<sequential>
139140
<!-- Clean the staging directory. -->
140-
<delete dir="@{stageDir}" />
141-
<mkdir dir="@{stageDir}" />
141+
<delete dir="@{stageDir}/${m2.groupDir}" />
142+
<mkdir dir="@{artifact}" />
142143

143144
<!-- Copy over the primary artifact from @{fromDir} to the staging area. -->
144-
<copy file="@{fromDir}/@{artifactId}.jar" tofile="@{stageDir}/@{basename}.jar" />
145+
<copy file="@{fromDir}/@{artifactId}.jar" tofile="@{artifact}/@{basename}.jar" />
145146

146147
<!-- The source and Javadoc are already prepared (but add the version to the name). -->
147-
<copy file="@{fromDir}/sources.jar" tofile="@{stageDir}/@{basename}-sources.jar" />
148-
<copy file="@{fromDir}/javadoc.jar" tofile="@{stageDir}/@{basename}-javadoc.jar" />
148+
<copy file="@{fromDir}/sources.jar" tofile="@{artifact}/@{basename}-sources.jar" />
149+
<copy file="@{fromDir}/javadoc.jar" tofile="@{artifact}/@{basename}-javadoc.jar" />
149150

150151
<!-- Create the POM from the given template with placeholders replaced. -->
151-
<copy file="maven/pom-template.xml" tofile="@{stageDir}/@{basename}.pom">
152+
<copy file="maven/pom-template.xml" tofile="@{artifact}/@{basename}.pom">
152153
<filterset>
153154
<filter token="PROJECT-VERSION" value="@{version}" />
154155
<filter token="ARTIFACT-ID" value="@{artifactId}" />
155156
</filterset>
156157
</copy>
157158

158159
<!-- Sign everything. -->
159-
<sign-all stageDir="@{stageDir}" artifactId="@{artifactId}" version="@{version}" />
160+
<sign-all artifact="@{artifact}" artifactId="@{artifactId}" version="@{version}" />
160161

161-
<!-- JAR-up the entire contents of the staging directory. -->
162-
<jar jarfile="${pubs.dir}/@{basename}-bundle.jar">
162+
<!-- Checksum JARs and POMs -->
163+
<checksum-pom-jar artifact="@{artifact}" />
164+
165+
<!-- ZIP-up the entire contents of the staging directory. -->
166+
<zip destfile="${pubs.dir}/@{basename}-bundle.zip">
163167
<fileset dir="@{stageDir}" />
164-
</jar>
168+
</zip>
165169
</sequential>
166170
</macrodef>
167171

@@ -171,62 +175,88 @@
171175
<macrodef name="m2-bundle-gradle">
172176
<attribute name="artifactId" />
173177
<attribute name="version" />
174-
<attribute name="fromDir" default="${gradle.repo}/${m2.groupDir}/@{artifactId}/@{version}" />
178+
<attribute name="fromDir" default="${gradle.repo}" />
175179
<attribute name="stageDir" default="${build.maven}" />
180+
<attribute name="artifact" default="@{stageDir}/${m2.groupDir}/@{artifactId}/@{version}" />
176181
<attribute name="basename" default="@{artifactId}-@{version}" />
177182
<sequential>
178-
<!-- Validate the POM -->
179-
<validate-pom file="@{fromdir}/@{basename}.pom" />
180-
181183
<!-- Clean the staging directory. -->
182-
<delete dir="@{stageDir}" />
183-
<mkdir dir="@{stageDir}" />
184+
<delete dir="@{stageDir}/${m2.groupDir}" />
185+
<mkdir dir="@{artifact}" />
184186

185187
<!-- Copy over all the artifacts from @{fromDir} to the staging area. -->
186188
<copy todir="@{stageDir}">
187189
<fileset dir="@{fromDir}">
188-
<include name="*.jar" />
189-
<include name="*.pom" />
190+
<include name="**/*.jar" />
191+
<include name="**/*.pom" />
190192
</fileset>
191193
</copy>
192194

195+
<!-- Validate the POM -->
196+
<validate-pom file="@{artifact}/@{basename}.pom" />
197+
193198
<!-- Sign everything. -->
194-
<sign-all stageDir="@{stageDir}" artifactId="@{artifactId}" version="@{version}" />
199+
<sign-all artifact="@{artifact}" artifactId="@{artifactId}" version="@{version}" />
200+
201+
<!-- Checksum JARs and POMs -->
202+
<checksum-pom-jar artifact="@{artifact}" />
195203

196-
<!-- JAR-up the entire contents of the staging directory. -->
197-
<jar jarfile="${pubs.dir}/@{basename}-bundle.jar">
204+
<!-- ZIP-up the entire contents of the staging directory. -->
205+
<zip destfile="${pubs.dir}/@{basename}-bundle.zip">
198206
<fileset dir="@{stageDir}" />
199-
</jar>
207+
</zip>
200208
</sequential>
201209
</macrodef>
202210

203-
<!-- Add detached signature for single artifact in staging directory. -->
211+
<!-- Add detached signature for single artifact in artifact directory. -->
204212
<macrodef name="sign-detached">
205213
<attribute name="file" />
206-
<attribute name="stageDir" />
214+
<attribute name="artifact" />
207215
<sequential>
208216
<!-- Generate a detached signature for each artifact in the bundle. -->
209-
<exec executable="gpg" dir="@{stageDir}">
217+
<exec executable="gpg" dir="@{artifact}">
210218
<arg value="-ab" />
211219
<arg value="@{file}" />
212220
</exec>
213221
</sequential>
214222
</macrodef>
215223

216-
<!-- Add detached signatures for group of artifacts in staging directory. -->
224+
<!-- Add detached signatures for group of artifacts in specified arifact directory. -->
217225
<macrodef name="sign-all">
218226
<attribute name="artifactId" />
219227
<attribute name="version" />
220-
<attribute name="stageDir" />
228+
<attribute name="artifact" />
221229
<attribute name="basename" default="@{artifactId}-@{version}" />
222230
<sequential>
223-
<sign-detached stageDir="@{stageDir}" file="@{basename}.pom" />
224-
<sign-detached stageDir="@{stageDir}" file="@{basename}.jar" />
225-
<sign-detached stageDir="@{stageDir}" file="@{basename}-sources.jar" />
226-
<sign-detached stageDir="@{stageDir}" file="@{basename}-javadoc.jar" />
231+
<sign-detached artifact="@{artifact}" file="@{basename}.pom" />
232+
<sign-detached artifact="@{artifact}" file="@{basename}.jar" />
233+
<sign-detached artifact="@{artifact}" file="@{basename}-sources.jar" />
234+
<sign-detached artifact="@{artifact}" file="@{basename}-javadoc.jar" />
227235
</sequential>
228236
</macrodef>
229237

238+
<!-- Add checksums for for JAR and POM files in specified arifact directory. -->
239+
<macrodef name="checksum-pom-jar">
240+
<attribute name="artifact" />
241+
<sequential>
242+
<!-- MD5 Checksum everything -->
243+
<checksum algorithm="MD5" fileext=".md5">
244+
<fileset dir="@{artifact}">
245+
<include name="*.jar" />
246+
<include name="*.pom" />
247+
</fileset>
248+
</checksum>
249+
250+
<!-- SHA-1 Checksum everything -->
251+
<checksum algorithm="SHA-1" fileext=".sha1">
252+
<fileset dir="@{artifact}">
253+
<include name="*.jar" />
254+
<include name="*.pom" />
255+
</fileset>
256+
</checksum>
257+
</sequential>
258+
</macrodef>
259+
230260
<!-- Validate a Maven POM . -->
231261
<macrodef name="validate-pom">
232262
<attribute name="file" />

0 commit comments

Comments
 (0)