Skip to content

Commit

Permalink
Start adding "info" compact index endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Jul 27, 2023
1 parent f75d6ed commit 06c7054
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public interface RubygemsFileFactory {

ApiV2File rubygemsInfoV2(String name, String version);

CompactInfoFile compactInfo(String name);

/**
* create <code>BundlerApiFile</code> /api/v1/dependencies?gems=name1,name2,etc
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <code>DependencyFile</code> for the given gem name
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> expiredNames = new LinkedList<>();
Expand Down
2 changes: 2 additions & 0 deletions rubygems-tools/src/test/hostedrepo/info/hashdb.compact
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
2.0 |checksum:d795f48c5a3d879f11aff4557c10956b87d58917b59928170e137381cf447dfd
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 06c7054

Please sign in to comment.