-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #470 from JoyOfCodingPDX/1.1.1-SNAPSHOT
Version 1.1.1 of top-level POM and version 1.2.0 of grader that add the ability to capture a student's GitHub username (#452) and validate that all of the desired Gradle files are submitted with an Android project (#455).
- Loading branch information
Showing
50 changed files
with
526 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
grader/src/it/java/edu/pdx/cs/joy/grader/SubmitAndroidProjectIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package edu.pdx.cs.joy.grader; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
|
||
public class SubmitAndroidProjectIT extends SubmitIT { | ||
|
||
@BeforeEach | ||
@Override | ||
public void createFilesToSubmit() throws IOException { | ||
File mainDir = createDirectories("app", "src", "main", "java", "edu", "pdx", "cs", "joy", studentLoginId); | ||
for (String fileName : Arrays.asList("MainActivity.java", "FirstFragment.java", "SecondFragment.java")) { | ||
this.filesToSubmit.add(createEmptyFile(mainDir, fileName)); | ||
} | ||
|
||
File root = tempDirectory; | ||
for (String fileName : Arrays.asList("build.gradle", "gradle.properties", "gradlew", "settings.gradle")) { | ||
this.filesToSubmit.add(createEmptyFile(root, fileName)); | ||
} | ||
|
||
File appDir = createDirectories("app"); | ||
this.filesToSubmit.add(createEmptyFile(appDir, "build.gradle")); | ||
|
||
File gradleDir = createDirectories("gradle"); | ||
this.filesToSubmit.add(createEmptyFile(gradleDir, "libs.versions.toml")); | ||
|
||
File wrapperDir = createDirectories("gradle", "wrapper"); | ||
for (String fileName : Arrays.asList("gradle-wrapper.jar", "gradle-wrapper.properties")) { | ||
this.filesToSubmit.add(createEmptyFile(wrapperDir, fileName)); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
protected ProjectSubmitter submitter() { | ||
return new AndroidProjectSubmitter(); | ||
} | ||
|
||
private class AndroidProjectSubmitter extends ProjectSubmitter { | ||
@Override | ||
protected Submit getSubmitProgram() { | ||
return new SubmitAndroidProject(() -> submitTime); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
grader/src/main/java/edu/pdx/cs/joy/grader/GitConfigParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package edu.pdx.cs.joy.grader; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.Reader; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class GitConfigParser { | ||
static final Pattern PROPERTY_PATTERN = Pattern.compile("\\s+(.*) = (.*)"); | ||
static final Pattern REMOTE_PATTERN = Pattern.compile("\\[remote \"(.*)\"]"); | ||
private final Reader reader; | ||
private String currentSection; | ||
|
||
public GitConfigParser(Reader reader) { | ||
this.reader = reader; | ||
} | ||
|
||
public void parse(Callback callback) throws IOException { | ||
try (BufferedReader br = new BufferedReader(this.reader)) { | ||
for (String line = br.readLine(); line != null; line = br.readLine()) { | ||
parseLine(line, callback); | ||
} | ||
|
||
endCurrentSection(callback); | ||
} | ||
|
||
} | ||
|
||
private void endCurrentSection(Callback callback) { | ||
callback.endSection(currentSection); | ||
} | ||
|
||
private void parseLine(String line, Callback callback) { | ||
if (line.startsWith("[core]")) { | ||
endCurrentSection(callback); | ||
startCoreSection(callback); | ||
|
||
} else if (line.startsWith("[remote ")) { | ||
endCurrentSection(callback); | ||
startRemoteSection(line, callback); | ||
|
||
} else if (line.contains(" = ")) { | ||
parseProperty(line, callback); | ||
} | ||
|
||
} | ||
|
||
private void startCoreSection(Callback callback) { | ||
this.currentSection = "core"; | ||
callback.startCoreSection(); | ||
} | ||
|
||
private void startRemoteSection(String line, Callback callback) { | ||
Matcher matcher = REMOTE_PATTERN.matcher(line); | ||
if (!matcher.matches()) { | ||
throw new IllegalStateException("Cannot parse line with remote: \"" + line + "\""); | ||
} | ||
|
||
String remoteName = matcher.group(1); | ||
this.currentSection = remoteName; | ||
callback.startRemoteSection(remoteName); | ||
} | ||
|
||
private void parseProperty(String line, Callback callback) { | ||
Matcher matcher = PROPERTY_PATTERN.matcher(line); | ||
if (!matcher.matches()) { | ||
throw new IllegalStateException("Cannot parse line with property: \"" + line + "\""); | ||
} | ||
|
||
String propertyName = matcher.group(1); | ||
String propertyValue = matcher.group(2); | ||
|
||
callback.property(propertyName, propertyValue); | ||
} | ||
|
||
public interface Callback { | ||
void startCoreSection(); | ||
|
||
void property(String name, String value); | ||
|
||
void endSection(String name); | ||
|
||
void startRemoteSection(String name); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
grader/src/main/java/edu/pdx/cs/joy/grader/GitHubUserNameFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package edu.pdx.cs.joy.grader; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class GitHubUserNameFinder implements GitConfigParser.Callback { | ||
private String gitHubUserName; | ||
private boolean isInOrigin; | ||
|
||
@Override | ||
public void startCoreSection() { | ||
|
||
} | ||
|
||
@Override | ||
public void property(String name, String value) { | ||
if (name.equals("url") && this.isInOrigin) { | ||
extractGitHubUserNameFrom(value); | ||
} | ||
} | ||
|
||
private void extractGitHubUserNameFrom(String gitUrl) { | ||
Pattern pattern = Pattern.compile("git@github.com:(.*)/.*\\.git"); | ||
Matcher matcher = pattern.matcher(gitUrl); | ||
if (matcher.matches()) { | ||
this.gitHubUserName = matcher.group(1); | ||
} | ||
} | ||
|
||
@Override | ||
public void endSection(String name) { | ||
this.isInOrigin = false; | ||
} | ||
|
||
@Override | ||
public void startRemoteSection(String name) { | ||
if (name.equals("origin")) { | ||
this.isInOrigin = true; | ||
} | ||
} | ||
|
||
public String getGitHubUserName() { | ||
return gitHubUserName; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
grader/src/main/java/edu/pdx/cs/joy/grader/SubmitAndroidProject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.