Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
   * and other contributors as indicated by the @author tags.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.hawkular.build.license;
 
 import java.io.File;
 import java.util.Map;
 
 
 
 public class CopyrightRangeProvider implements PropertiesProvider {
 
     public static final String COPYRIGHT_LAST_YEAR_KEY = "license.copyrightLastYear";
     public static final String COPYRIGHT_LAST_YEAR_MAX_COMMITS_LOOKUP_KEY = "license.git.copyrightLastYearMaxCommitsLookup";
     public static final String COPYRIGHT_LAST_YEAR_SOURCE_KEY = "license.git.copyrightLastYearSource";
     public static final String COPYRIGHT_LAST_YEAR_TIME_ZONE_KEY = "license.git.copyrightLastYearTimeZone";
     public static final String COPYRIGHT_YEARS_KEY = "license.copyrightYears";
     public static final String INCEPTION_YEAR_KEY = "project.inceptionYear";
 
     private volatile GitLookup gitLookup;
 
     public CopyrightRangeProvider() {
         super();
     }

    
Returns an unmodifiable map containing two entries COPYRIGHT_LAST_YEAR_KEY and COPYRIGHT_YEARS_KEY whose values are set based on inspecting git history. The INCEPTION_YEAR_KEY value is read from the supplied properties and it must available. Otherwise a java.lang.RuntimeException is thrown.
 
     public Map<StringStringgetAdditionalProperties(AbstractLicenseMojo mojoProperties properties,
             Document document) {
         String inceptionYear = properties.getProperty();
         if (inceptionYear == null) {
             throw new RuntimeException("'project.inceptionYear' must have a value for file "
                     + document.getFile().getAbsolutePath());
         }
         final int inceptionYearInt;
         try {
             inceptionYearInt = Integer.parseInt(inceptionYear);
         } catch (NumberFormatException e1) {
             throw new RuntimeException("'project.inceptionYear' must be an integer ; found = " + inceptionYear +" file: "
                     + document.getFile().getAbsolutePath());
         }
         try {
             Map<StringStringresult = new HashMap<StringString>(3);
             int copyrightEnd = getGitLookup(document.getFile(), properties).getYearOfLastChange(document.getFile());
             result.put(, Integer.toString(copyrightEnd));
             final String copyrightYears;
             if (inceptionYearInt >= copyrightEnd) {
                 copyrightYears = inceptionYear;
             } else {
                 copyrightYears = inceptionYear + "-" + copyrightEnd;
             }
             result.put(copyrightYears);
             return Collections.unmodifiableMap(result);
         } catch (Exception e) {
             throw new RuntimeException("Could not compute the year of the last git commit for file "
                     + document.getFile().getAbsolutePath(), e);
         }
    }

    
Lazily initializes #gitLookup assuming that all subsequent calls to this method will be related to the same git repository.

Parameters:
file
Returns:
Throws:
java.io.IOException
    private GitLookup getGitLookup(File fileProperties propsthrows IOException {
        if ( == null) {
            synchronized (this) {
                if ( == null) {
                    String dateSourceString = props.getProperty(,
                            ..name());
                    DateSource dateSource = DateSource.valueOf(dateSourceString.toUpperCase(.));
                    String checkCommitsCountString = props.getProperty();
                    int checkCommitsCount = .;
                    if (checkCommitsCountString != null) {
                        checkCommitsCountString = checkCommitsCountString.trim();
                        checkCommitsCount = Integer.parseInt(checkCommitsCountString);
                    }
                    final TimeZone timeZone;
                    String tzString = props.getProperty();
                    switch (dateSource) {
                    case :
                        timeZone = tzString == null ? . : TimeZone.getTimeZone(tzString);
                        break;
                    case :
                        if (tzString != null) {
                            throw new RuntimeException( + " must not be set with "
                                    +  + " = " + ..name()
                                    + " because git author name already contrains time zone information.");
                        }
                        timeZone = null;
                        break;
                    default:
                        throw new IllegalStateException("Unexpected " + DateSource.class.getName() + " " + dateSource);
                    }
                     = new GitLookup(filedateSourcetimeZonecheckCommitsCount);
                }
            }
        }
        return ;
    }
New to GrepCode? Check out our FAQ X