Produced by Araxis Merge on 7/20/2018 12:56:38 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | CTT_Release_8_June_2018.zip\CTT_ISAAC\db-config-builder\src\main\java\gov\vha\isaac\ochre\pombuilder | GitPublish.java | Tue Jul 17 16:27:51 2018 UTC |
| 2 | CTT_Release_8_June_2018.zip\CTT_ISAAC\db-config-builder\src\main\java\gov\vha\isaac\ochre\pombuilder | GitPublish.java | Wed Jul 18 18:55:58 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 4 | 466 |
| Changed | 3 | 8 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | /** | |
| 2 | * Copyrig ht Notice | |
| 3 | * | |
| 4 | * This is a work of the U.S. Government and is no t subject to copyrig ht | |
| 5 | * protect ion in the United St ates. Fore ign copyri ghts may a pply. | |
| 6 | * | |
| 7 | * License d under th e Apache L icense, Ve rsion 2.0 (the "Lice nse"); | |
| 8 | * you may not use t his file e xcept in c ompliance with the L icense. | |
| 9 | * You may obtain a copy of th e License at | |
| 10 | * | |
| 11 | * htt p://www.ap ache.org/l icenses/LI CENSE-2.0 | |
| 12 | * | |
| 13 | * Unless required b y applicab le law or agreed to in writing , software | |
| 14 | * distrib uted under the Licen se is dist ributed on an "AS IS " BASIS, | |
| 15 | * WITHOUT WARRANTIE S OR CONDI TIONS OF A NY KIND, e ither expr ess or imp lied. | |
| 16 | * See the License f or the spe cific lang uage gover ning permi ssions and | |
| 17 | * limitat ions under the Licen se. | |
| 18 | */ | |
| 19 | package go v.vha.isaa c.ochre.po mbuilder; | |
| 20 | ||
| 21 | import jav a.io.File; | |
| 22 | import jav a.io.IOExc eption; | |
| 23 | import jav a.nio.file .Files; | |
| 24 | import jav a.util.Arr ayList; | |
| 25 | import jav a.util.Has hMap; | |
| 26 | import jav a.util.Set ; | |
| 27 | import jav a.util.con current.lo cks.Reentr antLock; | |
| 28 | ||
| 29 | import org .apache.lo gging.log4 j.LogManag er; | |
| 30 | import org .apache.lo gging.log4 j.Logger; | |
| 31 | ||
| 32 | import gov .va.isaac. sync.git.S yncService GIT; | |
| 33 | import gov .va.isaac. sync.git.g itblit.Git BlitUtils; | |
| 34 | import gov .vha.isaac .ochre.api .util.Nume ricUtils; | |
| 35 | ||
| 36 | /** | |
| 37 | * {@link GitPublish } | |
| 38 | * | |
| 39 | * @author <a href=" mailto:dan iel.armbru st.list@gm ail.com">D an Armbrus t</a> | |
| 40 | */ | |
| 41 | public cla ss GitPubl ish | |
| 42 | { | |
| 43 | pr ivate stat ic final L ogger LOG = LogManag er.getLogg er(); | |
| 44 | ||
| 45 | /* * | |
| 46 | * Support l ocking our threads a cross mult iple opera tions (suc h as read tags, push a new tag ) to ensur e that two threads r unning in parallel | |
| 47 | * don't end up in a s tate where they can' t push, du e to a non -fastforwa rd. | |
| 48 | * / | |
| 49 | pr ivate stat ic final H ashMap<Str ing, Reent rantLock> repoLock = new HashM ap<>(); | |
| 50 | ||
| 51 | /* * | |
| 52 | * Take in a URL such as https: // DNS : PORT /git/ or h ttps:// DNS : PORT /git and t urn it int o | |
| 53 | * https:// DNS : PORT /git/r/con tentConfig urations.g it | |
| 54 | * | |
| 55 | * If a ful l repo URL is passed in, such as https:/ / DNS : PORT /git/r/con tentConfig urations.g it, this d oes no pro cessing | |
| 56 | * and retur ns the pas sed in val ue. | |
| 57 | * | |
| 58 | * @param g itblitBase URL a URL like https :// DNS : PORT /git/ | |
| 59 | * @return t he full gi t URL to a contentCo nfiguratio ns reposit ory. | |
| 60 | * @throws I OException | |
| 61 | * / | |
| 62 | pu blic stati c String c onstructCh angesetRep ositoryURL (String gi tblitBaseU RL) throws IOExcepti on | |
| 63 | { | |
| 64 | if ( gitblitBas eURL.match es("(?i)ht tps?:\\/\\ /[a-zA-Z0- 9\\.\\-_]+ :?\\d*\\/[ a-zA-Z0-9\ \-_]+\\/?$ ")) | |
| 65 | { | |
| 66 | return gitblitBa seURL + (g itblitBase URL.endsWi th("/") ? "" : "/") + "r/conte ntConfigur ations.git "; | |
| 67 | } | |
| 68 | else if (gitbl itBaseURL. matches("( ?i)https?: \\/\\/[a-z A-Z0-9\\.\ \-_]+:?\\d *\\/[a-zA- Z0-9\\-_]+ \\/r\\/[a- zA-Z0-9\\- _]+\\.git$ ")) | |
| 69 | { | |
| 70 | return gitblitBa seURL; | |
| 71 | } | |
| 72 | else | |
| 73 | { | |
| 74 | LOG.in fo("Failin g construc tChangeset Repository URL {}", g itblitBase URL); | |
| 75 | throw new IOExce ption("Une xpected gi tblit serv er pattern "); | |
| 76 | } | |
| 77 | } | |
| 78 | ||
| 79 | /* * | |
| 80 | * This rout ine will c heck out t he project from the repository (which sh ould have an empty m aster bran ch) - then locally | |
| 81 | * commit th e changes to master, then tag it - then push the t ag (but no t the chan ges to mas ter) so th e upstream repo only | |
| 82 | * receives the tag. | |
| 83 | * | |
| 84 | * Calls {@l ink #const ructChange setReposit oryURL(Str ing) to ad just the U RL as nece ssary | |
| 85 | * / | |
| 86 | pu blic stati c void pub lish(File folderWith Project, S tring gitR epository, String gi tUserName, char[] gi tPassword, String ta gToCreate) throws Ex ception | |
| 87 | { | |
| 88 | LOG. debug("Pub lishing '{ }' to '{}' using tag '{}'", fo lderWithPr oject.getA bsolutePat h(), gitRe pository, tagToCreat e); | |
| 89 | Stri ng correct edURL = co nstructCha ngesetRepo sitoryURL( gitReposit ory); | |
| 90 | crea teReposito ryIfNecess ary(correc tedURL, gi tUserName, gitPasswo rd); | |
| 91 | Sync ServiceGIT svc = new SyncServi ceGIT(); | |
| 92 | svc. setReadmeF ileContent ("ISAAC Da taprocessi ng Configu ration Sto rage\n==== \nIt is hi ghly recom mended you do not ma nually int eract with this repo sitory."); | |
| 93 | svc. setGitIgno reContent( ""); | |
| 94 | bool ean ignore Exists = n ew File(fo lderWithPr oject, ".g itignore") .exists(); | |
| 95 | bool ean readme Exists = n ew File(fo lderWithPr oject, "RE ADME.md"). exists(); | |
| 96 | svc. setRootLoc ation(fold erWithProj ect); | |
| 97 | svc. linkAndFet chFromRemo te(correct edURL, git UserName, gitPasswor d); | |
| 98 | svc. branch(fol derWithPro ject.getNa me()); | |
| 99 | //li nkAndFetch creates t hese in ma ster, but I don't wa nt them in my branch (if they didn't exi st before I linked / fetched). | |
| 100 | if ( !ignoreExi sts) | |
| 101 | { | |
| 102 | new Fi le(folderW ithProject , ".gitign ore").dele te(); | |
| 103 | } | |
| 104 | if ( !readmeExi sts) | |
| 105 | { | |
| 106 | new Fi le(folderW ithProject , "README. md").delet e(); | |
| 107 | } | |
| 108 | svc. addUntrack edFiles(); | |
| 109 | svc. commitAndT ag("publis hing conve rsion proj ect", tagT oCreate); | |
| 110 | svc. pushTag(ta gToCreate, gitUserNa me, gitPas sword); | |
| 111 | //No tice, I do NOT push the update s to the b ranch | |
| 112 | } | |
| 113 | ||
| 114 | /* * | |
| 115 | * Calls {@l ink #const ructChange setReposit oryURL(Str ing) to ad just the U RL as nece ssary | |
| 116 | * @param gi tRepositor y | |
| 117 | * @param gi tUserName | |
| 118 | * @param gi tPassword | |
| 119 | * @return | |
| 120 | * @throws E xception | |
| 121 | * / | |
| 122 | pu blic stati c ArrayLis t<String> readTags(S tring gitR epository, String gi tUserName, char[] gi tPassword) throws Ex ception | |
| 123 | { | |
| 124 | Stri ng correct edURL = co nstructCha ngesetRepo sitoryURL( gitReposit ory); | |
| 125 | crea teReposito ryIfNecess ary(correc tedURL, gi tUserName, gitPasswo rd); | |
| 126 | Sync ServiceGIT svc = new SyncServi ceGIT(); | |
| 127 | ||
| 128 | File tempFolde r = Files. createTemp Directory( "tagRead") .toFile(); | |
| 129 | ||
| 130 | svc. setRootLoc ation(temp Folder); | |
| 131 | svc. linkAndFet chFromRemo te(correct edURL, git UserName, gitPasswor d); | |
| 132 | Arra yList<Stri ng> temp = svc.readT ags(gitUse rName, git Password); | |
| 133 | try | |
| 134 | { | |
| 135 | FileUt il.recursi veDelete(t empFolder) ; | |
| 136 | } | |
| 137 | catc h (Excepti on e) | |
| 138 | { | |
| 139 | LOG.er ror("Probl em cleanin g up temp folder " + tempFolde r, e); | |
| 140 | } | |
| 141 | retu rn temp; | |
| 142 | } | |
| 143 | ||
| 144 | pu blic stati c void cre ateReposit oryIfNeces sary(Strin g gitRepos itory, Str ing gitUse rName, cha r[] gitPas sword) thr ows IOExce ption | |
| 145 | { | |
| 146 | Stri ng baseUrl = GitBlit Utils.pars eBaseRemot eAddress(g itReposito ry); | |
| 147 | ||
| 148 | Set< String> re pos = GitB litUtils.r eadReposit ories(base Url, gitUs erName, gi tPassword) ; | |
| 149 | ||
| 150 | Stri ng repoNam e = gitRep ository.su bstring(gi tRepositor y.lastInde xOf("/") + 1); | |
| 151 | ||
| 152 | if ( !repos.con tains(repo Name)) | |
| 153 | { | |
| 154 | LOG.in fo("Reques ted reposi tory '" + gitReposit ory + "' d oes not ex ist - crea ting"); | |
| 155 | GitBli tUtils.cre ateReposit ory(baseUr l, repoNam e, "Config uration St orage Repo sitory", g itUserName , gitPassw ord, true) ; | |
| 156 | } | |
| 157 | else | |
| 158 | { | |
| 159 | LOG.in fo("Reques ted reposi tory '" + gitReposit ory + "' e xists"); | |
| 160 | } | |
| 161 | } | |
| 162 | ||
| 163 | /* * | |
| 164 | * This will return -1 if no tag was found matching the tagWit houtRevNum ber. | |
| 165 | * This will return 0 if a tag w as found m atching th e tagWitho utRefNumbe r (but no tag was fo und with a revision number) | |
| 166 | * This will return X > 0 if one or more t ags were f ound with a revision number - returning the highes t value. | |
| 167 | * / | |
| 168 | pu blic stati c int read HighestRev isionNumbe r(ArrayLis t<String> existingTa gs, String tagWithou tRevNumber ) | |
| 169 | { | |
| 170 | int highestBui ldRevision = -1; | |
| 171 | for (String s : existing Tags) | |
| 172 | { | |
| 173 | if (s. equals("re fs/tags/" + tagWitho utRevNumbe r)) | |
| 174 | { | |
| 175 | if (0 > highestBui ldRevision ) | |
| 176 | { | |
| 177 | highestBui ldRevision = 0; | |
| 178 | } | |
| 179 | } | |
| 180 | else i f (s.start sWith("ref s/tags/" + tagWithou tRevNumber + "-")) | |
| 181 | { | |
| 182 | String r evNumber = s.substri ng(("refs/ tags/" + t agWithoutR evNumber + "-").leng th(), s.le ngth()); | |
| 183 | if (Nume ricUtils.i sInt(revNu mber)) | |
| 184 | { | |
| 185 | int parsed = Integer .parseInt( revNumber) ; | |
| 186 | if (parsed > highest BuildRevis ion) | |
| 187 | { | |
| 188 | hi ghestBuild Revision = parsed; | |
| 189 | } | |
| 190 | } | |
| 191 | } | |
| 192 | } | |
| 193 | retu rn highest BuildRevis ion; | |
| 194 | } | |
| 195 | ||
| 196 | pu blic stati c void loc k(String g itReposito ry) throws IOExcepti on | |
| 197 | { | |
| 198 | Stri ng correct edURL = co nstructCha ngesetRepo sitoryURL( gitReposit ory); | |
| 199 | Reen trantLock lock; | |
| 200 | ||
| 201 | sync hronized ( repoLock) | |
| 202 | { | |
| 203 | lock = repoLock. get(correc tedURL); | |
| 204 | if (lo ck == null ) | |
| 205 | { | |
| 206 | lock = n ew Reentra ntLock(); | |
| 207 | repoLock .put(corre ctedURL, l ock); | |
| 208 | } | |
| 209 | } | |
| 210 | ||
| 211 | LOG. debug("Loc king {}", correctedU RL); | |
| 212 | lock .lock(); | |
| 213 | } | |
| 214 | ||
| 215 | pu blic stati c void unl ock(String gitReposi tory) thro ws IOExcep tion | |
| 216 | { | |
| 217 | Stri ng correct edURL = co nstructCha ngesetRepo sitoryURL( gitReposit ory); | |
| 218 | Reen trantLock lock = rep oLock.get( correctedU RL); | |
| 219 | if ( lock == nu ll) | |
| 220 | { | |
| 221 | LOG.er ror("Unloc k called, but no loc k was pres ent!"); | |
| 222 | } | |
| 223 | else | |
| 224 | { | |
| 225 | if (lo ck.isHeldB yCurrentTh read()) | |
| 226 | { | |
| 227 | LOG.debu g("Unlocki ng {}", co rrectedURL ); | |
| 228 | lock.unl ock(); | |
| 229 | } | |
| 230 | else | |
| 231 | { | |
| 232 | //To sup port rapid unlock, b ut also al low an unl ock in a f inally blo ck, make i t ok to un lock when not locked | |
| 233 | LOG.debu g("Unlock called, bu t the lock wasn't he ld by this thread fo r {}", cor rectedURL) ; | |
| 234 | } | |
| 235 | } | |
| 236 | } | |
| 237 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.