1 11 package org.eclipse.pde.internal.build.site; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 import java.net.URL ; 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 28 public class BuildTimeFeatureFactory extends BaseFeatureFactory implements IFeatureFactory, IPDEBuildConstants, IBuildPropertiesConstants { 29 public final static String BUILDTIME_FEATURE_FACTORY_ID = PI_PDEBUILD + ".BuildTimeFeatureFactory"; 31 public IFeature createFeature(URL url, ISite site, IProgressMonitor p) throws CoreException { 32 Feature feature = null; 33 InputStream featureStream = null; 34 35 if (url == null) 36 return createFeature(site); 37 38 try { 39 IFeatureContentProvider contentProvider = new FeatureExecutableContentProvider(url); 41 42 URL nonResolvedURL = contentProvider.getFeatureManifestReference(null).asURL(); 43 URL resolvedURL = URLEncoder.encode(nonResolvedURL); 44 45 featureStream = resolvedURL.openStream(); 46 feature = (Feature) this.parseFeature(featureStream); 47 48 String qualifier = AbstractScriptGenerator.readProperties(new Path(url.getFile()).removeLastSegments(1).toOSString(), PROPERTIES_FILE, IStatus.OK).getProperty(PROPERTY_QUALIFIER); 49 String newVersion = QualifierReplacer.replaceQualifierInVersion(feature.getFeatureVersion(), feature.getFeatureIdentifier(), qualifier, ((BuildTimeSite) site).getFeatureVersions()); 50 if (newVersion != null){ 51 if (feature.getFeatureVersion().endsWith(PROPERTY_QUALIFIER) && (qualifier == null || qualifier.equalsIgnoreCase(PROPERTY_CONTEXT))) { 53 int idx = feature.getFeatureVersion().lastIndexOf("."); ((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 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 e) { 67 String 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); throw new CoreException(status); 71 } finally { 72 try { 73 if (featureStream != null) 74 featureStream.close(); 75 } catch (IOException e) { 76 } 78 } 79 return feature; 80 } 81 82 85 private IFeature createFeature(ISite site) throws CoreException { 86 Feature feature = null; 87 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 |