-
Notifications
You must be signed in to change notification settings - Fork 82
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
Implement Composer group repositories #14
Merged
Merged
Changes from 24 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
3c08b93
Initial commit of group without merge
ccd28c2
Implement method for obtaining packages/hashes from flattened package…
c06c2f7
Make buildPackagesJson method public
eea435d
Implement handler for merging flattened packages.json files
24f834e
Use new handler for merging group member packages.json files
04703af
Implement method for merging provider JSON from group members
0b845f8
Implement handler for merging provider JSON files
5c1f928
Use new handler for merging group member provider JSON files
4980377
Be consistent when generating ad-hoc UID values
c47dd4e
Encapsulate merging of packages.json in ComposerJsonProcessor
5c303c2
Correct inaccurate comment
ef6d883
Merge branch 'master' into composer-group
95a20b5
Handle absence of proxied provider JSON more gracefully
60f7c2d
Merge branch 'master' into composer-group
957c425
Add additional fields to group merge
6d08022
Combine operations into single stream traversal
8b43ec5
Combine operations into single stream traversal (different location)
8f727aa
Extract shared group merge code into ComposerGroupMergingHandler
5ae0913
Extract JSON builder code to shared methods
88f058a
Simplify proxy JSON rewrite to consolidate code
41c9271
Unused import
70805ad
Use static import for Collections.singletonMap()
c2be896
Unused import
788b51a
Make requests unconditional
b2be78b
Include reference and shasum for proxy, hosted, and group
3e11cb0
Remove unused constant
5ff36a4
Support additional fields for proxy, hosted, and group
b3e9b80
Add @TheBay0r to contributors list for QA assistance
6a9f08c
Add target-dir key
fcbc942
Add some additional fields
9f29f63
Remove duplicated code
2780bc3
Use existing times in provider JSON group merges
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
...ain/java/org/sonatype/nexus/repository/composer/internal/ComposerGroupMergingHandler.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,69 @@ | ||
/* | ||
* 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.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import org.sonatype.nexus.repository.Repository; | ||
import org.sonatype.nexus.repository.group.GroupFacet; | ||
import org.sonatype.nexus.repository.group.GroupHandler; | ||
import org.sonatype.nexus.repository.http.HttpResponses; | ||
import org.sonatype.nexus.repository.http.HttpStatus; | ||
import org.sonatype.nexus.repository.view.Content; | ||
import org.sonatype.nexus.repository.view.Context; | ||
import org.sonatype.nexus.repository.view.Payload; | ||
import org.sonatype.nexus.repository.view.Response; | ||
|
||
import static org.sonatype.nexus.repository.http.HttpConditions.makeConditional; | ||
import static org.sonatype.nexus.repository.http.HttpConditions.makeUnconditional; | ||
|
||
/** | ||
* Abstract handler for merging in the context of a Composer group repository, with merging left to concrete | ||
* implementations of the class. | ||
*/ | ||
public abstract class ComposerGroupMergingHandler | ||
extends GroupHandler | ||
{ | ||
@Override | ||
protected final Response doGet(@Nonnull final Context context, | ||
@Nonnull final GroupHandler.DispatchedRepositories dispatched) | ||
throws Exception | ||
{ | ||
Repository repository = context.getRepository(); | ||
GroupFacet groupFacet = repository.facet(GroupFacet.class); | ||
|
||
makeUnconditional(context.getRequest()); | ||
Map<Repository, Response> responses; | ||
try { | ||
responses = getAll(context, groupFacet.members(), dispatched); | ||
} | ||
finally { | ||
makeConditional(context.getRequest()); | ||
} | ||
|
||
List<Payload> payloads = responses.values().stream() | ||
.filter(response -> response.getStatus().getCode() == HttpStatus.OK && response.getPayload() != null) | ||
.map(Response::getPayload) | ||
.collect(Collectors.toList()); | ||
if (payloads.isEmpty()) { | ||
return notFoundResponse(context); | ||
} | ||
return HttpResponses.ok(merge(repository, payloads)); | ||
} | ||
|
||
protected abstract Content merge(final Repository repository, final List<Payload> payloads) throws Exception; | ||
} |
46 changes: 46 additions & 0 deletions
46
...ava/org/sonatype/nexus/repository/composer/internal/ComposerGroupPackagesJsonHandler.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,46 @@ | ||
/* | ||
* 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.util.List; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
import org.sonatype.nexus.repository.Repository; | ||
import org.sonatype.nexus.repository.view.Content; | ||
import org.sonatype.nexus.repository.view.Payload; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* Handler for merging packages.json files together. | ||
*/ | ||
@Named | ||
@Singleton | ||
public class ComposerGroupPackagesJsonHandler | ||
extends ComposerGroupMergingHandler | ||
{ | ||
private final ComposerJsonProcessor composerJsonProcessor; | ||
|
||
@Inject | ||
public ComposerGroupPackagesJsonHandler(final ComposerJsonProcessor composerJsonProcessor) { | ||
this.composerJsonProcessor = checkNotNull(composerJsonProcessor); | ||
} | ||
|
||
@Override | ||
protected Content merge(final Repository repository, final List<Payload> payloads) throws Exception { | ||
return composerJsonProcessor.mergePackagesJson(repository, payloads); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ava/org/sonatype/nexus/repository/composer/internal/ComposerGroupProviderJsonHandler.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,49 @@ | ||
/* | ||
* 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 java.util.List; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
import org.sonatype.nexus.repository.Repository; | ||
import org.sonatype.nexus.repository.view.Content; | ||
import org.sonatype.nexus.repository.view.Payload; | ||
|
||
import org.joda.time.DateTime; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* Handler for merging provider JSON files together. | ||
*/ | ||
@Named | ||
@Singleton | ||
public class ComposerGroupProviderJsonHandler | ||
extends ComposerGroupMergingHandler | ||
{ | ||
private final ComposerJsonProcessor composerJsonProcessor; | ||
|
||
@Inject | ||
public ComposerGroupProviderJsonHandler(final ComposerJsonProcessor composerJsonProcessor) { | ||
this.composerJsonProcessor = checkNotNull(composerJsonProcessor); | ||
} | ||
|
||
@Override | ||
protected Content merge(final Repository repository, final List<Payload> payloads) throws IOException { | ||
return composerJsonProcessor.mergeProviderJson(repository, payloads, DateTime.now()); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
src/main/java/org/sonatype/nexus/repository/composer/internal/ComposerGroupRecipe.groovy
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,109 @@ | ||
/* | ||
* Sonatype Nexus (TM) Open Source Version | ||
* Copyright (c) 2017-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.inject.Inject | ||
import javax.inject.Named | ||
import javax.inject.Provider | ||
import javax.inject.Singleton | ||
|
||
import org.sonatype.nexus.repository.Format | ||
import org.sonatype.nexus.repository.Repository | ||
import org.sonatype.nexus.repository.Type | ||
import org.sonatype.nexus.repository.group.GroupFacetImpl | ||
import org.sonatype.nexus.repository.group.GroupHandler | ||
import org.sonatype.nexus.repository.http.HttpHandlers | ||
import org.sonatype.nexus.repository.types.GroupType | ||
import org.sonatype.nexus.repository.view.ConfigurableViewFacet | ||
import org.sonatype.nexus.repository.view.Router | ||
import org.sonatype.nexus.repository.view.ViewFacet | ||
|
||
/** | ||
* Recipe for creating a Composer group repository. | ||
*/ | ||
@Named(ComposerGroupRecipe.NAME) | ||
@Singleton | ||
class ComposerGroupRecipe | ||
extends ComposerRecipeSupport | ||
{ | ||
public static final String NAME = 'composer-group' | ||
|
||
@Inject | ||
Provider<GroupFacetImpl> groupFacet | ||
|
||
@Inject | ||
GroupHandler standardGroupHandler | ||
|
||
@Inject | ||
ComposerGroupPackagesJsonHandler packagesJsonHandler | ||
|
||
@Inject | ||
ComposerGroupProviderJsonHandler providerJsonHandler | ||
|
||
@Inject | ||
ComposerGroupRecipe(@Named(GroupType.NAME) final Type type, @Named(ComposerFormat.NAME) final Format format) { | ||
super(type, format) | ||
} | ||
|
||
@Override | ||
void apply(@Nonnull final Repository repository) throws Exception { | ||
repository.attach(groupFacet.get()) | ||
repository.attach(storageFacet.get()) | ||
repository.attach(securityFacet.get()) | ||
repository.attach(configure(viewFacet.get())) | ||
repository.attach(attributesFacet.get()) | ||
} | ||
|
||
/** | ||
* Configure {@link ViewFacet}. | ||
*/ | ||
private ViewFacet configure(final ConfigurableViewFacet facet) { | ||
Router.Builder builder = new Router.Builder() | ||
|
||
builder.route(packagesMatcher() | ||
.handler(timingHandler) | ||
.handler(assetKindHandler.rcurry(AssetKind.PACKAGES)) | ||
.handler(securityHandler) | ||
.handler(exceptionHandler) | ||
.handler(handlerContributor) | ||
.handler(packagesJsonHandler) | ||
.create()) | ||
|
||
builder.route(providerMatcher() | ||
.handler(timingHandler) | ||
.handler(assetKindHandler.rcurry(AssetKind.PROVIDER)) | ||
.handler(securityHandler) | ||
.handler(exceptionHandler) | ||
.handler(handlerContributor) | ||
.handler(providerJsonHandler) | ||
.create()) | ||
|
||
builder.route(zipballMatcher() | ||
.handler(timingHandler) | ||
.handler(assetKindHandler.rcurry(AssetKind.ZIPBALL)) | ||
.handler(securityHandler) | ||
.handler(exceptionHandler) | ||
.handler(handlerContributor) | ||
.handler(standardGroupHandler) | ||
.create()) | ||
|
||
addBrowseUnsupportedRoute(builder) | ||
|
||
builder.defaultHandlers(HttpHandlers.notFound()) | ||
|
||
facet.configure(builder.create()) | ||
|
||
return facet | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trivial: no reason not to statically import these asset kinds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left them without static imports in the other recipes; to me it does provide a bit of useful context, but I'm not averse to changing them as part of a tidying PR at some point.