-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed configuration for Project to PROJECT.conf
- Loading branch information
Showing
28 changed files
with
537 additions
and
361 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
139 changes: 0 additions & 139 deletions
139
03-api/src/main/scala/camundala/api/ApiProjectConf.scala
This file was deleted.
Oops, something went wrong.
118 changes: 118 additions & 0 deletions
118
03-api/src/main/scala/camundala/api/ApiProjectConfig.scala
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,118 @@ | ||
package camundala.api | ||
|
||
import com.typesafe.config.ConfigFactory | ||
import scala.jdk.CollectionConverters.* | ||
|
||
final case class ApiProjectConfig( | ||
projectName: String, | ||
projectVersion: VersionConfig, | ||
subProjects: Seq[String], | ||
dependencies: Seq[DependencyConfig] | ||
): | ||
lazy val companyName: String = projectName.split("-").head | ||
end ApiProjectConfig | ||
|
||
object ApiProjectConfig: | ||
|
||
def init(projectName: String, newPackageFile: os.Path = os.pwd / defaultProjectConfigPath) = | ||
if !os.exists(newPackageFile) | ||
then | ||
println(s"Created initial $newPackageFile") | ||
os.makeDir.all(newPackageFile / os.up) | ||
os.write( | ||
newPackageFile, | ||
s""" | ||
|org = "${projectName.split("-").head}" | ||
|name = "$projectName" | ||
|version = "${DocProjectConfig.defaultVersion}" | ||
|dependencies: { | ||
| | ||
|} | ||
|""".stripMargin | ||
) | ||
end if | ||
apply(newPackageFile) | ||
end init | ||
|
||
def apply(projectConfigPath: os.Path = os.pwd / defaultProjectConfigPath): ApiProjectConfig = | ||
val projectConfig = ConfigFactory.parseFile(projectConfigPath.toIO) | ||
val projectName = projectConfig.getString("projectName") | ||
val projectVersion = projectConfig.getString("projectVersion") | ||
val subProjects = projectConfig.getStringList("subProjects").asScala.toSeq | ||
val dependencies = projectConfig | ||
.getObject("dependencies") | ||
.unwrapped() | ||
.asScala | ||
.map: | ||
case k -> v => | ||
DependencyConfig.apply(k, v.toString) | ||
.toSeq | ||
|
||
ApiProjectConfig( | ||
projectName, | ||
VersionConfig(projectVersion), | ||
subProjects, | ||
dependencies | ||
) | ||
end apply | ||
|
||
def apply(projectName: String, projectVersion: String): ApiProjectConfig = | ||
ApiProjectConfig( | ||
projectName = projectName, | ||
projectVersion = VersionConfig(projectVersion), | ||
subProjects = Seq.empty, | ||
dependencies = Seq.empty | ||
) | ||
end ApiProjectConfig | ||
|
||
case class VersionConfig(major: Int, minor: Int, patch: Int, isSnapshot: Boolean = false): | ||
def isMajor(version: VersionConfig): Boolean = | ||
major != version.major | ||
|
||
def isMinor(version: VersionConfig): Boolean = | ||
major == version.major && minor != version.minor | ||
|
||
def isPatch(version: VersionConfig): Boolean = | ||
major == version.major && minor == version.minor && patch != version.patch | ||
|
||
lazy val minorVersion: String = s"$major.$minor" | ||
lazy val versionAsInt: Int = | ||
major * 100000 + minor * 1000 + patch | ||
|
||
override def toString: String = s"$minorVersion.$patch${if isSnapshot then "-SNAPSHOT" else ""}" | ||
end VersionConfig | ||
|
||
object VersionConfig: | ||
def apply(version: String): VersionConfig = | ||
version.split("\\.") match | ||
case Array(major, minor, patch) => | ||
if patch.endsWith("-SNAPSHOT") then | ||
VersionConfig(major.toInt, minor.toInt, patch.dropRight(9).toInt, isSnapshot = true) | ||
else | ||
VersionConfig(major.toInt, minor.toInt, patch.toInt) | ||
end VersionConfig | ||
|
||
final case class DependencyConfig( | ||
projectName: String, | ||
projectVersion: VersionConfig | ||
): | ||
lazy val minorVersion: String = projectVersion.minorVersion | ||
lazy val companyName: String = projectName.split("-").head | ||
lazy val fullName = s"$companyName:$projectName:$projectVersion" | ||
lazy val projectPackage = s"${projectName.split("-").mkString(".")}" | ||
|
||
def equalTo(packageConf: DocProjectConfig): Boolean = | ||
packageConf.companyName == companyName && packageConf.projectName == projectName && packageConf.minorVersion == projectVersion.minorVersion | ||
end DependencyConfig | ||
|
||
object DependencyConfig: | ||
def apply(projectName: String, version: String): DependencyConfig = | ||
DependencyConfig(projectName, VersionConfig(version)) | ||
// "org:name:version" => DependencyConfig - only works for the company-project | ||
def apply(dependency: String): DependencyConfig = | ||
val dArray = dependency.replace("\"", "").split(":") | ||
// DependencyConfig(dArray(0), dArray(1), dArray(2)) | ||
val lastVersion = VersionHelper.repoSearch(dArray(1), dArray(0)) | ||
DependencyConfig(dArray(1), VersionConfig(lastVersion)) | ||
|
||
end DependencyConfig |
79 changes: 79 additions & 0 deletions
79
03-api/src/main/scala/camundala/api/DocProjectConfig.scala
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,79 @@ | ||
package camundala.api | ||
|
||
import com.typesafe.config.ConfigFactory | ||
|
||
import scala.jdk.CollectionConverters.CollectionHasAsScala | ||
import scala.util.Try | ||
|
||
case class DocProjectConfig( | ||
apiProjectConfig: ApiProjectConfig, | ||
versionPrevious: String, | ||
changelog: Seq[String] = Seq.empty, | ||
isWorker: Boolean = false | ||
): | ||
lazy val companyName: String = apiProjectConfig.companyName | ||
lazy val projectName: String = apiProjectConfig.projectName | ||
lazy val projectVersion: VersionConfig = apiProjectConfig.projectVersion | ||
lazy val versionPreviousConf: VersionConfig = versionFor(versionPrevious) | ||
lazy val version: String = projectVersion.toString | ||
lazy val versionAsInt: Int = projectVersion.versionAsInt | ||
|
||
lazy val dependencies: Seq[DependencyConfig] = apiProjectConfig.dependencies | ||
|
||
lazy val isNew = | ||
projectVersion.isMajor(versionPreviousConf) || projectVersion.isMinor(versionPreviousConf) | ||
lazy val isPatched = !isNew && projectVersion.isPatch(versionPreviousConf) | ||
lazy val minorVersion: String = projectVersion.minorVersion | ||
lazy val fullName = s"$companyName:$projectName:$projectVersion" | ||
|
||
private def versionFor(version: String) = | ||
Try(VersionConfig(version)) | ||
.getOrElse: | ||
println(s"Version $version is not valid. for $companyName:$projectName") | ||
VersionConfig(DocProjectConfig.defaultVersion) | ||
|
||
end DocProjectConfig | ||
|
||
object DocProjectConfig: | ||
lazy val defaultVersion = "0.1.0" | ||
|
||
def apply( | ||
packageFile: os.Path | ||
): DocProjectConfig = | ||
apply(packageFile, Seq.empty, DocProjectConfig.defaultVersion, false) | ||
def apply( | ||
packageFile: os.Path, | ||
changelog: Seq[String], | ||
versionPrevious: String, | ||
isWorker: Boolean | ||
): DocProjectConfig = | ||
val apiProjectConfig = ApiProjectConfig(packageFile) | ||
DocProjectConfig( | ||
apiProjectConfig, | ||
versionPrevious, | ||
changelog, | ||
isWorker | ||
) | ||
end apply | ||
|
||
def init(projectName: String, newPackageFile: os.Path) = | ||
if !os.exists(newPackageFile) | ||
then | ||
println(s"Created initial $newPackageFile") | ||
os.makeDir.all(newPackageFile / os.up) | ||
os.write( | ||
newPackageFile, | ||
s""" | ||
|org = "${projectName.split("-").head}" | ||
|name = "$projectName" | ||
|version = "${DocProjectConfig.defaultVersion}" | ||
|dependencies: { | ||
| | ||
|} | ||
|""".stripMargin | ||
) | ||
end if | ||
apply(newPackageFile) | ||
end init | ||
|
||
end DocProjectConfig |
Oops, something went wrong.