Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test failures when build under Windows #834

Merged
merged 4 commits into from
Aug 8, 2017

Conversation

akuhtz
Copy link
Contributor

@akuhtz akuhtz commented Aug 3, 2017

Fix test failures when build under Windows.
The validation of the Windows filename is copied from stackoverflow: https://stackoverflow.com/a/6804755

@codecov
Copy link

codecov bot commented Aug 3, 2017

Codecov Report

Merging #834 into master will increase coverage by 0.03%.
The diff coverage is 71.42%.

@@             Coverage Diff              @@
##             master     #834      +/-   ##
============================================
+ Coverage      47.6%   47.63%   +0.03%     
- Complexity     1072     1074       +2     
============================================
  Files           134      134              
  Lines          6936     6942       +6     
  Branches        913      914       +1     
============================================
+ Hits           3302     3307       +5     
  Misses         3350     3350              
- Partials        284      285       +1
Impacted Files Coverage Δ Complexity Δ
...8/maven/docker/config/BuildImageConfiguration.java 81.7% <0%> (-1.01%) 45 <0> (ø)
...ain/java/io/fabric8/maven/docker/util/EnvUtil.java 66.89% <100%> (+1.61%) 43 <1> (+2) ⬆️
...a/io/fabric8/maven/docker/util/DockerFileUtil.java 77.55% <100%> (ø) 13 <0> (ø) ⬇️

Copy link
Collaborator

@rhuss rhuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, looks good.

Some minor changes would be awesome + a unit test.

@@ -501,7 +501,7 @@ private File findDockerFileFile(Logger log) {
if (dockerFileDir == null) {
return dFile;
} else {
if (dFile.isAbsolute()) {
if (dFile.isAbsolute() || !EnvUtil.isValidWindowsFileName(dockerFile)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add this as an extra check with an extra error message for the invalide windows file name case ? Otherwise its confusing when the exception message does not fit to the error.


public static boolean isValidWindowsFileName(String text) {

if (!isWindows()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the windows checks outside this method (e.g. where it is called) as otherwise the semantics of this check is confusing (e.g. returning different return values depending on the same argument, depending on on which OS the method is called)

return true;
}

Pattern pattern = Pattern.compile(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a reference to the SO answer as comment above ?

@@ -392,4 +392,32 @@ public static Date loadTimestamp(File tsFile) throws MojoExecutionException {
public static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("windows");
}

public static boolean isValidWindowsFileName(String text) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some unit tests for this methods would be awesome (shouldn't be hard to build)

Copy link
Collaborator

@rhuss rhuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, LGTM, except one minor issue.

@@ -504,6 +504,9 @@ private File findDockerFileFile(Logger log) {
if (dFile.isAbsolute()) {
throw new IllegalArgumentException("<dockerFile> can not be absolute path if <dockerFileDir> also set.");
}
if (EnvUtil.isWindows() && !EnvUtil.isValidWindowsFileName(dockerFile)) {
throw new IllegalArgumentException("<dockerFile> can not be absolute path if <dockerFileDir> also set.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be something like

throw new IllegalArgumentException(String.format("Invalid windows file name %s for dockerFile", dockerFile))

@rhuss
Copy link
Collaborator

rhuss commented Aug 8, 2017

Thanks !

@rhuss rhuss merged commit d0aa142 into fabric8io:master Aug 8, 2017
@akuhtz akuhtz deleted the test-failure-windows branch August 8, 2017 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants