KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > site > BuildTimeFeatureFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.build.site;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.net.URL JavaDoc;
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.osgi.util.NLS;
18 import org.eclipse.pde.internal.build.*;
19 import org.eclipse.update.core.*;
20 import org.eclipse.update.core.model.FeatureModel;
21 import org.eclipse.update.internal.core.FeatureExecutableContentProvider;
22 import org.eclipse.update.internal.core.URLEncoder;
23
24 /**
25  *
26  *
27  */

28 public class BuildTimeFeatureFactory extends BaseFeatureFactory implements IFeatureFactory, IPDEBuildConstants, IBuildPropertiesConstants {
29     public final static String JavaDoc BUILDTIME_FEATURE_FACTORY_ID = PI_PDEBUILD + ".BuildTimeFeatureFactory"; //$NON-NLS-1$
30

31     public IFeature createFeature(URL JavaDoc url, ISite site, IProgressMonitor p) throws CoreException {
32         Feature feature = null;
33         InputStream JavaDoc featureStream = null;
34
35         if (url == null)
36             return createFeature(site);
37
38         try {
39             // TODO FeatureExecutableContentProvider is a non API class
40
IFeatureContentProvider contentProvider = new FeatureExecutableContentProvider(url);
41
42             URL JavaDoc nonResolvedURL = contentProvider.getFeatureManifestReference(null).asURL();
43             URL JavaDoc resolvedURL = URLEncoder.encode(nonResolvedURL);
44
45             featureStream = resolvedURL.openStream();
46             feature = (Feature) this.parseFeature(featureStream);
47
48             String JavaDoc qualifier = AbstractScriptGenerator.readProperties(new Path(url.getFile()).removeLastSegments(1).toOSString(), PROPERTIES_FILE, IStatus.OK).getProperty(PROPERTY_QUALIFIER);
49             String JavaDoc newVersion = QualifierReplacer.replaceQualifierInVersion(feature.getFeatureVersion(), feature.getFeatureIdentifier(), qualifier, ((BuildTimeSite) site).getFeatureVersions());
50             if (newVersion != null){
51                 //a feature version ending in qualifier using context will be further modified based on its included plugins
52
if (feature.getFeatureVersion().endsWith(PROPERTY_QUALIFIER) && (qualifier == null || qualifier.equalsIgnoreCase(PROPERTY_CONTEXT))) {
53                     int idx = feature.getFeatureVersion().lastIndexOf("."); //$NON-NLS-1$
54
((BuildTimeFeature)feature).setContextQualifierLength(newVersion.length() - idx - 1);
55                 }
56                 ((BuildTimeFeature) feature).setFeatureVersion(newVersion);
57             }
58
59             feature.setSite(site);
60             feature.setFeatureContentProvider(contentProvider);
61             feature.resolve(url, url);
62         } catch (CoreException e) {
63             String JavaDoc message = NLS.bind(Messages.error_creatingFeature, url);
64             BundleHelper.getDefault().getLog().log(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_PARSE, message, e));
65             throw e;
66         } catch (Exception JavaDoc e) {
67             String JavaDoc message = NLS.bind(Messages.exception_readingFile, url);
68             Status status = new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_MISSING, message, e);
69             BundleHelper.getDefault().getLog().log(status); //Logging here because the caller consumes CoreExceptions.
70
throw new CoreException(status);
71         } finally {
72             try {
73                 if (featureStream != null)
74                     featureStream.close();
75             } catch (IOException JavaDoc e) {
76                 //ignore
77
}
78         }
79         return feature;
80     }
81
82     /*
83      * Creates an empty feature on the site
84      */

85     private IFeature createFeature(ISite site) throws CoreException {
86         Feature feature = null;
87         //TODO FeatureExecutableContentProvider is a non API class
88
IFeatureContentProvider contentProvider = new FeatureExecutableContentProvider(null);
89         feature = (Feature) createFeatureModel();
90         feature.setSite(site);
91         feature.setFeatureContentProvider(contentProvider);
92         return feature;
93     }
94
95     public FeatureModel createFeatureModel() {
96         return new BuildTimeFeature();
97     }
98 }
99
Popular Tags