mirror of https://github.com/jruby-gradle/jem
Starting to implement install() by plopping the gem into the cache/ directory
This commit is contained in:
parent
acdf4b78e5
commit
5cef41e08f
|
@ -29,6 +29,8 @@ dependencies {
|
|||
codenarc "org.codenarc:CodeNarc:0.24"
|
||||
|
||||
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
|
||||
/* used for cleaning up directories in tests */
|
||||
testCompile 'org.apache.commons:commons-io:1.3.2+'
|
||||
}
|
||||
|
||||
codenarc {
|
||||
|
|
|
@ -7,6 +7,12 @@ import groovy.transform.CompileStatic
|
|||
*/
|
||||
@CompileStatic
|
||||
class GemInstaller {
|
||||
static enum DuplicateBehavior {
|
||||
OVERWRITE,
|
||||
SKIP,
|
||||
FAIL
|
||||
}
|
||||
|
||||
protected File installDirectory
|
||||
protected List<File> gems
|
||||
|
||||
|
|
|
@ -9,6 +9,10 @@ import org.slf4j.LoggerFactory
|
|||
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
import com.github.jrubygradle.groovygem.GemInstaller.DuplicateBehavior
|
||||
|
||||
import java.nio.file.Files
|
||||
|
||||
@CompileStatic
|
||||
class GemInstaller {
|
||||
static final List<String> GEM_HOME_DIRS = ['bin', 'build_info', 'cache', 'doc',
|
||||
|
@ -25,6 +29,27 @@ class GemInstaller {
|
|||
this.fileSystemManager = VFS.manager
|
||||
}
|
||||
|
||||
/** Install and overwrite anything that stands in the way */
|
||||
void install() {
|
||||
install(DuplicateBehavior.OVERWRITE)
|
||||
}
|
||||
|
||||
void install(DuplicateBehavior onDuplicateBehavior) {
|
||||
if (!mkdirs()) {
|
||||
/* raise some exception? */
|
||||
}
|
||||
|
||||
gems.each { File gem ->
|
||||
installGem(installDirectory, gem, onDuplicateBehavior)
|
||||
}
|
||||
}
|
||||
|
||||
boolean installGem(File installDir, File gem, DuplicateBehavior onDuplicate) {
|
||||
cacheGemInInstallDir(installDir, gem)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the requisite directories to map a GEM_HOME structure, namely:
|
||||
* bin/
|
||||
|
@ -80,4 +105,10 @@ class GemInstaller {
|
|||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** Cache the gem in GEM_HOME/cache */
|
||||
protected void cacheGemInInstallDir(File installDir, File gem) {
|
||||
File cacheDir = new File(installDir, 'cache')
|
||||
Files.copy(gem.toPath(), (new File(cacheDir, gem.name)).toPath())
|
||||
}
|
||||
}
|
|
@ -4,10 +4,12 @@ import spock.lang.*
|
|||
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import org.apache.commons.io.FileUtils
|
||||
|
||||
class GemInstallerSpec extends Specification {
|
||||
final String FIXTURES_ROOT = new File(['src', 'test', 'resources'].join(File.separator)).absolutePath
|
||||
final String GEM_FIXTURE = [FIXTURES_ROOT, 'thor-0.19.1.gem'].join(File.separator)
|
||||
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_FIXTURE = [FIXTURES_ROOT, GEM_FILENAME].join(File.separator)
|
||||
|
||||
GemInstaller installer
|
||||
Path installDirPath = Files.createTempDirectory("geminstallerspec")
|
||||
|
@ -67,3 +69,30 @@ class GemInstallerSpec extends Specification {
|
|||
installer.isValidGem(gem)
|
||||
}
|
||||
}
|
||||
|
||||
class GemInstallerIntegrationSpec extends Specification {
|
||||
GemInstaller installer
|
||||
|
||||
Path installDirPath = Files.createTempDirectory("geminstallerintegrationspec")
|
||||
String installDir = installDirPath as String
|
||||
|
||||
def setup() {
|
||||
installer = new GemInstaller(installDir, [new File(GemInstallerSpec.GEM_FIXTURE)])
|
||||
}
|
||||
|
||||
def cleanup() {
|
||||
File dir = new File(installDir)
|
||||
|
||||
if (dir.exists() && dir.absolutePath.startsWith('/tmp')) {
|
||||
FileUtils.deleteDirectory(dir)
|
||||
}
|
||||
}
|
||||
|
||||
def "install() should actually install my gem in the happy path"() {
|
||||
when:
|
||||
installer.install()
|
||||
|
||||
then:
|
||||
(new File(installDir, ['cache', GemInstallerSpec.GEM_FILENAME].join(File.separator))).exists()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue