Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 446f0571cffa49af042db6d815c49cf60c1ada30 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/******************************************************************************* 
* Copyright (c) 2009,2010 EclipseSource and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*   EclipseSource - initial API and implementation
******************************************************************************/
package org.eclipse.equinox.p2.repository.tools.analyzer;

import java.util.Iterator;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.p2.internal.repository.tools.Activator;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;

/**
 * @since 2.0
 *
 */
public class RepositoryAnalyzer {

	private final IMetadataRepository[] repositories;

	public RepositoryAnalyzer(IMetadataRepository[] repositories) {
		this.repositories = repositories;
	}

	public IStatus analyze(IProgressMonitor monitor) {
		MultiStatus result = new MultiStatus(Activator.ID, IStatus.OK, null, null);

		SubMonitor sub = SubMonitor.convert(monitor, repositories.length * 2);
		IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(IIUAnalyzer.ID);

		for (int i = 0; i < repositories.length; i++) {
			IQueryResult<IInstallableUnit> queryResult = repositories[i].query(InstallableUnitQuery.ANY, sub);

			SubMonitor repositoryMonitor = SubMonitor.convert(sub, IProgressMonitor.UNKNOWN);
			for (int j = 0; j < config.length; j++) {
				try {
					IIUAnalyzer verifier = (IIUAnalyzer) config[j].createExecutableExtension("class"); //$NON-NLS-1$
					String analyizerName = config[j].getAttribute("name"); //$NON-NLS-1$
					if (verifier instanceof IUAnalyzer) {
						((IUAnalyzer) verifier).setName(analyizerName);
					}
					verifier.preAnalysis(repositories[i]);
					Iterator<IInstallableUnit> iter = queryResult.iterator();
					while (iter.hasNext()) {
						IInstallableUnit iu = iter.next();
						verifier.analyzeIU(iu);
					}
					IStatus postAnalysisResult = verifier.postAnalysis();
					if (postAnalysisResult == null)
						postAnalysisResult = new Status(IStatus.OK, Activator.ID, analyizerName);
					if (postAnalysisResult.isOK() && !postAnalysisResult.isMultiStatus())
						postAnalysisResult = new Status(IStatus.OK, Activator.ID, analyizerName);
					result.add(postAnalysisResult);
				} catch (CoreException e) {
					if (e.getCause() instanceof ClassNotFoundException) {
						result.add(new Status(IStatus.ERROR, Activator.ID, "Cannot find: " + config[j].getAttribute("class")));
					} else
						e.printStackTrace();
				}
			}
			repositoryMonitor.done();
		}
		sub.done();
		return result;
	}
}

Back to the top