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

Job for purging unused releases #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -470,4 +470,18 @@ class TaskComponent
throw e
}
}

/**
* Retrieve a list of versions used for the purge of maven releases
*/
@DirectMethod
@Timed
@ExceptionMetered
@RequiresPermissions('nexus:tasks:read')
List<TaskOptionPurgeXO> readOptionsPurgeTask()
{
return [
new TaskOptionPurgeXO(name: 'version', description :"Version"),
new TaskOptionPurgeXO(name : 'dateRelease', description: "Release date")]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-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.coreui

import groovy.transform.ToString

@ToString(includePackage = false, includeNames = true)
class TaskOptionPurgeXO {

String name

String description
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Ext.define('NX.coreui.controller.Tasks', {
],
stores: [
'Task',
'TaskType'
'TaskType',
'TaskOptionPurge'
],
models: [
'Task'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-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.
*/
/**
* Task type model.
*
* @since 3.7
*/
Ext.define('NX.coreui.model.TaskOptionPurge', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string', sortType: 'asUCText'},
{name: 'description', type: 'string', sortType: 'asUCText'}
]
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-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.
*/
/*global Ext, NX*/

/**
* Task type store.
*
* @since 3.0
*/
Ext.define('NX.coreui.store.TaskOptionPurge', {
extend: 'Ext.data.Store',
model: 'NX.coreui.model.TaskOptionPurge',

proxy: {
type: 'direct',
paramsAsHash: false,

api: {
read: 'NX.direct.coreui_Task.readOptionsPurgeTask'
},

reader: {
type: 'json',
root: 'data',
idProperty : 'name',
successProperty: 'success'
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-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.maven;

import org.sonatype.nexus.repository.Facet;

/**
* Facet for purging unused Maven releases.
*
* @since 3.7
*/
@Facet.Exposed
public interface PurgeUnusedReleasesFacet extends Facet {


/**
* Purge the unused releases and keep the number of releases in parameter
* @param numberOfReleasesToKeep - the number of releases to keep
* @param option - Option used for purge
*/
void purgeUnusedReleases(int numberOfReleasesToKeep, String option);

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.sonatype.nexus.common.collect.NestedAttributesMap;
import org.sonatype.nexus.common.hash.HashAlgorithm;
import org.sonatype.nexus.repository.Repository;
import org.sonatype.nexus.repository.maven.MavenFacet;
import org.sonatype.nexus.repository.maven.MavenPath;
import org.sonatype.nexus.repository.maven.MavenPath.Coordinates;
import org.sonatype.nexus.repository.maven.MavenPath.HashType;
import org.sonatype.nexus.repository.maven.internal.hosted.metadata.MetadataUtils;
import org.sonatype.nexus.repository.storage.Asset;
import org.sonatype.nexus.repository.storage.Bucket;
import org.sonatype.nexus.repository.storage.Component;
Expand All @@ -47,10 +49,13 @@
import com.google.common.hash.HashCode;
import com.google.common.hash.HashingOutputStream;
import org.joda.time.DateTime;
import org.sonatype.nexus.transaction.UnitOfWork;

import static java.util.Collections.singletonList;
import static org.sonatype.nexus.common.app.VersionComparator.version;
import static org.sonatype.nexus.repository.maven.internal.Attributes.P_ARTIFACT_ID;
import static org.sonatype.nexus.repository.maven.internal.Attributes.P_BASE_VERSION;
import static org.sonatype.nexus.repository.maven.internal.Attributes.P_GROUP_ID;
import static org.sonatype.nexus.repository.maven.internal.Constants.SNAPSHOT_VERSION_SUFFIX;
import static org.sonatype.nexus.repository.storage.ComponentEntityAdapter.P_GROUP;
import static org.sonatype.nexus.repository.storage.ComponentEntityAdapter.P_VERSION;
Expand Down Expand Up @@ -219,4 +224,27 @@ public static boolean deleteWithHashes(final MavenFacet mavenFacet, final MavenP
}
return mavenFacet.delete(paths.toArray(new MavenPath[paths.size()]));
}

public static String deleteComponent(final StorageTx tx,
MavenFacet facet,
Component component) {
tx.deleteComponent(component);

NestedAttributesMap attributes = component.formatAttributes();
String groupId = attributes.get(P_GROUP_ID, String.class);
String artifactId = attributes.get(P_ARTIFACT_ID, String.class);
String baseVersion = attributes.get(P_BASE_VERSION, String.class);

try {
// We have to delete all metadata through GAV levels and rebuild in the next step, as the MetadataRebuilder
// isn't meant to remove metadata that has been orphaned by the deletion of a component
MavenFacetUtils.deleteWithHashes(facet, MetadataUtils.metadataPath(groupId, artifactId, baseVersion));
MavenFacetUtils.deleteWithHashes(facet, MetadataUtils.metadataPath(groupId, artifactId, null));
MavenFacetUtils.deleteWithHashes(facet, MetadataUtils.metadataPath(groupId, null, null));
}
catch (IOException e) {
throw new RuntimeException(e);
}
return groupId;
}
}
Loading