ANTLR4 does not find grammar on import - java

I am trying to split my ANTLR4 grammar in multiple files so i can test them more easily, i am using gradle as a build tool in a java project.
Both grammar compile correctly by separate but when i add the import to my main grammar i get the next compilation error
error(110): kanekotic/specflow/rider/SpecflowFeature.g4:3:7: can't find or load grammar SpecflowScenario
the inherited grammar looks like:
grammar SpecflowScenario;
#header {
package kanekotic.specflow.rider;
}
scenario
: 'Scenario: ';
and the main grammar looks like:
grammar SpecflowFeature;
import SpecflowScenario;
#header {
package kanekotic.specflow.rider;
}
file returns [List<String> values]
#init { $values = new ArrayList<String>(); }
: 'Feature: ' EOF;
What am i doing wrong? is this not allowed?
edit:
the gradle.build looks like:
plugins {
id "org.jetbrains.intellij" version "0.1.10"
}
apply plugin: 'org.jetbrains.intellij'
apply plugin: 'java'
apply plugin: 'antlr'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
intellij {
version '143.2370.31'
pluginName 'Specflow Rider'
}
group 'kanekotic.specflow.rider'
version '0.1'
repositories {
mavenCentral()
jcenter()
}
dependencies {
antlr "org.antlr:antlr4:4.5"
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:2.+"
}
all the code as it is open sourced is in this next link: https://github.com/kanekotic/Specflow.Rider/tree/antlr4_multiple_grammar

The Antlr plugin uses src/main/antlr as lib directory by default. As the grammar file to include is in kanekotic/specflow/rider, use the following code in your gradle file to include this location:
generateGrammarSource {
arguments << "-lib" << "src/main/antlr/kanekotic/specflow/rider"
}
See also this gradle thread.

Related

Way to get Gradle Jacoco to Output Coverage to Console?

In python, using Coverage.py we are able to get line information about code coverage on the command line using coverage report --show-missing. This showed what lines of each file weren't being covered.
Using gradle plugins, the best output I can get is:
- Class Coverage: 10%
- Method Coverage: 3.2%
- Branch Coverage: 100%
- Line Coverage: 1.2%
- Instruction Coverage: 1.1%
- Complexity Coverage: 3.2%
However as this does not give line information, you may as well just look at html output.
My test.gradle file:
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id 'application'
id 'jacoco'
id 'com.github.ksoichiro.console.reporter' version '0.6.2'
id 'org.barfuin.gradle.jacocolog' version '1.2.4'
}
dependencies {
implementation files('lib/json.jar')
implementation files('lib/junit-platform-console-standalone-1.7.0-M1.jar')
implementation files('lib/jsonassert-1.2.3.jar')
}
test {
useJUnitPlatform()
finalizedBy jacocoTestReport // report is always generated after tests run
ignoreFailures = true
}
test.outputs.upToDateWhen {false}
jacocoTestReport {
dependsOn test // tests are required to run before generating the report
}
repositories {
mavenCentral()
}
group 'unsw.blackout'
apply plugin: 'java'
sourceSets.test.java.srcDirs = ['src']
sourceSets.test.java.excludes = ['degree/*']
sourceSets.main.java.srcDirs = ['src']
sourceSets.main.java.excludes = ['degree/*']
Is there an equivalence for gradle?

Firebase Firestore crash at RunTime error

