-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: detect project folder for gradle kotlin projects (#19614)
Fixes #18682
- Loading branch information
1 parent
e457c62
commit f5379da
Showing
2 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
flow-server/src/test/java/com/vaadin/flow/server/AbstractConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* 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 | ||
* | ||
* http://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 com.vaadin.flow.server; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
public class AbstractConfigurationTest { | ||
|
||
@Rule | ||
public TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
||
AbstractConfiguration configuration = new AbstractConfiguration() { | ||
@Override | ||
public boolean isProductionMode() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getStringProperty(String name, String defaultValue) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean getBooleanProperty(String name, boolean defaultValue) { | ||
return false; | ||
} | ||
}; | ||
|
||
@Test | ||
public void getProjectFolder_mavenProject_detected() throws IOException { | ||
assertProjectFolderDetected("pom.xml"); | ||
} | ||
|
||
@Test | ||
public void getProjectFolder_gradleProject_detected() throws IOException { | ||
assertProjectFolderDetected("build.gradle"); | ||
} | ||
|
||
@Test | ||
public void getProjectFolder_gradleKotlinProject_detected() | ||
throws IOException { | ||
assertProjectFolderDetected("build.gradle.kts"); | ||
} | ||
|
||
@Test | ||
public void getProjectFolder_unknownProject_throws() throws IOException { | ||
withTemporaryUserDir(() -> { | ||
IllegalStateException exception = Assert.assertThrows( | ||
IllegalStateException.class, | ||
configuration::getProjectFolder); | ||
Assert.assertTrue(exception.getMessage().contains( | ||
"Failed to determine project directory for dev mode")); | ||
Assert.assertTrue(exception.getMessage() | ||
.contains(temporaryFolder.getRoot().getAbsolutePath())); | ||
}); | ||
} | ||
|
||
private void assertProjectFolderDetected(String projectFile) | ||
throws IOException { | ||
temporaryFolder.newFile(projectFile); | ||
withTemporaryUserDir(() -> { | ||
File projectFolder = configuration.getProjectFolder(); | ||
Assert.assertEquals(temporaryFolder.getRoot(), projectFolder); | ||
}); | ||
} | ||
|
||
private void withTemporaryUserDir(Runnable test) throws IOException { | ||
String userDir = System.getProperty("user.dir"); | ||
try { | ||
System.setProperty("user.dir", | ||
temporaryFolder.getRoot().getAbsolutePath()); | ||
test.run(); | ||
} finally { | ||
if (userDir != null) { | ||
System.setProperty("user.dir", userDir); | ||
} else { | ||
System.clearProperty("user.dir"); | ||
} | ||
} | ||
} | ||
|
||
} |