Java Code Examples for org.gradle.api.Transformer#transform()

The following examples show how to use org.gradle.api.Transformer#transform() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static <I extends Closeable> Supplier<I> ofQuietlyClosed(final Factory<I> factory) {
    return new Supplier<I>() {
        public <R> R supplyTo(Transformer<R, ? super I> transformer) {
            I thing = factory.create();
            try {
                return transformer.transform(thing);
            } finally {
                try {
                    thing.close();
                } catch (Exception ignore) {
                    // ignore
                }
            }
        }
    };
}
 
Example 2
public static <I extends Closeable> Supplier<I> ofQuietlyClosed(final Factory<I> factory) {
    return new Supplier<I>() {
        public <R> R supplyTo(Transformer<R, ? super I> transformer) {
            I thing = factory.create();
            try {
                return transformer.transform(thing);
            } finally {
                try {
                    thing.close();
                } catch (Exception ignore) {
                    // ignore
                }
            }
        }
    };
}
 
Example 3
public ClassLoaderDetails getDetails(ClassLoader classLoader, Transformer<ClassLoaderDetails, ClassLoader> factory) {
    lock.lock();
    try {
        ClassLoaderDetails details = classLoaderDetails.getIfPresent(classLoader);
        if (details != null) {
            return details;
        }

        details = factory.transform(classLoader);
        classLoaderDetails.put(classLoader, details);
        classLoaderIds.put(details.uuid, classLoader);
        return details;
    } finally {
        lock.unlock();
    }
}
 
Example 4
public static <I extends Closeable> Supplier<I> ofQuietlyClosed(final Factory<I> factory) {
    return new Supplier<I>() {
        public <R> R supplyTo(Transformer<R, ? super I> transformer) {
            I thing = factory.create();
            try {
                return transformer.transform(thing);
            } finally {
                try {
                    thing.close();
                } catch (Exception ignore) {
                    // ignore
                }
            }
        }
    };
}
 
Example 5
public ClassLoaderDetails getDetails(ClassLoader classLoader, Transformer<ClassLoaderDetails, ClassLoader> factory) {
    lock.lock();
    try {
        ClassLoaderDetails details = classLoaderDetails.getIfPresent(classLoader);
        if (details != null) {
            return details;
        }

        details = factory.transform(classLoader);
        classLoaderDetails.put(classLoader, details);
        classLoaderIds.put(details.uuid, classLoader);
        return details;
    } finally {
        lock.unlock();
    }
}
 
Example 6
public static <I extends Closeable> Supplier<I> ofQuietlyClosed(final Factory<I> factory) {
    return new Supplier<I>() {
        public <R> R supplyTo(Transformer<R, ? super I> transformer) {
            I thing = factory.create();
            try {
                return transformer.transform(thing);
            } finally {
                try {
                    thing.close();
                } catch (Exception ignore) {
                    // ignore
                }
            }
        }
    };
}
 
Example 7
public static <I> Supplier<I> of(final Factory<? extends I> factory) {
    return new Supplier<I>() {
        public <R> R supplyTo(Transformer<R, ? super I> transformer) {
            I value = factory.create();
            return transformer.transform(value);
        }
    };
}
 
Example 8
public static <I> Supplier<I> of(final Factory<? extends I> factory) {
    return new Supplier<I>() {
        public <R> R supplyTo(Transformer<R, ? super I> transformer) {
            I value = factory.create();
            return transformer.transform(value);
        }
    };
}
 
Example 9
/**
 * Search methods in an inheritance aware fashion, stopping when stopIndicator returns true.
 */
public static void searchMethods(Class<?> target, final Transformer<Boolean, Method> stopIndicator) {
    Spec<Method> stopIndicatorAsSpec = new Spec<Method>() {
        public boolean isSatisfiedBy(Method element) {
            return stopIndicator.transform(element);
        }
    };

    findAllMethodsInternal(target, stopIndicatorAsSpec, new MultiMap<String, Method>(), new ArrayList<Method>(1), true);
}
 
