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.ant;
019:
020: import java.io.File;
021: import java.net.MalformedURLException;
022: import java.util.ArrayList;
023: import java.util.List;
024:
025: import org.apache.ivy.Ivy;
026: import org.apache.ivy.util.Message;
027: import org.apache.tools.ant.BuildException;
028: import org.apache.tools.ant.DirectoryScanner;
029: import org.apache.tools.ant.types.FileSet;
030:
031: /**
032: * Checks the given ivy file using current configuration to see if all dependencies are available,
033: * with good confs. If a resolver name is given, it also checks that the declared publications are
034: * available in the corresponding resolver. Note that the check is not performed recursively, i.e.
035: * if a dependency has itself dependencies badly described or not available, this check will not
036: * discover it.
037: */
038: public class IvyCheck extends IvyTask {
039: private File file = null;
040:
041: private List filesets = new ArrayList();
042:
043: private String resolvername;
044:
045: public File getFile() {
046: return file;
047: }
048:
049: public void setFile(File file) {
050: this .file = file;
051: }
052:
053: /**
054: * Adds a set of files to check.
055: *
056: * @param set
057: * a set of files to check
058: */
059: public void addFileset(FileSet set) {
060: filesets.add(set);
061: }
062:
063: public String getResolvername() {
064: return resolvername;
065: }
066:
067: public void setResolvername(String resolverName) {
068: resolvername = resolverName;
069: }
070:
071: public void doExecute() throws BuildException {
072: try {
073: Ivy ivy = getIvyInstance();
074: if (file != null) {
075: if (ivy.check(file.toURL(), resolvername)) {
076: Message.verbose("checked " + file + ": OK");
077: }
078: }
079: for (int i = 0; i < filesets.size(); i++) {
080: FileSet fs = (FileSet) filesets.get(i);
081: DirectoryScanner ds = fs
082: .getDirectoryScanner(getProject());
083:
084: File fromDir = fs.getDir(getProject());
085:
086: String[] srcFiles = ds.getIncludedFiles();
087: for (int j = 0; j < srcFiles.length; j++) {
088: File file = new File(fromDir, srcFiles[j]);
089: if (ivy.check(file.toURL(), resolvername)) {
090: Message.verbose("checked " + file + ": OK");
091: }
092: }
093: }
094: } catch (MalformedURLException e) {
095: throw new BuildException(
096: "impossible to convert a file to an url! " + e, e);
097: }
098: }
099:
100: }
|