-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Composer hosted repositories (sonatype-nexus-community#12)
- Loading branch information
Showing
22 changed files
with
1,305 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...n/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedDownloadHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Sonatype Nexus (TM) Open Source Version | ||
* Copyright (c) 2018-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.sonatype.nexus.repository.composer.internal; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
import org.sonatype.nexus.repository.Repository; | ||
import org.sonatype.nexus.repository.http.HttpResponses; | ||
import org.sonatype.nexus.repository.view.Content; | ||
import org.sonatype.nexus.repository.view.Context; | ||
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.getProjectToken; | ||
import static org.sonatype.nexus.repository.composer.internal.ComposerPathUtils.getVendorToken; | ||
|
||
/** | ||
* Download handler for Composer hosted repositories. | ||
*/ | ||
@Named | ||
@Singleton | ||
public class ComposerHostedDownloadHandler | ||
implements Handler | ||
{ | ||
@Nonnull | ||
@Override | ||
public Response handle(@Nonnull final Context context) throws Exception { | ||
Repository repository = context.getRepository(); | ||
ComposerHostedFacet hostedFacet = repository.facet(ComposerHostedFacet.class); | ||
AssetKind assetKind = context.getAttributes().require(AssetKind.class); | ||
switch (assetKind) { | ||
case PACKAGES: | ||
return HttpResponses.ok(hostedFacet.getPackagesJson()); | ||
case LIST: | ||
throw new IllegalStateException("Unsupported assetKind: " + assetKind); | ||
case PROVIDER: | ||
return HttpResponses.ok(hostedFacet.getProviderJson(getVendorToken(context), getProjectToken(context))); | ||
case ZIPBALL: | ||
return responseFor(hostedFacet.getZipball(buildZipballPath(context))); | ||
default: | ||
throw new IllegalStateException("Unexpected assetKind: " + assetKind); | ||
} | ||
} | ||
|
||
private Response responseFor(@Nullable final Content content) { | ||
if (content == null) { | ||
return HttpResponses.notFound(); | ||
} | ||
return HttpResponses.ok(content); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedFacet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Sonatype Nexus (TM) Open Source Version | ||
* Copyright (c) 2018-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.sonatype.nexus.repository.composer.internal; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import org.sonatype.nexus.repository.Facet; | ||
import org.sonatype.nexus.repository.view.Content; | ||
import org.sonatype.nexus.repository.view.Payload; | ||
|
||
/** | ||
* Interface defining the features supported by Composer repository hosted facets. | ||
*/ | ||
@Facet.Exposed | ||
public interface ComposerHostedFacet | ||
extends Facet | ||
{ | ||
void upload(String path, Payload payload) throws IOException; | ||
|
||
Content getPackagesJson() throws IOException; | ||
|
||
Content getProviderJson(String vendor, String project) throws IOException; | ||
|
||
@Nullable | ||
Content getZipball(String path) throws IOException; | ||
} |
84 changes: 84 additions & 0 deletions
84
src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerHostedFacetImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Sonatype Nexus (TM) Open Source Version | ||
* Copyright (c) 2018-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.sonatype.nexus.repository.composer.internal; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
import org.sonatype.nexus.repository.FacetSupport; | ||
import org.sonatype.nexus.repository.storage.Query; | ||
import org.sonatype.nexus.repository.storage.StorageTx; | ||
import org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata; | ||
import org.sonatype.nexus.repository.view.Content; | ||
import org.sonatype.nexus.repository.view.Payload; | ||
import org.sonatype.nexus.transaction.UnitOfWork; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
import static java.util.Collections.singletonList; | ||
import static org.sonatype.nexus.repository.storage.ComponentEntityAdapter.P_GROUP; | ||
import static org.sonatype.nexus.repository.storage.MetadataNodeEntityAdapter.P_NAME; | ||
|
||
/** | ||
* Default implementation of a Composer hosted facet. | ||
*/ | ||
@Named | ||
public class ComposerHostedFacetImpl | ||
extends FacetSupport | ||
implements ComposerHostedFacet | ||
{ | ||
private final ComposerJsonProcessor composerJsonProcessor; | ||
|
||
@Inject | ||
public ComposerHostedFacetImpl(final ComposerJsonProcessor composerJsonProcessor) { | ||
this.composerJsonProcessor = checkNotNull(composerJsonProcessor); | ||
} | ||
|
||
@Override | ||
public void upload(final String path, final Payload payload) throws IOException { | ||
content().put(path, payload, AssetKind.ZIPBALL); | ||
} | ||
|
||
@Override | ||
public Content getZipball(final String path) throws IOException { | ||
return content().get(path); | ||
} | ||
|
||
@Override | ||
@TransactionalTouchMetadata | ||
public Content getPackagesJson() throws IOException { | ||
StorageTx tx = UnitOfWork.currentTx(); | ||
return composerJsonProcessor | ||
.generatePackagesFromComponents(getRepository(), tx.browseComponents(tx.findBucket(getRepository()))); | ||
} | ||
|
||
@Override | ||
@TransactionalTouchMetadata | ||
public Content getProviderJson(final String vendor, final String project) throws IOException { | ||
StorageTx tx = UnitOfWork.currentTx(); | ||
return composerJsonProcessor.buildProviderJson(getRepository(), | ||
tx.findComponents(buildQuery(vendor, project), singletonList(getRepository()))); | ||
} | ||
|
||
@VisibleForTesting | ||
protected Query buildQuery(final String vendor, final String project) { | ||
return Query.builder().where(P_GROUP).eq(vendor).and(P_NAME).eq(project).build(); | ||
} | ||
|
||
private ComposerContentFacet content() { | ||
return getRepository().facet(ComposerContentFacet.class); | ||
} | ||
} |
Oops, something went wrong.