You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "jtjeferreira (via GitHub)" <gi...@apache.org> on 2023/05/03 14:40:59 UTC

[GitHub] [incubator-pekko-connectors] jtjeferreira commented on issue #23: follow up with maintainers of externally maintained alpakka connectors

jtjeferreira commented on issue #23:
URL: https://github.com/apache/incubator-pekko-connectors/issues/23#issuecomment-1533149546

   I have used the following code to use source generators and search/replace on the imports to publish the same library for akka and pekko:
   
   ```scala
   import sbt._
   
   object PekkoMigration {
     def generatePekkoSourcesFromAkka(scalaSourceDirectory: File, sourceManagedDir: File): Seq[File] = {
       val scalaFiles: PathFinder = scalaSourceDirectory ** "*.scala"
       //collect the files
       val filesToBeCopied: Seq[(File, File)] = scalaFiles.get().map { f =>
         val Some(relative) = scalaSourceDirectory.relativize(f)
         val target: File = sourceManagedDir / relative.toPath.toString
         (f, target)
       }
       //copy the files
       val copiedFiles = IO.copy(filesToBeCopied).toSeq
       //rewrite imports
       copiedFiles.map { f =>
         val modifiedLines = IO.readLines(f).map {
           case l if l.startsWith("import akka.stream.alpakka") =>
             l.replaceFirst("import akka.stream.alpakka", "import org.apache.pekko.stream.connectors")
           case l if l.startsWith("import akka") =>
             l.replaceFirst("import akka", "import org.apache.pekko")
           case l => l
         }
         IO.writeLines(f, modifiedLines)
         f
       }
     }
   }
   ```
   
   and then you can use it like this
   
   ```scala
       Compile / sourceGenerators += Def.task {
         PekkoMigration.generatePekkoSourcesFromAkka((AKKA_PROJECT / Compile / scalaSource).value, (Compile / sourceManaged).value)
       }.taskValue
   ``` 
   
   
   It is not very fancy (i.e it does not use scalafix) but gets the job done for small libs


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org