package de.larmic.butterfaces.component.showcase;

import java.io.Serializable;

/**
 * Contains butterfaces maven pom.xml informations. templating-maven-plugin is used in pom.xml.
 */
@javax.inject.Named
@javax.faces.view.ViewScoped
@SuppressWarnings("serial")
public class Version implements Serializable {

    private static final String ERROR_VERSION = "1.9.0.CR7";

    private static final String VERSION = "${project.version}";
    private static final String GROUPID = "${project.groupId}";
    private static final String ARTIFACTID = "${project.artifactId}";
    private static final String REVISION = "${buildNumber}";
    private static final String JBOSS = "${version.jbossas}";

    public String getVersion() {
        return VERSION;
    }

    public String getLastestReleaseVersion() {
        if (VERSION.endsWith("SNAPSHOT")) {
            final String version = VERSION.replaceAll("-SNAPSHOT", "");
            final String[] splitted = version.split("\\.");
            final Integer minorVersion = getMinorVersion(splitted[splitted.length - 1]);

            if (minorVersion != null) {
                final StringBuilder stringBuilder = new StringBuilder();
                for (int i = 0; i < splitted.length - 1; i++) {
                    stringBuilder.append(splitted[i]);
                    stringBuilder.append(".");
                }
                stringBuilder.append(minorVersion);
            }

            return ERROR_VERSION;
        }

        return VERSION;
    }

    /**
     * @return null if value is not parsable or value is less than 0.
     */
    private Integer getMinorVersion(final String value) {
        try {
            final Integer newMinorVersion = Integer.valueOf(value) - 1;
            return newMinorVersion >= 0 ? newMinorVersion : null;
        } catch (NumberFormatException e) {
            return null;
        }
    }

    public String getGroupId() {
        return GROUPID;
    }

    public String getArtifactId() {
        return ARTIFACTID;
    }

    public String getRevision() {
        return REVISION;
    }

    public String getJBossVersion() {
        return JBOSS;
    }
}
@@ -72,16 +72,73 @@
 lizable;
+%0Aimport java.lang.String;%0Aimport java.lang.StringBuilder;
 %0A%0A/**%0A *
@@ -364,70 +364,8 @@
  %7B%0A%0A
-    private static final String ERROR_VERSION = %221.9.0.CR7%22;%0A%0A
     
@@ -991,17 +991,19 @@
 nal 
-Integer m
+String newM
 inor
@@ -1012,31 +1012,31 @@
 rsion = 
-getMinorVersion
+Integer.valueOf
 (splitte
@@ -1056,61 +1056,22 @@
 ngth
- - 1%5D)
+-1%5D)-1 + %22%22
 ;%0A%0A
-            if (minorVersion != null) %7B%0A    
     
@@ -1147,20 +1147,16 @@
         
-    
 for (int
@@ -1161,18 +1161,14 @@
 nt i
- = 
+=
 0; i
- %3C 
+%3C
 spli
@@ -1178,19 +1178,17 @@
 d.length
- - 
+-
 1; i++) 
@@ -1197,36 +1197,32 @@
                 
- 
-   
 stringBuilder.ap
@@ -1248,36 +1248,32 @@
                 
-    
 stringBuilder.ap
@@ -1295,26 +1295,18 @@
         
-  
-  %7D%0A    
+%7D%0A
         
@@ -1330,17 +1330,20 @@
 .append(
-m
+newM
 inorVers
@@ -1347,30 +1347,16 @@
 ersion);
-%0A            %7D
 %0A%0A      
@@ -1372,439 +1372,68 @@
 urn 
-ERROR_VERSION;%0A        %7D%0A%0A        return VERSION;%0A    %7D%0A%0A    /**%0A     * @return null if value is not parsable or value is less than 0.%0A     */%0A    private Integer getMinorVersion(final String value) %7B%0A        try %7B%0A            final Integer newMinorVersion = Integer.valueOf(value) - 1;%0A            return newMinorVersion %3E= 0 ? newMinorVersion : null;%0A        %7D catch (NumberFormatException e) %7B%0A            return null;%0A        %7D
+stringBuilder.toString();%0A        %7D%0A%0A        return VERSION;
 %0A   

update version