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
Source File: Suppliers.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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
Source File: Suppliers.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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
Source File: ClassLoaderCache.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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
Source File: Suppliers.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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
Source File: ClassLoaderCache.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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
Source File: Suppliers.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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
Source File: AbstractExternalResource.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T> T withContent(Transformer<? extends T, ? super InputStream> readAction) throws IOException {
    InputStream input = openStream();
    try {
        return readAction.transform(input);
    } finally {
        input.close();
    }
}
 
Example 8
Source File: Suppliers.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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
Source File: JavaReflectionUtil.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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
Source File: InMemoryCachingPluginResolutionServiceClient.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 11
Source File: CompileSpecToArgsTransformerChain.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 12
Source File: DefaultIvyContextManager.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 13
Source File: Suppliers.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 14
Source File: Suppliers.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 15
Source File: Suppliers.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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
Source File: CompileSpecToArgsTransformerChain.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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
Source File: AbstractExternalResource.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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
Source File: DefaultIvyContextManager.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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
Source File: DefaultModelRegistry.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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
Source File: DefaultModelRegistry.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}