Hi Team,
I am new to groovy getting the below error while creating the maven proxy. Please help me i am struck on this issue from last week.
groovy.lang.MissingPropertyException: No such property: name for class: java.util.LinkedHashMap$Entry\Possible solutions: value
code i used is:
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import org.sonatype.nexus.repository.config.Configuration
import java.util.Map
parsed_args = new JsonSlurper().parseText(args)
List<Map<String, String>> actionDetails = []
Map scriptResults = [changed: false, error: false]
scriptResults.put('action_details', actionDetails)
repositoryManager = repository.repositoryManager
private Configuration newConfiguration(Map map) {
Configuration config
try {
config = repositoryManager.newConfiguration()
} catch (MissingMethodException) {
// Compatibility with nexus versions older than 3.21
config = Configuration.newInstance()
}
config.with {
repositoryName = map.repositoryName
recipeName = map.recipeName
online = map.online
attributes = map.attributes as Map
}
return config
}
private boolean configurationChanged(Configuration oldConfig, Configuration newConfig) {
if (oldConfig.attributes.httpclient)
if (oldConfig.attributes.httpclient.authentication == [:])
oldConfig.attributes.httpclient.authentication = null
return oldConfig.properties == newConfig.properties
}
parsed_args.each { currentRepo ->
Map<String, String> currentResult = [name: currentRepo.name, format: currentRepo.format, type: currentRepo.type]
recipeName = currentRepo.format + '-' + currentRepo.type
existingRepository = repositoryManager.get(currentRepo.name)
try {
if (existingRepository == null) {
log.info('Creating configuration for new repo {} (Format: {}, Type: {})', currentRepo.name, currentRepo.format, currentRepo.type)
// Default and/or immutable values
configuration = newConfiguration(
repositoryName: currentRepo.name,
recipeName: recipeName,
online: true,
attributes: [
storage: [
blobStoreName: currentRepo.blob_store
]
]
)
} else {
log.info('Loading configuration for existing repo {} (Format: {}, Type: {})', currentRepo.name, currentRepo.format, currentRepo.type)
// load existing repository configuration
configuration = existingRepository.configuration.copy()
}
// Configs common to all repos
configuration.attributes['storage']['strictContentTypeValidation'] = Boolean.valueOf(currentRepo.strict_content_validation)
// Configs for all proxy repos
if (currentRepo.type == 'proxy') {
authentication = currentRepo.remote_username == null ? null : [
type : 'username',
username: currentRepo.remote_username,
password: currentRepo.remote_password
]
configuration.attributes['httpclient'] = [
authentication: authentication,
blocked : false,
autoBlock : true,
connection : [
useTrustStore: false
]
]
configuration.attributes['proxy'] = [
remoteUrl : currentRepo.remote_url,
contentMaxAge : currentRepo.get('maximum_component_age', 1440.0),
metadataMaxAge: currentRepo.get('maximum_metadata_age', 1440.0)
]
configuration.attributes['negativeCache'] = [
enabled: currentRepo.get('negative_cache_enabled', true),
timeToLive: currentRepo.get('negative_cache_ttl', 1440.0)
]
}
// Configs for maven proxy repos
if (currentRepo.type in ['proxy'] && currentRepo.format == 'maven2') {
configuration.attributes['maven'] = [
versionPolicy: currentRepo.version_policy.toUpperCase(),
layoutPolicy : currentRepo.layout_policy.toUpperCase()
]
}
if (existingRepository == null) {
repositoryManager.create(configuration)
currentResult.put('status', 'created')
scriptResults['changed'] = true
log.info('Configuration for repo {} created', currentRepo.name)
} else {
if (!configurationChanged(existingRepository.configuration, configuration)) {
repositoryManager.update(configuration)
currentResult.put('status', 'updated')
log.info('Configuration for repo {} saved', currentRepo.name)
scriptResults['changed'] = true
} else {
currentResult.put('status', 'no change')
}
}
} catch (Exception e) {
currentResult.put('status', 'error')
currentResult.put('error_msg', e.toString())
scriptResults['error'] = true
log.error('Configuration for repo {} could not be saved: {}', currentRepo.name, e.toString())
}
scriptResults['action_details'].add(currentResult)
}
return JsonOutput.toJson(scriptResults)