From 3173785cfa75b6b723f606df83478e4f2ee7032e Mon Sep 17 00:00:00 2001 From: Mohammad Razeghi Date: Thu, 23 Nov 2023 21:30:35 +0100 Subject: [PATCH] Migrate to use sbt --- .gitignore | 10 ++ README.md | 2 +- build.gradle | 106 ------------------ build.sbt | 54 +++++++++ project/build.properties | 1 + project/plugins.sbt | 3 + settings.gradle | 2 - .../java/ir/huri/jcal/JalaliCalendar.java | 46 ++++++-- ...enderTest.java => JalaliCalendarTest.java} | 60 +++++----- 9 files changed, 135 insertions(+), 149 deletions(-) delete mode 100644 build.gradle create mode 100644 build.sbt create mode 100644 project/build.properties create mode 100644 project/plugins.sbt delete mode 100644 settings.gradle rename src/test/java/ir/huri/jcal/{JalaliCalenderTest.java => JalaliCalendarTest.java} (67%) diff --git a/.gitignore b/.gitignore index 78de7fc..09d987b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,13 @@ gradle.properties .gradle/ .idea build/ +.bsp +dist/* +target/ +lib_managed/ +src_managed/ +project/boot/ +project/plugins/project/ +.history +.cache +.lib/ diff --git a/README.md b/README.md index 25719d8..59c5791 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ JalaliCalendar is a Persian Calendar for java inspired from Roozh project. It ha JalaliCalendar is available in central maven repository. add `mavenCentral()` to your repository list in build.gradle. Then add this line to your dependencies: ```gradle -compile 'ir.huri:JalaliCalendar:1.3.3' +compile 'ir.huri:jalalicalendar:' ``` # Getting Started diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 65f5a12..0000000 --- a/build.gradle +++ /dev/null @@ -1,106 +0,0 @@ -buildscript { - repositories { - mavenCentral() - } -} - - -//plugins { -// id "com.jfrog.bintray" version "1.6" -//} - -group 'ir.huri' -version '1.3.3' - - -allprojects { - repositories { - mavenCentral() - } - - apply plugin: 'java' - apply plugin: 'maven' - apply plugin: 'signing' -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives sourcesJar, javadocJar -} - -signing { - sign configurations.archives -} - -//publishing { -// publications { -// MyPublication(MavenPublication) { -// from components.java -// groupId 'ir.huri' -// artifactId 'JalaliCalendar' -// version '1.3.1' -// artifact sourcesJar -// artifact javadocJar -// } -// } -//} - -dependencies { - testCompile group: 'junit', name: 'junit', version: '4.11' -} - - - -uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { - authentication(userName: ossrhUsername, password: ossrhPassword) - } - - snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { - authentication(userName: ossrhUsername, password: ossrhPassword) - } - - pom.project { - name 'Jalali Calendar' - packaging 'jar' - // optionally artifactId can be defined here - description 'JalaliCalendar is a Persian Calendar for java inspired from Roozh project. It has a better API and it\'s more developer friendly' - url 'https://github.com/razeghi71/JalaliCalendar' - - scm { - connection 'scm:git:git@github.com:razeghi71/JalaliCalendar' - developerConnection 'scm:git:git@github.com:razeghi71/JalaliCalendar' - url 'https://github.com/razeghi71/JalaliCalendar' - } - - licenses { - license { - name 'GPL v3' - url 'https://www.gnu.org/licenses/gpl-3.0.en.html' - } - } - - developers { - developer { - id 'razeghi71' - name 'Mohammad Razeghi' - email 'razeghi71@gmail.com' - } - } - } - } - } -} diff --git a/build.sbt b/build.sbt new file mode 100644 index 0000000..ed3d78e --- /dev/null +++ b/build.sbt @@ -0,0 +1,54 @@ +import sbt.url + +scalaVersion := "2.13.6" + +// Java project settings +crossPaths := false +autoScalaLibrary := false + +// Project organization settings +organization := "ir.huri" +organizationName := "Marzghi" +organizationHomepage := Some(url("https://github.com/razeghi71/")) + +// Project metadata +description := "JalaliCalendar is a Persian Calendar for java inspired from Roozh project. It has a better API and it's more developer friendly" +homepage := Some(url("https://github.com/razeghi71/JalaliCalendar")) +licenses := List("MIT License" -> url("https://opensource.org/licenses/MIT")) + +// Developer information +developers := List( + Developer( + id = "razeghi71", + name = "Mohammad Razeghi", + email = "razeghi71@gmail.com", + url = url("https://github.com/razeghi71/") + ) +) + +// Source Control Management (SCM) information +scmInfo := Some( + ScmInfo( + url("https://github.com/razeghi71/JalaliCalendar"), + "scm:git@github.com:razeghi71/JalaliCalendar.git" + ) +) + +// Library dependencies +libraryDependencies ++= Seq( + "junit" % "junit" % "4.13.2" % Test, + "com.novocode" % "junit-interface" % "0.11" % Test +) + +// Publishing settings +publishTo := { + val nexus = "https://oss.sonatype.org/" + if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots") + else Some("releases" at nexus + "service/local/staging/deploy/maven2") +} + +publishMavenStyle := true + +// POM configuration +pomIncludeRepository := { _ => false } +enablePlugins(GitVersioning) \ No newline at end of file diff --git a/project/build.properties b/project/build.properties new file mode 100644 index 0000000..3040987 --- /dev/null +++ b/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.9.4 diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000..f60acef --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1,3 @@ +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.21") +addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1") +addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.1") \ No newline at end of file diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 5f7eb17..0000000 --- a/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'JalaliCalendar' - diff --git a/src/main/java/ir/huri/jcal/JalaliCalendar.java b/src/main/java/ir/huri/jcal/JalaliCalendar.java index dea0462..1fd0146 100644 --- a/src/main/java/ir/huri/jcal/JalaliCalendar.java +++ b/src/main/java/ir/huri/jcal/JalaliCalendar.java @@ -6,19 +6,21 @@ import java.util.Date; import java.util.GregorianCalendar; +/** + * Model for JalaliCalendar + */ public class JalaliCalendar { - private int year, month, day; /** - * Today Jalali Date + * Today's Jalali date */ public JalaliCalendar() { fromGregorian(new GregorianCalendar()); } /** - * Create a ir.huri.jcal.JalaliCalendar object + * Create a JalaliCalendar object * @param year Jalali Year * @param month Jalali Month * @param day Jalali Day @@ -29,7 +31,7 @@ public JalaliCalendar(int year, int month, int day) { /** - * Create a ir.huri.jcal.JalaliCalendar object from gregorian calendar + * Create a JalaliCalendar object from gregorian calendar * @param gc gregorian calendar object */ public JalaliCalendar(GregorianCalendar gc){ @@ -38,7 +40,7 @@ public JalaliCalendar(GregorianCalendar gc){ /** - * Create a ir.huri.jcal.JalaliCalendar object from Localdate(java 8) + * Create a JalaliCalendar object from Localdate(java 8) * @param ld local date object */ public JalaliCalendar(LocalDate ld) { @@ -47,7 +49,7 @@ public JalaliCalendar(LocalDate ld) { /** - * Create a ir.huri.jcal.JalaliCalendar object from Date object + * Create a JalaliCalendar object from Date object * @param date Date object */ public JalaliCalendar(Date date) { @@ -192,10 +194,16 @@ public boolean isLeap() { return getLeapFactor(getYear()) == 0; } + /** + * @return the length of the current year. 366 for leap years and 365 for normal + */ public int getYearLength() { return isLeap() ? 366 : 365; } + /** + * @return return length of the jalalic month + */ public int getMonthLength() { if ( getMonth() < 7 ) { return 31; @@ -210,30 +218,53 @@ public int getMonthLength() { return 0; } + /** + * @return day + */ public int getDay() { return day; } + /** + * @return month + */ public int getMonth() { return month; } + /** + * @return year + */ public int getYear() { return year; } + /** + * @param month month number to set + */ public void setMonth(int month) { this.month = month; } + /** + * @param year number to set + */ public void setYear(int year) { this.year = year; } + /** + * @param day number to set + */ public void setDay(int day) { this.day = day; } + /** + * @param year year number to set + * @param month month number to set + * @param day day number to set + */ public void set(int year, int month, int day) { setYear(year); setMonth(month); @@ -436,7 +467,4 @@ public int getDay() { return day; } } - - - } diff --git a/src/test/java/ir/huri/jcal/JalaliCalenderTest.java b/src/test/java/ir/huri/jcal/JalaliCalendarTest.java similarity index 67% rename from src/test/java/ir/huri/jcal/JalaliCalenderTest.java rename to src/test/java/ir/huri/jcal/JalaliCalendarTest.java index 38bcaf5..bd1c015 100644 --- a/src/test/java/ir/huri/jcal/JalaliCalenderTest.java +++ b/src/test/java/ir/huri/jcal/JalaliCalendarTest.java @@ -1,33 +1,33 @@ package ir.huri.jcal; -import junit.framework.TestCase; import org.junit.Test; import java.util.Calendar; import java.util.GregorianCalendar; +import static org.junit.Assert.*; + /** * Created by mohammad on 4/15/16. */ -public class JalaliCalenderTest extends TestCase { +public class JalaliCalendarTest { @Test public void testGregorianToJalali() { - JalaliCalendar codeCreationDate = new JalaliCalendar(new GregorianCalendar(2016, 3, 16)); + JalaliCalendar codeCreationDate = new JalaliCalendar(new GregorianCalendar(2016, Calendar.APRIL, 16)); assertEquals(codeCreationDate, new JalaliCalendar(1395, 1, 28)); - JalaliCalendar myRoomMateBirthday = new JalaliCalendar(new GregorianCalendar(1992, 9, 25)); + JalaliCalendar myRoomMateBirthday = new JalaliCalendar(new GregorianCalendar(1992, Calendar.OCTOBER, 25)); assertEquals(myRoomMateBirthday, new JalaliCalendar(1371, 8, 3)); - JalaliCalendar myBirthday = new JalaliCalendar(new GregorianCalendar(1992, 10, 18)); + JalaliCalendar myBirthday = new JalaliCalendar(new GregorianCalendar(1992, Calendar.NOVEMBER, 18)); assertEquals(myBirthday, new JalaliCalendar(1371, 8, 27)); - JalaliCalendar boundaryDay= new JalaliCalendar(new GregorianCalendar(2016, 0, 31)); + JalaliCalendar boundaryDay = new JalaliCalendar(new GregorianCalendar(2016, Calendar.JANUARY, 31)); assertEquals(boundaryDay, new JalaliCalendar(1394, 11, 11)); - JalaliCalendar otherBoundaryDay= new JalaliCalendar(new GregorianCalendar(2017, 0, 20)); + JalaliCalendar otherBoundaryDay = new JalaliCalendar(new GregorianCalendar(2017, Calendar.JANUARY, 20)); assertEquals(otherBoundaryDay, new JalaliCalendar(1395, 11, 1)); - } @Test @@ -53,7 +53,7 @@ public void testToString() { JalaliCalendar myRoomMateBirthday = new JalaliCalendar(1371, 8, 3); assertEquals(myRoomMateBirthday.toString(), "1371-08-03"); - JalaliCalendar codeCreationDate = new JalaliCalendar(new GregorianCalendar(2016, 3, 16)); + JalaliCalendar codeCreationDate = new JalaliCalendar(new GregorianCalendar(2016, Calendar.APRIL, 16)); assertEquals(codeCreationDate.toString(), "1395-01-28"); } @@ -62,14 +62,13 @@ public void testRelativeDates() { JalaliCalendar myFriendsBirthday = new JalaliCalendar(1372, 4, 8); JalaliCalendar nextDay = myFriendsBirthday.getTomorrow(); JalaliCalendar prevDay = myFriendsBirthday.getYesterday(); - JalaliCalendar boundaryDay = new JalaliCalendar(1372,8,30).getDateByDiff(2); - JalaliCalendar boundaryDay2 = new JalaliCalendar(1372,1,15).getDateByDiff(20); + JalaliCalendar boundaryDay = new JalaliCalendar(1372, 8, 30).getDateByDiff(2); + JalaliCalendar boundaryDay2 = new JalaliCalendar(1372, 1, 15).getDateByDiff(20); - - assertEquals(nextDay, new JalaliCalendar(1372,4, 9)); - assertEquals(prevDay, new JalaliCalendar(1372,4, 7)); - assertEquals(boundaryDay, new JalaliCalendar(1372,9, 2)); - assertEquals(boundaryDay2, new JalaliCalendar(1372,2, 4)); + assertEquals(nextDay, new JalaliCalendar(1372, 4, 9)); + assertEquals(prevDay, new JalaliCalendar(1372, 4, 7)); + assertEquals(boundaryDay, new JalaliCalendar(1372, 9, 2)); + assertEquals(boundaryDay2, new JalaliCalendar(1372, 2, 4)); } @Test @@ -86,26 +85,26 @@ public void testWeekDay() { @Test public void testLeap() { - JalaliCalendar leapYear = new JalaliCalendar(1391, 1 ,1); - assertEquals(true, leapYear.isLeap()); + JalaliCalendar leapYear = new JalaliCalendar(1391, 1, 1); + assertTrue(leapYear.isLeap()); - JalaliCalendar leapYear2 = new JalaliCalendar(1395, 1 ,1); - assertEquals(true, leapYear2.isLeap()); + JalaliCalendar leapYear2 = new JalaliCalendar(1395, 1, 1); + assertTrue(leapYear2.isLeap()); - JalaliCalendar leapYear3 = new JalaliCalendar(1383, 12 ,20); - assertEquals(true, leapYear3.isLeap()); + JalaliCalendar leapYear3 = new JalaliCalendar(1383, 12, 20); + assertTrue(leapYear3.isLeap()); - JalaliCalendar notLeapYear1 = new JalaliCalendar(1396, 1 ,1); - assertEquals(false, notLeapYear1.isLeap()); + JalaliCalendar notLeapYear1 = new JalaliCalendar(1396, 1, 1); + assertFalse(notLeapYear1.isLeap()); - JalaliCalendar notLeapYear2 = new JalaliCalendar(1398, 12 ,1); - assertEquals(false, notLeapYear2.isLeap()); + JalaliCalendar notLeapYear2 = new JalaliCalendar(1398, 12, 1); + assertFalse(notLeapYear2.isLeap()); - JalaliCalendar notLeapYear3 = new JalaliCalendar(1380, 7 ,1); - assertEquals(false, notLeapYear3.isLeap()); + JalaliCalendar notLeapYear3 = new JalaliCalendar(1380, 7, 1); + assertFalse(notLeapYear3.isLeap()); - JalaliCalendar notLeapYear4 = new JalaliCalendar(1384, 12 ,1); - assertEquals(false, notLeapYear4.isLeap()); + JalaliCalendar notLeapYear4 = new JalaliCalendar(1384, 12, 1); + assertFalse(notLeapYear4.isLeap()); assertEquals(366, leapYear.getYearLength()); assertEquals(366, leapYear2.getYearLength()); @@ -123,7 +122,6 @@ public void testLeap() { assertEquals(29, notLeapYear2.getMonthLength()); assertEquals(30, notLeapYear3.getMonthLength()); assertEquals(29, notLeapYear4.getMonthLength()); - }