Skip to content

Commit

Permalink
U 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fvarrui committed Nov 6, 2022
1 parent 2c02df3 commit db36273
Show file tree
Hide file tree
Showing 23 changed files with 448 additions and 231 deletions.
38 changes: 28 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>fvarrui.reviser</groupId>
<artifactId>Reviser</artifactId>
<version>0.4.3</version>
<version>0.5.0</version>

<name>Reviser</name>
<description>Asistente para la corrección de entregas realizadas en un aula virtual Moodle.</description>
Expand Down Expand Up @@ -32,31 +32,35 @@
</exclusion>
</exclusions>
</dependency>
<!-- javafx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12.0.2</version>
<version>17.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>12.0.2</version>
<version>17.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>12.0.2</version>
<version>17.0.1</version>
</dependency>
<!-- git library -->
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>6.1.0.202202221755-m3</version>
</dependency>
<!-- maven library -->
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>3.1.0</version>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand All @@ -67,11 +71,7 @@
<artifactId>slf4j-nop</artifactId>
<version>2.0.0-alpha6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.21</version>
</dependency>
<!-- common utils -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
Expand All @@ -82,21 +82,25 @@
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<!-- running system commands -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.4.1</version>
</dependency>
<!-- managing csv files -->
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.6</version>
</dependency>
<!-- javafx components -->
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.1.1</version>
</dependency>
<!-- javafx icons -->
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-javafx</artifactId>
Expand All @@ -108,6 +112,12 @@
<artifactId>ikonli-fontawesome5-pack</artifactId>
<version>12.3.0</version>
</dependency>
<!-- compressed files -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>com.github.junrar</groupId>
<artifactId>junrar</artifactId>
Expand All @@ -123,16 +133,24 @@
<artifactId>zip4j</artifactId>
<version>2.10.0</version>
</dependency>
<!-- check project comparison -->
<dependency>
<groupId>io.github.fvarrui</groupId>
<artifactId>VultureHunter</artifactId>
<version>0.3.0</version>
</dependency>
<!-- access microsoft windows credentials vault -->
<dependency>
<groupId>com.microsoft.alm</groupId>
<artifactId>auth-secure-storage</artifactId>
<version>0.6.4</version>
</dependency>
<!-- http client -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
</dependency>
</dependencies>

<repositories>
Expand Down Expand Up @@ -174,7 +192,7 @@
<plugin>
<groupId>io.github.fvarrui</groupId>
<artifactId>javapackager</artifactId>
<version>1.6.3</version>
<version>1.6.7</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/github/fvarrui/reviser/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import io.github.fvarrui.reviser.ui.Reviser;

public class Main {

public static void main(String[] args) throws Exception {
Reviser.main(args);
Reviser.main(args);
}

}
15 changes: 14 additions & 1 deletion src/main/java/io/github/fvarrui/reviser/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import javafx.geometry.Point2D;

