@@ -25,47 +25,6 @@ class GemUtils {
25
25
}
26
26
}
27
27
28
- /* * Extract a gem to the default {@code gemInstallDir} dreictory using the default jruby version
29
- *
30
- * @param project Current project
31
- * @param gem GEM to extract
32
- */
33
- static void extractGem (Project project , File gem ) {
34
- extractGem(project,gem,new File (project. jruby. gemInstallDir),GemUtils.OverwriteAction . SKIP )
35
- }
36
-
37
- /* * Extracts a gem to a folder using the default JRuby version
38
- *
39
- * @param project Project instance
40
- * @param gem Gem file to extract
41
- * @param destDir Directory to extract to
42
- * @param overwrite Allow overwrite of an existing gem folder
43
- */
44
- static void extractGem (Project project ,
45
- File gem ,
46
- File destDir ,
47
- GemUtils.OverwriteAction overwrite ) {
48
- extractGem(project,project. configurations. jrubyExec,gem,destDir,overwrite)
49
- }
50
-
51
- /* * Extracts a gem to a folder
52
- *
53
- * @param project Project instance
54
- * @param jRubyConfig Where to find the jruby-complete jar (FileCollection, File or Configuration)
55
- * @param gem Gem file to extract
56
- * @param destDir Directory to extract to
57
- * @param overwrite Allow overwrite of an existing gem folder
58
- */
59
- static void extractGem (Project project ,
60
- Configuration jRubyConfig ,
61
- File gem ,
62
- File destDir ,
63
- GemUtils.OverwriteAction overwrite ) {
64
- Set<File > cp = jRubyConfig. files
65
- File jRubyClasspath = cp. find { it. name. startsWith(' jruby-complete-' ) }
66
- extractGem(project,jRubyClasspath,gem,destDir,overwrite)
67
- }
68
-
69
28
/* * Extracts a gem to a folder
70
29
*
71
30
* @param project Project instance
@@ -79,45 +38,76 @@ class GemUtils {
79
38
File gem ,
80
39
File destDir ,
81
40
GemUtils.OverwriteAction overwrite ) {
82
- String gemName = gemFullNameFromFile(gem. name)
83
- File extractDir = new File (destDir, gemName)
84
41
85
- if (extractDir. exists()) {
42
+ extractGems(project,jRubyClasspath,project. files(gem),destDir,overwrite)
43
+ }
44
+
45
+ static void extractGems (Project project ,
46
+ File jRubyClasspath ,
47
+ FileCollection gems ,
48
+ File destDir ,
49
+ GemUtils.OverwriteAction overwrite ) {
50
+ Set<File > gemsToProcess = []
51
+ Set<File > deletes = []
52
+ getGems(gems). files. each { File gem ->
53
+ String gemName = gemFullNameFromFile(gem. name)
54
+ File extractDir = new File (destDir, gemName)
55
+
86
56
switch (overwrite) {
87
57
case GemUtils.OverwriteAction . SKIP :
88
- return
58
+ if (extractDir. exists()) {
59
+ return
60
+ }
89
61
case GemUtils.OverwriteAction . OVERWRITE :
90
- project . delete extractDir
62
+ deletes . add( extractDir)
91
63
break
92
64
case GemUtils.OverwriteAction . FAIL :
93
- throw new DuplicateFileCopyingException (" Gem ${ gem.name} already exists" )
65
+ if (extractDir. exists()) {
66
+ throw new DuplicateFileCopyingException (" Gem ${ gem.name} already exists" )
67
+ }
94
68
}
69
+
70
+ gemsToProcess. add(gem)
95
71
}
96
72
97
- destDir. mkdirs()
73
+ if (gemsToProcess. size()) {
74
+
75
+ deletes. each { project. delete it }
76
+ destDir. mkdirs()
77
+
78
+ project. logger. info " Installing " + (gemsToProcess. collect { File it -> it. name }). join(' ,' )
98
79
99
- project. javaexec {
100
- setEnvironment [:]
101
- main ' org.jruby.Main'
102
- classpath jRubyClasspath
103
- args ' -S' , ' gem' , ' install' , gem, ' --ignore-dependencies' , " --install-dir=${ destDir.absolutePath} " , ' -N'
80
+ project. javaexec {
81
+ setEnvironment [:]
82
+ main ' org.jruby.Main'
83
+ classpath jRubyClasspath
84
+ args ' -S' , ' gem' , ' install'
85
+ gemsToProcess. each { File gem ->
86
+ args gem
87
+ }
88
+ args ' --ignore-dependencies' , " --install-dir=${ destDir.absolutePath} " , ' -N'
89
+ }
104
90
}
105
91
}
106
92
107
93
/* * Extract Gems from a given configuration.
108
94
*
109
- * @param project Current project
110
- * @param jRubyClasspath
111
- * @param gemConfig
112
- * @param destDir
113
- * @param action
95
+ * @param project Project instance
96
+ * @param jRubyClasspath Where to find the jruby-complete jar
97
+ * @param gemConfig Configuration containing GEMs
98
+ * @param destDir Directory to extract to
99
+ * @param action Allow overwrite of an existing gem folder
114
100
*/
115
- static void extractGems (Project project ,Configuration jRubyClasspath , Configuration gemConfig ,File destDir ,GemUtils.OverwriteAction action ) {
116
- getGems(project. files(gemConfig. files)). each { File f ->
117
- GemUtils . extractGem(project,jRubyClasspath,f,destDir,action)
118
- }
119
-
101
+ static void extractGems (
102
+ Project project ,
103
+ Configuration jRubyConfig ,
104
+ Configuration gemConfig ,
105
+ File destDir ,
106
+ GemUtils.OverwriteAction action ) {
120
107
108
+ Set<File > cp = jRubyConfig. files
109
+ File jRubyClasspath = cp. find { it. name. startsWith(' jruby-complete-' ) }
110
+ extractGems(project,jRubyClasspath,project. files(gemConfig. files),destDir,action)
121
111
}
122
112
123
113
/* * Take the given .gem filename (e.g. rake-10.3.2.gem) and just return the
0 commit comments