01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.ant;
19:
20: import org.apache.ivy.core.cache.RepositoryCacheManager;
21: import org.apache.ivy.core.settings.IvySettings;
22: import org.apache.tools.ant.BuildException;
23:
24: /**
25: * Cleans the content of Ivy cache(s).
26: */
27: public class IvyCleanCache extends IvyTask {
28: public static final String ALL = "*";
29:
30: public static final String NONE = "NONE";
31:
32: private boolean resolution = true;
33:
34: private String cache = ALL;
35:
36: public String getCache() {
37: return cache;
38: }
39:
40: /**
41: * Sets the name of the repository cache to clean, '*' for all caches, 'NONE' for no repository
42: * cache cleaning at all.
43: *
44: * @param cache
45: * the name of the cache to clean. Must not be <code>null</code>.
46: */
47: public void setCache(String cache) {
48: this .cache = cache;
49: }
50:
51: public boolean isResolution() {
52: return resolution;
53: }
54:
55: /**
56: * Sets weither the resolution cache should be cleaned or not.
57: *
58: * @param resolution
59: * <code>true</code> if the resolution cache should be cleaned, <code>false</code>
60: * otherwise.
61: */
62: public void setResolution(boolean resolution) {
63: this .resolution = resolution;
64: }
65:
66: public void doExecute() throws BuildException {
67: IvySettings settings = getIvyInstance().getSettings();
68: if (isResolution()) {
69: settings.getResolutionCacheManager().clean();
70: }
71: if (ALL.equals(getCache())) {
72: RepositoryCacheManager[] caches = settings
73: .getRepositoryCacheManagers();
74: for (int i = 0; i < caches.length; i++) {
75: caches[i].clean();
76: }
77: } else if (!NONE.equals(getCache())) {
78: RepositoryCacheManager cache = settings
79: .getRepositoryCacheManager(getCache());
80: if (cache == null) {
81: throw new BuildException("unknown cache '" + getCache()
82: + "'");
83: } else {
84: cache.clean();
85: }
86: }
87: }
88: }
|