java.lang.IllegalStateException: not started exception occurs at line <sonar:sonar/> - java

I am trying to configure sonar for my project. First I am trying in local environment. Below is my configuration
<project name="dev" default="war" xmlns:sonar="antlib:org.sonar.ant">
<!-- Define the SonarQube global properties (the most usual way is to pass these properties via the command line) -->
<property name="sonar.host.url" value="http://localhost:9000/sonar" />
<!-- Define the SonarQube project properties -->
<property name="sonar.projectKey" value="org.codehaus.sonar:sonarqube-scanner-ant" />
<property name="sonar.projectName" value="Example of SonarQube Scanner for Ant Usage" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.language" value="java" />
<property name="sonar.sources" value="src" />
<property name="sonar.java.binaries" value="build" />
<property name="sonar.java.libraries" value="lib/*.jar" />
<property name="sonar.sourceEncoding" value="UTF-8" />
<!-- Code for clean compile the java files code comes here -->
<!-- Define SonarQube Scanner for Ant Target -->
<target name="sonar">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<!-- Update the following line, or put the "sonarqube-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
<classpath path="C:/eclipse-oxygen2-wf/plugins/org.apache.ant_1.10.1.v20170504-0840/lib/sonarqube-ant-task-2.5.jar" />
</taskdef>
<sonar:sonar/>
</target>
</project>
I am using sonarqube7.2.1 ansonarqube-ant-task-2.5.jar. When I run the below command it gives me IllegalStateException
ant sonar
Is there something I am missing here?
Below is the console output
Buildfile: C:\workspace\project_sonar\build.xml
sonar:
[sonar:sonar] Apache Ant(TM) version 1.10.1 compiled on February 2 2017
[sonar:sonar] SonarQube Ant Task version: 2.5
[sonar:sonar] Loaded from: file:/C:/sonar/sonarqube-ant-task-2.5.jar
[sonar:sonar] User cache: C:\Users\Usha\.sonar\cache
BUILD FAILED
C:\workspace\project_sonar\build.xml:231: java.lang.IllegalStateException: not started

Related

Getting error [taskdef] Could not load definitions from resource org/apache/maven/resolver/ant/antlib.xml

I am getting [taskdef] Could not load definitions from resource org/apache/maven/resolver/ant/antlib.xml. It could not be found. error while using the following using maven 3.1.1 and ant 1.10
`
<property name="maven.ant.resolver.version" value="1.6.5"/>
<property name="maven.ant.resolver.jar.name"
value="ant-apache-resolver-1.6.5.jar"/>
<get
src="https://artifacthub-phx.oci.oraclecorp.com/rsys-libs/ant/ant-apache-resolver/${maven.ant.resolver.version}/${maven.ant.resolver.jar.name}"
dest="." usetimestamp="true"/>
<taskdef uri="antlib:org.apache.maven.resolver.ant"
resource="org/apache/maven/resolver/ant/antlib.xml"
classpath="./${maven.ant.resolver.jar.name}"/>
<resolve failOnMissingAttachments="true">
<dependencies>
<dependency coords="org.apache.maven:maven-profile:2.0.6" />
<exclusion artifactId="junit" />
<exclusion groupId="org.codehaus.plexus" />
</dependencies>
<path refid="war.lib.path" classpath="runtime" />
</resolve>
</target> `
Any Idea to resolve this?

AccessDeniedException when copying maven application to Raspberry Pi with ant

I'm trying to run my Maven program from my Windows PC on my Raspberry Pi through Ant in Eclipse. Full disclosure, i have basically no experience with Raspberry, Linux and Ant.
I was following this guide and the code is from there.
The code for the build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="Der_HFBot" default="remote-run" basedir="."
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<!-- Setup RASPBERRY PI properties -->
<property name="raspberrypi" value="cencored" />
<property name="raspberryfolder" value="~" />
<property name="username" value="cencored" />
<property name="password" value="cencored" />
<!-- <path id="maven-ant-tasks.classpath" path="${ant.libs.dir}/maven-ant-tasks-2.1.3.jar" /> -->
<path id="maven-ant-tasks.classpath" path="lib/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-tasks.classpath" />
<typedef
resource="org/apache/maven/artifact/ant/antlib.xml"
uri="antlib:org.apache.maven.artifact.ant"
classpathref="maven-ant-tasks.classpath" />
<!-- Add maven install target to be run before deploy -->
<target name="maven-install">
<artifact:mvn pom="pom.xml">
<arg value="install"/>
</artifact:mvn>
</target>
<!-- Locate the project jar and transfer via scp to RASPBERRY PI -->
<target name="transfer" depends="maven-install">
<first id="jars">
<fileset dir="target" includes="**/*-SNAPSHOT-jar-with-dependencies.jar" />
<!--<fileset dir="target" includes="**/*.jar" /> -->
</first>
<pathconvert pathsep="," property="jar.path" refid="jars" />
<basename file="${jar.path}" property="jar.filename" />
<echo>">>> Found application ${jar.path}"</echo>
<echo>">>> Copying application to ${raspberrypi}:${raspberryfolder}/${jar.filename}"</echo>
<scp
localfile="${jar.path}"
todir="${username}:${password}#${raspberrypi}:${raspberryfolder}"
trust="true" />
</target>
<!-- Run java -->
<target name="remote-run" depends="transfer">
<echo>">>> Starting ${raspberrypi}:${raspberryfolder}/${jar.filename}"</echo>
<sshexec
host="${raspberrypi}"
username="${username}"
password="${password}"
trust="true"
failonerror="true"
usepty="true"
command="java -jar ${jar.filename}" />
</target>
<!-- Run java in debug mode and keep waiting for execution -->
<target name="remote-debug" depends="transfer">
<echo>">>> Starting ${raspberrypi}:${raspberryfolder}/${jar.filename} in debug mode"</echo>
<sshexec
host="${raspberrypi}"
username="${username}"
password="${password}"
trust="true"
failonerror="true"
usepty="true"
command="java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=y -jar ${jar.filename}" />
</target>
</project>
The project builds succesfully, but fails at the transfer with the following message:
transfer:
[echo] ">>> Found application "
[echo] ">>> Copying application to censored_IP:~/Der_HFBot"
[scp] Connecting to censored_IP:22
BUILD FAILED
C:\Users\Paddy\Desktop\Google Drive\Telegram Bots\Der_HFBot\build.xml:47: java.nio.file.AccessDeniedException: C:\Users\Paddy\Desktop\Google Drive\Telegram Bots\Der_HFBot
Total time: 3 seconds
I've tried running Eclipse as admin and moving the project to a folder outside of Drive.
edit: It seems like ${jar.path} doesn't return a path? It's supposed to echo "Found application ${jar.path}" but in the console it returns "Found application ".
edit2: When i enter the path manually the transfer works, so the problem is in the code that finds the jar path. Since this is a personal project i have no problem enterin the path manually, if your fingers are itching to fix the code feel free though.
AccessDeniedExceptions usually come from a lack of file permission. Use chmod 777 filename on both the program itself and all other applicable files, this will allow everything to read/write/execute on these files, so make sure you have a safe development environment.

Nutch - Could not load definitions from resource org/sonar/ant/antlib.xml

I'm learning Nutch through the official guide. So when I run Ant at bin directory, it says:
"Could not load definitions from resource org/sonar/ant/antlib.xml. It
could not be found."
I've spent a lot of time in google to solve it, but I failed. My OS is Ubuntu16.04.
Try to comment all this part in build.xml:
<!-- ================================================================== -->
<!-- SONAR targets -->
<!-- ================================================================== -->
<!-- Define the Sonar task if this hasn't been done in a common script -->
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="${ant.library.dir}"/>
<classpath path="${mysql.library.dir}"/>
</taskdef>
<!-- Add the target -->
<target name="sonar" description="--> run SONAR analysis">
<!-- list of mandatory source directories (required) -->
<property name="sonar.sources" value="${src.dir}"/>
<!-- list of properties (optional) -->
<property name="sonar.projectName" value="Nutch Trunk 1.4 Sonar Analysis" />
<property name="sonar.binaries" value="${build.dir}/classes" />
<property name="sonar.binaries" value="${build.dir}/plugins" />
<property name="sonar.tests" value="${test.src.dir}" />
<sonar:sonar workDir="${base.dir}" key="org.apache.nutch:trunk"
version="1.4-SNAPSHOT" xmlns:sonar="antlib:org.sonar.ant"/>
</target>
in this way, it should work.

How to add log4j.xml path in Ant build.xml

