Error compiling jsp files using ant from gradle - ant

I'm getting an error when i try to execute a custom gradle task to pre-compile jsp files.
My task looks like:
task compile_jsp(dependsOn: 'compileJava') << {
//Define master classpath
def masterpath = ant.path(id: 'master-classpath') {
fileset(dir: "${rootDir}/build/libs"){
include(name: '**.jar')
}
fileset(dir: sourceSets.main.output.classesDir) {
include(name: '**/*.class')
}
fileset(dir: "${rootDir}/src/main"){
include(name: '**/*.java')
}
}
ant.taskdef(classname: 'org.apache.jasper.JspC', name: 'jasper', classpath: configurations.jasper.asPath + masterpath)
ant.jasper(uriRoot: "${rootDir}/src/main/webapp/", outputDir: "${rootDir}/src/main/webapp/WEB-INF/" + "${compileJspOutputDir}/", webXmlFragment: "${rootDir}/src/main/webapp/WEB-INF/generated_web.xml", addWebXmlMappings: "true")
}
The error that i get is something like:
The value for the useBean class attribute <class> is invalid.
I think its related to the classes location in the project because the task works well if i define the sourceSets.main.output.classesDir like:
sourceSets.main.output.classesDir = "${rootDir}/src/main/webapp/WEB-INF/classes"
Otherwise, i get the mentioned error.
Is there any way to run this without change the classes dir?

Related

How can I move the AndroidManifest.xml file with the experimental gradle plugin 0.7.x?

