final ArtifactRepository localRepository, List<ArtifactRepository> remoteRepos,
String scope ) throws IOException,
ScriptException, GemException {
// start without script object.
// script object will be created when first un-installed gem is found
Script script = null;
if (pom != null) {
boolean hasAlreadyOpenSSL = false;
for (final Artifact artifact : pom.getArtifacts()) {
// assume pom.getBasedir() != null indicates the project pom
if ( ( "compile".equals(artifact.getScope()) ||
"runtime".equals(artifact.getScope()) ||
pom.getBasedir() != null ) &&
( scope == null || scope.equals(artifact.getScope()) ) ) {
if (!artifact.getFile().exists()) {
this.manager.resolve(artifact,
localRepository,
remoteRepos);
}
script = maybeAddArtifact(script, artifact);
hasAlreadyOpenSSL = hasAlreadyOpenSSL
|| artifact.getArtifactId().equals(OPENSSL);
}
}
if (artifacts != null) {
for (final Artifact artifact : artifacts) {
if (!artifact.getFile().exists()) {
this.manager.resolve(artifact,
localRepository,
remoteRepos);
}
script = maybeAddArtifact(script, artifact);
hasAlreadyOpenSSL = hasAlreadyOpenSSL
|| artifact.getArtifactId().equals(OPENSSL);
}
}
if ( pom.getArtifact().getFile() != null
// to filter out target/classes
&& pom.getArtifact().getFile().isFile()
// have only gem files
&& pom.getArtifact().getFile().getName().endsWith(".gem") ) {
script = maybeAddArtifact(script, pom.getArtifact());
}
if (!this.config.skipJRubyOpenSSL() && !hasAlreadyOpenSSL && script != null) {
// keep the version hard-coded to stay reproducible
final Artifact openssl = this.manager.createGemArtifact(OPENSSL,
OPENSSL_VERSION);
if (pom.getFile() == null) {
// we do not have a pom so we need the default gems repo
this.manager.addDefaultGemRepositories(remoteRepos);
}
for(Artifact a : this.manager.resolve(openssl,
localRepository,
remoteRepos, true) ) {
if (a.getFile() == null || !a.getFile().exists()) {
this.manager.resolve(a,
localRepository,
remoteRepos);
}
script = maybeAddArtifact(script, a);
}
}
}
if (script != null) {
script.addArg("--bindir", this.config.getBinDirectory());
if(this.config.getBinDirectory() != null && !this.config.getBinDirectory().exists()){
this.config.getBinDirectory().mkdirs();
}
script.execute();
if (this.config.getGemHome() != null){
// workaround for unpatched: https://github.com/rubygems/rubygems/commit/21cccd55b823848c5e941093a615b0fdd6cd8bc7
for(File spec : new File(this.config.getGemHome(), "specifications").listFiles(FILTER)){
String content = FileUtils.fileRead(spec);