javacc / javaccPlugin

A JavaCC plugin for Gradle
MIT License
33 stars 16 forks source link

gradle 3.2: resolutionStrategy question #29

Closed zosrothko closed 7 years ago

zosrothko commented 7 years ago

Hi This is not really an issue but as there is no way to ask question about javaccPlugin on GitHub.

I am trying to use another version of JavaCC, the 7.0 to generate a C++ parser with

buildscript {
        repositories {
                mavenLocal()
                mavenCentral()
        }
        dependencies {
                classpath group: 'ca.coglinc', name: 'javacc-gradle-plugin', version: '2.3.1'
        }
        configurations {
                all {
                        resolutionStrategy {
                                force group: 'net.java.dev.javacc', name: 'javacc', version: '7.0'
                        }
                }
        }
}
apply plugin: 'ca.coglinc.javacc'

compileJavacc {
    inputDirectory = projectDir
    outputDirectory = file(project.buildDir.absolutePath + '/generated/javacc')
//      arguments = [grammar_encoding: 'UTF-8', static: 'false']
}

but that does not work. What I am missing?

Z:\git\asn1cpp>c:\programfiles\gradle\bin\gradle --no-daemon compileJav -i
Initialized native services in: C:\Users\FrancisANDRE\.gradle\native
Starting Build
Settings evaluated using settings file 'Z:\git\asn1cpp\settings.gradle'.
Projects loaded. Root project using build file 'Z:\git\asn1cpp\build.gradle'.
Included projects: [root project 'asn1cpp', project ':code', project ':code:ASN1Sema', project ':code:ASN1Typer', project ':code:ASN1Ut
il']
Evaluating root project 'asn1cpp' using build file 'Z:\git\asn1cpp\build.gradle'.
Evaluating project ':code' using build file 'Z:\git\asn1cpp\code\build.gradle'.
Evaluating project ':code:ASN1Sema' using build file 'Z:\git\asn1cpp\code\ASN1Sema\build.gradle'.
Evaluating project ':code:ASN1Typer' using build file 'Z:\git\asn1cpp\code\ASN1Typer\build.gradle'.
Compiling build file 'Z:\git\asn1cpp\code\ASN1Typer\build.gradle' using SubsetScriptTransformer.
Compiling build file 'Z:\git\asn1cpp\code\ASN1Typer\build.gradle' using BuildScriptTransformer.
Evaluating project ':code:ASN1Util' using build file 'Z:\git\asn1cpp\code\ASN1Util\build.gradle'.
All projects evaluated.
Selected primary task 'compileJavacc' from project :
Tasks to be executed: [task ':code:ASN1Typer:compileJavacc']
:code:ASN1Typer:compileJavacc (Thread[main,5,main]) started.
:code:ASN1Typer:compileJavacc
Putting task artifact state for task ':code:ASN1Typer:compileJavacc' into context took 0.008 secs.
Task :code:ASN1Typer:compileJavacc class loader hash: bedc8dbeb2aa035465441ac5f533edec
Task :code:ASN1Typer:compileJavacc actions class loader hash: 4a89ef0ab58f289cd18652273b611ad8
Executing task ':code:ASN1Typer:compileJavacc' (up-to-date check took 0.017 secs) due to:
  No history is available.
Java Compiler Compiler Version 6.1_2 (Parser Generator)
(type "javacc" with no arguments for help)
Reading from file Z:\git\asn1cpp\code\ASN1Typer\Typer.jj . . .
org.javacc.parser.ParseException: Encountered " "(" "( "" at line 13, column 17.
Was expecting one of:
    "false" ...
    "true" ...
    <INTEGER_LITERAL> ...
    <STRING_LITERAL> ...

Detected 1 errors and 0 warnings.
:code:ASN1Typer:compileJavacc FAILED
:code:ASN1Typer:compileJavacc (Thread[main,5,main]) completed. Took 0.1 secs.
johnmartel commented 7 years ago

Not a problem with the resolution strategy or related to Gradle, your grammar file has an error in it. Please see the logs:

Reading from file Z:\git\asn1cpp\code\ASN1Typer\Typer.jj . . .
org.javacc.parser.ParseException: Encountered " "(" "( "" at line 13, column 17.
Was expecting one of:
    "false" ...
    "true" ...
    <INTEGER_LITERAL> ...
    <STRING_LITERAL> ...

Detected 1 errors and 0 warnings.
:code:ASN1Typer:compileJavacc FAILED
zosrothko commented 7 years ago

No, the grammar has no error, the JavaCC 7.0 supports the generation of C++ code which I have extended for supporting list for the PARSER_INCLUDE option. The line 13 corresponds to the first '(' of the list of the PARSER_INCLUDE option.

Typer.jj

options {
OUTPUT_LANGUAGE = "c++";
JDK_VERSION="1.7";
SANITY_CHECK=true;
DEBUG_PARSER=true;
DEBUG_TOKEN_MANAGER=false;
DEBUG_LOOKAHEAD=true;
STATIC=false;
COMMON_TOKEN_ACTION = true;
TOKEN_MANAGER_USES_PARSER=true;
//USER_CHAR_STREAM=true;
NAMESPACE="ASN1::Typer";
PARSER_INCLUDES=("ASN1Sema/Include.h", "ASN1Sema/Sema.h", "ASN1Sema/Context.h");
}

compiles fine with

Z:\git\gradle> java -classpath "C:\ProgramFiles\JavaCC\javacc-7.0.0\target\javacc.jar" javacc  -output_directory=Z:\git\asn1cpp\code\AS
N1Typer\ Z:\git\asn1cpp\code\ASN1Typer\Typer.jj
Java Compiler Compiler Version 7.0.0 (Parser Generator)
(type "javacc" with no arguments for help)
Reading from file Z:\git\asn1cpp\code\ASN1Typer\Typer.jj . . .
File "JavaCC.h" is being rebuilt.
Parser generated successfully.
johnmartel commented 7 years ago

Sorry, but JavaCC outputs an error, that’s crystal clear from the logs, you should check that, as I am not supporting JavaCC itself :)


Jonathan Martel Informaticien conseiller en Génie Logiciel Consultants CoGL inc. 581.986.7030 jonathan.martel@coglinc.ca Twitter: @johnmartelqc LinkedIn: http://www.linkedin.com/pub/jonathan-martel/24/312/711

Signature digitale: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x321163AE83A4068A

On Nov 1, 2016, at 13:00, zosrothko notifications@github.com wrote:

No, the grammar has no error, the JavaCC 7.0 supports the generation of C++ code which I have extended for supporting list for the PARSER_INCLUDE option. The line 13 corresponds to the first '(' of the list of the PARSER_INCLUDE option.

Typer.jj

options { OUTPUT_LANGUAGE = "c++"; JDK_VERSION="1.7"; SANITY_CHECK=true; DEBUG_PARSER=true; DEBUG_TOKEN_MANAGER=false; DEBUG_LOOKAHEAD=true; STATIC=false; COMMON_TOKEN_ACTION = true; TOKEN_MANAGER_USES_PARSER=true; //USER_CHAR_STREAM=true; NAMESPACE="ASN1::Typer"; PARSER_INCLUDES=("ASN1Sema/Include.h", "ASN1Sema/Sema.h", "ASN1Sema/Context.h"); } compiles fine with

Z:\git\gradle> java -classpath "C:\ProgramFiles\JavaCC\javacc-7.0.0\target\javacc.jar" javacc -output_directory=Z:\git\asn1cpp\code\AS N1Typer\ Z:\git\asn1cpp\code\ASN1Typer\Typer.jj Java Compiler Compiler Version 7.0.0 (Parser Generator) (type "javacc" with no arguments for help) Reading from file Z:\git\asn1cpp\code\ASN1Typer\Typer.jj . . . File "JavaCC.h" is being rebuilt. Parser generated successfully. — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/johnmartel/javaccPlugin/issues/29#issuecomment-257642317, or mute the thread https://github.com/notifications/unsubscribe-auth/AC7SX6l6mQFZgZcUCDqxgOhR90bumyOCks5q535FgaJpZM4KmWtE.

zosrothko commented 7 years ago

Sorry to insist, but this is not a request about JavaCC itself but on getting some help about the force resolutionStrategy on the buildscript ahead that does not work. The script is forcing to use the JavaCC 7.0 jar and the execution log shows that is JavaCC 6.1.2 that is used. Also, my previous message shows that JavaCC 7.0.0 compiles the grammar without error with the CLI.

johnmartel commented 7 years ago

Where did you get the javacc:7.0 artifact, is it installed in maven local? Can't find it in maven central for sure...

johnmartel commented 7 years ago

Can you provide a build script that I can try? Looks to me that the plugin is not using javacc 7.0 because it can't find it, which seems to be confirmed by the javacc output in the build log.

zosrothko commented 7 years ago

I am a contributor of JavaCC and specialy for the C++ generation...The 7.0 is not officialy released to any maven repository (it is up to Sreeni to do that) but this version can be build from the GitHub master repo. Thus I put the javacc 7.0 artifact is in the Maven local repository with this script

apply plugin: 'maven-publish'

def javacc = file('C:/ProgramFiles/JavaCC/javacc-7.0.0/target/javacc.jar')
publishing {
    publications {
        maven(MavenPublication) {
            groupId 'net.java.dev.javacc'
            artifactId 'javacc'
            version '7.0'
            artifact javacc
        }
    }
}

and the command gradlew publishToMavenLocal which produces this metadata

<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <groupId>net.java.dev.javacc</groupId>
  <artifactId>javacc</artifactId>
  <versioning>
    <release>7.0</release>
    <versions>
      <version>6.1.0</version>
      <version>7.0.0</version>
      <version>7.0</version>
    </versions>
    <lastUpdated>20161101165430</lastUpdated>
  </versioning>
</metadata>

here the build.gradle

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
            classpath group: 'ca.coglinc', name: 'javacc-gradle-plugin', version: '2.3.1'
    }
    configurations {
        all {
            resolutionStrategy {
                force group: 'net.java.dev.javacc', name: 'javacc', version: '7.0'
            }
        }
    }
}
apply plugin: 'ca.coglinc.javacc'

compileJavacc {
    inputDirectory = projectDir
    outputDirectory = file(project.buildDir.absolutePath + '/generated/javacc')
//  arguments = [grammar_encoding: 'UTF-8', static: 'false']
}
zosrothko commented 7 years ago

Hi

Running gradle compileJavaCC with debug produces a log where I found this snippet

20:02:47.241 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder] Visiting dependency a
sn1cpp.code:ASN1Parser:unspecified(classpath) -> dependency: ca.coglinc:javacc-gradle-plugin:2.3.1 from-conf: classpath to-conf: nul
l
20:02:47.257 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder] Selecting new module
version ca.coglinc:javacc-gradle-plugin:2.3.1
20:02:47.257 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainComponentMetaDataResolver] Attempting t
o resolve component for ca.coglinc:javacc-gradle-plugin:2.3.1 using repositories [MavenLocal, MavenRepo]
20:02:47.257 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver] Loading file:
/C:/Users/FrancisANDRE/.m2/repository/ca/coglinc/javacc-gradle-plugin/2.3.1/javacc-gradle-plugin-2.3.1.pom
20:02:47.272 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver] Loading file:
/C:/Users/FrancisANDRE/.m2/repository/ca/coglinc/javacc-gradle-plugin/2.3.1/javacc-gradle-plugin-2.3.1.jar
20:02:47.272 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver] No meta-data file or artifac
t found for module 'ca.coglinc:javacc-gradle-plugin:2.3.1' in repository 'MavenLocal'.
20:02:47.288 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Opening cache module-metadata.bin (C:\Users\Franc
isANDRE\.gradle\caches\modules-2\metadata-2.23\module-metadata.bin)
20:02:47.303 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository] Using cached module
metadata for module 'ca.coglinc:javacc-gradle-plugin:2.3.1' in 'MavenRepo'
20:02:47.319 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainComponentMetaDataResolver] Using ca.cog
linc:javacc-gradle-plugin:2.3.1 from Maven repository 'MavenRepo'
20:02:47.319 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder] Visiting configuratio
n ca.coglinc:javacc-gradle-plugin:2.3.1(default).
20:02:47.319 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder] Visiting dependency c
a.coglinc:javacc-gradle-plugin:2.3.1(default) -> dependency: net.java.dev.javacc:javacc:6.1.2, scope: Runtime, optional: false
20:02:47.319 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder] Selecting new module
version net.java.dev.javacc:javacc:6.1.2
20:02:47.319 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainComponentMetaDataResolver] Attempting t
o resolve component for net.java.dev.javacc:javacc:6.1.2 using repositories [MavenLocal, MavenRepo]
20:02:47.319 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver] Loading file:
/C:/Users/FrancisANDRE/.m2/repository/net/java/dev/javacc/javacc/6.1.2/javacc-6.1.2.pom
20:02:47.319 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver] Loading file:
/C:/Users/FrancisANDRE/.m2/repository/net/java/dev/javacc/javacc/6.1.2/javacc-6.1.2.jar
20:02:47.319 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver] No meta-data file or artifac
t found for module 'net.java.dev.javacc:javacc:6.1.2' in repository 'MavenLocal'.
20:02:47.319 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository] Using cached module
metadata for module 'net.java.dev.javacc:javacc:6.1.2' in 'MavenRepo'
20:02:47.319 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainComponentMetaDataResolver] Using net.ja
va.dev.javacc:javacc:6.1.2 from Maven repository 'MavenRepo'
20:02:47.319 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder] Visiting dependency c
a.coglinc:javacc-gradle-plugin:2.3.1(default) -> dependency: commons-io:commons-io:2.4, scope: Runtime, optional: false

gradle or the javacc plugin is looking for the 6.1.2 version in MavenLocal while it should used the 7.0.0 version. May be this could be a pointer to find out the problem?

johnmartel commented 7 years ago

I will have a look over the weekend. I'll build JavaCC 7 and try to force using this version. Sorry, I am away for work right now and can't find the time to work on this issue.

zosrothko commented 7 years ago

no problem..; I was thinking just to shorten the domain of research..thanks for taking care of this point.

johnmartel commented 7 years ago

Can you point me on the right repo/branch for JavaCC, just to be sure I have the correct source?

zosrothko commented 7 years ago

The master branch here is versionned at 7.0.0

johnmartel commented 7 years ago

Due to changes to the plugin publishing mechanism to the plugin portal, I need to reclaim the plugin with Gradle before being able to publish it to the plugin portal. The new version of the plugin is built and released and as soon as Gradle acknowledges my reclaim request, I will publish the new version to the plugin portal. This issue is now fixed.

The default version used is 6.1.2.

It is as easy as declaring a dependency on javacc to customize the javacc version:

dependencies {
    javacc 'net.java.dev.javacc:javacc:[version]'
}