use of org.codehaus.groovy.runtime.MethodClosure in project ysoserial by frohoff.
the class Groovy1 method getObject.
public InvocationHandler getObject(final String command) throws Exception {
final ConvertedClosure closure = new ConvertedClosure(new MethodClosure(command, "execute"), "entrySet");
final Map map = Gadgets.createProxy(closure, Map.class);
final InvocationHandler handler = Gadgets.createMemoizedInvocationHandler(map);
return handler;
}
use of org.codehaus.groovy.runtime.MethodClosure in project gradle-apt-plugin by tbroyer.
the class AptEclipsePlugin method configureEclipse.
/**
* Inspired by
* https://github.com/mkarneim/pojobuilder/wiki/Enabling-PojoBuilder-for-Eclipse-Using-Gradle
*/
private void configureEclipse(final Project project, final SourceSet mainSourceSet, final SourceSet testSourceSet) {
final EclipseModel eclipseModel = project.getExtensions().getByType(EclipseModel.class);
project.afterEvaluate(new Action<Project>() {
@Override
public void execute(final Project project) {
eclipseModel.getClasspath().getPlusConfigurations().addAll(Arrays.asList(project.getConfigurations().getByName(new DslObject(mainSourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class).getCompileOnlyConfigurationName()), project.getConfigurations().getByName(new DslObject(testSourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class).getCompileOnlyConfigurationName())));
}
});
if (project.getTasks().findByName("eclipseJdtApt") == null) {
GenerateEclipseJdtApt task = project.getTasks().create("eclipseJdtApt", GenerateEclipseJdtApt.class, new Action<GenerateEclipseJdtApt>() {
@Override
public void execute(GenerateEclipseJdtApt generateEclipseJdtApt) {
generateEclipseJdtApt.setDescription("Generates the Eclipse JDT APT settings file.");
generateEclipseJdtApt.setInputFile(project.file(".settings/org.eclipse.jdt.apt.core.prefs"));
generateEclipseJdtApt.setOutputFile(project.file(".settings/org.eclipse.jdt.apt.core.prefs"));
final EclipseJdtApt jdtApt = generateEclipseJdtApt.getJdtApt();
new DslObject(eclipseModel.getJdt()).getConvention().getPlugins().put("net.ltgt.apt-eclipse", new JdtAptConvention(jdtApt));
ConventionMapping conventionMapping = new DslObject(jdtApt).getConventionMapping();
conventionMapping.map("aptEnabled", new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return project.getTasks().findByName(mainSourceSet.getCompileJavaTaskName()).getConvention().getPlugin(AptPlugin.AptConvention.class).getAptOptions().isAnnotationProcessing();
}
});
conventionMapping.map("genSrcDir", new Callable<File>() {
@Override
public File call() throws Exception {
return project.file(".apt_generated");
}
});
conventionMapping.map("processorOptions", new Callable<Map<String, ?>>() {
@Override
public Map<String, ?> call() throws Exception {
return project.getTasks().findByName(mainSourceSet.getCompileJavaTaskName()).getConvention().getPlugin(AptPlugin.AptConvention.class).getAptOptions().getProcessorArgs();
}
});
eclipseModel.getJdt().getFile().withProperties(// withProperties(Action) overload was added in Gradle 2.14
new MethodClosure(new Action<Properties>() {
@Override
public void execute(Properties properties) {
properties.setProperty("org.eclipse.jdt.core.compiler.processAnnotations", jdtApt.isAptEnabled() ? "enabled" : "disabled");
}
}, "execute"));
}
});
project.getTasks().getByName("eclipse").dependsOn(task);
Delete cleanTask = project.getTasks().create("cleanEclipseJdtApt", Delete.class);
cleanTask.delete(getOutputs(task));
project.getTasks().getByName("cleanEclipse").dependsOn(cleanTask);
}
if (project.getTasks().findByName("eclipseFactorypath") == null) {
GenerateEclipseFactorypath task = project.getTasks().create("eclipseFactorypath", GenerateEclipseFactorypath.class, new Action<GenerateEclipseFactorypath>() {
@Override
public void execute(GenerateEclipseFactorypath generateEclipseFactorypath) {
generateEclipseFactorypath.setDescription("Generates the Eclipse factorypath file.");
generateEclipseFactorypath.setInputFile(project.file(".factorypath"));
generateEclipseFactorypath.setOutputFile(project.file(".factorypath"));
EclipseFactorypath factorypath = generateEclipseFactorypath.getFactorypath();
new DslObject(eclipseModel).getConvention().getPlugins().put("net.ltgt.apt-eclipse", new FactorypathConvention(factorypath));
factorypath.setPlusConfigurations(new ArrayList<>(Arrays.asList(project.getConfigurations().getByName(new DslObject(mainSourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class).getAnnotationProcessorConfigurationName()), project.getConfigurations().getByName(new DslObject(testSourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class).getAnnotationProcessorConfigurationName()))));
generateEclipseFactorypath.dependsOn(factorypath.getPlusConfigurations().toArray());
}
});
project.getTasks().getByName("eclipse").dependsOn(task);
Delete cleanTask = project.getTasks().create("cleanEclipseFactorypath", Delete.class);
cleanTask.delete(getOutputs(task));
project.getTasks().getByName("cleanEclipse").dependsOn(cleanTask);
}
}
use of org.codehaus.groovy.runtime.MethodClosure in project gradle-apt-plugin by tbroyer.
the class AptIdeaPlugin method configureIdeaProject.
private void configureIdeaProject(final Project project) {
if (project.getParent() == null) {
final IdeaProject ideaProject = project.getExtensions().getByType(IdeaModel.class).getProject();
final ProjectAptConvention apt = new ProjectAptConvention();
new DslObject(ideaProject).getConvention().getPlugins().put("net.ltgt.apt-idea", apt);
ideaProject.getIpr().withXml(// withXml(Action) overload was added in Gradle 2.14
new MethodClosure(new Action<XmlProvider>() {
@Override
public void execute(XmlProvider xmlProvider) {
if (!apt.isConfigureAnnotationProcessing()) {
return;
}
for (Object it : (NodeList) xmlProvider.asNode().get("component")) {
Node compilerConfiguration = (Node) it;
if (!Objects.equals(compilerConfiguration.attribute("name"), "CompilerConfiguration")) {
continue;
}
for (Object n : (NodeList) compilerConfiguration.get("annotationProcessing")) {
compilerConfiguration.remove((Node) n);
}
Node annotationProcessing = compilerConfiguration.appendNode("annotationProcessing");
Map<String, Object> profileAttributes = new LinkedHashMap<>();
profileAttributes.put("name", "Default");
profileAttributes.put("enabled", true);
profileAttributes.put("default", true);
Node profile = annotationProcessing.appendNode("profile", profileAttributes);
// XXX: this assumes that all subprojects use the same name for their
// buildDir
profile.appendNode("sourceOutputDir", Collections.singletonMap("name", project.relativePath(project.getBuildDir()) + "/generated/source/apt/" + SourceSet.MAIN_SOURCE_SET_NAME));
profile.appendNode("sourceTestOutputDir", Collections.singletonMap("name", project.relativePath(project.getBuildDir()) + "/generated/source/apt/" + SourceSet.TEST_SOURCE_SET_NAME));
profile.appendNode("outputRelativeToContentRoot", Collections.singletonMap("value", true));
profile.appendNode("processorPath", Collections.singletonMap("useClasspath", true));
}
}
}, "execute"));
}
}
use of org.codehaus.groovy.runtime.MethodClosure in project rest-assured by rest-assured.
the class EncoderRegistry method buildDefaultEncoderMap.
/**
* Returns a map of default encoders. Override this method to change
* what encoders are registered by default. You can of course call
* <code>super.buildDefaultEncoderMap()</code> and then add or remove
* from that result as well.
*/
protected Map<String, Closure> buildDefaultEncoderMap() {
Map<String, Closure> encoders = new HashMap<String, Closure>();
encoders.put(ContentType.BINARY.toString(), new MethodClosure(this, "encodeStream"));
encoders.put(ContentType.TEXT.toString(), new MethodClosure(this, "encodeText"));
encoders.put(ContentType.URLENC.toString(), new MethodClosure(this, "encodeForm"));
Closure encClosure = new MethodClosure(this, "encodeXML");
for (String ct : ContentType.XML.getContentTypeStrings()) encoders.put(ct, encClosure);
encoders.put(ContentType.HTML.toString(), encClosure);
encClosure = new MethodClosure(this, "encodeJSON");
for (String ct : ContentType.JSON.getContentTypeStrings()) encoders.put(ct, encClosure);
return encoders;
}
use of org.codehaus.groovy.runtime.MethodClosure in project groovy-core by groovy.
the class ClosureMetaMethod method createMethodList.
public static List<MetaMethod> createMethodList(final String name, final Class declaringClass, final Closure closure) {
List<MetaMethod> res = new ArrayList<MetaMethod>();
if (closure instanceof MethodClosure) {
MethodClosure methodClosure = (MethodClosure) closure;
Object owner = closure.getOwner();
Class ownerClass = (Class) (owner instanceof Class ? owner : owner.getClass());
for (CachedMethod method : ReflectionCache.getCachedClass(ownerClass).getMethods()) {
if (method.getName().equals(methodClosure.getMethod())) {
MetaMethod metaMethod = new MethodClosureMetaMethod(name, declaringClass, closure, method);
res.add(adjustParamTypesForStdMethods(metaMethod, name));
}
}
} else {
if (closure instanceof GeneratedClosure) {
for (CachedMethod method : ReflectionCache.getCachedClass(closure.getClass()).getMethods()) {
if (method.getName().equals("doCall")) {
MetaMethod metaMethod = new ClosureMetaMethod(name, declaringClass, closure, method);
res.add(adjustParamTypesForStdMethods(metaMethod, name));
}
}
} else {
MetaMethod metaMethod = new AnonymousMetaMethod(closure, name, declaringClass);
res.add(adjustParamTypesForStdMethods(metaMethod, name));
}
}
return res;
}
Aggregations