1 package net.sf.invicta.handler; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 import java.util.Map ; 7 8 import net.sf.invicta.InvictaConstants; 9 import net.sf.invicta.InvictaException; 10 import net.sf.invicta.api.InvictaComponent; 11 12 import org.apache.commons.lang.StringUtils; 13 14 21 public class DependListHandler extends InvictaBasicHandler { 22 23 private final static String INIT_TARGET_ALIAS = "INIT"; 24 private final static String BUILD_TARGET_ALIAS = "BUILD"; 25 private final static String CLEAN_TARGET_ALIAS = "CLEAN"; 26 private final static String DIST_TARGET_ALIAS = "DIST"; 27 private final static String DEFAULT_EMPTY_LIST = "init"; 28 private final static String DEFAULT_DEPEND_TARGET = BUILD_TARGET_ALIAS; 29 private final static boolean DEFAULT_USE_ALL = false; 30 private final static boolean DEFAULT_EXCLUDE_MODE = false; 31 private final static String EXCLUDE_COMPONENT_PROPERTY = "exclude"; 32 private final static boolean DEFAULT_EXCLUDE_COMPONENT = false; 33 34 37 public String getName() { 38 return "dependList"; 39 } 40 41 44 public String handle(Map paramsMap) throws InvictaException { 45 46 String dependTarget = getParameter("target", DEFAULT_DEPEND_TARGET); 47 boolean all = getBooleanParameter("all", DEFAULT_USE_ALL); 48 boolean exclude = getBooleanParameter("exclude", DEFAULT_EXCLUDE_MODE); 49 return prepareDependList(all, dependTarget, exclude); 50 } 51 52 55 public String handle(List params) throws InvictaException { 56 return prepareDependList(DEFAULT_USE_ALL, DEFAULT_DEPEND_TARGET, DEFAULT_EXCLUDE_MODE); 57 } 58 59 62 protected String prepareDependList(boolean all, String dependTarget, boolean exclude) { 63 List resultDependList = new ArrayList (); 64 String dependList = ""; 65 List componentList; 66 if (all) { 67 componentList = getProject().getComponents(); 68 } else { 69 componentList = getComponent().getDependComponents(); 70 } 71 72 for (Iterator iter = componentList.iterator(); iter.hasNext();) { 73 InvictaComponent dependentComponent = (InvictaComponent) iter.next(); 74 75 if ((exclude) && (excludeComponent(dependentComponent))) 76 continue; 77 78 String fullDependTarget = dependentComponent.getName() + InvictaConstants.TARGET_DELIMITER; 79 if (dependTarget.equals(INIT_TARGET_ALIAS)) 80 fullDependTarget += dependentComponent.getInitTarget(); 81 else if (dependTarget.equals(BUILD_TARGET_ALIAS)) 82 fullDependTarget += dependentComponent.getBuildTarget(); 83 else if (dependTarget.equals(CLEAN_TARGET_ALIAS)) 84 fullDependTarget += dependentComponent.getCleanTarget(); 85 else if (dependTarget.equals(DIST_TARGET_ALIAS)) 86 fullDependTarget += dependentComponent.getDistTarget(); 87 else { 88 if (!dependentComponent.containsTarget(dependTarget)) 90 continue; 91 fullDependTarget += dependTarget; 92 } 93 94 resultDependList.add(fullDependTarget); 95 } 96 97 String result = StringUtils.join(resultDependList.iterator(), InvictaConstants.DEPEND_LIST_DELIMITER); 98 if (result.length() == 0) { 99 return getComponent().getName() + 100 InvictaConstants.TARGET_DELIMITER + DEFAULT_EMPTY_LIST; 101 } 102 103 return result; 104 } 105 106 109 protected boolean excludeComponent(InvictaComponent dependentComponent) { 110 String propertyValue = dependentComponent.getPropertyValue(EXCLUDE_COMPONENT_PROPERTY); 113 boolean excludeComponentValue = DEFAULT_EXCLUDE_COMPONENT; 114 if (propertyValue != null) 115 excludeComponentValue = Boolean.valueOf(propertyValue).booleanValue(); 116 return excludeComponentValue; 117 } 118 119 } 120 | Popular Tags |