Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group 13 Validation #64

Closed
wants to merge 13 commits into from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ gradle-app.setting
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

gradle.properties
# Cache of project
.gradletasknamecache

Expand Down
27 changes: 18 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ plugins {
repositories {
mavenLocal()
mavenCentral()
// TODO: uncomment to be able to fetch packages in your own repository
// maven {
// name = "GitHubPackages"
// url = uri("https://maven.pkg.github.com/<your-username>/printscript")
// credentials {
// username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
// password = project.findProperty("gpr.key") ?: System.getenv("TOKEN")
// }
// }
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/Pedrodeforonda/printScript-ingsis")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("TOKEN")
}
}
}

java {
Expand All @@ -29,9 +28,19 @@ test {

dependencies {
testImplementation 'junit:junit:4.13.1'
implementation("com.github.printSrcript:token:1.1.61")
implementation("com.github.printSrcript:ast:1.1.61")
implementation("com.github.printSrcript:lexer:1.1.61")
implementation("com.github.printSrcript:parser:1.1.61")
implementation("com.github.printSrcript:interpreter:1.1.61")
implementation("com.github.printSrcript:formatter:1.1.61")
implementation("com.github.printSrcript:linter:1.1.61")
implementation("com.github.printSrcript:runner:1.1.61")
implementation("com.github.printSrcript:factory:1.1.61")
}

test {
environment "BEST_FOOTBALL_CLUB", "San Lorenzo"
useJUnit()
}

20 changes: 20 additions & 0 deletions src/main/java/adapters/AdapterInputProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package adapters;

import interpreter.InputProvider;
import org.jetbrains.annotations.NotNull;
import utils.StringInputProvider;

public class AdapterInputProvider implements StringInputProvider {

private final InputProvider inputProvider;

public AdapterInputProvider(InputProvider inputProvider) {
this.inputProvider = inputProvider;
}

@NotNull
@Override
public String input(@NotNull String name) {
return inputProvider.input(name);
}
}
31 changes: 31 additions & 0 deletions src/main/java/adapters/CustomFormatter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package adapters;

import factories.FormatterFactory;
import interpreter.PrintScriptFormatter;
import java.io.*;


public class CustomFormatter implements PrintScriptFormatter {

@Override
public void format(InputStream src, String version, InputStream config, Writer writer) {
FormatterFactory factory = new FormatterFactory();
return;
}
}

//class TCKConfigReader {
// private final Path path;
//
// public TCKConfigReader(Path path) {
// this.path = path;
// }
//
// public FormatterConfig readConfig() {
// try {
// return new FormatterConfig(Files.readAllLines(path));
// } catch (IOException e) {
// throw new RuntimeException("Error reading config file", e);
// }
// }
//}
42 changes: 42 additions & 0 deletions src/main/java/adapters/CustomInterpreter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package adapters;

import interpreter.ErrorHandler;
import interpreter.InputProvider;
import interpreter.PrintEmitter;
import interpreter.PrintScriptInterpreter;
import main.Runner;
import utils.InterpreterResult;

import java.io.*;
import java.util.Iterator;
import java.util.Map;


public class CustomInterpreter implements PrintScriptInterpreter {


@Override
public void execute(InputStream src, String version, PrintEmitter emitter, ErrorHandler handler, InputProvider provider) {
try {
AdapterInputProvider inputProvider = new AdapterInputProvider(provider);
Map<String,String> envMap = System.getenv();
Runner runner = new Runner();
Iterator<InterpreterResult> interpreterResults = runner.run(src, version, inputProvider, envMap, false).iterator();
while (interpreterResults.hasNext()) {
InterpreterResult result = interpreterResults.next();
if (result.hasException()) {
handler.reportError(result.getException().getMessage());
}
if (result.hasPrintln()) {
emitter.print(result.getPrintln());
}
}
} catch ( OutOfMemoryError | Exception e) {
emitter = null;
provider = null;
src = null;
version = null;
handler.reportError(e.getMessage());
}
}
}
26 changes: 26 additions & 0 deletions src/main/java/adapters/CustomLinter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package adapters;

import factories.LinterFactory;
import interpreter.ErrorHandler;
import interpreter.PrintScriptLinter;
import main.kotlin.main.Linter;
import utils.LinterResult;


import java.io.InputStream;
import java.util.Iterator;


public class CustomLinter implements PrintScriptLinter {
@Override
public void lint(InputStream src, String version, InputStream config, ErrorHandler handler) {
Iterator<LinterResult> results = new LinterFactory().lintCode(src, version, config);

for (Iterator<LinterResult> it = results; it.hasNext(); ) {
LinterResult result = it.next();
if (result.hasError()) {
handler.reportError(result.getMessage());
}
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/adapters/InputProviderAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package adapters;

public class InputProviderAdapter {
}
22 changes: 6 additions & 16 deletions src/main/java/implementation/CustomImplementationFactory.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
package implementation;

import adapters.CustomFormatter;
import adapters.CustomInterpreter;
import adapters.CustomLinter;
import interpreter.PrintScriptFormatter;
import interpreter.PrintScriptInterpreter;
import interpreter.PrintScriptLinter;

import java.io.BufferedInputStream;
import java.util.Arrays;

public class CustomImplementationFactory implements PrintScriptFactory {

@Override
public PrintScriptInterpreter interpreter() {
// your PrintScript implementation should be returned here.
// make sure to ADAPT your implementation to PrintScriptInterpreter interface.
throw new NotImplementedException("Needs implementation"); // TODO: implement

// Dummy impl: return (src, version, emitter, handler) -> { };
return new CustomInterpreter();
}

@Override
public PrintScriptFormatter formatter() {
// your PrintScript formatter should be returned here.
// make sure to ADAPT your formatter to PrintScriptFormatter interface.
throw new NotImplementedException("Needs implementation"); // TODO: implement

// Dummy impl: return (src, version, config, writer) -> { };
return new CustomFormatter();
}

@Override
public PrintScriptLinter linter() {
// your PrintScript linter should be returned here.
// make sure to ADAPT your linter to PrintScriptLinter interface.
throw new NotImplementedException("Needs implementation"); // TODO: implement
return new CustomLinter();
}
}
2 changes: 1 addition & 1 deletion src/test/java/interpreter/InterpreterLargeFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class InterpreterLargeFileTest {

private static final String MESSAGE = "This is a text";
private static final String LINE = "println(\"" + MESSAGE + "\");\n";
private static final int NUMBER_OF_LINES = 32 * 1024;
private static final int NUMBER_OF_LINES = 49 * 1024;
private final PrintScriptInterpreter interpreter = new CustomImplementationFactory().interpreter();

@Test
Expand Down
3 changes: 0 additions & 3 deletions src/test/java/linter/LinterTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package linter;

import implementation.CustomImplementationFactory;
import interpreter.PrintScriptFormatter;
import interpreter.PrintScriptLinter;
import org.hamcrest.Matcher;
import org.junit.Test;
Expand All @@ -11,7 +10,6 @@

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand All @@ -20,7 +18,6 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static util.SuiteOps.*;

@RunWith(Parameterized.class)
Expand Down
Loading