/** 读取project目录并完成初始化 */ private void init() { contentBox.removeAll(); // clear projectPanels.clear(); // clear publicLibraries.clear(); // clear File projectsDir = new File("projects"); if (!projectsDir.exists()) projectsDir.mkdir(); File libraryDir = new File("libProjects"); if (!libraryDir.exists()) libraryDir.mkdir(); syncProjectConfig(); File[] libFiles = libraryDir.listFiles(new ProjectFileFilter()); File[] projectFiles = projectsDir.listFiles(new ProjectFileFilter()); List<File> projects = new ArrayList<File>(); if (projectFiles != null) projects.addAll(Arrays.asList(projectFiles)); if (libFiles != null) projects.addAll(Arrays.asList(libFiles)); EditProjectHandler editHandler = new EditProjectHandler(); for (File projectFile : projects) { if (projectFile.getName().equals(".project")) continue; // 加强容错性 BatchPack pack = new BatchPack(projectFile.getAbsolutePath()); String fullName = projectFile.getName(); String fileName = fullName.substring(0, fullName.lastIndexOf('.')); if (pack.needImport()) { batchButton.setEnabled(false); progressBar.setString("正在同步导入" + fileName); progressBar.setIndeterminate(true); pack.importFromSVN(); records.setProjectVersion( projectFile.getAbsolutePath(), pack.getSVNVersion()); // ensure latest version records.saveRecords(); progressBar.setIndeterminate(false); progressBar.setString(""); batchButton.setEnabled(true); } ProjectPanel projectPanel = new ProjectPanel(pack, fileName); projectPanel.setEditProjectListener(editHandler); projectPanel.updateUI(); projectPanels.add(projectPanel); contentBox.add(projectPanel); } // prepare library for (ProjectPanel panel : projectPanels) { BatchPack pack = panel.getProjectBatch(); if (!pack.isLibrary()) continue; Attributes attributes = pack.getAttributes(); String projectPath = attributes.getProperty("projectPath"); String projectName = new File(projectPath).getName(); publicLibraries.put(projectName, projectPath); } // modify project to reference public library for (ProjectPanel panel : projectPanels) { prepareProjectPanel(panel); } contentBox.updateUI(); }
private void syncProjectConfig() { if (syncProjectConfigHelper == null) { Attributes attributes = new Attributes(); try { attributes.loadFromXML(new FileInputStream("config.xml")); if (attributes.containsKey(BatchPack.KEY_ACCOUNT)) { attributes.loadFromXML( new FileInputStream( Files.convert2AbsolutePath(".", attributes.getProperty(BatchPack.KEY_ACCOUNT)))); } syncProjectConfigHelper = new SVNHelper( attributes.getProperty("projectConfigUrl"), attributes.getProperty("userName"), attributes.getProperty("password")); int version = records.getProjectVersion(PackRecords.CONFIG_PROJECT_ID); if (version != syncProjectConfigHelper.getProjectVersion()) { syncProjectConfigHelper.exportProject(new File("projects").getAbsolutePath()); syncProjectConfigHelper.setProjectUrl(attributes.getProperty("libProjectConfigUrl")); syncProjectConfigHelper.exportProject(new File("libProjects").getAbsolutePath()); } records.setProjectVersion( PackRecords.CONFIG_PROJECT_ID, syncProjectConfigHelper.getProjectVersion()); records.saveRecords(); System.out.println("import latest config ok"); } catch (Exception e) { e.printStackTrace(); } } }