EMMA Coverage Report (generated Thu Nov 26 15:54:18 CST 2009)
[all classes][org.eclipse.pde.api.tools.internal.search]

COVERAGE SUMMARY FOR SOURCE FILE [SkippedComponent.java]

nameclass, %method, %block, %line, %
SkippedComponent.java100% (2/2)94%  (16/17)92%  (174/189)93%  (41/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SkippedComponent$1100% (1/1)50%  (1/2)55%  (6/11)67%  (2/3)
compare (Object, Object): int 0%   (0/1)0%   (0/5)0%   (0/1)
SkippedComponent$1 (SkippedComponent): void 100% (1/1)100% (6/6)100% (2/2)
     
class SkippedComponent100% (1/1)100% (15/15)94%  (168/178)95%  (40/42)
resolveRootErrors (ResolverError []): String [] 100% (1/1)88%  (70/80)87%  (13/15)
SkippedComponent (String, String, ResolverError []): void 100% (1/1)100% (15/15)100% (6/6)
equals (Object): boolean 100% (1/1)100% (12/12)100% (3/3)
getAncestor (int): IApiElement 100% (1/1)100% (2/2)100% (1/1)
getApiComponent (): IApiComponent 100% (1/1)100% (2/2)100% (1/1)
getComponentId (): String 100% (1/1)100% (3/3)100% (1/1)
getErrorDetails (): String 100% (1/1)100% (33/33)100% (7/7)
getErrors (): ResolverError [] 100% (1/1)100% (3/3)100% (1/1)
getName (): String 100% (1/1)100% (3/3)100% (1/1)
getParent (): IApiElement 100% (1/1)100% (2/2)100% (1/1)
getType (): int 100% (1/1)100% (2/2)100% (1/1)
getVersion (): String 100% (1/1)100% (3/3)100% (1/1)
hasResolutionErrors (): boolean 100% (1/1)100% (7/7)100% (1/1)
hashCode (): int 100% (1/1)100% (4/4)100% (1/1)
wasExcluded (): boolean 100% (1/1)100% (7/7)100% (1/1)

1/*******************************************************************************
2 * Copyright (c) 2009 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.pde.api.tools.internal.search;
12 
13import java.util.Comparator;
14import java.util.TreeSet;
15 
16import org.eclipse.osgi.service.resolver.BundleDescription;
17import org.eclipse.osgi.service.resolver.ResolverError;
18import org.eclipse.osgi.service.resolver.VersionConstraint;
19import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
20import org.eclipse.pde.api.tools.internal.provisional.model.IApiElement;
21 
22 
23public class SkippedComponent implements IApiElement{
24        /**
25         * the id of of the skipped component
26         */
27        private String componentid;
28        /**
29         * The version of the component 
30         */
31        private String version;
32        /**
33         * the set of resolution errors barring the component from being scanned
34         */
35        private ResolverError[] errors = null;
36 
37        /**
38         * Constructor
39         * @param componentid
40         * @param version
41         * @param errors the {@link ResolverError}s, if any, that prevented this component from being scanned
42         */
43        public SkippedComponent(String componentid, String version, ResolverError[] errors) {
44                this.componentid = componentid;
45                this.version = version;
46                this.errors = errors;
47        }
48        
49        /* (non-Javadoc)
50         * @see java.lang.Object#equals(java.lang.Object)
51         */
52        public boolean equals(Object obj) {
53                if(obj instanceof SkippedComponent) {
54                        return this.componentid.equals(((SkippedComponent)obj).componentid);
55                }
56                return false;
57        }
58        
59        /* (non-Javadoc)
60         * @see java.lang.Object#hashCode()
61         */
62        public int hashCode() {
63                return this.componentid.hashCode();
64        }
65        
66        /**
67         * @return the component id of the skipped component
68         */
69        public String getComponentId() {
70                return this.componentid;
71        }
72        
73        /**
74         * @return true if the component was skipped because it appeared in an exclude list
75         */
76        public boolean wasExcluded() {
77                return this.errors == null;
78        }
79        
80        /**
81         * @return true if the the component had resolution errors
82         */
83        public boolean hasResolutionErrors() {
84                return this.errors != null;
85        }
86 
87        /**
88         * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiElement#getAncestor(int)
89         */
90        public IApiElement getAncestor(int ancestorType) {
91                return null;
92        }
93 
94        /**
95         * @return the version
96         */
97        public String getVersion() {
98                return this.version;
99        }
100        
101        /**
102         * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiElement#getApiComponent()
103         */
104        public IApiComponent getApiComponent() {
105                return null;
106        }
107 
108        /**
109         * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiElement#getName()
110         */
111        public String getName() {
112                return this.componentid;
113        }
114 
115        /**
116         * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiElement#getParent()
117         */
118        public IApiElement getParent() {
119                return null;
120        }
121 
122        /**
123         * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiElement#getType()
124         */
125        public int getType() {
126                return IApiElement.COMPONENT;
127        }
128        
129        /**
130         * @return the errors
131         */
132        public ResolverError[] getErrors() {
133                return this.errors;
134        }
135        
136        /**
137         * Resolves the root errors for the given set of errors
138         * @param errors
139         * @param collector
140         * @return the resolved leaf set of problem messages
141         */
142        private String[] resolveRootErrors(ResolverError[] errors) {
143                TreeSet collector = new TreeSet(new Comparator() {
144                        public int compare(Object o1, Object o2) {
145                                return ((String)o1).compareTo(o2);
146                        }
147                });
148                ResolverError error = null;
149                VersionConstraint[] constraints = null;
150                BundleDescription[] bundle = new BundleDescription[1];
151                for (int i = 0; i < errors.length; i++) {
152                        error = errors[i];
153                        if(error.getType() != ResolverError.MISSING_REQUIRE_BUNDLE) {
154                                collector.add(error.toString());
155                        }
156                        bundle[0] = error.getBundle();
157                        constraints = bundle[0].getContainingState().getStateHelper().getUnsatisfiedLeaves(bundle);
158                        if(constraints.length == 0) {
159                                collector.add(error.toString());
160                        }
161                        for (int j = 0; j < constraints.length; j++) {
162                                collector.add(constraints[j].toString());
163                        }
164                }
165                return (String[]) collector.toArray(new String[collector.size()]);
166        }
167        
168        /**
169         * @return the formatted details of why the component was skipped
170         */
171        public String getErrorDetails() {
172                if(this.errors != null) {
173                        StringBuffer buffer = new StringBuffer();
174                        String[] problems = resolveRootErrors(this.errors);
175                        for (int i = 0; i < problems.length; i++) {
176                                buffer.append(problems[i]).append("<br/>"); //$NON-NLS-1$
177                        }
178                        return buffer.toString();
179                }
180                return SearchMessages.SkippedComponent_component_was_excluded;
181        }
182}

[all classes][org.eclipse.pde.api.tools.internal.search]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov