~ubuntu-branches/ubuntu/trusty/ivy/trusty

« back to all changes in this revision

Viewing changes to src/java/org/apache/ivy/core/cache/DefaultResolutionCacheManager.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2009-03-06 22:04:56 UTC
  • Revision ID: james.westby@ubuntu.com-20090306220456-5v37luqiuqda8ewp
Tags: upstream-2.0.0
ImportĀ upstreamĀ versionĀ 2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
8
 *
 
9
 *      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.core.cache;
 
19
 
 
20
import java.io.File;
 
21
import java.io.FilenameFilter;
 
22
 
 
23
import org.apache.ivy.core.IvyPatternHelper;
 
24
import org.apache.ivy.core.module.id.ModuleRevisionId;
 
25
import org.apache.ivy.util.FileUtil;
 
26
 
 
27
public class DefaultResolutionCacheManager implements ResolutionCacheManager {
 
28
    private static final String DEFAULT_CACHE_RESOLVED_IVY_PATTERN = 
 
29
        "resolved-[organisation]-[module]-[revision].xml";
 
30
 
 
31
    private static final String DEFAULT_CACHE_RESOLVED_IVY_PROPERTIES_PATTERN = 
 
32
        "resolved-[organisation]-[module]-[revision].properties";
 
33
 
 
34
 
 
35
    private String resolvedIvyPattern = DEFAULT_CACHE_RESOLVED_IVY_PATTERN;
 
36
 
 
37
    private String resolvedIvyPropertiesPattern = 
 
38
        DEFAULT_CACHE_RESOLVED_IVY_PROPERTIES_PATTERN;
 
39
    
 
40
    private File basedir;
 
41
 
 
42
    private String name = "resolution-cache"; 
 
43
 
 
44
    public DefaultResolutionCacheManager() {
 
45
    }
 
46
    
 
47
    public DefaultResolutionCacheManager(File basedir) {
 
48
        setBasedir(basedir);
 
49
    }
 
50
 
 
51
    public File getResolutionCacheRoot() {
 
52
        return basedir;
 
53
    }
 
54
    
 
55
    public File getBasedir() {
 
56
        return basedir;
 
57
    }
 
58
 
 
59
    public void setBasedir(File basedir) {
 
60
        this.basedir = basedir;
 
61
    }
 
62
 
 
63
    public String getResolvedIvyPattern() {
 
64
        return resolvedIvyPattern;
 
65
    }
 
66
 
 
67
    public void setResolvedIvyPattern(String cacheResolvedIvyPattern) {
 
68
        this.resolvedIvyPattern = cacheResolvedIvyPattern;
 
69
    }
 
70
 
 
71
    public String getResolvedIvyPropertiesPattern() {
 
72
        return resolvedIvyPropertiesPattern;
 
73
    }
 
74
 
 
75
    public void setResolvedIvyPropertiesPattern(String cacheResolvedIvyPropertiesPattern) {
 
76
        this.resolvedIvyPropertiesPattern = cacheResolvedIvyPropertiesPattern;
 
77
    }
 
78
 
 
79
    public String getName() {
 
80
        return name;
 
81
    }
 
82
 
 
83
    public void setName(String name) {
 
84
        this.name = name;
 
85
    }
 
86
 
 
87
 
 
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);
 
92
    }
 
93
 
 
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);
 
98
    }
 
99
 
 
100
    public File getConfigurationResolveReportInCache(String resolveId, String conf) {
 
101
        return new File(getResolutionCacheRoot(), resolveId + "-" + conf + ".xml");
 
102
    }
 
103
 
 
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));
 
110
            }
 
111
        });
 
112
    }
 
113
 
 
114
    public String toString() {
 
115
        return name;
 
116
    }
 
117
 
 
118
    public void clean() {
 
119
        FileUtil.forceDelete(getBasedir());
 
120
    }
 
121
 
 
122
}