ANT Script Build Messages into a log4j configured log file - ant

I am developing a java project using Eclipse as IDE and ant as the build tool. For logging I am making use of log4j library. I am able to get the log messages in a log file for my whole application using log4j configuration.
But when I build project using ANT, the ANT build messages are still posted to console.I want to make sure that when I build the project, the build messages that ANT generates, like build failure/success, should also be posted to that sames logger file using log4j.
Please help me in this if anyone has got an idea. Thanks

To pass the logging log4j, you can use this when you run Ant:
$ ant -listener org.apache.tools.ant.listener.Log4jListener
The configuration of log4j is then up to you. See the information on Listeners in the Ant manual.

Related

How do I analyze Groovy code with Sonarlint for IntelliJ?

The Sonarlint plugin for IntelliJ does analysis on our Java code, but it won't analyze Groovy code in the same project.
We have a Grails project which works with sonar-runner on the command line. When I install the IntelliJ IDEA Sonarlint plugin, the plugin doesn't seem to pick up the settings from our command line config, and it doesn't show the warning highlights for issues like it does for the Java files in the editor.
Our project uses the "code-coverage" Grails plugin to generate an XML coverage report, then the sonar runner (command line tool) pulls in the metrics. In sonar-project.properties, we set:
# Project key within sonar
sonar.projectKey=com.mycompany:myapp
sonar.projectName=My Grails Project
sonar.projectVersion=1.0
# Source directories to analyze
sonar.sources=src/groovy, grails-app/domain, grails-app/services, grails-app/controllers, grails-app/utils, grails-app/taglib, grails-app/views
# Set language for the project to be Groovy
sonar.language=grvy
# Path to the Cobertura XML report
sonar.grvy.coveragePlugin=cobertura
sonar.groovy.cobertura.reportPath=target/test-reports/cobertura/coverage.xml
sonar.jdbc.username=...
sonar.jdbc.password=...
sonar.host.url=http://sonar.mycompany.com
sonar.jdbc.url=...
sonar.jdbc.driverClassName=...
The properties file has JDBC settings, the coverage report path, etc.
SonarLint is a different product than SonarQube (even if there are some links). For example SonarLint doesn't know what is sonar-project.properties. The purpose is to integrate with IntelliJ, not with some external configuration.
Regarding Groovy support, this is not planned since we don't have any Groovy analyzer (the SonarQube plugin for Groovy is simply reusing codenarc reports AFAIK). If you want to run Codenarc in IntelliJ, there is already a dedicated plugin for that.

xjc with annox running from command prompt

I have tried to run a example from the website http://confluence.highsource.org/display/J2B/Annotate+Plugin#AnnotatePlugin-Activation. The very first schema provided in the webpage and I saved it as schema.xsd under c:\jaxb folder. Then, I ran the command 'xjc -extension schema.xsd' from command prompt and I get the similar error. Apparently xjc doesn't seem to understand this url http://annox.dev.java.net. How do I solve this?
You have to add the annotate plugin with all the dependencies to the classpath. See this Ant build file for what dependencies are
You have to activate the plugin using -Xannotate switch
Here's a sample Ant project. I'll assemble a command-line example for the next version.

Worklight ant task using apache commons - where is this loaded from?

I'm trying to diagnose a failure in my ant file when it runs a Worklight task. I have a small ant file containing a simple reference to a Worklight task. This works correctly.
<target name="rawBuildApplication" >
<app-builder
applicationFolder="${applicationSource}"
environments="mobilewebapp"
nativeProjectPrefix="xxx"
outputFolder="${outputFolder}"/>
</target>
However when I invoke this ant file from a build control ant file (actually from the RTC build system) I get a failure (below), showing worklight failing to find an apache Java class. I assume there's some simple environmental difference, perhaps a classpath. It might help to figure it out if I knew where Worklight loaded the apache commons from. Right now I can't see anything in my environment in the case that works that points any apache Jar.
myAntFile.xml:146: java.lang.NoSuchMethodError: org.apache.commons.io.FileUtils.deleteQuietly(Ljava/io/File;)Z
at com.worklight.builder.util.BuilderUtils.<clinit>(BuilderUtils.java:672)
at com.worklight.builder.config.UserBuildConfiguration$Builder.<init>(UserBuildConfiguration.java:203)
at com.worklight.ant.builders.ApplicationBuilderTask.createBuildConfiguration(ApplicationBuilderTask.java:149)
at com.worklight.ant.builders.ApplicationBuilderTask.execute(ApplicationBuilderTask.java:80)
Edited: the cause is the use of -lib to add the RTC toolkit directory, exactly why this clashes and how to work around yet to be determined
Usually means you have version of the commons jar in your classpath, and its overriding the one packaged in the worklight-ant.jar. the apache commons files are inside the worklight-ant.jar file
Additional info from djna: I can confirm that when adding the Rational Team Concert (RTC) 3.0 toolkit to the ant classpath, either explicitly with -lib, or when selecting that option in the RTC Build definition some conflicting commons jars are added to the classpath. Worklight packages the classes it needs in its jar, but the -lib folder seems to take precedence.
My workaround is to replace the conflicting jars with later ones. I used these jars
commons-io-2.4.jar
commons-codec-1.8.jar
httpclient-4.2.5.jar
httpcore-4.2.4.jar
httpmime-4.2.5.jar
I guess the other alternative is to upgrade to a newer RTC, but in our environment that's not currently possible.

