core/com.nokia.carbide.cpp.sdk.ui/src/com/nokia/carbide/cpp/internal/api/sdk/ui/TemplateUtils.java
changeset 0 fb279309251b
child 841 80149e1e5ec6
child 845 0e13f296b6a8
equal deleted inserted replaced
-1:000000000000 0:fb279309251b
       
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 package com.nokia.carbide.cpp.internal.api.sdk.ui;
       
    20 
       
    21 import java.util.ArrayList;
       
    22 import java.util.List;
       
    23 
       
    24 import org.osgi.framework.Version;
       
    25 
       
    26 import com.nokia.carbide.cpp.sdk.core.ISymbianSDK;
       
    27 import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin;
       
    28 import com.nokia.carbide.template.engine.ITemplate;
       
    29 
       
    30 public class TemplateUtils {
       
    31 	
       
    32 	private static final String FAMILY_DELIM = ":"; //$NON-NLS-1$
       
    33 	private static final String RANGE_DELIM = "-"; //$NON-NLS-1$
       
    34 	private static final String VERSION_DELIM = ";"; //$NON-NLS-1$
       
    35 
       
    36 	public static final String PROJECT_NAME = "projectName"; //$NON-NLS-1$
       
    37 	public static final String BASE_NAME = "baseName"; //$NON-NLS-1$
       
    38 	public static final String BASE_NAME_UPPER = "baseNameUpper"; //$NON-NLS-1$
       
    39 	public static final String BASE_NAME_LOWER = "baseNameLower"; //$NON-NLS-1$
       
    40 	public static final String PROJECT_LOCATION = "location"; //$NON-NLS-1$
       
    41 	public static final String USE_DEFAULT_LOCATION = "useDefaultLocation"; //$NON-NLS-1$
       
    42 
       
    43 	/**
       
    44 	 * @param symbianSDK
       
    45 	 * @param template
       
    46 	 * @return whether this sdk matches the template
       
    47 	 * template filter arguments:= framework[:versionSpec]
       
    48 	 * versionSpec is a list of version or versionRange delimited by ;
       
    49 	 * versionRange is a minVersion and maxVersion delimited by - 
       
    50 	 */
       
    51 	public static boolean sdkMatchesTemplate(ISymbianSDK symbianSDK, ITemplate template) {
       
    52 		Version sdkVersion = symbianSDK.getSDKVersion();
       
    53 		String family = symbianSDK.getFamily(); // ??? is this S60, UIQ, etc. ???
       
    54 		return sdkMatchesTemplate(sdkVersion, family, template);
       
    55 	}
       
    56 	
       
    57 	
       
    58 	private static boolean isSameFamily(String f1, String f2) {
       
    59 		if (f1.equalsIgnoreCase(f2))
       
    60 			return true;
       
    61 		
       
    62 		if ((f1.equalsIgnoreCase(ISymbianSDK.S60_FAMILY_ID) &&
       
    63 				f2.equalsIgnoreCase(ISymbianSDK.SERIES60_FAMILY_ID)) ||
       
    64 				(f2.equalsIgnoreCase(ISymbianSDK.S60_FAMILY_ID) &&
       
    65 						f1.equalsIgnoreCase(ISymbianSDK.SERIES60_FAMILY_ID)))
       
    66 			return true;
       
    67 		
       
    68 		return false;
       
    69 	}
       
    70 	
       
    71 	/**
       
    72 	 * @param symbianSDK
       
    73 	 * @param template
       
    74 	 * @return whether this sdk matches the template
       
    75 	 * template filter arguments:= family[:versionSpec]
       
    76 	 * versionSpec is a list of version or versionRange delimited by ;
       
    77 	 * versionRange is a minVersion and maxVersion delimited by - 
       
    78 	 */
       
    79 	public static boolean sdkMatchesTemplate(Version sdkVersion, String family, ITemplate template) {
       
    80 		String filterArgs = template.getFilterArguments();
       
    81 		if (filterArgs != null) {
       
    82 			String[] strings = filterArgs.split(FAMILY_DELIM);
       
    83 			if (strings.length > 0) {
       
    84 				if (!isSameFamily(family, strings[0]))
       
    85 					return false;
       
    86 				
       
    87 				if (strings.length > 1) {
       
    88 					String[] versions = strings[1].split(VERSION_DELIM);
       
    89 					for (int i = 0; i < versions.length; i++) {
       
    90 						String[] versionRange = versions[i].split(RANGE_DELIM);
       
    91 						if (versionRange.length == 1) {
       
    92 							Version version = Version.parseVersion(versionRange[0]);
       
    93 							if (sdkVersion.equals(version))
       
    94 								return true;
       
    95 						}
       
    96 						else if (versionRange.length > 1) {
       
    97 							Version minVersion = Version.parseVersion(versionRange[0]);
       
    98 							Version maxVersion = Version.parseVersion(versionRange[1]);
       
    99 							if (sdkVersion.compareTo(minVersion) >= 0 &&
       
   100 									sdkVersion.compareTo(maxVersion) <= 0)
       
   101 								return true;
       
   102 						}
       
   103 					}
       
   104 					return false;
       
   105 				}
       
   106 			}
       
   107 		}
       
   108 		return true;
       
   109 	}
       
   110 
       
   111 	public static List<ISymbianSDK> getEnabledSDKs() {
       
   112 		List<ISymbianSDK> enabledSDKList = new ArrayList<ISymbianSDK>();
       
   113 		
       
   114 		List<ISymbianSDK> sdkList = SDKCorePlugin.getSDKManager().getSDKList();
       
   115 		if (sdkList != null) {
       
   116 			// Only add SDKs that are enabled
       
   117 			for (ISymbianSDK currSDK : sdkList){
       
   118 				if (currSDK.isEnabled()){
       
   119 					enabledSDKList.add(currSDK);
       
   120 				}
       
   121 			}
       
   122 		}
       
   123 		
       
   124 		return enabledSDKList;
       
   125 	}
       
   126 
       
   127 }