@@ -10,9 +10,12 @@ package io.typefox.publishing
1010import com.google.common.collect.AbstractIterator
1111import com.google.common.io.Files
1212import java.io.File
13+ import java.io.FileInputStream
1314import java.io.FileOutputStream
1415import java.io.FilenameFilter
1516import java.io.IOException
17+ import java.io.InputStream
18+ import java.io.OutputStream
1619import java.nio.charset.Charset
1720import java.util.concurrent.Callable
1821import java.util.jar.JarFile
@@ -29,6 +32,8 @@ import org.gradle.api.Project
2932import org.gradle.api.tasks.Copy
3033import org.gradle.api.tasks.Delete
3134import org.gradle.api.tasks.bundling.Zip
35+ import org.tukaani.xz.LZMA2Options
36+ import org.tukaani.xz.XZOutputStream
3237import org.w3c.dom.Element
3338import pw.prok.download.Download
3439
@@ -128,7 +133,7 @@ class EclipsePublishing {
128133 from = ' ' ' «buildDir»/p2-«repoName.toLowerCase»/repository-unsigned' ' '
129134 into = ' ' ' «rootDir»/build-result/p2.repository' ' '
130135 if (osspub. signJars) {
131- exclude(' **/artifacts.jar ' )
136+ exclude(' **/artifacts.* ' )
132137 for (namespace : repository. namespaces) {
133138 exclude(' ' ' **/«namespace»*.jar' ' ' )
134139 }
@@ -195,7 +200,7 @@ class EclipsePublishing {
195200 packages.base=downloads
196201 tests.base=test-results
197202 group.owner=«repository.group»
198- downloads.area=/home/data/httpd/download.eclipse.org/«repository.group?.replace ('.', '/')»/
203+ downloads.area=/home/data/httpd/download.eclipse.org/«repository.deployPath ?: repository. group?.replace ('.', '/')»/
199204 '''
200205
201206 private def getBuildPrefix () {
@@ -238,15 +243,27 @@ class EclipsePublishing {
238243 }
239244
240245 private def updateArtifactsXml (String sourceDir , String destDir ) {
246+ var InputStream sourceStream
241247 var JarFile sourceJar
248+ var OutputStream targetStream
242249 var JarOutputStream targetJar
250+ var XZOutputStream targetXz
243251 try {
244- sourceJar = new JarFile (' ' ' «sourceDir»/artifacts.jar' ' ' )
245- val artifactsEntry = sourceJar. getEntry(' artifacts.xml' )
246- if (artifactsEntry == = null )
247- throw new GradleException (' artifacts.jar does not contain artifacts.xml' )
252+ val artifactsXmlFile = new File (' ' ' «sourceDir»/artifacts.xml' ' ' )
253+ val artifactsJarFile = new File (' ' ' «sourceDir»/artifacts.jar' ' ' )
254+ if (artifactsXmlFile. exists) {
255+ sourceStream = new FileInputStream (artifactsXmlFile)
256+ } else if (artifactsJarFile. exists) {
257+ sourceJar = new JarFile (artifactsJarFile)
258+ val artifactsEntry = sourceJar. getEntry(' artifacts.xml' )
259+ if (artifactsEntry == = null )
260+ throw new GradleException (' P2 repository: artifacts.jar does not contain artifacts.xml' )
261+ sourceStream = sourceJar. getInputStream(artifactsEntry)
262+ } else {
263+ throw new GradleException (' P2 repository does not contain artifacts.xml or artifacts.jar' )
264+ }
248265 val builder = DocumentBuilderFactory . newInstance. newDocumentBuilder
249- val document = builder. parse(sourceJar . getInputStream(artifactsEntry) )
266+ val document = builder. parse(sourceStream )
250267 val xmlRoot = document. documentElement
251268 if (xmlRoot. tagName == ' repository' ) {
252269 for (artifacts : xmlRoot. getElements(' artifacts' )) {
@@ -268,15 +285,32 @@ class EclipsePublishing {
268285 }
269286 }
270287
271- targetJar = new JarOutputStream (new FileOutputStream (' ' ' «destDir»/artifacts.jar' ' ' ))
272- targetJar. putNextEntry(new ZipEntry (' artifacts.xml' ))
273288 val transformer = TransformerFactory . newInstance. newTransformer
274- transformer. transform(new DOMSource (document), new StreamResult (targetJar))
275- targetJar. closeEntry()
289+ if (artifactsXmlFile. exists) {
290+ targetStream = new FileOutputStream (' ' ' «destDir»/artifacts.xml' ' ' )
291+ transformer. transform(new DOMSource (document), new StreamResult (targetStream))
292+ }
293+
294+ if (artifactsJarFile. exists) {
295+ targetJar = new JarOutputStream (new FileOutputStream (' ' ' «destDir»/artifacts.jar' ' ' ))
296+ targetJar. putNextEntry(new ZipEntry (' artifacts.xml' ))
297+ transformer. transform(new DOMSource (document), new StreamResult (targetJar))
298+ targetJar. closeEntry()
299+ }
300+
301+ val artifactsXmlXzFile = new File (' ' ' «sourceDir»/artifacts.xml.xz' ' ' )
302+ if (artifactsXmlXzFile. exists) {
303+ val options = new LZMA2Options
304+ targetXz = new XZOutputStream (new FileOutputStream (' ' ' «destDir»/artifacts.xml.xz' ' ' ), options)
305+ transformer. transform(new DOMSource (document), new StreamResult (targetXz))
306+ }
276307 } finally {
277308 try {
278- sourceJar ? . close()
309+ targetXz ? . close()
279310 targetJar? . close()
311+ targetStream? . close()
312+ sourceJar? . close()
313+ sourceStream? . close()
280314 } catch (IOException e) {}
281315 }
282316 }
0 commit comments