KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > site > QualifierReplacer


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.build.site;
12
13 import com.ibm.icu.util.Calendar;
14 import java.util.Properties JavaDoc;
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 final String DOT_QUALIFIER = '.' + PROPERTY_QUALIFIER;
21
private static String JavaDoc globalQualifier = null;
22     
23     public static String JavaDoc replaceQualifierInVersion(String JavaDoc version, String JavaDoc id, String JavaDoc replaceTag, Properties JavaDoc 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 JavaDoc 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) { //Skip the lookup in the file if there is no entries
35
newQualifier = (String JavaDoc) newVersions.get(id + ',' + version.substring(0, version.length() - PROPERTY_QUALIFIER.length() - 1)); //First we check to see if there is a precise version
36
if (newQualifier == null) //If not found, then lookup for the id,0.0.0
37
newQualifier = (String JavaDoc) 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             // newQualifier = '.' + newQualifier;
45
} else if (replaceTag.equalsIgnoreCase(PROPERTY_NONE)) {
46             newQualifier = ""; //$NON-NLS-1$
47
} else {
48             newQualifier = replaceTag;
49         }
50
51         return version.replaceFirst(PROPERTY_QUALIFIER, newQualifier);
52     }
53
54     private static String JavaDoc getDate() {
55         final String JavaDoc empty = ""; //$NON-NLS-1$
56
int monthNbr = Calendar.getInstance().get(Calendar.MONTH) + 1;
57         String JavaDoc month = (monthNbr < 10 ? "0" : empty) + monthNbr; //$NON-NLS-1$
58

59         int dayNbr = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
60         String JavaDoc day = (dayNbr < 10 ? "0" : empty) + dayNbr; //$NON-NLS-1$
61

62         int hourNbr = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
63         String JavaDoc hour = (hourNbr < 10 ? "0" : empty) + hourNbr; //$NON-NLS-1$
64

65         int minuteNbr = Calendar.getInstance().get(Calendar.MINUTE);
66         String JavaDoc minute = (minuteNbr < 10 ? "0" : empty) + minuteNbr; //$NON-NLS-1$
67

68         return empty + Calendar.getInstance().get(Calendar.YEAR) + month + day + hour + minute;
69     }
70
71     public static void setGlobalQualifier(String JavaDoc globalQualifier) {
72         if (globalQualifier.length() > 0 && globalQualifier.charAt(0) != '$')
73             QualifierReplacer.globalQualifier = globalQualifier;
74     }
75 }
76
Popular Tags