1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package nl.toolforge.karma.core.cmd.util;
20
21 import nl.toolforge.karma.core.KarmaRuntimeException;
22 import nl.toolforge.karma.core.manifest.Manifest;
23 import nl.toolforge.karma.core.manifest.ManifestException;
24 import nl.toolforge.karma.core.module.Module;
25 import org.apache.commons.io.FileUtils;
26
27 import java.io.File;
28 import java.io.IOException;
29 import java.util.Collection;
30 import java.util.Iterator;
31
32 /***
33 * Validates a modules' dependencies by checking if the actual artifacts already exists on a local disk.
34 *
35 *
36 * @author D.A. Smedes
37 * @version $Id: BuildUtil.java,v 1.6 2004/11/10 23:53:09 asmedes Exp $
38 */
39 public final class BuildUtil {
40
41
42
43
44
45 private Manifest currentManifest = null;
46
47 public BuildUtil(Manifest currentManifest) {
48 this.currentManifest = currentManifest;
49 }
50
51 /***
52 * Cleans a modules' dependencies, by (recursively) traversing all modules that depend on <code>module</code> and
53 * cleaning their <code>build</code>-directories.
54 *
55 * @param module The (root)-module for which dependencies should be cleaned.
56 * //@param modules All modules that have a dependency on <code>module</code>.
57 */
58 public void cleanDependencies(Module module) throws ManifestException {
59
60
61
62
63
64 Collection interDeps = currentManifest.getModuleInterdependencies(module);
65
66 for (Iterator i = interDeps.iterator(); i.hasNext();) {
67
68 Module dep = (Module) i.next();
69
70 if (currentManifest.getInterdependencies().containsKey(dep.getName())) {
71 cleanDependencies(dep);
72 }
73
74
75 try {
76 File buildDir = new File(currentManifest.getBuildBaseDirectory(), dep.getName());
77
78 FileUtils.deleteDirectory(buildDir);
79
80 } catch (IOException e) {
81 throw new KarmaRuntimeException(e.getMessage());
82 }
83 }
84 }
85
86 }