From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- graphs/java/fgen/.gitignore | 38 ++++++ graphs/java/fgen/pom.xml | 133 +++++++++++++++++++++ .../main/java/fr/epita/assistants/fgen/FGen.java | 105 ++++++++++++++++ graphs/java/fgen/src/main/resources/example.txt | 3 + 4 files changed, 279 insertions(+) create mode 100644 graphs/java/fgen/.gitignore create mode 100644 graphs/java/fgen/pom.xml create mode 100644 graphs/java/fgen/src/main/java/fr/epita/assistants/fgen/FGen.java create mode 100644 graphs/java/fgen/src/main/resources/example.txt (limited to 'graphs/java/fgen') diff --git a/graphs/java/fgen/.gitignore b/graphs/java/fgen/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/graphs/java/fgen/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/graphs/java/fgen/pom.xml b/graphs/java/fgen/pom.xml new file mode 100644 index 0000000..d227bcc --- /dev/null +++ b/graphs/java/fgen/pom.xml @@ -0,0 +1,133 @@ + + + 4.0.0 + fr.epita.assistants + fgen + 1.0 + + + 21 + 5.9.1 + 3.13.0 + 3.5.0 + 3.1.1 + 3.1.0 + + UTF-8 + + ${project.build.directory}/surefire-reports + + + + + org.junit.jupiter + junit-jupiter + ${versions.junit} + + + org.apache.maven.surefire + surefire-junit-platform + ${versions.maven-surefire-plugin} + + + org.apache.maven + maven-compat + 3.9.8 + + + org.apache.maven + maven-plugin-api + 3.9.8 + + + org.apache.maven + maven-project + 2.2.1 + + + org.apache.maven + maven-core + 3.8.1 + + + org.apache.maven + maven-monitor + 2.2.1 + + + org.codehaus.plexus + plexus-utils + 3.0.24 + + + org.apache.maven.shared + maven-filtering + 3.3.2 + + + org.codehaus.plexus + plexus-interpolation + 1.13 + + + org.apache.maven + maven-profile + 2.2.1 + + + org.apache.maven + maven-artifact-manager + 2.2.1 + + + org.apache.maven + maven-plugin-registry + 2.2.1 + + + org.apache.maven + maven-repository-metadata + 2.2.1 + + + classworlds + classworlds + 1.1 + + + org.junit.platform + junit-platform-commons + 1.9.3 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${versions.maven-compiler-plugin} + + ${versions.java} + ${versions.java} + + + + org.apache.maven.plugins + maven-install-plugin + ${versions.maven-install-plugin} + + + + org.apache.maven.plugins + maven-surefire-plugin + ${versions.maven-surefire-plugin} + + ${surefire.reportsDirectory} + + + + + diff --git a/graphs/java/fgen/src/main/java/fr/epita/assistants/fgen/FGen.java b/graphs/java/fgen/src/main/java/fr/epita/assistants/fgen/FGen.java new file mode 100644 index 0000000..5f5a470 --- /dev/null +++ b/graphs/java/fgen/src/main/java/fr/epita/assistants/fgen/FGen.java @@ -0,0 +1,105 @@ +package fr.epita.assistants.fgen; + +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Comparator; +import java.util.stream.Stream; + +public class FGen { + private Path cwd; + + public FGen(final String inputPath) { + this.cwd = Paths.get(new File("").getAbsolutePath()); + try (InputStream in = ClassLoader.getSystemResourceAsStream(inputPath)) { + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String line; + while ((line = br.readLine()) != null) { + execute(line); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void execute(String l) { + String[] args = l.split("\\s+"); + switch (args[0]) { + case "+": + create(args[1]); + break; + case "-": + delete(args[1]); + break; + case ">": + ceedee(args[1]); + break; + } + } + + private void create(String pathName) { + Path path = cwd.resolve(pathName); + File f = new File(String.valueOf(path)); + if (pathName.endsWith("/")) { + if (!f.exists()) { + if (!f.mkdirs()) + { + throw new RuntimeException("Could not create directories"); + } + } + } else { + if (!f.exists()) { + try { + if (pathName.contains("/")) + { + String tmp = cwd.toString() + "/" + pathName.substring(0, pathName.lastIndexOf('/')); + if (!new File(tmp).exists()) + { + if (!new File(tmp).mkdirs()) + throw new RuntimeException("create(file): Could not create dirs"); + } + } + + if (!f.createNewFile()) + throw new RuntimeException("Could not create file"); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + } + + private void ceedee(String pathName) { + Path res_path = cwd.resolve(pathName); + if (Files.exists(res_path) && Files.isDirectory(res_path)) { + cwd = res_path; + } + else throw new RuntimeException("Invalid path provided to cd"); + } + private boolean deleteDirectory (File file){ + File[] contents = file.listFiles(); + if (contents != null) { + for (File f : contents) { + deleteDirectory(f); + } + } + return file.delete(); + } + + private void delete(String pathString) { + Path path = cwd.resolve(pathString); + File file = new File(String.valueOf(path)); + if (Files.isDirectory(path)) { + if (!deleteDirectory(file)) + throw new RuntimeException("Unable to delete dir"); + } else { + try { + if (!Files.deleteIfExists(path)) + return; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } +} \ No newline at end of file diff --git a/graphs/java/fgen/src/main/resources/example.txt b/graphs/java/fgen/src/main/resources/example.txt new file mode 100644 index 0000000..f864008 --- /dev/null +++ b/graphs/java/fgen/src/main/resources/example.txt @@ -0,0 +1,3 @@ ++ hello/dossier +> hello +- dossier \ No newline at end of file -- cgit v1.2.3