I have a log4j2.xml file which is not being picked by Ant's build.xml. So, I keep getting the following error message in Eclipse console -
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
My build.xml file is very simple. (pasted below) I copied it from one of the examples online.
I have gone through ant documentation and am aware of the and I have used these to set the log4j2.xml in classpath and have failed.
<project name="Learning" default="hello" basedir=".">
<property name="src.dir" value="src"/>
<property name="lib.dir" value="${src.dir}/lib"/>
<property name="build.dir" value="build"/>
<target name="hello">
<!-- compile just the basic hello files -->
<echo> This will have all the basic builds </echo>
<javac srcdir="{src.dir}" destdir="{build.dir}"
includeantruntime="false"/>
</target>
Can you please give me a code snippet to add my Log4j2.xml file sitting in the basedir or the project to the classpath?
Unfortunately, javac does not copy the resources (the directory contains only the compiled classes). However, you can copy them. e.g.:
<project name="Learning" default="hello" basedir=".">
<property name="src.dir" value="src"/>
<property name="lib.dir" value="${src.dir}/lib"/>
<property name="build.dir" value="build"/>
<target name="hello">
<echo>Copy non-java resources</echo>
<copy todir="{build.dir}" overwrite="true">
<fileset dir="{src.dir}" excludes="**/*.java"/>
</copy>
<!-- compile just the basic hello files -->
<echo> This will have all the basic builds </echo>
<javac srcdir="{src.dir}" destdir="{build.dir}"
includeantruntime="false"/>
</target>
See more in Copy Task.

Android Ant Build

