热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

清理nexus3日志,从Nexus3清除旧版本

IuseNexus3andIwanttodeletemyoldreleases.InNexus2thereisascheduledtaskcalledRemoveReleasesF

I use Nexus 3 and I want to delete my old releases. In Nexus 2 there is a scheduled task called Remove Releases From Repository. It seems that this tasks is missing in Nexus 3.

How can we delete old release from Nexus 3 ?

Thanks

解决方案

Since the release of nexus 3 you can deploy groovy scripts to the nexus manager. Simply create a new execute script task and use the following script:

import org.sonatype.nexus.repository.storage.StorageFacet;

import org.sonatype.nexus.common.app.GlobalComponentLookupHelper

import org.sonatype.nexus.repository.maintenance.MaintenanceService

import org.sonatype.nexus.repository.storage.ComponentMaintenance

import org.sonatype.nexus.repository.storage.Query;

import org.sonatype.nexus.script.plugin.RepositoryApi

import org.sonatype.nexus.script.plugin.internal.provisioning.RepositoryApiImpl

import com.google.common.collect.ImmutableList

import org.joda.time.DateTime;

import org.slf4j.Logger

// ----------------------------------------------------

// delete these rows when this script is added to nexus

RepositoryApiImpl repository = null;

Logger log = null;

GlobalComponentLookupHelper container = null;

// ----------------------------------------------------

def retentionDays = 30;

def retentionCount = 10;

def repositoryName = 'maven-releases';

def whitelist = ["org.javaee7.sample/javaee7-simple-sample", "org.javaee7.next/javaee7-another-sample"].toArray();

log.info(":::Cleanup script started!");

MaintenanceService service = container.lookup("org.sonatype.nexus.repository.maintenance.MaintenanceService");

def repo = repository.repositoryManager.get(repositoryName);

def tx = repo.facet(StorageFacet.class).txSupplier().get();

def components = null;

try {

tx.begin();

components = tx.browseComponents(tx.findBucket(repo));

}catch(Exception e){

log.info("Error: "+e);

}finally{

if(tx!=null)

tx.close();

}

if(components != null) {

def retentionDate = DateTime.now().minusDays(retentionDays).dayOfMonth().roundFloorCopy();

int deletedComponentCount = 0;

int compCount = 0;

def listOfComponents = ImmutableList.copyOf(components);

def previousComp = listOfComponents.head().group() + listOfComponents.head().name();

listOfComponents.reverseEach{comp ->

log.info("Processing Component - group: ${comp.group()}, ${comp.name()}, version: ${comp.version()}");

if(!whitelist.contains(comp.group()+"/"+comp.name())){

log.info("previous: ${previousComp}");

if(previousComp.equals(comp.group() + comp.name())) {

compCount++;

log.info("ComCount: ${compCount}, ReteCount: ${retentionCount}");

if (compCount > retentionCount) {

log.info("CompDate: ${comp.lastUpdated()} RetDate: ${retentionDate}");

if(comp.lastUpdated().isBefore(retentionDate)) {

log.info("compDate after retentionDate: ${comp.lastUpdated()} isAfter ${retentionDate}");

log.info("deleting ${comp.group()}, ${comp.name()}, version: ${comp.version()}");

// ------------------------------------------------

// uncomment to delete components and their assets

// service.deleteComponent(repo, comp);

// ------------------------------------------------

log.info("component deleted");

deletedComponentCount++;

}

}

} else {

compCount = 1;

previousComp = comp.group() + comp.name();

}

}else{

log.info("Component skipped: ${comp.group()} ${comp.name()}");

}

}

log.info("Deleted Component count: ${deletedComponentCount}");

}

This script will clean your nexus repository by the specified parameters at the top.



推荐阅读
  • Java太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • 本文介绍了一个Java猜拳小游戏的代码,通过使用Scanner类获取用户输入的拳的数字,并随机生成计算机的拳,然后判断胜负。该游戏可以选择剪刀、石头、布三种拳,通过比较两者的拳来决定胜负。 ... [详细]
  • Java容器中的compareto方法排序原理解析
    本文从源码解析Java容器中的compareto方法的排序原理,讲解了在使用数组存储数据时的限制以及存储效率的问题。同时提到了Redis的五大数据结构和list、set等知识点,回忆了作者大学时代的Java学习经历。文章以作者做的思维导图作为目录,展示了整个讲解过程。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 本文介绍了如何在给定的有序字符序列中插入新字符,并保持序列的有序性。通过示例代码演示了插入过程,以及插入后的字符序列。 ... [详细]
  • JavaSE笔试题-接口、抽象类、多态等问题解答
    本文解答了JavaSE笔试题中关于接口、抽象类、多态等问题。包括Math类的取整数方法、接口是否可继承、抽象类是否可实现接口、抽象类是否可继承具体类、抽象类中是否可以有静态main方法等问题。同时介绍了面向对象的特征,以及Java中实现多态的机制。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 关键词:Golang, Cookie, 跟踪位置, net/http/cookiejar, package main, golang.org/x/net/publicsuffix, io/ioutil, log, net/http, net/http/cookiejar ... [详细]
  • 个人学习使用:谨慎参考1Client类importcom.thoughtworks.gauge.Step;importcom.thoughtworks.gauge.T ... [详细]
author-avatar
情系50后_989
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有