public class Config {

private static final String DEFAULT_MAVEN_HOME = System.getenv("MAVEN_HOME");

public static final File configDir = new File(System.getProperty("user.home"), ".Reviser");
Expand All @@ -30,6 +30,7 @@ public class Config {
private BooleanProperty maximized = new SimpleBooleanProperty();
private StringProperty lastDirectory = new SimpleStringProperty(".");
private StringProperty mavenHome = new SimpleStringProperty(DEFAULT_MAVEN_HOME);
private StringProperty gitHubToken = new SimpleStringProperty();

private static Config config;

Expand Down Expand Up @@ -126,4 +127,16 @@ public final void setMavenHome(final String mavenHome) {
this.mavenHomeProperty().set(mavenHome);
}

public final StringProperty gitHubTokenProperty() {
return this.gitHubToken;
}

public final String getGitHubToken() {
return this.gitHubTokenProperty().get();
}

public final void setGitHubToken(final String gitHubToken) {
this.gitHubTokenProperty().set(gitHubToken);
}

}
4 changes: 2 additions & 2 deletions src/main/java/io/github/fvarrui/reviser/model/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ public void updateSubmissions(File submissionsDir) {
for (File d : submissionsDir.listFiles()) {
if (d.isDirectory()) {
final String name = d.getName().split("_")[0];
Optional<Submission> first = getSubmissions().stream().filter(r -> r.getName().equals(name)).findFirst();
Optional<Submission> first = getSubmissions().stream().filter(r -> r.getDirectory().equals(d.getName())).findFirst();
Submission submission = null;
if (first.isPresent()) {
submission = first.get();
submission.setDirectory(d.getName());
} else {
submission = new Submission(d);
submission.setName(name);
submission.setName(name.trim());
submission.setDirectory(d.getName());
getSubmissions().add(submission);
}
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/io/github/fvarrui/reviser/model/Submission.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,24 @@ public String getFullFeedback() {
return "<p>" + StringUtils.join(feedback, "</p><p>") + "</p>";
}

public File getFilesDir() {
return new File(getPath(), "files");
}

public void analyze() {
File submissionsDir = new File(getParent(), getDirectory());
tester.set(Tester.analyze(submissionsDir));
tester.set(Tester.analyze(getFilesDir()));
}

public void test(File ... input) throws Exception {
public void run(File ... input) throws Exception {
if (getTester() == null) {
analyze();
}
File submissionsDir = new File(getParent(), getDirectory());
getTester().runTest(submissionsDir);
getTester().runTest(getFilesDir());
}

public void process() throws Exception {
Processor.process(getPath());
analyze();
}

}
75 changes: 53 additions & 22 deletions src/main/java/io/github/fvarrui/reviser/processors/Processor.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,61 @@
package io.github.fvarrui.reviser.processors;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;

import org.eclipse.jgit.api.errors.InvalidRemoteException;

import io.github.fvarrui.reviser.config.Config;
import io.github.fvarrui.reviser.utils.CompressionUtils;
import io.github.fvarrui.reviser.utils.FileUtils;
import io.github.fvarrui.reviser.utils.GitUtils;
import io.github.fvarrui.reviser.utils.URLUtils;

public class Processor {

public static void process(File submissionDir) throws Exception {
public static File process(File submissionDir) throws Exception {
System.out.println("Procesando todos los ficheros de la entrega: " + submissionDir.getName());
try {
File destinationDir = new File(submissionDir, "files");
FileUtils.createFolder(destinationDir);
for (File submittedFile : Arrays.asList(submissionDir.listFiles())) {
processFile(submittedFile);
processFile(submittedFile, destinationDir);
}
System.out.println("¡Completado!");
System.out.println("¡Completado!");
return destinationDir;
} catch (InvalidRemoteException e) {
if (e.getMessage().equals("Invalid remote: origin")) throw new Exception("La URL del repositorio no es correcta");
throw e;
}
}

private static void processFile(File submittedFile) throws Exception {
private static void processFile(File submittedFile, File destinationDir) throws Exception {

System.out.println("Procesando entrega: " + submittedFile.getName() + " ... ");
System.out.println("Procesando fichero: " + submittedFile.getName() + " ... ");

// el envío es un fichero comprimido
if (CompressionUtils.isCompressedFile(submittedFile)) {

System.out.println("El fichero está comprimido");
uncompress(submittedFile);
uncompress(submittedFile, destinationDir);

}
// el envío es texto en línea
else if (submittedFile.getName().equals("onlinetext.html")) {

System.out.println("El envío es texto en línea: " + submittedFile.getName());
processOnlineText(submittedFile);
processOnlineText(submittedFile, destinationDir);

}

System.out.println("Procesamiento completado");

}

private static void processOnlineText(File onlineTextFile) throws Exception {
private static void processOnlineText(File onlineTextFile, File destinationDir) throws Exception {

// si la entrega es una URL, realiza un procesamiento extra

Expand All @@ -59,15 +65,7 @@ private static void processOnlineText(File onlineTextFile) throws Exception {
if (url != null) {

System.out.println("URL encontrada: " + url);
File outputDir = onlineTextFile.getParentFile();
processUrl(outputDir, url);
onlineTextFile.delete();

} else {

System.out.println("No se ha encontrado ninguna URL");
System.out.println("Renombrando entrega por onlinetext.processed.html ...");
FileUtils.rename(onlineTextFile, "onlinetext.processed.html");
processUrl(destinationDir, url);

}

Expand All @@ -82,9 +80,12 @@ private static void processUrl(File destinationDir, String url) throws Exception
System.out.println("Clonando repositorio GIT desde " + url + " en " + destinationDir + "...");
GitUtils.clone(url, destinationDir);

} else if (url.matches("https://raw.githubusercontent.com/.*")) {

downloadPrivateResource(url, destinationDir, Config.getConfig().getGitHubToken());

} else {

System.out.println("La entrega es un recurso en la nube");
downloadResource(url, destinationDir);

}
Expand All @@ -98,19 +99,49 @@ private static void downloadResource(String url, File destinationDir) throws Exc

System.out.println("Descargando recurso desde " + url + " en " + destinationFile + "...");

org.apache.commons.io.FileUtils.copyURLToFile(URLUtils.toURL(url), destinationFile);
try {

URLUtils.download(url, destinationFile);

} catch (FileNotFoundException e) {

throw new Exception("Recurso NO encontrado (404): " + url, e);

}

}

@SuppressWarnings("serial")
private static void downloadPrivateResource(String url, File destinationDir, String token) throws Exception {

String filename = URLUtils.getFile(url);
File destinationFile = new File(destinationDir, filename);

System.out.println("Descargando recurso privado desde " + url + " en " + destinationFile + "...");

try {

URLUtils.download(url, destinationFile, new HashMap<>() {{
put("Authorization", "token " + token);
}});

} catch (FileNotFoundException e) {

throw new Exception("Recurso NO encontrado (404): " + url, e);

}

}

private static void uncompress(File submittedFile) throws IOException {
private static void uncompress(File submittedFile, File destinationDir) throws IOException {

System.out.println("Descomprimiendo " + submittedFile.getName() + " ...");

// descomprime el fichero
CompressionUtils.decompress(submittedFile, false);
CompressionUtils.decompress(submittedFile, destinationDir);

// elimina el original y se queda con el extraído
submittedFile.delete();
// submittedFile.delete();

System.out.println("Fichero extraído: " + submittedFile.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public boolean matches(File submissionDir) {
public void test(File submissionDir) throws Exception {
Reviser.console.println("Abriendo PowerShell en " + submissionDir);
new ProcessBuilder()
.command("powershell")
.command("cmd", "/c", "start /max powershell")
.directory(submissionDir)
.start();
Reviser.console.println("¡Completado!");
Expand Down
Loading

0 comments on commit db36273

Please sign in to comment.