All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.akhikhl.gretty.SpringBootLauncher.groovy Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
/*
 * Gretty
 *
 * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors.
 *
 * See the file "LICENSE" for copying and usage permission.
 * See the file "CONTRIBUTORS" for complete list of contributors.
 */
package org.akhikhl.gretty

import groovy.text.GStringTemplateEngine
import org.gradle.api.Project
import org.slf4j.Logger
import org.slf4j.LoggerFactory

/**
 *
 * @author akhikhl
 */
class SpringBootLauncher extends DefaultLauncher {

  protected static final Logger log = LoggerFactory.getLogger(SpringBootLauncher)

  SpringBootLauncher(Project project, LauncherConfig config) {
    super(project, config)
  }

  @Override
  protected Collection getRunnerClassPath() {
    def servletContainerConfig = getServletContainerConfig()
    def files = project.configurations.grettyNoSpringBoot.files +
      project.configurations[servletContainerConfig.servletContainerRunnerConfig].files
    if(servletContainerConfig.servletContainerType == 'jetty')
      files += project.configurations.grettyRunnerSpringBootJetty.files
    else if(servletContainerConfig.servletContainerType == 'tomcat')
      files += project.configurations.grettyRunnerSpringBootTomcat.files
    def classPath = files.collect { it.toURL() } as LinkedHashSet
    def classPathResolver = config.getWebAppClassPathResolver()
    if(classPathResolver)
      for(def wconfig in webAppConfigs)
        if(wconfig.projectPath && ProjectUtils.isSpringBootApp(project, wconfig)) {
          def cp = classPathResolver.resolveWebAppClassPath(wconfig)
          if(cp)
            classPath += cp
        }
    classPath
  }

  @Override
  protected String getServerManagerFactory() {
    'org.akhikhl.gretty.SpringBootServerManagerFactory'
  }

  protected String getSpringBootMainClass() {
    sconfig.springBootMainClass ?:
    SpringBootMainClassFinder.findMainClass(project) ?:
    webAppConfigs.findResult { it.projectPath ? SpringBootMainClassFinder.findMainClass(project.project(it.projectPath)) : null }
  }

  @Override
  protected void writeRunConfigJson(json) {
    super.writeRunConfigJson(json)
    json.with {
      springBootMainClass getSpringBootMainClass()
    }
  }

  protected void writeWebAppClassPath(json, WebAppConfig webAppConfig) {
    if(ProjectUtils.isSpringBootApp(project, webAppConfig)) {
      json.springBoot true
      return // webapp classpath is passed directly to the runner
    }
    super.writeWebAppClassPath(json, webAppConfig)
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy