Skip to content

Commit 1c6b906

Browse files
committed
adds compatibility to install gems with jruby > 9.2.10.x
1 parent bb80f25 commit 1c6b906

File tree

21 files changed

+658
-165
lines changed

21 files changed

+658
-165
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ target
77
tmp
88
*Backup
99
release.properties
10+
.idea/
11+
*.iml

gem-maven-plugin/src/it/include-rubygems-in-test-resources-failure/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.example</groupId>
6-
<artifactId>target/rubygems-in-test-resources</artifactId>
6+
<artifactId>rubygems-in-test-resources-failure</artifactId>
77
<version>testing</version>
88
<repositories>
99
<repository>

gem-maven-plugin/src/it/include-rubygems-in-test-resources/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<dependencies>
1515
<dependency>
1616
<groupId>rubygems</groupId>
17-
<artifactId>yard</artifactId>
18-
<version>0.8.0</version>
17+
<artifactId>sass</artifactId>
18+
<version>3.2.7</version>
1919
<type>gem</type>
2020
</dependency>
2121
<dependency>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>rubygems</groupId>
5+
<artifactId>pom_first</artifactId>
6+
<version>0.0.0</version>
7+
<description>Installs a gem from http://rubygems.org with Ruby 2.7 compatibility</description>
8+
<properties>
9+
<jruby.version>9.2.10.0</jruby.version>
10+
</properties>
11+
<dependencies>
12+
<dependency>
13+
<groupId>rubygems</groupId>
14+
<artifactId>yard</artifactId>
15+
<version>0.9.25</version>
16+
<type>gem</type>
17+
</dependency>
18+
</dependencies>
19+
<build>
20+
<extensions>
21+
<extension>
22+
<groupId>org.torquebox.mojo</groupId>
23+
<artifactId>mavengem-wagon</artifactId>
24+
<version>1.0.3</version>
25+
</extension>
26+
</extensions>
27+
<plugins>
28+
<plugin>
29+
<groupId>de.saumya.mojo</groupId>
30+
<artifactId>gem-maven-plugin</artifactId>
31+
<version>@project.version@</version>
32+
<configuration>
33+
<jrubyVersion>${jruby.version}</jrubyVersion>
34+
</configuration>
35+
<executions>
36+
<execution>
37+
<id>install-gems</id>
38+
<goals>
39+
<goal>initialize</goal>
40+
</goals>
41+
<phase>initialize</phase>
42+
</execution>
43+
</executions>
44+
</plugin>
45+
</plugins>
46+
</build>
47+
<repositories>
48+
<repository>
49+
<id>mavengems</id>
50+
<url>mavengem:http://rubygems.org</url>
51+
</repository>
52+
</repositories>
53+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import java.io.*;
2+
import org.codehaus.plexus.util.FileUtils;
3+
4+
File f = new File( basedir, "target/rubygems/gems/yard-0.9.25" );
5+
if ( !f.exists() )
6+
{
7+
throw new RuntimeException( "file does not exists: " + f );
8+
}

parent-mojo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
<plugins>
119119
<plugin>
120120
<artifactId>maven-invoker-plugin</artifactId>
121-
<version>1.5</version>
121+
<version>3.0.1</version>
122122
<configuration>
123123
<projectsDirectory>src/it</projectsDirectory>
124124
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
<version>4.8.2</version>
4242
<scope>test</scope>
4343
</dependency>
44+
<dependency>
45+
<groupId>org.assertj</groupId>
46+
<artifactId>assertj-core</artifactId>
47+
<version>3.16.1</version>
48+
<scope>test</scope>
49+
</dependency>
4450
</dependencies>
4551

4652
<repositories>

ruby-tools/src/main/java/de/saumya/mojo/ruby/gems/GemsInstaller.java

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
/**
2-
*
2+
*
33
*/
44
package de.saumya.mojo.ruby.gems;
55

6-
import java.io.File;
7-
import java.io.FileFilter;
8-
import java.io.IOException;
9-
import java.util.Collection;
10-
import java.util.List;
11-
6+
import de.saumya.mojo.ruby.script.JRubyVersion;
7+
import de.saumya.mojo.ruby.script.Script;
8+
import de.saumya.mojo.ruby.script.ScriptException;
9+
import de.saumya.mojo.ruby.script.ScriptFactory;
1210
import org.apache.maven.artifact.Artifact;
1311
import org.apache.maven.artifact.repository.ArtifactRepository;
1412
import org.apache.maven.plugin.descriptor.PluginDescriptor;
1513
import org.apache.maven.project.MavenProject;
1614
import org.codehaus.plexus.util.FileUtils;
1715

18-
import de.saumya.mojo.ruby.script.Script;
19-
import de.saumya.mojo.ruby.script.ScriptException;
20-
import de.saumya.mojo.ruby.script.ScriptFactory;
16+
import java.io.File;
17+
import java.io.FileFilter;
18+
import java.io.IOException;
19+
import java.util.Collection;
20+
import java.util.List;
21+
2122

2223
public class GemsInstaller {
2324

2425
private static final String OPENSSL_VERSION = "0.8.2";
2526
private static final String OPENSSL = "jruby-openssl";
26-
27+
2728
private static final FileFilter FILTER = new FileFilter() {
28-
29+
2930
public boolean accept(File f) {
3031
return f.getName().endsWith(".gemspec");
3132
}
3233
};
33-
34+
3435
public final GemsConfig config;
3536

3637
public final ScriptFactory factory;
@@ -54,19 +55,19 @@ public void installPom(final MavenProject pom,
5455
ScriptException, GemException {
5556
installPom(pom, localRepository, null);
5657
}
57-
58+
5859
public void installPom(final MavenProject pom,
5960
final ArtifactRepository localRepository, String scope) throws IOException,
6061
ScriptException, GemException {
6162
installGems(pom, localRepository, scope);
6263
}
63-
64+
6465
public MavenProject installOpenSSLGem(final Object repositorySystemSession,
6566
final ArtifactRepository localRepository, List<ArtifactRepository> remotes) throws GemException,
6667
IOException, ScriptException {
6768
return installGem(OPENSSL, OPENSSL_VERSION, repositorySystemSession, localRepository, remotes);
6869
}
69-
70+
7071
public MavenProject installGem(final String name, final String version,
7172
final Object repositorySystemSession,
7273
final ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories) throws GemException,
@@ -87,21 +88,21 @@ public MavenProject installGem(final String name, final String version,
8788
installPom(pom);
8889
return pom;
8990
}
90-
91+
9192
public void installGems(final MavenProject pom,
92-
final ArtifactRepository localRepository)
93+
final ArtifactRepository localRepository)
9394
throws IOException, ScriptException, GemException
9495
{
9596
installGems(pom, localRepository, null);
96-
97+
9798
}
98-
99+
99100
public void installGems(final MavenProject pom,
100-
final ArtifactRepository localRepository, String scope )
101+
final ArtifactRepository localRepository, String scope )
101102
throws IOException, ScriptException, GemException {
102103
installGems(pom, (Collection<Artifact>)null, localRepository, scope);
103104
}
104-
105+
105106
public void installGems(final MavenProject pom, PluginDescriptor plugin,
106107
final ArtifactRepository localRepository) throws IOException,
107108
ScriptException, GemException {
@@ -118,7 +119,7 @@ public void installGems(final MavenProject pom, final Collection<Artifact> artif
118119
throws IOException, ScriptException, GemException {
119120
installGems( pom, artifacts, localRepository, remoteRepos, null );
120121
}
121-
122+
122123
public void installGems(final MavenProject pom, final Collection<Artifact> artifacts,
123124
final ArtifactRepository localRepository, List<ArtifactRepository> remoteRepos,
124125
String scope ) throws IOException,
@@ -130,9 +131,9 @@ public void installGems(final MavenProject pom, final Collection<Artifact> artif
130131
boolean hasAlreadyOpenSSL = false;
131132
for (final Artifact artifact : pom.getArtifacts()) {
132133
// assume pom.getBasedir() != null indicates the project pom
133-
if ( ( "compile".equals(artifact.getScope()) ||
134+
if ( ( "compile".equals(artifact.getScope()) ||
134135
"runtime".equals(artifact.getScope()) ||
135-
pom.getBasedir() != null ) &&
136+
pom.getBasedir() != null ) &&
136137
( scope == null || scope.equals(artifact.getScope()) ) ) {
137138
if (!artifact.getFile().exists()) {
138139
this.manager.resolve(artifact,
@@ -160,7 +161,7 @@ public void installGems(final MavenProject pom, final Collection<Artifact> artif
160161
}
161162
if ( pom.getArtifact().getFile() != null
162163
// to filter out target/classes
163-
&& pom.getArtifact().getFile().isFile()
164+
&& pom.getArtifact().getFile().isFile()
164165
// have only gem files
165166
&& pom.getArtifact().getFile().getName().endsWith(".gem") ) {
166167
script = maybeAddArtifact(script, pom.getArtifact());
@@ -194,7 +195,7 @@ public void installGems(final MavenProject pom, final Collection<Artifact> artif
194195
this.config.getBinDirectory().mkdirs();
195196
}
196197
script.execute();
197-
198+
198199
if (this.config.getGemHome() != null){
199200
// workaround for unpatched: https://github.com/rubygems/rubygems/commit/21cccd55b823848c5e941093a615b0fdd6cd8bc7
200201
for(File spec : new File(this.config.getGemHome(), "specifications").listFiles(FILTER)){
@@ -227,21 +228,26 @@ private boolean exists(Artifact artifact) {
227228
}
228229
return false;
229230
}
230-
231+
231232
private Script maybeAddArtifact(Script script, final Artifact artifact)
232233
throws IOException, GemException {
233234
if (artifact.getType().contains("gem")) {
234235
if (!exists(artifact)) {
235236
if (script == null) {
237+
236238
script = this.factory.newScriptFromJRubyJar("gem")
237239
.addArg("install")
238240
.addArg("--ignore-dependencies")
239-
.addArg(booleanArg(this.config.isAddRdoc(), "rdoc"))
240-
.addArg(booleanArg(this.config.isAddRI(), "ri"))
241-
.addArg(booleanArg(this.config.isUserInstall(),
242-
"user-install"))
243-
.addArg(booleanArg(this.config.isVerbose(),
244-
"verbose"));
241+
.addArg(booleanArg(this.config.isUserInstall(), "user-install"))
242+
.addArg(booleanArg(this.config.isVerbose(), "verbose"));
243+
244+
final JRubyVersion version = this.getVersion();
245+
if (version == null || version.isLanguageLowerThan(2,6)) {
246+
script.addArg(booleanArg(this.config.isAddRdoc(), "rdoc"))
247+
.addArg(booleanArg(this.config.isAddRI(), "ri"));
248+
} else {
249+
script.addArg(booleanArg(this.config.isAddRdoc(), "document"));
250+
}
245251
}
246252
if (artifact.getFile() != null)
247253
{
@@ -252,6 +258,14 @@ private Script maybeAddArtifact(Script script, final Artifact artifact)
252258
return script;
253259
}
254260

261+
private JRubyVersion getVersion() {
262+
try {
263+
return this.factory.getVersion();
264+
} catch (Exception e) {
265+
return null;
266+
}
267+
}
268+
255269
private String booleanArg(final boolean flag, final String name) {
256270
return "--" + (flag ? "" : "no-") + name;
257271
}

ruby-tools/src/main/java/de/saumya/mojo/ruby/rails/RailsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class RailsService {
1616
private final GemsInstaller installer;
1717
private final RailsManager manager;
1818
private final RailsState state;
19-
private final Object session;
19+
private Object session;
2020

2121
public RailsService(final RailsState state,
2222
final Object repositorySystemSession,

ruby-tools/src/main/java/de/saumya/mojo/ruby/script/AbstractLauncher.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,67 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.io.OutputStream;
56
import java.util.List;
67

78
abstract class AbstractLauncher implements Launcher {
89

910
protected abstract void doExecute(final File launchDirectory,
10-
final List<String> args, final File outputFile)
11+
final List<String> args, final File outputFile)
12+
throws ScriptException, IOException;
13+
14+
protected abstract void doExecute(final File launchDirectory,
15+
final List<String> args, final OutputStream outputStream)
1116
throws ScriptException, IOException;
1217

1318
public void execute(final List<String> args) throws ScriptException,
1419
IOException {
15-
doExecute(null, args, null);
20+
doExecute(null, args, (File) null);
1621
}
1722

1823
public void execute(final List<String> args, final File outputFile)
1924
throws ScriptException, IOException {
2025
doExecute(null, args, outputFile);
2126
}
2227

28+
public void execute(final List<String> args, final OutputStream outputStream)
29+
throws ScriptException, IOException {
30+
doExecute(null, args, outputStream);
31+
}
32+
2333
public void executeIn(final File launchDirectory, final List<String> args)
2434
throws ScriptException, IOException {
25-
doExecute(launchDirectory, args, null);
35+
doExecute(launchDirectory, args, (File) null);
2636
}
2737

2838
public void executeIn(final File launchDirectory, final List<String> args,
29-
final File outputFile) throws ScriptException, IOException {
39+
final File outputFile) throws ScriptException, IOException {
3040
doExecute(launchDirectory, args, outputFile);
3141
}
3242

43+
public void executeIn(final File launchDirectory, final List<String> args,
44+
final OutputStream outputStream) throws ScriptException, IOException {
45+
doExecute(launchDirectory, args, outputStream);
46+
}
47+
3348
public void executeScript(final String script, final List<String> args)
3449
throws ScriptException, IOException {
35-
executeScript(script, args, null);
50+
executeScript(script, args, (File) null);
3651
}
3752

3853
public void executeScript(final String script, final List<String> args,
39-
final File outputFile) throws ScriptException, IOException {
54+
final File outputFile) throws ScriptException, IOException {
4055
executeScript(null, script, args, outputFile);
4156
}
4257

58+
public void executeScript(final String script, final List<String> args,
59+
final OutputStream outputStream) throws ScriptException, IOException {
60+
executeScript(null, script, args, outputStream);
61+
}
62+
4363
public void executeScript(final File launchDirectory, final String script,
44-
final List<String> args) throws ScriptException, IOException {
45-
executeScript(launchDirectory, script, args, null);
64+
final List<String> args) throws ScriptException, IOException {
65+
executeScript(launchDirectory, script, args, (File) null);
4666
}
67+
4768
}

0 commit comments

Comments
 (0)