1 package org.apache.maven.artifact.repository;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Calendar;
23 import java.util.Date;
24
25
26
27
28
29
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 this( true, null, null );
56 }
57
58 public ArtifactRepositoryPolicy( boolean enabled, String updatePolicy, String checksumPolicy )
59 {
60 this.enabled = enabled;
61
62 if ( updatePolicy == null )
63 {
64 updatePolicy = UPDATE_POLICY_DAILY;
65 }
66 this.updatePolicy = updatePolicy;
67
68 if ( checksumPolicy == null )
69 {
70 checksumPolicy = CHECKSUM_POLICY_WARN;
71 }
72 this.checksumPolicy = checksumPolicy;
73 }
74
75 public void setEnabled( boolean enabled )
76 {
77 this.enabled = enabled;
78 }
79
80 public void setUpdatePolicy( String updatePolicy )
81 {
82 this.updatePolicy = updatePolicy;
83 }
84
85 public void setChecksumPolicy( String checksumPolicy )
86 {
87 this.checksumPolicy = checksumPolicy;
88 }
89
90 public boolean isEnabled()
91 {
92 return enabled;
93 }
94
95 public String getUpdatePolicy()
96 {
97 return updatePolicy;
98 }
99
100 public String getChecksumPolicy()
101 {
102 return checksumPolicy;
103 }
104
105 public boolean checkOutOfDate( Date lastModified )
106 {
107 boolean checkForUpdates = false;
108
109 if ( UPDATE_POLICY_ALWAYS.equals( updatePolicy ) )
110 {
111 checkForUpdates = true;
112 }
113 else if ( UPDATE_POLICY_DAILY.equals( updatePolicy ) )
114 {
115
116 Calendar cal = Calendar.getInstance();
117 cal.set( Calendar.HOUR_OF_DAY, 0 );
118 cal.set( Calendar.MINUTE, 0 );
119 cal.set( Calendar.SECOND, 0 );
120 cal.set( Calendar.MILLISECOND, 0 );
121 if ( cal.getTime().after( lastModified ) )
122 {
123 checkForUpdates = true;
124 }
125 }
126 else if ( updatePolicy.startsWith( UPDATE_POLICY_INTERVAL ) )
127 {
128 String s = updatePolicy.substring( UPDATE_POLICY_INTERVAL.length() + 1 );
129 int minutes = Integer.valueOf( s ).intValue();
130 Calendar cal = Calendar.getInstance();
131 cal.add( Calendar.MINUTE, -minutes );
132 if ( cal.getTime().after( lastModified ) )
133 {
134 checkForUpdates = true;
135 }
136 }
137
138 return checkForUpdates;
139 }
140 }