@@ -31,8 +31,8 @@ import org.gradle.api.Action
31
31
import org.gradle.api.Project
32
32
import org.gradle.api.artifacts.repositories.ArtifactRepository
33
33
import org.gradle.api.artifacts.repositories.IvyArtifactRepository
34
- import org.gradle.api.artifacts.repositories.MavenArtifactRepository
35
34
import org.gradle.util.GradleVersion
35
+ import org.ysb33r.grolifant.api.ClosureUtils
36
36
37
37
/* * Extension which can be added to {@code project.repositories}.
38
38
*
@@ -60,7 +60,31 @@ class RepositoryHandlerExtension {
60
60
* @return Artifact repository.
61
61
*/
62
62
ArtifactRepository gems () {
63
- bindRepositoryToProxyServer(' https://rubygems.org' . toURI(), DEFAULT_GROUP_NAME )
63
+ bindRepositoryToProxyServer(
64
+ RUBYGEMS_URI ,
65
+ DEFAULT_GROUP_NAME ,
66
+ new GemRepositoryConfiguration ()
67
+ )
68
+ }
69
+
70
+ /* * Create an artifact repository which will use {@link https://rubygems.org} and
71
+ * associate group {@code rubygems} with it.
72
+ *
73
+ * @param cfg GEM repository configuration
74
+ * @return Artifact repository.
75
+ */
76
+ ArtifactRepository gems (@DelegatesTo (GemRepositoryConfiguration ) Closure cfg ) {
77
+ bindRepositoryToProxyServer(RUBYGEMS_URI , DEFAULT_GROUP_NAME , cfg)
78
+ }
79
+
80
+ /* * Create an artifact repository which will use {@link https://rubygems.org} and
81
+ * associate group {@code rubygems} with it.
82
+ *
83
+ * @param cfg GEM repository configuration
84
+ * @return Artifact repository.
85
+ */
86
+ ArtifactRepository gems (Action<GemRepositoryConfiguration > cfg ) {
87
+ bindRepositoryToProxyServer(RUBYGEMS_URI , DEFAULT_GROUP_NAME , cfg)
64
88
}
65
89
66
90
/* * Create an artifact repository which will use specified URI and
@@ -72,7 +96,33 @@ class RepositoryHandlerExtension {
72
96
* @return Artifact repository.
73
97
*/
74
98
ArtifactRepository gems (Object uri ) {
75
- bindRepositoryToProxyServer(project. uri(uri), DEFAULT_GROUP_NAME )
99
+ bindRepositoryToProxyServer(project. uri(uri), DEFAULT_GROUP_NAME , new GemRepositoryConfiguration ())
100
+ }
101
+
102
+ /* * Create an artifact repository which will use specified URI and
103
+ * associate group {@code rubygems} with it.
104
+ *
105
+ * @param uri URI of remote repository that serves up Rubygems. Any object convertible
106
+ * with {@code project.uri} can be provided.
107
+ * @param cfg GEM repository configuration
108
+ *
109
+ * @return Artifact repository.
110
+ */
111
+ ArtifactRepository gems (Object uri , @DelegatesTo (GemRepositoryConfiguration ) Closure cfg ) {
112
+ bindRepositoryToProxyServer(project. uri(uri), DEFAULT_GROUP_NAME , cfg)
113
+ }
114
+
115
+ /* * Create an artifact repository which will use specified URI and
116
+ * associate group {@code rubygems} with it.
117
+ *
118
+ * @param uri URI of remote repository that serves up Rubygems. Any object convertible
119
+ * with {@code project.uri} can be provided.
120
+ * @param cfg GEM repository configuration
121
+ *
122
+ * @return Artifact repository.
123
+ */
124
+ ArtifactRepository gems (Object uri , Action<GemRepositoryConfiguration > cfg ) {
125
+ bindRepositoryToProxyServer(project. uri(uri), DEFAULT_GROUP_NAME , cfg)
76
126
}
77
127
78
128
/* * Create an artifact repository which will use specified URI and
@@ -84,37 +134,65 @@ class RepositoryHandlerExtension {
84
134
* @return Artifact repository.
85
135
*/
86
136
ArtifactRepository gems (String group , Object uri ) {
87
- bindRepositoryToProxyServer(project. uri(uri), group)
137
+ bindRepositoryToProxyServer(project. uri(uri), group, new GemRepositoryConfiguration () )
88
138
}
89
139
90
- /* * Adds the legacy Torquebox Maven proxy to {@code rubygems.org}.
140
+ /* * Create an artifact repository which will use specified URI and
141
+ * associate a specified group with it.
91
142
*
92
- * Please note that this proxy is effectively unmaintained an no longer supported
93
- * by the original creators.
143
+ * @param group Group to associate this server with.
144
+ * @param uri URI of remote repository that serves up Rubygems. Any object convertible
145
+ * with {@code project.uri} can be provided.
146
+ * @param cfg GEM repository configuration
147
+ * @return Artifact repository.
148
+ */
149
+ ArtifactRepository gems (String group , Object uri , @DelegatesTo (GemRepositoryConfiguration ) Closure cfg ) {
150
+ bindRepositoryToProxyServer(project. uri(uri), group, cfg)
151
+ }
152
+
153
+ /* * Create an artifact repository which will use specified URI and
154
+ * associate a specified group with it.
94
155
*
95
- * @return Maven artifact repository
156
+ * @param group Group to associate this server with.
157
+ * @param uri URI of remote repository that serves up Rubygems. Any object convertible
158
+ * with {@code project.uri} can be provided.
159
+ * @param cfg GEM repository configuration
160
+ * @return Artifact repository.
96
161
*/
97
- MavenArtifactRepository torquebox () {
98
- Action mvnConfigurator = new Action<MavenArtifactRepository > () {
99
- void execute (MavenArtifactRepository mvn ) {
100
- mvn. url = ' http://rubygems-proxy.torquebox.org/releases' . toURI()
101
- }
102
- }
103
- (MavenArtifactRepository ) restrictToGems(
104
- this . project. repositories. maven(mvnConfigurator),
105
- DEFAULT_GROUP_NAME
106
- )
162
+ ArtifactRepository gems (String group , Object uri , Action<GemRepositoryConfiguration > cfg ) {
163
+ bindRepositoryToProxyServer(project. uri(uri), group, cfg)
107
164
}
108
165
109
166
private ArtifactRepository bindRepositoryToProxyServer (
110
167
URI serverUri ,
111
- String group
168
+ String group ,
169
+ GemRepositoryConfiguration cfg
112
170
) {
113
- IvyXmlProxyServer proxy = ivyProxies. registerProxy(serverUri, group)
171
+ IvyXmlProxyServer proxy = ivyProxies. registerProxy(serverUri, group, cfg )
114
172
project. extensions. getByType(GemResolverStrategy ). addGemGroup(group)
115
173
restrictToGems(createIvyRepo(serverUri, proxy. bindAddress), group)
116
174
}
117
175
176
+ private ArtifactRepository bindRepositoryToProxyServer (
177
+ URI serverUri ,
178
+ String group ,
179
+ @DelegatesTo (GemRepositoryConfiguration ) Closure cfg
180
+ ) {
181
+ GemRepositoryConfiguration grc = new GemRepositoryConfiguration ()
182
+ ClosureUtils . configureItem(grc, cfg)
183
+ bindRepositoryToProxyServer(serverUri, group, grc)
184
+ }
185
+
186
+ private ArtifactRepository bindRepositoryToProxyServer (
187
+ URI serverUri ,
188
+ String group ,
189
+ Action<GemRepositoryConfiguration > cfg
190
+ ) {
191
+ GemRepositoryConfiguration grc = new GemRepositoryConfiguration ()
192
+ cfg. execute(grc)
193
+ bindRepositoryToProxyServer(serverUri, group, grc)
194
+ }
195
+
118
196
@CompileDynamic
119
197
private IvyArtifactRepository createIvyRepo (URI server , URI bindAddress ) {
120
198
this . project. repositories. ivy {
@@ -141,4 +219,5 @@ class RepositoryHandlerExtension {
141
219
private final IvyXmlGlobalProxyRegistry ivyProxies
142
220
private static final boolean HAS_CONTENT_FEATURE = GradleVersion . current() >= GradleVersion . version(' 5.1' )
143
221
private static final boolean HAS_SECURE_PROTOCOL_FEATURE = GradleVersion . current() >= GradleVersion . version(' 6.0' )
222
+ private static final URI RUBYGEMS_URI = ' https://rubygems.org' . toURI()
144
223
}
0 commit comments