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.core.resolve;
019:
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Date;
023: import java.util.Iterator;
024: import java.util.LinkedHashMap;
025: import java.util.Map;
026: import java.util.Map.Entry;
027:
028: import org.apache.ivy.core.cache.RepositoryCacheManager;
029: import org.apache.ivy.core.event.EventManager;
030: import org.apache.ivy.core.module.id.ModuleRevisionId;
031: import org.apache.ivy.core.report.ConfigurationResolveReport;
032:
033: public class ResolveData {
034: private ResolveEngine engine;
035:
036: private Map visitData; // shared map of all visit data: Map (ModuleRevisionId -> VisitData)
037:
038: private ConfigurationResolveReport report;
039:
040: private ResolveOptions options;
041:
042: public ResolveData(ResolveData data, boolean validate) {
043: this (data.engine, new ResolveOptions(data.options)
044: .setValidate(validate), data.report, data.visitData);
045: }
046:
047: public ResolveData(ResolveEngine engine, ResolveOptions options) {
048: this (engine, options, null, new LinkedHashMap());
049: }
050:
051: public ResolveData(ResolveEngine engine, ResolveOptions options,
052: ConfigurationResolveReport report) {
053: this (engine, options, report, new LinkedHashMap());
054: }
055:
056: public ResolveData(ResolveEngine engine, ResolveOptions options,
057: ConfigurationResolveReport report, Map visitData) {
058: this .engine = engine;
059: this .report = report;
060: this .visitData = visitData;
061: this .options = options;
062: }
063:
064: public ConfigurationResolveReport getReport() {
065: return report;
066: }
067:
068: public IvyNode getNode(ModuleRevisionId mrid) {
069: VisitData visitData = getVisitData(mrid);
070: return visitData == null ? null : visitData.getNode();
071: }
072:
073: public Collection getNodes() {
074: Collection nodes = new ArrayList();
075: for (Iterator iter = visitData.values().iterator(); iter
076: .hasNext();) {
077: VisitData vdata = (VisitData) iter.next();
078: nodes.add(vdata.getNode());
079: }
080: return nodes;
081: }
082:
083: public Collection getNodeIds() {
084: return visitData.keySet();
085: }
086:
087: public VisitData getVisitData(ModuleRevisionId mrid) {
088: return (VisitData) visitData.get(mrid);
089: }
090:
091: public void register(VisitNode node) {
092: register(node.getId(), node);
093: }
094:
095: public void register(ModuleRevisionId mrid, VisitNode node) {
096: VisitData visitData = getVisitData(mrid);
097: if (visitData == null) {
098: visitData = new VisitData(node.getNode());
099: visitData.addVisitNode(node);
100: this .visitData.put(mrid, visitData);
101: } else {
102: visitData.setNode(node.getNode());
103: visitData.addVisitNode(node);
104: }
105: }
106:
107: /**
108: * Updates the visit data currently associated with the given mrid with the given node and the
109: * visit nodes of the old visitData for the given rootModuleConf
110: *
111: * @param mrid
112: * the module revision id for which the update should be done
113: * @param node
114: * the IvyNode to associate with the visit data to update
115: * @param rootModuleConf
116: * the root module configuration in which the update is made
117: */
118: void replaceNode(ModuleRevisionId mrid, IvyNode node,
119: String rootModuleConf) {
120: VisitData visitData = getVisitData(mrid);
121: if (visitData == null) {
122: throw new IllegalArgumentException(
123: "impossible to replace node for id " + mrid
124: + ". No registered node found.");
125: }
126: VisitData keptVisitData = getVisitData(node.getId());
127: if (keptVisitData == null) {
128: throw new IllegalArgumentException(
129: "impossible to replace node with " + node
130: + ". No registered node found for "
131: + node.getId() + ".");
132: }
133: // replace visit data in Map (discards old one)
134: this .visitData.put(mrid, keptVisitData);
135: // update visit data with discarde visit nodes
136: keptVisitData.addVisitNodes(rootModuleConf, visitData
137: .getVisitNodes(rootModuleConf));
138: }
139:
140: public void setReport(ConfigurationResolveReport report) {
141: this .report = report;
142: }
143:
144: public Date getDate() {
145: return options.getDate();
146: }
147:
148: public boolean isValidate() {
149: return options.isValidate();
150: }
151:
152: public boolean isTransitive() {
153: return options.isTransitive();
154: }
155:
156: public ResolveOptions getOptions() {
157: return options;
158: }
159:
160: public ResolveEngineSettings getSettings() {
161: return engine.getSettings();
162: }
163:
164: public EventManager getEventManager() {
165: return engine.getEventManager();
166: }
167:
168: public ResolveEngine getEngine() {
169: return engine;
170: }
171:
172: void blacklist(IvyNode node) {
173: for (Iterator iter = visitData.entrySet().iterator(); iter
174: .hasNext();) {
175: Entry entry = (Entry) iter.next();
176: VisitData vdata = (VisitData) entry.getValue();
177: if (vdata.getNode() == node
178: && !node.getResolvedId().equals(entry.getKey())) {
179: // this visit data was associated with the blacklisted node,
180: // we discard this association
181: iter.remove();
182: }
183: }
184: }
185:
186: public boolean isBlacklisted(String rootModuleConf,
187: ModuleRevisionId mrid) {
188: IvyNode node = getNode(mrid);
189: return node != null && node.isBlacklisted(rootModuleConf);
190: }
191:
192: }
|