Usage

Resolving properties

def noDefault = grolifantOps.resolveProperty('a.b.c') (1)
def withDefault = grolifantOps.resolveProperty('a.b.c', '1.2.3') (2)
1 A string provider that is resolved by first looking for a Gradle property named a.b.c, missing that a system property by the same name and finally an environment variable called A_B_C.
2 As above, but also set a default value.

Access to utilities that are configuration cache safe

grolifantOps.execTools() (1)
grolifantOps.fsOperations() (2)
grolifantOps.jvmTools() (3)
grolifantOps.providerTools() (4)
grolifantOps.projectTools() (5)
grolifantOps.stringTools() (6)
1 Utilities for running external processes.
2 Utilities for handling files and resources and converting objects to files and file collections.
3 Utilities for working with JVM processes and workers.
4 Utilities for providers.
5 Utilities for obtaining project information.
6 Utilities for converting objects to strings, URIs and Pattern instances.

Access to utilities that are only safe during the configuration phase

grolifantOps.configurationTools() (1)
grolifantOps.repositoryTools() (2)
grolifantOps.taskTools() (3)
1 Utilities for managing and creating configurations.
2 Utilities for manipulating repositories.
3 Utilities for manipulating tasks.

Useful string utilities

These are some examples of the string utilities

def s1 = grolifantOps.stringTools().stringize("1.2.3") (1)
def p1 = grolifantOps.stringTools().provideString("1.2.3") (2)
def s2 = grolifantOps.stringTools().stringizeOrNull("1.2.3") (3)
def s3 = grolifantOps.stringTools().stringize(["1.2.3", { -> '4.5.6' }]) (4)
def p2 = grolifantOps.stringTools().provideStrings(["1.2.3", { -> '4.5.6' }]) (5)
def p3 = grolifantOps.stringTools().provideStringsDropNull(["1.2.3", { -> '4.5.6' }, null]) (6)
def c1 = grolifantOps.stringTools().stringizeValues([a: { -> '1.2.3' }]) (7)
def c2 = grolifantOps.stringTools().stringizeValuesDropNull([a: { -> '1.2.3' }, b: null]) (8)
def p4 = grolifantOps.stringTools().provideValues([a: { -> '1.2.3' }]) (9)
def p5 = grolifantOps.stringTools().provideValues(project.provider { -> [a: { -> '1.2.3' }] }) (10)
1 Converts the object to a string immediately.
2 A provider that will convert the object to a string when realised.
3 Similar, but allows a null.
4 Resolves a collection of objects to a list of strings.
5 Only convert the collection when the provider is realised.
6 Lazy-evaluated, but drops anything that resolves to a null. The returned provider will always be present, but the contained list might be empty.
7 Converts the values of a map.
8 Converts the values of a map, but drops any entries where the value resolved to null.
9 Creates lazy-evaluates resolver.
10 Similar, but that a provider to a map.
The utilities recursively unwind until it gets to a real object. If you have a Provider that wraps an Optional, that wraps a Supplier, it will unwind all of those.

Useful file utilities

These are some examples of the file utilities

def f1 = grolifantOps.fsOperations().file('some.txt') (1)
def p1 = grolifantOps.fsOperations().provideFile('some.txt') (2)
def p2 = grolifantOps.fsOperations().provideRegularFile('some.txt') (3)
def p3 = grolifantOps.fsOperations().provideDirectory('path/to') (4)
def f2 = grolifantOps.fsOperations().files(['some.txt', 'others.txt']) (5)
1 Immediately resolves the object to a File.
2 Similar to the previous, but returns a provider to a resolved object. The supplied object must not resolve to null. If you need that option, replace provideFile, with provideFileNullable.
3 Instead of returning a Provider<File>, it returns a Provider<RegularFile>.
4 Instead of returning a Provider<File>, it returns a Provider<Directory>.
5 Immediately convert a collection of objects to a ConfigurableFileCollection.

Useful URI utilities

These are some examples of the URI utilities.

def u1 = grolifantOps.stringTools().urize('http://place.example') (1)
def p1 = grolifantOps.stringTools().provideUri('http://place.example') (2)
def s1 = grolifantOps.stringTools().hashUri(u1) (3)
def u2 = grolifantOps.stringTools().safeUri('http://USER:PASS@place.example'.toURI()) (4)
1 Immediately converts the object to a URI. If the passed object is a File or a Path, it creates a file: URI.
2 A provider to a lazy-evaluated object.
3 Creates a hash of a URI.
4 Creates a new URI where the password is masked out. Useful for printing and logging.

Useful Provider utilities

def p5 = grolifantOps.providerTools().zip3(p1, p2, p3) { uri, part1, part2 -> (1)
    uri.resolve(part1 + '/' + part2)
}
def p6 = grolifantOps.providerTools().resolveOrderly(p4, p3, p2) (2)
1 If you thought Provider.zip is useful for putting two providers together, you can also put three providers together with zip3, OR if you so need, four providers with zip4.
2 Resolves three string providers in order, taking the first provider that is not empty.