1 /*******************************************************************************
2 * Copyright (c) 2010, 2012 Sonatype, Inc.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Sonatype, Inc. - initial API and implementation
10 *******************************************************************************/
11 package org
.eclipse
.aether
.repository
;
14 * A policy controlling access to a repository.
16 public final class RepositoryPolicy
20 * Never update locally cached data.
22 public static final String UPDATE_POLICY_NEVER
= "never";
25 * Always update locally cached data.
27 public static final String UPDATE_POLICY_ALWAYS
= "always";
30 * Update locally cached data once a day.
32 public static final String UPDATE_POLICY_DAILY
= "daily";
35 * Update locally cached data every X minutes as given by "interval:X".
37 public static final String UPDATE_POLICY_INTERVAL
= "interval";
40 * Verify checksums and fail the resolution if they do not match.
42 public static final String CHECKSUM_POLICY_FAIL
= "fail";
45 * Verify checksums and warn if they do not match.
47 public static final String CHECKSUM_POLICY_WARN
= "warn";
50 * Do not verify checksums.
52 public static final String CHECKSUM_POLICY_IGNORE
= "ignore";
54 private final boolean enabled
;
56 private final String updatePolicy
;
58 private final String checksumPolicy
;
61 * Creates a new policy with checksum warnings and daily update checks.
63 public RepositoryPolicy()
65 this( true, UPDATE_POLICY_DAILY
, CHECKSUM_POLICY_WARN
);
69 * Creates a new policy with the specified settings.
71 * @param enabled A flag whether the associated repository should be accessed or not.
72 * @param updatePolicy The update interval after which locally cached data from the repository is considered stale
73 * and should be refetched, may be {@code null}.
74 * @param checksumPolicy The way checksum verification should be handled, may be {@code null}.
76 public RepositoryPolicy( boolean enabled
, String updatePolicy
, String checksumPolicy
)
78 this.enabled
= enabled
;
79 this.updatePolicy
= ( updatePolicy
!= null ) ? updatePolicy
: "";
80 this.checksumPolicy
= ( checksumPolicy
!= null ) ? checksumPolicy
: "";
84 * Indicates whether the associated repository should be contacted or not.
86 * @return {@code true} if the repository should be contacted, {@code false} otherwise.
88 public boolean isEnabled()
94 * Gets the update policy for locally cached data from the repository.
96 * @return The update policy, never {@code null}.
98 public String
getUpdatePolicy()
104 * Gets the policy for checksum validation.
106 * @return The checksum policy, never {@code null}.
108 public String
getChecksumPolicy()
110 return checksumPolicy
;
114 public String
toString()
116 StringBuilder buffer
= new StringBuilder( 256 );
117 buffer
.append( "enabled=" ).append( isEnabled() );
118 buffer
.append( ", checksums=" ).append( getChecksumPolicy() );
119 buffer
.append( ", updates=" ).append( getUpdatePolicy() );
120 return buffer
.toString();
124 public boolean equals( Object obj
)
131 if ( obj
== null || !getClass().equals( obj
.getClass() ) )
136 RepositoryPolicy that
= (RepositoryPolicy
) obj
;
138 return enabled
== that
.enabled
&& updatePolicy
.equals( that
.updatePolicy
)
139 && checksumPolicy
.equals( that
.checksumPolicy
);
143 public int hashCode()
146 hash
= hash
* 31 + ( enabled ?
1 : 0 );
147 hash
= hash
* 31 + updatePolicy
.hashCode();
148 hash
= hash
* 31 + checksumPolicy
.hashCode();