本文整理匯總了Java中groovy.lang.Closure類的典型用法代碼示例。如果您正苦於以下問題:Java Closure類的具體用法?Java Closure怎麽用?Java Closure使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Closure類屬於groovy.lang包,在下文中一共展示了Closure類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import groovy.lang.Closure; //導入依賴的package包/類
public void execute(T delegate) {
if (closure == null) {
return;
}
try {
if (configureableAware && delegate instanceof Configurable) {
((Configurable) delegate).configure(closure);
} else {
Closure copy = (Closure) closure.clone();
copy.setResolveStrategy(resolveStrategy);
copy.setDelegate(delegate);
if (copy.getMaximumNumberOfParameters() == 0) {
copy.call();
} else {
copy.call(delegate);
}
}
} catch (groovy.lang.MissingMethodException e) {
if (Objects.equal(e.getType(), closure.getClass()) && Objects.equal(e.getMethod(), "doCall")) {
throw new InvalidActionClosureException(closure, delegate);
}
throw e;
}
}
示例2: methodMissing
import groovy.lang.Closure; //導入依賴的package包/類
public Object methodMissing(String name, Object args) {
Object[] argsArray = (Object[]) args;
Configuration configuration = configurationContainer.findByName(name);
if (configuration == null) {
throw new MissingMethodException(name, this.getClass(), argsArray);
}
List<?> normalizedArgs = CollectionUtils.flattenCollections(argsArray);
if (normalizedArgs.size() == 2 && normalizedArgs.get(1) instanceof Closure) {
return doAdd(configuration, normalizedArgs.get(0), (Closure) normalizedArgs.get(1));
} else if (normalizedArgs.size() == 1) {
return doAdd(configuration, normalizedArgs.get(0), null);
} else {
for (Object arg : normalizedArgs) {
doAdd(configuration, arg, null);
}
return null;
}
}
示例3: configure
import groovy.lang.Closure; //導入依賴的package包/類
@Override
public LazyCredentialsExtension configure(Closure c) {
if (!Closure.class.isInstance(c.getDelegate()) ||
DefaultMavenArtifactRepository.class.isInstance(((Closure)c.getDelegate()))) {
throw new IllegalStateException("This extension can only be used in maven repository config.");
}
LazyCredentials credentials = new LazyCredentials(project);
Object originalDelegate = ((Closure)c.getDelegate()).getDelegate();
c.setResolveStrategy(Closure.DELEGATE_FIRST);
c.setDelegate(credentials);
c.call();
((DefaultMavenArtifactRepository) originalDelegate).setConfiguredCredentials(credentials);
return this;
}
示例4: signPom
import groovy.lang.Closure; //導入依賴的package包/類
/**
* Signs the POM artifact for the given Maven deployment.
*
* <p>You can use this method to sign the generated POM when publishing to a Maven repository with the Maven plugin. </p> <pre autoTested=''> uploadArchives { repositories { mavenDeployer {
* beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } } } } </pre> <p>You can optionally provide a configuration closure to fine tune the {@link SignOperation sign
* operation} for the POM.</p> <p> If {@link #isRequired()} is false and the signature cannot be generated (e.g. no configured signatory), this method will silently do nothing. That is, a
* signature for the POM file will not be uploaded.
*
* @param mavenDeployment The deployment to sign the POM of
* @param closure the configuration of the underlying {@link SignOperation sign operation} for the POM (optional)
* @return the generated signature artifact
*/
public Signature signPom(final MavenDeployment mavenDeployment, final Closure closure) {
SignOperation signOperation = doSignOperation(new Action<SignOperation>() {
public void execute(SignOperation so) {
so.sign(mavenDeployment.getPomArtifact());
so.configure(closure);
}
});
Signature pomSignature = signOperation.getSingleSignature();
if (!pomSignature.getFile().exists()) {
// This means that the signature was not required and we couldn't generate the signature
// (most likely project.required == false and there is no signatory)
// So just noop
return null;
}
// Have to alter the "type" of the artifact to match what is published
// See https://issues.gradle.org/browse/GRADLE-1589
pomSignature.setType("pom." + pomSignature.getSignatureType().getExtension());
mavenDeployment.addArtifact(pomSignature);
return pomSignature;
}
示例5: getByName
import groovy.lang.Closure; //導入依賴的package包/類
public T getByName(String name, Closure configureClosure) throws UnknownDomainObjectException {
T t = getByName(name);
ConfigureUtil.configure(configureClosure, t);
return t;
}
示例6: copy
import groovy.lang.Closure; //導入依賴的package包/類
public WorkResult copy(final Closure closure) {
return fileCopier.copy(new Action<CopySpec>() {
public void execute(CopySpec copySpec) {
copySpec.from(DefaultConfigurableFileTree.this);
ConfigureUtil.configure(closure, copySpec);
}
});
}
示例7: from
import groovy.lang.Closure; //導入依賴的package包/類
@Override
public DefaultManifest from(Object mergePaths, Closure<?> closure) {
DefaultManifestMergeSpec mergeSpec = new DefaultManifestMergeSpec();
mergeSpec.from(mergePaths);
manifestMergeSpecs.add(mergeSpec);
ConfigureUtil.configure(closure, mergeSpec);
return this;
}
示例8: logical
import groovy.lang.Closure; //導入依賴的package包/類
private static Object logical(Object node, String op, final Action<Object> withNode) {
GroovyObject groovyObject = (GroovyObject) node;
groovyObject.invokeMethod(op, new Closure(null, null) {
void doCall() {
withNode.execute(getDelegate());
}
});
return node;
}
示例9: on
import groovy.lang.Closure; //導入依賴的package包/類
/**
* Allows executing a consumer with some context to setup events.
*
* @param aggregate The aggregate on which the consumer must operate
* @param entityConsumer A Consumer that decides what happens when apply is called on an
* entity
* @param positionSupplier A supplier which offers the default position number for an event
* when it is not provided
* @param timestampSupplier A supplier that provides the date for an event if it isn't set
* @param closure The block of code to execute with the aggregate
*
* @return The aggregate after all the code has been executed
*/
public AggregateT on(
AggregateT aggregate, Consumer entityConsumer, Supplier<Long> positionSupplier,
Supplier<Date> timestampSupplier, @DelegatesTo(OnSpec.class) Closure closure) {
OnSpec<AggregateT, EventIdT, EventT, ?, ?> spec = new OnSpec<>();
spec.setAggregate(aggregate);
spec.setEntityConsumer(entityConsumer);
spec.setTimestampSupplier(timestampSupplier);
spec.setPositionSupplier(positionSupplier);
closure.setDelegate(spec);
closure.call(spec);
return aggregate;
}
示例10: createModule
import groovy.lang.Closure; //導入依賴的package包/類
public ClientModule createModule(Object dependencyNotation, Closure configureClosure) {
ClientModule clientModule = clientModuleNotationParser.parseNotation(dependencyNotation);
if (configureClosure != null) {
configureModule(clientModule, configureClosure);
}
return clientModule;
}
示例11: execute
import groovy.lang.Closure; //導入依賴的package包/類
public void execute(final Closure antClosure) {
classLoaderCache.withCachedClassLoader(libClasspath, gradleApiGroovyLoader, antAdapterGroovyLoader,
new Factory<ClassLoader>() {
@Override
public ClassLoader create() {
return new VisitableURLClassLoader(baseAntLoader, libClasspath);
}
}, new Action<CachedClassLoader>() {
@Override
public void execute(CachedClassLoader cachedClassLoader) {
ClassLoader classLoader = cachedClassLoader.getClassLoader();
Object antBuilder = newInstanceOf("org.gradle.api.internal.project.ant.BasicAntBuilder");
Object antLogger = newInstanceOf("org.gradle.api.internal.project.ant.AntLoggingAdapter");
// This looks ugly, very ugly, but that is apparently what Ant does itself
ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
try {
configureAntBuilder(antBuilder, antLogger);
// Ideally, we'd delegate directly to the AntBuilder, but its Closure class is different to our caller's
// Closure class, so the AntBuilder's methodMissing() doesn't work. It just converts our Closures to String
// because they are not an instanceof its Closure class.
Object delegate = new AntBuilderDelegate(antBuilder, classLoader);
ClosureBackedAction.execute(delegate, antClosure);
} finally {
Thread.currentThread().setContextClassLoader(originalLoader);
disposeBuilder(antBuilder, antLogger);
}
}
});
}
示例12: resources
import groovy.lang.Closure; //導入依賴的package包/類
public SourceSet resources(Closure configureClosure) {
return resources(ClosureBackedAction.of(configureClosure));
}
示例13: beforeTask
import groovy.lang.Closure; //導入依賴的package包/類
public void beforeTask(final Closure closure) {
taskListeners.add(new ClosureBackedMethodInvocationDispatch("beforeExecute", closure));
}
示例14: getByName
import groovy.lang.Closure; //導入依賴的package包/類
public U getByName(String name, Closure configureClosure) throws UnknownDomainObjectException {
return delegate.getByName(name, configureClosure);
}
示例15: and
import groovy.lang.Closure; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public AndSpec<T> and(Closure spec) {
return and(new ClosureSpec<T>(spec));
}