Skip to content

Commit

Permalink
Heavily reformatted plugin code
Browse files Browse the repository at this point in the history
The formatting of all the plugin code has been mostly homogenized:
- All the plugins were fed through an autoformatter
- The header data (license, imports, javadoc) are mostly uniform
- Spacing within/indentation of comments is mostly sensible and uniform
- Some comments are wrapped to 80 characters
- All trailing whitespace is removed
- All empty lines immediately following a '{' are removed
- All empty lines immediately preceding a '}' are removed
- All contiguous sets of empty lines are truncated to a single line
- All files have exactly one trailing empty line
- Some other unnecessary empty lines have been removed
- Some empty lines between blocks/javadoc/etc have been added
  • Loading branch information
travisf committed Sep 18, 2015
1 parent 72c80b2 commit 2f20da3
Show file tree
Hide file tree
Showing 115 changed files with 1,247 additions and 1,208 deletions.
4 changes: 2 additions & 2 deletions ArtifactoryUserPlugins.gdsl
Expand Up @@ -3,15 +3,15 @@
*/

contributor(context(scriptScope())) {
//global context
// global context
property name: 'log', type: 'org.slf4j.Logger', doc: 'Writes to Artifactory log; logger name is the name of the script file '
property name: 'repositories', type: 'org.artifactory.repo.Repositories', doc: 'Allows queries and operations on repositories and artifacts '
property name: 'security', type: 'org.artifactory.security.Security', doc: 'Provides information about current security context, (e.g. current user and her permissions) '
property name: 'searches', type: 'org.artifactory.search.Searches', doc: 'API for searching for artifacts and builds'
property name: 'builds', type: 'org.artifactory.build.Builds', doc: 'Allows CRUD operations on builds'
property name: 'ctx', type: 'org.artifactory.spring.InternalArtifactoryContext', doc: 'Internal Artifactory context'

//plugin types
// plugin types
method name: 'download', type: 'void', params: [closure: 'groovy.lang.Closure'], doc: 'A section for handling and manipulating download events'
method name: 'storage', type: 'void', params: [closure: 'groovy.lang.Closure'], doc: 'A section for handling and manipulating storage events'
method name: 'jobs', type: 'void', params: [closure: 'groovy.lang.Closure'], doc: '''A section for defining scheduled jobs.<p>
Expand Down
5 changes: 4 additions & 1 deletion DB/DBSyncNotification/DBSyncNotification.groovy
Expand Up @@ -13,16 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.artifactory.addon.AddonsManager
import org.artifactory.addon.HaAddon
import org.artifactory.addon.ha.message.HaMessageTopic

/**
* This plugin will send a notification on CONFIG_CHANGE_TOPIC and ACL_CHANGE_TOPIC
*
* Created by Michal on 10/20/2014.
* To run this plugin use:
* curl -X GET -v -u {user}:{password} -X POST "http://{Artifactory_IP}/artifactory/api/plugins/execute/syncNotification"
*
* @author Michal
* @since 10/20/14
*/
executions {
syncNotification(description: 'send HA notifications for permission target and configuration change') {
Expand Down
9 changes: 5 additions & 4 deletions DB/DBSyncNotification/DBSyncNotificationTest.groovy
@@ -1,15 +1,16 @@
import static org.jfrog.artifactory.client.ArtifactoryClient.create
import spock.lang.Specification

import static org.jfrog.artifactory.client.ArtifactoryClient.create

class DBSyncNotificationTest extends Specification {
def 'test name'() {
setup:
def artifactory = create("http://localhost:8088/artifactory", "admin", "password")

//when:
// when:

//then:
// then:

//cleanup:
// cleanup:
}
}
5 changes: 3 additions & 2 deletions archive/archiveOldArtifacts/README.md
@@ -1,8 +1,9 @@
Artifactory Archive Old Artifacts User Plugin
=============================================

This plugin is used to archive artifacts from a given source repository in Artifactory to a given destination repository. The artifacts are chosen based on a mixture of available parameters.

This plugin is used to archive artifacts from a given source repository in
Artifactory to a given destination repository. The artifacts are chosen based on
a mixture of available parameters.

Installation
------------
Expand Down
98 changes: 45 additions & 53 deletions archive/archiveOldArtifacts/archiveOldArtifacts.groovy
Expand Up @@ -14,16 +14,11 @@
* limitations under the License.
*/

import org.artifactory.repo.RepoPath
import org.artifactory.repo.RepoPathFactory
import org.artifactory.fs.FileInfo
import org.artifactory.exception.CancelException
import org.artifactory.fs.StatsInfo
import org.artifactory.md.Properties
import org.artifactory.exception.CancelException

/**
* @author Adam Kunk
*/
import org.artifactory.repo.RepoPath
import org.artifactory.repo.RepoPathFactory

/**
* Example REST call(s):
Expand All @@ -49,8 +44,10 @@ import org.artifactory.exception.CancelException
* (NOTE: the time period archive policies are all specified in number of days)
*
* Available 'property' archive policies:
* 1. includePropertySet the artifact will be archived if it possesses all of the passed in properties
* 2. excludePropertySet the artifact will not be archived if it possesses all of the passed in properties
* 1. includePropertySet the artifact will be archived if it possesses all of
* the passed in properties
* 2. excludePropertySet the artifact will not be archived if it possesses all
* of the passed in properties
* (NOTE: property set format ==> prop[:value1[;prop2[:value2]......[;propN[:valueN]]])
* A property key must be provided, but a corresponding value is not necessary.
* If a property is set without a value, then a check is made for just the key.
Expand All @@ -72,22 +69,23 @@ import org.artifactory.exception.CancelException
* 4. Moves the artifact from the source repository to the destination repository specified
* 5. Adds a property containing the archive timestamp to the artifact
*
* @author Adam Kunk
*/

executions {
archive_old_artifacts { params ->
def filePattern = params['filePattern'] ? params['filePattern'][0] as String: '*'
def srcRepo = params['srcRepo'] ? params['srcRepo'][0] as String: 'build-packages'
def archiveRepo = params['archiveRepo'] ? params['archiveRepo'][0] as String: 'build-packages-archived'
def lastModifiedDays = params['lastModifiedDays'] ? params['lastModifiedDays'][0] as int: 0
def lastUpdatedDays = params['lastUpdatedDays'] ? params['lastUpdatedDays'][0] as int: 0
def createdDays = params['createdDays'] ? params['createdDays'][0] as int: 0
def lastDownloadedDays = params['lastDownloadedDays'] ? params['lastDownloadedDays'][0] as int: 0
def ageDays = params['ageDays'] ? params['ageDays'][0] as int: 0
def excludePropertySet = params['excludePropertySet'] ? params['excludePropertySet'][0] as String: ''
def includePropertySet = params['includePropertySet'] ? params['includePropertySet'][0] as String: ''
def archiveProperty = params['archiveProperty'] ? params['archiveProperty'][0] as String: 'archived.timestamp'
def numKeepArtifacts = params['numKeepArtifacts'] ? params['numKeepArtifacts'][0] as int: 0
def filePattern = params['filePattern'] ? params['filePattern'][0] as String : '*'
def srcRepo = params['srcRepo'] ? params['srcRepo'][0] as String : 'build-packages'
def archiveRepo = params['archiveRepo'] ? params['archiveRepo'][0] as String : 'build-packages-archived'
def lastModifiedDays = params['lastModifiedDays'] ? params['lastModifiedDays'][0] as int : 0
def lastUpdatedDays = params['lastUpdatedDays'] ? params['lastUpdatedDays'][0] as int : 0
def createdDays = params['createdDays'] ? params['createdDays'][0] as int : 0
def lastDownloadedDays = params['lastDownloadedDays'] ? params['lastDownloadedDays'][0] as int : 0
def ageDays = params['ageDays'] ? params['ageDays'][0] as int : 0
def excludePropertySet = params['excludePropertySet'] ? params['excludePropertySet'][0] as String : ''
def includePropertySet = params['includePropertySet'] ? params['includePropertySet'][0] as String : ''
def archiveProperty = params['archiveProperty'] ? params['archiveProperty'][0] as String : 'archived.timestamp'
def numKeepArtifacts = params['numKeepArtifacts'] ? params['numKeepArtifacts'][0] as int : 0

archiveOldArtifacts(
log,
Expand Down Expand Up @@ -125,20 +123,19 @@ class ArchiveConstants {
* that are not used in a meaningful way within an organization.
*/
private archiveOldArtifacts(
log,
filePattern,
srcRepo,
archiveRepo,
lastModifiedDays,
lastUpdatedDays,
createdDays,
lastDownloadedDays,
ageDays,
excludePropertySet,
includePropertySet,
archiveProperty,
numKeepArtifacts) {

log,
filePattern,
srcRepo,
archiveRepo,
lastModifiedDays,
lastUpdatedDays,
createdDays,
lastDownloadedDays,
ageDays,
excludePropertySet,
includePropertySet,
archiveProperty,
numKeepArtifacts) {
log.warn('Starting archive process for old artifacts ...')
log.info('File match pattern: {}', filePattern)
log.info('Source repository: {}', srcRepo)
Expand All @@ -161,7 +158,6 @@ private archiveOldArtifacts(
ageDays == 0 &&
excludePropertySet == '' &&
includePropertySet == '') {

log.error('No selection criteria specified, exiting now!')
throw new CancelException('No selection criteria specified!', 400)
}
Expand Down Expand Up @@ -198,7 +194,6 @@ private archiveOldArtifacts(
createdDays != 0 ||
lastDownloadedDays != 0 ||
ageDays != 0) {

log.info('We are going to perform a timing policies check...')

// Call the function to check if we need to archive based on timing policies
Expand Down Expand Up @@ -243,8 +238,7 @@ private archiveOldArtifacts(
def boolean keepArtifact = false

// Check if we are supposed to leave any number of artifacts per directory
if (numKeepArtifacts > 0)
{
if (numKeepArtifacts > 0) {
// Get the parent path
// NOTE: assuming one directory per unique type of artifact
def parentPath = artifact.getParent()
Expand Down Expand Up @@ -278,16 +272,15 @@ private archiveOldArtifacts(
properties.keys().each { key ->
Set<String> values = properties.get(key)
log.debug('Adding key: {}, values: {} to re-deployed artifact', key, values)
repositories.setProperty(artifact, key, * (values as List))
repositories.setProperty(artifact, key, *(values as List))
}

// Call the function to move the artifact
moveBuildArtifact(archiveRepo, artifact, archiveProperty, todayTime)

artifactsArchived++
}
}
else {
} else {
log.info('Not archiving artifact: {}', artifact)
log.debug('Timing archive policy status: {}', archiveTiming)
log.debug('Exclude properties policy status: {}', archiveExcludeProperties)
Expand All @@ -300,7 +293,7 @@ private archiveOldArtifacts(
}

// Function to move the build artifact and set a property for the time it was moved
def moveBuildArtifact (archiveRepo, RepoPath artifact, String property, time) {
def moveBuildArtifact(archiveRepo, RepoPath artifact, String property, time) {
// Get the translated file path for the new repo
def translatedFilePath = repositories.translateFilePath(artifact, archiveRepo)
log.debug('translatedFilePath: {}', translatedFilePath)
Expand All @@ -323,15 +316,14 @@ def moveBuildArtifact (archiveRepo, RepoPath artifact, String property, time) {

// Function to check if an artifact meets the archive timing policies
boolean checkArchiveTimingPolicies(
artifact,
lastModifiedDays,
lastUpdatedDays,
createdDays,
lastDownloadedDays,
ageDays,
itemInfo,
todayTime) {

artifact,
lastModifiedDays,
lastUpdatedDays,
createdDays,
lastDownloadedDays,
ageDays,
itemInfo,
todayTime) {
long compareDays

// Check the last modified policy if it is set
Expand Down
3 changes: 2 additions & 1 deletion archive/archiveOldArtifacts/archiveOldArtifactsTest.groovy
@@ -1,6 +1,7 @@
import static org.jfrog.artifactory.client.ArtifactoryClient.create
import spock.lang.Specification

import static org.jfrog.artifactory.client.ArtifactoryClient.create

class ArchiveOldArtifactsTest extends Specification {
def 'archive old artifacts plugin test'() {
setup:
Expand Down
4 changes: 2 additions & 2 deletions build/beforeBuildSave/beforeBuildSave.groovy
@@ -1,5 +1,5 @@
/*
* Copyright 2014 JFrog Ltd.
* Copyright (C) 2014 JFrog Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,7 +25,7 @@ build {
m.artifacts.each { a ->
def type = a.getType()
if (type.contains(';')) {
a.setType(type.substring(0,type.indexOf(';')))
a.setType(type.substring(0, type.indexOf(';')))
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions build/beforeBuildSave/beforeBuildSaveTest.groovy
@@ -1,15 +1,16 @@
import static org.jfrog.artifactory.client.ArtifactoryClient.create
import spock.lang.Specification

import static org.jfrog.artifactory.client.ArtifactoryClient.create

class BeforeBuildSaveTest extends Specification {
def 'test name'() {
setup:
def artifactory = create("http://localhost:8088/artifactory", "admin", "password")

//when:
// when:

//then:
// then:

//cleanup:
// cleanup:
}
}
19 changes: 10 additions & 9 deletions build/buildPropertySetter/buildPropertySetter.groovy
Expand Up @@ -13,25 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* This plugin show tagging all files published by a build with latest=true
* whenever a new build arrives
*/

import org.artifactory.build.BuildRun
import org.artifactory.build.DetailedBuildRun
import org.artifactory.repo.RepoPath

import static com.google.common.collect.Multimaps.forMap

/**
* This plugin show tagging all files published by a build with latest=true
* whenever a new build arrives
*/

build {
afterSave { DetailedBuildRun buildRun ->
if (shouldActivateLatest(buildRun)) {
log.info "Build ${buildRun.getName()}:${buildRun.getNumber()} artifacts set to latest"
// First remove all latest=true flags for same build name
searches.itemsByProperties(forMap([
'build.name': buildRun.getName(),
'latest': 'true'
'build.name': buildRun.getName(),
'latest' : 'true'
])).each { RepoPath previousLatest ->
log.debug "Artifact ${previousLatest.getId()} removed from latest"
repositories.deleteProperty(previousLatest, 'latest')
Expand All @@ -41,8 +42,8 @@ build {
Set<String> publishedHashes = new HashSet<>()
buildRun.modules?.each { it.artifacts?.each { publishedHashes << it.sha1 } }
searches.itemsByProperties(forMap([
'build.name': buildRun.getName(),
'build.number': buildRun.getNumber()
'build.name' : buildRun.getName(),
'build.number': buildRun.getNumber()
])).each { RepoPath published ->
def info = repositories.getFileInfo(published)
if (publishedHashes.contains(info.sha1)) {
Expand All @@ -55,7 +56,7 @@ build {
}
}

boolean shouldActivateLatest( BuildRun buildRun ) {
boolean shouldActivateLatest(BuildRun buildRun) {
log.debug "Evaluating if build ${buildRun.getName()}:${buildRun.getNumber()} should be set to latest!"
true
}
9 changes: 5 additions & 4 deletions build/buildPropertySetter/buildPropertySetterTest.groovy
@@ -1,15 +1,16 @@
import static org.jfrog.artifactory.client.ArtifactoryClient.create
import spock.lang.Specification

import static org.jfrog.artifactory.client.ArtifactoryClient.create

class BuildPropertySetterTest extends Specification {
def 'test name'() {
setup:
def artifactory = create("http://localhost:8088/artifactory", "admin", "password")

//when:
// when:

//then:
// then:

//cleanup:
// cleanup:
}
}

0 comments on commit 2f20da3

Please sign in to comment.