package com.perforce.workspace.tjuricek.p4oauth.storage; import com.esotericsoftware.yamlbeans.YamlReader; import com.esotericsoftware.yamlbeans.YamlWriter; import com.perforce.workspace.tjuricek.p4oauth.config.P4OAuthConfig; import org.apache.commons.io.IOUtils; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; /** * Most of our "stores" really just sit on top of a file system structure. */ public interface FilesystemStore { /** * The stores must have access to the application configuration. */ P4OAuthConfig getConfig(); /** * Returns the path to the file based on our configured rootDirectory. * <p> * If there is no root directory configured in the system, we just generate * a file from the indicated paths, which should become a relative path * from the current working folder. * * @param paths * @return */ default File getFile(String... paths) { String rootDir = getConfig().getRootDirectory(); File cur = rootDir == null ? null : new File(rootDir); for (String path : paths) { cur = cur == null ? new File(path) : new File(cur, path); } return cur; } default void writeYamlFile(Object object, File file) throws IOException { FileWriter writer = null; try { writer = new FileWriter(file); YamlWriter yamlWriter = new YamlWriter(writer); yamlWriter.write(object); yamlWriter.close(); } finally { IOUtils.closeQuietly(writer); } } default <T> T readYamlFile(Class<T> classType, File file) throws IOException { FileReader reader = null; try { reader = new FileReader(file); YamlReader yamlReader = new YamlReader(reader); return yamlReader.read(classType); } finally { IOUtils.closeQuietly(reader); } } default void ensureParentExists(File file) { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 9095 | tjuricek | Added some basic test data and renamed "workspace" to "workshop" in package name | ||
#1 | 9089 | tjuricek |
Moving some code that worked via some manual validation to the workshop. This just implements a basic code authorization grant scheme. Automated tests are forthcoming, awating some gradle plugin work that should sit outside of this project. |