-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRYness: consolidate duplicated code
I've added a dependency on devtools-common from all of the extension build plugins, so that I can eliminate duplicated code I introduced in the last changeset. The implementation is just copied across from the duplicated versions. I rewrote the test to use webcompere system stubs, for more control and more consistent behaviour. (And avoiding irritating CI-only failures.) I left bootstrap out of the changeset to avoid a circular dependency. Since I removed the changes to the bootstrap bom, which is the parent of the extension-maven-plugin, so I need to set the version manually for that plugin.
- Loading branch information
1 parent
45db96a
commit dafa8d2
Showing
10 changed files
with
95 additions
and
51 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
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
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
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
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
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
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
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
24 changes: 24 additions & 0 deletions
24
...devtools-common/src/main/java/io/quarkus/devtools/project/extensions/ScmInfoProvider.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,24 @@ | ||
package io.quarkus.devtools.project.extensions; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ScmInfoProvider { | ||
|
||
public static Map<String, String> getSourceRepo() { | ||
// We could try and parse the .git/config file, but that will be fragile | ||
// Let's assume we only care about the repo for official-ish builds produced via github actions | ||
String repo = System.getenv("GITHUB_REPOSITORY"); | ||
if (repo != null) { | ||
Map info = new HashMap(); | ||
String qualifiedRepo = "https://github.com/" + repo; | ||
// Don't try and guess where slashes will be, just deal with any double slashes by brute force | ||
qualifiedRepo = qualifiedRepo.replace("github.com//", "github.com/"); | ||
|
||
info.put("url", qualifiedRepo); | ||
return info; | ||
} | ||
return null; | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...ools-common/src/test/java/io/quarkus/devtools/project/extensions/ScmInfoProviderTest.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,44 @@ | ||
package io.quarkus.devtools.project.extensions; | ||
|
||
import static io.quarkus.devtools.project.extensions.ScmInfoProvider.getSourceRepo; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; | ||
import uk.org.webcompere.systemstubs.jupiter.SystemStub; | ||
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; | ||
|
||
@ExtendWith(SystemStubsExtension.class) | ||
public class ScmInfoProviderTest { | ||
|
||
@SystemStub | ||
private EnvironmentVariables environment; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
environment.set("GITHUB_REPOSITORY", null); | ||
} | ||
|
||
@Test | ||
public void shouldReturnNullWhenNoEnvironmentOrBuildConfigIsPresent() { | ||
Map scm = getSourceRepo(); | ||
// We shouldn't throw an exception or get upset, we should just quietly return null | ||
assertNull(scm); | ||
} | ||
|
||
@Test | ||
void testGetSourceControlCoordinates() { | ||
String repoName = "org/place"; | ||
environment.set("GITHUB_REPOSITORY", repoName); | ||
Map repo = getSourceRepo(); | ||
assertNotNull(repo); | ||
assertEquals(repo.get("url").toString(), "https://github.com/org/place"); | ||
} | ||
} |