From e670efd4f8e759eeed42c720bb36686488893fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fede=20Fern=C3=A1ndez?= Date: Mon, 24 Apr 2017 17:37:47 +0200 Subject: [PATCH 1/3] Unifies filetye and validation types --- .../sbtorgpolicies/github/GitHubOps.scala | 4 +- .../scala/sbtorgpolicies/io/FileReader.scala | 73 ++++++++++--------- .../sbtorgpolicies/io/ReplaceTextEngine.scala | 30 +------- .../rules/ValidationFunctions.scala | 2 + .../sbtorgpolicies/templates/model.scala | 4 +- .../sbtorgpolicies/templates/templates.scala | 26 +++++-- .../sbtorgpolicies/github/GitHubOpsTest.scala | 13 +++- .../sbtorgpolicies/rules/RulesTest.scala | 20 ++--- project/ProjectPlugin.scala | 4 +- .../sbtorgpolicies/OrgPoliciesKeys.scala | 3 - .../settings/DefaultSettings.scala | 3 +- .../settings/fileValidation.scala | 52 +++---------- .../scala/sbtorgpolicies/settings/files.scala | 11 ++- 13 files changed, 113 insertions(+), 132 deletions(-) diff --git a/core/src/main/scala/sbtorgpolicies/github/GitHubOps.scala b/core/src/main/scala/sbtorgpolicies/github/GitHubOps.scala index f9766fa..c345df0 100644 --- a/core/src/main/scala/sbtorgpolicies/github/GitHubOps.scala +++ b/core/src/main/scala/sbtorgpolicies/github/GitHubOps.scala @@ -67,7 +67,7 @@ class GitHubOps(owner: String, repo: String, accessToken: Option[String]) { def readFileContents: IOResult[List[(String, String)]] = { files.foldLeft[IOResult[List[(String, String)]]](Right(Nil)) { case (Right(partialResult), file) => - fileReader.getFileContent(file.getAbsolutePath).map { content => + fileReader.getFileContent(file.getAbsolutePath) map { content => (relativePath(file), content) :: partialResult } case (Left(e), _) => Left(e) @@ -170,7 +170,7 @@ class GitHubOps(owner: String, repo: String, accessToken: Option[String]) { def getAllFilesAsGithub4sResponse(dir: File): Github4sResponse[List[File]] = { val ghio: GHIO[GHResponse[List[File]]] = Free.pure { fileReader - .fetchFilesRecursively(dir) + .fetchFilesRecursively(List(dir)) .bimap( e => UnexpectedException(e.getMessage), v => newGHResult(v) diff --git a/core/src/main/scala/sbtorgpolicies/io/FileReader.scala b/core/src/main/scala/sbtorgpolicies/io/FileReader.scala index 5c19023..10deee4 100644 --- a/core/src/main/scala/sbtorgpolicies/io/FileReader.scala +++ b/core/src/main/scala/sbtorgpolicies/io/FileReader.scala @@ -27,9 +27,6 @@ import scala.annotation.tailrec class FileReader { - def getChildPath(parent: File, childPath: String): String = - new File(parent, childPath).getAbsolutePath - def exists(path: String): Boolean = Either .catchNonFatal(file(path).exists()) getOrElse false @@ -47,44 +44,50 @@ class FileReader { .catchNonFatal(IO.readBytes(file)) .leftMap(e => IOException(s"Error loading ${file.getAbsolutePath} content", Some(e))) - def fetchFilesRecursivelyFromPath(sourcePath: String, acceptedExtensions: List[String] = Nil): IOResult[List[File]] = - fetchFilesRecursively(sourcePath.toFile, acceptedExtensions) + private[this] val defaultValidDirs: (File) => Boolean = (f: File) => { + !Set("target", "bin", "output").contains(f.getName) && !f.getName.startsWith(".") + } + + def fetchFilesRecursivelyFromPath( + sourcePath: String, + isFileSupported: (File) => Boolean = _ => true, + isDirSupported: (File) => Boolean = defaultValidDirs): IOResult[List[File]] = + fetchFilesRecursively(List(sourcePath.toFile)) - def fetchFilesRecursively(sourceFile: File, acceptedExtensions: List[String] = Nil): IOResult[List[File]] = + def fetchFilesRecursively( + in: List[File], + isFileSupported: (File) => Boolean = _ => true, + isDirSupported: (File) => Boolean = defaultValidDirs): IOResult[List[File]] = Either .catchNonFatal { - @tailrec - def innerRecursive(files: List[File], accum: List[File]): List[File] = { - - val acceptedFiles = files filter acceptedExtension - val filesDirectories = files filter (_.isDirectory) flatMap (_.listFiles().toList) - - val newAccum = accum ++ acceptedFiles - - filesDirectories match { - case Nil => newAccum - case _ => innerRecursive(filesDirectories, newAccum) + def findAllFiles( + in: List[File], + isFileSupported: (File) => Boolean, + isDirSupported: (File) => Boolean, + processedFiles: List[File] = Nil, + processedDirs: List[String] = Nil): List[File] = { + + val allFiles: List[File] = processedFiles ++ in.filter(f => f.exists && f.isFile && isFileSupported(f)) + + in.filter { f => + f.isDirectory && + isDirSupported(f) && + !processedDirs.contains(f.getCanonicalPath) + } match { + case Nil => allFiles + case list => + val subFiles = list.flatMap(_.listFiles().toList) + findAllFiles( + subFiles, + isFileSupported, + isDirSupported, + allFiles, + processedDirs ++ list.map(_.getCanonicalPath)) } } - def acceptedExtension(file: File): Boolean = - file.isFile && - (acceptedExtensions.isEmpty || - acceptedExtensions.foldLeft(false) { (b, ext) => - b || file.getName.endsWith(ext) - }) - - (sourceFile.exists(), sourceFile.isFile, acceptedExtension(sourceFile)) match { - case (false, _, _) => - Nil - case (_, true, false) => - Nil - case (_, true, true) => - List(sourceFile) - case _ => - innerRecursive(Option(sourceFile.listFiles.toList).toList.flatten, Nil) - } + findAllFiles(in, isFileSupported, isDirSupported) } - .leftMap(e => IOException(s"Error fetching files recursively from ${sourceFile.getAbsolutePath}", Some(e))) + .leftMap(e => IOException(s"Error fetching files recursively", Some(e))) } diff --git a/core/src/main/scala/sbtorgpolicies/io/ReplaceTextEngine.scala b/core/src/main/scala/sbtorgpolicies/io/ReplaceTextEngine.scala index 31ad350..903711a 100644 --- a/core/src/main/scala/sbtorgpolicies/io/ReplaceTextEngine.scala +++ b/core/src/main/scala/sbtorgpolicies/io/ReplaceTextEngine.scala @@ -33,39 +33,15 @@ class ReplaceTextEngine { val fileReader: FileReader = new FileReader val fileWriter: FileWriter = new FileWriter - val excludeDirs: Set[String] = Set("target", "bin", "output") - final def replaceBlocks( startBlockRegex: Regex, endBlockRegex: Regex, replacements: Map[String, String], in: List[File], - isFileSupported: (File) => Boolean): List[ProcessedFile] = - findAllFiles(in, isFileSupported) map { - replaceBlocksInFile(startBlockRegex, endBlockRegex, replacements, _) - } - - @tailrec - private[this] final def findAllFiles( - in: List[File], - isFileSupported: (File) => Boolean, - processedFiles: List[File] = Nil, - processedDirs: List[String] = Nil): List[File] = { - - val allFiles: List[File] = processedFiles ++ in.filter(f => f.isFile && isFileSupported(f)) - - in.filter { f => - f.isDirectory && - !excludeDirs.contains(f.getName) && - !f.getName.startsWith(".") && - !processedDirs.contains(f.getCanonicalPath) - } match { - case Nil => allFiles - case list => - val subFiles = list.flatMap(_.listFiles().toList) - findAllFiles(subFiles, isFileSupported, allFiles, processedDirs ++ list.map(_.getCanonicalPath)) + isFileSupported: (File) => Boolean): IOResult[List[ProcessedFile]] = + fileReader.fetchFilesRecursively(in, isFileSupported) map { files => + files.map(replaceBlocksInFile(startBlockRegex, endBlockRegex, replacements, _)) } - } private[this] def replaceBlocksInFile( startBlockRegex: Regex, diff --git a/core/src/main/scala/sbtorgpolicies/rules/ValidationFunctions.scala b/core/src/main/scala/sbtorgpolicies/rules/ValidationFunctions.scala index 7f4d989..f5f8d1e 100644 --- a/core/src/main/scala/sbtorgpolicies/rules/ValidationFunctions.scala +++ b/core/src/main/scala/sbtorgpolicies/rules/ValidationFunctions.scala @@ -102,3 +102,5 @@ trait ValidationFunctions { validateTasks(content, "after_success", afterSuccessTasks) } } + +object ValidationFunctions extends ValidationFunctions \ No newline at end of file diff --git a/core/src/main/scala/sbtorgpolicies/templates/model.scala b/core/src/main/scala/sbtorgpolicies/templates/model.scala index 2522441..c4d2cb5 100644 --- a/core/src/main/scala/sbtorgpolicies/templates/model.scala +++ b/core/src/main/scala/sbtorgpolicies/templates/model.scala @@ -17,6 +17,7 @@ package sbtorgpolicies.templates import org.joda.time.DateTime +import sbtorgpolicies.rules.ValidationFunction import sbtorgpolicies.templates.syntax._ import scala.util.matching.Regex @@ -41,7 +42,8 @@ case class FileType( templatePath: String, outputPath: String, replacements: Replacements, - fileSections: List[FileSection] = Nil) + fileSections: List[FileSection] = Nil, + validations: List[ValidationFunction] = Nil) case class FileSection( appendPosition: AppendPosition, diff --git a/core/src/main/scala/sbtorgpolicies/templates/templates.scala b/core/src/main/scala/sbtorgpolicies/templates/templates.scala index c52ec84..ae518c2 100644 --- a/core/src/main/scala/sbtorgpolicies/templates/templates.scala +++ b/core/src/main/scala/sbtorgpolicies/templates/templates.scala @@ -21,6 +21,7 @@ import net.jcazevedo.moultingyaml._ import org.joda.time.DateTime import org.joda.time.format.DateTimeFormat import sbtorgpolicies.model._ +import sbtorgpolicies.rules.ValidationFunctions._ import sbtorgpolicies.templates.badges.{BadgeBuilder, BadgeInformation} import sbtorgpolicies.templates.sectionTemplates._ import sbtorgpolicies.templates.syntax._ @@ -55,7 +56,8 @@ package object templates { "year" -> replaceableYear(startYear).asReplaceable, "organizationName" -> ghSettings.organizationName.asReplaceable, "organizationHomePage" -> ghSettings.organizationHomePage.asReplaceable - ) + ), + validations = List(requiredStrings(List(license.name))) ) } @@ -86,6 +88,8 @@ package object templates { case None => s"[${dev.id}](https://github.com/${dev.id})" } + def devListStrings(list: List[Dev]): List[String] = list.map(_.id) ++ list.flatMap(_.name) + FileType( mandatory = true, overWritable = true, @@ -96,7 +100,8 @@ package object templates { "name" -> projectName.asReplaceable, "maintainers" -> maintainers.map(devTemplate).asReplaceable, "contributors" -> contributors.map(devTemplate).asReplaceable - ) + ), + validations = List(requiredStrings(devListStrings(maintainers ++ contributors))) ) } @@ -117,7 +122,8 @@ package object templates { "name" -> projectName.asReplaceable, "organizationName" -> ghSettings.organizationName.asReplaceable, "licenseName" -> license.name.asReplaceable - ) + ), + validations = List(requiredStrings(List(projectName, license.name))) ) } @@ -187,6 +193,8 @@ package object templates { badgeBuilderList.map(_(info)).map(_.asMarkDown.getOrElse("")).mkString(" ").asReplaceable } + def readmeSections(name: String): List[String] = List(s"$name in the wild") + FileType( mandatory = true, overWritable = false, @@ -214,7 +222,8 @@ package object templates { template = badgesSectionTemplate, replacements = Map("badges" -> replaceableBadges) ) - ) + ), + validations = List(requiredStrings(readmeSections(projectName))) ) } @@ -230,7 +239,7 @@ package object templates { ) } - def TravisFileType(crossScalaV: Seq[String]): FileType = { + def TravisFileType(crossScalaV: Seq[String], scriptCICommand: String, afterCISuccessCommand: String): FileType = { import sbtorgpolicies.model.YamlFormats._ @@ -242,6 +251,13 @@ package object templates { outputPath = travisFilePath, replacements = Map( "crossScalaVersions" -> crossScalaV.toYaml.prettyPrint.asReplaceable + ), + validations = List( + validTravisFile( + crossScalaV, + Seq(scriptCICommand), + Seq(afterCISuccessCommand) + ) ) ) } diff --git a/core/src/test/scala/sbtorgpolicies/github/GitHubOpsTest.scala b/core/src/test/scala/sbtorgpolicies/github/GitHubOpsTest.scala index 554ea31..fce0a01 100644 --- a/core/src/test/scala/sbtorgpolicies/github/GitHubOpsTest.scala +++ b/core/src/test/scala/sbtorgpolicies/github/GitHubOpsTest.scala @@ -373,7 +373,12 @@ class GitHubOpsTest extends TestOps { val files: List[(File, String)] = filesAndContents.map(t => (new File(baseDir, t._1), t._2)) - when(fileReaderMock.fetchFilesRecursively(any[File], any[List[String]])) + when( + fileReaderMock + .fetchFilesRecursively( + any[List[File]], + any[Function1[File, Boolean]].apply, + any[Function1[File, Boolean]].apply)) .thenReturn(files.map(_._1).asRight) files foreach { @@ -428,7 +433,11 @@ class GitHubOpsTest extends TestOps { val ioException: IOException = IOException("Test error") - when(fileReaderMock.fetchFilesRecursively(any[File], any[List[String]])) + when( + fileReaderMock.fetchFilesRecursively( + any[List[File]], + any[Function1[File, Boolean]].apply, + any[Function1[File, Boolean]].apply)) .thenReturn(ioException.asLeft) val result: Either[OrgPolicyException, Ref] = diff --git a/core/src/test/scala/sbtorgpolicies/rules/RulesTest.scala b/core/src/test/scala/sbtorgpolicies/rules/RulesTest.scala index 42859f6..4012a1d 100644 --- a/core/src/test/scala/sbtorgpolicies/rules/RulesTest.scala +++ b/core/src/test/scala/sbtorgpolicies/rules/RulesTest.scala @@ -23,7 +23,7 @@ import sbtorgpolicies.exceptions.ValidationException class RulesTest extends TestOps { - val vfs = new ValidationFunctions {} + import ValidationFunctions._ test("emptyValidation should return Right for all strings") { @@ -44,7 +44,7 @@ class RulesTest extends TestOps { |End """.stripMargin - vfs.requiredStrings(randomStrings)(content) shouldBeEq ().validNel + requiredStrings(randomStrings)(content) shouldBeEq ().validNel } check(property) @@ -62,7 +62,7 @@ class RulesTest extends TestOps { val realMissing = missing.filterNot(existing.contains).filter(_.nonEmpty) - val result = vfs.requiredStrings(existing ++ realMissing)(content) + val result = requiredStrings(existing ++ realMissing)(content) if (realMissing.isEmpty) { result shouldBeEq ().validNel } else { @@ -96,8 +96,8 @@ class RulesTest extends TestOps { if (s.contains("User 1") && s.contains("User 2") && s.contains("User 3")) validResponse else ValidationException("").invalidNel - vfs.requiredSection("\\#\\#\\#.*Changelog".r, "\\#\\#\\#".r, changelogValidation)(content) shouldBeEq validResponse - vfs.requiredSection("\\#\\#\\#.*Contributors".r, "\\#\\#\\#".r, contributorsValidation)(content) shouldBeEq validResponse + requiredSection("\\#\\#\\#.*Changelog".r, "\\#\\#\\#".r, changelogValidation)(content) shouldBeEq validResponse + requiredSection("\\#\\#\\#.*Contributors".r, "\\#\\#\\#".r, contributorsValidation)(content) shouldBeEq validResponse } test("requiredSection should return Left if the section is not included in the content") { @@ -114,7 +114,7 @@ class RulesTest extends TestOps { def changelogValidation(s: String): ValidationResult = ().validNel - vfs.requiredSection("\\#\\#\\#.*Changelog".r, "\\#\\#\\#".r, changelogValidation)(content) shouldBeEq invalidResponse + requiredSection("\\#\\#\\#.*Changelog".r, "\\#\\#\\#".r, changelogValidation)(content) shouldBeEq invalidResponse } test("requiredSection should return Left if the section is not valid") { @@ -136,7 +136,7 @@ class RulesTest extends TestOps { def contributorsValidation(s: String): ValidationResult = ValidationException("Section not valid").invalidNel - vfs.requiredSection("\\#\\#\\#.*Contributors".r, "\\#\\#\\#".r, contributorsValidation)(content) shouldBeEq invalidResponse + requiredSection("\\#\\#\\#.*Contributors".r, "\\#\\#\\#".r, contributorsValidation)(content) shouldBeEq invalidResponse } test("requiredStrings and requiredSection should works as expected when combined") { @@ -159,10 +159,10 @@ class RulesTest extends TestOps { if (s.nonEmpty) validResponse else ValidationException("").invalidNel def contributorsValidation(s: String): ValidationResult = - vfs.requiredStrings(List("User 1", "User 2", "User 3"))(s) + requiredStrings(List("User 1", "User 2", "User 3"))(s) - vfs.requiredSection("\\#\\#\\#.*Changelog".r, "\\#\\#\\#".r, changelogValidation)(content) shouldBeEq validResponse - vfs.requiredSection("\\#\\#\\#.*Contributors".r, "\\#\\#\\#".r, contributorsValidation)(content) shouldBeEq validResponse + requiredSection("\\#\\#\\#.*Changelog".r, "\\#\\#\\#".r, changelogValidation)(content) shouldBeEq validResponse + requiredSection("\\#\\#\\#.*Contributors".r, "\\#\\#\\#".r, contributorsValidation)(content) shouldBeEq validResponse } } diff --git a/project/ProjectPlugin.scala b/project/ProjectPlugin.scala index 928ac9c..a4ae874 100644 --- a/project/ProjectPlugin.scala +++ b/project/ProjectPlugin.scala @@ -32,8 +32,8 @@ object ProjectPlugin extends AutoPlugin { addSbtPlugin("de.heikoseeberger" % "sbt-header" % "1.8.0"), addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0"), addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.6.8"), - addSbtPlugin("com.47deg" % "sbt-dependencies" % "0.1.0"), - addSbtPlugin("com.47deg" % "sbt-microsites" % "0.5.3") + addSbtPlugin("com.47deg" % "sbt-dependencies" % "0.1.1"), + addSbtPlugin("com.47deg" % "sbt-microsites" % "0.5.4") ) ++ ScriptedPlugin.scriptedSettings ++ Seq( scriptedDependencies := (compile in Test) map { _ => diff --git a/src/main/scala/sbtorgpolicies/OrgPoliciesKeys.scala b/src/main/scala/sbtorgpolicies/OrgPoliciesKeys.scala index 84bb780..d9b156a 100644 --- a/src/main/scala/sbtorgpolicies/OrgPoliciesKeys.scala +++ b/src/main/scala/sbtorgpolicies/OrgPoliciesKeys.scala @@ -89,9 +89,6 @@ sealed trait OrgPoliciesSettingsKeys { "Optional. Directory where are placed the different templates it'll be used. " + "By default, it'll be the resourcesDirectory + '/org/templates'") - val orgValidationListSetting: SettingKey[List[Validation]] = - settingKey[List[Validation]]("Validation list the plugin must check") - val orgUpdateDocFilesSetting: SettingKey[List[File]] = settingKey[List[File]]("List of files and directories whose replace blocks will be replaced with the new values.") diff --git a/src/main/scala/sbtorgpolicies/settings/DefaultSettings.scala b/src/main/scala/sbtorgpolicies/settings/DefaultSettings.scala index 3f4b960..2b86c6e 100644 --- a/src/main/scala/sbtorgpolicies/settings/DefaultSettings.scala +++ b/src/main/scala/sbtorgpolicies/settings/DefaultSettings.scala @@ -52,7 +52,6 @@ trait DefaultSettings extends AllSettings { orgBashTasks ++ orgCommonTasks ++ sbtDependenciesSettings ++ - fileValidationDefaultSettings ++ AutomateHeaderPlugin.automateFor(Compile, Test) lazy val orgCommonDefaultSettings = Seq( @@ -109,7 +108,7 @@ trait DefaultSettings extends AllSettings { orgBadgeListSetting.value ), ScalafmtFileType, - TravisFileType(crossScalaVersions.value) + TravisFileType(crossScalaVersions.value, orgScriptCICommandKey, orgAfterCISuccessCommandKey) ), orgTemplatesDirectorySetting := (resourceDirectory in Compile).value / "org" / "templates", commands ++= Seq(orgScriptCICommand, orgPublishReleaseCommand, orgAfterCISuccessCommand), diff --git a/src/main/scala/sbtorgpolicies/settings/fileValidation.scala b/src/main/scala/sbtorgpolicies/settings/fileValidation.scala index b2146f7..438e804 100644 --- a/src/main/scala/sbtorgpolicies/settings/fileValidation.scala +++ b/src/main/scala/sbtorgpolicies/settings/fileValidation.scala @@ -20,60 +20,30 @@ import cats.data.Validated.{Invalid, Valid} import sbt.Keys._ import sbt._ import sbtorgpolicies.exceptions.ValidationException -import sbtorgpolicies.model.Dev import sbtorgpolicies.rules._ import sbtorgpolicies.OrgPoliciesKeys._ +import sbtorgpolicies.templates.FileType trait fileValidation extends ValidationFunctions { val fileValidation = new FileValidation - import fileValidation.fileReader._ - - val fileValidationDefaultSettings = Seq( - orgValidationListSetting := List( - mkValidation( - getChildPath(baseDirectory.value, "README.md"), - List(requiredStrings(readmeSections(orgProjectName.value)))), - mkValidation(getChildPath(baseDirectory.value, "CONTRIBUTING.md"), List(emptyValidation)), - mkValidation( - getChildPath(baseDirectory.value, "AUTHORS.md"), - List(requiredStrings(devListStrings(orgMaintainersSetting.value ++ orgContributorsSetting.value)))), - mkValidation( - getChildPath(baseDirectory.value, "LICENSE"), - List(requiredStrings(List(orgLicenseSetting.value.name))) - ), - mkValidation( - getChildPath(baseDirectory.value, "NOTICE.md"), - List(requiredStrings(List(orgProjectName.value, orgLicenseSetting.value.name))) - ), - mkValidation(getChildPath(baseDirectory.value, sbtorgpolicies.templates.versionFilePath), List(emptyValidation)), - mkValidation( - getChildPath(baseDirectory.value, ".travis.yml"), - List( - validTravisFile( - crossScalaVersions.value, - Seq(orgScriptCICommandKey), - Seq(orgAfterCISuccessCommandKey) - ) - ) - ) - ) - ) val orgFileValidationTasks = Seq( orgValidateFiles := Def.task { - onlyRootUnitTask(baseDirectory.value, (baseDirectory in LocalRootProject).value, streams.value.log) { - validationFilesTask(orgValidationListSetting.value, streams.value.log) + val baseDirFile: File = (baseDirectory in LocalRootProject).value + onlyRootUnitTask(baseDirectory.value, baseDirFile, streams.value.log) { + val files: List[FileType] = orgEnforcedFilesSetting.value + val validations: List[Validation] = files.flatMap { + case FileType(true, _, _, _, path, _, _, list) => + List(mkValidation((baseDirFile / path).getAbsolutePath, if (list.isEmpty) List(emptyValidation) else list)) + case _ => + Nil + } + validationFilesTask(validations, streams.value.log) } }.value ) - private[this] def readmeSections(name: String): List[String] = - List(s"$name in the wild") - - private[this] def devListStrings(list: List[Dev]): List[String] = - list.map(_.id) ++ list.flatMap(_.name) - private[this] def validationFilesTask(list: List[Validation], log: Logger): Unit = list foreach (validationFileTask(_, log)) diff --git a/src/main/scala/sbtorgpolicies/settings/files.scala b/src/main/scala/sbtorgpolicies/settings/files.scala index 5ec34bb..4ce664c 100644 --- a/src/main/scala/sbtorgpolicies/settings/files.scala +++ b/src/main/scala/sbtorgpolicies/settings/files.scala @@ -21,6 +21,7 @@ import sbt.Keys._ import sbt._ import sbtorgpolicies.OrgPoliciesKeys._ import sbtorgpolicies.github.GitHubOps +import sbtorgpolicies.io.ReplaceTextEngine.ProcessedFile import sbtorgpolicies.io._ import sbtorgpolicies.templates.FileType import sbtorgpolicies.templates.utils._ @@ -75,12 +76,18 @@ trait files { file.getName.indexOf('.') < 0 || file.getName.endsWith(".md") } - val replaced = replaceTextEngine.replaceBlocks( + val replaced: List[ProcessedFile] = replaceTextEngine.replaceBlocks( startBlockRegex, endBlockRegex, orgUpdateDocFilesReplacementsSetting.value, orgUpdateDocFilesSetting.value, - isFileSupported) + isFileSupported) match { + case Left(e) => + streams.value.log.error(s"Error updating policy files") + e.printStackTrace() + Nil + case Right(l) => l + } val errorFiles = replaced.filter(_.status.failure).map(_.file.getAbsolutePath) if (errorFiles.nonEmpty) { From 79ad7e39491183b0b794c26cfe9a2c19f00e171d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fede=20Fern=C3=A1ndez?= Date: Mon, 24 Apr 2017 18:22:06 +0200 Subject: [PATCH 2/3] fixes scripted tests --- .../sbtorgpolicies/ci-script/README.md | 5 ----- .../sbtorgpolicies/ci-script/build.sbt | 2 ++ .../sbtorgpolicies/valid-files/.scalafmt.conf | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) delete mode 100644 src/sbt-test/sbtorgpolicies/ci-script/README.md create mode 100644 src/sbt-test/sbtorgpolicies/valid-files/.scalafmt.conf diff --git a/src/sbt-test/sbtorgpolicies/ci-script/README.md b/src/sbt-test/sbtorgpolicies/ci-script/README.md deleted file mode 100644 index e1b04a9..0000000 --- a/src/sbt-test/sbtorgpolicies/ci-script/README.md +++ /dev/null @@ -1,5 +0,0 @@ -## README - -## sbt-org-policies in the wild - -If you wish to add your library here please consider a PR to include it in the list below. \ No newline at end of file diff --git a/src/sbt-test/sbtorgpolicies/ci-script/build.sbt b/src/sbt-test/sbtorgpolicies/ci-script/build.sbt index 08bb9de..77686a6 100644 --- a/src/sbt-test/sbtorgpolicies/ci-script/build.sbt +++ b/src/sbt-test/sbtorgpolicies/ci-script/build.sbt @@ -1,5 +1,7 @@ name := "sbt-org-policies" +version := "0.0.1" + scalaVersion := sbtorgpolicies.model.scalac.`2.12` libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test" diff --git a/src/sbt-test/sbtorgpolicies/valid-files/.scalafmt.conf b/src/sbt-test/sbtorgpolicies/valid-files/.scalafmt.conf new file mode 100644 index 0000000..a831a03 --- /dev/null +++ b/src/sbt-test/sbtorgpolicies/valid-files/.scalafmt.conf @@ -0,0 +1,22 @@ +style = defaultWithAlign +maxColumn = 120 + +continuationIndent.callSite = 2 + +newlines { + sometimesBeforeColonInMethodReturnType = false +} + +align { + arrowEnumeratorGenerator = false + ifWhileOpenParen = false + openParenCallSite = false + openParenDefnSite = false +} + +docstrings = JavaDoc + +rewrite { + rules = [SortImports, RedundantBraces] + redundantBraces.maxLines = 1 +} \ No newline at end of file From 8d87c3810b05d087eedde6e0453aad3d51e01296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fede=20Fern=C3=A1ndez?= Date: Mon, 24 Apr 2017 18:41:58 +0200 Subject: [PATCH 3/3] Release 0.4.15 version --- version.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.sbt b/version.sbt index 0c8cbbc..9212c47 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version in ThisBuild := "0.4.15-SNAPSHOT" \ No newline at end of file +version in ThisBuild := "0.4.15" \ No newline at end of file