@Override public String toString() { return "ProjectRepository{" + "kind='" + kind + '\'' + ", user='" + getUser() + '\'' + ", repoName='" + getRepoName() + '\'' + ", url='" + url + '\'' + '}'; }
public String getRepoName() { if (repoName == null) { extractOrganisationAndUserFromUrl(); } return repoName; }
public static ProjectConfig parseProjectConfig(File file) throws IOException { return parseYaml(file, ProjectConfig.class); }
/** * Tries to find the project configuration from the current directory or a parent folder. * * If no fabric8.yml file can be found just return an empty configuration */ public static ProjectConfig findFromFolder(File folder) { if (folder.isDirectory()) { File projectConfigFile = new File(folder, FILE_NAME); if (projectConfigFile != null && projectConfigFile.exists() && projectConfigFile.isFile()) { return loadFromFolder(folder); } File parentFile = folder.getParentFile(); if (parentFile != null) { return findFromFolder(parentFile); } } return new ProjectConfig(); }
/** * Returns the configuration from the {@link #FILE_NAME} in the given folder or returns the default configuration */ public static ProjectConfig loadFromFolder(File folder) { File projectConfigFile = new File(folder, FILE_NAME); if (projectConfigFile != null && projectConfigFile.exists() && projectConfigFile.isFile()) { LOG.debug("Parsing fabric8 devops project configuration from: " + projectConfigFile.getName()); try { return ProjectConfigs.parseProjectConfig(projectConfigFile); } catch (IOException e) { LOG.warn("Failed to parse " + projectConfigFile + ". " + e, e); } } return new ProjectConfig(); }
public ProjectConfig getProjectConfig() { try { return ProjectConfigs.parseProjectConfig(readFile("fabric8.yml")); } catch (Exception e) { // its fine if no fabric8.yml file is found return null; } }
protected void updateConfiguration(UIExecutionContext context, ProjectConfig config) { Map<Object, Object> attributeMap = context.getUIContext().getAttributeMap(); ProjectConfigs.configureProperties(config, attributeMap); Object pipelineValue = attributeMap.get("selectedPipeline"); if (pipelineValue instanceof PipelineDTO) { PipelineDTO pipeline = (PipelineDTO) pipelineValue; if (pipeline != null) { config.setPipeline(pipeline.getValue()); } } }
/** * Saves the configuration as YAML in the given file */ public static boolean saveConfig(ProjectConfig config, File file) throws IOException { createObjectMapper().writeValue(file, config); return true; }
public boolean isGitHubProject() { return Objects.equals(getKind(), Kinds.GITHUB); }
public static List<ProjectRepository> loadProjectRepositories(File yamlFile) throws IOException { if (yamlFile.exists() && yamlFile.isFile()) { return parseYamlValues(yamlFile, ProjectRepository.class); } else { return new ArrayList<>(); } }
public String getGitUrl() { if (Strings.isNullOrBlank(gitUrl) && Strings.isNotBlank(url)) { if (isGitHubProject()) { gitUrl = url + ".git"; } } return gitUrl; }
public ProjectConfig getProjectConfig() { try { return ProjectConfigs.parseProjectConfig(readFile("fabric8.yml")); } catch (Exception e) { // its fine if no fabric8.yml file is found return null; } }
private static void updateConfiguration(UIExecutionContext context, ProjectConfig config) { Map<Object, Object> attributeMap = context.getUIContext().getAttributeMap(); ProjectConfigs.configureProperties(config, attributeMap); Object pipelineValue = attributeMap.get("selectedPipeline"); if (pipelineValue instanceof PipelineDTO) { PipelineDTO pipeline = (PipelineDTO) pipelineValue; if (pipeline != null) { config.setPipeline(pipeline.getValue()); } } }
public static String toYaml(Object dto) throws JsonProcessingException { ObjectMapper mapper = createObjectMapper(); return mapper.writeValueAsString(dto); }
public static ProjectConfig parseProjectConfig(String yaml) throws IOException { return parseYaml(yaml, ProjectConfig.class); }
public String getUser() { if (user == null) { extractOrganisationAndUserFromUrl(); } return user; }
private static <T> T parseYaml(File file, Class<T> clazz) throws IOException { ObjectMapper mapper = createObjectMapper(); return mapper.readValue(file, clazz); }
public static ProjectConfig parseProjectConfig(InputStream input) throws IOException { return parseYaml(input, ProjectConfig.class); }
private static <T> T parseYaml(InputStream inputStream, Class<T> clazz) throws IOException { ObjectMapper mapper = createObjectMapper(); return mapper.readValue(inputStream, clazz); }
private static <T> T parseYaml(String yaml, Class<T> clazz) throws IOException { ObjectMapper mapper = createObjectMapper(); return mapper.readValue(yaml, clazz); }