Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 236709 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/.project (+5 lines)
Lines 25-30 Link Here
25
			<arguments>
25
			<arguments>
26
			</arguments>
26
			</arguments>
27
		</buildCommand>
27
		</buildCommand>
28
		<buildCommand>
29
			<name>org.eclipse.pde.ds.core.builder</name>
30
			<arguments>
31
			</arguments>
32
		</buildCommand>
28
	</buildSpec>
33
	</buildSpec>
29
	<natures>
34
	<natures>
30
		<nature>org.eclipse.pde.PluginNature</nature>
35
		<nature>org.eclipse.pde.PluginNature</nature>
(-)a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/META-INF/MANIFEST.MF (+2 lines)
Lines 43-49 Import-Package: javax.xml.parsers, Link Here
43
 org.eclipse.osgi.service.resolver;version="1.2.0";resolution:=optional,
43
 org.eclipse.osgi.service.resolver;version="1.2.0";resolution:=optional,
44
 org.eclipse.osgi.util;version="1.1.0",
44
 org.eclipse.osgi.util;version="1.1.0",
45
 org.osgi.framework;version="1.3.0",
45
 org.osgi.framework;version="1.3.0",
46
 org.osgi.service.packageadmin;version="1.2.0",
46
 org.osgi.service.prefs;version="1.1.1",
47
 org.osgi.service.prefs;version="1.1.1",
47
 org.osgi.util.tracker;version="1.4.0",
48
 org.osgi.util.tracker;version="1.4.0",
48
 org.w3c.dom,
49
 org.w3c.dom,
49
 org.xml.sax
50
 org.xml.sax
