From 574c35ac2d5ce0326aed663436a5be1751dcf3d0 Mon Sep 17 00:00:00 2001 From: James Carnegie Date: Thu, 9 Feb 2017 18:03:54 +0000 Subject: [PATCH] Don't duplicate implicit parameters in calling editor/generator #258 --- CHANGELOG.md | 11 ++++- .../atomist/param/ParameterizedSupport.scala | 11 +++-- .../ProjectOperationArchiveReaderTest.scala | 41 +++++++++++++++++++ 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0080489b3..80ecde4bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,11 +17,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added `ScalaFileType` backed by ScalaMeta + +### Fixed + - Fix: Elm parser failed on files with two multiline comments - https://github.com/atomist/rug/issues/268 + https://github.com/atomist/rug/issues/268 - Raise an `InvalidRugTestScenarioName` when a Rug test scenario is missing a name #71 - + +- Implicit DLS parameters (from `uses`) are no longer duplicate if multiple + editors declare the same parameter. The first one is chosen. + https://github.com/atomist/rug/issues/258 + ### Changed - Upgrade TS compiler to 2.1.5 diff --git a/src/main/scala/com/atomist/param/ParameterizedSupport.scala b/src/main/scala/com/atomist/param/ParameterizedSupport.scala index 1f66b1b21..7ed0df513 100644 --- a/src/main/scala/com/atomist/param/ParameterizedSupport.scala +++ b/src/main/scala/com/atomist/param/ParameterizedSupport.scala @@ -11,9 +11,12 @@ trait ParameterizedSupport extends Parameterized { override final def parameters: Seq[Parameter] = params.filterNot(_ == null) - protected def addParameter(tp: Parameter): Unit = - params += tp + protected def addParameter(tp: Parameter): Unit = { + if(!params.exists(p => tp.name == p.name)){ + params += tp + } + } + + protected def addParameters(tps: Seq[Parameter]): Unit = tps.foreach(p => addParameter(p)) - protected def addParameters(tps: Seq[Parameter]): Unit = - params ++= tps } diff --git a/src/test/scala/com/atomist/project/archive/ProjectOperationArchiveReaderTest.scala b/src/test/scala/com/atomist/project/archive/ProjectOperationArchiveReaderTest.scala index d01bb239c..417177f8d 100644 --- a/src/test/scala/com/atomist/project/archive/ProjectOperationArchiveReaderTest.scala +++ b/src/test/scala/com/atomist/project/archive/ProjectOperationArchiveReaderTest.scala @@ -41,6 +41,7 @@ class ProjectOperationArchiveReaderTest extends FlatSpec with Matchers { """.stripMargin ) + val EditorWithImports = StringFileArtifact(atomistConfig.editorsRoot + "/EditorWithImports.rug", """ |editor EditorWithImports @@ -52,6 +53,46 @@ class ProjectOperationArchiveReaderTest extends FlatSpec with Matchers { """.stripMargin ) + val EditorWithProjectName = StringFileArtifact(atomistConfig.editorsRoot + "/Stuff.rug", + """ + |editor Stuff + | + |param project_name: ^.*$ + | + |with File f do setPath "" + """.stripMargin + ) + + val AnotherEditorWithProjectName = StringFileArtifact(atomistConfig.editorsRoot + "/MoreStuff.rug", + """ + |editor MoreStuff + | + |param project_name: ^.*$ + | + |with File f do setPath "" + """.stripMargin + ) + + val GeneratorWithoutProjectName = StringFileArtifact(atomistConfig.editorsRoot + "/Published.rug", + """ + |generator Published + | + |uses Stuff + |uses MoreStuff + | + |Stuff + |MoreStuff + """.stripMargin + ) + + //https://github.com/atomist/rug/issues/258 + it should "only describe a single project_name parameter if it's declared" in { + val apc = new ProjectOperationArchiveReader(atomistConfig) + val ops = apc.findOperations(new SimpleFileBasedArtifactSource("", Seq(GeneratorWithoutProjectName, EditorWithProjectName, AnotherEditorWithProjectName)), None, Nil) + assert(ops.generators.size === 1) + assert(ops.generators.head.parameters.size === 1) + } + it should "parse single editor" in { val apc = new ProjectOperationArchiveReader(atomistConfig) val ops = apc.findOperations(new SimpleFileBasedArtifactSource("", FirstEditor), None, Nil)