Coverage Report - org.apache.maven.artifact.repository.ArtifactRepositoryPolicy
 
Classes in this File Line Coverage Branch Coverage Complexity
ArtifactRepositoryPolicy
0 %
0/40
0 %
0/14
1,778
 
 1  
 package org.apache.maven.artifact.repository;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.util.Calendar;
 23  
 import java.util.Date;
 24  
 
 25  
 /**
 26  
  * Describes a set of policies for a repository to use under certain conditions.
 27  
  *
 28  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 29  
  * @version $Id: ArtifactRepositoryPolicy.java 640549 2008-03-24 20:05:11Z bentmann $
 30  
  */
 31  
 public class ArtifactRepositoryPolicy
 32  
 {
 33  
     public static final String UPDATE_POLICY_NEVER = "never";
 34  
 
 35  
     public static final String UPDATE_POLICY_ALWAYS = "always";
 36  
 
 37  
     public static final String UPDATE_POLICY_DAILY = "daily";
 38  
 
 39  
     public static final String UPDATE_POLICY_INTERVAL = "interval";
 40  
 
 41  
     public static final String CHECKSUM_POLICY_FAIL = "fail";
 42  
 
 43  
     public static final String CHECKSUM_POLICY_WARN = "warn";
 44  
 
 45  
     public static final String CHECKSUM_POLICY_IGNORE = "ignore";
 46  
 
 47  
     private boolean enabled;
 48  
 
 49  
     private String updatePolicy;
 50  
 
 51  
     private String checksumPolicy;
 52  
 
 53  
     public ArtifactRepositoryPolicy()
 54  
     {
 55  0
         this( true, null, null );
 56  0
     }
 57  
 
 58  
     public ArtifactRepositoryPolicy( boolean enabled, String updatePolicy, String checksumPolicy )
 59  0
     {
 60  0
         this.enabled = enabled;
 61  
 
 62  0
         if ( updatePolicy == null )
 63  
         {
 64  0
             updatePolicy = UPDATE_POLICY_DAILY;
 65  
         }
 66  0
         this.updatePolicy = updatePolicy;
 67  
 
 68  0
         if ( checksumPolicy == null )
 69  
         {
 70  0
             checksumPolicy = CHECKSUM_POLICY_WARN;
 71  
         }
 72  0
         this.checksumPolicy = checksumPolicy;
 73  0
     }
 74  
 
 75  
     public void setEnabled( boolean enabled )
 76  
     {
 77  0
         this.enabled = enabled;
 78  0
     }
 79  
 
 80  
     public void setUpdatePolicy( String updatePolicy )
 81  
     {
 82  0
         this.updatePolicy = updatePolicy;
 83  0
     }
 84  
 
 85  
     public void setChecksumPolicy( String checksumPolicy )
 86  
     {
 87  0
         this.checksumPolicy = checksumPolicy;
 88  0
     }
 89  
 
 90  
     public boolean isEnabled()
 91  
     {
 92  0
         return enabled;
 93  
     }
 94  
 
 95  
     public String getUpdatePolicy()
 96  
     {
 97  0
         return updatePolicy;
 98  
     }
 99  
 
 100  
     public String getChecksumPolicy()
 101  
     {
 102  0
         return checksumPolicy;
 103  
     }
 104  
 
 105  
     public boolean checkOutOfDate( Date lastModified )
 106  
     {
 107  0
         boolean checkForUpdates = false;
 108  
 
 109  0
         if ( UPDATE_POLICY_ALWAYS.equals( updatePolicy ) )
 110  
         {
 111  0
             checkForUpdates = true;
 112  
         }
 113  0
         else if ( UPDATE_POLICY_DAILY.equals( updatePolicy ) )
 114  
         {
 115  
             // Get midnight boundary
 116  0
             Calendar cal = Calendar.getInstance();
 117  0
             cal.set( Calendar.HOUR_OF_DAY, 0 );
 118  0
             cal.set( Calendar.MINUTE, 0 );
 119  0
             cal.set( Calendar.SECOND, 0 );
 120  0
             cal.set( Calendar.MILLISECOND, 0 );
 121  0
             if ( cal.getTime().after( lastModified ) )
 122  
             {
 123  0
                 checkForUpdates = true;
 124  
             }
 125  0
         }
 126  0
         else if ( updatePolicy.startsWith( UPDATE_POLICY_INTERVAL ) )
 127  
         {
 128  0
             String s = updatePolicy.substring( UPDATE_POLICY_INTERVAL.length() + 1 );
 129  0
             int minutes = Integer.valueOf( s ).intValue();
 130  0
             Calendar cal = Calendar.getInstance();
 131  0
             cal.add( Calendar.MINUTE, -minutes );
 132  0
             if ( cal.getTime().after( lastModified ) )
 133  
             {
 134  0
                 checkForUpdates = true;
 135  
             }
 136  
         }
 137  
         // else assume "never"
 138  0
         return checkForUpdates;
 139  
     }
 140  
 }