KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > artifact > repository > ArtifactRepositoryPolicy


1 package org.apache.maven.artifact.repository;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.util.Calendar JavaDoc;
20 import java.util.Date JavaDoc;
21
22 /**
23  * Describes a set of policies for a repository to use under certain conditions.
24  *
25  * @author <a HREF="mailto:brett@apache.org">Brett Porter</a>
26  * @version $Id: ArtifactRepositoryPolicy.java 225714 2005-07-28 06:35:47Z brett $
27  */

28 public class ArtifactRepositoryPolicy
29 {
30     public static final String JavaDoc UPDATE_POLICY_NEVER = "never";
31
32     public static final String JavaDoc UPDATE_POLICY_ALWAYS = "always";
33
34     public static final String JavaDoc UPDATE_POLICY_DAILY = "daily";
35
36     public static final String JavaDoc UPDATE_POLICY_INTERVAL = "interval";
37
38     public static final String JavaDoc CHECKSUM_POLICY_FAIL = "fail";
39
40     public static final String JavaDoc CHECKSUM_POLICY_WARN = "warn";
41
42     public static final String JavaDoc CHECKSUM_POLICY_IGNORE = "ignore";
43
44     private boolean enabled;
45
46     private String JavaDoc updatePolicy;
47
48     private String JavaDoc checksumPolicy;
49
50     public ArtifactRepositoryPolicy()
51     {
52         this( true, null, null );
53     }
54
55     public ArtifactRepositoryPolicy( boolean enabled, String JavaDoc updatePolicy, String JavaDoc checksumPolicy )
56     {
57         this.enabled = enabled;
58
59         if ( updatePolicy == null )
60         {
61             updatePolicy = UPDATE_POLICY_DAILY;
62         }
63         this.updatePolicy = updatePolicy;
64
65         if ( checksumPolicy == null )
66         {
67             checksumPolicy = CHECKSUM_POLICY_WARN;
68         }
69         this.checksumPolicy = checksumPolicy;
70     }
71
72     public void setEnabled( boolean enabled )
73     {
74         this.enabled = enabled;
75     }
76
77     public void setUpdatePolicy( String JavaDoc updatePolicy )
78     {
79         this.updatePolicy = updatePolicy;
80     }
81
82     public void setChecksumPolicy( String JavaDoc checksumPolicy )
83     {
84         this.checksumPolicy = checksumPolicy;
85     }
86
87     public boolean isEnabled()
88     {
89         return enabled;
90     }
91
92     public String JavaDoc getUpdatePolicy()
93     {
94         return updatePolicy;
95     }
96
97     public String JavaDoc getChecksumPolicy()
98     {
99         return checksumPolicy;
100     }
101
102     public boolean checkOutOfDate( Date JavaDoc lastModified )
103     {
104         boolean checkForUpdates = false;
105
106         if ( UPDATE_POLICY_ALWAYS.equals( updatePolicy ) )
107         {
108             checkForUpdates = true;
109         }
110         else if ( UPDATE_POLICY_DAILY.equals( updatePolicy ) )
111         {
112             // Get midnight boundary
113
Calendar JavaDoc cal = Calendar.getInstance();
114             cal.set( Calendar.HOUR_OF_DAY, 0 );
115             cal.set( Calendar.MINUTE, 0 );
116             cal.set( Calendar.SECOND, 0 );
117             cal.set( Calendar.MILLISECOND, 0 );
118             if ( cal.getTime().after( lastModified ) )
119             {
120                 checkForUpdates = true;
121             }
122         }
123         else if ( updatePolicy.startsWith( UPDATE_POLICY_INTERVAL ) )
124         {
125             String JavaDoc s = updatePolicy.substring( UPDATE_POLICY_INTERVAL.length() + 1 );
126             int minutes = Integer.valueOf( s ).intValue();
127             Calendar JavaDoc cal = Calendar.getInstance();
128             cal.add( Calendar.MINUTE, -minutes );
129             if ( cal.getTime().after( lastModified ) )
130             {
131                 checkForUpdates = true;
132             }
133         }
134         // else assume "never"
135
return checkForUpdates;
136     }
137 }
138
Popular Tags