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

« back to all changes in this revision

Viewing changes to src/java/org/apache/ivy/ant/IvyCheck.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.ant;
 
19
 
 
20
import java.io.File;
 
21
import java.net.MalformedURLException;
 
22
import java.util.ArrayList;
 
23
import java.util.List;
 
24
 
 
25
import org.apache.ivy.Ivy;
 
26
import org.apache.ivy.util.Message;
 
27
import org.apache.tools.ant.BuildException;
 
28
import org.apache.tools.ant.DirectoryScanner;
 
29
import org.apache.tools.ant.types.FileSet;
 
30
 
 
31
/**
 
32
 * Checks the given ivy file using current configuration to see if all dependencies are available,
 
33
 * with good confs. If a resolver name is given, it also checks that the declared publications are
 
34
 * available in the corresponding resolver. Note that the check is not performed recursively, i.e.
 
35
 * if a dependency has itself dependencies badly described or not available, this check will not
 
36
 * discover it.
 
37
 */
 
38
public class IvyCheck extends IvyTask {
 
39
    private File file = null;
 
40
 
 
41
    private List filesets = new ArrayList();
 
42
 
 
43
    private String resolvername;
 
44
 
 
45
    public File getFile() {
 
46
        return file;
 
47
    }
 
48
 
 
49
    public void setFile(File file) {
 
50
        this.file = file;
 
51
    }
 
52
 
 
53
    /**
 
54
     * Adds a set of files to check.
 
55
     * 
 
56
     * @param set
 
57
     *            a set of files to check
 
58
     */
 
59
    public void addFileset(FileSet set) {
 
60
        filesets.add(set);
 
61
    }
 
62
 
 
63
    public String getResolvername() {
 
64
        return resolvername;
 
65
    }
 
66
 
 
67
    public void setResolvername(String resolverName) {
 
68
        resolvername = resolverName;
 
69
    }
 
70
 
 
71
    public void doExecute() throws BuildException {
 
72
        try {
 
73
            Ivy ivy = getIvyInstance();
 
74
            if (file != null) {
 
75
                if (ivy.check(file.toURI().toURL(), resolvername)) {
 
76
                    Message.verbose("checked " + file + ": OK");
 
77
                }
 
78
            }
 
79
            for (int i = 0; i < filesets.size(); i++) {
 
80
                FileSet fs = (FileSet) filesets.get(i);
 
81
                DirectoryScanner ds = fs.getDirectoryScanner(getProject());
 
82
 
 
83
                File fromDir = fs.getDir(getProject());
 
84
 
 
85
                String[] srcFiles = ds.getIncludedFiles();
 
86
                for (int j = 0; j < srcFiles.length; j++) {
 
87
                    File file = new File(fromDir, srcFiles[j]);
 
88
                    if (ivy.check(file.toURI().toURL(), resolvername)) {
 
89
                        Message.verbose("checked " + file + ": OK");
 
90
                    }
 
91
                }
 
92
            }
 
93
        } catch (MalformedURLException e) {
 
94
            throw new BuildException("impossible to convert a file to an url! " + e, e);
 
95
        }
 
96
    }
 
97
 
 
98
}