Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2b91c3e6c1dbe2da14dac07757cf7f36c5b4fa25 (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
/******************************************************************************* 
* Copyright (c) 2009, 2017 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.internal.repository.tools.analyzer;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.tools.analyzer.IIUAnalyzer;

/**
 * This service just counts the total number of IUs
 */
public class IUCounting implements IIUAnalyzer {

	int totalIUs = 0;
	int totalGroups = 0;
	int totalFragments = 0;
	int totalCategories = 0;

	private boolean hasProperty(IInstallableUnit iu, String property) {
		return Boolean.parseBoolean(iu.getProperty(property));
	}

	@Override
	public void analyzeIU(IInstallableUnit iu) {
		totalIUs++;
		if (hasProperty(iu, InstallableUnitDescription.PROP_TYPE_FRAGMENT))
			totalFragments++;
		if (hasProperty(iu, InstallableUnitDescription.PROP_TYPE_GROUP))
			totalGroups++;
		if (hasProperty(iu, InstallableUnitDescription.PROP_TYPE_CATEGORY))
			totalCategories++;
	}

	@Override
	public IStatus postAnalysis() {
		System.out.println("Total IUs: " + totalIUs);
		System.out.println("  Total Groups: " + totalGroups);
		System.out.println("  Total Fragments: " + totalFragments);
		System.out.println("  Total Categories: " + totalCategories);
		return null;
	}

	@Override
	public void preAnalysis(IMetadataRepository repo) {
		totalIUs = 0;
		totalGroups = 0;
		totalFragments = 0;
		totalCategories = 0;
	}

}

Back to the top