SaxonParserTest missing SaxonXQDataSource? - java

Looking to run the simplest possible example using saxon, and, specifically, Saxon-HE:
thufir#dur:~/NetBeansProjects/helloWorldSaxon$
thufir#dur:~/NetBeansProjects/helloWorldSaxon$ gradle clean run
> Task :compileJava FAILED
/home/thufir/NetBeansProjects/helloWorldSaxon/src/main/java/helloWorldSaxon/App.java:6: error: package com.saxonica.xqj does not exist
import com.saxonica.xqj.SaxonXQDataSource;
^
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
2 actionable tasks: 2 executed
thufir#dur:~/NetBeansProjects/helloWorldSaxon$
I don't think that's the right import statement, but neither am I sure what would be correct. A closer look at the sample reveals that it's using saxonica and has actually commented out the import:
//import net.sf.saxon.xqj.SaxonXQDataSource;
To re-iterate, would want to stay within Saxon-HE. But how?
From the build file:
compile (group = "net.sf.saxon" , name = "Saxon-HE" , version = "9.9.0-2")
Sticking to Saxon-HE this is the correct import?
Which data source does this ship with?
thufir#dur:~/saxon$
thufir#dur:~/saxon$ jar tf Saxon-HE.jar | grep data
net/sf/saxon/data/
net/sf/saxon/data/analyze-string.xsd
net/sf/saxon/data/casevariants.xml
net/sf/saxon/data/categories.xml
net/sf/saxon/data/chameleon.xsl
net/sf/saxon/data/json.xsd
net/sf/saxon/data/normalizationData.xml
net/sf/saxon/data/override.xsl
net/sf/saxon/data/unicodeBlocks.xml
net/sf/saxon/data/xml-to-json-indent.xsl
net/sf/saxon/data/xml-to-json-pkg.xsl
net/sf/saxon/data/xml-to-json.xsl
net/sf/saxon/data/xpath-functions.scm
net/sf/saxon/data/xpath-functions.xsd
net/sf/saxon/resource/MetadataResource$1.class
net/sf/saxon/resource/MetadataResource.class
thufir#dur:~/saxon$
Do I need more compile dependencies? If so, which ones?

The class SaxonXQDataSource is in package com.saxonica.xqj. If you are using Saxon-HE, then you will need to have the JAR file saxon9-xqj.jar on the classpath.
The reason Saxon's XQJ library is treated differently from the rest of Saxon-HE is that the licensing is different. The XQJ interface is published by Oracle, and Oracle claim that implementations are subject to the Oracle licensing conditions (some people dispute that implementing a published API requires a license, but that's a matter for the lawyers). The Oracle licensing conditions don't conform to the accepted standards for open source licensing (for two reasons: (a) they disallow modifications, and (b) they require implementations to pass all the reference tests). For this reason some software companies who redistribute Saxon-HE prefer to exclude XQJ from the distribution, and to make this easy, we put the XQJ classes in a separate JAR file.

Related

Error during SonarScanner execution after executing SonarScanner.MSBuild.exe end command

Sonarqube Version -7.9.5
SonarQube Scanner - sonar-scanner-msbuild-5.0.4.24009-net46
Source code contains - C#, angular.js, html5, javascript.
Hi,
I executed the following commands and after executing the 3rd command I am getting execution failure error.
The command I executed in the CMD prompt are browsing to the path where solution is present are,
SonarScanner.MSBuild.exe begin /k:"Demo" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="TokenID_ABC"
MsBuild.exe /t:Rebuild
SonarScanner.MSBuild.exe end /d:sonar.login="TokenID_ABC"
ERROR: Error during SonarScanner execution
org.sonar.java.AnalysisException: Please provide compiled classes of your project with sonar.java.binaries property
I found one similar kind of issue reported where it is said that due to .java file present in the code the issue occurs, in our code as well .java files are present, not sure the use of them. How can I exclude those .java files while SonarQube analysis is performed and in which file do I need to add exclusion code?
Also, if there is some another solution to resolve this issue, then please let me know as I have very limited knowledge of Sonar.
Link of similar issue -
https://community.sonarsource.com/t/error-while-running-sonar-scanner-please-provide-compiled-classes-of-your-project-with-sonar-java-binaries-property/30027/2
You can exclude arbitrary files by going to your project settings in SonarQube -> Analysis Scope -> Source File Exclusions. Use regex to match your java files, i.e. *.java.

Where/how to get the MSVC dlls Java 1.8.0_144 wants?