I have a project where i use Google Cloud Speech, and Firebase RealTime Database, and also as the project evolved i would like to add Google FireStore functionallity. But after I compile the dependency i have a RunTime error:
Error:(458, 21) error: no suitable method found for
intercept(GoogleCredentialsInterceptor)
method zzbc.intercept(List<zzl>) is not applicable
(argument mismatch; GoogleCredentialsInterceptor cannot be converted to List<zzl>)
method zzbc.intercept(zzl...) is not applicable
(varargs mismatch; GoogleCredentialsInterceptor cannot be converted to zzl)
method AbstractManagedChannelImplBuilder.intercept(List<zzl>) is not applicable
(argument mismatch; GoogleCredentialsInterceptor cannot be converted to List<zzl>)
method AbstractManagedChannelImplBuilder.intercept(zzl...) is not applicable
(varargs mismatch; GoogleCredentialsInterceptor cannot be converted to zzl)
This error occurs when i try to get the credentials from GCS.
#Override
protected void onPostExecute(AccessToken accessToken) {
mAccessTokenTask = null;
final ManagedChannel channel = new OkHttpChannelProvider()
.builderForAddress(HOSTNAME, PORT)
.nameResolverFactory(new DnsNameResolverProvider())
.intercept(new GoogleCredentialsInterceptor(new GoogleCredentials(accessToken)
.createScoped(SCOPE)))
.build();
mApi = SpeechGrpc.newStub(channel);
// Schedule access token refresh before it expires
if (mHandler != null) {
mHandler.postDelayed(mFetchAccessTokenRunnable,
Math.max(accessToken.getExpirationTime().getTime()
- System.currentTimeMillis()
- ACCESS_TOKEN_FETCH_MARGIN, ACCESS_TOKEN_EXPIRATION_TOLERANCE));
}
}
}
The code is crashing at this part of code:
.intercept(new GoogleCredentialsInterceptor(new GoogleCredentials(accessToken).createScoped(SCOPE)))
My dependencies:
ext {
//FirebaseUI Version Firebase/Play Services Version
// 3.1.0 11.4.2
supportLibraryVersion = '27.0.0'
grpcVersion = '1.7.0'
googlePlayVersion = '11.4.2'
firebaseVersion = '11.4.2'
fireUIVersion = '3.1.0'
facebookVersion = '4.27.0'
glideVersion = '4.3.0'
}
...
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "io.grpc:grpc-okhttp:$grpcVersion"
compile "io.grpc:grpc-protobuf-lite:$grpcVersion"
compile "io.grpc:grpc-stub:$grpcVersion"
compile('com.google.auth:google-auth-library-oauth2-http:0.7.1') {
exclude module: 'httpclient'
}
// Support Libraries:
compile "com.android.support:appcompat-v7:$supportLibraryVersion"
compile "com.android.support:preference-v7:$supportLibraryVersion"
compile "com.android.support:design:$supportLibraryVersion"
compile "com.android.support:cardview-v7:$supportLibraryVersion"
compile "com.android.support:preference-v7:$supportLibraryVersion"
compile "com.google.android.gms:play-services-auth:$firebaseVersion"
// FirebaseUI for Firebase Auth
compile "com.google.android.gms:play-services-auth:$googlePlayVersion"
compile "com.google.firebase:firebase-database:$firebaseVersion"
compile "com.google.firebase:firebase-auth:$firebaseVersion"
compile "com.google.firebase:firebase-core:$firebaseVersion"
compile "com.google.firebase:firebase-firestore:$firebaseVersion"
compile "com.android.support:recyclerview-v7:$supportLibraryVersion"
compile "com.android.support:support-v4:$supportLibraryVersion"
compile 'com.firebaseui:firebase-ui-auth:3.1.0'
compile 'com.android.support.constraint:constraint-layout-solver:1.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'javax.annotation:javax.annotation-api:1.2'
apply plugin: 'com.google.gms.google-services'
The project level :
buildscript {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
classpath 'com.android.tools.build:gradle:3.1.0-alpha01'
classpath 'com.google.gms:google-services:3.1.1'
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
maven { url "https://jitpack.io" }
maven {
url "http://dl.bintray.com/ahmedrizwan/maven"
}
maven {
url "http://dl.bintray.com/glomadrian/maven"
}
mavenCentral()
}
}
If i remove the:
// TRYED WITH compile 'com.google.firebase:firebase-firestore:11.4.2'
compile 'com.firebaseui:firebase-ui-auth:3.1.0'
All works great! But i need it for Firestore functionallity.
I have all API enabled, And Google Cloud Data Storage disabled.
Cloud Firestore and App Engine: You can't use both Cloud Firestore and Cloud Datastore in the same project, which might affect apps using App Engine. Try using Cloud Firestore with a different project.
Sorry you're encountering this, but Firestore is not (currently) compatible with an external gRPC, as answered here:
Cloud Firestore with gRPC build error
The 11.8.0 release fixes this.

OWLAPI: Parser not found if run from Jar

