#152 - Fix IoProperties.javaHome setter.

We now correctly set the javaHome variable instead of the workDir if the io.javaHome property is set.
Include the property in the template file and add the maven.parallelize=true flag as well.

Closes: #152
This commit is contained in:
Christoph Strobl
2020-10-15 08:28:51 +02:00
parent 18fb35c4cf
commit fca3466a42
3 changed files with 99 additions and 3 deletions

View File

@@ -5,8 +5,15 @@ git.email=
git.password=
github.api.url=https://api.github.com
# IO
# Optionally set the JavaHome path used for exeuting maven goals (eg. /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/)
# If the property does not exist, is empty or points to an invalid directory the OS default JavaHome will be used.
#io.javaHome=
# Maven
maven.mavenHome=
maven.parallelize=true
# Deployment
deployment.repository-prefix=

View File

@@ -22,10 +22,12 @@ import java.io.File;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
/**
* @author Oliver Gierke
* @author Mark Paluch
* @author Christoph Strobl
*/
@Slf4j
@Data
@@ -37,13 +39,26 @@ class IoProperties {
public void setWorkDir(String workDir) {
log.info(String.format("Using %s as working directory!", workDir));
log.info(String.format("🔧 Using %s as working directory!", workDir));
this.workDir = new File(workDir.replace("~", System.getProperty("user.home")));
}
public void setJavaHome(String javaHome) {
log.info(String.format("Using %s as Java home!", javaHome));
this.workDir = new File(javaHome.replace("~", System.getProperty("user.home")));
if (!StringUtils.hasText(javaHome)) {
return;
}
File javaHomeDir = new File(javaHome.replace("~", System.getProperty("user.home")));
if (!javaHomeDir.isDirectory()) {
log.warn(String.format(
"⚠️️ Property 'io.javaHome' does not point to a vaild directory ('%s')! Falling back to os.default.",
javaHomeDir.getPath()));
return;
}
log.info(String.format("🔧 Setting javaHome to: '%s'.", javaHomeDir.getPath()));
this.javaHome = javaHomeDir;
}
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright 2020 the original author or authors.
*
* 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
*
* https://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 org.springframework.data.release.io;
import static org.assertj.core.api.Assertions.*;
import java.io.File;
import java.io.IOException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
/**
* @author Christoph Strobl
*/
public class IoPropertiesUnitTests {
@TempDir File tempDir;
IoProperties properties;
@BeforeEach
void beforeEach() {
properties = new IoProperties();
}
@Test // GH-152
void setJavaHomeToDir() {
properties.setJavaHome(tempDir.getPath());
assertThat(properties.getJavaHome()).isNotNull().isDirectory();
}
@Test // GH-152
void setJavaHomeIgnoresEmptyString() {
properties.setJavaHome("");
assertThat(properties.getJavaHome()).isNull();
}
@Test // GH-152
void setJavaHomeIgnoresFile() throws IOException {
File f = new File(tempDir, "java.txt");
f.createNewFile();
properties.setJavaHome(f.getPath());
assertThat(properties.getJavaHome()).isNull();
}
@Test // GH-152
void setJavaHomeIgnoresDirectoryThatDoesNotExist() throws IOException {
properties.setJavaHome(new File(tempDir, "java-bin").getPath());
assertThat(properties.getJavaHome()).isNull();
}
}