Skip to content

Commit 908516c

Browse files
author
R. Tyler Croy
committed
Merge pull request #52 from ysb33r/master
Added a gemCopySpec utility function
2 parents 5989e72 + 15a0613 commit 908516c

File tree

3 files changed

+158
-5
lines changed

3 files changed

+158
-5
lines changed

src/main/groovy/com/github/jrubygradle/GemUtils.groovy

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.jrubygradle
22

33
import org.gradle.api.Project
44
import org.gradle.api.artifacts.Configuration
5+
import org.gradle.api.file.CopySpec
56
import org.gradle.api.file.DuplicateFileCopyingException
67
import org.gradle.api.file.FileCollection
78

@@ -124,4 +125,38 @@ class GemUtils {
124125
static String gemFullNameFromFile(String filename) {
125126
return filename.replaceAll(~".gem", "")
126127
}
128+
129+
/** Adds a GEM CopySpec to an archive
130+
*
131+
* The following are supported as properties:
132+
* <ul>
133+
* <li>fullGem (boolean) - Copy all of the GEM content, not just a minimal subset</li>
134+
* <li>subfolder (Object) - Adds an additional subfolder into the GEM
135+
* </ul>
136+
*
137+
* @param Additional properties to control behaviour
138+
* @param dir The source of the GEM files
139+
* @return Returns a CopySpec which can be attached as a child to another object that implements a CopySpec
140+
* @since 0.1.2
141+
*/
142+
static CopySpec gemCopySpec(def properties=[:],Project project,Object dir) {
143+
boolean fullGem=false
144+
if(properties.containsKey('fullGem')) {
145+
fullGem = properties['fullGem']
146+
}
147+
project.copySpec {
148+
from(dir) {
149+
include '**'
150+
if(!fullGem) {
151+
exclude 'cache/**'
152+
exclude 'gems/*/test/**'
153+
exclude 'build_info'
154+
}
155+
}
156+
157+
if(properties.containsKey('subfolder')) {
158+
into properties['subfolder']
159+
}
160+
}
161+
}
127162
}

src/main/groovy/com/github/jrubygradle/JRubyPlugin.groovy

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ class JRubyPlugin implements Plugin<Project> {
2424
}
2525

2626
// Set up a special configuration group for our embedding jars
27-
project.configurations {
28-
jrubyEmbeds
29-
gems
30-
}
31-
27+
project.configurations.create('gems')
28+
project.configurations.create('jrubyEmbeds')
3229
project.configurations.create(JRubyExec.JRUBYEXEC_CONFIG)
3330
JRubyExecDelegate.addToProject(project)
3431

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package com.github.jrubygradle
2+
3+
import org.gradle.testfixtures.ProjectBuilder
4+
import spock.lang.*
5+
6+
7+
/**
8+
* @author Schalk W. Cronjé
9+
*/
10+
class GemUtilsSpec extends Specification {
11+
12+
static final File TESTROOT = new File("${System.getProperty('TESTROOT') ?: 'build/tmp/test/unittests'}/gus")
13+
14+
def project
15+
File src = new File(TESTROOT,'src')
16+
File dest = new File(TESTROOT,'dest')
17+
File fakeGem = new File(src,'gems/mygem-1.0')
18+
19+
void setup() {
20+
project = ProjectBuilder.builder().build()
21+
project.buildDir = TESTROOT
22+
23+
if(TESTROOT.exists()) {
24+
TESTROOT.deleteDir()
25+
}
26+
src.mkdirs()
27+
dest.mkdirs()
28+
29+
/* Creating a folder structure that should look like
30+
* src
31+
* src/cache
32+
* src/cache/cache.txt
33+
* src/gems
34+
* src/gems/mygem-1.0/fake.txt
35+
* src/gems/mygem-1.0/test
36+
* src/gems/mygem-1.0/test/test.txt
37+
*/
38+
new File(fakeGem,'test').mkdirs()
39+
new File(fakeGem,'fake.txt').text = 'fake.content'
40+
new File(fakeGem,'test/test.txt').text = 'test.content'
41+
42+
new File(src,'cache').mkdirs()
43+
new File(src,'cache/cache.txt').text = 'cache.content'
44+
}
45+
46+
def "Attach a fake gem folder to a copy command"() {
47+
when:
48+
project.copy {
49+
into dest
50+
51+
with GemUtils.gemCopySpec(project,src)
52+
}
53+
54+
then:
55+
new File(dest,'gems/mygem-1.0/fake.txt').exists()
56+
!new File(dest,'gems/mygem-1.0/test/test.txt').exists()
57+
!new File(dest,'cache').exists()
58+
}
59+
60+
def "Attach a fake gem folder to a copy command with fullGem=false"() {
61+
when:
62+
project.copy {
63+
into dest
64+
65+
with GemUtils.gemCopySpec(project,src,fullGem:false)
66+
}
67+
68+
then:
69+
new File(dest,'gems/mygem-1.0/fake.txt').exists()
70+
!new File(dest,'gems/mygem-1.0/test/test.txt').exists()
71+
!new File(dest,'cache').exists()
72+
}
73+
74+
def "Attach a fake gem folder to a copy command with subfolder"() {
75+
when:
76+
project.copy {
77+
into dest
78+
79+
with GemUtils.gemCopySpec(project,src,subfolder:'foo')
80+
}
81+
82+
then:
83+
!new File(dest,'gems/mygem-1.0/fake.txt').exists()
84+
!new File(dest,'gems/mygem-1.0/test/test.txt').exists()
85+
!new File(dest,'cache').exists()
86+
new File(dest,'foo/gems/mygem-1.0/fake.txt').exists()
87+
!new File(dest,'foo/gems/mygem-1.0/test/test.txt').exists()
88+
!new File(dest,'foo/cache').exists()
89+
}
90+
91+
def "Attach a fake gem folder to a copy command with fullGem=true"() {
92+
when:
93+
project.copy {
94+
into dest
95+
96+
with GemUtils.gemCopySpec( project, src, fullGem : true )
97+
}
98+
99+
then: "Expecting test and cache folders to be copied"
100+
new File(dest,'gems/mygem-1.0/fake.txt').exists()
101+
new File(dest,'gems/mygem-1.0/test/test.txt').exists()
102+
new File(dest,'cache/cache.txt').exists()
103+
}
104+
105+
def "Attach a fake gem folder to a copy command with subfolder and fullGem=true"() {
106+
when:
107+
project.copy {
108+
into dest
109+
110+
with GemUtils.gemCopySpec(project,src,subfolder:'foo',fullGem:true)
111+
}
112+
113+
then:
114+
!new File(dest,'gems/mygem-1.0/fake.txt').exists()
115+
!new File(dest,'gems/mygem-1.0/test/test.txt').exists()
116+
!new File(dest,'cache').exists()
117+
new File(dest,'foo/gems/mygem-1.0/fake.txt').exists()
118+
new File(dest,'foo/gems/mygem-1.0/test/test.txt').exists()
119+
new File(dest,'foo/cache').exists()
120+
}
121+
}

0 commit comments

Comments
 (0)