Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3c650293d3c017c1d15bab1808f513ffb0e9313a (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
/******************************************************************************* 
* 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.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.tools.analyzer.IUAnalyzer;

/**
 * This service checks that each IU has a proper version number
 *  1. No 0.0.0
 *  2. No x.y.z.qualifier (each qualifier has been replaced)
 */
public class VersionAnalyzer extends IUAnalyzer {

	@Override
	public void analyzeIU(IInstallableUnit iu) {
		if (iu.getVersion().equals(Version.emptyVersion)) {
			error(iu, "[ERROR] IU: " + iu.getId() + " has not replaced its qualifiier");
			return;
		}
		if (iu.getVersion().isOSGiCompatible()) {
			String qualifier = toOSGiVersion(iu.getVersion()).getQualifier();
			if (qualifier != null && qualifier.equals("qualifier")) {
				error(iu, "[ERROR] IU: " + iu.getId() + " has not replaced its qualifiier");
				return;
			}
		}
	}

	private static org.osgi.framework.Version toOSGiVersion(Version version) {
		if (version == null)
			return null;
		if (version == Version.emptyVersion)
			return org.osgi.framework.Version.emptyVersion;
		if (version == Version.MAX_VERSION)
			return new org.osgi.framework.Version(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);

		return new org.osgi.framework.Version(version.toString());
	}

	@Override
	public void preAnalysis(IMetadataRepository repo) {
		// Do nothing
	}

}

Back to the top