2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.ivy.plugins.circular;
20
import java.util.HashSet;
21
import java.util.Iterator;
22
import java.util.List;
25
import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
26
import org.apache.ivy.core.module.id.ModuleRevisionId;
28
public final class CircularDependencyHelper {
30
/** CircularDependencyHelper is not designed to be an instance */
31
private CircularDependencyHelper() {
36
* Returns a string representation of this circular dependency graph
39
* in order of circular dependency
40
* @return a string representation of this circular dependency graph
42
public static String formatMessage(final ModuleRevisionId[] mrids) {
43
Set alreadyAdded = new HashSet();
44
StringBuffer buff = new StringBuffer();
45
buff.append(mrids[0]);
46
alreadyAdded.add(mrids[0]);
47
for (int i = 1; i < mrids.length; i++) {
49
if (alreadyAdded.add(mrids[i])) {
50
buff.append(mrids[i]);
56
return buff.toString();
59
public static String formatMessage(final ModuleDescriptor[] descriptors) {
60
return formatMessage(toMrids(descriptors));
65
* a List<ModuleDescriptor>
67
public static String formatMessageFromDescriptors(List loopElements) {
68
ModuleRevisionId[] mrids = new ModuleRevisionId[loopElements.size()];
70
for (Iterator it = loopElements.iterator(); it.hasNext();) {
71
ModuleDescriptor descriptor = (ModuleDescriptor) it.next();
72
mrids[pos] = descriptor.getModuleRevisionId();
75
return formatMessage(mrids);
78
public static ModuleRevisionId[] toMrids(ModuleDescriptor[] descriptors) {
79
ModuleRevisionId[] mrids = new ModuleRevisionId[descriptors.length];
80
for (int i = 0; i < descriptors.length; i++) {
81
mrids[i] = descriptors[i].getModuleRevisionId();