Ant - 1.8.3 and Junit #Ignore - ant

Ant 1.8.3 is not ignoring the junit test class with #Ignore annotation. Where as Ant 1.8.1 ignores the test class perfectly.
This is how my test class looks like:
....
import org.junit.Ignore
import org.junit.Test
....
#Ignore("Want to ignore this class tests")
public class TestClass extends ABCDTestCase {
#Test
public void testAbcd(){
....
}
}
After struggling for a day, found that ant-junit.jar in ant-1.8.3 is the culprit. When this ant-junit.jar of ant-1.8.3 is replaced with ant-junit.jar of 1.8.1 it works perfectly well.
Am i missing something here ? or is the only tweak which solves this problem ?

Related

Expression codec (grails.views.gsp.codecs.expression) seems to be ignored in deployed war file

In a fresh grails 4.0.4 application the settings of
grails:
views:
gsp:
codecs:
expression: none
seem to be ignored when deployed as a war file in a Tomcat 8.5.39. (JVM 11.0.7+10-post-Ubuntu-2ubuntu218.04)
Adding this
<head>
...
<script>
var foo = ${[a:23, b:42, c:666] as grails.converters.JSON};
</script>
</head>
to the generated grails-app/views/index.gsp shows up as
var foo = {"a":23,"b":42,"c":666};
when running grails run-app or even grails prod run-app(!), but is encoded as
var foo = {"a":23,"b":42,"c":666};
in the packaged (grails prod war) deployed war file.
The build.gradle was unmodified, except for changing
compile "org.grails.plugins:cache"
to this
compile("org.grails.plugins:cache") {
exclude module:'groovy-all'
}
Is this a bug or am I using the codecs settings wrong? Maybe there is a plugin overwriting this settings (like here https://github.com/grails/grails-core/issues/10722) but i cannot find any other yml files. Any help is appreciated!
It works like a charm in Grails 4.0.3. Seems it is broken in Grails 4.0.4 ...
Maybe the problem came with the new Groovy Page Compiler Task. The config file (aka application.yml) variable here is never used. But that's only an assumption after quick investigation with too little coffee ;-)
Workaround or my preferred way (still working in Grails 4.0.4)
Some helper TagLib like this:
import grails.converters.JSON
class FooTagLib {
static defaultEncodeAs = [taglib:'none']
static namespace = "foo"
def json = { attrs, body ->
out << raw(attrs.data as JSON)
}
}
Usage:
var foo = <foo:json data="[a:23, b:42, c:666]"/>

what's the different between full path and relative path in dart

I develop a flutter app, define serveral models in 'model' package.
Then I declare a class Example in 'model' for example.
model/example.dart
class Example {
#override
String toString() {
return 'class example';
}
}
test_a.dart
import 'package:example/model/example.dart'
Example testA() {
return Example()
}
test.dart
import 'model/example.dart'
import 'test_a.dart'
test() {
Example example = testA();
if (example is Example) {
print('this class is Example');
} else {
print('$example');
}
}
I will get output class example🌚
If I change from import 'model/example.dart' to import 'package:example/model/example.dart' in test.dart, then I will get the output this class is Example.
So I'm confused what is different between the full path and relative path in dart.
package imports
'package:... imports work from everywhere to import files from lib/*.
relative imports
Relative imports are always relative to the importing file.
If lib/model/test.dart imports 'example.dart', it imports lib/model/example.dart.
If you want to import test/model_tests/fixture.dart from any file within test/*, you can only use relative imports because package imports always assume lib/.
This also applies for all other non-lib/ top-level directories like drive_test/, example/, tool/, ...
lib/main.dart
There is currently a known issue with entry-point files in lib/* like lib/main.dart in Flutter. https://github.com/dart-lang/sdk/issues/33076
Dart always assumed entry-point files to be in other top-level directories then lib/ (like bin/, web/, tool/, example/, ...).
Flutter broke this assumption.
Therefore you currently must not use relative imports in entry-point files inside lib/
See also
How to reference another file in Dart?

Grails import class from java or groovy folder

I put several .groovy scripts in the src/groovy/search/ folder and got astrayed on how to use them in my controller.
My controller is grails-app/controller/EnvironmentController.groovy and I want to know how to import the classes like
import src.groovy.search.*
Also it's appreciated if anybody could point me to a complete explanation how the import works in Grails (namely how the groovy and java folders are included in the project and how to import them, including importing the java folder inside the groovy one).
Thanks!
Edit: My grails is on 2.4.4
Imports in Grails works in same fashion as in Java. You put your groovy files under src/groovy and java files under src/java. While importing simply import with the package name and no need to include src or groovy in import.
For how to execute groovy scripts in controller or anywhere, you can't just import them. I am assuming you are talking about groovy script and not groovy class. To execute a groovy script, you have two choices.
Suppose you Sample.groovy script file contains below code
public void sayHello(String name) {
println "Say Hello to $name..."
}
public static void sayStaticHello(String name) {
println "Say Static Hello to $name..."
}
So in order to execute it in your controller you can do either:
def script = new GroovyShell().parse(new File('<Path to SampleScript.groovy>'))
script.sayHello("Sandeep Poonia")
script.sayStaticHello("Sandeep Poonia")
or
//for non-static methods
this.class.classLoader.loadClass("SampleScript").newInstance().invokeMethod("sayHello", "Sandeep Poonia")
//for static method
this.class.classLoader.loadClass("SampleScript").invokeMethod("sayStaticHello", "Sandeep Poonia")
Use and IDE: (Grails 2 or less GGTS/STS) (Grails 3 Intelij community edition)
Organise import feature short cuts:
on GGTS/STS(Eclipse)
Ctrl + shift + o all together
on Intelij
Ctrl + Alt + o all together
In your case, if you are using vi or some text editor then all you need is :
import search.*
i.e. remove src.groovy.

Importing external domain classes into Grails

I'm trying to create a sample project where domain classes are in an external normal groovy project and then used in a grails app (see https://github.com/ivanarrizabalaga/grails-domain-griffon):
book-svr
book-common
I'm also following the grails guide in order to get this (see http://grails.org/doc/latest/guide/hibernate.html) but the imported classes are not being recognized as domain classes.
The relevant parts:
External domain class:
package com.nortia.book
import grails.persistence.Entity
#Entity
class Book implements Serializable{
private static final long serialVersionUID = 1L;
String title
String author
static constraints = {
title blank:false
author blank:false
}
}
build.gradle:
....
dependencies {
// We use the latest groovy 2.x version for building this library
compile 'org.codehaus.groovy:groovy:2.1.7'
compile "org.grails:grails-datastore-gorm-hibernate4:3.0.0.RELEASE"
compile "org.grails:grails-spring:2.3.7"
....
In the grails app,
hibernate.cfg.xml:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
'-//Hibernate/Hibernate Configuration DTD 3.0//EN'
'http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd'>
<hibernate-configuration>
<session-factory>
<mapping package='com.nortia.book' />
<mapping class='com.nortia.book.Book' />
</session-factory>
</hibernate-configuration>
BookController.groovy (I've tried an scaffolded and coded controller, and both failed):
...
class BookController{
static scaffold=Book
}
...
console.log (error):
ERROR ScaffoldingGrailsPlugin - Cannot generate controller logic for scaffolded class class com.nortia.book.Book. It is not a domain class!
Finally, suspicious log messages while initializing:
DEBUG cfg.Configuration - session-factory config [null] named package [com.nortia.book] for mapping
INFO cfg.Configuration - Mapping package com.nortia.book
WARN cfg.AnnotationBinder - Package not found or wo package-info.java: com.nortia.book
DEBUG cfg.Configuration - session-factory config [null] named class [com.nortia.book.Book] for mapping
INFO cfg.Configuration - Configured SessionFactory: null
So I'm wondering:
What's the missing piece?
According to the docs, looks like external 'domains' must be java classes but that's not a good option for my purpose.
I haven't try yet with a grails binary plugin instead of a groovy project, is it the way to go? (I need to use the domains in a griffon project that is why I opted this way first).
Finally solve it creating a 'sort of' a binary plugin manually.
Let's take a look step by step:
book-domain
Tree structure
src
main
groovy
demo
Book.groovy
resources
META-INF
grails-plugin.xml
build.gradle
Book.groovy
package demo
import grails.persistence.Entity
#Entity
class Book{
String title
static constraints = {
title blank: false
}
}
grails-plugin.xml
<plugin name='book-domain' version='1.0' grailsVersion='2.3 > *'>
<author>Ivan Arrizabalaga</author>
<title>External domains</title>
<description>An external domain plugin</description>
<documentation>http://grails.org/plugin/book-domain</documentation>
<type>demo.BookDomainGrailsPlugin</type>
<packaging>binary</packaging>
<resources>
<resource>demo.Book</resource>
</resources>
</plugin>
build.gradle
/*
* This build file was auto generated by running the Gradle 'init' task
* by 'arrizabalaga' at '5/26/14 12:34 PM' with Gradle 1.11
*
* This generated file contains a sample Groovy project to get you started.
* For more details take a look at the Groovy Quickstart chapter in the Gradle
* user guide available at http://gradle.org/docs/1.11/userguide/tutorial_groovy_projects.html
*/
// Apply the groovy plugin to add support for Groovy
apply plugin: 'groovy'
apply plugin: 'maven'
group = 'demo'
version = '1.0'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'maven central' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
mavenLocal()
}
// In this section you declare the dependencies for your production and test code
dependencies {
// We use the latest groovy 2.x version for building this library
compile 'org.codehaus.groovy:groovy-all:2.1.9'
//compile "org.grails:grails-datastore-gorm-hibernate4:3.1.0.RELEASE"
compile "org.grails:grails-datastore-gorm-hibernate:3.1.0.RELEASE"
compile "commons-lang:commons-lang:2.6"
// We use the awesome Spock testing and specification framework
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
testCompile 'junit:junit:4.11'
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
using it
Now the project can be built (gradle install to publish it into your local maven repo) and used (declaring the proper dependency) in any given project.
If the project that uses the jar is a Grails app it turns automatically the #Entity classes into real Domains.
Hope it helps.

#Resource Injection in jar in 'lib' of an ear; why doesn't that work?

I have simple ear (GF 4.0, JDK 7; sticking with EE6 for now)
The ear contains:
EJBJar
WAR
lib/Shared.jar
Shared has an #Qualifier (#UserDS) in it (it also has META-INF/beans.xml).
I have an #Producer like this:
package fhw.producers;
import fhw.qaulifiers.ListingDS;
import fhw.qaulifiers.UserDS;
import javax.annotation.Resource;
import javax.sql.DataSource;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.Produces;
#Default
public class DataSourceProducer
{
#Resource(lookup = "Member")
private DataSource userDS;
public DataSourceProducer()
{
System.err.println("DataSourceProducer.DataSourceProducer -- CONSTRUCTION");
}
#Produces
#UserDS
public DataSource getUserDataSource()
{
System.err.println("******DataSourceProducer.getUserDataSource; am I null? " + (null == userDS) ) ;
return userDS;
}
}
I have a simple EJB (it has a beans.xml) that uses it via:
#Inject
#UserDS
private DataSource userDS;
QUESTION: When I put DataSourceProducer in the EJBJAR and deploy; my print statements come out and my #Resource resolves and everything is fine. When I put DataSourceProducer in the Shared.jar; the print statements still come out but the #Resource didn't work and the EJB NPE's on the null DS returned by producer method etc. In both tests the qualifier stayed in the Shared.jar. I have no DDs anyway where (well a web.xml for the war -- all else is implicit)
Part of me thinks this makes a bit of sense; #Resource is sort of EE oriented (or no?); and should mostly make sense within a EE deployable.
OTOH, why can't have I have hand-full of qualifiers and some producers in a Shared JAR in lib dir of an EAR that all EJBJars and WARs (in the EAR) can use?
Is there a way to make this work?
If you really want -- you can see an entire example here: https://github.com/fwelland/ResJect
I got the same issue on GF3, but the solution seems the same.
Remove the dependency from the lib directory and add it to the root of the ear.
Then add the following to the application.xml
<module><ejb>Shared.jar</ejb></module>
Tip: using maven-ear-plugin you can automatically add dependencies as modules to your ear
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<displayName>...</displayName>
<application-name>...</application-name>
<defaultJavaBundleDir>lib</defaultJavaBundleDir>
<!-- not generate application.xml! we include it ourselves -->
<generateApplicationXml>false</generateApplicationXml>
<modules>
<ejbModule>
<groupId>...</groupId>
<artifactId>Shared</artifactId>
<bundleFileName>Shared.jar</bundleFileName>
</ejbModule>
</modules>
</configuration>
</plugin>
Note that if you're using GlassFish 4, you're using Java EE 7, not Java EE 6. In order for your situation to work, you need to register your shared jar as a module in the application.xml, so that it knows to scan it.

Resources