Beispiel #1
0
  private static void createRepository(File sub, List<Repository> list, int i)
      throws ContainerException {

    if (sub.isDirectory()) {
      try {
        ContainerConfig config = OsgiServiceUtil.getOsgiService(ContainerConfig.class);

        String reposiName =
            sub.getPath().substring(config.getSofaContainerHome().getPath().length());
        // list.add(new LocalRepository(StringUtil.formatPath(reposiName), sub.toURI(), i + 1));
        list.add(createRepository(StringUtil.formatPath(reposiName)));
        // 子目录sub.getName()
        File[] subDirs =
            sub.listFiles(
                new FileFilter() {

                  public boolean accept(File pathname) {

                    return pathname.isDirectory();
                  }
                });
        if (subDirs != null && subDirs.length > 0) {
          // 创建子库
          for (File f : subDirs) {
            createRepository(f, list, i + 1);
          }
        }
      } catch (Throwable e) {
        throw new ContainerException(e);
      }
    }
  }
Beispiel #2
0
  public static Repository createRepository(String repository) throws ContainerException {

    if (repositorys != null) {
      for (Repository r : repositorys) {

        if (r.getName().endsWith(repository)) {
          return r;
        }
      }
    } else {
      repositorys = new LinkedList<Repository>();
    }

    ContainerConfig config = OsgiServiceUtil.getOsgiService(ContainerConfig.class);
    File home = config.getSofaContainerHome();
    File file = null;
    if (repository.startsWith("/repository")
        || repository.startsWith("repository")
        || repository.startsWith("/kernel")
        || repository.startsWith("kernel")
        || repository.startsWith("stage")
        || repository.startsWith("/stage")) {
      file = new File(home, repository);
    } else {
      file = new File(new File(home, "/repository"), repository);
    }

    String reposiName = file.getPath().substring(config.getSofaContainerHome().getPath().length());
    Repository exactRep = new LocalRepository(StringUtil.formatPath(reposiName), file.toURI(), 200);
    repositorys.add(exactRep);
    return exactRep;
  }
Beispiel #3
0
  /**
   * 获取自动启动的bundle标识集合.
   *
   * @return bundle的标识名集合
   */
  public String[] getAutoStartBundleSymbolicNames() {

    String val = "";
    try {
      val = StringUtil.trim(properties.get("repository.autostart.bundles"));
    } catch (IllegalAccessException e) {
    }
    if (val.equals("")) {
      return new String[] {
        "org.springframework.osgi.core",
        "org.springframework.osgi.extender",
        "org.springframework.osgi.io",
        "org.springframework.osgi.web",
        "org.springframework.core",
        "org.springframework.beans",
        "org.springframework.context",
        "org.springframework.aop",
        "org.springframework.aspects",
        "org.springframework.jdbc",
        "org.springframework.orm",
        "org.springframework.oxm",
        "org.springframework.transaction",
        "org.springframework.web.servlet",
        "com.lc.sofa.container.web",
        "com.lc.sofa.container.org.eclipse.equinox.http.servlet"
      };
    }
    return val.split(",");
  }
Beispiel #4
0
  /**
   * 热部署目录监控扫描时间
   *
   * @return 热部署目录监控扫描时间间隔
   */
  public int getHotDeployDirScanInterval() {

    int val = StringUtil.toInt(properties.get(DEPLOY_HOT_DIR_SCAN_INTERAL));
    if (val == 0) {
      val = 3000;
    }
    return val;
  }
Beispiel #5
0
  /**
   * 获取热部署目录
   *
   * @return 热部署目录
   */
  public File getHotDeployDir() {

    String val = properties.get(DEPLOY_HOT_DIR);
    if (StringUtil.isEmpty(val)) {
      val = "pickup";
    }
    return new File(sofaContainerHome, val);
  }
Beispiel #6
0
  /**
   * 是否记录组件状态
   *
   * @return true 记录组件状态,false 不记录
   */
  public boolean rememberBundleState() {

    try {
      return StringUtil.toBoolean(properties.get("repository.remember.bundle.state"));
    } catch (IllegalAccessException e) {
      return true;
    }
  }