I would like to build two versions of my Androidapplication using an Apache ant file. The problem is, that both versions are identical except the advertisement in the lite version. I read about using Configurations with ant to build debug versions.
The following class defines some constants that can be referenced within the application.
public class Config {
// Whether or not to include logging in the app.
public final static boolean LOGGING = true;
}
And here is an example on how to use this constants to determine if logging is enabled or not.
if (Config.LOGGING) {
Log.d(TAG, "[onCreate] Success");
}
Now i can enable and disable logging in my properties file.
# Turn on or off logging.
config.logging=true
That does not work, because before using this config I have to create a second config file and use filterset and copy.
public class Config {
// Whether or not to include logging in the app.
public final static boolean LOGGING = #CONFIG.LOGGING#;
}
That's pretty easy, but how I could use this to build two versions of my application with and without advertisement. And how could I change the package names using ant, so the android market would accept both packages (Full and Lite).
Thank you, for your suggestions, but I still have some problems.
I managed to write some basic targets that cleanup my builds and copy all files needed to build the application in two folders /full and /lite. So I have two directories with the same content. Now I rename all matches of the applications package name in all *.java files and the AndroidManifest file (target prepare).
To really build two different version I would now have to include the code from my first post. But how do I have to do this and how can I build both versions in the release target and write the resulting *.apk files into the build directoy?
Finally ... Would that be all I have to do to build running *.apks that would be accepted by the android market?
<?xml version="1.0" encoding="UTF-8"?>
<project name="my.application" default="help" basedir=".">
<!-- Load the custom property files -->
<property file="build.properties" />
<property file="passwords.properties" />
<!-- Set global properties for this build -->
<property name="my.application.pkg" value="my.application"/>
<property name="my.application.pkg.full" value="my.application.full"/>
<property name="my.application.pkg.lite" value="my.application.lite"/>
<property name="my.application" location="."/>
<property name="my.application.build" location="build"/>
<property name="my.application.src" location="src"/>
<property name="my.application.res" location="res"/>
<property name="my.application.gen" location="gen"/>
<property name="my.application.full" location="full"/>
<property name="my.application.full.src" location="full/src"/>
<property name="my.application.full.res" location="full/res"/>
<property name="my.application.full.gen" location="full/gen"/>
<property name="my.application.full.build" location="full/build"/>
<property name="my.application.lite" location="lite"/>
<property name="my.application.lite.build" location="lite/build"/>
<property name="my.application.lite.src" location="lite/src"/>
<property name="my.application.lite.res" location="lite/res"/>
<property name="my.application.lite.gen" location="lite/gen"/>
<!-- Create and update the local.properties file -->
<loadproperties srcFile="local.properties" />
<!-- Load the ant.properties file -->
<property file="ant.properties" />
<!-- Load the project.properties file -->
<loadproperties srcFile="project.properties" />
<!-- Quick check on sdk.dir. -->
<fail
message="sdk.dir is missing."
unless="sdk.dir" />
<!-- Version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
<target name="release" depends="report, prepare">
<echo>Building the target!</echo>
</target>
<target name="prepare" depends="cleanup" >
<!-- Copy the Manifest.xml to the full copy -->
<copyfile src="${my.application}/AndroidManifest.xml"
dest="${my.application.full}/AndroidManifest.xml" />
<!-- Copy the source files to the full copy -->
<copy todir="${my.application.full.src}" overwrite="true">
<fileset dir="${my.application.src}" />
</copy>
<!-- Copy the resources to the full copy -->
<copy todir="${my.application.full.res}" overwrite="true">
<fileset dir="${my.application.res}" />
</copy>
<!-- Copy the generated to the full copy -->
<copy todir="${my.application.full.gen}" overwrite="true">
<fileset dir="${my.application.gen}" />
</copy>
<!-- Replace the package name in the full manifest file -->
<replaceregexp file="${my.application.full}/AndroidManifest.xml"
match='package="(.*)"'
replace='package="${my.application.pkg.full}"'
byline="false" />
<!-- Change the package name in all Java files -->
<replaceregexp flags="g" byline="false">
<regexp pattern="${my.application.pkg}" />
<substitution expression="${my.application.pkg.full}" />
<fileset dir="${my.application.full.src}" includes="**/*.java" />
</replaceregexp>
<!-- Copy the Manifest.xml to the lite copy -->
<copyfile src="${my.application}/AndroidManifest.xml"
dest="${my.application.lite}/AndroidManifest.xml" />
<!-- Copy the source files to the lite copy -->
<copy todir="${my.application.lite.src}" overwrite="true">
<fileset dir="${my.application.src}" />
</copy>
<!-- Copy the resources to the lite copy -->
<copy todir="${my.application.lite.res}" overwrite="true">
<fileset dir="${my.application.res}" />
</copy>
<!-- Copy the generated to the lite copy -->
<copy todir="${my.application.lite.gen}" overwrite="true">
<fileset dir="${my.application.gen}" />
</copy>
<!-- Replace the package name in the lite manifest file -->
<replaceregexp file="${my.application.lite}/AndroidManifest.xml"
match='package="(.*)"'
replace='package="${my.application.pkg.lite}"'
byline="false" />
<!-- Change the package name in all Java files -->
<replaceregexp flags="g" byline="false">
<regexp pattern="${my.application.pkg}" />
<substitution expression="${my.application.pkg.lite}" />
<fileset dir="${my.application.lite.src}" includes="**/*.java" />
</replaceregexp>
</target>
<!-- Deletes all directories, not needed anymore after compiling the source files -->
<target name="cleanup">
<!-- Delete the full version build dir -->
<delete dir="${my.application.full}"/>
<!-- Delete the lite version build dir -->
<delete dir="${my.application.lite}"/>
<!-- Delete the *.apk file -->
<delete file="my.application.full.apk"/>
<!-- Delete the *.apk file -->
<delete file="my.application.lite.apk"/>
</target>
</project>
There are a number of ways in which you could achieve what you require.
Here are a couple of ideas that I have used in the past,
1) Have two application 'heads' that pull in a common Android library.
Each head initializes static data that sets up the library to behave as either the lite or the full version of your application.
This has the advantage that you can perform the build from Eclipse projects as well as with Ant.
2) Have two seperate build targets that share common build targets to create two seperate apk files.
In the Ant build script have it build two versions of the APK.
One that is the full version and then the other which builds the lite version.
The difference between the two targets are that they build using slightly different files (either by copying, directing to diferent directories or modifying with scripts).
This can all be done in Ant using targets and properties.
If at the top level of your build you have a release target depending on two other targets.
e.g.
<target name="release"
depends="release-Full, release-Lite">
</target>
<target name="release-Full">
<ant antfile="thisbuild.xml" inheritAll="true" target="full">
<property name="MyCustomProperty" value="Full" />
</ant>
</target>
<target name="release-Lite">
<ant antfile="thisbuild.xml" inheritAll="true" target="lite">
<property name="MyCustomProperty" value="Lite" />
</ant>
</target>
You can then use these targets and properties to modify your build to do whatever you require to build each of the APK files.

Categories