/** * Determine the spring-boot devtools version for the current project */ public static Optional<String> getSpringBootDevToolsVersion(MavenProject mavenProject) { return getSpringBootVersion(mavenProject); }
private void ensureSpringDevToolSecretToken() throws MojoExecutionException { Properties properties = SpringBootUtil.getSpringBootApplicationProperties(MavenUtil.getCompileClassLoader(getProject())); String remoteSecret = properties.getProperty(DEV_TOOLS_REMOTE_SECRET); if (Strings.isNullOrEmpty(remoteSecret)) { addSecretTokenToApplicationProperties(); throw new MojoExecutionException("No spring.devtools.remote.secret found in application.properties. Plugin has added it, please re-run goals"); } }
/** * Returns the spring boot configuration (supports `application.properties` and `application.yml`) * or an empty properties object if not found */ public static Properties getSpringBootApplicationProperties(URLClassLoader compileClassLoader) { URL ymlResource = compileClassLoader.findResource("application.yml"); URL propertiesResource = compileClassLoader.findResource("application.properties"); Properties props = YamlUtil.getPropertiesFromYamlResource(ymlResource); props.putAll(getPropertiesResource(propertiesResource)); return props; }
@Override protected List<String> extractPorts() { List<String> answer = new ArrayList<>(); Properties properties = SpringBootUtil.getSpringBootApplicationProperties(MavenUtil.getCompileClassLoader(this.getProject())); SpringBootConfigurationHelper propertyHelper = new SpringBootConfigurationHelper(SpringBootUtil.getSpringBootVersion(getProject())); String port = properties.getProperty(propertyHelper.getServerPortPropertyKey(), DEFAULT_SERVER_PORT); addPortIfValid(answer, getConfig(JavaExecGenerator.Config.webPort, port)); addPortIfValid(answer, getConfig(JavaExecGenerator.Config.jolokiaPort)); addPortIfValid(answer, getConfig(JavaExecGenerator.Config.prometheusPort)); return answer; }
private File getSpringBootDevToolsJar(MavenProject project) throws IOException { String version = SpringBootUtil.getSpringBootDevToolsVersion(project).orElseThrow(() -> new IllegalStateException("Unable to find the spring-boot version")); return getContext().getFabric8ServiceHub().getArtifactResolverService().resolveArtifact(SpringBootConfigurationHelper.SPRING_BOOT_GROUP_ID, SpringBootConfigurationHelper.SPRING_BOOT_DEVTOOLS_ARTIFACT_ID, version, "jar"); }
private String getPortForwardUrl(final Set<HasMetadata> resources) throws Exception { LabelSelector selector = KubernetesResourceUtil.getPodLabelSelector(resources); if (selector == null) { log.warn("Unable to determine a selector for application pods"); return null; } Properties properties = SpringBootUtil.getSpringBootApplicationProperties(MavenUtil.getCompileClassLoader(getContext().getProject())); SpringBootConfigurationHelper propertyHelper = new SpringBootConfigurationHelper(SpringBootUtil.getSpringBootVersion(getContext().getProject())); int port = IoUtil.getFreeRandomPort(); int containerPort = propertyHelper.getServerPort(properties); portForwardService.forwardPortAsync(getContext().getLogger(), selector, containerPort, port); return createForwardUrl(propertyHelper, properties, port); }
private File getSpringBootDevToolsJar() throws IOException { String version = SpringBootUtil.getSpringBootDevToolsVersion(getProject()).orElseThrow(() -> new IllegalStateException("Unable to find the spring-boot version")); return getContext().getArtifactResolver().resolveArtifact(SpringBootConfigurationHelper.SPRING_BOOT_GROUP_ID, SpringBootConfigurationHelper.SPRING_BOOT_DEVTOOLS_ARTIFACT_ID, version, "jar"); }
private String validateSpringBootDevtoolsSettings() throws IllegalStateException { String configuration = MavenUtil.getPlugin(getContext().getProject(), null, SpringBootConfigurationHelper.SPRING_BOOT_MAVEN_PLUGIN_ARTIFACT_ID).getConfiguration().toString(); if(!configuration.contains("<excludeDevtools>false</excludeDevtools>")) { log.warn("devtools need to be included in repacked archive, please set <excludeDevtools> to false in plugin configuration"); throw new IllegalStateException("devtools needs to be included in fat jar"); } Properties properties = SpringBootUtil.getSpringBootApplicationProperties(MavenUtil.getCompileClassLoader(getContext().getProject())); String remoteSecret = properties.getProperty(DEV_TOOLS_REMOTE_SECRET, System.getProperty(DEV_TOOLS_REMOTE_SECRET)); if (StringUtils.isBlank(remoteSecret)) { log.warn("There is no `%s` property defined in your src/main/resources/application.properties. Please add one!", DEV_TOOLS_REMOTE_SECRET); throw new IllegalStateException("No " + DEV_TOOLS_REMOTE_SECRET + " property defined in application.properties or system properties"); } return properties.getProperty(DEV_TOOLS_REMOTE_SECRET); }
protected Probe buildProbe(Properties springBootProperties, Integer initialDelay, Integer period, Integer timeout) { SpringBootConfigurationHelper propertyHelper = new SpringBootConfigurationHelper(SpringBootUtil.getSpringBootVersion(getContext().getProject())); Integer managementPort = PropertiesHelper.getInteger(springBootProperties, propertyHelper.getManagementPortPropertyKey()); boolean usingManagementPort = managementPort != null;
@Override protected Map<String, String> getEnv(boolean prePackagePhase) throws MojoExecutionException { Map<String, String> res = super.getEnv(prePackagePhase); if (getContext().getGeneratorMode() == GeneratorMode.WATCH) { // adding dev tools token to env variables to prevent override during recompile String secret = SpringBootUtil.getSpringBootApplicationProperties(MavenUtil.getCompileClassLoader(getProject())).getProperty(SpringBootConfigurationHelper.DEV_TOOLS_REMOTE_SECRET); if (secret != null) { res.put(SpringBootConfigurationHelper.DEV_TOOLS_REMOTE_SECRET_ENV, secret); } } return res; }
protected Probe discoverSpringBootHealthCheck(Integer initialDelay, Integer period, Integer timeout) { try { if (MavenUtil.hasAllClasses(this.getProject(), REQUIRED_CLASSES)) { Properties properties = SpringBootUtil.getSpringBootApplicationProperties(this.getProject()); return buildProbe(properties, initialDelay, period, timeout); } } catch (Exception ex) { log.error("Error while reading the spring-boot configuration", ex); } return null; }
protected Probe discoverSpringBootHealthCheck(Integer initialDelay, Integer period, Integer timeout, Integer failureTh, Integer successTh) { try { if (getContext().getProjectClassLoaders().isClassInCompileClasspath(true, REQUIRED_CLASSES)) { Properties properties = SpringBootUtil.getSpringBootApplicationProperties(getContext().getProjectClassLoaders().getCompileClassLoader()); return buildProbe(properties, initialDelay, period, timeout, failureTh, successTh); } } catch (Exception ex) { log.error("Error while reading the spring-boot configuration", ex); } return null; }