001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.util;
006:
007: import java.io.IOException;
008: import java.util.Iterator;
009: import java.util.Properties;
010: import java.util.Set;
011:
012: /**
013: * Terracotta Integration Module Util
014: * This should be the only source where the TIM names and versions
015: * are defined. Check content of integration-modules.properties
016: */
017: public class TIMUtil {
018: public static final String APACHE_STRUTS_1_1;
019: public static final String CGLIB_2_1_3;
020: public static final String COMMONS_COLLECTIONS_3_1;
021: public static final String EHCACHE_1_2_4;
022: public static final String EHCACHE_1_3;
023: public static final String HIBERNATE_3_1_2;
024: public static final String IBATIS_2_2_0;
025: public static final String JETTY_6_1;
026: public static final String LUCENE_2_0_0;
027: public static final String RIFE_1_6_0;
028: public static final String SUREFIRE_2_3;
029: public static final String WEBSPHERE_6_1_0_7;
030: public static final String WICKET_1_3;
031: public static final String MODULES_COMMON;
032:
033: private static final Properties modules = new Properties();
034:
035: static {
036: try {
037: modules
038: .load(TIMUtil.class
039: .getResourceAsStream("integration-modules.properties"));
040: } catch (IOException e) {
041: throw new RuntimeException(e);
042: }
043: APACHE_STRUTS_1_1 = lookup(".*apache-struts-1.1");
044: CGLIB_2_1_3 = lookup(".*cglib-2.1.3");
045: COMMONS_COLLECTIONS_3_1 = lookup(".*commons-collections-3.1");
046: EHCACHE_1_2_4 = lookup(".*ehcache-1.2.4");
047: EHCACHE_1_3 = lookup(".*ehcache-1.3");
048: HIBERNATE_3_1_2 = lookup(".*hibernate-3.1.2");
049: IBATIS_2_2_0 = lookup(".*iBatis-2.2.0");
050: JETTY_6_1 = lookup(".*jetty-6.1");
051: LUCENE_2_0_0 = lookup(".*lucene-2.0.0");
052: RIFE_1_6_0 = lookup(".*rife-1.6.0");
053: SUREFIRE_2_3 = lookup(".*surefire-2.3");
054: WEBSPHERE_6_1_0_7 = lookup(".*websphere-6.1.0.7");
055: WICKET_1_3 = lookup(".*wicket-1.3");
056: MODULES_COMMON = lookup("modules-common");
057: }
058:
059: private TIMUtil() {
060: // singleton
061: }
062:
063: private static String lookup(String pattern) {
064: String name = searchModuleName(pattern);
065: if (name == null) {
066: throw new RuntimeException(
067: "Can't find module with pattern: [" + pattern + "]");
068: }
069: return name;
070: }
071:
072: /**
073: * @param pattern: java regular expression
074: */
075: public static String searchModuleName(String pattern) {
076: if (modules.containsKey(pattern)) {
077: return pattern;
078: }
079: String name = null;
080: for (Iterator it = modules.keySet().iterator(); it.hasNext();) {
081: String moduleName = (String) it.next();
082: if (moduleName.matches(pattern)) {
083: name = moduleName;
084: break;
085: }
086: }
087: return name;
088: }
089:
090: public static String getVersion(String moduleName) {
091: return modules.getProperty(moduleName);
092: }
093:
094: public static Set getModuleNames() {
095: return modules.keySet();
096: }
097:
098: public static void main(String[] args) {
099: System.out.println(TIMUtil.getVersion(APACHE_STRUTS_1_1));
100: System.out.println(TIMUtil.getModuleNames());
101: }
102: }
|