I wrote an ontology importer in Java to parse an RDF-formatted .owl file into a JSON-formatted string. More specifically, the static method parseOntologyObjectHierarchy parses the class hierarchy defined in the ontology into JSON. Everything works fine if I call the method from a JUnit test or the main method of a class (JUnit and the class main are invoked from IntelliJ IDEA Professional 2017). However, if I package my classes as a jar using gradle (including all dependencies), I get an org.semanticweb.owlapi.io.UnparsableOntologyException. The jar actually contains the required RDFXMLParser. Is the classpath in the jar not set properly?
Here is a minimal example IntelliJ IDEA project: https://drive.google.com/open?id=0B10MbhsMWfrydVNKZVJ0QVg1NlE
And here is the corresponding minimal jar: https://drive.google.com/open?id=0B10MbhsMWfrybjJIcDNWd0JFMUk
Here is the code:
public static String parseOntologyObjectHierarchy(String filename) throws OWLException {
System.out.println("OWL file: " + filename);
OWLOntology ontology = loadOntology(filename);
OWLDataFactory df = OWLManager.getOWLDataFactory();
return json = hierarchyToString(ontology, df.getOWLThing());
}
public static OWLOntology loadOntology(String filename) throws OWLOntologyCreationException {
File ontologyFile = new File(filename);
if (!ontologyFile.exists() || !ontologyFile.isFile()) {
throw new IllegalArgumentException("OWL file is not a file");
}
OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
OWLOntologyDocumentSource source = new FileDocumentSource(new File(filename), new RDFXMLDocumentFormat());
return ontologyManager.loadOntologyFromOntologyDocument(source);
}
Here is my build.gradle:
group 'com.example'
version '0.1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'net.sourceforge.owlapi', name: 'owlapi-osgidistribution', version: '5.1.0'
compile group: 'net.sourceforge.owlapi', name: 'owlapi-apibinding', version: '5.1.0'
compile group: 'net.sourceforge.owlapi', name: 'owlapi-parsers', version: '5.1.0'
compile group: 'net.sourceforge.owlapi', name: 'owlapi-impl', version: '5.1.0'
compile 'com.google.code.gson:gson:2.8.0'
compile 'net.sourceforge.owlapi:org.semanticweb.hermit:1.3.8.510'
compile group: 'org.glassfish', name: 'javax.json', version: '1.0.4'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'ExampleCom Ontology Importer',
'Implementation-Version': version,
'Main-Class': 'com.example.ontology.OntologyImporter'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
Here is the exception text:
$ java -jar am-ontology_importer-all-0.1.0-SNAPSHOT.jar
OWL file: C:/Users/me/Desktop/Projects/example/example-0.1.0.owl
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further detail
s.
Exception in thread "main" org.semanticweb.owlapi.io.UnparsableOntologyException
: Problem parsing file:/C:/Users/me/Desktop/Projects/example/example-0.1.0.owl
Could not parse ontology. Either a suitable parser could not be found, or parsi
ng failed. See parser logs below for explanation.
The following parsers were tried:
1) org.coode.owlapi.obo12.parser.OWLOBO12Parser#1ca3d04
Detailed logs:
--------------------------------------------------------------------------------
Parser: org.coode.owlapi.obo12.parser.OWLOBO12Parser#1ca3d04
Stack trace:
Lexical error at line 1, column 22. Encountered: "\n" (10), after : "" o
rg.coode.owlapi.obo12.parser.OBOParserTokenManager.getNextToken(OBOParserTokenMa
nager.java:1059)
org.coode.owlapi.obo12.parser.OBOParser.jj_ntk_f(OBOParser.java:296)
org.coode.owlapi.obo12.parser.OBOParser.TagValuePair(OBOParser.java:147)
org.coode.owlapi.obo12.parser.OBOParser.Header(OBOParser.java:110)
org.coode.owlapi.obo12.parser.OBOParser.parse(OBOParser.java:80)
org.coode.owlapi.obo12.parser.OWLOBO12Parser.parse(OWLOBO12Parser.java:1
09)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.loadOWLOntology(OW
LOntologyFactoryImpl.java:188)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.load(OWLOntologyMa
nagerImpl.java:1072)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OWLOn
tologyManagerImpl.java:1033)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOn
tologyDocument(OWLOntologyManagerImpl.java:982)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.loadOWLOntology
(OWLOntologyFactoryImpl.java:229)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.load(OWLOntolog
yManagerImpl.java:1072)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OW
LOntologyManagerImpl.java:1033)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFro
mOntologyDocument(OWLOntologyManagerImpl.java:982)
at com.example.ontology.OntologyImporter.loadOntology(OntologyImpo
rter.java:52)
at com.example.ontology.OntologyImporter.parseOntologyObjectHierar
chy(OntologyImporter.java:64)
at com.example.ontology.OntologyImporter.main(OntologyImporter.jav
a:142)
in your minimal jar, the META-INF/services folder contains multiple copies of org.semanticweb.owlapi.io.OWLParserFactory - these are likely coming from your merging of OWLAPI dependencies.
Each module declares in this file which parsers can be found in the module (they are interpreted by ServiceLoader to provide instances); owlapi-distribution contains a merged copy of all the files provided by OWLAPI modules. You need to ensure that that's the only file included in your jar.
The same is true for the other files found in this folder.