Beispiel #7
0
  /**
   * 应用平台组件库
   *
   * @return 应用平台组件库跟目录
   */
  public String[] getAppPlatformDirs() {

    String val = properties.get("repository.appPlatform.dirs");
    if (StringUtil.isEmpty(val)) {
      val = "acs";
    }
    return val.split(",");
  }
Beispiel #8
0
  /**
   * SOFA平台组件库
   *
   * @return SOFA平台组件跟目录
   */
  public File getSOFARootDir() {

    String val = properties.get("repository.sofa.root.dir");
    if (StringUtil.isEmpty(val)) {
      val = "sofa";
    }
    return new File(sofaContainerHome, REPOSITORY_ROOT_NAME + "/" + val);
  }
Beispiel #9
0
  public String get3rdReposityName() {

    String val = properties.get("repository.3rd.root.dir");
    if (StringUtil.isEmpty(val)) {
      val = "3rd";
    }
    return REPOSITORY_ROOT_NAME + "/" + val;
  }
Beispiel #10
0
  /**
   * 当组件库中存在多个相同组件(组件标识和版本相同)时是否抛出异常。
   *
   * @return true 抛出异常并放弃本组件的加载;取值为false时不抛出异常并取更新时间最新的组件加载。
   */
  public boolean isThrowExceptionByDupbundle() {

    String val = "";
    try {
      val = StringUtil.trim(properties.get("repository.dupbundle.throwexception"));
    } catch (IllegalAccessException e) {
    }
    return val.equals("") || val.equals("false") ? false : true;
  }
Beispiel #11
0
  /**
   * 当记录组件状态时排除掉不被记录的组件类型(如第三方组件)
   *
   * @return 组件库目录集
   */
  public String[] getNoRememberBundleStateType() {

    String val = "";
    try {
      val = StringUtil.trim(properties.get("repository.remember.bundle.state.noinclude"));
    } catch (IllegalAccessException e) {
    }
    if (val.equals("")) {
      return new String[] {"3rd"};
    }
    return val.split(",");
  }
Beispiel #12
0
  /**
   * 组件库启动顺序
   *
   * @return 按启动顺序排列的目录集合
   */
  public String getRepositoryByStartOrder() {

    String val = "";
    try {
      val = StringUtil.trim(properties.get("repository.start.order"));
    } catch (IllegalAccessException e) {
    }
    if (val.equals("")) {
      val = "3rd,kernel/ext,sofa,acs,stage";
    }
    return val;
  }
Beispiel #13
0
  /**
   * 返回组件分类和组件库的映射配置串
   *
   * @return 组件分类1:组件库1,组件分类2:组件库, 组件分类3:组件库
   */
  public String getRepositoryBundleCategoryMapperStr() {

    String val = "";
    try {
      val = StringUtil.trim(properties.get("repository.bundle.category.mapper"));
    } catch (IllegalAccessException e) {
    }
    if (val.equals("")) {
      // 默认值
      val = "sofa:sofa,acs:acs,others:3rd/upload";
    }
    return val;
  }
Beispiel #14
0
  public static List<Repository> createRepositories(String[] rsos) throws ContainerException {

    long b = System.currentTimeMillis();
    String sch = RepositoryConfig.getInstance().getSofaContainerHome(); // 跟目录

    List<Repository> list = new LinkedList<Repository>();
    String res = RepositoryConfig.getInstance().getRepositoryByStartOrder();
    log.info(I18n.getMessage("RF001", res));
    int i = 0;
    for (String rs : rsos) {
      i++;
      if (rs.startsWith("/") && (!rs.startsWith("repository") || !rs.startsWith("/repository"))) {
        rs = "/repository" + rs;
      }
      File file = new File(sch, rs);
      list.add(createRepository(StringUtil.formatPath(rs)));
      // 子目录
      if (!rs.endsWith(Constains.REPOSIRORY_STAGE_NAME)) {
        File[] subDirs =
            file.listFiles(
                new FileFilter() {

                  public boolean accept(File pathname) {

                    return pathname.isDirectory();
                  }
                });

        if (subDirs != null && subDirs.length > 0) {
          // 创建子库
          for (File sub : subDirs) {
            i++;
            createRepository(sub, list, i);
          }
        }
      }
    }
    long t = System.currentTimeMillis() - b;
    log.info(I18n.getMessage("RF002", res, t));
    return list;
  }