1 9 package org.eclipse.pde.internal.build.packager; 10 11 import java.io.*; 12 import java.util.ArrayList ; 13 import java.util.Properties ; 14 import org.eclipse.core.runtime.*; 15 import org.eclipse.osgi.service.resolver.BundleDescription; 16 import org.eclipse.osgi.util.NLS; 17 import org.eclipse.pde.internal.build.*; 18 import org.eclipse.pde.internal.build.ant.FileSet; 19 import org.eclipse.pde.internal.build.builder.FeatureBuildScriptGenerator; 20 import org.eclipse.pde.internal.build.builder.ModelBuildScriptGenerator; 21 import org.eclipse.pde.internal.build.site.BuildTimeSiteContentProvider; 22 import org.eclipse.update.core.IFeature; 23 24 public class PackageConfigScriptGenerator extends AssembleConfigScriptGenerator { 25 26 private Properties packagingProperties; 27 28 private String getFinalName(BundleDescription bundle, String shape) { 29 final String JAR = "jar"; final String DOT_JAR = '.' + JAR; 31 if (! AbstractScriptGenerator.getPropertyAsBoolean(IBuildPropertiesConstants.PROPERTY_PACKAGER_AS_NORMALIZER)) { 32 Path path = new Path(bundle.getLocation()); 33 if (shape.equals(FILE) && !JAR.equalsIgnoreCase(path.getFileExtension())) 34 return path.lastSegment().concat(DOT_JAR); 35 return path.lastSegment(); 36 } 37 if (shape.equals(FILE)) 38 return ModelBuildScriptGenerator.getNormalizedName(bundle) + DOT_JAR; 39 return ModelBuildScriptGenerator.getNormalizedName(bundle); 40 } 41 42 private String getFinalName(IFeature feature) { 43 if (! AbstractScriptGenerator.getPropertyAsBoolean(IBuildPropertiesConstants.PROPERTY_PACKAGER_AS_NORMALIZER)) { 44 Path featurePath = new Path(feature.getURL().getPath()); 45 return featurePath.segment(featurePath.segmentCount() - 2); 46 } 47 return FeatureBuildScriptGenerator.getNormalizedName(feature); 48 } 49 50 protected void generateGatherBinPartsCalls() { String excludedFiles = null; 52 if (AbstractScriptGenerator.getPropertyAsBoolean(IBuildPropertiesConstants.PROPERTY_PACKAGER_AS_NORMALIZER)) 53 excludedFiles = "build.properties, .project, .classpath"; IPath baseLocation = null; 55 try { 56 String url = ((BuildTimeSiteContentProvider) getSite(false).getSiteContentProvider()).getInstalledBaseURL(); 57 if (url != null) 58 baseLocation = new Path(url); 59 } catch (CoreException e) { 60 } 62 for (int i = 0; i < plugins.length; i++) { 63 Path pluginLocation = new Path(plugins[i].getLocation()); 64 String location = pluginLocation.toOSString(); 65 boolean isFolder = isFolder(pluginLocation); 66 67 if (baseLocation != null && baseLocation.isPrefixOf(pluginLocation)) { 69 IPath relative = pluginLocation.removeFirstSegments(baseLocation.segmentCount()); 70 location = new Path(Utils.getPropertyFormat(PROPERTY_BASE_LOCATION)).append(relative).toOSString(); 71 } 72 if (isFolder) { 73 script.printCopyTask(null, Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '/' + Utils.getPropertyFormat(PROPERTY_PLUGIN_ARCHIVE_PREFIX) + '/' + getFinalName(plugins[i], FOLDER), new FileSet[] {new FileSet(location, null, null, null, excludedFiles, null, null)}, false, false); 74 } else { 75 script.printCopyFileTask(location, Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '/' + Utils.getPropertyFormat(PROPERTY_PLUGIN_ARCHIVE_PREFIX) + '/' + getFinalName(plugins[i], FILE), false); 76 } 77 } 78 79 for (int i = 0; i < features.length; i++) { 80 IPath featureLocation = new Path(features[i].getURL().getPath()); featureLocation = featureLocation.removeLastSegments(1); 82 String location = featureLocation.toOSString(); 83 if (baseLocation != null && baseLocation.isPrefixOf(featureLocation)) { 84 IPath relative = featureLocation.removeFirstSegments(baseLocation.segmentCount()); 85 location = new Path(Utils.getPropertyFormat(PROPERTY_BASE_LOCATION)).append(relative).toOSString(); 86 } 87 script.printCopyTask(null, Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '/' + Utils.getPropertyFormat(PROPERTY_FEATURE_ARCHIVE_PREFIX) + '/' + getFinalName(features[i]), new FileSet[] {new FileSet(location, null, null, null, null, null, null)}, false, false); 88 } 89 90 if (packagingProperties.size() != 0) { 91 String filesToPackage = null; 92 filesToPackage = packagingProperties.getProperty(ROOT, null); 93 if (filesToPackage != null) 94 filesToPackage += ','; 95 96 String tmp = packagingProperties.getProperty(ROOT_PREFIX + configInfo.toString("."), null); if (tmp != null) 98 filesToPackage += tmp; 99 100 if (filesToPackage == null) 101 filesToPackage = "**/**"; 103 FileSet rootFiles = new FileSet(Utils.getPropertyFormat("tempDirectory") + '/' + configInfo.toStringReplacingAny(".", ANY_STRING) + "/eclipse", null, filesToPackage, null, null, null, null); String target = Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER); script.printCopyTask(null, target, new FileSet[] {rootFiles}, false, false); 106 107 Utils.generatePermissions(packagingProperties, configInfo, PROPERTY_ECLIPSE_BASE, script); 108 109 rootFileProviders = new ArrayList (1); 111 rootFileProviders.add("elt"); } 113 } 114 115 public String getTargetName() { 116 return "package" + (featureId.equals("") ? "" : ('.' + featureId)) + (configInfo.equals(Config.genericConfig()) ? "" : ('.' + configInfo.toStringReplacingAny(".", ANY_STRING))); } 118 119 private boolean isFolder(Path pluginLocation) { 120 return pluginLocation.toFile().isDirectory(); 121 } 122 123 public void setPackagingPropertiesLocation(String packagingPropertiesLocation) throws CoreException { 124 packagingProperties = new Properties (); 125 if (packagingPropertiesLocation == null || packagingPropertiesLocation.equals("")) return; 127 128 InputStream propertyStream = null; 129 try { 130 propertyStream = new BufferedInputStream(new FileInputStream(packagingPropertiesLocation)); 131 try { 132 packagingProperties.load(new BufferedInputStream(propertyStream)); 133 } finally { 134 propertyStream.close(); 135 } 136 } catch (FileNotFoundException e) { 137 String message = NLS.bind(Messages.exception_readingFile, packagingPropertiesLocation); 138 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_READING_FILE, message, e)); 139 } catch (IOException e) { 140 String message = NLS.bind(Messages.exception_readingFile, packagingPropertiesLocation); 141 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_READING_FILE, message, e)); 142 } 143 } 144 145 protected void generateGatherSourceCalls() { 146 } 148 149 protected FileSet[] generatePermissions(boolean zip) { 150 return new FileSet[0]; 152 } 153 154 protected void generateGZipTarget(boolean assembling) { 155 super.generateGZipTarget(false); 156 } 157 158 public void generateTarGZTasks(boolean assembling) { 159 super.generateTarGZTasks(false); 160 } 161 162 protected Object [] getFinalShape(BundleDescription bundle) { 163 if (AbstractScriptGenerator.getPropertyAsBoolean(IBuildPropertiesConstants.PROPERTY_PACKAGER_MODE) == true) { 164 String shape = isFolder(new Path(bundle.getLocation())) ? FOLDER : FILE; 165 return new Object [] {getFinalName(bundle, shape), shape}; 166 } 167 return super.getFinalShape(bundle); 168 } 169 170 protected Object [] getFinalShape(IFeature feature) { 171 if (AbstractScriptGenerator.getPropertyAsBoolean(IBuildPropertiesConstants.PROPERTY_PACKAGER_MODE) == true) 172 return new Object [] {getFinalName(feature), FOLDER}; 173 return super.getFinalShape(feature); 174 } 175 } 176 | Popular Tags |