@@ -31,8 +31,8 @@ import org.gradle.api.Action
3131import org.gradle.api.Project
3232import org.gradle.api.artifacts.repositories.ArtifactRepository
3333import org.gradle.api.artifacts.repositories.IvyArtifactRepository
34- import org.gradle.api.artifacts.repositories.MavenArtifactRepository
3534import org.gradle.util.GradleVersion
35+ import org.ysb33r.grolifant.api.ClosureUtils
3636
3737/* * Extension which can be added to {@code project.repositories}.
3838 *
@@ -60,7 +60,31 @@ class RepositoryHandlerExtension {
6060 * @return Artifact repository.
6161 */
6262 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)
6488 }
6589
6690 /* * Create an artifact repository which will use specified URI and
@@ -72,7 +96,33 @@ class RepositoryHandlerExtension {
7296 * @return Artifact repository.
7397 */
7498 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)
76126 }
77127
78128 /* * Create an artifact repository which will use specified URI and
@@ -84,18 +134,65 @@ class RepositoryHandlerExtension {
84134 * @return Artifact repository.
85135 */
86136 ArtifactRepository gems (String group , Object uri ) {
87- bindRepositoryToProxyServer(project. uri(uri), group)
137+ bindRepositoryToProxyServer(project. uri(uri), group, new GemRepositoryConfiguration ())
138+ }
139+
140+ /* * Create an artifact repository which will use specified URI and
141+ * associate a specified group with it.
142+ *
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.
155+ *
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.
161+ */
162+ ArtifactRepository gems (String group , Object uri , Action<GemRepositoryConfiguration > cfg ) {
163+ bindRepositoryToProxyServer(project. uri(uri), group, cfg)
88164 }
89165
90166 private ArtifactRepository bindRepositoryToProxyServer (
91167 URI serverUri ,
92- String group
168+ String group ,
169+ GemRepositoryConfiguration cfg
93170 ) {
94- IvyXmlProxyServer proxy = ivyProxies. registerProxy(serverUri, group)
171+ IvyXmlProxyServer proxy = ivyProxies. registerProxy(serverUri, group, cfg )
95172 project. extensions. getByType(GemResolverStrategy ). addGemGroup(group)
96173 restrictToGems(createIvyRepo(serverUri, proxy. bindAddress), group)
97174 }
98175
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+
99196 @CompileDynamic
100197 private IvyArtifactRepository createIvyRepo (URI server , URI bindAddress ) {
101198 this . project. repositories. ivy {
@@ -122,4 +219,5 @@ class RepositoryHandlerExtension {
122219 private final IvyXmlGlobalProxyRegistry ivyProxies
123220 private static final boolean HAS_CONTENT_FEATURE = GradleVersion . current() >= GradleVersion . version(' 5.1' )
124221 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()
125223}
0 commit comments