I use the groovy AntBuilder in a custom written installer, eg. to unpack the installation package.
One thing I cannot figure out, is how to detect, whether the unzip task failed, eg.
I have the following code:
...
AntBuilder antBuilder = new AntBuilder()
antBuilder.mkdir(dir:installationPath)
antBuilder.unzip(src:zipFileName, dest:installationPath,overwrite:"yes")
...
If the destination path ("installationPath") is write protected, the unzip reports errors ("unable to expand..."), but the task itself does not fail. There is also no "failOnError" attribute for unzip.
Is there a way to force a unzip task to fail, if the target is writeprotected (or the drive is full, etc.)?
It seems there is no way to catch the exception.
According to the source code from ant
protected void extractFile(FileUtils fileUtils, File srcF, File dir,
InputStream compressedInputStream,
String entryName, Date entryDate,
boolean isDirectory, FileNameMapper mapper)
throws IOException {
...........................
...........................
...........................
} catch (FileNotFoundException ex) {
log("Unable to expand to file " + f.getPath(),
ex,
Project.MSG_WARN);
}
}
It silently catches the exception without re-throwing it further.
Related
I recently added database-migration-plugin to my grails 3.0.11 app. The problem is when I try to run-app I get a following error:
ERROR grails.boot.GrailsApp - Application startup failed
Exception in thread "main" org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'springLiquibase_dataSource':
Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException:
java.lang.IllegalArgumentException: Script text to compile cannot be null!
Looks like it can't find changelog.xml in my grails-app/migrations folder. My build.gradle file contains:
buildscript {
dependencies {
classpath "org.grails.plugins:database-migration:2.0.0.RC1"
}
}
and
sourceSets {
main {
resources {
srcDir 'grails-app/migrations'
}
}
}
I also added the following lines in my application.groovy file:
grails.plugin.databasemigration.updateOnStart = true
grails.plugin.databasemigration.updateOnStartFileNames = ['changelog.xml']
I would by very gratefull for any advice how to make database-migration-plugin work properly.
Edit:
I created changelog.xml file using $grails dbm-create-changelog command
I also added to build.gradle (as suggested by $grails plugin-info database-migration command):
dependencies {
compile "org.grails.plugins:database-migration:2.0.0.RC1"
}
then I changed it to (following official documentation):
dependencies {
runtime "org.grails.plugins:database-migration:2.0.0.RC1"
}
and then (as suggested by manual for startup error) I forced liquibase:
dependencies {
compile 'org.liquibase:liquibase-core:3.3.2'
runtime 'org.grails.plugins:database-migration:2.0.0.RC1'
}
and
dependencies {
compile 'org.liquibase:liquibase-core:3.3.2'
compile 'org.grails.plugins:database-migration:2.0.0.RC1'
}
The problem still remains: java.lang.IllegalArgumentException: Script text to compile cannot be null!
We ran into the same problem when upgrading to Grails 3.
A look into the code of the grails-database-migration plugin made clear that the configuration parameter is changed from a list updateOnStartFileNames to a single value updateOnStartFileName.
So when you change your config from
grails.plugin.databasemigration.updateOnStartFileNames = ['changelog.xml']
to
grails.plugin.databasemigration.updateOnStartFileName = 'changelog.xml'
it should work again.
I ran into a similar error. In my case we had some lookup tables where we were populating using a hand crafted script which was included into the main changelog.groovy like:
include file: 'data/001-tablex-data.groovy'
except the file name was incorrect - it should have been 002-... instead. The error is basically the same, but there is no reporting to indicate which included file is not being found/parsed, which is a pain. So if you have manually included files, then look for incorrectly named ones in addition to checking the top-level changelog.groovy or changelog.xml
Ok, I finally found a solution. Maybe it will help someone someday. So what I did was simply delete changelog.groovy (i switched from XML to Groovy) file. Then I generated a new one with $grails dbm-create-changelog changelog.groovycommand. As a final step I run $grails dbm-changelog-sync and everything started to work just fine.
I was facing this issue too and in my case, the problem was the order of that block in build.gradoe
sourceSets {
main {
resources {
srcDir 'grails-app/migrations'
}
}
}
It MUST be before the bootRun, like the below code.
sourceSets {
main {
resources {
srcDir 'grails-app/migrations'
}
}
}
bootRun {
jvmArgs(
'-Dspring.output.ansi.enabled=always',
'-noverify',
'-XX:TieredStopAtLevel=1',
'-Xmx1024m')
sourceResources sourceSets.main
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}
If you put sourceSets after bootRun your application will not find the migrations file.
Make sure:
You have set up the changelog, i.e., the file grails-app/migrations/changelog.xml exists and is valid.
How you do this depends on your situation. The plugin's documentation has a section for how to create the file initially.
Your datasource is set up to use the database that changelog.xml applies to.
Another potential cause for this problem that we had run into was incorrect capitalization. If changelog.groovy references path/someFile.groovy but the actual name is path/somefile.groovy then you will get this error. Make sure the path name capitalization matches.
I'd like to run the JUnit tests in our project from the command line using an Ant target. Up until now we ran the tests manually from Eclipse without any issues using the embedded JUnit in Eclipse.
After finally having figured out how the set the classpath I now get failed Tests for all classes that use the Parameterized Runner from JUnit 4.11.
While running the test target (ant test) the only output is "FAILED" after the name of the Testclass, even with option -v.
Generating testreports shows the following Exception:
java.lang.IllegalArgumentException: wrong number of arguments
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
What does this mean?
The version are:
- JDK 1.6
- ant 1.9.3
- JUnit 4.11
My build.xml is over 400 lines long so I'm not sure if it makes sense to post it here. Let me know if you need parts of the build.xml.
Update 13.05.2015: Here's a sample section from on of our JUnit Test classes that fail. The #Parameters section contains only one entry which is pretty useless in this case but this class still fails when run from ant.
#Parameters
public static Iterable<String[]> testData() {
return Arrays
.asList(new String[][] { { "a-rules-filename" } });
}
#Parameter
public String RULES_FILE_NAME;
Our Test class is annotated like this:
#FixMethodOrder(MethodSorters.NAME_ASCENDING)
#RunWith(Parameterized.class)
public class OurRulesTest {
The Exception is thrown due to a missing constructor in the test class.
It seems that when using the Parameterized Runner you need to specify a constructor with as many arguments as you have parameters.
For some reason this works in Eclipse without specifying a constructor.
I have an application that was working fine until I added code to run a JasperReport. The error is the well known
Target Unreachable, identifier 'studentBean' resolved to null
After adding the code needed to run a JasperReport, the particular page that uses that bean (StudenBean) started to show such an exception before it even shows. After a process of commenting/uncommenting lines of code, I could isolate de precise line that brings the problem. It's shown below:
private void gerarRelatorioPDF(List<Student> students, InputStream report, OutputStream pdf) {
JRDataSource jrds = new JRBeanCollectionDataSource(students);
try {
JasperRunManager.runReportToPdfStream(report, pdf, null, jrds); // <<-- Here!!!
} catch (Exception e) {
e.printStackTrace();
}
}
It's the line that generates a PDF stream from a JasperReport definition. This method is private because it's called by another public method. The public method is the action of a <p:commandButton/> in the page, so this button is not even being clicked, because the exception prevents the page to render.
If I comment that line of code, the page renders ok and I can click the button, but obviously no report will be generated.
Any ideas how to fix it?
After some study, I decided to modify my POM.xml (Maven script) to include JasperReports 6.0.0. Previously I had only installed JasperReports 6.0.1 plugin in Eclipse, created and configured the report.
When we add a new report to a project, Eclipse automatically adds the path to JasperReports libraries to the class path, so the project compiles fine, but it seems that some other dependencies are not added and, specially, not deployed to the application server (in my case JBoss AS 7.1).
After updating the POM.xml to include JasperReports, everything started to work as desired.
I launch my Grails 2.1.5 app from an IDE with an exception breakpoint set for NumberFormatException (meaning that the application will break whenever this exception is thrown).
If I then execute the following code from the Grails console:
import groovy.util.*
import groovyx.net.http.*
def uri = 'http://ws.audioscrobbler.com/2.0/?artist=Yelle&mbid=f43d43c8-eedf-4628-99b0-04120e7124c8&method=artist.gettopalbums&api_key=6e331f856413a5e3dfc91ec41cea5415&limit=6'
XmlSlurper().parse(uri)
The exception breakpoint is triggered because of the following code in Long.parseLong
public static long parseLong(String s, int radix)
throws NumberFormatException
{
if (s == null) {
throw new NumberFormatException("null");
}
// rest of method omitted
}
However it seems that XmlSlurper().parse(uri) returns the expected value, so I guess this exception is handled somewhere, but I can't figure out where. I'm puzzled about why Long.parseLong is called with a null value for the first param. Is this a bug in XmlSlurper or just some strange implementation detail?
Update
As requested, here's the call stack. I'm using JDK 7 and Groovy 1.8.8. I tried debugging it myself, but as you can see, I'm missing a lot of the relevant source files.
at java.lang.Long.parseLong(Long.java:404)
at java.lang.Long.parseLong(Long.java:483)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1571)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source:-1)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source:-1)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source:-1)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source:-1)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source:-1)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source:-1)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source:-1)
at groovy.util.XmlSlurper.parse(XmlSlurper.java:146)
at groovy.util.XmlSlurper.parse(XmlSlurper.java:212)
As far as I can tell, this file from the OpenJDK mercurial repository is the version of sun.net.www.protocol.http.HttpURLConnection that is in Java 7 update 25, and the relevant extract is
1570 try {
1571 cl = Long.parseLong(responses.findValue("content-length"));
1572 } catch (Exception exc) { };
so the NumberFormatException will be thrown (and immediately ignored) whenever an HTTP response doesn't have a Content-Length header.
I have a custom build activity, but it's not executing. I've put it in try-catch block which catches Sysytem.Exception in my build template, and first line of overriden execute method is throwing Sysytem.Exception. On the log I see only line with the name of my custom activity! Any guesses?
protected override void Execute(CodeActivityContext context)
{
throw new System.Exception("This is hello messasge");
...
}
I found out! I have specified path to assembly with my custom activities in the properties of build controller, but a had assembly with the same name in GAC. So, I suppose, TFS was using not my assemly, but assembly from GAC.