I'm trying to change the location of the AndroidManifest.xml file when using the experimental gradle plugin version 0.7.x. The reason for doing this is that I generate the file (as there is no manifest merger/property replacer in the experimental plugin) so I don't want an output file together with the sources.
My app build.gradle:
apply plugin: "com.android.model.application"
def buildDir = project.buildDir
model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.myapp.android"
minSdkVersion.apiLevel 9
targetSdkVersion.apiLevel 23
versionCode 1
versionName "1.0"
}
sources {
main {
manifest {
source {
srcDirs = ["$buildDir"]
}
}
}
}
}
}
task createManifest {
doLast {
buildDir.mkdirs()
new FileOutputStream(new File(buildDir, "AndroidManifest.xml"))
}
}
tasks.all { task ->
if (task.name.startsWith('check') && task.name.endsWith('Manifest')) {
task.dependsOn createManifest
}
}
The above configures fine but when I try to build I get:
A problem was found with the configuration of task ':app:checkDebugManifest'.
> File '/home/the_jk/source/test/app/src/main/AndroidManifest.xml' specified for property 'manifest' does not exist.`
I cannot seem to change the default manifest "property" at all, anyone had any luck?
Try
manifest { source { srcDirs = $buildDir } }
This seems to do ok with just 1 manifest, but the experimental plugin barfs if you give it 2 directories that you want to merge.
(I'm also guessing you have some other task to generate the manifest in the $buildDir since that gets blown away by clean tasks....)
Update:
Secondary issue, the check[Deubg|Release]Manifest task wants the file to exist when it runs. The above works ok for me for a static file. For something generated from a task in the build directory I had to add a dependency that looks like
task createManifest {
// code to create $buildDir if it did not exist
// code to generate AndrdroidManfest.xml in $buildDir
}
tasks.all {
task ->
if (task.name.startsWith('check') && task.name.endsWith('Manifest')) {
task.dependsOn createManifest
}
}
The tasks.all loop lets me only add it if checkDebugManifest and/or checkReleaseManifest tasks are going to happen (I had trouble with ./gradlew clean not finding the checkDebugManifest task without it.)
I had a similar issue with com.android.tools.build:gradle-experimental:0.7.0-alpha4. The way I solve it was with the following code:
sources {
main {
manifest {
source {
srcDirs = [ "$buildDir" ]
}
}
}
}

grails kickstart plugin KickstartFilters how to prevent password information on logs

I am using Grails version 2.2.4 and I have installed kickstart plugin as compile ":kickstart-with-bootstrap:0.9.6".
BuildConfig.groovy
plugins {
runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.8.3"
runtime ":resources:1.1.6"
compile ":kickstart-with-bootstrap:0.9.6"
build ":tomcat:$grailsVersion"
runtime ":database-migration:1.3.2"
compile ':cache:1.0.1'
}
I found "KickstartFilters.groovy" filter with following directory structure
plugin
-> kickstart-with-bootstrap:0.9.6
-> conf
-> kickstart
-> KickstartFilters.groovy
my "KickstartFilters.groovy" file contains following information
package kickstart
class KickstartFilters {
def filters = {
all() {
before = {
// Small "logging" filter for controller & actions
log.info(!params.controller ? '/: ' + params : params.controller +"."+(params.action ?: "index")+": "+params)
}
after = {
}
afterView = {
}
}
}
}
while log.info are printed in logs at that time if password is passed as params then password information are visible on log so how can I prevent only password Information?
I have a work around for this...
https://github.com/joergrech/KickstartWithBootstrap/issues/84
Basically create your filter under conf/kickstart/YourAppFilters.groovy
package kickstart
class YourAppFilters extends KickstartFilters {
def filters = {
kickstartLogger() {
before = {
// Small "logging" filter for controller & actions
if (log.infoEnabled) {
if (!params.controller.equals('chat')) {
if (!params.password ) {
log.info(!params.controller ? '/: ' + params : params.controller +"."+(params.action ?: "index")+": "+params)
}else{
log.info (params.controller+","+params.action+":"+params?.username)
}
}
}
}
}
}
}
Now under conf/spring/resources.groovy under beans add:
yourAppFilters(KickstartFilters)
This should now override kickstarts filter

Grails config file returning empty object instead of string

I am trying to read a string in from an external config file, but am for some reason only getting an empty object. Here is the config file (DirectoryConfig.groovy)
directory {
logDirectory = "c:\\opt\\tomcat\\logs\\"
}
And the code that retrieves the directory (from a controller):
String dirName = grailsApplication.config.directory.logDirectory
File directory = new File(dirName)
For some reason, dirName always ends up being "{}", and as a result the file cannot be read. What am I doing wrong here?
Creating DirectoryConfig.groovy in your grails-app/conf/ directory will not work by convention.
You should consider implementing solution that is recommended for externalizing Grails configuration - delivering .groovy or .properties files from classpath or filesystem. Take a look at commented code in Config.groovy:
// grails.config.locations = [ "classpath:${appName}-config.properties",
// "classpath:${appName}-config.groovy",
// "file:${userHome}/.grails/${appName}-config.properties",
// "file:${userHome}/.grails/${appName}-config.groovy"]
It's very common way to provide configuration files that depend on runtime property:
// if (System.properties["${appName}.config.location"]) {
// grails.config.locations << "file:" + System.properties["${appName}.config.location"]
// }
I often use something like this (it's part of the Config.groovy file):
grails.config.locations = []
grails.project.config.type = "classpath"
grails.project.config.extension = "groovy"
environments {
development {
grails.project.config.file = "development-config.${grails.project.config.extension}"
}
test {
grails.project.config.file = "test-config.${grails.project.config.extension}"
}
}
if (System.properties["grails.config.type"]) {
grails.project.config.type = System.properties["grails.config.type"]
}
if (System.properties["grails.config.file"]) {
grails.project.config.file = System.properties["grails.config.file"]
}
grails.config.locations << "${grails.project.config.type}:${grails.project.config.file}"
By default it assumes that there is e.g. development-config.groovy file in the classpath, but I can simply change it by setting -Dgrails.config.file=/etc/development.properties -Dgrails.config.type=file in Java runtime so it uses /etc/development.properties file instead of the default one.
If you would like to run your example in the simplest way, you will have to do:
1) put your DirectoryConfig.groovy in the classpath source e.g. src/java (attention: it wont work if you put your file in src/groovy)
2) define in your Config.groovy:
grails.config.locations = [
"classpath:DirectoryConfig.groovy"
]
3) re-run your application. grailsApplication.config.directory.logDirectory should now return the value you expect.
For more information about externalizing configuration go to http://grails.org/doc/latest/guide/conf.html#configExternalized

Cannot create AntBuilder object in groovy gradle

When try to create AntBuidler object in groovy file I am getting below exception
java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)
at java.lang.Class.getDeclaredConstructors(Class.java:1901)
.....
at at features.step_definitions.RewardEventsGeneration.GetEventXML(RewardEventsGeneration.groovy:40)
at ✽.Then updateLoyaltyInfo event should be generated
I have added relevant jar to my lib folder and then placed below code under the build.gradle
repositories {
mavenCentral()
flatDir {
dirs 'lib'
}
}
My code as below
def GetEventXML (userId, eventTypeIn)
{
def Host = "10.77.69.14"
def UserName = "system"
def Password = "password"
def Path = "/temp"
def eventTypeToLookFor = "eventType=\"$eventTypeIn\""
def resultAsString = "" as String
def commandToRun = "grep -lH $userId $Path/*.xml | xargs grep -l '$eventTypeToLookFor' | cut -d: -f1"
def antEventCheck = new AntBuilder(); ********** Error line ******************
antEventCheck.sshexec( trust:'true',
host:Host,
username:UserName,
password:Password,
command:commandToRun,
verbose:'true',
timeout:'10000',
failonerror:'false',
outputproperty:'eventCheckResult');
resultAsString = antEventCheck.properties.eventCheckResult.toString()
return resultAsString
}
build.gradle
dependencies {
ext.groovyVersion = "2.0.4"
ext.cucumberJvmVersion = "1.1.5"
ext.httpclientVersion = "4.2.1"
cucumberRuntime files("${jar.archivePath}")
compile ('com.jcraft:jsch:0.1.49')
compile('com.github.groovy-wslite:groovy-wslite:0.8.0')
groovy("org.codehaus.groovy:groovy-all:${groovyVersion}")
compile("org.apache.httpcomponents:httpmime:4.1.2")
compile("org.codehaus.groovy.modules.http-builder:http-builder:0.5.2") {
exclude group: "org.codehaus.groovy", module: "groovy"
}
compile("net.sf.json-lib:json-lib:2.4:jdk15")
compile("javax.mail:mail:1.4.5")
compile("org.apache.httpcomponents:httpclient:${httpclientVersion}")
compile("org.codehaus.geb:geb-core:0.7.2") {
exclude group: "org.codehaus.geb", module: "geb-implicit-assertions"
}
drivers.each { driver ->
testCompile "org.seleniumhq.selenium:selenium-$driver-driver:$version.selenium"
}
compile("org.seleniumhq.selenium:selenium-support:2.25.0")
compile("log4j:log4j:1.2.17")
testCompile("junit:junit:4.10")
testCompile("info.cukes:cucumber-groovy:${cucumberJvmVersion}")
testCompile("info.cukes:cucumber-junit:${cucumberJvmVersion}")
}
Appreciate your comments
Following works perfectly
As specified by Peter's answer adding flatDir is not gonna be enough. Need to add same to the dependencies as well
repositories {
mavenCentral()
flatDir {
dirs 'lib'
}
}
dependencies {
compile("ant:ant:1.7.0")
}
Thanks Peter

How do I completely bootstrap a grails environment?

I have the included grails script that I found in some random place on the internet and it works pretty well for firing up scripts in a bootstrapped grails env. The only thing it doesn't seem to do is kick off my conf/*Bootstrap.groovy scripts like when I do run-app.
Is there another function like loadApp() and configureApp() that will do that for me?
import org.codehaus.groovy.grails.support.PersistenceContextInterceptor
Ant.property(environment: "env")
grailsHome = Ant.antProject.properties."env.GRAILS_HOME"
includeTargets << new File("${grailsHome}/scripts/Bootstrap.groovy")
target('default': "Runs scripts in the test/local directory") {
if (!args) { throw new RuntimeException("[fail] This script requires an argument - the script to run.") }
depends(configureProxy, packageApp, classpath)
classLoader = new URLClassLoader([classesDir.toURI().toURL()] as URL[], rootLoader)
Thread.currentThread().setContextClassLoader(classLoader)
loadApp()
configureApp()
def interceptor = null
def beanNames = appCtx.getBeanNamesForType(PersistenceContextInterceptor)
if (beanNames && beanNames.size() == 1) {
interceptor = appCtx.getBean(beanNames[0])
}
try {
interceptor?.init()
new GroovyScriptEngine(Ant.antProject.properties."base.dir", classLoader).run("scripts/${args}.groovy", new Binding(['appCtx':appCtx]))
interceptor?.flush()
} catch (Exception e) {
e.printStackTrace()
interceptor?.clear()
} finally {
interceptor?.destroy()
}
}
Yes, try
new BootStrap().init()

Resources