Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 442206

Summary: Eclipse Copyright Tool date integration with Git
Product: [Eclipse Project] Platform Reporter: Jody Garnett <jody.garnett>
Component: RelengAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: david_williams, martin.karpisek, thanh.ha
Version: 4.4Keywords: helpwanted
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard: stalebug

Description Jody Garnett CLA 2014-08-20 15:15:06 EDT
Although #345669 notes that the Copyright Tool does work with Git it is missing a key feature required during eclipse incubation of new projects .. filling in the correct date range from version control.

Care should be taken to to use "git log --follow" when obtaining the date range (for the complete file history across renames).

This is especially important during Eclipse incubation as all prior project history is compressed into a single commit making this our last chance to obtain this information.
Comment 1 Jody Garnett CLA 2014-08-20 15:33:47 EDT
Context: I am using this tool to clean up headers for the GeoGig project as part of locationtech incubation.

For point of reference (no pun intended) consider the following Ref.java file.

Before rename: (history stretching back to 2012)

* https://github.com/boundlessgeo/GeoGig/commits/0.11.x/src/core/src/main/java/org/geogit/api/Ref.java

After rename in July:

* https://github.com/boundlessgeo/GeoGig/commits/r1.0-beta1/src/core/src/main/java/org/locationtech/geogig/api/Ref.java

The use of "git log --follow Ref.java" is able to trace the complete file history.

As it stands the Eclipse Copyright Tool is unable to determine the correct creation date and uses the default provided during configuration.
Comment 2 Jody Garnett CLA 2014-08-22 15:29:03 EDT
That is my understanding as well Gabriel. I will submit those two files now in order to avoid stretching this out.
Comment 3 David Williams CLA 2014-08-22 16:17:33 EDT
(In reply to Jody Garnett from comment #2)
> That is my understanding as well Gabriel. I will submit those two files now
> in order to avoid stretching this out.

Who's Gabriel? Did you mean this comment for this bug?
Comment 4 Jody Garnett CLA 2014-08-22 20:37:56 EDT
> Who's Gabriel? Did you mean this comment for this bug?

My apologises I am still not used to Bugzilla automatically advancing to the "next" bug :(
Comment 5 David Williams CLA 2014-08-27 10:12:35 EDT
Leo, 

Would you be able/interested in taking a look at this one? 

I'll confess it's "over my head" :) ... but am hoping since you've been working on copyright tool lately you'll understand exactly what the issue is, and how to solve it. 

If not (i.e. not able/interested) please re-assign to inbox.
Comment 6 Leo Ufimtsev CLA 2014-08-27 10:47:53 EDT
Hey ya, 

I'm working on the save-actions at the moment:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=369992

If I get time, I'll try to look into this guy.
Comment 7 Leo Ufimtsev CLA 2014-08-27 11:23:26 EDT
Hello, 

I'm being re-directed to work on another project (I was just informed), so unfortunately I won't be able to start on new releng-copyright bugs/tasks anymore. 

However, I will respond to existing gerrit reviews and bugs that I worked on. 

It was fun working on this tool :-).
Comment 8 David Williams CLA 2014-08-27 12:36:26 EDT
Thanks Leo. I'll get to those Gerrit reviews today or tomorrow. Thanks for your help and improvements to the tool. 

Jody, 

maybe you can guess, and I hate to say it, since I hate it when people say it to me ... but I must say "we'll need a high quality patch" before looking at this. That's not to say it's not important or anything ... just the way our priorities are. 

But even if you can't provide a patch, we appreciate the bug report. 

Thanks,
Comment 9 Jody Garnett CLA 2014-08-27 16:13:45 EDT
As a project lead I understand the issue, I have managed to get by with an evil bash script for now that produces a CSV file with the needed details.

The script is here

#!/bin/bash
for file in `git ls-files -x src/*`
do
    HASH=`git log --diff-filter=A --format="%H" -- $file | tail -n 1`
    AUTHOR=`git show -s --format="%aN" --date=short $HASH --`
    CREATED=`git show -s --format="%cd" --date=short $HASH --`
    MODIFIED=`git log --format="%cd" --date=short -n 1 -- $file`
    printf "%s,%s,%s,%s,%s\n" $file "$AUTHOR" "${CREATED:0:4}" "${MODIFIED:0:4}" $HASH 
done

For details see https://github.com/boundlessgeo/GeoGig/issues/799

I will hand this script out to other LocationTech projects going through incubation.
Comment 10 Jody Garnett CLA 2014-09-04 11:12:20 EDT
The output of the previous script is of the form:

e98dfad482e6a70c24773860f05f451572f365f9,src/cli/src/main/java/org/locationtech/geogig/cli/AbstractCommand.java,x,Gabriel Roldan (Boundless),2012,2014,java
e98dfad482e6a70c24773860f05f451572f365f9,src/cli/src/main/java/org/locationtech/geogig/cli/AnsiDecorator.java,x,Gabriel Roldan (Boundless),2012,2014,java
aa4237fceec09e039efe6d5cf44c28162c091d8d,src/cli/src/main/java/org/locationtech/geogig/cli/ArgumentTokenizer.java,x,Victor Olaya (Boundless),2014,2014,java

Here is a second script that can batch update the headers:

#!/bin/bash
function update_header() {
   FILE=$1
   AUTHOR=$2
   YEAR=$3
   MODIFIED=$4   
   if [ "${YEAR}" = "${MODIFIED}" ]
   then
      COPYRIGHT="Copyright (c) ${YEAR} Boundless and others."
   else
      COPYRIGHT="Copyright (c) ${YEAR}-${MODIFIED} Boundless and others."
   fi
   #echo "Looking for ${FILE}"
   if [ -f "${FILE}" ]
   then
      echo "Process: ${FILE} --> ${COPYRIGHT} Contributor: ${AUTHOR}"
      HEADER=$"/* ${COPYRIGHT}\n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Distribution License v1.0\n * which accompanies this distribution, and is available at\n * https://www.eclipse.org/org/documents/edl-v10.html\n *\n * Contributors:\n * ${AUTHOR} - initial implementation\n */"

      #echo -e "${HEADER}"
      PACKAGE=`grep -n -m 1 package "${FILE}" | cut -d':' -f1`

      echo -e "${HEADER}" > tmp
      tail -n +${PACKAGE} ${FILE} >> tmp

      mv tmp "${FILE}"
   else 
      echo "Skipped: ${FILE}..."
      echo "${FILE}" >> skipped
   fi
}

HERE=`dirname $0`
FILE_LIST=$1

OIFS=$IFS
IFS=$'\n'
for line in `cat ${FILE_LIST}`
do
   #echo "${line}"
   FILE=$(echo $line | cut -f2 -d ',')
   AUTHOR=$(echo $line | cut -f4 -d ',')
   YEAR=$(echo $line | cut -f5 -d ',')
   MODIFIED=$(echo $line | cut -f6 -d ',')
   TYPE=$(echo $line | cut -f7 -d ',')
   if [ "${TYPE}" = "java" ]
   then
      update_header ${FILE} ${AUTHOR} ${YEAR} ${MODIFIED}
   else
      echo "Ignore ${TYPE} : ${FILE}"
   fi
done
IFS=$OIFS
Comment 11 Eclipse Genie CLA 2019-12-14 11:21:28 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.