| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| nl.toolforge.karma.core.cmd.util.BuildUtil |
|
|
| 1 | /* |
|
| 2 | Karma core - Core of the Karma application |
|
| 3 | Copyright (C) 2004 Toolforge <www.toolforge.nl> |
|
| 4 | ||
| 5 | This library is free software; you can redistribute it and/or |
|
| 6 | modify it under the terms of the GNU Lesser General Public |
|
| 7 | License as published by the Free Software Foundation; either |
|
| 8 | version 2.1 of the License, or (at your option) any later version. |
|
| 9 | ||
| 10 | This library is distributed in the hope that it will be useful, |
|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 13 | Lesser General Public License for more details. |
|
| 14 | ||
| 15 | You should have received a copy of the GNU Lesser General Public |
|
| 16 | License along with this library; if not, write to the Free Software |
|
| 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 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 | // todo MOVE TO AbstractBuildCommand after ample consideration ... |
|
| 42 | ||
| 43 | // private static final String DEFAULT_BUILD_DIR = "build"; |
|
| 44 | ||
| 45 | 0 | private Manifest currentManifest = null; |
| 46 | ||
| 47 | 0 | public BuildUtil(Manifest currentManifest) { |
| 48 | 0 | this.currentManifest = currentManifest; |
| 49 | 0 | } |
| 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 | // todo proper exception handling --> CommandException ???? |
|
| 61 | ||
| 62 | // Get all modules that depend on this module. |
|
| 63 | // |
|
| 64 | 0 | Collection interDeps = currentManifest.getModuleInterdependencies(module); |
| 65 | ||
| 66 | 0 | for (Iterator i = interDeps.iterator(); i.hasNext();) { |
| 67 | ||
| 68 | 0 | Module dep = (Module) i.next(); |
| 69 | ||
| 70 | 0 | if (currentManclass="keyword">ifest.getInterdependencies().containsKey(dep.getName())) { |
| 71 | 0 | cleanDependencies(dep); |
| 72 | } |
|
| 73 | // No interdependencies found for the dependency, so we remove its build-directory. |
|
| 74 | // |
|
| 75 | try { |
|
| 76 | 0 | File buildDir = new File(currentManifest.getBuildBaseDirectory(), dep.getName()); |
| 77 | ||
| 78 | 0 | FileUtils.deleteDirectory(buildDir); |
| 79 | ||
| 80 | 0 | } catch (IOException e) { |
| 81 | 0 | throw new KarmaRuntimeException(e.getMessage()); |
| 82 | 0 | } |
| 83 | } |
|
| 84 | 0 | } |
| 85 | ||
| 86 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |