1 11 package org.eclipse.pde.internal.build; 12 13 import java.io.IOException ; 14 import java.io.OutputStream ; 15 import java.util.LinkedHashMap ; 16 import java.util.Map ; 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.osgi.service.resolver.BundleDescription; 19 import org.eclipse.osgi.util.NLS; 20 import org.eclipse.pde.internal.build.builder.FeatureBuildScriptGenerator; 21 import org.eclipse.update.core.*; 22 import org.eclipse.update.core.model.URLEntryModel; 23 24 public class FeatureWriter extends XMLWriter implements IPDEBuildConstants { 25 protected Feature feature; 26 protected FeatureBuildScriptGenerator generator; 27 private Map parameters = new LinkedHashMap (10); 28 29 public FeatureWriter(OutputStream out, Feature feature, FeatureBuildScriptGenerator generator) throws IOException { 30 super(out); 31 this.feature = feature; 32 this.generator = generator; 33 } 34 35 public void printFeature() throws CoreException { 36 printFeatureDeclaration(); 37 printInstallHandler(); 38 printDescription(); 39 printCopyright(); 40 printLicense(); 41 printURL(); 42 printIncludes(); 43 printRequires(); 44 printPlugins(); 45 printData(); 46 endTag("feature"); super.close(); 48 } 49 50 public void printFeatureDeclaration() { 51 parameters.clear(); 52 parameters.put("id", feature.getFeatureIdentifier()); parameters.put("version", feature.getVersionedIdentifier().getVersion().toString()); parameters.put("label", feature.getLabelNonLocalized()); parameters.put("provider-name", feature.getProviderNonLocalized()); parameters.put("image", feature.getImageURLString()); parameters.put("os", feature.getOS()); parameters.put("arch", feature.getOSArch()); parameters.put("ws", feature.getWS()); parameters.put("nl", feature.getNL()); parameters.put("colocation-affinity", feature.getAffinityFeature()); parameters.put("primary", new Boolean (feature.isPrimary())); parameters.put("application", feature.getApplication()); 65 startTag("feature", parameters, true); } 67 68 public void printInstallHandler() { 69 if (feature.getInstallHandlerEntry() == null) 70 return; 71 parameters.clear(); 72 parameters.put("library", feature.getInstallHandlerModel().getLibrary()); parameters.put("handler", feature.getInstallHandlerModel().getHandlerName()); startTag("install-handler", parameters); endTag("install-handler"); } 77 78 public void printDescription() { 79 if (feature.getDescriptionModel() == null) 80 return; 81 parameters.clear(); 82 parameters.put("url", feature.getDescriptionModel().getURLString()); 84 startTag("description", parameters, true); printTabulation(); 86 printlnEscaped(feature.getDescriptionModel().getAnnotationNonLocalized()); 87 endTag("description"); } 89 90 private void printCopyright() { 91 if (feature.getCopyrightModel() == null) 92 return; 93 parameters.clear(); 94 parameters.put("url", feature.getCopyrightModel().getURLString()); startTag("copyright", parameters, true); printTabulation(); 97 printlnEscaped(feature.getCopyrightModel().getAnnotationNonLocalized()); 98 endTag("copyright"); } 100 101 public void printLicense() { 102 if (feature.getLicenseModel() == null) 103 return; 104 parameters.clear(); 105 parameters.put("url", feature.getLicenseModel().getURLString()); startTag("license", parameters, true); printTabulation(); 108 printlnEscaped(feature.getLicenseModel().getAnnotationNonLocalized()); 109 endTag("license"); } 111 112 public void printURL() { 113 if (feature.getUpdateSiteEntryModel() != null || feature.getDiscoverySiteEntryModels().length != 0) { 114 parameters.clear(); 115 116 startTag("url", null); if (feature.getUpdateSiteEntryModel() != null) { 118 parameters.clear(); 119 parameters.put("url", feature.getUpdateSiteEntryModel().getURLString()); parameters.put("label", feature.getUpdateSiteEntryModel().getAnnotationNonLocalized()); printTag("update", parameters, true, true, true); } 123 124 URLEntryModel[] siteEntries = feature.getDiscoverySiteEntryModels(); 125 for (int i = 0; i < siteEntries.length; i++) { 126 parameters.clear(); 127 parameters.put("url", siteEntries[i].getURLString()); parameters.put("label", siteEntries[i].getAnnotationNonLocalized()); printTag("discovery", parameters, true, true, true); } 131 endTag("url"); } 133 } 134 135 public void printIncludes() throws CoreException { 136 IIncludedFeatureReference[] features = feature.getRawIncludedFeatureReferences(); 137 for (int i = 0; i < features.length; i++) { 138 parameters.clear(); 139 try { 140 parameters.put("id", features[i].getVersionedIdentifier().getIdentifier()); IFeature tmpFeature = generator.getSite(false).findFeature(features[i].getVersionedIdentifier().getIdentifier(), null, true); 142 parameters.put("version", tmpFeature.getVersionedIdentifier().getVersion().toString()); } catch (CoreException e) { 144 String message = NLS.bind(Messages.exception_missingFeature, features[i].getVersionedIdentifier().getIdentifier()); 145 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_MISSING, message, null)); 146 } 147 148 printTag("includes", parameters, true, true, true); } 150 } 151 152 private void printRequires() { 153 if (feature.getImportModels().length == 0) 154 return; 155 startTag("requires", null); printImports(); 157 endTag("requires"); } 159 160 private void printImports() { 161 IImport[] imports = feature.getRawImports(); 162 for (int i = 0; i < imports.length; i++) { 163 parameters.clear(); 164 if (imports[i].getKind() == IImport.KIND_PLUGIN) { 165 parameters.put("plugin", imports[i].getVersionedIdentifier().getIdentifier()); parameters.put("version", imports[i].getVersionedIdentifier().getVersion().toString()); } else { 168 parameters.put("feature", imports[i].getVersionedIdentifier().getIdentifier()); parameters.put("version", imports[i].getVersionedIdentifier().getVersion().toString()); } 172 parameters.put("match", getStringForMatchingRule(imports[i].getRule())); printTag("import", parameters, true, true, true); } 175 } 176 177 181 private String getStringForMatchingRule(int ruleNumber) { 182 switch (ruleNumber) { 183 case 1 : 184 return "perfect"; case 2 : 186 return "equivalent"; case 3 : 188 return "compatible"; case 4 : 190 return "greaterOrEqual"; case 0 : 192 default : 193 return ""; } 195 } 196 197 public void printPlugins() throws CoreException { 198 IPluginEntry[] plugins = feature.getRawPluginEntries(); 199 for (int i = 0; i < plugins.length; i++) { 200 parameters.clear(); 201 parameters.put("id", plugins[i].getVersionedIdentifier().getIdentifier()); 203 String versionRequested = plugins[i].getVersionedIdentifier().getVersion().toString(); 204 BundleDescription effectivePlugin = null; 205 try { 206 effectivePlugin = generator.getSite(false).getRegistry().getResolvedBundle(plugins[i].getVersionedIdentifier().getIdentifier(), versionRequested); 207 } catch (CoreException e) { 208 String message = NLS.bind(Messages.exception_missingPlugin, plugins[i].getVersionedIdentifier()); 209 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_PLUGIN_MISSING, message, null)); 210 } 211 if (effectivePlugin == null) { 212 String message = NLS.bind(Messages.exception_missingPlugin, plugins[i].getVersionedIdentifier()); 213 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_PLUGIN_MISSING, message, null)); 214 } 215 parameters.put("version", effectivePlugin.getVersion()); parameters.put("fragment", new Boolean (plugins[i].isFragment())); parameters.put("os", plugins[i].getOS()); parameters.put("arch", plugins[i].getOSArch()); parameters.put("ws", plugins[i].getWS()); parameters.put("nl", plugins[i].getNL()); if (plugins[i] instanceof PluginEntry && !((PluginEntry)plugins[i]).isUnpack()) 222 parameters.put("unpack", Boolean.FALSE.toString()); parameters.put("download-size", new Long (plugins[i].getDownloadSize() != -1 ? plugins[i].getDownloadSize() : 0)); parameters.put("install-size", new Long (plugins[i].getInstallSize() != -1 ? plugins[i].getInstallSize() : 0)); printTag("plugin", parameters, true, true, true); } 227 } 228 229 private void printData() { 230 INonPluginEntry[] entries = feature.getNonPluginEntries(); 231 for (int i = 0; i < entries.length; i++) { 232 parameters.put("id", entries[i].getIdentifier()); parameters.put("os", entries[i].getOS()); parameters.put("arch", entries[i].getOSArch()); parameters.put("ws", entries[i].getWS()); parameters.put("nl", entries[i].getNL()); parameters.put("download-size", new Long (entries[i].getDownloadSize() != -1 ? entries[i].getDownloadSize() : 0)); parameters.put("install-size", new Long (entries[i].getInstallSize() != -1 ? entries[i].getInstallSize() : 0)); printTag("data", parameters, true, true, true); } 241 } 242 } 243 | Popular Tags |