lgrignon / jsweet-maven-plugin

JSweet maven plugin providing build and clean operations of JSweet sources
Apache License 2.0
18 stars 20 forks source link

Configure path to jsweetconfig.json and jsweet_extension #38

Closed ADegele closed 6 years ago

ADegele commented 6 years ago

We are changing our maven build to a multi-module build. Assume a directory layout like this:

project
    module1
        pom.xml (with jsweet plugin)
        jsweetconfig.json
        jsweet_extension
    module2

Our old build script changes the working directory to each module and calls maven inside:

cd module1;
maven install;
cd ../module2;
maven install;
[...]

Now we would just run maven install on our root pom. This change means that the working directory is now project instead of project/module1. Because of that, the jsweet plugin does not find the jsweetconfig.json or the jsweet_extension folder.

As a quick fix, I'm going to pull these two up one level, which means I cannot run a cd module1; maven install; all by itself. The best way to fix it would be to add a parameter to the plugin configuration to specify these two paths with something like ${project.basedir}/jsweetconfig.json. Any thoughts on this? Can you add these parameters for the next release, please?

ADegele commented 6 years ago

Most paths resolve relative to the working dir (tsout, jsout, workingDir,...). Would it make sense to resolve all of them against project.basedir?

lgrignon commented 6 years ago

That was fixed in this one I think, isn't it? https://github.com/lgrignon/jsweet-maven-plugin/issues/37

What version of the plugin are you using?

ADegele commented 6 years ago

I'm sorry, I didn't find the issue you referenced. We were running on Version 2.0.0 of the plugin. I updated to 2.0.1-SNAPSHOT and all paths are resolved relative to the module pom now. However, the paths to jsweetconfig.json or jsweet_extension are still not configurable, right? It is not a problem right now, but it would be a nice to have. Nevertheless, I'm closing the issue. Thank you for your help!

ADegele commented 6 years ago

The project structure outlined above worked with Version 2.0.1-SNAPSHOT, but does not work anymore with Version 2.0.1 or 2.1.0-SNAPSHOT. When running mvn generate-source on the root project, JSweet generates its output relative to the root project instead of relative to the module1.pom. It also doesn't find jsweetconfig.json nor jsweet_extension

lgrignon commented 6 years ago

I will take a look soon, everything should work as intended in 2.1.0-SNAPSHOT. Could you please post your pom.xml Did you set your <workingDir>${project.basedir}</workingDir>

Thanks for reporting anyway

ADegele commented 6 years ago

