From 180acdeb7af6bea259e7baafa8e73b053a3a6baf Mon Sep 17 00:00:00 2001 From: buaacss Date: Sun, 21 Apr 2019 15:58:43 +0800 Subject: [PATCH] add satis --- .../composer/internal/AssetKind.java | 1 + .../internal/ComposerGroupRecipe.groovy | 11 ++++- .../ComposerHostedDownloadHandler.java | 5 +- .../internal/ComposerHostedFacet.java | 2 +- .../internal/ComposerHostedFacetImpl.java | 4 +- .../internal/ComposerHostedRecipe.groovy | 29 ++++++++++- .../internal/ComposerJsonProcessor.java | 4 +- .../composer/internal/ComposerPathUtils.java | 32 +++++------- .../internal/ComposerProxyFacetImpl.java | 11 +++-- .../internal/ComposerProxyRecipe.groovy | 16 +++++- .../internal/ComposerRecipeSupport.groovy | 6 ++- .../ComposerHostedDownloadHandlerTest.java | 31 ++++++++---- .../internal/ComposerHostedFacetImplTest.java | 10 +++- .../internal/ComposerPathUtilsTest.java | 13 +++-- .../internal/ComposerProxyFacetImplTest.java | 49 +++++++++++++++++-- 15 files changed, 166 insertions(+), 58 deletions(-) diff --git a/src/main/java/org/sonatype/nexus/repository/composer/internal/AssetKind.java b/src/main/java/org/sonatype/nexus/repository/composer/internal/AssetKind.java index a690258c..f9748b0a 100644 --- a/src/main/java/org/sonatype/nexus/repository/composer/internal/AssetKind.java +++ b/src/main/java/org/sonatype/nexus/repository/composer/internal/AssetKind.java @@ -23,6 +23,7 @@ public enum AssetKind { ZIPBALL(CONTENT), + TARBALL(CONTENT), PACKAGES(METADATA), LIST(METADATA), PROVIDER(METADATA); diff --git a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerGroupRecipe.groovy b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerGroupRecipe.groovy index 80d1c520..b62d96b0 100644 --- a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerGroupRecipe.groovy +++ b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerGroupRecipe.groovy @@ -89,7 +89,7 @@ class ComposerGroupRecipe .handler(providerJsonHandler) .create()) - builder.route(zipballMatcher() + builder.route(packageMatcher() .handler(timingHandler) .handler(assetKindHandler.rcurry(AssetKind.ZIPBALL)) .handler(securityHandler) @@ -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()) diff --git a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedDownloadHandler.java b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedDownloadHandler.java index 56013e14..bf1b5a78 100644 --- a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedDownloadHandler.java +++ b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedDownloadHandler.java @@ -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; @@ -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); } diff --git a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedFacet.java b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedFacet.java index acea423a..059aceb8 100644 --- a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedFacet.java +++ b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedFacet.java @@ -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; } diff --git a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedFacetImpl.java b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedFacetImpl.java index f74a12ef..c56a84ce 100644 --- a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedFacetImpl.java +++ b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedFacetImpl.java @@ -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); } diff --git a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedRecipe.groovy b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedRecipe.groovy index 3448606d..ddb10f5a 100644 --- a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedRecipe.groovy +++ b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedRecipe.groovy @@ -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 /** @@ -103,7 +104,7 @@ class ComposerHostedRecipe .handler(downloadHandler) .create()) - builder.route(zipballMatcher() + builder.route(packageMatcher() .handler(timingHandler) .handler(assetKindHandler.rcurry(ZIPBALL)) .handler(securityHandler) @@ -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)) @@ -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()) diff --git a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerJsonProcessor.java b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerJsonProcessor.java index 44e72c0e..d044cf5c 100644 --- a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerJsonProcessor.java +++ b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerJsonProcessor.java @@ -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 @@ -405,7 +405,7 @@ private Map buildDistInfo(final Repository repository, String packageProject = packageNameParts[1]; Map 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); diff --git a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerPathUtils.java b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerPathUtils.java index 4c829c2c..dfbc15d4 100644 --- a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerPathUtils.java +++ b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerPathUtils.java @@ -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"; @@ -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 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); } /** diff --git a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerProxyFacetImpl.java b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerProxyFacetImpl.java index f130ebd9..bfd984e6 100644 --- a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerProxyFacetImpl.java +++ b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerProxyFacetImpl.java @@ -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; @@ -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(); } @@ -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(); } @@ -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(); diff --git a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerProxyRecipe.groovy b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerProxyRecipe.groovy index 4d2725fc..5182cb45 100644 --- a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerProxyRecipe.groovy +++ b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerProxyRecipe.groovy @@ -129,7 +129,7 @@ class ComposerProxyRecipe .handler(proxyHandler) .create()) - builder.route(zipballMatcher() + builder.route(packageMatcher() .handler(timingHandler) .handler(assetKindHandler.rcurry(AssetKind.ZIPBALL)) .handler(securityHandler) @@ -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()) diff --git a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerRecipeSupport.groovy b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerRecipeSupport.groovy index 6b591133..2f9e7dc9 100644 --- a/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerRecipeSupport.groovy +++ b/src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerRecipeSupport.groovy @@ -56,6 +56,8 @@ abstract class ComposerRecipeSupport public static final String NAME_TOKEN = 'name' + public static final String TYPE_TOKEN = 'type' + @Inject Provider contentFacet @@ -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:.+}') )) } diff --git a/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedDownloadHandlerTest.java b/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedDownloadHandlerTest.java index c968ca8b..b233c19a 100644 --- a/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedDownloadHandlerTest.java +++ b/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedDownloadHandlerTest.java @@ -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 @@ -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(); @@ -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)); @@ -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())); diff --git a/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedFacetImplTest.java b/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedFacetImplTest.java index e2e8985b..98ec72e1 100644 --- a/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedFacetImplTest.java +++ b/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedFacetImplTest.java @@ -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 @@ -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 diff --git a/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerPathUtilsTest.java b/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerPathUtilsTest.java index 410a1688..5c037341 100644 --- a/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerPathUtilsTest.java +++ b/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerPathUtilsTest.java @@ -25,10 +25,7 @@ import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.when; -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.*; public class ComposerPathUtilsTest extends TestSupport @@ -55,8 +52,9 @@ public void buildZipballPathFromContextWithNameToken() { when(tokens.get(PROJECT_TOKEN)).thenReturn("testproject"); when(tokens.get(VERSION_TOKEN)).thenReturn("1.2.3"); when(tokens.get(NAME_TOKEN)).thenReturn("name"); + when(tokens.get(TYPE_TOKEN)).thenReturn("zip"); - assertThat(ComposerPathUtils.buildZipballPath(context), is("testvendor/testproject/1.2.3/name.zip")); + assertThat(ComposerPathUtils.buildPackagePath(context), is("testvendor/testproject/1.2.3/name.zip")); } @Test @@ -68,8 +66,9 @@ public void buildZipballPathFromContextWithoutNameToken() { when(tokens.get(VENDOR_TOKEN)).thenReturn("testvendor"); when(tokens.get(PROJECT_TOKEN)).thenReturn("testproject"); when(tokens.get(VERSION_TOKEN)).thenReturn("1.2.3"); + when(tokens.get(TYPE_TOKEN)).thenReturn("zip"); - assertThat(ComposerPathUtils.buildZipballPath(context), + assertThat(ComposerPathUtils.buildPackagePath(context), is("testvendor/testproject/1.2.3/testvendor-testproject-1.2.3.zip")); } @@ -79,7 +78,7 @@ public void buildZipballPathFromValues() { when(contextAttributes.require(TokenMatcher.State.class)).thenReturn(state); when(state.getTokens()).thenReturn(tokens); - assertThat(ComposerPathUtils.buildZipballPath("testvendor", "testproject", "1.2.3"), + assertThat(ComposerPathUtils.buildPackagePath("testvendor", "testproject", "1.2.3", null, "zip"), is("testvendor/testproject/1.2.3/testvendor-testproject-1.2.3.zip")); } diff --git a/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerProxyFacetImplTest.java b/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerProxyFacetImplTest.java index a1dda31f..5ae8fa3f 100644 --- a/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerProxyFacetImplTest.java +++ b/src/test/java/org/sonatype/nexus/repository/composer/internal/ComposerProxyFacetImplTest.java @@ -36,10 +36,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; 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.AssetKind.*; public class ComposerProxyFacetImplTest extends TestSupport @@ -52,6 +49,8 @@ public class ComposerProxyFacetImplTest private static final String ZIPBALL_PATH = "vendor/project/version/project-version.zip"; + private static final String TARBALL_PATH = "vendor/project/version/project-version.tar"; + @Mock private Repository repository; @@ -148,6 +147,25 @@ public void getCachedContentZipball() throws Exception { .put("project", "project") .put("version", "version") .put("name", "project-version") + .put("type", "zip") + .build()); + + assertThat(underTest.getCachedContent(context), is(content)); + } + + @Test + public void getCachedContentTarball() throws Exception { + when(contextAttributes.require(AssetKind.class)).thenReturn(ZIPBALL); + when(contextAttributes.require(TokenMatcher.State.class)).thenReturn(state); + + when(composerContentFacet.get(TARBALL_PATH)).thenReturn(content); + + when(state.getTokens()).thenReturn(new ImmutableMap.Builder() + .put("vendor", "vendor") + .put("project", "project") + .put("version", "version") + .put("name", "project-version") + .put("type", "tar") .build()); assertThat(underTest.getCachedContent(context), is(content)); @@ -196,6 +214,7 @@ public void indicateVerifiedZipball() throws Exception { .put("project", "project") .put("version", "version") .put("name", "project-version") + .put("type", "zip") .build()); underTest.indicateVerified(context, content, cacheInfo); @@ -203,6 +222,25 @@ public void indicateVerifiedZipball() throws Exception { verify(composerContentFacet).setCacheInfo(ZIPBALL_PATH, content, cacheInfo); } + + @Test + public void indicateVerifiedTarball() throws Exception { + when(contextAttributes.require(TokenMatcher.State.class)).thenReturn(state); + when(contextAttributes.require(AssetKind.class)).thenReturn(TARBALL); + + when(state.getTokens()).thenReturn(new ImmutableMap.Builder() + .put("vendor", "vendor") + .put("project", "project") + .put("version", "version") + .put("name", "project-version") + .put("type", "tar") + .build()); + + underTest.indicateVerified(context, content, cacheInfo); + + verify(composerContentFacet).setCacheInfo(TARBALL_PATH, content, cacheInfo); + } + @Test public void storePackages() throws Exception { when(contextAttributes.require(AssetKind.class)).thenReturn(PACKAGES); @@ -255,6 +293,7 @@ public void storeZipball() throws Exception { .put("project", "project") .put("version", "version") .put("name", "project-version") + .put("type", "zip") .build()); assertThat(underTest.store(context, content), is(content)); @@ -299,6 +338,7 @@ public void getUrlZipball() throws Exception { .put("project", "project") .put("version", "version") .put("name", "project-version") + .put("type", "zip") .build()); assertThat(underTest.getUrl(context), is("distUrl")); @@ -317,6 +357,7 @@ public void getUrlZipballMissingProviderJson() throws Exception { .put("project", "project") .put("version", "version") .put("name", "project-version") + .put("type", "zip") .build()); underTest.getUrl(context);