예제 #1
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;
  }
예제 #2
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);
      }
    }
  }
예제 #3
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;
  }