01: /*******************************************************************************
02: * Copyright (c) 2004, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM - Initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.build.site;
11:
12: import com.ibm.icu.util.Calendar;
13: import java.util.Properties;
14: import org.eclipse.pde.internal.build.AbstractScriptGenerator;
15: import org.eclipse.pde.internal.build.IBuildPropertiesConstants;
16: import org.osgi.framework.Version;
17:
18: public class QualifierReplacer implements IBuildPropertiesConstants {
19: // private static final String DOT_QUALIFIER = '.' + PROPERTY_QUALIFIER;
20: private static String globalQualifier = null;
21:
22: public static String replaceQualifierInVersion(String version,
23: String id, String replaceTag, Properties newVersions) {
24: if (!AbstractScriptGenerator
25: .getPropertyAsBoolean(IBuildPropertiesConstants.PROPERTY_PACKAGER_AS_NORMALIZER))
26: return version;
27: if (!version.endsWith(PROPERTY_QUALIFIER))
28: return version;
29:
30: String newQualifier = null;
31: if (replaceTag == null
32: || replaceTag.equalsIgnoreCase(PROPERTY_CONTEXT)) {
33: if (globalQualifier != null)
34: newQualifier = globalQualifier;
35:
36: if (newQualifier == null && newVersions != null
37: && newVersions.size() != 0) { //Skip the lookup in the file if there is no entries
38: newQualifier = (String) newVersions.get(id
39: + ','
40: + version.substring(0, version.length()
41: - PROPERTY_QUALIFIER.length() - 1)); //First we check to see if there is a precise version
42: if (newQualifier == null) //If not found, then lookup for the id,0.0.0
43: newQualifier = (String) newVersions.get(id + ','
44: + Version.emptyVersion.toString());
45: if (newQualifier == null)
46: newQualifier = newVersions
47: .getProperty(DEFAULT_MATCH_ALL);
48: }
49: if (newQualifier == null)
50: newQualifier = getDate();
51:
52: // newQualifier = '.' + newQualifier;
53: } else if (replaceTag.equalsIgnoreCase(PROPERTY_NONE)) {
54: newQualifier = ""; //$NON-NLS-1$
55: } else {
56: newQualifier = replaceTag;
57: }
58:
59: return version.replaceFirst(PROPERTY_QUALIFIER, newQualifier);
60: }
61:
62: private static String getDate() {
63: final String empty = ""; //$NON-NLS-1$
64: int monthNbr = Calendar.getInstance().get(Calendar.MONTH) + 1;
65: String month = (monthNbr < 10 ? "0" : empty) + monthNbr; //$NON-NLS-1$
66:
67: int dayNbr = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
68: String day = (dayNbr < 10 ? "0" : empty) + dayNbr; //$NON-NLS-1$
69:
70: int hourNbr = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
71: String hour = (hourNbr < 10 ? "0" : empty) + hourNbr; //$NON-NLS-1$
72:
73: int minuteNbr = Calendar.getInstance().get(Calendar.MINUTE);
74: String minute = (minuteNbr < 10 ? "0" : empty) + minuteNbr; //$NON-NLS-1$
75:
76: return empty + Calendar.getInstance().get(Calendar.YEAR)
77: + month + day + hour + minute;
78: }
79:
80: public static void setGlobalQualifier(String globalQualifier) {
81: if (globalQualifier == null || globalQualifier.length() == 0)
82: QualifierReplacer.globalQualifier = null;
83: else if (globalQualifier.length() > 0
84: && globalQualifier.charAt(0) != '$')
85: QualifierReplacer.globalQualifier = globalQualifier;
86: }
87: }
|