1 11 package org.eclipse.pde.internal.build.site; 12 13 import com.ibm.icu.util.Calendar; 14 import java.util.Properties ; 15 import org.eclipse.pde.internal.build.AbstractScriptGenerator; 16 import org.eclipse.pde.internal.build.IBuildPropertiesConstants; 17 import org.osgi.framework.Version; 18 19 public class QualifierReplacer implements IBuildPropertiesConstants { 20 private static String globalQualifier = null; 22 23 public static String replaceQualifierInVersion(String version, String id, String replaceTag, Properties newVersions) { 24 if (! AbstractScriptGenerator.getPropertyAsBoolean(IBuildPropertiesConstants.PROPERTY_PACKAGER_AS_NORMALIZER)) 25 return version; 26 if (!version.endsWith(PROPERTY_QUALIFIER)) 27 return version; 28 29 String newQualifier = null; 30 if (replaceTag == null || replaceTag.equalsIgnoreCase(PROPERTY_CONTEXT)) { 31 if (globalQualifier != null) 32 newQualifier = globalQualifier; 33 34 if (newQualifier == null && newVersions != null && newVersions.size() != 0) { newQualifier = (String ) newVersions.get(id + ',' + version.substring(0, version.length() - PROPERTY_QUALIFIER.length() - 1)); if (newQualifier == null) newQualifier = (String ) newVersions.get(id + ',' + Version.emptyVersion.toString()); 38 if (newQualifier == null) 39 newQualifier = newVersions.getProperty(DEFAULT_MATCH_ALL); 40 } 41 if (newQualifier == null) 42 newQualifier = getDate(); 43 44 } else if (replaceTag.equalsIgnoreCase(PROPERTY_NONE)) { 46 newQualifier = ""; } else { 48 newQualifier = replaceTag; 49 } 50 51 return version.replaceFirst(PROPERTY_QUALIFIER, newQualifier); 52 } 53 54 private static String getDate() { 55 final String empty = ""; int monthNbr = Calendar.getInstance().get(Calendar.MONTH) + 1; 57 String month = (monthNbr < 10 ? "0" : empty) + monthNbr; 59 int dayNbr = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); 60 String day = (dayNbr < 10 ? "0" : empty) + dayNbr; 62 int hourNbr = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); 63 String hour = (hourNbr < 10 ? "0" : empty) + hourNbr; 65 int minuteNbr = Calendar.getInstance().get(Calendar.MINUTE); 66 String minute = (minuteNbr < 10 ? "0" : empty) + minuteNbr; 68 return empty + Calendar.getInstance().get(Calendar.YEAR) + month + day + hour + minute; 69 } 70 71 public static void setGlobalQualifier(String globalQualifier) { 72 if (globalQualifier.length() > 0 && globalQualifier.charAt(0) != '$') 73 QualifierReplacer.globalQualifier = globalQualifier; 74 } 75 } 76 | Popular Tags |