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; }
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); } } }