2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
package org.apache.ivy.core.cache;
21
import java.io.FilenameFilter;
23
import org.apache.ivy.core.IvyPatternHelper;
24
import org.apache.ivy.core.module.id.ModuleRevisionId;
25
import org.apache.ivy.util.FileUtil;
27
public class DefaultResolutionCacheManager implements ResolutionCacheManager {
28
private static final String DEFAULT_CACHE_RESOLVED_IVY_PATTERN =
29
"resolved-[organisation]-[module]-[revision].xml";
31
private static final String DEFAULT_CACHE_RESOLVED_IVY_PROPERTIES_PATTERN =
32
"resolved-[organisation]-[module]-[revision].properties";
35
private String resolvedIvyPattern = DEFAULT_CACHE_RESOLVED_IVY_PATTERN;
37
private String resolvedIvyPropertiesPattern =
38
DEFAULT_CACHE_RESOLVED_IVY_PROPERTIES_PATTERN;
42
private String name = "resolution-cache";
44
public DefaultResolutionCacheManager() {
47
public DefaultResolutionCacheManager(File basedir) {
51
public File getResolutionCacheRoot() {
55
public File getBasedir() {
59
public void setBasedir(File basedir) {
60
this.basedir = basedir;
63
public String getResolvedIvyPattern() {
64
return resolvedIvyPattern;
67
public void setResolvedIvyPattern(String cacheResolvedIvyPattern) {
68
this.resolvedIvyPattern = cacheResolvedIvyPattern;
71
public String getResolvedIvyPropertiesPattern() {
72
return resolvedIvyPropertiesPattern;
75
public void setResolvedIvyPropertiesPattern(String cacheResolvedIvyPropertiesPattern) {
76
this.resolvedIvyPropertiesPattern = cacheResolvedIvyPropertiesPattern;
79
public String getName() {
83
public void setName(String name) {
88
public File getResolvedIvyFileInCache(ModuleRevisionId mrid) {
89
String file = IvyPatternHelper.substitute(getResolvedIvyPattern(), mrid
90
.getOrganisation(), mrid.getName(), mrid.getRevision(), "ivy", "ivy", "xml");
91
return new File(getResolutionCacheRoot(), file);
94
public File getResolvedIvyPropertiesInCache(ModuleRevisionId mrid) {
95
String file = IvyPatternHelper.substitute(getResolvedIvyPropertiesPattern(),
96
mrid.getOrganisation(), mrid.getName(), mrid.getRevision(), "ivy", "ivy", "xml");
97
return new File(getResolutionCacheRoot(), file);
100
public File getConfigurationResolveReportInCache(String resolveId, String conf) {
101
return new File(getResolutionCacheRoot(), resolveId + "-" + conf + ".xml");
104
public File[] getConfigurationResolveReportsInCache(final String resolveId) {
105
final String prefix = resolveId + "-";
106
final String suffix = ".xml";
107
return getResolutionCacheRoot().listFiles(new FilenameFilter() {
108
public boolean accept(File dir, String name) {
109
return (name.startsWith(prefix) && name.endsWith(suffix));
114
public String toString() {
118
public void clean() {
119
FileUtil.forceDelete(getBasedir());