No, I did not set the workingDir, but it did not change it. This is the pom right now:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>----common</artifactId>
    <packaging>jar</packaging>
    <name>----common</name>

    <parent>
        <groupId>de.---</groupId>
        <artifactId>----root-pom</artifactId>
        <version>0.0.0-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <properties>
        <jsweet.tsout.path>../online-auftritt/----rest-services/lib/validierung/generated</jsweet.tsout.path>
    </properties>

    <pluginRepositories>
        <pluginRepository>
            <id>jsweet-plugins-release</id>
            <name>plugins-release</name>
            <url>http://repository.jsweet.org/artifactory/plugins-release-local</url>
        </pluginRepository>
        <pluginRepository>
            <snapshots/>
            <id>jsweet-plugins-snapshots</id>
            <name>plugins-snapshot</name>
            <url>http://repository.jsweet.org/artifactory/plugins-snapshot-local</url>
        </pluginRepository>
    </pluginRepositories>
    <repositories>
        <repository>
            <id>jsweet-central</id>
            <name>libs-release</name>
            <url>http://repository.jsweet.org/artifactory/libs-release-local</url>
        </repository>
        <repository>
            <snapshots/>
            <id>jsweet-snapshots</id>
            <name>libs-snapshot</name>
            <url>http://repository.jsweet.org/artifactory/libs-snapshot-local</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.-----.isi</groupId>
            <artifactId>-----isi-common</artifactId>
            <version>${isi.version}</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.jaxb-namespaceprefixmapper-interfaces</groupId>
            <artifactId>JAXBNamespacePrefixMapper</artifactId>
            <version>${jaxb.namespacemapper.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${com.fasterxml.jackson-annotations.version}</version>
        </dependency>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-jersey2-jaxrs</artifactId>
            <version>${io.swagger.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.glassfish.jersey.containers</groupId>
                    <artifactId>jersey-container-servlet-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.jsweet</groupId>
            <artifactId>jsweet-core</artifactId>
            <version>${org.jsweet.core.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jsweet</groupId>
            <artifactId>jsweet-transpiler</artifactId>
            <version>${org.jsweet.transpiler.version}</version>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.jsweet</groupId>
                <artifactId>jsweet-maven-plugin</artifactId>
                <version>${org.jsweet.transpiler.version}</version>
                <configuration>
                    <tsOut>${jsweet.tsout.path}</tsOut>
                    <outDir>target/js</outDir>
                    <candiesJsOut>webapp</candiesJsOut>
                    <noRootDirectories>true</noRootDirectories>
                    <workingDir>${project.basedir}</workingDir>
                    <includes>
                        <!-- TBEs müssen angegeben werde, obwohl sie nicht transpiliert werden, damit JSweet die Typen kennt und richtig umwandeln kann -->
                        <include>**/*TBE.java</include>
                        <include>**/*Enum.java</include>
                        <include>**/*DBE.java</include>
                        <include>**/de/sdk/common/base/validationmodel/**</include>
                        <include>**/de/sdk/common/**/*ValidationModel.java</include>
                    </includes>
                    <excludes>
                        <!-- Diese TBEs verwenden Konstrukte, von denen JSweet nicht weiß, wie es sie transpilieren soll. Da diese TBEs momentan nicht gebraucht werden, werden sie von der transpilierung einfach ausgeschlossen. -->
                        <exclude>**/ErrorsAndWarningsTBE.java</exclude>
                        <exclude>**/SuchErgebnisTBE.java</exclude>
                    </excludes>
                    <tsOnly>true</tsOnly>
                    <encoding>UTF-8</encoding>
                    <targetVersion>ES6</targetVersion>
                    <module>commonjs</module>
                </configuration>
                <executions>
                    <execution>
                        <id>generate-js</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>jsweet</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <configuration>
                    <executable>python</executable>
                    <workingDirectory>${project.basedir}</workingDirectory>
                    <arguments>
                        <argument>../../3-tools/bin/repair-lineending-to-unix.py</argument>
                        <argument>${jsweet.tsout.path}</argument>
                    </arguments>
                </configuration>
                <executions>
                    <execution>
                        <id>repair-lineendings</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. -->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>
                                            org.jsweet
                                        </groupId>
                                        <artifactId>
                                            jsweet-maven-plugin
                                        </artifactId>
                                        <versionRange>
                                            [1.0.0,)
                                        </versionRange>
                                        <goals>
                                            <goal>jsweet</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.codehaus.mojo</groupId>
                                        <artifactId>exec-maven-plugin</artifactId>
                                        <versionRange>[1.6.0,)</versionRange>
                                        <goals>
                                            <goal>exec</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

To mitigate this, our actual pom has the plugins moved to a profile, so it doesn't run Jsweet when building the aggregator pom. Apart from that, both poms are the same.

ADegele commented 6 years ago

I don't know why your email does not show up as a comment here, I'll quote it:

I wasn't sure about it so I created a very simple project https://github.com/lgrignon/jsweet-parent-project It seems to work. Could you please tell me the difference with your project?

I checked out the project and ran mvn clean install in the project root / directory. After that, I have a /target folder directly in the root. I would have expected TS and JS files to be generated to /child/target instead. There is also a /.jsweet working dir, which should have been /child/.jsweet Surprisingly, the /child/target/candies folder is where I expect it to be, although it is empty.

I cannot check if your /child/jsweetconfig.json was respected or not. The log does not state whether jsweet loaded the adapters.

For me, it seems the problem is still there.

lgrignon commented 6 years ago

Hello actually I deleted my comment because I had a problem I didn't notice on my jsweet_extension/*Adapter.java files compilation

For the TypeScript output file you can configure it as well. I will push on the GitHub project an example but please take a look at the child's pom.xml. I specify outDir & candiesJsOut, I just didn't specify ts output. I will do so in order to show you.

lgrignon commented 6 years ago

It is ok now, could you please check the child's pom.xml https://github.com/lgrignon/jsweet-parent-project

Try to mvn clean install again, it will only output in child/target

Nevertheless, you are right, the default directory should output by default in child's directory. Please close this issue if ok for you.

ADegele commented 6 years ago

The problem is not, that I don't know how how to configure the output dirs, the problem is that jsweet resolves the paths differently where you run maven. If I run maven in /, I get the JS and TS files in /target. If I run maven in /child/, I get the JS and TS files in /child/target. Jsweet always resolves paths relative to the current working directory of the console instead of the pom.xml of the project.

lgrignon commented 6 years ago

nope, that works for me. Which version of maven are you running please? This is supposed to work. If I run mvn clean install on the parent project, with the last output configuration, it outputs its files to child/target/... as requested. I doubt this is a Maven version issue but maybe. I use 3.5

ADegele commented 6 years ago

Ok, that is strange. I use Maven 3.5.2 on Windows.

ADegele commented 6 years ago

I just setup a fresh VM with Xubuntu 16.4.3, apt install git maven nodejs nodejs-legacy npm, which outputs to /target as well. Maven Version there is 3.3.9. I also tried with Maven 3.5.0, which behaved the same.

lgrignon commented 6 years ago

Ok, same project (you confirm that you test with the last version of https://github.com/lgrignon/jsweet-parent-project), same version, different behaviors.. I will try to refresh all my dependencies just in case and I get back to you. Thanks again for your help

ADegele commented 6 years ago

Yes, I tested it with your example project.

lgrignon commented 6 years ago

Ok, after a bit of cleaning I now have the same behavior. Well I hope it is only a matter of deployed version on the Maven repository. I will dive deeper into this later this day. Thanks.

lgrignon commented 6 years ago

I confirm this was only a deployment issue. Could you please clean your maven repo (or at least the org/jsweet part) and try again. Thanks!

ADegele commented 6 years ago

Works for me, too.