How to Open an Ant project (Nutch Source) at Intellij Idea?

I want to open Nutch 2.1 source file (http://www.eu.apache.org/dist/nutch/2.1/) at Intellij IDEA. Here is an explanation of how to open it at Eclipse: http://wiki.apache.org/nutch/RunNutchInEclipse
However I am not familiar with Ant (I use Maven) and when I open that source file many classes are not known by Intellij.
i.e.:
org.apache.hadoop.mapreduce.JobContext
org.apache.gora.mapreduce.GoraMapper
How can I add them to library or what should I do?
I finally figure out how to do it. Now our team can dev nutch in IntellIJ
The process we do
Get nutch source from apache.org
wget http://www.eu.apache.org/dist/nutch/2.3/apache-nutch-2.3-src.tar.gz
Import nutch source in intellij
Get Dependencies by Ant
Run ant runtime
Run ant test
Import dependencies into Intellij
File > Project Structures
Library > Ivy
Click to Plus button
Select all libraries in apache-nutch-2.3/build/lib
Now we have a project with nutch source and all dependencies
I think, you should use ant build for nutch project. Because, pom.xml is problematical for nutch. If you want to use it anyway maven, you check maven dependency in pom.xml .
I think, the problem can be solved with the following:
You create new project via idea and add nutch source. Idea is not
supported ivy ant project. You can install ivy plugin for idea, I
suppose, Idea12 does not support it.
or
You can create ant project for nutch via eclipse and then save
project. Then open the project on idea via eclipse classpath.
or
You can configure classpath. If you use ant build, you should add jars : File->ProjectStructure as follows:
Create a library
Attach Files
Then, if you use ant build, select jars from NUTCH_HOME/build/lib/* after build.
If you use maven build, select jars from ~/.m2/* (MAVEN_REPO)
Although Intellij supports running ant scripts directly through the IDE via the ant plugin, the Intellij editor will not figure out the classpath using your build.xml file by itself.This will result in the editor showing the code littered with errors.
Unfortunately the only solution I found to this is to add all the jars manually.You can get all the jars needed by building the ant project using the ant jar command.
So these are the steps you need to follow :->
1.Run ant jar command in the root of your program
2.Copy all the jars created inside the build folder(they will not be directly inside build folder.I had to go from build->ivy->lib->{project name})
3.Paste these jars to a new folder created somewhere outside the directory
4.Go to File->Project Structure->Libraries. Press the + button.
5.Select all the copied jars and press ok to any prompts which appear.
6.Press finish and wait for indexing to complete.Any dependency errors in the editor should resolve now.
Note: Since you are manually adding jars, you would need to keep them in sync if you change your build.xml file for any dependency change.
It seems that dependencies are managed using Ivy (see the ivy folder in the sources archives), so you could try to install the Ivy plugin, which would allow you to fix your classpath issues.

External Log files from Ant

I have configured Log4j in my project and that is invoked by an Ant task.
I want the Ant logs as well as project logs to be written to single file along with timestamps.
Could you let me know how to take care of this in Ant?
You can run Ant in such a way that it's logging is via Log4j, there's an example in the Ant Listeners & Loggers page:
ant -listener org.apache.tools.ant.listener.Log4jListener
but see the Ant documentation for proper details, how to ensure log4j.properties etc. are found.

Resources