<commit_before>/*
 * Copyright (C) 2016-2017 Lightbend Inc. <https://www.lightbend.com>
 */
package com.lightbend.lagom.maven

import java.io.File
import javax.inject.{ Inject, Singleton }

import com.lightbend.lagom.core.LagomVersion
import com.lightbend.lagom.dev.PortAssigner.{ Port, PortRange, ProjectName }
import com.lightbend.lagom.dev.Reloader.{ CompileFailure, CompileResult, CompileSuccess, DevServer }
import com.lightbend.lagom.dev.{ LagomConfig, PortAssigner, Reloader }
import org.apache.maven.Maven
import org.apache.maven.artifact.ArtifactUtils
import org.apache.maven.execution.MavenSession
import org.apache.maven.project.MavenProject
import org.eclipse.aether.artifact.{ Artifact, DefaultArtifact }
import org.eclipse.aether.graph.Dependency
import play.api.PlayException
import play.dev.filewatch.FileWatchService

import scala.collection.JavaConverters._
import scala.util.control.NonFatal

/**
 * Manages services
 */
@Singleton
class ServiceManager @Inject() (logger: MavenLoggerProxy, session: MavenSession, facade: MavenFacade,
                                scalaClassLoaderManager: ScalaClassLoaderManager) {

  private var runningServices = Map.empty[MavenProject, DevServer]
  private var runningExternalProjects = Map.empty[Dependency, DevServer]
  private var portMap: Option[Map[ProjectName, Port]] = None

  private def detectScalaBinaryVersion(artifacts: Seq[Artifact]) = {
    artifacts.collectFirst {
      case scala if scala.getGroupId == "org.scala-lang" && scala.getArtifactId == "scala-library" =>
        ServiceManager.scalaBinaryVersion(scala.getVersion)
    } getOrElse ServiceManager.DefaultScalaBinaryVersion
  }

  private def devModeDependencies(scalaBinaryVersion: String, artifacts: Seq[String]) = artifacts.map { dep =>
    new Dependency(new DefaultArtifact(s"com.lightbend.lagom:${dep}_$scalaBinaryVersion:${LagomVersion.current}"), "runtime")
  }

  private def calculateDevModeDependencies(scalaBinaryVersion: String, playService: Boolean,
                                           serviceLocatorUrl: Option[String], cassandraPort: Option[Int]): Seq[Dependency] = {
    if (playService) {
      devModeDependencies(scalaBinaryVersion, Seq("lagom-play-integration", "lagom-reloadable-server"))
    } else {
      devModeDependencies(
        scalaBinaryVersion,
        Seq("lagom-reloadable-server") ++<commit_msg>Ensure maven plugin adds right dependency for Play integration (#684)<commit_after>/*
 * Copyright (C) 2016-2017 Lightbend Inc. <https://www.lightbend.com>
 */
package com.lightbend.lagom.maven

import java.io.File
import javax.inject.{ Inject, Singleton }

import com.lightbend.lagom.core.LagomVersion
import com.lightbend.lagom.dev.PortAssigner.{ Port, PortRange, ProjectName }
import com.lightbend.lagom.dev.Reloader.{ CompileFailure, CompileResult, CompileSuccess, DevServer }
import com.lightbend.lagom.dev.{ LagomConfig, PortAssigner, Reloader }
import org.apache.maven.Maven
import org.apache.maven.artifact.ArtifactUtils
import org.apache.maven.execution.MavenSession
import org.apache.maven.project.MavenProject
import org.eclipse.aether.artifact.{ Artifact, DefaultArtifact }
import org.eclipse.aether.graph.Dependency
import play.api.PlayException
import play.dev.filewatch.FileWatchService

import scala.collection.JavaConverters._
import scala.util.control.NonFatal

/**
 * Manages services
 */
@Singleton
class ServiceManager @Inject() (logger: MavenLoggerProxy, session: MavenSession, facade: MavenFacade,
                                scalaClassLoaderManager: ScalaClassLoaderManager) {

  private var runningServices = Map.empty[MavenProject, DevServer]
  private var runningExternalProjects = Map.empty[Dependency, DevServer]
  private var portMap: Option[Map[ProjectName, Port]] = None

  private def detectScalaBinaryVersion(artifacts: Seq[Artifact]) = {
    artifacts.collectFirst {
      case scala if scala.getGroupId == "org.scala-lang" && scala.getArtifactId == "scala-library" =>
        ServiceManager.scalaBinaryVersion(scala.getVersion)
    } getOrElse ServiceManager.DefaultScalaBinaryVersion
  }

  private def devModeDependencies(scalaBinaryVersion: String, artifacts: Seq[String]) = artifacts.map { dep =>
    new Dependency(new DefaultArtifact(s"com.lightbend.lagom:${dep}_$scalaBinaryVersion:${LagomVersion.current}"), "runtime")
  }

  private def calculateDevModeDependencies(scalaBinaryVersion: String, playService: Boolean,
                                           serviceLocatorUrl: Option[String], cassandraPort: Option[Int]): Seq[Dependency] = {
    if (playService) {
      devModeDependencies(scalaBinaryVersion, Seq("lagom-javadsl-play-integration", "lagom-reloadable-server"))
    } else {
      devModeDependencies(
        scalaBinaryVersion,
        Seq("lagom-reloadable-server") ++
{'fraction_non_alphanumeric': 0.10399334442595674, 'fraction_numerical': 0.003951747088186356, 'mean_word_length': 4.6643109540636045, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7062369', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1391, 'n_words': 273}