Check values and Increment decimal value of a xml file





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I have a shell script to increment pom file version by one. But every time I have to change the script to increment the version (major.minor.patch). Now I want to write a script to increment it automatically. As a example if patch version equals to 0.0.10 automatically increment minor and set minor version as 0.1.0



#!/bin/bash
get_version()
{
# Get the package version from pom.xml
group_id=$(grep -ri "<groupId>" pom.xml |head -n 1 | sed -e 's/^[ t]*<groupId>([^<]*)<.*$/1/')
artifact_id=$(grep -ri "<artifactId>" pom.xml |head -n 1 | sed -e 's/^[ t]*<artifactId>([^<]*)<.*$/1/')
artifact_version=$(grep -ri "<version>" pom.xml |head -n 1 | sed -e 's/^[ t]*<version>([^<]*)<.*$/1/' | sed 's/[-SNAPSHOT]//g')
echo Group ID: ${group_id}
echo Package Name: ${artifact_id}
echo Package Version: ${artifact_version}
}

version_split()
{
version=$(grep -ri "<version>" pom.xml |head -n 1 | sed -e 's/^[ t]*<version>([^<]*)<.*$/1/')
major_version=$(echo $version| cut -c1)
minor_version=$(echo $version| cut -c3)
patch_version=$(echo $version| cut -c3)
}

increment_patch_version()
{
patch_version=$((patch_version+ 1))
}

update_build_version()
{
updated_version=${major_version}.${minor_version}.${patch_version}
echo Updated Build Version: ${updated_version}
}

update_version_file()
{
LN=$(grep -n "<version>" pom.xml | head -1 | awk -F ":" '{print $1}')
LN=$(sed -i "$LN s/$artifact_version/$updated_version/" pom.xml)
updated_newversion=$(grep -ri "<version>" pom.xml |head -n 1 | sed -e 's/^[ t]*<version>([^<]*)<.*$/1/')
echo POM UPDATED AS: ${updated_newversion}
}

get_version
version_split
increment_patch_version
update_build_version
update_version_file


Can I do this using if condition?



I wrote an if condition to check PATCH_VERSION and update. But cannot do by using it.



increment_patch_version()
{
NUM="*.*.10"
CHECK="$major_version.$minor_version.$patch_version"
if [[ $CHECK < $NUM || bc ]]; then
patch_version=$((patch_version+ 1))
echo $patch_version
fi
}


Is there a way to apply this to all version updates? My pom.xml file looks like this.



<?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>test24x7</groupId>
<artifactId>ab-backend</artifactId>
<version>0.0.2</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>com.test24x7.innovation.quickcheckout.main.QuickCheckoutBackendMain</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/out</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!--Clean out folder-->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>out</directory>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>${basedir}</directory>
<includes>
<include>**/ABBBackend-tcp*/</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<!--Copy folder to out-->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/out/abresources</outputDirectory>
<resources>
<resource>
<directory>${basedir}/abresources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-resource-one</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>

<configuration>
<outputDirectory>${basedir}/out/</outputDirectory>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>Runner.bat</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-logback</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>

<configuration>
<outputDirectory>${basedir}/out/</outputDirectory>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>logback.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>version.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>


<dependencies>
<!-- https://mvnrepository.com/artifact/org.eclipse.paho/org.eclipse.paho.client.mqttv3 -->
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.sonarsource.scanner.maven/sonar-maven-plugin -->
<dependency>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.5.0.1254</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.scream3r/jssc -->
<dependency>
<groupId>org.scream3r</groupId>
<artifactId>jssc</artifactId>
<version>2.8.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.4.2</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>


</dependencies>

<properties>
<jdk.version>1.8</jdk.version>
</properties>

</project>









share|improve this question




















  • 3





    We can't really help you parse data you don't show. Since we have no idea what's in those variables, we can't understand what your commands are supposed to be doing. The if condition you have in the end makes no sense, but I don't know what you want it to be doing. Please edit your question and clarify what you are processing. Also, as a general rule, avoid using ALLCAPS variable names in shell scripts since by convention, environment variables are in caps and this can lead to unintended name overlaps and bugs.

    – terdon
    Feb 25 at 11:28


















1















I have a shell script to increment pom file version by one. But every time I have to change the script to increment the version (major.minor.patch). Now I want to write a script to increment it automatically. As a example if patch version equals to 0.0.10 automatically increment minor and set minor version as 0.1.0



