Appengine Maven Plugin - Endpoints Goal - Enable filtering on .discovery files

498 Views Asked by At

Following this guide, I implemented the Google Cloud Endpoints in my Maven project

Here is the properties of my pom.xml

<properties>
    <appengine.app.id>xxxxxxxx</appengine.app.id>
</properties>

Here is my maven-war-plugin configuration in pom.xml

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>

        <!-- http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html -->
        <!-- To prevent corrupting your binary files when filtering is enabled, you can configure a list of file extensions that will not be filtered. -->
        <nonFilteredFileExtensions>
            <nonFilteredFileExtension>p12</nonFilteredFileExtension>
        </nonFilteredFileExtensions>

        <archiveClasses>true</archiveClasses>

        <!-- https://cloud.google.com/appengine/docs/java/tools/maven#cloud_endpoints_goals -->
        <webXml>${project.build.directory}/generated-sources/appengine-endpoints/WEB-INF/web.xml</webXml>

        <webResources>

            <!-- in order to interpolate version from pom into appengine-web.xml -->
            <resource>
                <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                <filtering>true</filtering>
                <targetPath>WEB-INF</targetPath>
            </resource>

            <resource>
                <directory>${project.build.directory}/generated-sources/appengine-endpoints</directory>
                <includes>
                    <include>WEB-INF/*.discovery</include>
                    <include>WEB-INF/*.api</include>
                </includes>
            </resource>

        </webResources>

    </configuration>
</plugin>

Here is the head of my appengine-web.xml file

<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">

    <application>${appengine.app.id}</application>
    <version>${project.version}</version>
    ....
</appengine-web-app>

Here is the generated data

enter image description here

The problem the .discovery files does not resolve the maven property during their creation

mystore-v1-rest.discovery

"protocol": "rest",
"baseUrl": "https://${appengine.app.id}.appspot.com/_ah/api/mystore/v1/",
"basePath": "/_ah/api/mystore/v1/",
"rootUrl": "https://${appengine.app.id}.appspot.com/_ah/api/",
"servicePath": "mystore/v1/",

mystore-v1-rpc.discovery

protocol": "rpc",
"rootUrl": "https://${appengine.app.id}.appspot.com/_ah/api/",
"rpcUrl": "https://${appengine.app.id}.appspot.com/_ah/api/rpc",
"rpcPath": "/_ah/api/rpc",

Why this files are not filtered like any other file saved in the WEB-INF folder?

I use the Maven variables in many files (under the WEB-INF parent folder) and the values are replaced w/o problems.

How can i adjust my configuration to allow the filtering also on the .discovery files?

I think that (during the lib generation) the application value from the appengine-web.xml is taken without resolving the value and, during the Maven build, the filtering is not applied.

I already tried to add <filtering>true</filtering> to the resource configuration, w/o success

--- EDIT 25/01/2014 ---

After some received suggestions, I need to clarify a thing that I forgot to write in the original post.

The problem is related to the endpoints_get_discovery_doc

Here is the log of the Maven Goal

API Discovery Document written to ..\target\generated-sources\appengine-endpoints\WEB-INF/mystore-v3-rpc.discovery
API Discovery Document written to ..\target\generated-sources\appengine-endpoints\WEB-INF/mystore-androidtest-rpc.discovery

The file \target\generated-sources\appengine-endpoints\WEB-INF/mystore-v3-rpc.discovery is generated by the endpoints goal and it is not filtered.

Even with the filtering property

<resource>
    <directory>${project.build.directory}/generated-sources/appengine-endpoints</directory>
    <filtering>true</filtering>
    <includes>
        <include>WEB-INF/*.discovery</include>
        <include>WEB-INF/*.api</include>
    </includes>
</resource>

The generated files are not filtered.

Maybe the problem is that if the files are directly written in the ${project.build.directory}/generated-sources/appengine-endpoints folder, the files are not filtered?

2

There are 2 best solutions below

0
On
<!--User the below Line, I also had the same problem that I solved using Note: <version>${app.version}</version><appId>${app.id}</appId> folow as per your configuration --!>                                
    <plugin>
    <groupId>com.google.appengine</groupId>
            <artifactId>appengine-maven-plugin</artifactId>
            <version>${appengine.version}</version>
            <configuration>
                <enableJarClasses>false</enableJarClasses>
                <version>${app.version}</version>
                <appId>${app.id}</appId>
                <!-- Comment in the below snippet to bind to all IPs instead of just localhost -->
                <address>0.0.0.0</address>
                <port>8080</port>
                <!-- Comment in the below snippet to enable local debugging with a remote debugger
                     like those included with Eclipse or IntelliJ -->
                <jvmFlags>
                  <jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag>
                </jvmFlags>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>endpoints_get_discovery_doc</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
0
On
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <webXml>${project.build.directory}/generated-sources/appengine-endpoints/WEB-INF/web.xml</webXml>
                <webResources>
                    <!-- in order to interpolate version from pom into appengine-web.xml -->
                    <resource>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF</targetPath>
                    </resource>
                    <resource>
                        <!-- this is relative to the pom.xml directory -->
                        <directory>${project.build.directory}/generated-sources/appengine-endpoints</directory>
                        <!-- the list has a default value of ** -->
                        <includes>
                            <include>WEB-INF/*.discovery</include>
                            <include>WEB-INF/*.api</include>
                        </includes>
                        <filtering>true</filtering>
                    </resource>
                </webResources>
            </configuration>
        </plugin>