001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.core.cache;
019:
020: import java.io.File;
021: import java.io.FilenameFilter;
022:
023: import org.apache.ivy.core.IvyPatternHelper;
024: import org.apache.ivy.core.module.id.ModuleRevisionId;
025: import org.apache.ivy.util.FileUtil;
026:
027: public class DefaultResolutionCacheManager implements
028: ResolutionCacheManager {
029: private static final String DEFAULT_CACHE_RESOLVED_IVY_PATTERN = "resolved-[organisation]-[module]-[revision].xml";
030:
031: private static final String DEFAULT_CACHE_RESOLVED_IVY_PROPERTIES_PATTERN = "resolved-[organisation]-[module]-[revision].properties";
032:
033: private String resolvedIvyPattern = DEFAULT_CACHE_RESOLVED_IVY_PATTERN;
034:
035: private String resolvedIvyPropertiesPattern = DEFAULT_CACHE_RESOLVED_IVY_PROPERTIES_PATTERN;
036:
037: private File basedir;
038:
039: private String name = "resolution-cache";
040:
041: public DefaultResolutionCacheManager() {
042: }
043:
044: public DefaultResolutionCacheManager(File basedir) {
045: setBasedir(basedir);
046: }
047:
048: public File getResolutionCacheRoot() {
049: return basedir;
050: }
051:
052: public File getBasedir() {
053: return basedir;
054: }
055:
056: public void setBasedir(File basedir) {
057: this .basedir = basedir;
058: }
059:
060: public String getResolvedIvyPattern() {
061: return resolvedIvyPattern;
062: }
063:
064: public void setResolvedIvyPattern(String cacheResolvedIvyPattern) {
065: this .resolvedIvyPattern = cacheResolvedIvyPattern;
066: }
067:
068: public String getResolvedIvyPropertiesPattern() {
069: return resolvedIvyPropertiesPattern;
070: }
071:
072: public void setResolvedIvyPropertiesPattern(
073: String cacheResolvedIvyPropertiesPattern) {
074: this .resolvedIvyPropertiesPattern = cacheResolvedIvyPropertiesPattern;
075: }
076:
077: public String getName() {
078: return name;
079: }
080:
081: public void setName(String name) {
082: this .name = name;
083: }
084:
085: public File getResolvedIvyFileInCache(ModuleRevisionId mrid) {
086: String file = IvyPatternHelper.substitute(
087: getResolvedIvyPattern(), mrid.getOrganisation(), mrid
088: .getName(), mrid.getRevision(), "ivy", "ivy",
089: "xml");
090: return new File(getResolutionCacheRoot(), file);
091: }
092:
093: public File getResolvedIvyPropertiesInCache(ModuleRevisionId mrid) {
094: String file = IvyPatternHelper.substitute(
095: getResolvedIvyPropertiesPattern(), mrid
096: .getOrganisation(), mrid.getName(), mrid
097: .getRevision(), "ivy", "ivy", "xml");
098: return new File(getResolutionCacheRoot(), file);
099: }
100:
101: public File getConfigurationResolveReportInCache(String resolveId,
102: String conf) {
103: return new File(getResolutionCacheRoot(), resolveId + "-"
104: + conf + ".xml");
105: }
106:
107: public File[] getConfigurationResolveReportsInCache(
108: final String resolveId) {
109: final String prefix = resolveId + "-";
110: final String suffix = ".xml";
111: return getResolutionCacheRoot().listFiles(new FilenameFilter() {
112: public boolean accept(File dir, String name) {
113: return (name.startsWith(prefix) && name
114: .endsWith(suffix));
115: }
116: });
117: }
118:
119: public String toString() {
120: return name;
121: }
122:
123: public void clean() {
124: FileUtil.forceDelete(getBasedir());
125: }
126:
127: }
|