I'm experimenting with building my application with Java 1.8.0_144 to workaround an issue that apparently started after that. I run this command to build:
gradle jfxNative -Dorg.gradle.java.home="c:\Program Files\Java\jdk1.8.0_144"
and it stops with this error:
Execution failed for task ':jfxNative'.
> Not found MSVC dlls
Where and how do I get these MSVC dlls?
The full output looks like this:
c:\...\>gradle jfxNative -Dorg.gradle.java.home="c:\Program Files\Java\jdk1.8.0_144"
> Task :jfxNative
The jar lib\lombok-1.16.18.jar has a main class lombok.launch.Main that does not match the declared main tech.dashman.dashman.ConfiguratorApp
The jar lib\jna-4.5.0.jar has a main class com.sun.jna.Native that does not match the declared main tech.dashman.dashman.ConfiguratorApp
The jar lib\javassist-3.22.0-CR2.jar has a main class javassist.CtClass that does not match the declared main tech.dashman.dashman.ConfiguratorApp
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':jfxNative'.
> Not found MSVC dlls
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
5 actionable tasks: 2 executed, 3 up-to-date
My current list of dependencies look like this:
dependencies {
compile "tech.dashman:dashmancommon:1.0.0-SNAPSHOT"
compile "org.projectlombok:lombok:1.16.18"
compile "org.springframework:spring-web:5.0.2.RELEASE"
compile "org.springframework.retry:spring-retry:1.2.2.RELEASE"
compile "com.fasterxml.jackson.core:jackson-databind:2.9.3"
compile "org.kordamp.ikonli:ikonli-javafx:2.1.0"
compile "org.kordamp.ikonli:ikonli-fontawesome5-pack:2.1.1"
compile "net.harawata:appdirs:1.0.1"
compile "io.sentry:sentry:1.6.4"
compile "org.javassist:javassist:3.22.0-CR2"
testCompile "junit:junit:4.12"
}
I tried adding
compile "net.java.dev.jna:jna-platform:4.5.1"
to that list but I'm still getting the same error when trying to build the installer.
Adding it to my buildscript dependencies did not change the error either:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "de.dynamicfiles.projects.gradle.plugins:javafx-gradle-plugin:8.8.2"
classpath "com.github.ben-manes:gradle-versions-plugin:0.17.0"
classpath "de.dynamicfiles.projects.javafx.bundler:custom-file-extension-windows-bundler:1.0.2-SNAPSHOT"
classpath "net.java.dev.jna:jna-platform:4.5.1"
}
}
Maintainer of the javafx-maven-plugin/Author of the javafx-gradle-plugin here!
Even if this is a very old post, and I did not see this one before (sorry), I might have an answer to this issue. And it happens even today.
While debugging an issue on the plugin (https://github.com/javafx-maven-plugin/javafx-maven-plugin/issues/395) I found that sometimes there are 2 files missing inside the JDK itself.
In case someone has installed any non-Oracle JDK, e.g. OpenLogic, the provided files are incomplete.
The JDK provided by OpenLogic (other others) provides a file called ant-javafx.jar, where all the system native files are contained (can be found inside the installed JDK in the lib-folder). That file is missing the required runtime files, that are required by the launcher.
Here a screenshot of what it looks like with OracleJDK:
Here a screenshot of what it looks with OpenLogic JDK:
As you can see, there are files missing in there, which makes that JDK not equivalent to the OracleJDK sadly.
On maven-plugin level I can not do anything here to fix this, but you might be able to fix that by modifying that JAR-file by adding the missing files. You should be able to find them on your local windows installation at C:\Windows\System32\vcruntime140.dll or C:\Windows\System32\msvcp140.dll. If these files are missing, you just can download a official runtime installer of these Visual C++ Redistributable files here:
for 32-bit: https://aka.ms/vs/16/release/vc_redist.x86.exe
for 64-bit: https://aka.ms/vs/16/release/vc_redist.x64.exe
Another alternative would be to install a different OpenJDK, for example ojdkbuild (https://github.com/ojdkbuild/ojdkbuild). Using chocolatey on Windows just makes this a one-liner choco install ojdkbuild8 and does contain these required files.

Gradle - What is a non-zero exit value and how do I fix it?

I am developing an Android application, and every time I run it, I get this message:
:module:someTask FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':module:someTask'.
> some message here... finished with non-zero exit value X
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: Y.ZZ secs
I have already tried cleaning and building the project, but the error persists.
I have seen answers that say to enable Multidex or increase the heap size, but I am sure I don't need either solution.
What can I do to solve this?
About this question: This is a direct extension of What is a stack trace, and how can I use it to debug my application errors? except you are looking at a Gradle stack trace instead of a Java stack trace.
Foreword
That error message is not enough information to diagnose the problem. There are ways to get more information, and that should be inspected first.
The Gradle output itself should point at the actual error in the few lines above that message between :module:someTask FAILED and the last :module:someOtherTask. Therefore, if you ask a question about your error, please edit your questions to include more context to the error.
The problem
The someTask part of the app:someTask FAILED is very important as it tells you exactly which step of the build process has crashed.
These steps include preparing dependencies, generating and merging the assets and resource files, checking the code for errors and compiling, then finally installing the app.
If at any point of the build process Gradle detects an anomaly, it will throw a non-zero exit value indicating an error has occurred.
The exit value itself is somewhat important.
1 is a just a general error code and the error is likely in the Gradle output
2 seems to be related to overlapping dependencies or project misconfiguration.
3 seems to be from including too many dependencies, or a memory issue.
There are probably others, so please feel free to provide your own comments or answers with other values.
The solution
The general solutions for the above (after attempting a Clean and Rebuild of the project) are:
1 - Address the error that is mentioned. Generally, this is a compile-time error, meaning some piece of code in your project is not valid. This includes both XML and Java for an Android project. Refer to the image for all the things going into the app
2 & 3 - Many answers here tell you to enable multidex. While it may fix the problem, it is most likely a workaround. If you don't understand why you are using it (see the link), you probably don't need it.
If you are unable to find any error output in the Gradle log, then the recommended course of action would be to open Gradle window of Android Studio.
Open up the Tasks folder for each module and perform some combination of the following.
To clean and reset the code of generated files, use build > clean followed by build > build.
To inspect nested dependencies, use help > dependencies. Make sure none are duplicated.
To check your code for syntax errors and warnings, run verification > lint. This will output an HTML file that you can read in your browser. The Gradle logs will say Wrote HTML report to file:///path/to/app/build/outputs/lint-results.html, so just open that file to see all the errors and warnings.
To try and run the app on a device, use install > installDebug.
Additional notes
I've seen many post with value 2 when just installing Android Studio and there is an error
'android-studio/jre/bin/java' finished with non-zero exit value 2
Installing the Java JDK and correctly configuring Android Studio to use the JDK seems to fix this issue.
If you are using the Google Play Services by compile 'com.google.android.gms:play-services:X.Y.Z', then only include the dependencies you actually need, otherwise you most likely did hit the Multidex limit. See how to enable it.
If you have a line in your Gradle file that reads compile fileTree(dir: 'libs', include: ['*.jar']), then you don't need any other line that has compile files('libs/some_file.jar') because that first way says "include every JAR file in the libs/ directory."
Along with that point, if you are using Gradle and are able to find the dependencies that you would like to use by searching the Maven Repository, then it is strongly encouraged to use that instead of manually placing JAR files into the libs/ directory. For each library on that site, there is a Gradle tab and you just need to copy that one line and put compile <line you copied> into the dependencies section.
If you have a line that compiles another project such as compile project(":project_name"), then make sure you aren't duplicating dependencies from there.
Another solution for memory-related issues involves expanding the heap size, which is done from the build.gradle like so
android {
// Other stuffs
dexOptions {
javaMaxHeapSize "2g" // or "4g" if your device has enough memory
}
}
A non-zero exit value is like a check engine light. It simply tells you that something went wrong. You still need to do further diagnostics to figure out what the problem is exactly. To start, you should scroll up in the output from Gradle and see if there is anything else that gives more specific details about what went wrong.

importing NotNull or Nullable and Android Studio won't compile

When I add #NotNull or #Nullable annotations to a parameter Android Studio automatically helps me with adding /lib/annotations.jar and importing
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable;
But after this, the project won't compile. If I also remove the annotations but keep the import statements the project still won't compile. But if I remove the import statements for NotNull and Nullable the project compiles fine!
Android Studio gives a generic error:
Gradle:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':Bugtester:compileDebug'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Running gradlew compileDebug from cmd gives a slight hint:
:Bugtester:compileDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':Bugtester:compileDebug'.
> Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
So I checked my environment variables and they are set as:
JAVA_HOME=C:\Program Files (x86)\Java\jre7
JDK_HOME=C:\Program Files\Java\jdk1.7.0_21\
Anyone got any idea for this? (I'm new to both java and android programming)
I guess, the right way is using original JetBrains library from MavenCentral repository in your build.gradle dependencies (latest available version in this example):
dependencies {
implementation 'com.intellij:annotations:+#jar'
...
}
You can also use android's own #NonNull & #Nullable:
Add the following to build.gradle:
dependencies {
...
// For #Nullable/#NonNull
compile 'com.android.support:support-annotations:+'
}
Go to File / Setting → Project Settings → Inspections and search for "nullable".
In Constant conditions & exceptions and #NotNull/#Nullable problems, click Configure annotations and select Android's annotations.
You may also want to check out Suggest #Nullable annotations… under Constant conditions & exceptions, or possibly tweak other options.
For using Android support anotation like - #Nullable, #NonNull etc.. In your project must be imported android support annotations library. Just add this line to dependensies in gradle file
dependencies {
compile 'com.android.support:support-annotations:+'
}
And import package to class.
For using #Nullable annotation:
import android.support.annotation.Nullable;
For #NonNull
import android.support.annotation.NonNull;
More info you can find here Android developers
At the moment, there is no NonNull/Nullable annotations in the Android API or in the support library. You also cannot use the IntelliJ one since they are not on the compilation classpath when building with Gradle.
However, you can easily create your own. It's very simple:
#Documented
#Retention(RetentionPolicy.CLASS)
#Target({METHOD,PARAMETER,LOCAL_VARIABLE,FIELD})
public #interface NonNull {
}
Once this is down, you can configure IntelliJ (or Android Studio) to recognize this one (and the matching #Nullable) to be the default annotation used for Null-checks.
To do this, go in the IntelliJ preferences, under Inpections, and then find the #NotNull/#Nullable problems entry under Probable Bugs in the inspection tree.
Select the item, and in the bottom right you'll have a button to "Configure Annotations". This will allow you set your own annotations as the one intelliJ will use for this inspection.
In 2015, you would have used annotations from android.support.annotation package. I am just not sure when they added them as in the docs there isn't that typical sentence "Added in API level X" and I don't feel like reading blogs, etc. >]
import android.support.annotation.NonNull;
...
public void fooFighter(#NonNull Object honeyBunny){
...
}
I am facing that problem for gradle-5.1.1 - Android Studio 3.4 and the error like that - Compilation failed; see the compiler error output for details. Execution failed for task ':app:compileDebugJavaWithJavac'. etc. In this case I use
implementation 'org.jetbrains:annotations:16.0.2'
and above all error will be clear.
Just import androidx.annotation.Nullable for that purpose
The best way is to use the maven dependency
set the repository path, by adding
repositories {
maven {
url "https://repository.jboss.org/nexus/content/repositories/thirdparty-releases"
}
}
add the dependency
dependencies {
compile 'org.jetbrains:annotations:7.0.2'
}
PROFIT!
For Maven add dependency:
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>16.0.1</version>
</dependency>

Populating Team Build summary with errors / warning from an ant build

I am using TFS 2008 and team build to compile some Java code using ant and the Microsoft Team Foundation Server 2010 Build Extensions. My experience is with the Microsoft stack and ant is a bit of an unknown for me, we have a contractor who knows all about the Java / ant world but he's never used TFS before.
I've created a TFSbuild.proj which calls an ant build.xml file. The build runs and compiles the code, the output is copied to the drop location, so all of that is good. However when I inspect the build log I can see lots of warnings from the Java compiler, but the build summary says 0 errors, 0 warnings.
Our coding standards dictate that all compiler and static code anlysis warnings should be addressed and the build summary is a great way to let developers know that they need to look at the code. Is there any way of getting ant to return the errors / warnings back to team build so that it can populate the build summary with the warnings? Below are some examples of the warnings I can see in the log.
[buildObjects] E:\Build\Sources\Project\custom\WEB-INF\config\Configuration\Audit Configuration.xml: warning: You are overring an object imported by init.xml with the same 'Audit Configuration' but with a different ID '#ID#Configuration:AuditConfiguration'.
[buildObjects] E:\Build\Sources\Project\custom\WEB-INF\config\AdminGroup\Manager Operations.xml: warning: It is a recommended best practice that the object 'Manage Operations' specify an ID '#ID#AdminGroup:Manage Operations'.
[buildObjects] E:\Build\Project\custom\WEB-INF\config\AdminRole\AdminRole-operations.xml: warning: ObjectRef to object 'IS Admin' cannot be resolved in the current project.
[buildObjects] E:\Build\Project\custom\WEB-INF\config\Configuration\SubProcess-addAccessManager.xml:153: warning: Unresolved reference to variable 'user'. Variable is assumed to be a task input variable.
The Build Extensions power tool should be parsing out errors and warnings and putting them into your build log already I think. Can you drop me a line (martinwo#microsoft.com) with your ant log output and I'll try and take a look? I'll edit this answer again once we've figured it out.

Categories

Resources