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 | 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 | |
|
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 | |
|
138 | 0 | return checkForUpdates; |
139 | |
} |
140 | |
} |