Skip to content

Commit

Permalink
Setup Project
Browse files Browse the repository at this point in the history
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
DK96-OS authored Nov 4, 2023
2 parents ae2b9b8 + c0b3485 commit b61ee90
Show file tree
Hide file tree
Showing 21 changed files with 361 additions and 5 deletions.
6 changes: 6 additions & 0 deletions artifacts.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def commonArtifactVersion = "0.1"
ext {
artifactVersions = [
visitors: commonArtifactVersion,
]
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
google()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20")
}
}

Expand All @@ -15,7 +15,7 @@ allprojects {
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "11"
jvmTarget = "17"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pluginManagement {
plugins {
id "org.jetbrains.kotlin.jvm" version "1.9.10"
id "org.jetbrains.kotlin.jvm" version "1.9.20"
}
repositories {
google()
Expand All @@ -11,7 +11,7 @@ pluginManagement {
gradlePluginPortal()
}
}
rootProject.name = "java-project"
rootProject.name = "files-jvm"
include(
//":module",
":visitors",
)
57 changes: 57 additions & 0 deletions visitors/build.gradle
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
}
}
}
}
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 {
}
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;
}

}
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;
}

}
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.
10 changes: 10 additions & 0 deletions visitors/test_directory/build.gradle
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
}
3 changes: 3 additions & 0 deletions visitors/test_directory/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ext {

}
Empty file.
18 changes: 18 additions & 0 deletions visitors/test_directory/module1/src/main/java/package1/File1.java
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;
}

}
Loading

0 comments on commit b61ee90

Please sign in to comment.