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

Implement Composer group repositories #14

Merged
merged 32 commits into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
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
Apr 5, 2018
ccd28c2
Implement method for obtaining packages/hashes from flattened package…
Apr 6, 2018
c06c2f7
Make buildPackagesJson method public
Apr 6, 2018
eea435d
Implement handler for merging flattened packages.json files
Apr 6, 2018
24f834e
Use new handler for merging group member packages.json files
Apr 6, 2018
04703af
Implement method for merging provider JSON from group members
Apr 6, 2018
0b845f8
Implement handler for merging provider JSON files
Apr 6, 2018
5c1f928
Use new handler for merging group member provider JSON files
Apr 6, 2018
4980377
Be consistent when generating ad-hoc UID values
Apr 6, 2018
c47dd4e
Encapsulate merging of packages.json in ComposerJsonProcessor
Apr 6, 2018
5c303c2
Correct inaccurate comment
Apr 6, 2018
ef6d883
Merge branch 'master' into composer-group
Apr 17, 2018
95a20b5
Handle absence of proxied provider JSON more gracefully
Apr 19, 2018
60f7c2d
Merge branch 'master' into composer-group
May 31, 2018
957c425
Add additional fields to group merge
May 31, 2018
6d08022
Combine operations into single stream traversal
May 31, 2018
8b43ec5
Combine operations into single stream traversal (different location)
May 31, 2018
8f727aa
Extract shared group merge code into ComposerGroupMergingHandler
May 31, 2018
5ae0913
Extract JSON builder code to shared methods
May 31, 2018
88f058a
Simplify proxy JSON rewrite to consolidate code
May 31, 2018
41c9271
Unused import
May 31, 2018
70805ad
Use static import for Collections.singletonMap()
May 31, 2018
c2be896
Unused import
May 31, 2018
788b51a
Make requests unconditional
May 31, 2018
b2be78b
Include reference and shasum for proxy, hosted, and group
Jun 8, 2018
3e11cb0
Remove unused constant
Jun 8, 2018
5ff36a4
Support additional fields for proxy, hosted, and group
Jun 8, 2018
b3e9b80
Add @TheBay0r to contributors list for QA assistance
Jun 8, 2018
6a9f08c
Add target-dir key
Jun 8, 2018
fcbc942
Add some additional fields
Jun 8, 2018
9f29f63
Remove duplicated code
Jun 12, 2018
2780bc3
Use existing times in provider JSON group merges
Jun 12, 2018
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
@@ -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;
}
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);
}
}
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());
}
}
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))
Copy link
Contributor

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.

Copy link
Contributor Author

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.

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.

.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
}
}
Loading