Skip to content

Commit

Permalink
Merge pull request #28 from alejandrohdezma/remove-scalaj
Browse files Browse the repository at this point in the history
Remove dependency on `scalaj-http`
  • Loading branch information
alejandrohdezma authored Feb 15, 2020
2 parents 16ec9bd + 0267e7c commit 82010bd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
1 change: 0 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ lazy val `sbt-fix` = project
.enablePlugins(SbtPlugin)
.settings(addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.11"))
.settings(addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.1"))
.settings(libraryDependencies += "org.scalaj" %% "scalaj-http" % "2.4.2")

lazy val `sbt-fix-it` = project
.settings(description := "Enables scalafix/scalafmt settings in it configuration")
Expand Down
2 changes: 0 additions & 2 deletions project/dependencies.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
libraryDependencies += "org.scalaj" %% "scalaj-http" % "2.4.2"

// For using the plugins in their own build
unmanagedSourceDirectories in Compile +=
baseDirectory.in(ThisBuild).value.getParentFile / "sbt-fix" / "src" / "main" / "scala"
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2019-2020 Alejandro Hernández <https://github.com/alejandrohdezma>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alejandrohdezma.sbt.fix.http

import java.net.{HttpURLConnection, URL}
import java.util.concurrent.ConcurrentHashMap

import scala.io.Source

object client {

/** Calls the provided URL and returns its contents as `String` */
@SuppressWarnings(Array("all"))
def get(uri: String): String = cache.computeIfAbsent(
uri, { _ =>
val url = new URL(uri)

val connection = url.openConnection.asInstanceOf[HttpURLConnection]

connection.setInstanceFollowRedirects(true)

val inputStream = connection.getInputStream

Source.fromInputStream(inputStream, "UTF-8").mkString
}
)

private val cache: ConcurrentHashMap[String, String] = new ConcurrentHashMap[String, String]()

}
12 changes: 3 additions & 9 deletions sbt-fix/src/main/scala/com/alejandrohdezma/sbt/fix/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ package com.alejandrohdezma.sbt
import sbt._
import sbt.io.IO

import scalaj.http.Http
import scalaj.http.HttpOptions.followRedirects

package object fix {

/** Extracts from the state the list of configurations with the scalafix task */
Expand Down Expand Up @@ -51,12 +48,9 @@ package object fix {
|# not be edited nor added to source control systems.
|# Extra configurations can be added to ${including.name}""".stripMargin

lazy val localContent = IO.read(to)
lazy val extraContent = IO.read(including)
lazy val remoteContent = header + "\n\n" + Http(from)
.option(followRedirects(true))
.asString
.body
lazy val localContent = IO.read(to)
lazy val extraContent = IO.read(including)
lazy val remoteContent = header + "\n\n" + http.client.get(from)

lazy val download = log(s"Downloading $to from $from ...") IO.write(to, remoteContent)
lazy val includeExtra = log(s"Appending $including ...") IO.append(to, s"\n\n$extraContent")
Expand Down

0 comments on commit 82010bd

Please sign in to comment.