(→Perforce: Read File From Depot Without Syncing and Parse Using Regex)
|
(→AHPSCRIPTS-82)
|
Line 113: | |||
==== AHPSCRIPTS-82 ==== | ==== AHPSCRIPTS-82 ==== | ||
<pre>${bsh:changes=ChangeSetHelper.getChangeSetArray(); if (changes != null && changes.length > 0) { return changes[0].getChangeId(); \} else { return "no revision"; \}}</pre> | <pre>${bsh:changes=ChangeSetHelper.getChangeSetArray(); if (changes != null && changes.length > 0) { return changes[0].getChangeId(); \} else { return "no revision"; \}}</pre> | ||
+ | = Incrementing Stamp Script Allowing For Manual Input = | ||
+ | *This script depends on a workflow property called "inputversion" where a user can specify a stamp at the time a build is being started. If inputversion is left blank, it uses the project property "my-stamp-property" as the stamp, and increments it. If "inputversion" is not null, and a value is passed, that value is used as the stamp, and becomes the new value of the "my-stamp-property" . | ||
+ | ==== AHPSCRIPTS-32 ==== | ||
+ | <pre>import com.urbancode.anthill3.persistence.UnitOfWork; | ||
+ | import com.urbancode.anthill3.runtime.scripting.helpers.*; | ||
+ | final int PREFIX = 1; | ||
+ | final int DIGIT = 2; | ||
+ | final int POSTFIX = 3; | ||
+ | |||
+ | UnitOfWork uow = UnitOfWork.getCurrent(); | ||
+ | String input = PropertyLookup.getValue("inputversion"); | ||
+ | String inc = PropertyLookup.getValue("my-stamp-property"); | ||
+ | static final private org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("ReportScript"); | ||
+ | |||
+ | public String incrementVersion(String versionStr) | ||
+ | throws Exception { | ||
+ | // incrementing only the version number | ||
+ | char c; | ||
+ | StringBuffer prefix = new StringBuffer(); | ||
+ | StringBuffer digits = new StringBuffer(); | ||
+ | StringBuffer postfix = new StringBuffer(); | ||
+ | log.warn("im in the method"); | ||
+ | int state = POSTFIX; | ||
+ | log.warn("im in the method2 "+versionStr.length()); | ||
+ | for (int i = versionStr.length() - 1; i >= 0; i--) { | ||
+ | log.warn("im in the method3"); | ||
+ | c = versionStr.charAt(i); | ||
+ | if (!Character.isDigit(c)) { | ||
+ | log.warn("im in the method4"); | ||
+ | if (state == POSTFIX) { | ||
+ | log.warn("im in the method5"); | ||
+ | postfix.insert(0, c); | ||
+ | } | ||
+ | else { | ||
+ | if (state == DIGIT) { | ||
+ | log.warn("im in the method6"); | ||
+ | state = PREFIX; | ||
+ | } | ||
+ | prefix.insert(0, c); | ||
+ | log.warn("im in the method7"); | ||
+ | } | ||
+ | } | ||
+ | else { | ||
+ | if (state == POSTFIX || state == DIGIT) { | ||
+ | log.warn("im in the method8"); | ||
+ | state = DIGIT; | ||
+ | digits.insert(0, c); | ||
+ | } | ||
+ | else { | ||
+ | log.warn("im in the method9"); | ||
+ | prefix.insert(0, c); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | log.warn("im in the method10"); | ||
+ | int version = 0; | ||
+ | try { | ||
+ | version = Integer.parseInt(digits.toString()); | ||
+ | log.warn("im in the method11"); | ||
+ | } | ||
+ | catch (NumberFormatException nfe) { | ||
+ | throw new Exception("Version String illegal. " + | ||
+ | "Can't parse version number. " + | ||
+ | "versionStr: " + versionStr); | ||
+ | } | ||
+ | version++; | ||
+ | log.warn("im in the method12"); | ||
+ | return prefix.toString() + String.valueOf(version) + postfix.toString(); | ||
+ | log.warn("im in the method13"); | ||
+ | }//end method | ||
+ | log.warn("inputversion :" + input); | ||
+ | log.warn("####"+ProjectLookup.getCurrent().getProperty("my-stamp-property")); | ||
+ | log.warn("mystampprop :" + inc); | ||
+ | String stampValue = null; | ||
+ | if(input == null || input.length() == 0){ | ||
+ | stampValue = incrementVersion(inc); | ||
+ | }else{ | ||
+ | stampValue = input; | ||
+ | } | ||
+ | ProjectLookup.getCurrent().getProperty("my-stamp-property").setValue(stampValue); | ||
+ | uow.commit(); | ||
+ | stampContext.put("stampValue", ""+stampValue );</pre> |