@@ -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,37 +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 () )
88138 }
89139
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.
91142 *
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.
94155 *
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.
96161 */
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)
107164 }
108165
109166 private ArtifactRepository bindRepositoryToProxyServer (
110167 URI serverUri ,
111- String group
168+ String group ,
169+ GemRepositoryConfiguration cfg
112170 ) {
113- IvyXmlProxyServer proxy = ivyProxies. registerProxy(serverUri, group)
171+ IvyXmlProxyServer proxy = ivyProxies. registerProxy(serverUri, group, cfg )
114172 project. extensions. getByType(GemResolverStrategy ). addGemGroup(group)
115173 restrictToGems(createIvyRepo(serverUri, proxy. bindAddress), group)
116174 }
117175
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+
118196 @CompileDynamic
119197 private IvyArtifactRepository createIvyRepo (URI server , URI bindAddress ) {
120198 this . project. repositories. ivy {
@@ -141,4 +219,5 @@ class RepositoryHandlerExtension {
141219 private final IvyXmlGlobalProxyRegistry ivyProxies
142220 private static final boolean HAS_CONTENT_FEATURE = GradleVersion . current() >= GradleVersion . version(' 5.1' )
143221 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()
144223}
0 commit comments