Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for satis #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public enum AssetKind
{
ZIPBALL(CONTENT),
TARBALL(CONTENT),
PACKAGES(METADATA),
LIST(METADATA),
PROVIDER(METADATA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ComposerGroupRecipe
.handler(providerJsonHandler)
.create())

builder.route(zipballMatcher()
builder.route(packageMatcher()
.handler(timingHandler)
.handler(assetKindHandler.rcurry(AssetKind.ZIPBALL))
.handler(securityHandler)
Expand All @@ -98,6 +98,15 @@ class ComposerGroupRecipe
.handler(standardGroupHandler)
.create())

builder.route(packageMatcher()
.handler(timingHandler)
.handler(assetKindHandler.rcurry(AssetKind.TARBALL))
.handler(securityHandler)
.handler(exceptionHandler)
.handler(handlerContributor)
.handler(standardGroupHandler)
.create())

addBrowseUnsupportedRoute(builder)

builder.defaultHandlers(HttpHandlers.notFound())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.sonatype.nexus.repository.view.Handler;
import org.sonatype.nexus.repository.view.Response;

import static org.sonatype.nexus.repository.composer.internal.ComposerPathUtils.buildZipballPath;
import static org.sonatype.nexus.repository.composer.internal.ComposerPathUtils.buildPackagePath;
import static org.sonatype.nexus.repository.composer.internal.ComposerPathUtils.getProjectToken;
import static org.sonatype.nexus.repository.composer.internal.ComposerPathUtils.getVendorToken;

Expand All @@ -50,7 +50,8 @@ public Response handle(@Nonnull final Context context) throws Exception {
case PROVIDER:
return HttpResponses.ok(hostedFacet.getProviderJson(getVendorToken(context), getProjectToken(context)));
case ZIPBALL:
return responseFor(hostedFacet.getZipball(buildZipballPath(context)));
case TARBALL:
return responseFor(hostedFacet.getPackage(buildPackagePath(context)));
default:
throw new IllegalStateException("Unexpected assetKind: " + assetKind);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ public interface ComposerHostedFacet
void rebuildProviderJson(String vendor, String project) throws IOException;

@Nullable
Content getZipball(String path) throws IOException;
Content getPackage(String path) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public ComposerHostedFacetImpl(final ComposerJsonProcessor composerJsonProcessor
public void upload(final String vendor, final String project, final String version, final Payload payload)
throws IOException
{
content().put(ComposerPathUtils.buildZipballPath(vendor, project, version), payload, AssetKind.ZIPBALL);
content().put(ComposerPathUtils.buildPackagePath(vendor, project, version, null, "zip"), payload, AssetKind.ZIPBALL);
}

@Override
public Content getZipball(final String path) throws IOException {
public Content getPackage(final String path) throws IOException {
return content().get(path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.sonatype.nexus.repository.view.ViewFacet

import static org.sonatype.nexus.repository.composer.internal.AssetKind.PACKAGES
import static org.sonatype.nexus.repository.composer.internal.AssetKind.PROVIDER
import static org.sonatype.nexus.repository.composer.internal.AssetKind.TARBALL
import static org.sonatype.nexus.repository.composer.internal.AssetKind.ZIPBALL

/**
Expand Down Expand Up @@ -103,7 +104,7 @@ class ComposerHostedRecipe
.handler(downloadHandler)
.create())

builder.route(zipballMatcher()
builder.route(packageMatcher()
.handler(timingHandler)
.handler(assetKindHandler.rcurry(ZIPBALL))
.handler(securityHandler)
Expand All @@ -116,6 +117,19 @@ class ComposerHostedRecipe
.handler(downloadHandler)
.create())

builder.route(packageMatcher()
.handler(timingHandler)
.handler(assetKindHandler.rcurry(TARBALL))
.handler(securityHandler)
.handler(exceptionHandler)
.handler(handlerContributor)
.handler(conditionalRequestHandler)
.handler(partialFetchHandler)
.handler(contentHeadersHandler)
.handler(unitOfWorkHandler)
.handler(downloadHandler)
.create())

builder.route(uploadMatcher()
.handler(timingHandler)
.handler(assetKindHandler.rcurry(ZIPBALL))
Expand All @@ -129,6 +143,19 @@ class ComposerHostedRecipe
.handler(uploadHandler)
.create())

builder.route(uploadMatcher()
.handler(timingHandler)
.handler(assetKindHandler.rcurry(TARBALL))
.handler(securityHandler)
.handler(exceptionHandler)
.handler(handlerContributor)
.handler(conditionalRequestHandler)
.handler(partialFetchHandler)
.handler(contentHeadersHandler)
.handler(unitOfWorkHandler)
.handler(uploadHandler)
.create())

addBrowseUnsupportedRoute(builder)

builder.defaultHandlers(HttpHandlers.notFound())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Collections.singletonMap;
import static org.sonatype.nexus.repository.composer.internal.ComposerPathUtils.buildZipballPath;
import static org.sonatype.nexus.repository.composer.internal.ComposerPathUtils.buildPackagePath;

/**
* Class encapsulating JSON processing for Composer-format repositories, including operations for parsing JSON indexes
Expand Down Expand Up @@ -405,7 +405,7 @@ private Map<String, Object> buildDistInfo(final Repository repository,
String packageProject = packageNameParts[1];
Map<String, Object> newDistInfo = new LinkedHashMap<>();
newDistInfo
.put(URL_KEY, repository.getUrl() + "/" + buildZipballPath(packageVendor, packageProject, packageVersion));
.put(URL_KEY, repository.getUrl() + "/" + buildPackagePath(packageVendor, packageProject, packageVersion, null, type));
newDistInfo.put(TYPE_KEY, type);
newDistInfo.put(REFERENCE_KEY, reference);
newDistInfo.put(SHASUM_KEY, shasum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@
import org.eclipse.sisu.Nullable;

import static com.google.common.base.Preconditions.checkNotNull;
import static org.sonatype.nexus.repository.composer.internal.ComposerRecipeSupport.NAME_TOKEN;
import static org.sonatype.nexus.repository.composer.internal.ComposerRecipeSupport.PROJECT_TOKEN;
import static org.sonatype.nexus.repository.composer.internal.ComposerRecipeSupport.VENDOR_TOKEN;
import static org.sonatype.nexus.repository.composer.internal.ComposerRecipeSupport.VERSION_TOKEN;
import static org.sonatype.nexus.repository.composer.internal.ComposerRecipeSupport.*;

/**
* Utility class containing methods for working with Composer routes and paths.
*/
public final class ComposerPathUtils
{
private static final String ZIPBALL_PATH = "%s/%s/%s/%s.zip";
private static final String PACKAGE_PATH = "%s/%s/%s/%s.%s";

private static final String PROVIDER_JSON_PATH = "p/%s/%s.json";

Expand Down Expand Up @@ -66,31 +63,26 @@ public static String getVersionToken(final Context context) {
* path will not be known because the filename will not be present, so the name portion will be constructed from
* the vendor, project, and version information contained in the other path segments.
*/
public static String buildZipballPath(final Context context) {
public static String buildPackagePath(final Context context) {
TokenMatcher.State state = context.getAttributes().require(TokenMatcher.State.class);
Map<String, String> tokens = state.getTokens();
return buildZipballPath(
return buildPackagePath(
tokens.get(VENDOR_TOKEN),
tokens.get(PROJECT_TOKEN),
tokens.get(VERSION_TOKEN),
tokens.get(NAME_TOKEN));
tokens.get(NAME_TOKEN),
tokens.get(TYPE_TOKEN));
}

/**
* Builds the zipball path based on the provided vendor, project, and version. The filename will be constructed based
* on the values of those parameters.
*/
public static String buildZipballPath(final String vendor, final String project, final String version) {
return buildZipballPath(vendor, project, version, null);
}

private static String buildZipballPath(final String vendor,
public static String buildPackagePath(final String vendor,
final String project,
final String version,
@Nullable final String name)
@Nullable final String name,
final String type)
{
return String.format(ZIPBALL_PATH, vendor, project, version,
name == null ? String.format(NAME_PATTERN, vendor, project, version) : name);
return String.format(PACKAGE_PATH, vendor, project, version,
name == null ? String.format(NAME_PATTERN, vendor, project, version) : name,
type);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import com.google.common.base.Throwables;

import static com.google.common.base.Preconditions.checkNotNull;
import static org.sonatype.nexus.repository.composer.internal.ComposerPathUtils.buildPackagePath;
import static org.sonatype.nexus.repository.composer.internal.ComposerPathUtils.buildProviderPath;
import static org.sonatype.nexus.repository.composer.internal.ComposerPathUtils.buildZipballPath;
import static org.sonatype.nexus.repository.composer.internal.ComposerRecipeSupport.PROJECT_TOKEN;
import static org.sonatype.nexus.repository.composer.internal.ComposerRecipeSupport.VENDOR_TOKEN;
import static org.sonatype.nexus.repository.composer.internal.ComposerRecipeSupport.VERSION_TOKEN;
Expand Down Expand Up @@ -92,7 +92,8 @@ protected Content getCachedContent(final Context context) throws IOException {
case PROVIDER:
return content().get(buildProviderPath(context));
case ZIPBALL:
return content().get(buildZipballPath(context));
case TARBALL:
return content().get(buildPackagePath(context));
default:
throw new IllegalStateException();
}
Expand All @@ -109,7 +110,8 @@ protected Content store(final Context context, final Content content) throws IOE
case PROVIDER:
return content().put(buildProviderPath(context), content, assetKind);
case ZIPBALL:
return content().put(buildZipballPath(context), content, assetKind);
case TARBALL:
return content().put(buildPackagePath(context), content, assetKind);
default:
throw new IllegalStateException();
}
Expand All @@ -131,7 +133,8 @@ protected void indicateVerified(final Context context, final Content content, fi
content().setCacheInfo(buildProviderPath(context), content, cacheInfo);
break;
case ZIPBALL:
content().setCacheInfo(buildZipballPath(context), content, cacheInfo);
case TARBALL:
content().setCacheInfo(buildPackagePath(context), content, cacheInfo);
break;
default:
throw new IllegalStateException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class ComposerProxyRecipe
.handler(proxyHandler)
.create())

builder.route(zipballMatcher()
builder.route(packageMatcher()
.handler(timingHandler)
.handler(assetKindHandler.rcurry(AssetKind.ZIPBALL))
.handler(securityHandler)
Expand All @@ -143,6 +143,20 @@ class ComposerProxyRecipe
.handler(proxyHandler)
.create())

builder.route(packageMatcher()
.handler(timingHandler)
.handler(assetKindHandler.rcurry(AssetKind.TARBALL))
.handler(securityHandler)
.handler(exceptionHandler)
.handler(handlerContributor)
.handler(negativeCacheHandler)
.handler(conditionalRequestHandler)
.handler(partialFetchHandler)
.handler(contentHeadersHandler)
.handler(unitOfWorkHandler)
.handler(proxyHandler)
.create())

addBrowseUnsupportedRoute(builder)

builder.defaultHandlers(HttpHandlers.notFound())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ abstract class ComposerRecipeSupport

public static final String NAME_TOKEN = 'name'

public static final String TYPE_TOKEN = 'type'

@Inject
Provider<ComposerContentFacet> contentFacet

Expand Down Expand Up @@ -134,11 +136,11 @@ abstract class ComposerRecipeSupport
))
}

static Builder zipballMatcher() {
static Builder packageMatcher() {
new Builder().matcher(
LogicMatchers.and(
new ActionMatcher(GET, HEAD),
new TokenMatcher('/{vendor:.+}/{project:.+}/{version:.+}/{name:.+}.zip')
new TokenMatcher('/{vendor:.+}/{project:.+}/{version:.+}/{name:.+}.{type:.+}')
))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,8 @@
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import static org.sonatype.nexus.repository.composer.internal.AssetKind.LIST;
import static org.sonatype.nexus.repository.composer.internal.AssetKind.PACKAGES;
import static org.sonatype.nexus.repository.composer.internal.AssetKind.PROVIDER;
import static org.sonatype.nexus.repository.composer.internal.AssetKind.ZIPBALL;
import static org.sonatype.nexus.repository.composer.internal.ComposerRecipeSupport.NAME_TOKEN;
import static org.sonatype.nexus.repository.composer.internal.ComposerRecipeSupport.PROJECT_TOKEN;
import static org.sonatype.nexus.repository.composer.internal.ComposerRecipeSupport.VENDOR_TOKEN;
import static org.sonatype.nexus.repository.composer.internal.ComposerRecipeSupport.VERSION_TOKEN;
import static org.sonatype.nexus.repository.composer.internal.AssetKind.*;
import static org.sonatype.nexus.repository.composer.internal.ComposerRecipeSupport.*;

public class ComposerHostedDownloadHandlerTest
extends TestSupport
Expand All @@ -55,6 +49,8 @@ public class ComposerHostedDownloadHandlerTest

private static final String ZIPBALL_PATH = "testvendor/testproject/testversion/testvendor-testproject-testversion.zip";

private static final String TARBALL_PATH = "testvendor/testproject/testversion/testvendor-testproject-testversion.tar";

@Rule
public ExpectedException exception = ExpectedException.none();

Expand Down Expand Up @@ -128,7 +124,22 @@ public void testHandleZipballPresent() throws Exception {
when(tokens.get(PROJECT_TOKEN)).thenReturn(PROJECT);
when(tokens.get(VERSION_TOKEN)).thenReturn(VERSION);
when(tokens.get(NAME_TOKEN)).thenReturn(NAME);
when(composerHostedFacet.getZipball(ZIPBALL_PATH)).thenReturn(content);
when(tokens.get(TYPE_TOKEN)).thenReturn("zip");
when(composerHostedFacet.getPackage(ZIPBALL_PATH)).thenReturn(content);
Response response = underTest.handle(context);
assertThat(response.getStatus().getCode(), is(200));
assertThat(response.getPayload(), is(content));
}

@Test
public void testHandleTarballPresent() throws Exception {
when(attributes.require(AssetKind.class)).thenReturn(TARBALL);
when(tokens.get(VENDOR_TOKEN)).thenReturn(VENDOR);
when(tokens.get(PROJECT_TOKEN)).thenReturn(PROJECT);
when(tokens.get(VERSION_TOKEN)).thenReturn(VERSION);
when(tokens.get(NAME_TOKEN)).thenReturn(NAME);
when(tokens.get(TYPE_TOKEN)).thenReturn("tar");
when(composerHostedFacet.getPackage(TARBALL_PATH)).thenReturn(content);
Response response = underTest.handle(context);
assertThat(response.getStatus().getCode(), is(200));
assertThat(response.getPayload(), is(content));
Expand All @@ -141,7 +152,7 @@ public void testHandleZipballAbsent() throws Exception {
when(tokens.get(PROJECT_TOKEN)).thenReturn(PROJECT);
when(tokens.get(VERSION_TOKEN)).thenReturn(VERSION);
when(tokens.get(NAME_TOKEN)).thenReturn(NAME);
when(composerHostedFacet.getZipball(ZIPBALL_PATH)).thenReturn(null);
when(composerHostedFacet.getPackage(ZIPBALL_PATH)).thenReturn(null);
Response response = underTest.handle(context);
assertThat(response.getStatus().getCode(), is(404));
assertThat(response.getPayload(), is(nullValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class ComposerHostedFacetImplTest

private static final String ZIPBALL_PATH = "vendor/project/version/vendor-project-version.zip";

private static final String TARBALL_PATH = "vendor/project/version/vendor-project-version.tar";

private static final String PROVIDER_PATH = "p/vendor/project.json";

@Mock
Expand Down Expand Up @@ -105,7 +107,13 @@ public void testUpload() throws Exception {
@Test
public void testGetZipball() throws Exception {
when(composerContentFacet.get(ZIPBALL_PATH)).thenReturn(content);
assertThat(underTest.getZipball(ZIPBALL_PATH), is(content));
assertThat(underTest.getPackage(ZIPBALL_PATH), is(content));
}

@Test
public void testGetTarball() throws Exception {
when(composerContentFacet.get(TARBALL_PATH)).thenReturn(content);
assertThat(underTest.getPackage(TARBALL_PATH), is(content));
}

@Test
Expand Down
Loading