public ProjectConfig getProjectConfig() { try { return ProjectConfigs.parseProjectConfig(readFile("fabric8.yml")); } catch (Exception e) { // its fine if no fabric8.yml file is found return null; } }
/** * Saves the fabric8.yml file to the given project directory */ public static boolean saveToFolder(File basedir, ProjectConfig config, boolean overwriteIfExists) throws IOException { File file = new File(basedir, ProjectConfigs.FILE_NAME); if (file.exists()) { if (!overwriteIfExists) { LOG.warn("Not generating " + file + " as it already exists"); return false; } } return saveConfig(config, file); }
/** * 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; }
boolean hasFile = false; if (configFile.exists()) { config = ProjectConfigs.parseProjectConfig(configFile); hasFile = true; operation = "Created"; ProjectConfigs.saveConfig(config, configFile); message = operation + " " + fileName; ProjectConfigs.defaultEnvironments(config, namespace);
/** * 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(); }
ProjectConfig projectConfig = ProjectConfigs.findFromFolder(folder); if (projectConfig != null) { LinkedHashMap<String, String> environments = projectConfig.getEnvironments();
public static ProjectConfig parseProjectConfig(File file) throws IOException { return parseYaml(file, ProjectConfig.class); }
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()); } } }
/** * Returns the project config from the given url if it exists or null */ public static ProjectConfig loadFromUrl(String url) { if (Strings.isNotBlank(url)) { try { return loadFromUrl(new URL(url)); } catch (MalformedURLException e) { LOG.warn("Failed to create URL from: " + url + ". " + e, e); } } return null; }
public static ProjectConfig parseProjectConfig(String yaml) throws IOException { return parseYaml(yaml, ProjectConfig.class); }
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()); } } }
public ProjectConfig getProjectConfig() { try { return ProjectConfigs.parseProjectConfig(readFile("fabric8.yml")); } catch (Exception e) { // its fine if no fabric8.yml file is found return null; } }
public static String toYaml(Object dto) throws JsonProcessingException { ObjectMapper mapper = createObjectMapper(); return mapper.writeValueAsString(dto); }
public static ProjectConfig parseProjectConfig(InputStream input) throws IOException { return parseYaml(input, ProjectConfig.class); }
/** * Returns the project config from the given url if it exists or null */ public static ProjectConfig loadFromUrl(URL url) { InputStream input = null; try { input = url.openStream(); } catch (FileNotFoundException e) { LOG.info("No fabric8.yml at URL: " + url); } catch (IOException e) { LOG.warn("Failed to open fabric8.yml file at URL: " + url + ". " + e, e); } if (input != null) { try { LOG.info("Parsing " + ProjectConfigs.FILE_NAME + " from " + url); return ProjectConfigs.parseProjectConfig(input); } catch (IOException e) { LOG.warn("Failed to parse " + ProjectConfigs.FILE_NAME + " from " + url + ". " + e, e); } } return null; }
private static <T> T parseYaml(File file, Class<T> clazz) throws IOException { ObjectMapper mapper = createObjectMapper(); return mapper.readValue(file, clazz); }
/** * 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(); }
private static <T> T parseYaml(InputStream inputStream, Class<T> clazz) throws IOException { ObjectMapper mapper = createObjectMapper(); return mapper.readValue(inputStream, clazz); }
File configFile = getProjectConfigFile(context, getSelectedProject(context)); if (configFile != null && configFile.exists()) { config = ProjectConfigs.parseProjectConfig(configFile);
private static <T> T parseYaml(String yaml, Class<T> clazz) throws IOException { ObjectMapper mapper = createObjectMapper(); return mapper.readValue(yaml, clazz); }