2015-08-14 00:31:40 +00:00
|
|
|
package com.github.jrubygradle.jem;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GemInstaller manages the installation of a .gem file into a given directory
|
|
|
|
*/
|
|
|
|
public class GemInstaller {
|
|
|
|
public static enum DuplicateBehavior {
|
|
|
|
OVERWRITE,
|
|
|
|
SKIP,
|
|
|
|
FAIL
|
|
|
|
};
|
|
|
|
|
|
|
|
protected com.github.jrubygradle.jem.internal.GemInstaller impl;
|
2015-09-18 22:10:34 +00:00
|
|
|
protected GemInstallEvent callback;
|
2015-08-14 00:31:40 +00:00
|
|
|
|
2015-08-22 01:32:52 +00:00
|
|
|
/**
|
|
|
|
* Create an installer with the given installation directory and a single gem
|
|
|
|
*
|
2015-09-18 22:31:15 +00:00
|
|
|
* @param installDir relative or absoluate path to the installation destination directory
|
|
|
|
* @param gemPath relative or absolute path to the gem to be installed
|
2015-08-22 01:32:52 +00:00
|
|
|
*/
|
2015-08-14 00:31:40 +00:00
|
|
|
public GemInstaller(String installDir, String gemPath) {
|
|
|
|
this(installDir, new File(gemPath));
|
|
|
|
}
|
|
|
|
|
2015-08-22 01:32:52 +00:00
|
|
|
/**
|
|
|
|
* Create an installer with the given installation directory and a single gem
|
|
|
|
*
|
2015-09-18 22:31:15 +00:00
|
|
|
* @param installDir relative or absoluate path to the installation destination directory
|
|
|
|
* @param gemFile File object for the gem to be installed
|
2015-08-22 01:32:52 +00:00
|
|
|
*/
|
2015-08-14 00:31:40 +00:00
|
|
|
public GemInstaller(String installDir, File gemFile) {
|
|
|
|
this(installDir, Arrays.asList(gemFile));
|
|
|
|
}
|
|
|
|
|
2015-08-22 01:32:52 +00:00
|
|
|
/**
|
|
|
|
* Create an installer with the given installation directory and a list of gems
|
|
|
|
*
|
2015-09-18 22:31:15 +00:00
|
|
|
* @param installDir relative or absoluate path to the installation destination directory
|
|
|
|
* @param gemPaths List of File objects for gems to be installed
|
2015-08-22 01:32:52 +00:00
|
|
|
*/
|
2015-08-14 00:31:40 +00:00
|
|
|
public GemInstaller(String installDir, List<File> gemPaths) {
|
|
|
|
impl = new com.github.jrubygradle.jem.internal.GemInstaller(installDir, gemPaths);
|
|
|
|
}
|
|
|
|
|
2015-08-22 01:32:52 +00:00
|
|
|
/**
|
|
|
|
* Inject a custom GemInstaller implementation that adheres to the private internal API.
|
|
|
|
*
|
|
|
|
* Chances are you do not want this constructor, which is largely used for unit testing!
|
|
|
|
*
|
2015-09-18 22:31:15 +00:00
|
|
|
* @param implementation An internal GemInstaller implementation to use for the public API
|
2015-08-22 01:32:52 +00:00
|
|
|
*/
|
|
|
|
public GemInstaller(com.github.jrubygradle.jem.internal.GemInstaller implementation) {
|
|
|
|
impl = implementation;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Install the gems in the configured installation directory with all
|
|
|
|
* the default settings
|
|
|
|
*/
|
2015-08-14 00:31:40 +00:00
|
|
|
public void install() {
|
|
|
|
impl.install();
|
|
|
|
}
|
2015-08-22 01:32:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Install the gems in the configuration installation directory with the given
|
|
|
|
* overwrite setting
|
|
|
|
*
|
2015-09-18 22:31:15 +00:00
|
|
|
* @param overwriteBehavior Flag to determine what behavior should be taken on overwriting existing gems
|
2015-08-22 01:32:52 +00:00
|
|
|
*/
|
|
|
|
public void install(DuplicateBehavior overwriteBehavior) {
|
|
|
|
impl.install(overwriteBehavior);
|
|
|
|
}
|
2015-09-18 22:10:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
public void install(GemInstallEvent eventCallback) {
|
|
|
|
impl.install(eventCallback, DuplicateBehavior.OVERWRITE);
|
|
|
|
}
|
2015-08-14 00:31:40 +00:00
|
|
|
}
|