Example 10
public <T> T withContent(Transformer<? extends T, ? super InputStream> readAction) throws IOException {
    InputStream input = openStream();
    try {
        return readAction.transform(input);
    } finally {
        input.close();
    }
}
 
Example 11
public static <I> Supplier<I> of(final Factory<? extends I> factory) {
    return new Supplier<I>() {
        public <R> R supplyTo(Transformer<R, ? super I> transformer) {
            I value = factory.create();
            return transformer.transform(value);
        }
    };
}
 
Example 12
private <K, V> Response<V> getResponse(Key<K> key, Cache<Key<K>, Response<V>> cache, Factory<Response<V>> responseFactory, Transformer<Key<K>, ? super Response<V>> keyGenerator) {
    Response<V> response = key == null ? null : cache.getIfPresent(key);
    if (response != null) {
        return response;
    } else {
        response = responseFactory.create();
        if (!response.isError()) {
            Key<K> actualKey = keyGenerator.transform(response);
            cache.put(actualKey, response);
        }
        return response;
    }
}
 
Example 13
public List<String> transform(T spec) {
    List<String> args = delegate.transform(spec);
    for (Transformer<List<String>, List<String>> transformer : transformers) {
        args = transformer.transform(args);
    }
    return args;
}
 
Example 14
public <T> T withIvy(Transformer<? extends T, ? super Ivy> action) {
    Integer currentDepth = depth.get();

    if (currentDepth != null) {
        depth.set(currentDepth + 1);
        try {
            return action.transform(IvyContext.getContext().getIvy());
        } finally {
            depth.set(currentDepth);
        }
    }

    IvyContext.pushNewContext();
    try {
        depth.set(1);
        try {
            Ivy ivy = getIvy();
            try {
                IvyContext.getContext().setIvy(ivy);
                return action.transform(ivy);
            } finally {
                releaseIvy(ivy);
            }
        } finally {
            depth.set(null);
        }
    } finally {
        IvyContext.popContext();
    }
}
 
Example 15
public static <I> Supplier<I> of(final Factory<? extends I> factory) {
    return new Supplier<I>() {
        public <R> R supplyTo(Transformer<R, ? super I> transformer) {
            I value = factory.create();
            return transformer.transform(value);
        }
    };
}
 
Example 16
public List<String> transform(T spec) {
    List<String> args = delegate.transform(spec);
    for (Transformer<List<String>, List<String>> transformer : transformers) {
        args = transformer.transform(args);
    }
    return args;
}
 
Example 17
public <T> T withContent(Transformer<? extends T, ? super InputStream> readAction) throws IOException {
    InputStream input = openStream();
    try {
        return readAction.transform(input);
    } finally {
        input.close();
    }
}
 
Example 18
public <T> T withIvy(Transformer<? extends T, ? super Ivy> action) {
    Integer currentDepth = depth.get();

    if (currentDepth != null) {
        depth.set(currentDepth + 1);
        try {
            return action.transform(IvyContext.getContext().getIvy());
        } finally {
            depth.set(currentDepth);
        }
    }

    IvyContext.pushNewContext();
    try {
        depth.set(1);
        try {
            Ivy ivy = getIvy();
            try {
                IvyContext.getContext().setIvy(ivy);
                return action.transform(ivy);
            } finally {
                releaseIvy(ivy);
            }
        } finally {
            depth.set(null);
        }
    } finally {
        IvyContext.popContext();
    }
}
 
Example 19
private <T> boolean hasModelPath(ModelPath candidate, Iterable<T> things, Transformer<? extends Iterable<ModelPath>, T> transformer) {
    for (T thing : things) {
        for (ModelPath path : transformer.transform(thing)) {
            if (path.equals(candidate)) {
                return true;
            }
        }
    }

    return false;
}
 
Example 20
private <T> boolean hasModelPath(ModelPath candidate, Iterable<T> things, Transformer<? extends Iterable<ModelPath>, T> transformer) {
    for (T thing : things) {
        for (ModelPath path : transformer.transform(thing)) {
            if (path.equals(candidate)) {
                return true;
            }
        }
    }

    return false;
}