com.netflix.gradle.plugins.packaging.AliasHelper.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-ospackage-plugin Show documentation
Show all versions of gradle-ospackage-plugin Show documentation
Provides a task similar to Tar and Zip for constructing RPM and DEB package files.
package com.netflix.gradle.plugins.packaging
import groovy.transform.CompileDynamic
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging
import java.lang.reflect.Field
import java.lang.reflect.Modifier
@CompileDynamic
class AliasHelper {
private static Logger logger = Logging.getLogger(AliasHelper);
static > void aliasEnumValues(T[] values, dynAware) {
for (T value : values) {
assert !dynAware.hasProperty(value.name())
logger.debug("Setting ${value.name()} onto ${dynAware}")
dynAware.metaClass."${value.name()}" = value
}
}
static void aliasStaticInstances(Class forClass, dynAware) {
aliasStaticInstances(forClass, forClass, dynAware)
}
static boolean hasModifier(Field field, int modifier) {
(field.modifiers & modifier) == modifier
}
static void aliasStaticInstances(Class forClass, Class ofClass, dynAware) {
for (Field field : forClass.fields) {
if (field.type == ofClass && hasModifier(field, Modifier.STATIC)) {
assert !dynAware.hasProperty(field.name)
logger.debug("Setting ${field.name} to ${field.get(null)} onto ${dynAware}")
dynAware.metaClass."${field.name}" = field.get(null)
}
}
}
}