Get dependencies from subproject within root project

Can't get the subproject dependencies in root build file. They isn't initialized for some reasons.
Is there a possibility to get list of dependencies from project1 for example inside root ?
Pls see copyToLib task. It should return values from dependencies section of project1, but actually it's not.
Gradle version is 2.0
Root
|
|-project1
| |-build.gradle
|-project2
| |-build.gradle
|-core1
| |-build.gradle
|-core2
| |-build.gradle
|-build.gradle
|-settings.gradle
settings.gradle
include 'project1','project2','core1','core2'
rootProject.name="Root"
project1:build.gradle
version = '0.1'
dependencies {
compile project(':core1'),
project(':core2'),
'org.springframework:spring-web:4.0.6.RELEASE'
}
root:build.gradle
subprojects{
apply plugin: 'java'
apply plugin: 'eclipse'
apply from: "${rootProject.projectDir}/eclipse.gradle"
sourceCompatibility = 1.7
repositories {
mavenCentral()
}
task copyToLib(type: Copy) {
def deps = project.configurations.compile.getAllDependencies().withType(ProjectDependency)
for ( dep in deps ) {
println dep.getDependencyProject().projectDir
}
}
build.dependsOn(copyToLib)
}
When project variable is used in subprojects it refers to the current project - in this particular case - root.
You need to remove adding the task from subprojects closure and add the following piece of code:
subprojects.each { p ->
configure(p) {
task copyToLib << {
def deps = p.configurations.compile.allDependencies.withType(ProjectDependency)
for ( dep in deps ) {
println dep.getDependencyProject().projectDir
}
}
p.build.dependsOn(copyToLib)
}
}
Have simplified the task (it's not of type Copy) - You need to differentiate task action from configuration.

Android Studio (0.8.2) + Android Annotations (3.0.1) cannot symbol class MyClass

I have this problem with the annotations for few days...
Error:(13, 26) cannot find symbol class LoginActivityAnnotations_
But the annotation class exist and the class import in my MainActivity work greate
http://imagizer.imageshack.us/v2/150x100q90/911/x8RzRM.png
The annotaitons classes were generated correctly in this directory:
http://imagizer.imageshack.us/v2/150x100q90/538/bEplNx.png
This is my build.grandle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:+'
}
}
apply plugin: 'android'
apply plugin: 'android-apt'
repositories {
mavenCentral()
mavenLocal()
}
apt {
arguments {
resourcePackageName "com.ar.sdocs"
androidManifestFile variant.processResources.manifestFile
}
}
dependencies {
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.android.support:support-v4:20.0.0'
apt "org.androidannotations:androidannotations:+"
compile 'org.androidannotations:androidannotations-api:+'
compile 'com.nhaarman.listviewanimations:library:2.6.0'
compile files('libs/commons-lang3-3.3.1.jar')
compile 'com.google.android.gms:play-services:4.3.+'
compile files('libs/joda-time-2.3.jar')
compile files('libs/bcprov-ext-jdk15on-150.jar')
compile files('libs/bugsense-3.6.1.jar')
compile 'org.apache.httpcomponents:httpcore:4.3.2'
compile 'org.apache.httpcomponents:httpmime:4.3.4'
compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/json-simple-1.1.1.jar')
apt "org.androidannotations:androidannotations:+"
compile 'org.androidannotations:androidannotations-api:+'
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName '0.1'
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
android.applicationVariants.each { variant ->
aptOutput = file("${project.buildDir}/generated/source/apt/${variant.dirName}")
println "****************************"
println "variant: ${variant.name}"
println "manifest: ${variant.processResources.manifestFile}"
println "aptOutput: ${aptOutput}"
println "****************************"
variant.javaCompile.doFirst {
println "*** compile doFirst ${variant.name}"
aptOutput.mkdirs()
variant.javaCompile.options.compilerArgs += [
'-processorpath', configurations.apt.getAsPath(),
'-AandroidManifestFile=' + variant.processResources.manifestFile,
'-s', aptOutput
]
}
variant.addJavaSourceFoldersToModel(aptOutput)
}
But every time I run a build, I get the error I mentioned before. I'm trying different configurations days ago but I can not find one that works
Thats the complete error (I only import the annotations class)
Error:(14, 26) cannot find symbol class LoginActivityAnnotations_
Note: Resolve log file to /Users/CARRY/AndroidStudioProjects/sdocs/SDocs/build/generated/source/apt/androidannotations.log
Note: Initialize AndroidAnnotations 3.0.1 with options {resourcePackageName=com.ar.sdocs, androidManifestFile=/Users/CARRY/AndroidStudioProjects/sdocs/SDocs/build/intermediates/manifests/debug/AndroidManifest.xml}
Note: Start processing for 5 annotations on 145 elements
Note: AndroidManifest.xml file found with specified path: /Users/CARRY/AndroidStudioProjects/sdocs/SDocs/build/intermediates/manifests/debug/AndroidManifest.xml
Note: AndroidManifest.xml found: AndroidManifest [applicationPackage=com.ar.sdocs, componentQualifiedNames=[com.ar.sdocs.main.MainActivity, com.ar.sdocs.login.LoginActivity, com.ar.sdocs.dashboard.DashboardActivity, com.ar.sdocs.login.registro.RegistroActivity, com.ar.sdocs.dashboard.settings.editar.SettingsUserEditActivity, com.ar.sdocs.dashboard.upload.UploadActivity, com.ar.sdocs.dashboard.materias.main.MateriaActivity, com.ar.sdocs.util.media.FilePickerActivity, com.ar.sdocs.gcm.GcmIntentService, com.ar.sdocs.gcm.GcmBroadcastReceiver], permissionQualifiedNames=[android.permission.USE_CREDENTIALS, android.permission.GET_ACCOUNTS, android.permission.READ_PROFILE, android.permission.READ_CONTACTS, android.permission.INTERNET, android.permission.WAKE_LOCK, com.google.android.c2dm.permission.RECEIVE, android.permission.CAMERA, android.permission.READ_EXTERNAL_STORAGE, com.example.gcm.permission.C2D_MESSAGE], applicationClassName=null, libraryProject=false, debugabble=false, minSdkVersion=14, maxSdkVersion=-1, targetSdkVersion=19]
Note: Found project R class: com.ar.sdocs.R
Note: Found Android class: android.R
Note: Validating elements
Note: Validating with EActivityHandler: [com.ar.sdocs.login.LoginActivityAnnotations]
/Users/CARRY/AndroidStudioProjects/sdocs/SDocs/src/main/java/com/ar/sdocs/login/LoginActivityAnnotations.java
Warning:(45, 1) The component LoginActivityAnnotations_ is not registered in the AndroidManifest.xml file.
Note: Validating with ViewByIdHandler: [emailEditText, passwordEditText]
Note: Validating with ClickHandler: [loginButtonClicked(), registerButtonClicked()]
Note: Validating with TouchHandler: [loginRelativeLayoutTouched(android.view.View,android.view.MotionEvent)]
Note: Validating with AfterViewsHandler: [verificarLogin()]
Note: Processing root elements
Note: Processing root elements EActivityHandler: [com.ar.sdocs.login.LoginActivityAnnotations]
Note: Processing enclosed elements
Note: Number of files generated by AndroidAnnotations: 1
Note: Writting following API classes in project: []
Note: Generating class: com.ar.sdocs.login.LoginActivityAnnotations_
Note: Time measurements: [Whole Processing = 148 ms], [Process Annotations = 32 ms], [Generate Sources = 31 ms], [Find R Classes = 24 ms], [Extract Annotations = 23 ms], [Validate Annotations = 16 ms], [Extract Manifest = 11 ms],
Note: Finish processing
Note: Start processing for 0 annotations on 1 elements
Note: Time measurements: [Whole Processing = 3 ms],
Note: Finish processing
Note: Start processing for 0 annotations on 0 elements
Note: Time measurements: [Whole Processing = 1 ms],
Note: Finish processing
Warning:Unclosed files for the types '[dummy1407025286017]'; these types will not undergo annotation processing
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Information:BUILD SUCCESSFUL
Information:Total time: 21.886 secs
Information:1 error
Information:4 warnings
Information:See complete output in console
I could be because you havn't included the LoginActivityAnnotations_ file where you use it - because Android Studio does not help you with that. I had that problem.
You need to make an include of the package where the LoginActivityAnnotations file.
If you were using this include, to get the file without the underscore:
com.example.LoginActivityAnnotations
Then use this one:
com.example.* //To load LoginActivityAnnotations_
(The include will be grey and you will still be left with red words but it will compile)

Categories

Resources