blob: 68b637b5cf518d3dc5ddcc49436733e94d6001b6 (
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/*******************************************************************************
* Copyright (c) 2007 Innoopract Informationssysteme GmbH
* 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:
* Innoopract - initial API and implementation
*******************************************************************************/
package org.eclipse.epp.packaging.core.configuration;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import org.eclipse.update.core.VersionedIdentifier;
import org.osgi.framework.Version;
/**
*
*/
public class FeatureVersionRepository {
private Map<String, VersionList> features = new HashMap<String, VersionList>();
public void addVersionIdentifier( final VersionedIdentifier versionedIdentifier ) {
String identifier = versionedIdentifier.getIdentifier();
String version = versionedIdentifier.getVersion().toString();
if( !this.features.containsKey( identifier ) ) {
this.features.put( identifier, new VersionList() );
}
VersionList versionList = this.features.get( identifier );
versionList.addVersion( version );
}
/**
* Searches for the highest version number of a given feature or bundle,
* identified by the identifier string.
*
* @param identifier of the feature
* @return the highest available version number or <code>null</code> if the
* identifier is not found.
*/
public Version getHighestVersion( final String identifier ) {
Version result = null;
VersionList versionList = this.features.get( identifier );
if( versionList != null ) {
result = versionList.getHighestVersion();
}
return result;
}
/**
* Checks if a given identifier is already in the list of available features.
*
* @param identifier String with the feature identifier.
* @return <code>true</code> if the identifier is found in the list of
* available features, <code>false</code> otherwise.
*/
public boolean containsIdentifier( final String identifier ) {
return this.features.containsKey( identifier );
}
/**
* This class provides a modifiable list of
* <code>PluginVersionIdentifier</code> and returns the highest possible
* version number. Internally it uses the OSGi <code>Version</code>
* implementation because of its <code>Comparable</code> interface.
*/
class VersionList {
private SortedSet<Version> versions = new TreeSet<Version>();
/**
* Adds a new version to the list of available versions if the version is
* not yet included in the list.
*
* @param version the version that is to be added to the list
*/
void addVersion( final String versionString ) {
Version version = new Version( versionString );
if( !this.versions.contains( version ) ) {
this.versions.add( version );
}
}
/**
* @return the highest version number in the list
*/
Version getHighestVersion() {
return this.versions.last();
}
}
}
|