diff --git a/.gitignore b/.gitignore index 2608ec2..586658d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store -.vscode \ No newline at end of file +.vscode +.fake \ No newline at end of file diff --git a/task_1_4_1/.gitattributes b/task_1_4_1/.gitattributes new file mode 100644 index 0000000..097f9f9 --- /dev/null +++ b/task_1_4_1/.gitattributes @@ -0,0 +1,9 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# Linux start script should use lf +/gradlew text eol=lf + +# These are Windows script files and should use crlf +*.bat text eol=crlf + diff --git a/task_1_4_1/.gitignore b/task_1_4_1/.gitignore new file mode 100644 index 0000000..01d6c0f --- /dev/null +++ b/task_1_4_1/.gitignore @@ -0,0 +1,7 @@ +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build + +bin \ No newline at end of file diff --git a/task_1_4_1/app/build.gradle b/task_1_4_1/app/build.gradle new file mode 100644 index 0000000..ab36713 --- /dev/null +++ b/task_1_4_1/app/build.gradle @@ -0,0 +1,50 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This generated file contains a sample Java application project to get you started. + * For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.4/userguide/building_java_projects.html in the Gradle documentation. + */ + +plugins { + // Apply the application plugin to add support for building a CLI application in Java. + id 'application' + id 'jacoco' +} + +repositories { + // Use Maven Central for resolving dependencies. + mavenCentral() +} + +dependencies { + // Use JUnit Jupiter for testing. + testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3' + + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + + // This dependency is used by the application. + implementation 'com.google.guava:guava:32.1.1-jre' +} + +// Apply a specific Java toolchain to ease working on different environments. +java { + toolchain { + languageVersion = JavaLanguageVersion.of(20) + } +} + +application { + // Define the main class for the application. + mainClass = 'task.StudentBook' +} + +tasks.named('test') { + // Use JUnit Platform for unit tests. + useJUnitPlatform() +} + +jacocoTestReport { + reports { + xml.required = true + } +} \ No newline at end of file diff --git a/task_1_4_1/app/src/main/java/task/ExcludeFromJacocoGeneratedReport.java b/task_1_4_1/app/src/main/java/task/ExcludeFromJacocoGeneratedReport.java new file mode 100644 index 0000000..48f2689 --- /dev/null +++ b/task_1_4_1/app/src/main/java/task/ExcludeFromJacocoGeneratedReport.java @@ -0,0 +1,14 @@ +package task; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Excluding From Jacoco Test Report interface. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface ExcludeFromJacocoGeneratedReport { +} diff --git a/task_1_4_1/app/src/main/java/task/Grade.java b/task_1_4_1/app/src/main/java/task/Grade.java new file mode 100644 index 0000000..52f6ad6 --- /dev/null +++ b/task_1_4_1/app/src/main/java/task/Grade.java @@ -0,0 +1,143 @@ +package task; + +/** + * Class represents subject grade in gradebook. + */ +public class Grade { + + /** + * Name of subject. + */ + private String subject; + + /** + * Grade for this subject. + */ + private int mark; + + /** + * Boolean variable. True if mark is differentiated, false otherwise. + */ + private boolean differentiated; + + /** + * Constructor of Grade class. + * + * @param subject name of the subject. + * @param mark grade for this subject. + * @param differentiated boolean variable. True if mark is differentiated, false otherwise. + * @throws GradeException special exception for GradeBook class. Contains information message. + */ + public Grade(String subject, int mark, boolean differentiated) throws GradeException { + this.subject = subject; + this.differentiated = differentiated; + this.setMark(mark); + } + + /** + * Getter for mark. + * + * @return mark for subject. + */ + public int getMark() { + return mark; + } + + /** + * Setter for mark. + * + * @param mark mark. + * @throws GradeException special exception for GradeBook class. Contains information message. + */ + public void setMark(int mark) throws GradeException { + if (mark < 2 || mark > 5) { + throw new GradeException("Mark must be between 2 and 5.\n"); + } + if (differentiated) { + this.mark = mark; + } else { + this.mark = mark > 2 ? 5 : 2; + } + } + + /** + * Getter for subject. + * + * @return name of the subject. + */ + public String getSubject() { + return subject; + } + + /** + * Setter for subject. + * + * @param subject name of the subject. + */ + public void setSubject(String subject) { + this.subject = subject; + } + + /** + * Getter for differentiated. + * + * @return true if mark is differentiated, false otherwise. + */ + public boolean isDifferentiated() { + return differentiated; + } + + /** + * Setter for differentiated. + * + * @param differentiated boolean variable. True if mark is differentiated, false otherwise. + */ + public void setDifferentiated(boolean differentiated) { + this.differentiated = differentiated; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((subject == null) ? 0 : subject.hashCode()); + result = prime * result + mark; + result = prime * result + (differentiated ? 1231 : 1237); + return result; + } + + /** + * {@inheritDoc} + */ + @ExcludeFromJacocoGeneratedReport + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Grade other = (Grade) obj; + if (subject == null) { + if (other.subject != null) { + return false; + } + } else if (!subject.equals(other.subject)) { + return false; + } + if (mark != other.mark) { + return false; + } + if (differentiated != other.differentiated) { + return false; + } + return true; + } +} diff --git a/task_1_4_1/app/src/main/java/task/GradeBook.java b/task_1_4_1/app/src/main/java/task/GradeBook.java new file mode 100644 index 0000000..b527b1f --- /dev/null +++ b/task_1_4_1/app/src/main/java/task/GradeBook.java @@ -0,0 +1,226 @@ +package task; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** + * Represents an electronic student grade book with methods for managing and analyzing grades. + */ +public class GradeBook { + /** + * Array of marks pages. + */ + private MarksPage[] pages; + + /** + * Count of pages (semesters) in gradebook. + */ + private int pageCount; + + /** + * Student name in format: last name, first name, patronymic. + */ + private String studentName; + + /** + * Class constructor. + * + * @param studentName name in the format: first name, last name, patronymic. + * @param pageCount count of pages in Grade Book. + * @throws GradeException special exception for GradeBook class. Contains information message. + */ + public GradeBook(String studentName, int pageCount) throws GradeException { + pages = new MarksPage[pageCount]; + for (int i = 0; i < pageCount; i++) { + pages[i] = new MarksPage(); + } + this.pageCount = pageCount; + this.setStudentName(studentName); + } + + /** + * Getter for student name. + * + * @return full student name. + */ + public String getStudentName() { + return studentName; + } + + /** + * Setter for student name. + * + * @param studentName a name that will be checked to match the format. + * @throws GradeException special exception for GradeBook class. Contains information message. + */ + public void setStudentName(String studentName) throws GradeException { + String[] nameParts = studentName.split(" "); + if (nameParts.length != 3) { + throw new GradeException("\"" + studentName + "\"" + + " is not supported in this record book.\n" + + "Please, Make sure your name is in the format:\n" + + "last name, first name, patronymic (\"-\" if absent).\n"); + } + if (studentName.matches(".*\\d.*")) { + throw new GradeException("\"" + studentName + "\"" + " contains numbers. Fix this.\n"); + } + this.studentName = studentName; + } + + /** + * Adds a new grade entry to the GradeBook for a specific semester. + * + * @param currentSemester number of page (semester) in GradeBook. + * @param subject name of the subject. + * @param mark grade for this subject. + * @param differentiated boolean variable. True if mark is differentiated, false otherwise. + * @throws GradeException special exception for GradeBook class. Contains information message. + */ + public void writeInGradeBook(int currentSemester, + String subject, + int mark, + boolean differentiated) throws GradeException { + if (currentSemester < 1 || currentSemester > pageCount) { + throw new GradeException("Semester must be between 1 and " + pageCount); + } + pages[currentSemester - 1].addNote(subject, mark, differentiated); + } + + /** + * Removes a note from the gradebook for a specific semester. + * + * @param currentSemester number of page (semester) in GradeBook. + * @param subject name of the subject to remove. + */ + public void removeFromGradeBook(int currentSemester, String subject) { + var currSemGrades = pages[currentSemester - 1].getNotes(); + for (var i : currSemGrades) { + if (i.getSubject() == subject) { + currSemGrades.remove(i); + return; + } + } + } + + /** + * Checks if the student is eligible for an increased scholarship in a specific semester. + * + * @param semester number of page (semester) in GradeBook. + * @return true if eligible, false otherwise. + */ + public boolean scholarship(int semester) { + return pages[semester - 1].getNotes().stream().allMatch(x -> x.getMark() == 5); + } + + /** + * Checks if the student is eligible for a red diploma based on their entire academic history. + * + * @return true if eligible, false otherwise. + */ + public boolean redDiploma() { + Set visited = new HashSet<>(); + int[] goodMarks = {0}; + int[] countMarks = {0}; + boolean[] diplomWritten = {false}; + + Arrays.stream(pages) + .flatMap(curr -> curr.getNotes().stream()) + .filter(i -> !visited.contains(i.getSubject())) + .peek(i -> visited.add(i.getSubject())) + .allMatch(j -> { + if (j.getMark() <= 3) { + return false; + } + if ("Diploma".equals(j.getSubject())) { + diplomWritten[0] = true; + return j.getMark() == 5; + } + if (j.getMark() == 5) { + goodMarks[0]++; + } + countMarks[0]++; + return true; + }); + + return diplomWritten[0] && ((float) goodMarks[0] / countMarks[0] >= 0.75); + } + + /** + * Calculates the average grade for all semesters. + * + * @return float number of average grade. + */ + public float averageMark() { + float[] total = {0f}; + long countMarks = Arrays.stream(pages) + .flatMap(curr -> curr.getNotes().stream()) + .peek(j -> { + total[0] += (float) j.getMark(); + }).count(); + return total[0] / (float) countMarks; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + for (var i : pages) { + result += i.hashCode(); + } + result = prime * result + pageCount; + result = prime * result + ((studentName == null) ? 0 : studentName.hashCode()); + return result; + } + + /** + * {@inheritDoc} + */ + @Override + @ExcludeFromJacocoGeneratedReport + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + GradeBook other = (GradeBook) obj; + if (pageCount != other.pageCount) { + return false; + } + if (studentName == null) { + if (other.studentName != null) { + return false; + } + } else if (!studentName.equals(other.studentName)) { + return false; + } + Set thisSet = new HashSet<>(Arrays.asList(pages)); + Set otherSet = new HashSet<>(Arrays.asList(other.pages)); + return thisSet.equals(otherSet); + } + + /** + * {@inheritDoc} + */ + @Override + @ExcludeFromJacocoGeneratedReport + public String toString() { + StringBuilder res = new StringBuilder(); + for (int i = 0; i < pageCount; i++) { + var currPage = pages[i]; + res.append("Semester number " + (i + 1) + "\n"); + for (var j : currPage.getNotes()) { + res.append(" " + j.getSubject() + " " + j.getMark() + "\n"); + } + } + return res.toString(); + } +} diff --git a/task_1_4_1/app/src/main/java/task/GradeException.java b/task_1_4_1/app/src/main/java/task/GradeException.java new file mode 100644 index 0000000..72b7dc2 --- /dev/null +++ b/task_1_4_1/app/src/main/java/task/GradeException.java @@ -0,0 +1,15 @@ +package task; + +/** + * Custom exception class for handling exceptions in the GradeBook system. + */ +public class GradeException extends Exception { + /** + * Constructs a GradeException with the specified error message. + * + * @param message The detail message. + */ + public GradeException(String message) { + super(message); + } +} diff --git a/task_1_4_1/app/src/main/java/task/Main.java b/task_1_4_1/app/src/main/java/task/Main.java new file mode 100644 index 0000000..6d1520f --- /dev/null +++ b/task_1_4_1/app/src/main/java/task/Main.java @@ -0,0 +1,29 @@ +package task; + +/** + * Main class to demonstrate the functionality of the GradeBook system. + */ +public class Main { + /** + * Main method to run the GradeBook demonstration. + * + * @param args Command line arguments (not used in this context). + */ + @ExcludeFromJacocoGeneratedReport + public static void main(String[] args) { + try { + GradeBook newBook = new GradeBook("Petrov Petr Petrovich", 1); + newBook.writeInGradeBook(1, "Math", 5, true); + newBook.writeInGradeBook(1, "Rus", 4, true); + newBook.writeInGradeBook(1, "Diploma", 5, true); + System.out.println(newBook.toString()); + System.out.println("Average Mark: " + newBook.averageMark()); + System.out.println("Red Diploma Eligibility: " + newBook.redDiploma()); + System.out.println("Scholarship Eligibility for Semester 1: " + newBook.scholarship(1)); + + } catch (Exception e) { + var message = e.getMessage(); + System.out.println(message); + } + } +} diff --git a/task_1_4_1/app/src/main/java/task/MarksPage.java b/task_1_4_1/app/src/main/java/task/MarksPage.java new file mode 100644 index 0000000..4a94aee --- /dev/null +++ b/task_1_4_1/app/src/main/java/task/MarksPage.java @@ -0,0 +1,93 @@ +package task; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; + +/** + * Represents a page in the gradebook containing subject grades. + * Provides methods to add and retrieve grades. + */ +public class MarksPage { + /** + * A list of subject grades. + */ + private ArrayList notes; + + /** + * Constructs a MarksPage object with an empty list of grades. + */ + public MarksPage() { + notes = new ArrayList<>(); + } + + /** + * Adds a new grade entry to the gradebook. + * + * @param subject The name of the subject. + * @param mark The grade for this subject. + * @param differentiated True if the grading is differentiated, false otherwise. + * @throws GradeException Special exception for the GradeBook class containing a message. + */ + public void addNote(String subject, int mark, boolean differentiated) throws GradeException { + Grade newNote = new Grade(subject, mark, differentiated); + notes.add(newNote); + } + + /** + * Retrieves the list of grades on this page. + * + * @return The list of grades. + */ + public ArrayList getNotes() { + return notes; + } + + /** + * Sets the list of grades for this page. + * + * @param notes The list of grades to set. + */ + public void setNotes(ArrayList notes) { + this.notes = notes; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + for (var i : notes) { + result += i.hashCode(); + } + return result * prime; + } + + /** + * {@inheritDoc} + */ + @ExcludeFromJacocoGeneratedReport + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + MarksPage other = (MarksPage) obj; + if (notes == null) { + if (other.notes != null) { + return false; + } + } + Set thisSet = new HashSet<>(notes); + Set otherSet = new HashSet<>(other.notes); + return thisSet.equals(otherSet); + } +} diff --git a/task_1_4_1/app/src/test/java/task/StudentBookTest.java b/task_1_4_1/app/src/test/java/task/StudentBookTest.java new file mode 100644 index 0000000..f26e16a --- /dev/null +++ b/task_1_4_1/app/src/test/java/task/StudentBookTest.java @@ -0,0 +1,146 @@ +package task; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +class StudentBookTest { + GradeBook testBook = testData(); + + GradeBook testData() { + try { + GradeBook book = new GradeBook("Vlasov Vlas Vlasovich", 4); + book.writeInGradeBook(1, "Math", 5, true); + book.writeInGradeBook(1, "Rus", 3, false); + book.writeInGradeBook(1, "Discrete", 4, true); + book.writeInGradeBook(1, "History", 4, true); + book.writeInGradeBook(1, "Haskell", 5, true); + book.writeInGradeBook(1, "Digital Platforms", 5, false); + book.writeInGradeBook(1, "Imperative Programming", 5, true); + book.writeInGradeBook(2, "Imperative Programming", 4, true); + book.writeInGradeBook(2, "SQL", 2, false); + book.writeInGradeBook(2, "Math", 4, true); + book.writeInGradeBook(4, "Diploma", 5, true); + book.writeInGradeBook(3, "Introdution to AI", 5, true); + book.writeInGradeBook(3, "OOP", 5, true); + book.writeInGradeBook(3, "Diffurs", 4, true); + book.writeInGradeBook(3, "OSI", 5, true); + book.writeInGradeBook(4, "Models", 5, true); + book.writeInGradeBook(4, "Philosophy", 5, true); + return book; + } catch (Exception e) { + System.out.println(e.getMessage()); + return null; + } + + } + + @Test + public void setAndGetStudentNameTest() { + try { + testBook.setStudentName("Ivanov Ivan Ivanovich"); + } catch (GradeException e) { + System.out.println(e.getMessage()); + } + assertEquals("Ivanov Ivan Ivanovich", testBook.getStudentName()); + } + + @Test + public void setStudentIncorrectNameFormatExceptionTest() { + assertThrows(GradeException.class, () -> testBook.setStudentName("Ivan Ivanovich")); + } + + @Test + public void setStudentDigitsInNameExceptionTest() { + try { + testBook.setStudentName("Ivanov I4an Ivanovich"); + } catch (GradeException e) { + assertTrue(true); + } + } + + @Test + public void incorrectPageCountTest() { + try { + testBook.writeInGradeBook(10, null, 3, false); + } catch (GradeException e) { + assertTrue(true); + } + } + + @Test + public void incorrectMarktTest() { + try { + testBook.writeInGradeBook(3, null, 187, true); + } catch (GradeException e) { + assertTrue(true); + } + } + + @Test + public void writeInAndRemoveFromGradeBookTest() { + var newBook = testData(); + try { + testBook.writeInGradeBook(3, "Fizra", 5, false); + testBook.removeFromGradeBook(3, "Fizra"); + } catch (GradeException e) { + System.out.println(e.getMessage()); + } + assertEquals(newBook, testBook); + } + + @Test + public void scholarshipTest() { + assertTrue(testBook.scholarship(4)); + } + + @Test + public void redDiplomaTest() { + assertFalse(testBook.redDiploma()); + } + + @Test + public void redDiplomaGoodFinalTest() { + GradeBook newBook = null; + try { + newBook = new GradeBook("Petrov Petr Petrovich", 1); + newBook.writeInGradeBook(1, "Math", 5, true); + newBook.writeInGradeBook(1, "Diploma", 5, true); + } catch (GradeException e) { + System.out.println(e.getMessage()); + } + assertTrue(newBook.redDiploma()); + } + + @Test + public void averageMarkTest() { + assertEquals(4.529412f, testBook.averageMark()); + } + + @Test + public void hashCodeTest() { + var newBook = testData(); + newBook.removeFromGradeBook(1, "Haskell"); + try { + newBook.writeInGradeBook(1, "Haskell", 5, true); + } catch (GradeException e) { + System.out.println(e.getMessage()); + } + assertEquals(testBook.hashCode(), newBook.hashCode()); + } + + @Test + public void toStringTest() { + try { + var newBook = new GradeBook("Palkin Igor Alexandrovich", 2); + newBook.writeInGradeBook(1, "Math", 4, true); + newBook.writeInGradeBook(2, "Rus", 4, true); + newBook.writeInGradeBook(2, "Phis", 4, true); + } catch (GradeException e) { + System.out.println(e.getMessage()); + } + } +} diff --git a/task_1_4_1/gradle/wrapper/gradle-wrapper.jar b/task_1_4_1/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7f93135 Binary files /dev/null and b/task_1_4_1/gradle/wrapper/gradle-wrapper.jar differ diff --git a/task_1_4_1/gradle/wrapper/gradle-wrapper.properties b/task_1_4_1/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..3fa8f86 --- /dev/null +++ b/task_1_4_1/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/task_1_4_1/gradlew b/task_1_4_1/gradlew new file mode 100644 index 0000000..1aa94a4 --- /dev/null +++ b/task_1_4_1/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/task_1_4_1/gradlew.bat b/task_1_4_1/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/task_1_4_1/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/task_1_4_1/settings.gradle b/task_1_4_1/settings.gradle new file mode 100644 index 0000000..9ee0aec --- /dev/null +++ b/task_1_4_1/settings.gradle @@ -0,0 +1,14 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * The settings file is used to specify which projects to include in your build. + * For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.4/userguide/building_swift_projects.html in the Gradle documentation. + */ + +plugins { + // Apply the foojay-resolver plugin to allow automatic download of JDKs + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0' +} + +rootProject.name = 'task_1_4_1' +include('app')