#!/bin/bash
get_version()
{
# Get the package version from pom.xml
group_id=$(grep -ri "<groupId>" pom.xml |head -n 1 | sed -e 's/^[ t]*<groupId>([^<]*)<.*$/1/')
artifact_id=$(grep -ri "<artifactId>" pom.xml |head -n 1 | sed -e 's/^[ t]*<artifactId>([^<]*)<.*$/1/')
artifact_version=$(grep -ri "<version>" pom.xml |head -n 1 | sed -e 's/^[ t]*<version>([^<]*)<.*$/1/' | sed 's/[-SNAPSHOT]//g')
echo Group ID: ${group_id}
echo Package Name: ${artifact_id}
echo Package Version: ${artifact_version}
}

version_split()
{
version=$(grep -ri "<version>" pom.xml |head -n 1 | sed -e 's/^[ t]*<version>([^<]*)<.*$/1/')
major_version=$(echo $version| cut -c1)
minor_version=$(echo $version| cut -c3)
patch_version=$(echo $version| cut -c3)
}

increment_patch_version()
{
patch_version=$((patch_version+ 1))
}

update_build_version()
{
updated_version=${major_version}.${minor_version}.${patch_version}
echo Updated Build Version: ${updated_version}
}

update_version_file()
{
LN=$(grep -n "<version>" pom.xml | head -1 | awk -F ":" '{print $1}')
LN=$(sed -i "$LN s/$artifact_version/$updated_version/" pom.xml)
updated_newversion=$(grep -ri "<version>" pom.xml |head -n 1 | sed -e 's/^[ t]*<version>([^<]*)<.*$/1/')
echo POM UPDATED AS: ${updated_newversion}
}

get_version
version_split
increment_patch_version
update_build_version
update_version_file


Can I do this using if condition?



I wrote an if condition to check PATCH_VERSION and update. But cannot do by using it.



increment_patch_version()
{
NUM="*.*.10"
CHECK="$major_version.$minor_version.$patch_version"
if [[ $CHECK < $NUM || bc ]]; then
patch_version=$((patch_version+ 1))
echo $patch_version
fi
}


Is there a way to apply this to all version updates? My pom.xml file looks like this.



<?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>test24x7</groupId>
<artifactId>ab-backend</artifactId>
<version>0.0.2</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>com.test24x7.innovation.quickcheckout.main.QuickCheckoutBackendMain</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/out</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!--Clean out folder-->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>out</directory>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>${basedir}</directory>
<includes>
<include>**/ABBBackend-tcp*/</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<!--Copy folder to out-->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/out/abresources</outputDirectory>
<resources>
<resource>
<directory>${basedir}/abresources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-resource-one</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>

<configuration>
<outputDirectory>${basedir}/out/</outputDirectory>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>Runner.bat</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-logback</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>

<configuration>
<outputDirectory>${basedir}/out/</outputDirectory>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>logback.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>version.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>


<dependencies>
<!-- https://mvnrepository.com/artifact/org.eclipse.paho/org.eclipse.paho.client.mqttv3 -->
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.sonarsource.scanner.maven/sonar-maven-plugin -->
<dependency>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.5.0.1254</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.scream3r/jssc -->
<dependency>
<groupId>org.scream3r</groupId>
<artifactId>jssc</artifactId>
<version>2.8.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.4.2</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>


</dependencies>

<properties>
<jdk.version>1.8</jdk.version>
</properties>

</project>









share|improve this question




















  • 3





    We can't really help you parse data you don't show. Since we have no idea what's in those variables, we can't understand what your commands are supposed to be doing. The if condition you have in the end makes no sense, but I don't know what you want it to be doing. Please edit your question and clarify what you are processing. Also, as a general rule, avoid using ALLCAPS variable names in shell scripts since by convention, environment variables are in caps and this can lead to unintended name overlaps and bugs.

    – terdon
    Feb 25 at 11:28














1












1








1








I have a shell script to increment pom file version by one. But every time I have to change the script to increment the version (major.minor.patch). Now I want to write a script to increment it automatically. As a example if patch version equals to 0.0.10 automatically increment minor and set minor version as 0.1.0



#!/bin/bash
get_version()
{
# Get the package version from pom.xml
group_id=$(grep -ri "<groupId>" pom.xml |head -n 1 | sed -e 's/^[ t]*<groupId>([^<]*)<.*$/1/')
artifact_id=$(grep -ri "<artifactId>" pom.xml |head -n 1 | sed -e 's/^[ t]*<artifactId>([^<]*)<.*$/1/')
artifact_version=$(grep -ri "<version>" pom.xml |head -n 1 | sed -e 's/^[ t]*<version>([^<]*)<.*$/1/' | sed 's/[-SNAPSHOT]//g')
echo Group ID: ${group_id}
echo Package Name: ${artifact_id}
echo Package Version: ${artifact_version}
}

version_split()
{
version=$(grep -ri "<version>" pom.xml |head -n 1 | sed -e 's/^[ t]*<version>([^<]*)<.*$/1/')
major_version=$(echo $version| cut -c1)
minor_version=$(echo $version| cut -c3)
patch_version=$(echo $version| cut -c3)
}

increment_patch_version()
{
patch_version=$((patch_version+ 1))
}

update_build_version()
{
updated_version=${major_version}.${minor_version}.${patch_version}
echo Updated Build Version: ${updated_version}
}

update_version_file()
{
LN=$(grep -n "<version>" pom.xml | head -1 | awk -F ":" '{print $1}')
LN=$(sed -i "$LN s/$artifact_version/$updated_version/" pom.xml)
updated_newversion=$(grep -ri "<version>" pom.xml |head -n 1 | sed -e 's/^[ t]*<version>([^<]*)<.*$/1/')
echo POM UPDATED AS: ${updated_newversion}
}

get_version
version_split
increment_patch_version
update_build_version
update_version_file


Can I do this using if condition?



I wrote an if condition to check PATCH_VERSION and update. But cannot do by using it.



increment_patch_version()
{
NUM="*.*.10"
CHECK="$major_version.$minor_version.$patch_version"
if [[ $CHECK < $NUM || bc ]]; then
patch_version=$((patch_version+ 1))
echo $patch_version
fi
}


Is there a way to apply this to all version updates? My pom.xml file looks like this.



<?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>test24x7</groupId>
<artifactId>ab-backend</artifactId>
<version>0.0.2</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>com.test24x7.innovation.quickcheckout.main.QuickCheckoutBackendMain</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/out</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!--Clean out folder-->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>out</directory>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>${basedir}</directory>
<includes>
<include>**/ABBBackend-tcp*/</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<!--Copy folder to out-->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/out/abresources</outputDirectory>
<resources>
<resource>
<directory>${basedir}/abresources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-resource-one</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>

<configuration>
<outputDirectory>${basedir}/out/</outputDirectory>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>Runner.bat</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-logback</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>

<configuration>
<outputDirectory>${basedir}/out/</outputDirectory>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>logback.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>version.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>


<dependencies>
<!-- https://mvnrepository.com/artifact/org.eclipse.paho/org.eclipse.paho.client.mqttv3 -->
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.sonarsource.scanner.maven/sonar-maven-plugin -->
<dependency>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.5.0.1254</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.scream3r/jssc -->
<dependency>
<groupId>org.scream3r</groupId>
<artifactId>jssc</artifactId>
<version>2.8.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.4.2</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>


</dependencies>

<properties>
<jdk.version>1.8</jdk.version>
</properties>

</project>









share|improve this question
















I have a shell script to increment pom file version by one. But every time I have to change the script to increment the version (major.minor.patch). Now I want to write a script to increment it automatically. As a example if patch version equals to 0.0.10 automatically increment minor and set minor version as 0.1.0



#!/bin/bash
get_version()
{
# Get the package version from pom.xml
group_id=$(grep -ri "<groupId>" pom.xml |head -n 1 | sed -e 's/^[ t]*<groupId>([^<]*)<.*$/1/')
artifact_id=$(grep -ri "<artifactId>" pom.xml |head -n 1 | sed -e 's/^[ t]*<artifactId>([^<]*)<.*$/1/')
artifact_version=$(grep -ri "<version>" pom.xml |head -n 1 | sed -e 's/^[ t]*<version>([^<]*)<.*$/1/' | sed 's/[-SNAPSHOT]//g')
echo Group ID: ${group_id}
echo Package Name: ${artifact_id}
echo Package Version: ${artifact_version}
}

version_split()
{
version=$(grep -ri "<version>" pom.xml |head -n 1 | sed -e 's/^[ t]*<version>([^<]*)<.*$/1/')
major_version=$(echo $version| cut -c1)
minor_version=$(echo $version| cut -c3)
patch_version=$(echo $version| cut -c3)
}

