##// END OF EJS Templates
Implemented RunContainer, ExecContainer, StopContainer, RmContainer, ComposeExec tasks
Implemented RunContainer, ExecContainer, StopContainer, RmContainer, ComposeExec tasks

File last commit:

r19:5e6d0e24a5d2 v1.3.0 default
r19:5e6d0e24a5d2 v1.3.0 default
Show More
ProjectMixin.java
69 lines | 2.5 KiB | text/x-java-source | JavaLexer
package org.implab.gradle.containers;
import java.util.Collections;
import java.util.Optional;
import javax.inject.Inject;
import org.gradle.api.Action;
import org.gradle.api.NamedDomainObjectProvider;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.file.Directory;
import org.gradle.api.tasks.TaskProvider;
import org.implab.gradle.containers.dsl.ExtraProps;
import org.implab.gradle.containers.dsl.MapEntry;
/** Project configuration traits */
public interface ProjectMixin {
@Inject
Project getProject();
/** registers the new task */
default <T extends Task> TaskProvider<T> task(String name, Class<T> clazz, Action<? super T> configure) {
return getProject().getTasks().register(name, clazz, configure);
}
/** Registers the new configuration */
default NamedDomainObjectProvider<Configuration> configuration(String name, Action<? super Configuration> configure) {
return getProject().getConfigurations().register(name, configure);
}
/** Returns the project directory */
default Directory projectDirectory() {
return getProject().getLayout().getProjectDirectory();
}
/** Applies and returns the specified plugin, the plugin is applied only once. */
default <T extends Plugin<Project>> T plugin(Class<T> clazz) {
getProject().getPluginManager().apply(clazz);
return getProject().getPlugins().findPlugin(clazz);
}
/** Creates and register a new project extension.
*
* @param <T> The type of the extension
* @param extensionName The name of the extension in the project
* @param clazz The class of the extension
* @return the newly created extension
*/
default <T> T extension(String extensionName, Class<T> clazz) {
T extension = getProject().getObjects().newInstance(clazz);
getProject().getExtensions().add(extensionName, extension);
return extension;
}
/** Return extra properties container for the specified object */
default Optional<ExtraProps> extra(Object target) {
return ExtraProps.extra(target);
}
/** Returns accessor for the specified extra property name */
default <T> MapEntry<T> extra(Object target, String prop, Class<T> clazz) {
return ExtraProps.extra(target)
.map(x -> x.prop(prop, clazz))
.orElseGet(() -> new MapEntry<T>(Collections.emptyMap(), prop, clazz));
}
}