mirror of https://github.com/jruby-gradle/jem
Extract specifications and executables from the gem package
This commit is contained in:
parent
9eb78bba76
commit
34b6e0c2e6
|
@ -1,8 +1,12 @@
|
|||
package com.github.jrubygradle.groovygem.internal
|
||||
|
||||
import org.apache.commons.io.IOUtils
|
||||
import org.apache.commons.vfs2.AllFileSelector
|
||||
import org.apache.commons.vfs2.FileFilter
|
||||
import org.apache.commons.vfs2.FileFilterSelector
|
||||
import org.apache.commons.vfs2.FileNotFolderException
|
||||
import org.apache.commons.vfs2.FileObject
|
||||
import org.apache.commons.vfs2.FileSelectInfo
|
||||
import org.apache.commons.vfs2.FileSystemManager
|
||||
import org.apache.commons.vfs2.VFS
|
||||
import org.slf4j.Logger
|
||||
|
@ -64,7 +68,9 @@ class GemInstaller {
|
|||
FileObject dataTar = fileSystemManager.resolveFile("tgz:${tempTar}")
|
||||
logger.info("The contents of our data.tar.gz: ${dataTar.children}")
|
||||
|
||||
extractSpecification(installDir, dataTar, gemMetadata)
|
||||
extractSpecification(installDir, gemMetadata)
|
||||
extractData(installDir, dataTar, gemMetadata)
|
||||
extractExecutables(installDir, dataTar, gemMetadata)
|
||||
|
||||
//FileObject metadata = fileSystemManager.resolveFile("gz:tar:${gem.absolutePath}!/metadata.gz!metadata")
|
||||
//StringWriter writer = new StringWriter()
|
||||
|
@ -135,13 +141,24 @@ class GemInstaller {
|
|||
Files.copy(gem.toPath(), (new File(cacheDir, gem.name)).toPath())
|
||||
}
|
||||
|
||||
/** Extract the gemspec file from the dataTarGz provided into the ${installDir}/specifications */
|
||||
protected void extractSpecification(File installDir, FileObject dataTarGz, Gem gem) {
|
||||
FileObject gemspec = dataTarGz.getChild("${gem.name}.gemspec")
|
||||
String outputFile = "${gem.name}-${gem.version}.gemspec"
|
||||
/** Extract the gemspec file from the {@code Gem} provided into the ${installDir}/specifications */
|
||||
protected void extractSpecification(File installDir, Gem gem) {
|
||||
String outputFileName = "${gem.name}-${gem.version.version}.gemspec"
|
||||
FileObject outputFile = fileSystemManager.resolveFile(new File(installDir, 'specifications'), outputFileName)
|
||||
|
||||
File specification = new File(installDir, ['specifications', outputFile].join(File.separator))
|
||||
PrintWriter writer = new PrintWriter(outputFile.content.outputStream)
|
||||
writer.write(gem.toRuby())
|
||||
writer.flush()
|
||||
}
|
||||
|
||||
IOUtils.copy(gemspec.content.inputStream, specification.newOutputStream())
|
||||
protected void extractData(File installDir, FileObject dataTarGz, Gem gem) {
|
||||
String dir = "${gem.name}-${gem.version.version}"
|
||||
FileObject outputDir = fileSystemManager.resolveFile(new File(installDir, 'gems'), dir)
|
||||
outputDir.copyFrom(dataTarGz, new AllFileSelector())
|
||||
}
|
||||
|
||||
protected void extractExecutables(File installDir, FileObject dataTarGz, Gem gem) {
|
||||
FileObject binObject = fileSystemManager.resolveFile(installDir, 'bin')
|
||||
binObject.copyFrom(dataTarGz.getChild(gem.bindir), new AllFileSelector())
|
||||
}
|
||||
}
|
|
@ -8,7 +8,8 @@ import org.apache.commons.io.FileUtils
|
|||
|
||||
class GemInstallerSpec extends Specification {
|
||||
static final String FIXTURES_ROOT = new File(['src', 'test', 'resources'].join(File.separator)).absolutePath
|
||||
static final String GEM_FILENAME = 'thor-0.19.1.gem'
|
||||
static final String GEM_NAME = 'thor-0.19.1'
|
||||
static final String GEM_FILENAME = "${GEM_NAME}.gem"
|
||||
static final String GEM_FIXTURE = [FIXTURES_ROOT, GEM_FILENAME].join(File.separator)
|
||||
|
||||
GemInstaller installer
|
||||
|
@ -84,6 +85,7 @@ class GemInstallerIntegrationSpec extends Specification {
|
|||
File dir = new File(installDir)
|
||||
|
||||
if (dir.exists() && dir.absolutePath.startsWith('/tmp')) {
|
||||
println dir
|
||||
FileUtils.deleteDirectory(dir)
|
||||
}
|
||||
}
|
||||
|
@ -96,6 +98,17 @@ class GemInstallerIntegrationSpec extends Specification {
|
|||
(new File(installDir, ['cache', GemInstallerSpec.GEM_FILENAME].join(File.separator))).exists()
|
||||
|
||||
and: "the ${installDir}/specifications dir should contain the gemspec"
|
||||
(new File(installDir, ['specifications', "${GemInstallerSpec.GEM_FILENAME}spec"].join(File.separator))).exists()
|
||||
File specification = new File(installDir, ['specifications', "${GemInstallerSpec.GEM_NAME}.gemspec"].join(File.separator))
|
||||
specification.isFile()
|
||||
specification.size() > 0
|
||||
|
||||
and: "the ${installDir}/gems/ directory should contain an extract of data.tar.gz"
|
||||
File outputDir = new File(installDir, ['gems', GemInstallerSpec.GEM_NAME].join(File.separator))
|
||||
outputDir.isDirectory()
|
||||
(new File(outputDir, "thor.gemspec")).isFile()
|
||||
|
||||
and: "the executable should be placed in ${installDir}/bin"
|
||||
File binFile = new File(installDir, ['bin', 'thor'].join(File.separator))
|
||||
binFile.isFile()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue