diff --git a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/CompactInfoFile.java b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/CompactInfoFile.java new file mode 100644 index 0000000..5142f42 --- /dev/null +++ b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/CompactInfoFile.java @@ -0,0 +1,25 @@ +/* + * Sonatype Nexus (TM) Open Source Version + * Copyright (c) 2008-present Sonatype, Inc. + * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions. + * + * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0, + * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks + * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the + * Eclipse Foundation. All other trademarks are the property of their respective owners. + */ +package org.torquebox.mojo.rubygems; + +/** + * for the new API, /info/GEM + */ +public class CompactInfoFile + extends RubygemsFile { + CompactInfoFile(RubygemsFileFactory factory, String storage, String remote, String name) { + super(factory, FileType.COMPACT, storage, remote, name); + + set(null);// no payload + } +} \ No newline at end of file diff --git a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/DefaultRubygemsFileFactory.java b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/DefaultRubygemsFileFactory.java index 33466ce..15299a0 100644 --- a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/DefaultRubygemsFileFactory.java +++ b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/DefaultRubygemsFileFactory.java @@ -182,6 +182,11 @@ public ApiV2File rubygemsInfoV2(String name, String version) { return new ApiV2File(this, join(API_V2_RUBYGEMS, SEPARATOR, name, SEPARATOR, "versions", SEPARATOR, version, ".json"), join(API_V2_RUBYGEMS, SEPARATOR, name, SEPARATOR, "versions", SEPARATOR, version, ".json"), name, version); } + @Override + public CompactInfoFile compactInfo(String name) { + return new CompactInfoFile(this, join("/info", SEPARATOR, name, ".compact"), join("/info", SEPARATOR, name), name); + } + @Override public BundlerApiFile bundlerApiFile(String names) { // normalize query string first diff --git a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/FileType.java b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/FileType.java index 4724e92..8df4bdb 100644 --- a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/FileType.java +++ b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/FileType.java @@ -38,7 +38,8 @@ public enum FileType { FORBIDDEN(null), TEMP_UNAVAILABLE(null), NO_CONTENT("text/plain"), - JSON_API("text/plain", "utf-8"); + JSON_API("text/plain", "utf-8"), + COMPACT("test/plain", "utf-8"); private final String encoding; diff --git a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/RubygemsFileFactory.java b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/RubygemsFileFactory.java index 8e3c330..0e8e2bb 100644 --- a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/RubygemsFileFactory.java +++ b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/RubygemsFileFactory.java @@ -91,6 +91,8 @@ public interface RubygemsFileFactory { ApiV2File rubygemsInfoV2(String name, String version); + CompactInfoFile compactInfo(String name); + /** * create BundlerApiFile /api/v1/dependencies?gems=name1,name2,etc * diff --git a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/DefaultRubygemsFileSystem.java b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/DefaultRubygemsFileSystem.java index 40b69a1..c152731 100644 --- a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/DefaultRubygemsFileSystem.java +++ b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/DefaultRubygemsFileSystem.java @@ -18,6 +18,7 @@ import org.torquebox.mojo.rubygems.cuba.api.ApiV1DependenciesCuba; import org.torquebox.mojo.rubygems.cuba.api.ApiV2Cuba; import org.torquebox.mojo.rubygems.cuba.api.ApiV2RubygemsCuba; +import org.torquebox.mojo.rubygems.cuba.api.CompactInfoCuba; import org.torquebox.mojo.rubygems.cuba.gems.GemsCuba; import org.torquebox.mojo.rubygems.cuba.maven.MavenCuba; import org.torquebox.mojo.rubygems.cuba.maven.MavenPrereleasesCuba; @@ -33,7 +34,19 @@ public class DefaultRubygemsFileSystem extends RubygemsFileSystem { public DefaultRubygemsFileSystem(RubygemsFileFactory fileLayout, Layout getLayout, Layout postLayout, Layout deleteLayout) { super(fileLayout, getLayout, postLayout, deleteLayout, // TODO move to javax.inject - 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())))); + 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())), + new CompactInfoCuba() + )); } public DefaultRubygemsFileSystem(Layout getLayout, Layout postLayout, Layout deleteLayout) { diff --git a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/RootCuba.java b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/RootCuba.java index 67a988a..d0a831b 100644 --- a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/RootCuba.java +++ b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/RootCuba.java @@ -35,6 +35,8 @@ public class RootCuba implements Cuba { public static final String MAVEN = "maven"; + public static final String INFO = "info"; + private static final Pattern SPECS = Pattern.compile("^((prerelease_|latest_)?specs)" + _4_8 + "(" + GZ + ")?$"); private final Cuba api; @@ -45,11 +47,14 @@ public class RootCuba implements Cuba { private final Cuba maven; - public RootCuba(Cuba api, Cuba quick, Cuba gems, Cuba maven) { + private final Cuba info; + + public RootCuba(Cuba api, Cuba quick, Cuba gems, Cuba maven, Cuba info) { this.api = api; this.quick = quick; this.gems = gems; this.maven = maven; + this.info = info; } /** @@ -68,6 +73,8 @@ public RubygemsFile on(State state) { return state.nested(gems); case MAVEN: return state.nested(maven); + case INFO: + return state.nested(info); case "": return state.context.factory.directory(state.context.original, "api/", "quick/", "gems/", "maven/", "specs.4.8", "latest_specs.4.8", "prerelease_specs.4.8", "specs.4.8.gz", "latest_specs.4.8.gz", "prerelease_specs.4.8.gz"); default: diff --git a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/api/CompactInfoCuba.java b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/api/CompactInfoCuba.java new file mode 100644 index 0000000..9d27dbd --- /dev/null +++ b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/api/CompactInfoCuba.java @@ -0,0 +1,42 @@ +/* + * Sonatype Nexus (TM) Open Source Version + * Copyright (c) 2008-present Sonatype, Inc. + * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions. + * + * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0, + * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks + * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the + * Eclipse Foundation. All other trademarks are the property of their respective owners. + */ +package org.torquebox.mojo.rubygems.cuba.api; + +import org.torquebox.mojo.rubygems.RubygemsFile; +import org.torquebox.mojo.rubygems.cuba.Cuba; +import org.torquebox.mojo.rubygems.cuba.State; + +/** + * cuba for /info/GEMNAME + */ +public class CompactInfoCuba implements Cuba { + public CompactInfoCuba() { + } + + /** + * json listing of all versions of a given gem with dependencies + */ + @Override + public RubygemsFile on(State state) { + if (state.name != null) { + String baseName = state.name; + int ext = baseName.indexOf(".compact"); + if (ext != -1) { + baseName = baseName.substring(0, ext); + } + return state.context.factory.compactInfo(baseName); + } + + return state.context.factory.noContent(state.path); + } +} \ No newline at end of file diff --git a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/DELETELayout.java b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/DELETELayout.java index cde8688..a6e59bc 100644 --- a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/DELETELayout.java +++ b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/DELETELayout.java @@ -17,6 +17,7 @@ import org.torquebox.mojo.rubygems.DependencyFile; import org.torquebox.mojo.rubygems.GemFile; import org.torquebox.mojo.rubygems.GemspecFile; +import org.torquebox.mojo.rubygems.CompactInfoFile; import org.torquebox.mojo.rubygems.RubygemsGateway; import org.torquebox.mojo.rubygems.SpecsIndexFile; import org.torquebox.mojo.rubygems.SpecsIndexZippedFile; @@ -104,4 +105,11 @@ public ApiV2File rubygemsInfoV2(String name, String version) { store.delete(file); return file; } + + @Override + public CompactInfoFile compactInfo(String name) { + CompactInfoFile file = super.compactInfo(name); + store.retrieve(file); + return file; + } } diff --git a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedDELETELayout.java b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedDELETELayout.java index ca1cdf2..2d01571 100644 --- a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedDELETELayout.java +++ b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedDELETELayout.java @@ -20,6 +20,7 @@ import org.torquebox.mojo.rubygems.GemspecFile; import org.torquebox.mojo.rubygems.GemspecHelper; import org.torquebox.mojo.rubygems.IOUtil; +import org.torquebox.mojo.rubygems.CompactInfoFile; import org.torquebox.mojo.rubygems.RubygemsGateway; import org.torquebox.mojo.rubygems.SpecsHelper; import org.torquebox.mojo.rubygems.SpecsIndexFile; @@ -85,6 +86,13 @@ public ApiV2File rubygemsInfoV2(String name, String version) { return file; } + @Override + public CompactInfoFile compactInfo(String name) { + CompactInfoFile file = super.compactInfo(name); + file.markAsForbidden(); + return file; + } + @Override public ApiV1File apiV1File(String name) { ApiV1File file = super.apiV1File(name); diff --git a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedGETLayout.java b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedGETLayout.java index c0e2ec5..072a8dd 100644 --- a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedGETLayout.java +++ b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedGETLayout.java @@ -19,6 +19,7 @@ import org.torquebox.mojo.rubygems.GemspecFile; import org.torquebox.mojo.rubygems.GemspecHelper; import org.torquebox.mojo.rubygems.IOUtil; +import org.torquebox.mojo.rubygems.CompactInfoFile; import org.torquebox.mojo.rubygems.RubygemsGateway; import org.torquebox.mojo.rubygems.SpecsHelper; import org.torquebox.mojo.rubygems.SpecsIndexFile; @@ -124,6 +125,17 @@ public ApiV2File rubygemsInfoV2(String name, String version) { return file; } + @Override + public CompactInfoFile compactInfo(String name) { + CompactInfoFile file = super.compactInfo(name); + store.retrieve(file); + if (file.notExists()) { + throw new RuntimeException("not found: " + file); + } + + return file; + } + /** * create the DependencyFile for the given gem name */ diff --git a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedPOSTLayout.java b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedPOSTLayout.java index 68c4b2d..13aba14 100644 --- a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedPOSTLayout.java +++ b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/HostedPOSTLayout.java @@ -21,6 +21,7 @@ import org.torquebox.mojo.rubygems.GemspecFile; import org.torquebox.mojo.rubygems.GemspecHelper; import org.torquebox.mojo.rubygems.IOUtil; +import org.torquebox.mojo.rubygems.CompactInfoFile; import org.torquebox.mojo.rubygems.RubygemsFile; import org.torquebox.mojo.rubygems.RubygemsGateway; import org.torquebox.mojo.rubygems.SpecsHelper; @@ -188,4 +189,11 @@ public ApiV2File rubygemsInfoV2(String name, String version) { file.markAsForbidden(); return file; } + + @Override + public CompactInfoFile compactInfo(String name) { + CompactInfoFile file = super.compactInfo(name); + file.markAsForbidden(); + return file; + } } diff --git a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/ProxiedGETLayout.java b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/ProxiedGETLayout.java index febef57..f848be8 100644 --- a/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/ProxiedGETLayout.java +++ b/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/ProxiedGETLayout.java @@ -19,6 +19,7 @@ import org.torquebox.mojo.rubygems.GemFile; import org.torquebox.mojo.rubygems.GemspecFile; import org.torquebox.mojo.rubygems.GemspecHelper; +import org.torquebox.mojo.rubygems.CompactInfoFile; import org.torquebox.mojo.rubygems.RubygemsGateway; import java.io.IOException; @@ -84,6 +85,13 @@ public ApiV2File rubygemsInfoV2(String name, String version) { return file; } + @Override + public CompactInfoFile compactInfo(String name) { + CompactInfoFile file = super.compactInfo(name); + store.retrieve(file); + return file; + } + @Override protected void retrieveAll(BundlerApiFile file, DependencyHelper deps) throws IOException { List expiredNames = new LinkedList<>(); diff --git a/rubygems-tools/src/test/hostedrepo/info/hashdb.compact b/rubygems-tools/src/test/hostedrepo/info/hashdb.compact new file mode 100644 index 0000000..636e9df --- /dev/null +++ b/rubygems-tools/src/test/hostedrepo/info/hashdb.compact @@ -0,0 +1,2 @@ +--- +2.0 |checksum:d795f48c5a3d879f11aff4557c10956b87d58917b59928170e137381cf447dfd diff --git a/rubygems-tools/src/test/java/org/torquebox/mojo/rubygems/DefaultRubygemsFileSystemTest.java b/rubygems-tools/src/test/java/org/torquebox/mojo/rubygems/DefaultRubygemsFileSystemTest.java index a90f0eb..1321856 100644 --- a/rubygems-tools/src/test/java/org/torquebox/mojo/rubygems/DefaultRubygemsFileSystemTest.java +++ b/rubygems-tools/src/test/java/org/torquebox/mojo/rubygems/DefaultRubygemsFileSystemTest.java @@ -107,6 +107,14 @@ public void testApiV2() throws Exception { assertFiletype(paths, FileType.JSON_API); } + @Test + public void testGemInfo() throws Exception { + String[] paths = { + "/info/hashdb" + }; + assertFiletype(paths, FileType.COMPACT); + } + @Test public void testApiV1() throws Exception { String[] pathes = {"/api/v1/gems", "/api/v1/api_key"}; diff --git a/rubygems-tools/src/test/java/org/torquebox/mojo/rubygems/layout/HostedGETLayoutTest.java b/rubygems-tools/src/test/java/org/torquebox/mojo/rubygems/layout/HostedGETLayoutTest.java index 5ea8996..d9320a8 100644 --- a/rubygems-tools/src/test/java/org/torquebox/mojo/rubygems/layout/HostedGETLayoutTest.java +++ b/rubygems-tools/src/test/java/org/torquebox/mojo/rubygems/layout/HostedGETLayoutTest.java @@ -274,6 +274,14 @@ public void testApiV2() throws Exception { assertFiletypeWithPayload(paths, FileType.JSON_API, URLStreamLocation.class); } + @Test + public void testGemInfo() throws Exception { + String[] paths = { + "/info/hashdb.compact" + }; + assertFiletypeWithPayload(paths, FileType.COMPACT, URLStreamLocation.class); + } + @Test public void testDependency() throws Exception { String[] pathes = { diff --git a/rubygems-tools/src/test/java/org/torquebox/mojo/rubygems/layout/ProxiesGETLayoutTest.java b/rubygems-tools/src/test/java/org/torquebox/mojo/rubygems/layout/ProxiesGETLayoutTest.java index 2aae290..6a25f62 100644 --- a/rubygems-tools/src/test/java/org/torquebox/mojo/rubygems/layout/ProxiesGETLayoutTest.java +++ b/rubygems-tools/src/test/java/org/torquebox/mojo/rubygems/layout/ProxiesGETLayoutTest.java @@ -22,6 +22,7 @@ import org.torquebox.mojo.rubygems.Directory; import org.torquebox.mojo.rubygems.FileType; import org.torquebox.mojo.rubygems.GemArtifactFile; +import org.torquebox.mojo.rubygems.CompactInfoFile; import org.torquebox.mojo.rubygems.RubyScriptingTestSupport; import org.torquebox.mojo.rubygems.RubygemsFile; import org.torquebox.mojo.rubygems.cuba.DefaultRubygemsFileSystem; @@ -74,6 +75,13 @@ public ApiV2File rubygemsInfoV2(String name, String version) { return file; } + @Override + public CompactInfoFile compactInfo(String name) { + CompactInfoFile file = super.compactInfo(name); + store.retrieve(file); + return file; + } + }, null, null); isProxy = false; }