mercurial/HGCopyrightUpdater.st
author Patrik Svestka <patrik.svestka@gmail.com>
Mon, 10 Jan 2022 14:21:17 +0100
changeset 938 2bb53758015c
parent 903 3c6c268d7395
permissions -rw-r--r--
Enable support for Mercurial 6.x
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
817
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     1
"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     2
stx:libscm - a new source code management library for Smalltalk/X
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     3
Copyright (C) 2012-2015 Jan Vrany
903
3c6c268d7395 Improve `doCompileCopyrightMethodFor:` to update copyright upon commit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 817
diff changeset
     4
Copyright (C) 2020 LabWare
817
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     5
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     6
This library is free software; you can redistribute it and/or
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     7
modify it under the terms of the GNU Lesser General Public
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     8
License as published by the Free Software Foundation; either
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     9
version 2.1 of the License. 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    10
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    11
This library is distributed in the hope that it will be useful,
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    12
but WITHOUT ANY WARRANTY; without even the implied warranty of
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
Lesser General Public License for more details.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
You should have received a copy of the GNU Lesser General Public
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
License along with this library; if not, write to the Free Software
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    19
"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    20
"{ Package: 'stx:libscm/mercurial' }"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    21
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    22
"{ NameSpace: Smalltalk }"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    23
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    24
Object subclass:#HGCopyrightUpdater
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    25
	instanceVariableNames:'verbose dryrun removeYearToNow'
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    26
	classVariableNames:''
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    27
	poolDictionaries:''
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    28
	category:'SCM-Mercurial-StX-Tools'
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    29
!
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    30
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    31
!HGCopyrightUpdater class methodsFor:'documentation'!
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    32
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    33
copyright
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    34
"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    35
stx:libscm - a new source code management library for Smalltalk/X
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    36
Copyright (C) 2012-2015 Jan Vrany
903
3c6c268d7395 Improve `doCompileCopyrightMethodFor:` to update copyright upon commit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 817
diff changeset
    37
Copyright (C) 2020 LabWare
817
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    38
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    39
This library is free software; you can redistribute it and/or
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    40
modify it under the terms of the GNU Lesser General Public
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    41
License as published by the Free Software Foundation; either
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    42
version 2.1 of the License. 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    43
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    44
This library is distributed in the hope that it will be useful,
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    45
but WITHOUT ANY WARRANTY; without even the implied warranty of
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    46
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    47
Lesser General Public License for more details.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    48
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    49
You should have received a copy of the GNU Lesser General Public
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    50
License along with this library; if not, write to the Free Software
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    51
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    52
"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    53
! !
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    54
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    55
!HGCopyrightUpdater methodsFor:'initialization'!
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    56
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    57
initialize
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    58
    "Invoked when a new instance is created."
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    59
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    60
    "/ please change as required (and remove this comment)
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    61
    "/ repository := nil.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    62
    "/ patterns := nil.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    63
    "/ wc := nil.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    64
    verbose := 0.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    65
    dryrun := false.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    66
    removeYearToNow := false.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    67
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    68
    "/ super initialize.   -- commented since inherited method does nothing
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    69
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    70
    "Modified: / 17-05-2018 / 11:42:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    71
!
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    72
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    73
setDryRun: aBoolean
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    74
    
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    75
    dryrun := aBoolean
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    76
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    77
    "Created: / 14-05-2018 / 19:57:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    78
!
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    79
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    80
setRemoveYearToNow: aBoolean
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    81
    removeYearToNow := aBoolean
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    82
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    83
    "Created: / 17-05-2018 / 11:41:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    84
!
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    85
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    86
setVerbose: anInteger
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    87
    
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    88
    verbose := anInteger
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    89
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    90
    "Created: / 03-05-2018 / 22:36:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    91
