/** * Loads a {@link FlowScript} with the specified ID. * * @param properties source properties * @param flowId the target flow ID * @return the loaded script * @throws IllegalArgumentException if script is invalid, or some parameters were {@code null} * @see #extractFlowIds(Properties) */ public static FlowScript load(Properties properties, String flowId) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); // $NON-NLS-1$ } if (flowId == null) { throw new IllegalArgumentException("flowId must not be null"); // $NON-NLS-1$ } String prefix = getPrefix(flowId); LOG.debug("Loading execution scripts: {}*", prefix); NavigableMap<String, String> flowMap = PropertiesUtil.createPrefixMap(properties, prefix); String blockersString = extract(flowMap, prefix, KEY_BLOCKERS); Set<String> blockerIds = parseTokens(blockersString); EnumMap<ExecutionPhase, List<ExecutionScript>> scripts = new EnumMap<ExecutionPhase, List<ExecutionScript>>(ExecutionPhase.class); for (ExecutionPhase phase : ExecutionPhase.values()) { scripts.put(phase, Collections.<ExecutionScript>emptyList()); } int count = 0; Map<String, NavigableMap<String, String>> phaseMap = partitioning(flowMap); for (Map.Entry<String, NavigableMap<String, String>> entry : phaseMap.entrySet()) { String phaseSymbol = entry.getKey(); NavigableMap<String, String> phaseContents = entry.getValue(); ExecutionPhase phase = ExecutionPhase.findFromSymbol(phaseSymbol); if (phase == null) { throw new IllegalArgumentException( MessageFormat.format("Unknown phase in \"{0}\": {1}", flowId, phaseSymbol)); } List<ExecutionScript> scriptsInPhase = loadScripts(flowId, phase, phaseContents); scripts.put(phase, scriptsInPhase); count += scriptsInPhase.size(); } FlowScript script = new FlowScript(flowId, blockerIds, scripts); LOG.debug("Loaded {} execution scripts: {}*", count, prefix); LOG.trace("Loaded {}*: {}", prefix, script); return script; }
/** * Creates a new instance. * * @param id the flow ID * @param blockerIds the predecessors' flow ID * @param scripts the execution scripts for each {@link ExecutionPhase} * @throws IllegalArgumentException if some parameters were {@code null} */ public FlowScript( String id, Set<String> blockerIds, Map<ExecutionPhase, ? extends Collection<? extends ExecutionScript>> scripts) { if (id == null) { throw new IllegalArgumentException("id must not be null"); // $NON-NLS-1$ } if (id.indexOf('.') >= 0) { throw new IllegalArgumentException("id must not contain dot"); // $NON-NLS-1$ } if (blockerIds == null) { throw new IllegalArgumentException("blockerIds must not be null"); // $NON-NLS-1$ } if (scripts == null) { throw new IllegalArgumentException("scripts must not be null"); // $NON-NLS-1$ } this.id = id; this.blockerIds = Collections.unmodifiableSet(new LinkedHashSet<String>(blockerIds)); EnumMap<ExecutionPhase, Set<ExecutionScript>> map = new EnumMap<ExecutionPhase, Set<ExecutionScript>>(ExecutionPhase.class); for (ExecutionPhase phase : ExecutionPhase.values()) { if (scripts.containsKey(phase)) { TreeSet<ExecutionScript> set = new TreeSet<ExecutionScript>(SCRIPT_COMPARATOR); set.addAll(scripts.get(phase)); if (set.size() != scripts.get(phase).size()) { throw new IllegalArgumentException( MessageFormat.format("{0}@{1} contains duplicated IDs in scripts", id, phase)); } map.put(phase, Collections.unmodifiableSet(set)); } else { map.put(phase, Collections.<ExecutionScript>emptySet()); } } this.scripts = Collections.unmodifiableMap(map); }
private static String getPrefix(String flowId, ExecutionPhase phase) { assert flowId != null; assert phase != null; return getPrefix(flowId) + phase.getSymbol() + '.'; }