increment_patch_version()
{
patch_version=$((patch_version+ 1))
}

update_build_version()
{
updated_version=${major_version}.${minor_version}.${patch_version}
echo Updated Build Version: ${updated_version}
}

update_version_file()
{
LN=$(grep -n "<version>" pom.xml | head -1 | awk -F ":" '{print $1}')
LN=$(sed -i "$LN s/$artifact_version/$updated_version/" pom.xml)
updated_newversion=$(grep -ri "<version>" pom.xml |head -n 1 | sed -e 's/^[ t]*<version>([^<]*)<.*$/1/')
echo POM UPDATED AS: ${updated_newversion}
}

get_version
version_split
increment_patch_version
update_build_version
update_version_file


Can I do this using if condition?



I wrote an if condition to check PATCH_VERSION and update. But cannot do by using it.



increment_patch_version()
{
NUM="*.*.10"
CHECK="$major_version.$minor_version.$patch_version"
if [[ $CHECK < $NUM || bc ]]; then
patch_version=$((patch_version+ 1))
echo $patch_version
fi
}


Is there a way to apply this to all version updates? My pom.xml file looks like this.



<?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>test24x7</groupId>
<artifactId>ab-backend</artifactId>
<version>0.0.2</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>com.test24x7.innovation.quickcheckout.main.QuickCheckoutBackendMain</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/out</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!--Clean out folder-->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>out</directory>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>${basedir}</directory>
<includes>
<include>**/ABBBackend-tcp*/</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<!--Copy folder to out-->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/out/abresources</outputDirectory>
<resources>
<resource>
<directory>${basedir}/abresources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-resource-one</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>

<configuration>
<outputDirectory>${basedir}/out/</outputDirectory>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>Runner.bat</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-logback</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>

<configuration>
<outputDirectory>${basedir}/out/</outputDirectory>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>logback.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>version.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>


<dependencies>
<!-- https://mvnrepository.com/artifact/org.eclipse.paho/org.eclipse.paho.client.mqttv3 -->
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.sonarsource.scanner.maven/sonar-maven-plugin -->
<dependency>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.5.0.1254</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.scream3r/jssc -->
<dependency>
<groupId>org.scream3r</groupId>
<artifactId>jssc</artifactId>
<version>2.8.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.4.2</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>


</dependencies>

<properties>
<jdk.version>1.8</jdk.version>
</properties>

</project>






bash scripts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 26 at 2:51







Janith

















asked Feb 25 at 8:42









JanithJanith

798




798








  • 3





    We can't really help you parse data you don't show. Since we have no idea what's in those variables, we can't understand what your commands are supposed to be doing. The if condition you have in the end makes no sense, but I don't know what you want it to be doing. Please edit your question and clarify what you are processing. Also, as a general rule, avoid using ALLCAPS variable names in shell scripts since by convention, environment variables are in caps and this can lead to unintended name overlaps and bugs.

    – terdon
    Feb 25 at 11:28














  • 3





    We can't really help you parse data you don't show. Since we have no idea what's in those variables, we can't understand what your commands are supposed to be doing. The if condition you have in the end makes no sense, but I don't know what you want it to be doing. Please edit your question and clarify what you are processing. Also, as a general rule, avoid using ALLCAPS variable names in shell scripts since by convention, environment variables are in caps and this can lead to unintended name overlaps and bugs.

    – terdon
    Feb 25 at 11:28








3




3





We can't really help you parse data you don't show. Since we have no idea what's in those variables, we can't understand what your commands are supposed to be doing. The if condition you have in the end makes no sense, but I don't know what you want it to be doing. Please edit your question and clarify what you are processing. Also, as a general rule, avoid using ALLCAPS variable names in shell scripts since by convention, environment variables are in caps and this can lead to unintended name overlaps and bugs.

– terdon
Feb 25 at 11:28





We can't really help you parse data you don't show. Since we have no idea what's in those variables, we can't understand what your commands are supposed to be doing. The if condition you have in the end makes no sense, but I don't know what you want it to be doing. Please edit your question and clarify what you are processing. Also, as a general rule, avoid using ALLCAPS variable names in shell scripts since by convention, environment variables are in caps and this can lead to unintended name overlaps and bugs.

– terdon
Feb 25 at 11:28










0






active

oldest

votes












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1121040%2fcheck-values-and-increment-decimal-value-of-a-xml-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1121040%2fcheck-values-and-increment-decimal-value-of-a-xml-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?