! !
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    92
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    93
!HGCopyrightUpdater methodsFor:'private'!
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    94
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    95
collectCopyrightsFromContributionsTo:anHGChangesetFile 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    96
    | contributions  copyrights |
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    97
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    98
    contributions := self searchForContributions:anHGChangesetFile.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    99
    contributions isEmpty ifTrue:[
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   100
        ^ #()
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   101
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   102
    copyrights := OrderedCollection new.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   103
    contributions do:[:contribution | 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   104
        contribution years do:[:years | 
903
3c6c268d7395 Improve `doCompileCopyrightMethodFor:` to update copyright upon commit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 817
diff changeset
   105
            copyrights add:((SCMCopyrightLine new)
817
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   106
                        years:years;
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   107
                        holder:contribution name)
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   108
        ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   109
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   110
    ^ copyrights
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   111
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   112
    "Created: / 15-05-2018 / 13:17:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
903
3c6c268d7395 Improve `doCompileCopyrightMethodFor:` to update copyright upon commit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 817
diff changeset
   113
    "Modified: / 27-05-2020 / 13:53:41 / Jan Vrany <jan.vrany@labware.com>"
817
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   114
!
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   115
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   116
collectCopyrightsFromText:lines 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   117
    | current  copyrights  lineNr |
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   118
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   119
    copyrights := OrderedCollection new.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   120
    current := nil.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   121
    lineNr := 1.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   122
    [ lineNr <= lines size ] whileTrue:[
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   123
        | line  copyright |
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   124
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   125
        line := lines at:lineNr.
903
3c6c268d7395 Improve `doCompileCopyrightMethodFor:` to update copyright upon commit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 817
diff changeset
   126
        copyright := SCMCopyrightLine readFrom:line onError:[ nil ].
817
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   127
        copyright notNil ifTrue:[
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   128
            copyright line:lineNr.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   129
            current isNil ifTrue:[
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   130
                current := OrderedCollection with:copyright.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   131
            ] ifFalse:[
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   132
                current add:copyright
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   133
            ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   134
        ] ifFalse:[
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   135
            current notNil ifTrue:[
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   136
                copyrights add:current.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   137
                current := nil.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   138
            ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   139
        ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   140
        lineNr := lineNr + 1.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   141
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   142
    current notNil ifTrue:[
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   143
        copyrights add:current.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   144
        current := nil.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   145
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   146
    ^ copyrights
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   147
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   148
    "Created: / 17-04-2018 / 13:50:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   149
    "Modified: / 16-05-2018 / 13:49:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
903
3c6c268d7395 Improve `doCompileCopyrightMethodFor:` to update copyright upon commit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 817
diff changeset
   150
    "Modified: / 27-05-2020 / 13:53:36 / Jan Vrany <jan.vrany@labware.com>"
817
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   151
!
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   152
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   153
collectMissing1: computed in: present
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   154
    "
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   155
    Return a list of copyright lines missing in `present`. 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   156
    Both `present` and `computed` lines MUST have the same holder.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   157
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   158
    WARNING: do not use this method, this is a helper for
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   159
    #collectMissing:in:
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   160
    "
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   161
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   162
    | missing |
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   163
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   164
    missing := Set new.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   165
    computed do:[:c |
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   166
        (present noneSatisfy:[:p|(c years start in: p years) and:[c years stop in: p years]]) ifTrue:[ 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   167
            missing add: c.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   168
        ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   169
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   170
    ^ missing.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   171
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   172
    "Created: / 16-05-2018 / 09:33:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   173
    "Modified: / 16-05-2018 / 13:57:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   174
!
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   175
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   176
collectMissing: computed in: present
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   177
    "
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   178
    Return a list of copyright lines missing in `present`
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   179
    "
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   180
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   181
    | presentHolders buckets missing |
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   182
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   183
    "/ First, sort copyright lines into 'buckets' by copyright holder.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   184
    buckets := Dictionary new.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   185
    presentHolders := Set new.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   186
    present do:[:each | 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   187
        (buckets at: each holder ifAbsentPut: [Array with: Set new with: Set new]) second add: each.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   188
        presentHolders add: each holder.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   189
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   190
    computed do:[:each | 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   191
        | holder |
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   192
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   193
        holder := presentHolders detect:[:holder | holder includesString: each holder caseSensitive: false ] ifNone:[ each holder ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   194
        (buckets at: each holder ifAbsentPut: [Array with: Set new with: Set new]) first add: each.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   195
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   196
    missing := SortedCollection new.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   197
    buckets do:[:bucket | 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   198
        missing addAll: (self collectMissing1: bucket first in: bucket second).
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   199
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   200
    ^ missing.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   201
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   202
    "Created: / 15-05-2018 / 13:34:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   203
    "Modified: / 16-05-2018 / 09:31:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   204
!
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   205
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   206
searchForContributions: anHGChangesetFile
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   207
    "
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   208
    Return a list of contributions (as HGContribution) for given changeset file.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   209
    "
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   210
    | contributions |
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   211
    contributions := HGContribution summaryFromFile:anHGChangesetFile.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   212
    (contributions notEmpty and:[verbose > 1]) ifTrue:[ 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   213
        Transcript showCR:'Contributions:'.  
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   214
        contributions do:[:contribution |  
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   215
            Transcript space; show: contribution author; show: ': '; cr.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   216
            contribution changesets do:[:changeset | 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   217
                Transcript show: '  * '; show: changeset id printString; show:' ('; show: changeset timestamp printString; show: ')'.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   218
                verbose > 3 ifTrue:[ 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   219
                    Transcript cr; nextPutAll: changeset message; cr.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   220
                ] ifFalse:[ 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   221
                    Transcript space; showCR: changeset summary
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   222
                ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   223
            ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   224
        ]
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   225
    ].    
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   226
    ^ contributions
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   227
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   228
    "Created: / 15-05-2018 / 13:08:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   229
!
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   230
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   231
updateCopyrights: computed present: present in: lines
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   232
    | changed missingInsertPosition missing |
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   233
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   234
    self assert: present notEmpty.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   235
    self assert: present last line notNil.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   236
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   237
    missingInsertPosition := present last line .
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   238
    changed := false.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   239
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   240
    verbose > 0 ifTrue:[ 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   241
        Transcript showCR: 'Copyrights:'.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   242
        present do:[:copyright | Transcript show: ((removeYearToNow and:[copyright isYearToNow]) ifTrue:[ '- ' ] ifFalse:[ '  ']); showCR: copyright asString ]
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   243
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   244
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   245
    "/ Reject (invalid) copyright lines in form YYYY-now (such as 2016-now)
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   246
    present copy reverseDo:[ :copyright |
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   247
        (removeYearToNow and:[ copyright isYearToNow ]) ifTrue:[ 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   248
            present remove: copyright.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   249
            lines removeIndex: copyright line.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   250
            missingInsertPosition := missingInsertPosition - 1.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   251
            changed := true.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   252
        ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   253
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   254
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   255
    "/ Add all missing copyrights
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   256
    missing := self collectMissing: computed in: present. 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   257
    missing isEmpty ifTrue:[ ^ changed ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   258
    verbose > 0 ifTrue:[ 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   259
        missing do:[:copyright | Transcript show: '+ '; showCR: copyright asString ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   260
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   261
    missing withIndexDo:[ :copyright :index |
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   262
        lines add: copyright asString beforeIndex: missingInsertPosition + index.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   263
        changed := true.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   264
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   265
    ^ changed
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   266
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   267
    "Created: / 23-04-2018 / 15:55:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   268
    "Modified: / 17-05-2018 / 11:42:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   269
! !
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   270
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   271
!HGCopyrightUpdater methodsFor:'utilities'!
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   272
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   273
updateFile:file
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   274
    "
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   275
    For given file (as `HGWorkingCopyFile`) add missing copyright lines
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   276
    based on commits and saves update contents back to file (unless dry-run
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   277
    is specified, see #setDryRun:)
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   278
    "
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   279
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   280
    | wc computed lines presentRuns changed |
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   281
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   282
    verbose > 0 ifTrue:[ 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   283
       Transcript show:'File '; showCR: file baseName.  
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   284
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   285
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   286
    wc := file repository workingCopy.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   287
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   288
    self assert:(wc parent1Id = file changesetId).
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   289
    self assert:(wc / file pathName) exists.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   290
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   291
    "/ Collect copyright lines from file contents....
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   292
    lines := (wc / file pathName) contents.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   293
    presentRuns := self collectCopyrightsFromText:lines.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   294
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   295
    "/ Compute copyright lines from contributions (i.e., based on commit authors)
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   296
    computed := self collectCopyrightsFromContributionsTo: file.  
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   297
    computed isEmpty ifTrue:[ ^ self ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   298
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   299
    "/ At this point, we know that there has been a contribution.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   300
    "/ If there are existing no copytight notices in the file
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   301
    "/ (i.e, `presentRuns` is empty), raise a warning.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   302
    presentRuns isEmpty ifTrue:[ 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   303
        Warning raiseErrorString: ('File %1 has contributions but not copyright notice!!' bindWith: file pathName).
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   304
        ^ self 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   305
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   306
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   307
    computed do:[:each | each prefix: presentRuns first last prefix ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   308
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   309
    changed := false.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   310
    presentRuns reverseDo:[:copyright |
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   311
        changed := (self updateCopyrights: computed present: copyright in: lines) or:[ changed ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   312
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   313
    (changed and:[dryrun not]) ifTrue:[ 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   314
        (wc / file pathName) contents: lines.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   315
    ].
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   316
    verbose > 0 ifTrue:[ 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   317
       Transcript showCR:'--'; cr.
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   318
    ]. 
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   319
    "
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   320
    HGCopyrightUpdateTool main:#('--cwd' 'goodies/regression'   '-v' '-v' '-v' '--dry-run')
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   321
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   322
    HGCopyrightUpdateTool main:#('--cwd' 'librun'   '-v' '-v' '-v' '--dry-run' 'send.c')
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   323
    HGCopyrightUpdateTool main:#('--cwd' 'librun'   '-v' '-v' '-v' '--dry-run' 'hmm.c')
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   324
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   325
    HGCopyrightUpdateTool main:#('--cwd' '../..'   '-v' '-v' '-v' '--dry-run' 'LICENSE.txt')
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   326
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   327
    HGCopyrightUpdateTool main:#('--cwd' 'goodies/smallsense'   '-v' '-v' '-v' '--dry-run' 'SmallSense__SmalltalkQuickFixer.st')
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   328
    HGCopyrightUpdateTool main:#('--cwd' 'goodies/smallsense'   '-v' '-v' '-v' '--dry-run' 'SmallSense__SmalltalkEditSupportTests.st')
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   329
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   330
    HGCopyrightUpdateTool main:#('--cwd' 'libbasic' '-v' '-v' '-v' '--dry-run')
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   331
    HGCopyrightUpdateTool main:#('--cwd' 'libbasic' '-v' '-v' '-v' '--dry-run' 'SmalltalkChunkFileSourceReader.st')
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   332
    HGCopyrightUpdateTool main:#('--cwd' 'libbasic' '-v' '-v' '-v' '--dry-run' 'UnorderedNumbersError.st')
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   333
    HGCopyrightUpdateTool main:#('--cwd' 'libbasic' '-v' '-v' '-v' '--dry-run' 'Method.st')
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   334
    HGCopyrightUpdateTool main:#('--cwd' 'libbasic' '-v' '-v' '-v' '--dry-run' 'Array.st')
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   335
    HGCopyrightUpdateTool main:#('--cwd' 'libbasic' '-v' '-v' '-v' '--dry-run' 'WeakArray.st')
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   336
    HGCopyrightUpdateTool main:#('--cwd' 'libbasic' '-v' '-v' '-v' '--dry-run' 'UnixOperatingSystem.st')
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   337
    "
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   338
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   339
    "Created: / 16-05-2018 / 23:01:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   340
    "Modified: / 10-06-2018 / 21:02:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   341
! !
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   342
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   343
!HGCopyrightUpdater class methodsFor:'documentation'!
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   344
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   345
version_HG
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   346
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   347
    ^ '$Changeset: <not expanded> $'
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   348
! !
e38e4f23a097 Added tool to update copyright notices in files based on commits
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   349