takari / polyglot-maven

Support alternative markup for Apache Maven POM files
Eclipse Public License 1.0
890 stars 99 forks source link

[polyglot-groovy] translation of empty element (relativePath) generates invalid groovy #60

Open fbricon opened 8 years ago

fbricon commented 8 years ago

This one is kinda similar to bug #57 : translating a pom generated by the spring starter service (http://start.spring.io/starter.zip?name=demo&groupId=com.example&artifactId=demo&version=0.0.1-SNAPSHOT&description=Demo+project+for+Spring+Boot&packageName=com.example&type=maven-project&packaging=jar&javaVersion=1.8&language=java&bootVersion=1.3.0.RELEASE) to groovy results in an invalid pom.groovy.

The culprit is the empty relativePath node in the parent section. Simplest pom to reproduce the issue:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>io.maven.polyglot.test</groupId>
    <artifactId>app</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
</project>

Having an empty relativePath seems dubious to me in the 1st place. Maybe some kind of optimization? (@martinlippert any idea?)

Still, ideally, the translator should be able to produce valid groovy.

This problem was originally reported by @dsayer in https://github.com/jbosstools/m2e-polyglot-poc/issues/3

jdillon commented 8 years ago

what invalid groovy does this generate? if its similar to https://github.com/takari/polyglot-maven/issues/57 i'm wondering if the change for that also fixes this, or if there is another change needed?

fbricon commented 8 years ago

Sorry I forgot to paste it:

  parent {
    groupId 'org.springframework.boot'
    artifactId 'spring-boot-starter-parent'
    version '1.3.0.RELEASE'
    relativePath
  }
  No such property: relativePath for class: org.sonatype.maven.polyglot.groovy.builder.ModelBuilder$1

This is using polyglot-groovy 0.1.14

jdillon commented 8 years ago

If that is the case, then a fix for this could already be in place:

https://github.com/takari/polyglot-maven/commit/13509ccd8d6a00954f5454e7d90933d0dd9f18a7

Could you try with a build of the latest changes? I'm not sure what the release strategy is, nor if there is automation to deploy updated SNAPSHOT builds of this stuff ATM.

martinlippert commented 8 years ago

@fbricon I am not aware of any optimization here (at least not in STS), but it looks like this is already generated in that way by the spring starter (no STS involved at all in that case). I could ask Dave, he might know why the starter project produces it that way.

jdillon commented 8 years ago

@fbricon @martinlippert IIRC empty parent is used when ../pom.xml exists and is not the actual parent of the pom.