From 9a059dc820dd28139d42830df84359fee6f8f5ac Mon Sep 17 00:00:00 2001 From: Anatoliy Ornatovskyy Date: Wed, 26 Aug 2020 13:32:59 +0300 Subject: [PATCH] NEXUS-23827 - PACKAGES.gz cannot be updated if R repo doesn't allow reupload --- .../r/internal/hosted/RHostedFacetImpl.java | 7 ++++ .../r/internal/hosted/RHostedRecipe.groovy | 2 +- .../internal/hosted/RWritePolicySelector.java | 40 +++++++++++++++++++ pom.xml | 4 +- 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 nexus-repository-r/src/main/java/org/sonatype/nexus/repository/r/internal/hosted/RWritePolicySelector.java diff --git a/nexus-repository-r/src/main/java/org/sonatype/nexus/repository/r/internal/hosted/RHostedFacetImpl.java b/nexus-repository-r/src/main/java/org/sonatype/nexus/repository/r/internal/hosted/RHostedFacetImpl.java index 60dc5fb0..e6dd60b3 100644 --- a/nexus-repository-r/src/main/java/org/sonatype/nexus/repository/r/internal/hosted/RHostedFacetImpl.java +++ b/nexus-repository-r/src/main/java/org/sonatype/nexus/repository/r/internal/hosted/RHostedFacetImpl.java @@ -21,6 +21,7 @@ import javax.inject.Named; import org.sonatype.nexus.repository.FacetSupport; +import org.sonatype.nexus.repository.config.Configuration; import org.sonatype.nexus.repository.r.RFacet; import org.sonatype.nexus.repository.r.RHostedFacet; import org.sonatype.nexus.repository.r.internal.util.RFacetUtils; @@ -55,6 +56,12 @@ public class RHostedFacetImpl extends FacetSupport implements RHostedFacet { + @Override + protected void doInit(final Configuration configuration) throws Exception { + super.doInit(configuration); + getRepository().facet(StorageFacet.class).registerWritePolicySelector(new RWritePolicySelector()); + } + @Override @TransactionalTouchBlob public Content getStoredContent(final String contentPath) { diff --git a/nexus-repository-r/src/main/java/org/sonatype/nexus/repository/r/internal/hosted/RHostedRecipe.groovy b/nexus-repository-r/src/main/java/org/sonatype/nexus/repository/r/internal/hosted/RHostedRecipe.groovy index 6f7c412c..97bbd251 100644 --- a/nexus-repository-r/src/main/java/org/sonatype/nexus/repository/r/internal/hosted/RHostedRecipe.groovy +++ b/nexus-repository-r/src/main/java/org/sonatype/nexus/repository/r/internal/hosted/RHostedRecipe.groovy @@ -76,13 +76,13 @@ class RHostedRecipe void apply(@Nonnull final Repository repository) throws Exception { repository.attach(securityFacet.get()) repository.attach(configure(viewFacet.get())) + repository.attach(storageFacet.get()) repository.attach(httpClientFacet.get()) repository.attach(componentMaintenanceFacet.get()) repository.attach(hostedFacet.get()) repository.attach(packagesBuilderFacet.get()) repository.attach(rFacet.get()) repository.attach(rRestoreFacet.get()) - repository.attach(storageFacet.get()) repository.attach(searchFacet.get()) repository.attach(attributesFacet.get()) } diff --git a/nexus-repository-r/src/main/java/org/sonatype/nexus/repository/r/internal/hosted/RWritePolicySelector.java b/nexus-repository-r/src/main/java/org/sonatype/nexus/repository/r/internal/hosted/RWritePolicySelector.java new file mode 100644 index 00000000..d7cf2371 --- /dev/null +++ b/nexus-repository-r/src/main/java/org/sonatype/nexus/repository/r/internal/hosted/RWritePolicySelector.java @@ -0,0 +1,40 @@ +/* + * 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.r.internal.hosted; + +import java.util.Objects; + +import org.sonatype.nexus.repository.storage.Asset; +import org.sonatype.nexus.repository.storage.WritePolicy; +import org.sonatype.nexus.repository.storage.WritePolicySelector; + +import static org.sonatype.nexus.repository.r.internal.AssetKind.PACKAGES; +import static org.sonatype.nexus.repository.r.internal.AssetKind.RDS_METADATA; +import static org.sonatype.nexus.repository.storage.AssetEntityAdapter.P_ASSET_KIND; +import static org.sonatype.nexus.repository.storage.WritePolicy.ALLOW; +import static org.sonatype.nexus.repository.storage.WritePolicy.ALLOW_ONCE; + +public class RWritePolicySelector implements WritePolicySelector +{ + @Override + public WritePolicy select(final Asset asset, final WritePolicy configured) { + if (ALLOW_ONCE == configured) { + final String assetKind = asset.formatAttributes().get(P_ASSET_KIND, String.class); + if (Objects.equals(PACKAGES.name(), assetKind) || + Objects.equals(RDS_METADATA.name(), assetKind)) { + return ALLOW; + } + } + return configured; + } +} diff --git a/pom.xml b/pom.xml index 16424966..b3c7c673 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ org.sonatype.nexus.plugins nexus-plugins - 3.27.0-SNAPSHOT + 3.28.0-SNAPSHOT nexus-repository-base @@ -47,7 +47,7 @@ - 3.27.0-SNAPSHOT + 3.28.0-SNAPSHOT