Skip to content

Commit 248b901

Browse files
committed
First pass adding V2 rubygems.org API support
1 parent d964e52 commit 248b901

17 files changed

+277
-3
lines changed

rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/DefaultRubygemsFileFactory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ public class DefaultRubygemsFileFactory implements RubygemsFileFactory {
3737

3838
private static final String API_V1 = "/" + RootCuba.API + "/" + ApiCuba.V1;
3939

40+
private static final String API_V2 = "/" + RootCuba.API + "/" + ApiCuba.V2;
41+
4042
private static final String API_V1_DEPS = API_V1 + "/" + ApiV1Cuba.DEPENDENCIES;
4143

44+
private static final String API_V2_RUBYGEMS = API_V2 + "/rubygems";
45+
46+
private static final String INFO = "info";
47+
4248
private static final String MAVEN_PRERELEASED_RUBYGEMS = "/" + RootCuba.MAVEN + "/" + MavenCuba.PRERELEASES + "/" + MavenReleasesCuba.RUBYGEMS;
4349

4450
private static final String MAVEN_RELEASED_RUBYGEMS = "/" + RootCuba.MAVEN + "/" + MavenCuba.RELEASES + "/" + MavenReleasesCuba.RUBYGEMS;
@@ -171,6 +177,11 @@ public DependencyFile dependencyFile(String name) {
171177
return new DependencyFile(this, join(API_V1_DEPS, SEPARATOR, name, ApiV1DependenciesCuba.RUBY), join(API_V1_DEPS, "?gems=" + name), name);
172178
}
173179

180+
@Override
181+
public DependencyFile rubygemsInfoV2(String name, String version) {
182+
return new DependencyFile(this, join(API_V2_RUBYGEMS, SEPARATOR, name, SEPARATOR, "versions", SEPARATOR, version, ".json"), join(API_V2_RUBYGEMS, SEPARATOR, name, SEPARATOR, "versions", SEPARATOR, version, ".json"), name);
183+
}
184+
174185
@Override
175186
public BundlerApiFile bundlerApiFile(String names) {
176187
// normalize query string first

rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/RubygemsFileFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public interface RubygemsFileFactory {
8888
*/
8989
DependencyFile dependencyFile(String name);
9090

91+
DependencyFile rubygemsInfoV2(String name, String version);
92+
9193
/**
9294
* create <code>BundlerApiFile</code> /api/v1/dependencies?gems=name1,name2,etc
9395
*

rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/DefaultRubygemsFileSystem.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import org.torquebox.mojo.rubygems.cuba.api.ApiCuba;
1717
import org.torquebox.mojo.rubygems.cuba.api.ApiV1Cuba;
1818
import org.torquebox.mojo.rubygems.cuba.api.ApiV1DependenciesCuba;
19+
import org.torquebox.mojo.rubygems.cuba.api.ApiV2Cuba;
20+
import org.torquebox.mojo.rubygems.cuba.api.ApiV2RubygemsCuba;
1921
import org.torquebox.mojo.rubygems.cuba.gems.GemsCuba;
2022
import org.torquebox.mojo.rubygems.cuba.maven.MavenCuba;
2123
import org.torquebox.mojo.rubygems.cuba.maven.MavenPrereleasesCuba;
@@ -31,7 +33,7 @@ public class DefaultRubygemsFileSystem extends RubygemsFileSystem {
3133
public DefaultRubygemsFileSystem(RubygemsFileFactory fileLayout, Layout getLayout, Layout postLayout, Layout deleteLayout) {
3234
super(fileLayout, getLayout, postLayout, deleteLayout,
3335
// TODO move to javax.inject
34-
new RootCuba(new ApiCuba(new ApiV1Cuba(new ApiV1DependenciesCuba()), new QuickCuba(new QuickMarshalCuba()), new GemsCuba()), new QuickCuba(new QuickMarshalCuba()), new GemsCuba(), new MavenCuba(new MavenReleasesCuba(new MavenReleasesRubygemsCuba()), new MavenPrereleasesCuba(new MavenPrereleasesRubygemsCuba()))));
36+
new RootCuba(new ApiCuba(new ApiV1Cuba(new ApiV1DependenciesCuba()), new ApiV2Cuba(new ApiV2RubygemsCuba()), new QuickCuba(new QuickMarshalCuba()), new GemsCuba()), new QuickCuba(new QuickMarshalCuba()), new GemsCuba(), new MavenCuba(new MavenReleasesCuba(new MavenReleasesRubygemsCuba()), new MavenPrereleasesCuba(new MavenPrereleasesRubygemsCuba()))));
3537
}
3638

3739
public DefaultRubygemsFileSystem(Layout getLayout, Layout postLayout, Layout deleteLayout) {

rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/RootCuba.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class RootCuba implements Cuba {
2929

3030
public static final String API = "api";
3131

32+
public static final String API2 = "api2";
33+
3234
public static final String QUICK = "quick";
3335

3436
public static final String GEMS = "gems";

rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/api/ApiCuba.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@
2525
public class ApiCuba implements Cuba {
2626
public static final String V1 = "v1";
2727

28+
public static final String V2 = "v2";
29+
2830
private final Cuba v1;
2931

32+
private final Cuba v2;
33+
3034
private final Cuba quick;
3135

3236
private final Cuba gems;
3337

34-
public ApiCuba(Cuba v1, Cuba quick, Cuba gems) {
38+
public ApiCuba(Cuba v1, Cuba v2, Cuba quick, Cuba gems) {
3539
this.v1 = v1;
40+
this.v2 = v2;
3641
this.quick = quick;
3742
this.gems = gems;
3843
}
@@ -45,6 +50,8 @@ public RubygemsFile on(State state) {
4550
switch (state.name) {
4651
case V1:
4752
return state.nested(v1);
53+
case V2:
54+
return state.nested(v2);
4855
case RootCuba.QUICK:
4956
return state.nested(quick);
5057
case RootCuba.GEMS:
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Sonatype Nexus (TM) Open Source Version
3+
* Copyright (c) 2008-present Sonatype, Inc.
4+
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
5+
*
6+
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
7+
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
8+
*
9+
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
10+
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
11+
* Eclipse Foundation. All other trademarks are the property of their respective owners.
12+
*/
13+
package org.torquebox.mojo.rubygems.cuba.api;
14+
15+
import org.torquebox.mojo.rubygems.RubygemsFile;
16+
import org.torquebox.mojo.rubygems.cuba.Cuba;
17+
import org.torquebox.mojo.rubygems.cuba.State;
18+
19+
/**
20+
* cuba for /api/v2 to fetch gem details
21+
*
22+
* @author christian
23+
*/
24+
public class ApiV2Cuba
25+
implements Cuba {
26+
public static final String RUBYGEMS = "rubygems";
27+
28+
private final Cuba apiV2Rubygems;
29+
30+
public ApiV2Cuba(Cuba apiV2Rubygems) {
31+
this.apiV2Rubygems = apiV2Rubygems;
32+
}
33+
34+
/**
35+
* directory [dependencies], files [api_key,gems]
36+
*/
37+
@Override
38+
public RubygemsFile on(State state) {
39+
if (state.name.equals(ApiV2Cuba.RUBYGEMS)) {
40+
return state.nested(apiV2Rubygems);
41+
}
42+
return state.context.factory.notFound(state.context.original);
43+
}
44+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Sonatype Nexus (TM) Open Source Version
3+
* Copyright (c) 2008-present Sonatype, Inc.
4+
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
5+
*
6+
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
7+
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
8+
*
9+
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
10+
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
11+
* Eclipse Foundation. All other trademarks are the property of their respective owners.
12+
*/
13+
package org.torquebox.mojo.rubygems.cuba.api;
14+
15+
import org.torquebox.mojo.rubygems.RubygemsFile;
16+
import org.torquebox.mojo.rubygems.cuba.Cuba;
17+
import org.torquebox.mojo.rubygems.cuba.State;
18+
19+
/**
20+
* cuba for /api/v2/rubygems to fetch gem details
21+
*/
22+
public class ApiV2RubygemsCuba implements Cuba {
23+
/**
24+
* directory [dependencies], files [api_key,gems]
25+
*/
26+
@Override
27+
public RubygemsFile on(State state) {
28+
if (state.name.isEmpty()) {
29+
return state.context.factory.notFound(state.context.original);
30+
}
31+
return state.nested(new ApiV2RubygemsNameCuba(state.name));
32+
}
33+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Sonatype Nexus (TM) Open Source Version
3+
* Copyright (c) 2008-present Sonatype, Inc.
4+
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
5+
*
6+
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
7+
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
8+
*
9+
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
10+
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
11+
* Eclipse Foundation. All other trademarks are the property of their respective owners.
12+
*/
13+
package org.torquebox.mojo.rubygems.cuba.api;
14+
15+
import org.torquebox.mojo.rubygems.RubygemsFile;
16+
import org.torquebox.mojo.rubygems.cuba.Cuba;
17+
import org.torquebox.mojo.rubygems.cuba.State;
18+
19+
/**
20+
* cuba for /api/v2/rubygems to fetch gem details
21+
*/
22+
public class ApiV2RubygemsNameCuba implements Cuba {
23+
24+
public static final String VERSIONS = "versions";
25+
26+
private final String name;
27+
28+
public ApiV2RubygemsNameCuba(String name) {
29+
this.name = name;
30+
}
31+
32+
/**
33+
* directory [dependencies], files [api_key,gems]
34+
*/
35+
@Override
36+
public RubygemsFile on(State state) {
37+
if (state.name.equals(VERSIONS)) {
38+
return state.nested(new ApiV2RubygemsNameVersionsCuba(name));
39+
}
40+
return state.context.factory.notFound(state.context.original);
41+
}
42+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Sonatype Nexus (TM) Open Source Version
3+
* Copyright (c) 2008-present Sonatype, Inc.
4+
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
5+
*
6+
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
7+
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
8+
*
9+
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
10+
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
11+
* Eclipse Foundation. All other trademarks are the property of their respective owners.
12+
*/
13+
package org.torquebox.mojo.rubygems.cuba.api;
14+
15+
import org.torquebox.mojo.rubygems.RubygemsFile;
16+
import org.torquebox.mojo.rubygems.cuba.Cuba;
17+
import org.torquebox.mojo.rubygems.cuba.State;
18+
19+
/**
20+
* cuba for /api/v2/rubygems/NAME/versions/VERSION
21+
*/
22+
public class ApiV2RubygemsNameVersionsCuba implements Cuba {
23+
24+
private final String name;
25+
26+
public ApiV2RubygemsNameVersionsCuba(String name) {
27+
this.name = name;
28+
}
29+
30+
/**
31+
* directory [dependencies], files [api_key,gems]
32+
*/
33+
@Override
34+
public RubygemsFile on(State state) {
35+
if (state.name.isEmpty()) {
36+
return state.context.factory.notFound(state.context.original);
37+
}
38+
return state.nested(new ApiV2RubygemsNameVersionsNumberCuba(name, state.name));
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Sonatype Nexus (TM) Open Source Version
3+
* Copyright (c) 2008-present Sonatype, Inc.
4+
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
5+
*
6+
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
7+
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
8+
*
9+
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
10+
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
11+
* Eclipse Foundation. All other trademarks are the property of their respective owners.
12+
*/
13+
package org.torquebox.mojo.rubygems.cuba.api;
14+
15+
import org.torquebox.mojo.rubygems.RubygemsFile;
16+
import org.torquebox.mojo.rubygems.cuba.Cuba;
17+
import org.torquebox.mojo.rubygems.cuba.State;
18+
19+
/**
20+
* cuba for /api/v2/rubygems/GEM/versions/NUM
21+
*
22+
* @author christian
23+
*/
24+
public class ApiV2RubygemsNameVersionsNumberCuba implements Cuba {
25+
private final String name;
26+
private final String version;
27+
28+
public ApiV2RubygemsNameVersionsNumberCuba(String name, String version) {
29+
this.name = name;
30+
this.version = version;
31+
}
32+
33+
@Override
34+
public RubygemsFile on(State state) {
35+
return state.context.factory.rubygemsInfoV2(name, version);
36+
}
37+
}

rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/DELETELayout.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,11 @@ public DependencyFile dependencyFile(String name) {
9595
store.delete(file);
9696
return file;
9797
}
98+
99+
@Override
100+
public DependencyFile rubygemsInfoV2(String name, String version) {
101+
DependencyFile file = super.rubygemsInfoV2(name, version);
102+
store.delete(file);
103+
return file;
104+
}
98105
}

rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedDELETELayout.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ public DependencyFile dependencyFile(String name) {
7676
return file;
7777
}
7878

79+
@Override
80+
public DependencyFile rubygemsInfoV2(String name, String version) {
81+
DependencyFile file = super.rubygemsInfoV2(name, version);
82+
file.markAsForbidden();
83+
return file;
84+
}
85+
7986
@Override
8087
public ApiV1File apiV1File(String name) {
8188
ApiV1File file = super.apiV1File(name);

rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedGETLayout.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ public DependencyFile dependencyFile(String name) {
111111
return file;
112112
}
113113

114+
@Override
115+
public DependencyFile rubygemsInfoV2(String name, String version) {
116+
DependencyFile file = super.rubygemsInfoV2(name, version);
117+
store.retrieve(file);
118+
if (file.notExists()) {
119+
createDependency(file);
120+
}
121+
122+
return file;
123+
}
124+
114125
/**
115126
* create the <code>DependencyFile</code> for the given gem name
116127
*/

rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedPOSTLayout.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,11 @@ public DependencyFile dependencyFile(String name) {
179179
file.markAsForbidden();
180180
return file;
181181
}
182+
183+
@Override
184+
public DependencyFile rubygemsInfoV2(String name, String version) {
185+
DependencyFile file = super.rubygemsInfoV2(name, version);
186+
file.markAsForbidden();
187+
return file;
188+
}
182189
}

rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/ProxiedGETLayout.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import java.util.LinkedList;
2626
import java.util.List;
2727

28-
public class ProxiedGETLayout extends GETLayout {
28+
public class ProxiedGETLayout
29+
extends GETLayout {
2930
private final ProxyStorage store;
3031

3132
public ProxiedGETLayout(RubygemsGateway gateway, ProxyStorage store) {
@@ -74,6 +75,13 @@ public DependencyFile dependencyFile(String name) {
7475
return file;
7576
}
7677

78+
@Override
79+
public DependencyFile rubygemsInfoV2(String name, String version) {
80+
DependencyFile file = super.rubygemsInfoV2(name, version);
81+
store.retrieve(file);
82+
return file;
83+
}
84+
7785
@Override
7886
protected void retrieveAll(BundlerApiFile file, DependencyHelper deps) throws IOException {
7987
List<String> expiredNames = new LinkedList<>();

rubygems-tools/src/test/java/org/torquebox/mojo/rubygems/DefaultRubygemsFileSystemTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ public void testBundlerApi() throws Exception {
9999
assertFiletype(pathes, FileType.BUNDLER_API);
100100
}
101101

102+
@Test
103+
public void testApiV2() throws Exception {
104+
String[] paths = {
105+
"/api/v2/rubygems/rails/versions/7.0.1.json"
106+
};
107+
assertFiletype(paths, FileType.DEPENDENCY);
108+
}
102109

103110
@Test
104111
public void testApiV1() throws Exception {

0 commit comments

Comments
 (0)