51
Service-Component: OSGI-INF/bundleGroup.xml
(-)a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/OSGI-INF/bundleGroup.xml (+7 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="false" name="org.eclipse.equinox.p2.touchpoint.eclipse.bundlegroup">
3
   <implementation class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.BundleGroupComponent"/>
4
   <service>
5
      <provide interface="org.eclipse.core.runtime.IBundleGroupProvider"/>
6
   </service>
7
</scr:component>
(-)a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/build.properties (-1 / +2 lines)
Lines 14-20 bin.includes = META-INF/,\ Link Here
14
               .,\
14
               .,\
15
               plugin.xml,\
15
               plugin.xml,\
16
               about.html,\
16
               about.html,\
17
               plugin.properties
17
               plugin.properties,\
18
               OSGI-INF/
18
src.includes = about.html
19
src.includes = about.html
19
javacTarget=jsr14
20
javacTarget=jsr14
20
javacSource=1.5
21
javacSource=1.5
(-)a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/AboutInfo.java (+224 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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
 *******************************************************************************/
11
package org.eclipse.equinox.internal.p2.touchpoint.eclipse;
12
13
import java.net.URL;
14
import java.util.Hashtable;
15
import org.eclipse.core.runtime.IPath;
16
import org.eclipse.core.runtime.Path;
17
18
/**
19
 * The information within this object is obtained from the about INI file.
20
 * This file resides within an install configurations directory and must be a 
21
 * standard java property file.  
22
 * <p>
23
 * This class is not intended to be instantiated or subclassed by clients.
24
 * </p>
25
 */
26
public final class AboutInfo {
27
	private final static String INI_FILENAME = "about.ini"; //$NON-NLS-1$
28
	private final static String PROPERTIES_FILENAME = "about.properties"; //$NON-NLS-1$
29
	private final static String MAPPINGS_FILENAME = "about.mappings"; //$NON-NLS-1$
30
31
	private String featureId;
32
	private String versionId = ""; //$NON-NLS-1$
33
	private String providerName;
34
	private String appName;
35
	private URL windowImageURL;
36
	private URL[] windowImagesURLs;
37
	private URL aboutImageURL;
38
	private URL featureImageURL;
39
	private URL welcomePageURL;
40
	private String aboutText;
41
	private String welcomePerspective;
42
	private String tipsAndTricksHref;
43
44
	/*
45
	 * Create a new about info for a feature with the given id.
46
	 */
47
	/* package */AboutInfo(String featureId) {
48
		super();
49
		this.featureId = featureId;
50
	}
51
52
	/**
53
	 * Returns the configuration information for the feature with the 
54
	 * given id.
55
	 * 
56
	 * @param featureId the feature id
57
	 * @param versionId the version id (of the feature)
58
	 * @param pluginId the plug-in id
59
	 * @return the configuration information for the feature
60
	 */
61
	public static AboutInfo readFeatureInfo(String featureId, String versionId, String pluginId) {
62
63
		AboutInfo info = new AboutInfo(featureId);
64
		IniFileReader reader = new IniFileReader(featureId, pluginId, INI_FILENAME, PROPERTIES_FILENAME, MAPPINGS_FILENAME);
65
		if (!reader.load().isOK())
66
			return info;
67
		Hashtable<String, String> runtimeMappings = new Hashtable<String, String>();
68
		runtimeMappings.put("{featureVersion}", versionId); //$NON-NLS-1$
69
		info.versionId = versionId;
70
		info.providerName = reader.getProviderName();
71
		info.appName = reader.getString("appName", true, runtimeMappings); //$NON-NLS-1$
72
		info.aboutText = reader.getString("aboutText", true, runtimeMappings); //$NON-NLS-1$
73
		info.windowImageURL = reader.getURL("windowImage"); //$NON-NLS-1$
74
		// look for the newer array, but if its not there then use the older,
75
		// single image definition
76
		info.windowImagesURLs = reader.getURLs("windowImages"); //$NON-NLS-1$
77
		info.aboutImageURL = reader.getURL("aboutImage"); //$NON-NLS-1$
78
		info.featureImageURL = reader.getURL("featureImage"); //$NON-NLS-1$
79
		info.welcomePageURL = reader.getURL("welcomePage"); //$NON-NLS-1$
80
		info.welcomePerspective = reader.getString("welcomePerspective", false, runtimeMappings); //$NON-NLS-1$
81
		info.tipsAndTricksHref = reader.getString("tipsAndTricksHref", false, runtimeMappings); //$NON-NLS-1$
82
		return info;
83
	}
84
85
	/**
86
	 * Returns the URL for an image which can be shown in an "about" dialog 
87
	 * for this product. Products designed to run "headless" typically would not 
88
	 * have such an image.
89
	 * 
90
	 * @return the URL for an about image, or <code>null</code> if none
91
	 */
92
	public URL getAboutImageURL() {
93
		return aboutImageURL;
94
	}
95
96
	/**
97
	 * Returns the URL for an image which can be shown in an "about features" 
98
	 * dialog. Products designed to run "headless" typically would not have such an image.
99
	 * 
100
	 * @return the URL for a feature image, or <code>null</code> if none
101
	 */
102
	public URL getFeatureImageURL() {
103
		return featureImageURL;
104
	}
105
106
	/**
107
	 * Returns the simple name of the feature image file.
108
	 * 
109
	 * @return the simple name of the feature image file,
110
	 * or <code>null</code> if none
111
	 */
112
	public String getFeatureImageName() {
113
		if (featureImageURL != null) {
114
			IPath path = new Path(featureImageURL.getPath());
115
			return path.lastSegment();
116
		}
117
		return null;
118
	}
119
120
	/**
121
	 * Returns the id for this feature.
122
	 * 
123
	 * @return the feature id
124
	 */
125
	public String getFeatureId() {
126
		return featureId;
127
	}
128
129
	/**
130
	 * Returns the text to show in an "about" dialog for this product.
131
	 * Products designed to run "headless" typically would not have such text.
132
	 * 
133
	 * @return the about text, or <code>null</code> if none
134
	 */
135
	public String getAboutText() {
136
		return aboutText;
137
	}
138
139
	/**
140
	 * Returns the application name or <code>null</code>.
141
	 * Note this is never shown to the user.
142
	 * It is used to initialize the SWT Display.
143
	 * <p>
144
	 * On Motif, for example, this can be used
145
	 * to set the name used for resource lookup.
146
	 * </p>
147
	 *
148
	 * @return the application name, or <code>null</code>
149
	 */
150
	public String getAppName() {
151
		return appName;
152
	}
153
154
	/**
155
	 * Returns the provider name or <code>null</code>.
156
	 *
157
	 * @return the provider name, or <code>null</code>
158
	 */
159
	public String getProviderName() {
160
		return providerName;
161
	}
162
163
	/**
164
	 * Returns the feature version id.
165
	 *
166
	 * @return the version id of the feature
167
	 */
168
	public String getVersionId() {
169
		return versionId;
170
	}
171
172
	/**
173
	 * Returns a <code>URL</code> for the welcome page.
174
	 * Products designed to run "headless" typically would not have such an page.
175
	 * 
176
	 * @return the welcome page, or <code>null</code> if none
177
	 */
178
	public URL getWelcomePageURL() {
179
		return welcomePageURL;
180
	}
181
182
	/**
183
	 * Returns the ID of a perspective in which to show the welcome page.
184
	 * May be <code>null</code>.
185
	 * 
186
	 * @return the welcome page perspective id, or <code>null</code> if none
187
	 */
188
	public String getWelcomePerspectiveId() {
189
		return welcomePerspective;
190
	}
191
192
	/**
193
	 * Returns a <code>String</code> for the tips and trick href.
194
	 * 
195
	 * @return the tips and tricks href, or <code>null</code> if none
196
	 */
197
	public String getTipsAndTricksHref() {
198
		return tipsAndTricksHref;
199
	}
200
201
	/**
202
	 * Returns the image url for the window image to use for this product.
203
	 * Products designed to run "headless" typically would not have such an image.
204
	 * 
205
	 * @return the image url for the window image, or <code>null</code> if none
206
	 */
207
	public URL getWindowImageURL() {
208
		return windowImageURL;
209
	}
210
211
	/**
212
	 * Return an array of image URLs for the window images to use for
213
	 * this product. The expectations is that the elements will be the same
214
	 * image rendered at different sizes. Products designed to run "headless"
215
	 * typically would not have such images.
216
	 * 
217
	 * @return an array of the image descriptors for the window images, or
218
	 *         <code>null</code> if none
219
	 * @since 3.0
220
	 */
221
	public URL[] getWindowImagesURLs() {
222
		return windowImagesURLs;
223
	}
224
}
(-)a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Activator.java (-3 / +47 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
2
 * Copyright (c) 2007, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-21 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.internal.p2.touchpoint.eclipse;
11
package org.eclipse.equinox.internal.p2.touchpoint.eclipse;
12
12
13
import org.osgi.framework.BundleActivator;
13
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
14
import org.osgi.framework.BundleContext;
14
import org.eclipse.equinox.p2.core.IProvisioningAgent;
15
import org.eclipse.equinox.p2.engine.IProfile;
16
import org.eclipse.equinox.p2.engine.IProfileRegistry;
17
import org.osgi.framework.*;
18
import org.osgi.service.packageadmin.PackageAdmin;
19
import org.osgi.util.tracker.ServiceTracker;
15
20
16
public class Activator implements BundleActivator {
21
public class Activator implements BundleActivator {
17
	public static final String ID = "org.eclipse.equinox.p2.touchpoint.eclipse"; //$NON-NLS-1$
22
	public static final String ID = "org.eclipse.equinox.p2.touchpoint.eclipse"; //$NON-NLS-1$
18
	private static BundleContext context = null;
23
	private static BundleContext context = null;
24
	private static ServiceTracker<?, ?> bundleTracker;
19
25
20
	public void start(BundleContext ctx) throws Exception {
26
	public void start(BundleContext ctx) throws Exception {
21
		Activator.context = ctx;
27
		Activator.context = ctx;
Lines 23-32 public class Activator implements BundleActivator { Link Here
23
29
24
	public void stop(BundleContext ctx) throws Exception {
30
	public void stop(BundleContext ctx) throws Exception {
25
		Activator.context = null;
31
		Activator.context = null;
32
		if (Activator.bundleTracker != null) {
33
			Activator.bundleTracker.close();
34
			Activator.bundleTracker = null;
35
		}
26
	}
36
	}
27
37
28
	public static BundleContext getContext() {
38
	public static BundleContext getContext() {
29
		return Activator.context;
39
		return Activator.context;
30
	}
40
	}
31
41
42
	/*
43
	 * Return the current profile or null if it cannot be retrieved.
44
	 */
45
	public static IProfile getProfile() {
46
		IProvisioningAgent agent = getAgent();
47
		IProfileRegistry profileRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
48
		if (profileRegistry == null)
49
			return null;
50
		return profileRegistry.getProfile(IProfileRegistry.SELF);
51
	}
52
53
	private static IProvisioningAgent getAgent() {
54
		return (IProvisioningAgent) ServiceHelper.getService(Activator.getContext(), IProvisioningAgent.SERVICE_NAME);
55
	}
56
57
	public static synchronized Bundle getBundle(String symbolicName) {
58
		if (bundleTracker == null) {
59
			bundleTracker = new ServiceTracker(getContext(), PackageAdmin.class, null);
60
			bundleTracker.open();
61
		}
62
		PackageAdmin admin = (PackageAdmin) bundleTracker.getService();
63
		if (admin == null)
64
			return null;
65
		Bundle[] bundles = admin.getBundles(symbolicName, null);
66
		if (bundles == null)
67
			return null;
68
		//Return the first bundle that is not installed or uninstalled
69
		for (int i = 0; i < bundles.length; i++) {
70
			if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
71
				return bundles[i];
72
			}
73
		}
74
		return null;
75
	}
32
}
76
}
(-)a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/BundleGroupComponent.java (+164 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 *
7
 * Contributors: 
8
 *   IBM Corporation - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.equinox.internal.p2.touchpoint.eclipse;
11
12
import java.net.URL;
13
import java.util.*;
14
import org.eclipse.core.runtime.IBundleGroup;
15
import org.eclipse.core.runtime.IBundleGroupProvider;
16
import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
17
import org.eclipse.equinox.internal.p2.metadata.TranslationSupport;
18
import org.eclipse.equinox.p2.engine.IProfile;
19
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
20
import org.eclipse.equinox.p2.metadata.IRequirement;
21
import org.eclipse.equinox.p2.query.IQueryResult;
22
import org.eclipse.equinox.p2.query.QueryUtil;
23
import org.osgi.framework.Bundle;
24
25
public class BundleGroupComponent implements IBundleGroupProvider {
26
27
	TranslationSupport translator = TranslationSupport.getInstance();
28
29
	public class IUBundleGroup implements IBundleGroup, IBundleGroupConstants, IProductConstants {
30
		IInstallableUnit iu;
31
		AboutInfo branding;
32
33
		public IUBundleGroup(IInstallableUnit iu) {
34
			this.iu = iu;
35
		}
36
37
		private AboutInfo getBranding() {
38
			if (branding == null)
39
				branding = AboutInfo.readFeatureInfo(getIdentifier(), getVersion(), getIdentifier());
40
			return branding;
41
		}
42
43
		public String getIdentifier() {
44
			String id = iu.getId();
45
			if (id == null)
46
				return null;
47
			// trim the id if it ends in ".feature.group" so it looks more
48
			// like a feature id than an IU id
49
			final String END = ".feature.group"; //$NON-NLS-1$
50
			if (id.endsWith(END))
51
				id = id.substring(0, id.length() - END.length());
52
			return id;
53
		}
54
55
		public String getName() {
56
			return translator.getIUProperty(iu, IInstallableUnit.PROP_NAME);
57
		}
58
59
		public String getVersion() {
60
			return iu.getVersion().toString();
61
		}
62
63
		public String getDescription() {
64
			return translator.getIUProperty(iu, IInstallableUnit.PROP_DESCRIPTION);
65
		}
66
67
		public String getProviderName() {
68
			return translator.getIUProperty(iu, IInstallableUnit.PROP_PROVIDER);
69
		}
70
71
		public Bundle[] getBundles() {
72
			Collection<Bundle> result = new HashSet<Bundle>();
73
			Collection<IRequirement> reqs = iu.getRequirements();
74
			for (IRequirement obj : reqs) {
75
				if (!(obj instanceof IRequiredCapability))
76
					continue;
77
				IRequiredCapability req = (IRequiredCapability) obj;
78
				// we are only interested in requirements on other IUs
79
				if (!IInstallableUnit.NAMESPACE_IU_ID.equals(req.getNamespace()))
80
					continue;
81
				String id = req.getName();
82
				Bundle b = Activator.getBundle(id);
83
				if (b != null)
84
					result.add(b);
85
			}
86
			return result.toArray(new Bundle[result.size()]);
87
		}
88
89
		public String getProperty(String key) {
90
			AboutInfo branding = getBranding();
91
			// IBundleGroupConstants
92
			if (key.equals(FEATURE_IMAGE))
93
				return branding.getFeatureImageURL() == null ? null : branding.getFeatureImageURL().toExternalForm();
94
			else if (key.equals(TIPS_AND_TRICKS_HREF))
95
				return branding.getTipsAndTricksHref();
96
			else if (key.equals(IBundleGroupConstants.WELCOME_PAGE)) // same value is used by product and bundle group
97
				return branding.getWelcomePageURL() == null ? null : branding.getWelcomePageURL().toExternalForm();
98
			else if (key.equals(WELCOME_PERSPECTIVE))
99
				return branding.getWelcomePerspectiveId();
100
			else if (key.equals(BRANDING_BUNDLE_ID))
101
				// TODO
102
				return getIdentifier();
103
			else if (key.equals(BRANDING_BUNDLE_VERSION))
104
				// TODO
105
				return getVersion();
106
			// IProductConstants
107
			else if (key.equals(APP_NAME))
108
				return branding.getAppName();
109
			else if (key.equals(ABOUT_TEXT))
110
				return branding.getAboutText();
111
			else if (key.equals(ABOUT_IMAGE))
112
				return branding.getAboutImageURL() == null ? null : branding.getAboutImageURL().toExternalForm();
113
			else if (key.equals(WINDOW_IMAGE))
114
				return branding.getWindowImageURL() == null ? null : branding.getWindowImageURL().toExternalForm();
115
			else if (key.equals(WINDOW_IMAGES)) {
116
				URL[] urls = branding.getWindowImagesURLs();
117
				if (urls == null)
118
					return null;
119
				StringBuffer windowImagesURLs = new StringBuffer();
120
				for (int i = 0; i < urls.length; i++) {
121
					windowImagesURLs.append(urls[i].toExternalForm());
122
					if (i != urls.length - 1)
123
						windowImagesURLs.append(',');
124
				}
125
				return windowImagesURLs.toString();
126
			} else if (key.equals(LICENSE_HREF))
127
				// TODO
128
				//return getLicenseURL();
129
				return null;
130
131
			return translator.getIUProperty(iu, key);
132
		}
133
134
		public String toString() {
135
			return "IUBundleGroup(" + getIdentifier() + " " + getVersion() + ")";
136
		}
137
	}
138
139
	public String getName() {
140
		return Messages.bundleGroupComponentName;
141
	}
142
143
	public IBundleGroup[] getBundleGroups() {
144
		if (!isReconciling())
145
			return new IBundleGroup[0];
146
		IProfile profile = Activator.getProfile();
147
		IQueryResult<IInstallableUnit> profileQueryResult = profile.query(QueryUtil.createIUGroupQuery(), null);
148
		List<IBundleGroup> result = new ArrayList<IBundleGroup>();
149
		for (Iterator<IInstallableUnit> it = profileQueryResult.iterator(); it.hasNext();) {
150
			IInstallableUnit iu = it.next();
151
			result.add(new IUBundleGroup(iu));
152
		}
153
		return result.toArray(new IUBundleGroup[result.size()]);
154
	}
155
156
	/**
157
	 * Returns whether or not we are reconciling. Check the system property to see
158
	 * if the update manager is doing the work or not. 
159
	 */
160
	public static boolean isReconciling() {
161
		String reconcile = Activator.getContext().getProperty("org.eclipse.update.reconcile"); //$NON-NLS-1$
162
		return reconcile != null && reconcile.equalsIgnoreCase("false"); //$NON-NLS-1$
163
	}
164
}
(-)a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/IBundleGroupConstants.java (+63 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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
 *******************************************************************************/
11
package org.eclipse.equinox.internal.p2.touchpoint.eclipse;
12
13
/**
14
 * These constants define the set of properties that the UI expects to
15
 * be available via <code>IBundleGroup.getProperty(String)</code>.
16
 * 
17
 * @since 3.0
18
 * @see org.eclipse.core.runtime.IBundleGroup#getProperty(String)
19
 */
20
public interface IBundleGroupConstants {
21
	/**
22
	 * An image which can be shown in an "about features" dialog (32x32).
23
	 */
24
	public static final String FEATURE_IMAGE = "featureImage"; //$NON-NLS-1$
25
26
	/**
27
	 * A help reference for the feature's tips and tricks page (optional).
28
	 */
29
	public static final String TIPS_AND_TRICKS_HREF = "tipsAndTricksHref"; //$NON-NLS-1$
30
31
	/**
32
	 * A URL for the feature's welcome page (special XML-based format)
33
	 * ($nl$/ prefix to permit locale-specific translations of entire file).
34
	 * Products designed to run "headless" typically would not have such a page.
35
	 */
36
	public static final String WELCOME_PAGE = "welcomePage"; //$NON-NLS-1$
37
38
	/**
39
	 * The id of a perspective in which to show the welcome page
40
	 * (optional).
41
	 */
42
	public static final String WELCOME_PERSPECTIVE = "welcomePerspective"; //$NON-NLS-1$
43
44
	/**
45
	 * The URL of the license page for the feature
46
	 * (optional).
47
	 */
48
	public static final String LICENSE_HREF = "licenseHref"; //$NON-NLS-1$
49
50
	/**
51
	 * The id of the bundle group's branding bundle.
52
	 * @see IFeatureEntry#getFeaturePluginIdentifier()
53
	 * @since 3.3
54
	 */
55
	public static final String BRANDING_BUNDLE_ID = "brandingBundleId"; //$NON-NLS-1$
56
57
	/**
58
	 * The version of the feature branding bundle.
59
	 * @see IFeatureEntry#getFeaturePluginVersion()
60
	 * @since 3.3
61
	 */
62
	public static final String BRANDING_BUNDLE_VERSION = "brandingBundleVersion"; //$NON-NLS-1$
63
}
(-)a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/IProductConstants.java (+77 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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
 *******************************************************************************/
11
package org.eclipse.equinox.internal.p2.touchpoint.eclipse;
12
13
/**
14
 * These constants define the set of properties that the UI expects to
15
 * be available via <code>IProduct.getProperty(String)</code>.
16
 * 
17
 * @since 3.0
18
 * @see org.eclipse.core.runtime.IProduct#getProperty(String)
19
 */
20
public interface IProductConstants {
21
	/**
22
	 * The application name, used to initialize the SWT Display.  This
23
	 * value is distinct from the string displayed in the application
24
	 * title bar.
25
	 * <p>
26
	 * E.g., On motif, this can be used to set the name used for
27
	 * resource lookup.
28
	 * </p>
29
	 */
30
	public static final String APP_NAME = "appName"; //$NON-NLS-1$
31
32
	/**
33
	 * The text to show in an "about" dialog for this product.
34
	 * Products designed to run "headless" typically would not
35
	 * have such text.
36
	 */
37
	public static final String ABOUT_TEXT = "aboutText"; //$NON-NLS-1$
38
39
	/**
40
	 * An image which can be shown in an "about" dialog for this
41
	 * product. Products designed to run "headless" typically would not 
42
	 * have such an image.
43
	 * <p>
44
	 * A full-sized product image (no larger than 500x330 pixels) is
45
	 * shown without the "aboutText" blurb.  A half-sized product image
46
	 * (no larger than 250x330 pixels) is shown with the "aboutText"
47
	 * blurb beside it.
48
	 */
49
	public static final String ABOUT_IMAGE = "aboutImage"; //$NON-NLS-1$
50
51
	/**
52
	 * An image to be used as the window icon for this product (16x16).  
53
	 * Products designed to run "headless" typically would not have such an image.
54
	 * <p>
55
	 * If the <code>WINDOW_IMAGES</code> property is given, then it supercedes
56
	 * this one.
57
	 * </p>
58
	 */
59
	public static final String WINDOW_IMAGE = "windowImage"; //$NON-NLS-1$
60
61
	/**
62
	 * An array of one or more images to be used for this product.  The
63
	 * expectation is that the array will contain the same image rendered
64
	 * at different sizes (16x16 and 32x32).  
65
	 * Products designed to run "headless" typically would not have such images.
66
	 * <p>
67
	 * If this property is given, then it supercedes <code>WINDOW_IMAGE</code>.
68
	 * </p>
69
	 */
70
	public static final String WINDOW_IMAGES = "windowImages"; //$NON-NLS-1$
71
	/**
72
	 * A URL for the products's welcome page (special XML-based format)
73
	 * ($nl$/ prefix to permit locale-specific translations of entire file).
74
	 * Products designed to run "headless" typically would not have such a page.
75
	 */
76
	public static final String WELCOME_PAGE = "welcomePage"; //$NON-NLS-1$
77
}
(-)a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/IniFileReader.java (+353 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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
 *******************************************************************************/
11
package org.eclipse.equinox.internal.p2.touchpoint.eclipse;
12
13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.net.URL;
16
import java.text.MessageFormat;
17
import java.util.*;
18
import org.eclipse.core.runtime.*;
19
import org.eclipse.osgi.util.NLS;
20
import org.osgi.framework.Bundle;
21
import org.osgi.framework.Constants;
22
23
// Have to use MessageFormat directly, can't use ICU, possible launch problem?
24
25
/**
26
 * Reads the information found in an "INI" file. This file must be in a
27
 * standard Java properties format. A properties file may also be provided
28
 * to NL values in the INI file - values must start with the % prefix. A
29
 * mapping file may also be provided that contains "fill-ins" for the
30
 * properties file - format being "n = some text", where n is a number.
31
 */
32
public class IniFileReader {
33
	private static final String PID = "org.eclipse.update.configurator"; //$NON-NLS-1$
34
	private static final Status OK_STATUS = new Status(IStatus.OK, PID, 0, "", null); //$NON-NLS-1$
35
	private static final String KEY_PREFIX = "%"; //$NON-NLS-1$
36
	private static final String KEY_DOUBLE_PREFIX = "%%"; //$NON-NLS-1$
37
	private static final String NLS_TAG = "$nl$"; //$NON-NLS-1$
38
39
	private String featureId;
40
	private String pluginId;
41
	private String iniFilename;
42
	private String propertiesFilename;
43
	private String mappingsFilename;
44
	private Properties ini = null;
45
	private PropertyResourceBundle properties = null;
46
	private String[] mappings = null;
47
	private Bundle bundle;
48
49
	/**
50
	 * Creates an INI file reader that can parse the contents into key,value pairs.
51
	 * 
52
	 * @param featureId the unique identifier of the feature, must not be <code>null</code>
53
	 * @param pluginId the unique identifier of the feature plug-in, must not be <code>null</code>
54
	 * @param iniFilename the INI file name, must not be <code>null</code>
55
	 * @param propertiesFilename the properties filename, can be <code>null</code> if not required
56
	 * @param mappingsFilename the mappings filename, can be <code>null</code> if not required
57
	 */
58
	public IniFileReader(String featureId, String pluginId, String iniFilename, String propertiesFilename, String mappingsFilename) {
59
		super();
60
61
		if (featureId == null || pluginId == null || iniFilename == null) {
62
			throw new IllegalArgumentException();
63
		}
64
65
		this.featureId = featureId;
66
		this.pluginId = pluginId;
67
		this.iniFilename = iniFilename;
68
		this.propertiesFilename = propertiesFilename;
69
		this.mappingsFilename = mappingsFilename;
70
	}
71
72
	/**
73
	 * Read the contents of the INI, properties, and mappings files.
74
	 * Does nothing if the content has already been read and parsed.
75
	 * 
76
	 * @return an <code>IStatus</code> indicating the success or failure
77
	 * 	of reading and parsing the INI file content
78
	 */
79
	public IStatus load() {
80
		if (ini != null)
81
			return OK_STATUS;
82
83
		// attempt to locate the corresponding plugin
84
		bundle = Activator.getBundle(pluginId);
85
		if (bundle == null || bundle.getState() == Bundle.UNINSTALLED || bundle.getState() == Bundle.INSTALLED) {
86
			bundle = null; // make it null for other test down the road
87
			String message = NLS.bind("Cannot find plug-in for feature {0}.", (new String[] {featureId}));
88
			return new Status(IStatus.ERROR, PID, 0, message, null);
89
		}
90
91
		// Determine the ini file location
92
		URL iniURL = null;
93
		IOException ioe = null;
94
		iniURL = FileLocator.find(bundle, new Path(NLS_TAG).append(iniFilename), null);
95
		if (iniURL == null) {
96
			String message = NLS.bind("Cannot open branding file {0}.", (new String[] {iniFilename}));
97
			return new Status(IStatus.ERROR, PID, 0, message, ioe);
98
		}
99
100
		// Determine the properties file location
101
		URL propertiesURL = null;
102
		if (propertiesFilename != null & propertiesFilename.length() > 0) {
103
			propertiesURL = FileLocator.find(bundle, new Path(NLS_TAG).append(propertiesFilename), null);
104
		}
105
106
		// Determine the mappings file location
107
		URL mappingsURL = null;
108
		if (mappingsFilename != null && mappingsFilename.length() > 0) {
109
			mappingsURL = FileLocator.find(bundle, new Path(NLS_TAG).append(mappingsFilename), null);
110
		}
111
112
		// OK to pass null properties and/or mapping file
113
		return load(iniURL, propertiesURL, mappingsURL);
114
	}
115
116
	/**
117
	 * Returns the string value for the given key, or <code>null</code>.
118
	 * The string value is NLS if requested.
119
	 * 
120
	 * @return the string value for the given key, or <code>null</code>
121
	 */
122
	public String getString(String key, boolean doNls, Hashtable<String, String> runtimeMappings) {
123
		if (ini == null)
124
			return null;
125
		String value = ini.getProperty(key);
126
		if (value != null && doNls)
127
			return getResourceString(value, runtimeMappings);
128
		return value;
129
	}
130
131
	/**
132
	 * Returns a URL for the given key, or <code>null</code>.
133
	 * 
134
	 * @return a URL for the given key, or <code>null</code>
135
	 */
136
	public URL getURL(String key) {
137
		if (ini == null)
138
			return null;
139
140
		URL url = null;
141
		String fileName = ini.getProperty(key);
142
		if (fileName != null) {
143
			if (bundle == null)
144
				return null;
145
			url = FileLocator.find(bundle, new Path(fileName), null);
146
		}
147
		return url;
148
	}
149
150
	/**
151
	 * Returns a array of URL for the given key, or <code>null</code>. The
152
	 * property value should be a comma separated list of urls, tokens for
153
	 * which bundle cannot build an url will have a null entry.
154
	 * 
155
	 * @param key name of the property containing the requested urls
156
	 * @return a URL for the given key, or <code>null</code>
157
	 * @since 3.0
158
	 */
159
	public URL[] getURLs(String key) {
160
		if (ini == null || bundle == null)
161
			return null;
162
163
		String value = ini.getProperty(key);
164
		if (value == null)
165
			return null;
166
167
		StringTokenizer tokens = new StringTokenizer(value, ","); //$NON-NLS-1$
168
		ArrayList<URL> array = new ArrayList<URL>(10);
169
		while (tokens.hasMoreTokens()) {
170
			String str = tokens.nextToken().trim();
171
			array.add(FileLocator.find(bundle, new Path(str), null));
172
		}
173
		return array.toArray(new URL[array.size()]);
174
	}
175
176
	/**
177
	 * Returns the feature plugin label, or <code>null</code>.
178
	 * 
179
	 * @return the feature plugin lable, or <code>null</code> if none.
180
	 */
181
	public String getFeaturePluginLabel() {
182
		return bundle == null ? null : bundle.getHeaders().get(Constants.BUNDLE_NAME);
183
	}
184
185
	/**
186
	 * Returns the provider name for this feature, or <code>null</code>.
187
	 * 
188
	 * @return the provider name for this feature, or <code>null</code>
189
	 */
190
	public String getProviderName() {
191
		return bundle == null ? null : bundle.getHeaders().get(Constants.BUNDLE_VENDOR);
192
	}
193
194
	/*
195
	 * Returns a resource string corresponding to the given argument 
196
	 * value and bundle.
197
	 * If the argument value specifies a resource key, the string
198
	 * is looked up in the given resource bundle. If the argument does not
199
	 * specify a valid key, the argument itself is returned as the
200
	 * resource string. The key lookup is performed against the
201
	 * specified resource bundle. If a resource string 
202
	 * corresponding to the key is not found in the resource bundle
203
	 * the key value, or any default text following the key in the
204
	 * argument value is returned as the resource string.
205
	 * A key is identified as a string begining with the "%" character.
206
	 * Note that the "%" character is stripped off prior to lookup
207
	 * in the resource bundle.
208
	 * <p>
209
	 * For example, assume resource bundle plugin.properties contains
210
	 * name = Project Name
211
	 * <pre>
212
	 *     <li>getResourceString("Hello World") returns "Hello World"</li>
213
	 *     <li>getResourceString("%name") returns "Project Name"</li>
214
	 *     <li>getResourceString("%name Hello World") returns "Project Name"</li>
215
	 *     <li>getResourceString("%abcd Hello World") returns "Hello World"</li>
216
	 *     <li>getResourceString("%abcd") returns "%abcd"</li>
217
	 *     <li>getResourceString("%%name") returns "%name"</li>
218
	 *     <li>getResourceString(<code>null</code>) returns <code>null</code></li>
219
	 * </pre>
220
	 * </p>
221
	 *
222
	 * @param value the value or <code>null</code>
223
	 * @param runtimeMappings runtime mappings or <code>null</code>
224
	 * @return the resource string
225
	 */
226
	public String getResourceString(String value, Hashtable<String, String> runtimeMappings) {
227
228
		if (value == null)
229
			return null;
230
		String s = value.trim();
231
232
		if (!s.startsWith(KEY_PREFIX))
233
			return s;
234
235
		if (s.startsWith(KEY_DOUBLE_PREFIX))
236
			return s.substring(1);
237
238
		int ix = s.indexOf(" "); //$NON-NLS-1$
239
		String key = ix == -1 ? s : s.substring(0, ix);
240
		String dflt = ix == -1 ? s : s.substring(ix + 1);
241
242
		if (properties == null)
243
			return dflt;
244
245
		String result = null;
246
		try {
247
			result = properties.getString(key.substring(1));
248
		} catch (MissingResourceException e) {
249
			return dflt;
250
		}
251
		if (runtimeMappings != null) {
252
			for (Enumeration<String> e = runtimeMappings.keys(); e.hasMoreElements();) {
253
				String keyValue = e.nextElement();
254
				int i = result.indexOf(keyValue);
255
				if (i != -1) {
256
					String s1 = result.substring(0, i);
257
					String s2 = runtimeMappings.get(keyValue);
258
					String s3 = result.substring(i + keyValue.length());
259
					result = s1 + s2 + s3;
260
				}
261
			}
262
		}
263
264
		if (result.indexOf('{') != -1) {
265
			// We test for the curly braces since due to NL issues we do not
266
			// want to use MessageFormat unless we have to.
267
			try {
268
				result = MessageFormat.format(result, mappings);
269
			} catch (IllegalArgumentException e) {
270
				//ignore and return string without bound parameters
271
			}
272
		}
273
274
		return result;
275
	}
276
277
	/*
278
	 * Read the contents of the ini, properties, and mappings files.
279
	 */
280
	private IStatus load(URL iniURL, URL propertiesURL, URL mappingsURL) {
281
282
		InputStream is = null;
283
		try {
284
			is = iniURL.openStream();
285
			ini = new Properties();
286
			ini.load(is);
287
		} catch (IOException e) {
288
			ini = null;
289
			String message = NLS.bind("Error reading branding file {0}.", (new String[] {iniURL.toExternalForm()}));
290
			return new Status(IStatus.ERROR, PID, 0, message, e);
291
		} finally {
292
			try {
293
				if (is != null)
294
					is.close();
295
			} catch (IOException e) {
296
			}
297
		}
298
299
		if (propertiesURL != null) {
300
			is = null;
301
			try {
302
				is = propertiesURL.openStream();
303
				properties = new PropertyResourceBundle(is);
304
			} catch (IOException e) {
305
				properties = null;
306
				String message = NLS.bind("Error reading branding properties file {0}.", (new String[] {propertiesURL.toExternalForm()}));
307
				return new Status(IStatus.ERROR, PID, 0, message, e);
308
			} finally {
309
				try {
310
					if (is != null)
311
						is.close();
312
				} catch (IOException e) {
313
				}
314
			}
315
		}
316
317
		PropertyResourceBundle bundle = null;
318
		if (mappingsURL != null) {
319
			is = null;
320
			try {
321
				is = mappingsURL.openStream();
322
				bundle = new PropertyResourceBundle(is);
323
			} catch (IOException e) {
324
				bundle = null;
325
				String message = NLS.bind("Error reading branding mapping file {0}.", (new String[] {mappingsURL.toExternalForm()}));
326
				return new Status(IStatus.ERROR, PID, 0, message, e);
327
			} finally {
328
				try {
329
					if (is != null)
330
						is.close();
331
				} catch (IOException e) {
332
				}
333
			}
334
		}
335
336
		ArrayList mappingsList = new ArrayList();
337
		if (bundle != null) {
338
			boolean found = true;
339
			int i = 0;
340
			while (found) {
341
				try {
342
					mappingsList.add(bundle.getString(Integer.toString(i)));
343
				} catch (MissingResourceException e) {
344
					found = false;
345
				}
346
				i++;
347
			}
348
		}
349
		mappings = (String[]) mappingsList.toArray(new String[mappingsList.size()]);
350
351
		return OK_STATUS;
352
	}
353
}
(-)a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Messages.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 *  Copyright (c) 2008, 2009 IBM Corporation and others.
2
 *  Copyright (c) 2008, 2011 IBM Corporation and others.
3
 *  All rights reserved. This program and the accompanying materials
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
5
 *  which accompanies this distribution, and is available at
Lines 28-33 public class Messages extends NLS { Link Here
28
	public static String artifact_file_not_found;
28
	public static String artifact_file_not_found;
29
	public static String artifact_retrieval_unsupported;
29
	public static String artifact_retrieval_unsupported;
30
	public static String bundle_pool_not_writeable;
30
	public static String bundle_pool_not_writeable;
31
	public static String bundleGroupComponentName;
31
	public static String cannot_calculate_extension_location;
32
	public static String cannot_calculate_extension_location;
32
	public static String parent_dir_features;
33
	public static String parent_dir_features;
33
	public static String platform_config_unavailable;
34
	public static String platform_config_unavailable;
(-)a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/messages.properties (-1 / +2 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
#  Copyright (c) 2008, 2009 IBM Corporation and others.
2
#  Copyright (c) 2008, 2011 IBM Corporation and others.
3
#  All rights reserved. This program and the accompanying materials
3
#  All rights reserved. This program and the accompanying materials
4
#  are made available under the terms of the Eclipse Public License v1.0
4
#  are made available under the terms of the Eclipse Public License v1.0
5
#  which accompanies this distribution, and is available at
5
#  which accompanies this distribution, and is available at
Lines 21-26 artifact_write_unsupported=Repository not writeable. Link Here
21
artifact_file_not_found=The artifact file for {0} was not found.
21
artifact_file_not_found=The artifact file for {0} was not found.
22
artifact_retrieval_unsupported=Repository does not support artifact retrieval
22
artifact_retrieval_unsupported=Repository does not support artifact retrieval
23
bundle_pool_not_writeable=Bundle pool repository not writeable: {0}
23
bundle_pool_not_writeable=Bundle pool repository not writeable: {0}
24
bundleGroupComponentName=Equinox p2 Bundle Group Provider
24
BundlePool=Bundle pool
25
BundlePool=Bundle pool
25
cannot_calculate_extension_location=Unable to calculate extension location for: {0}.
26
cannot_calculate_extension_location=Unable to calculate extension location for: {0}.
26
parent_dir_features=Parent directory should be "features": {0}.
27
parent_dir_features=Parent directory should be "features": {0}.

Return to bug 236709