ProjectService { public Project load(String projectHomeDir) { Project project = new Project(projectHomeDir); if (project.getProjectInfoFile().exists()) { project.loadSettings(); } else if (!validateProject(project)) { throw new ApplicationRuntimeException(String.format("Invalid project home '%s' - not a proper Citrus project", projectHomeDir)); } log.info("Loading project: " + projectHomeDir); Optional<File> applicationProperties = FileUtils.findFiles(projectHomeDir + File.separator + project.getSettings().getXmlSrcDirectory(), Collections.singleton("citrus-application.properties")).stream().findAny(); if (applicationProperties.isPresent()) { try (FileInputStream fileInputStream = new FileInputStream(applicationProperties.get())) { Properties properties = new Properties(); properties.load(fileInputStream); Optional.ofNullable(properties.get(Citrus.DEFAULT_APPLICATION_CONTEXT_PROPERTY)).ifPresent(value -> project.getSettings().setSpringApplicationContext(value.toString())); Optional.ofNullable(properties.get(Citrus.DEFAULT_APPLICATION_CONTEXT_CLASS_PROPERTY)).ifPresent(value -> project.getSettings().setSpringJavaConfig(value.toString())); } catch (IOException e) { log.warn("Failed to read application properties file in project", e); } } if (project.isMavenProject()) { try { String pomXml = FileUtils.readToString(new FileSystemResource(project.getMavenPomFile())); SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); nsContext.bindNamespaceUri("mvn", "http: Document pomDoc = XMLUtils.parseMessagePayload(pomXml); project.setName(evaluate(pomDoc, "/mvn:project/mvn:artifactId", nsContext)); String version = evaluate(pomDoc, "/mvn:project/mvn:version", nsContext); String parentVersion = evaluate(pomDoc, "/mvn:project/mvn:parent/mvn:version", nsContext); if (StringUtils.hasText(version)) { project.setVersion(version); } else if (StringUtils.hasText(parentVersion)) { project.setVersion(parentVersion); } project.getSettings().setBasePackage(evaluate(pomDoc, "/mvn:project/mvn:groupId", nsContext)); String citrusVersion = evaluate(pomDoc, "/mvn:project/mvn:properties/mvn:citrus.version", nsContext); if (StringUtils.hasText(citrusVersion)) { project.getSettings().setCitrusVersion(citrusVersion); } project.setDescription(evaluate(pomDoc, "/mvn:project/mvn:description", nsContext)); project.getSettings().setConnectorActive(StringUtils.hasText(evaluate(pomDoc, "/mvn:project/mvn:dependencies/mvn:dependency/mvn:artifactId[. = 'citrus-admin-connector']", nsContext))); } catch (IOException e) { throw new ApplicationRuntimeException("Unable to open Maven pom.xml file", e); } } else if (project.isAntProject()) { try { String buildXml = FileUtils.readToString(new FileSystemResource(project.getAntBuildFile())); SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); Document buildDoc = XMLUtils.parseMessagePayload(buildXml); project.setName(evaluate(buildDoc, "/project/@name", nsContext)); String citrusVersion = evaluate(buildDoc, "/project/property[@name='citrus.version']/@value", nsContext); if (StringUtils.hasText(citrusVersion)) { project.getSettings().setCitrusVersion(citrusVersion); } project.setDescription(evaluate(buildDoc, "/project/@description", nsContext)); } catch (IOException e) { throw new ApplicationRuntimeException("Unable to open Apache Ant build.xml file", e); } } saveProjectInfo(project); return project; }  @PostConstruct void loadDefaultProject(); Project load(String projectHomeDir); Project create(Repository repository); Project create(MavenArchetype archetype); File getSpringXmlApplicationContextFile(); File getSpringJavaConfigFile(); boolean hasSpringXmlApplicationContext(); boolean hasSpringJavaConfig(); void update(Project project); void saveProjectInfo(Project project); Properties getProjectProperties(); boolean validateProject(Project project); Project getActiveProject(); void closeActiveProject(); void setActiveProject(Project project); void addConnector(); void removeConnector(); List<Module> getModules(); void add(Module module); void remove(Module module); String getCloneDownloadUrl(Repository repository); void setFileBrowserService(FileBrowserService fileBrowserService); void setSpringBeanService(SpringBeanService springBeanService); void setSpringJavaConfigService(SpringJavaConfigService springJavaConfigService); void setEnvironment(Environment environment); String[] getRecentProjects(); void setProject(Project project);  }
@Test(expectedExceptions = { ApplicationRuntimeException.class }, expectedExceptionsMessageRegExp = "Invalid project home 'invalid' - not a proper Citrus project") public void testInvalidProjectHome() { projectService.load("invalid"); }