-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CTO: * Create README.md * Create commit_organizer.py * Create launch.py Files: * Create file_management.py * Create file_names.py Tests: * Create Sample Input and Output files * Create Tests Validating specific Input and Output * Create Tests for Data Structures Text: * Create commit_line.py * Create commit_line_prefixes.py * Create commit_text_group.py Workflow: * Create ci_run.yml * Create requirements.txt - empty file
- Loading branch information
Showing
21 changed files
with
361 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
def commonArtifactVersion = "0.1" | ||
ext { | ||
artifactVersions = [ | ||
visitors: commonArtifactVersion, | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
plugins { | ||
id 'java-library' | ||
id 'jacoco' | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
withJavadocJar() | ||
withSourcesJar() | ||
} | ||
|
||
dependencies { | ||
testImplementation 'junit:junit:4.13.2' | ||
} | ||
|
||
publishing { | ||
publications { | ||
maven(MavenPublication) { | ||
groupId = "io.github.dk96-os.files-jvm" | ||
artifactId = "visitors" | ||
apply from: "../artifacts.gradle" | ||
version = artifactVersions.visitors | ||
from components.java | ||
} | ||
} | ||
} | ||
|
||
tasks.test { | ||
maxParallelForks = 3 | ||
} | ||
|
||
tasks.jacocoTestReport { | ||
dependsOn tasks.test | ||
reports { | ||
xml.required = false | ||
csv.required = false | ||
html.outputLocation = layout.buildDirectory.dir("jacocoReport") | ||
} | ||
} | ||
|
||
tasks.jacocoTestCoverageVerification { | ||
dependsOn tasks.test | ||
violationRules { | ||
failOnViolation = true | ||
rule { | ||
limit { | ||
counter = "INSTRUCTION" | ||
minimum = 0.960 | ||
} | ||
limit { | ||
counter = "BRANCH" | ||
minimum = 0.850 | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
visitors/src/main/java/files/jvm/visitors/ExcludeFromJacocoGeneratedReport.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,11 @@ | ||
package files.jvm.visitors; | ||
|
||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
/** Annotation that removes a method from Code Coverage Report. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ExcludeFromJacocoGeneratedReport { | ||
} |
46 changes: 46 additions & 0 deletions
46
visitors/src/main/java/files/jvm/visitors/SimplifiedFileVisitor.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,46 @@ | ||
package files.jvm.visitors; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileVisitResult; | ||
import java.nio.file.FileVisitor; | ||
import java.nio.file.Path; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
|
||
/** Overrides the FileVisitor and provides default implementations for methods not commonly needed. | ||
*/ | ||
public abstract class SimplifiedFileVisitor | ||
implements FileVisitor<Path> { | ||
|
||
@ExcludeFromJacocoGeneratedReport | ||
@Override | ||
public FileVisitResult preVisitDirectory( | ||
Path path, | ||
BasicFileAttributes basicFileAttributes | ||
) { | ||
return path != null ? FileVisitResult.CONTINUE | ||
: FileVisitResult.SKIP_SUBTREE; | ||
} | ||
|
||
@ExcludeFromJacocoGeneratedReport | ||
@Override | ||
public FileVisitResult visitFileFailed( | ||
Path path, | ||
IOException exception | ||
) throws IOException { | ||
if (exception != null) | ||
throw exception; | ||
return FileVisitResult.TERMINATE; | ||
} | ||
|
||
@ExcludeFromJacocoGeneratedReport | ||
@Override | ||
public FileVisitResult postVisitDirectory( | ||
Path path, | ||
IOException exception | ||
) throws IOException { | ||
if (exception != null) | ||
throw exception; | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
} |
93 changes: 93 additions & 0 deletions
93
visitors/src/main/java/files/jvm/visitors/SingleLevelFileVisitor.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,93 @@ | ||
package files.jvm.visitors; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileVisitResult; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** Visits Files and Directories in a single level, | ||
* records the files and directories that were found in a list. | ||
*/ | ||
public class SingleLevelFileVisitor { | ||
|
||
/** Whether the Path given in the constructor is a valid directory. | ||
*/ | ||
public final boolean isValidDirectory; | ||
|
||
private final List<String> mDirectories; | ||
|
||
private final List<String> mFiles; | ||
|
||
/** Constructor. | ||
* @param path The path to visit. | ||
* @throws IOException Any Exception thrown while Visiting the Path. | ||
*/ | ||
public SingleLevelFileVisitor( | ||
final Path path | ||
) throws IOException { | ||
if (!Files.isDirectory(path)) { | ||
isValidDirectory = false; | ||
mDirectories = null; | ||
mFiles = null; | ||
return; | ||
} | ||
isValidDirectory = true; | ||
// Create Mutable Collections to store verified files and directories. | ||
final var directories = new ArrayList<String>(); | ||
final var files = new ArrayList<String>(); | ||
// Create A Temporary Visitor | ||
final var visitor = new SimplifiedFileVisitor() { | ||
@Override | ||
public FileVisitResult visitFile( | ||
Path path, BasicFileAttributes basicFileAttributes | ||
) { | ||
if (path == null) { | ||
return FileVisitResult.TERMINATE; | ||
} | ||
final String name = path.getFileName().toString(); | ||
if (Files.isDirectory(path)) { | ||
directories.add(name); | ||
} else { | ||
files.add(name); | ||
} | ||
return FileVisitResult.CONTINUE; | ||
} | ||
}; | ||
// Search the Path using the temporary file visitor | ||
Files.walkFileTree( | ||
path, | ||
Set.of(), | ||
1, | ||
visitor | ||
); | ||
// Check for empty Collections of data | ||
mDirectories = directories.isEmpty() ? null | ||
: directories; | ||
mFiles = files.isEmpty() ? null | ||
: files; | ||
} | ||
|
||
/** Obtain the directory names found at this Path. | ||
* @return The List of directories, or an empty List. | ||
*/ | ||
public List<String> getDirectories() { | ||
if (mDirectories == null) | ||
return Collections.emptyList(); | ||
return mDirectories; | ||
} | ||
|
||
/** Obtain the File names found at this Path. | ||
* @return The List of File Names, or an empty List. | ||
*/ | ||
public List<String> getFiles() { | ||
if (mFiles == null) | ||
return Collections.emptyList(); | ||
return mFiles; | ||
} | ||
|
||
} |
92 changes: 92 additions & 0 deletions
92
visitors/src/test/java/files/jvm/visitors/SingleLevelFileVisitorTest.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,92 @@ | ||
package files.jvm.visitors; | ||
|
||
import static junit.framework.TestCase.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
/** Testing SingleLevelFileVisitor class. | ||
*/ | ||
public final class SingleLevelFileVisitorTest { | ||
|
||
private final Path testProjectDirectory = Path.of("test_directory"); | ||
|
||
private SingleLevelFileVisitor mInstance; | ||
|
||
@Before | ||
public void testSetup() throws IOException { | ||
mInstance = new SingleLevelFileVisitor(testProjectDirectory); | ||
} | ||
|
||
@Test | ||
public void testInitialCondition() { | ||
assertTrue( | ||
mInstance.isValidDirectory | ||
); | ||
assertEquals( | ||
4, | ||
mInstance.getDirectories().size() | ||
); | ||
assertEquals( | ||
5, | ||
mInstance.getFiles().size() | ||
); | ||
} | ||
|
||
@Test | ||
public void testConstructor_FilePath_NotValidDirectory() throws IOException { | ||
final Path filePath = Path.of("test_project/build.gradle"); | ||
mInstance = new SingleLevelFileVisitor(filePath); | ||
assertFalse( | ||
mInstance.isValidDirectory | ||
); | ||
assertEquals( | ||
0, | ||
mInstance.getDirectories().size() | ||
); | ||
assertEquals( | ||
0, | ||
mInstance.getFiles().size() | ||
); | ||
} | ||
|
||
@Test | ||
public void testConstructor_InvalidPath_Fails() throws IOException { | ||
final Path invalidPath = Path.of("invalid_path"); | ||
mInstance = new SingleLevelFileVisitor(invalidPath); | ||
assertFalse( | ||
mInstance.isValidDirectory | ||
); | ||
assertEquals( | ||
0, | ||
mInstance.getDirectories().size() | ||
); | ||
assertEquals( | ||
0, | ||
mInstance.getFiles().size() | ||
); | ||
} | ||
|
||
@Test | ||
public void testConstructor_EmptyDirectory() throws IOException { | ||
final Path path = testProjectDirectory.resolve("samples"); | ||
mInstance = new SingleLevelFileVisitor(path); | ||
assertTrue( | ||
mInstance.isValidDirectory | ||
); | ||
assertEquals( | ||
0, | ||
mInstance.getDirectories().size() | ||
); | ||
assertEquals( | ||
1, | ||
mInstance.getFiles().size() | ||
); | ||
} | ||
|
||
} |
Empty file.
Empty file.
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,10 @@ | ||
plugins { | ||
id 'java-library' | ||
id 'jacoco' | ||
id 'kotlin' | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} |
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,3 @@ | ||
ext { | ||
|
||
} |
Empty file.
18 changes: 18 additions & 0 deletions
18
visitors/test_directory/module1/src/main/java/package1/File1.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,18 @@ | ||
package package1; | ||
|
||
/** The First File in this Test-Project. | ||
*/ | ||
public final class File1 { | ||
|
||
public void updateInstance() { | ||
System.out.println("updateInstance"); | ||
} | ||
|
||
/** Returns the number 12. | ||
* @return The number 12. | ||
*/ | ||
public int getNumber() { | ||
return 12; | ||
} | ||
|
||
} |
Oops, something went wrong.