Groovy web console

subscribe to the feed Subscribe
to this
site
test xml (via #groovywebconsole)
tweet this snippet Tweet
this
script

test xml

Published 4 months ago by Morgan Wattiez
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.xml.*

def getProjectVersion() {
def pom = '''<?xml version="1.0" encoding="UTF-8"?>
<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>

  <groupId>be.isabel.intellisign</groupId>
  <artifactId>intellisign-connective-module</artifactId>
  <version>0.1.0-SNAPSHOT</version>
  <name>Intellisign connective signing module</name>
  <description>Intellisign connective signing module</description>
  <packaging>war</packaging>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
  </parent>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

    <maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>

    <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>

    <postgresql.version>42.2.0</postgresql.version>
    <h2.version>1.4.196</h2.version>
    <httpclient.version>4.5.4</httpclient.version>

    <sonar-maven-plugin.version>3.4.0.905</sonar-maven-plugin.version>

    <jacoco-listeners.version>1.4</jacoco-listeners.version>
    <jacoco.version>0.8.1</jacoco.version>
    <jacoco.outputDir>${project.build.directory}</jacoco.outputDir>
    <jacoco.out.ut.file>jacoco.exec</jacoco.out.ut.file>
    <sonar.jacoco.utReportPath>${jacoco.outputDir}/${jacoco.out.ut.file}</sonar.jacoco.utReportPath>
    <maven-surefire-plugin.version>2.20.1</maven-surefire-plugin.version>

    <sonar.junit.reportPaths>${project.build.directory}/surefire-reports</sonar.junit.reportPaths>
    <sonar.jacoco.reportPath>${project.build.directory}/jacoco.exec</sonar.jacoco.reportPath>

    <swagger-maven-plugin-version>3.1.6</swagger-maven-plugin-version>
    <swagger.version>1.5.18</swagger.version>
  </properties>

  <dependencies>
    <!-- Spring Boot -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- Persistence -->
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>${postgresql.version}</version>
    </dependency>
    <!-- In memory DB for testing -->
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <version>${h2.version}</version>
      <scope>test</scope>
    </dependency>

    <!-- Apache HttpComponents library -->
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>${httpclient.version}</version>
    </dependency>

    <!-- Jacoco -->
    <dependency>
      <groupId>org.codehaus.sonar-plugins.java</groupId>
      <artifactId>sonar-jacoco-listeners</artifactId>
      <version>${jacoco-listeners.version}</version>
      <scope>test</scope>
    </dependency>

    <!-- Swagger -->
    <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-annotations</artifactId>
      <version>${swagger.version}</version>
      <scope>compile</scope>
    </dependency>

  </dependencies>

  <build>
    <pluginManagement>
      <!-- SonarQube integration -->
      <plugins>
        <plugin>
          <groupId>org.sonarsource.scanner.maven</groupId>
          <artifactId>sonar-maven-plugin</artifactId>
          <version>${sonar-maven-plugin.version}</version>
        </plugin>
        <!-- Fortify -->
        <plugin>
          <groupId>com.fortify.ps.maven.plugin</groupId>
          <artifactId>sca-maven-plugin</artifactId>
          <version>RELEASE</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <!-- Spring Boot -->
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <executable>true</executable>
        </configuration>
      </plugin>
      <!-- Automatic code formatting according to Google format-->
      <plugin>
        <groupId>com.coveo</groupId>
        <artifactId>fmt-maven-plugin</artifactId>
        <version>2.1.0</version>
        <executions>
          <execution>
            <goals>
              <goal>format</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <!-- Linting of code -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${maven-compiler-plugin.version}</version>
        <configuration>
          <compilerArgs>
            <arg>-Xlint:all,-options,-path</arg>
          </compilerArgs>
        </configuration>
      </plugin>
      <!-- Swagger -->
      <plugin>
        <groupId>com.github.kongchen</groupId>
        <artifactId>swagger-maven-plugin</artifactId>
        <version>${swagger-maven-plugin-version}</version>
        <configuration>
          <apiSources>
            <apiSource>
              <springmvc>true</springmvc>
              <locations>
                <location>be.isabel.intellisign.connective</location>
              </locations>
              <schemes>
                <scheme>https</scheme>
              </schemes>
              <basePath>/sign/connective</basePath>
              <info>
                <title>connective signing module</title>
                <version>${project.version}</version>
                <description>
                  This api allows for using connective for signing in Intellisign
                </description>
              </info>
              <outputFormats>json,yaml</outputFormats>
              <swaggerDirectory>target/swagger</swaggerDirectory>
              <swaggerFileName>connective-module</swaggerFileName>
            </apiSource>
          </apiSources>
        </configuration>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <excludes>
          <exclude>*</exclude>
        </excludes>
      </resource>
    </resources>
  </build>

  <!-- Push to nexus -->
  <distributionManagement>
    <repository>
      <id>nexus-isabel</id>
      <name>Nexus Isabel repository</name>
      <layout>default</layout>
      <uniqueVersion>false</uniqueVersion>
      <url>http://nexus.isabelteam.be/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
      <id>nexus-isabel-snapshots</id>
      <name>Nexus Isabel Snapshot Repository</name>
      <layout>default</layout>
      <uniqueVersion>false</uniqueVersion>
      <url>http://nexus.isabelteam.be/content/repositories/snapshots</url>
    </snapshotRepository>
  </distributionManagement>

  <!-- Jacoco code coverage of unit tests profile-->
  <profiles>
    <profile>
      <id>jacoco</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>${jacoco.version}</version>
            <executions>
              <execution>
                <id>prepare-agent</id>
                <goals>
                  <goal>prepare-agent</goal>
                </goals>
                <configuration>
                  <destFile>${sonar.jacoco.utReportPath}</destFile>
                  <propertyName>jacoco.agent.ut.arg</propertyName>
                  <append>true</append>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven-surefire-plugin.version}</version>
            <configuration>
              <argLine>-Xmx1024m ${jacoco.agent.ut.arg}</argLine>
              <!-- Specific to generate mapping between tests and covered code -->
              <properties>
                <property>
                  <name>listener</name>
                  <value>org.sonar.java.jacoco.JUnitListener</value>
                </property>
              </properties>
              <reportsDirectory>${sonar.junit.reportPaths}</reportsDirectory>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>develop</id>
      <build>
        <resources>
          <resource>
            <directory>src/main/resources</directory>
            <includes>
              <include>*</include>
            </includes>
          </resource>
        </resources>
      </build>
    </profile>
  </profiles>
</project>
'''

      def project = new XmlSlurper().parseText(pom)
      def version = project.version.text()
      return version.replace("-SNAPSHOT", "").trim()
    }

getProjectVersion()