summaryrefslogtreecommitdiff
path: root/graphs/java/fgen
diff options
context:
space:
mode:
Diffstat (limited to 'graphs/java/fgen')
-rw-r--r--graphs/java/fgen/.gitignore38
-rw-r--r--graphs/java/fgen/pom.xml133
-rw-r--r--graphs/java/fgen/src/main/java/fr/epita/assistants/fgen/FGen.java105
-rw-r--r--graphs/java/fgen/src/main/resources/example.txt3
4 files changed, 279 insertions, 0 deletions
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>fr.epita.assistants</groupId>
+ <artifactId>fgen</artifactId>
+ <version>1.0</version>
+
+ <properties>
+ <versions.java>21</versions.java>
+ <versions.junit>5.9.1</versions.junit>
+ <versions.maven-compiler-plugin>3.13.0</versions.maven-compiler-plugin>
+ <versions.maven-surefire-plugin>3.5.0</versions.maven-surefire-plugin>
+ <versions.maven-jar-plugin>3.1.1</versions.maven-jar-plugin>
+ <versions.maven-install-plugin>3.1.0</versions.maven-install-plugin>
+
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <surefire.reportsDirectory>${project.build.directory}/surefire-reports</surefire.reportsDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <version>${versions.junit}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-junit-platform</artifactId>
+ <version>${versions.maven-surefire-plugin}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-compat</artifactId>
+ <version>3.9.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>3.9.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-monitor</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>3.0.24</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-filtering</artifactId>
+ <version>3.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-interpolation</artifactId>
+ <version>1.13</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-profile</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact-manager</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-registry</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-repository-metadata</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>classworlds</groupId>
+ <artifactId>classworlds</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-commons</artifactId>
+ <version>1.9.3</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${versions.maven-compiler-plugin}</version>
+ <configuration>
+ <source>${versions.java}</source>
+ <target>${versions.java}</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>${versions.maven-install-plugin}</version>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${versions.maven-surefire-plugin}</version>
+ <configuration>
+ <reportsDirectory>${surefire.reportsDirectory}</reportsDirectory>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
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