-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
index.html (welcome page) now dynamic
Signed-off-by: Phillip Kruger <phillip.kruger@gmail.com>
- Loading branch information
1 parent
419ed1a
commit e919139
Showing
17 changed files
with
560 additions
and
386 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
18 changes: 18 additions & 0 deletions
18
...-http/deployment/src/main/java/io/quarkus/devui/deployment/welcome/SelectedExtension.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,18 @@ | ||
package io.quarkus.devui.deployment.welcome; | ||
|
||
import java.net.URL; | ||
|
||
public class SelectedExtension { | ||
public String name; | ||
public String description; | ||
public URL guide; | ||
|
||
public SelectedExtension() { | ||
} | ||
|
||
public SelectedExtension(String name, String description, URL guide) { | ||
this.name = name; | ||
this.guide = guide; | ||
this.description = description; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/welcome/WelcomeData.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,18 @@ | ||
package io.quarkus.devui.deployment.welcome; | ||
|
||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class WelcomeData { | ||
|
||
public String configFile; | ||
public String resourcesDir; | ||
public String sourceDir; | ||
public List<SelectedExtension> selectedExtensions = new ArrayList<>(); | ||
|
||
public void addSelectedExtension(String name, String description, URL guide) { | ||
selectedExtensions.add(new SelectedExtension(name, description, guide)); | ||
} | ||
|
||
} |
148 changes: 148 additions & 0 deletions
148
...x-http/deployment/src/main/java/io/quarkus/devui/deployment/welcome/WelcomeProcessor.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,148 @@ | ||
package io.quarkus.devui.deployment.welcome; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import io.quarkus.bootstrap.workspace.SourceDir; | ||
import io.quarkus.bootstrap.workspace.WorkspaceModule; | ||
import io.quarkus.deployment.IsDevelopment; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; | ||
import io.quarkus.devui.deployment.ExtensionsBuildItem; | ||
import io.quarkus.devui.deployment.InternalPageBuildItem; | ||
import io.quarkus.devui.deployment.extension.Extension; | ||
import io.quarkus.devui.spi.page.Page; | ||
|
||
/** | ||
* This creates Welcome page | ||
*/ | ||
public class WelcomeProcessor { | ||
|
||
@BuildStep(onlyIf = IsDevelopment.class) | ||
InternalPageBuildItem createWelcomePages(CurateOutcomeBuildItem curateOutcomeBuildItem, | ||
ExtensionsBuildItem extensionsBuildItem) { | ||
|
||
InternalPageBuildItem welcomePageBuildItem = new InternalPageBuildItem("Welcome", -1); | ||
|
||
welcomePageBuildItem.addBuildTimeData("welcomeData", createWelcomeData(curateOutcomeBuildItem, extensionsBuildItem)); | ||
|
||
welcomePageBuildItem.addPage(Page.webComponentPageBuilder() | ||
.namespace("devui-welcome") | ||
.title("Welcome") | ||
.icon("font-awesome-brands:redhat") | ||
.componentLink("qwc-welcome.js") | ||
.excludeFromMenu()); | ||
|
||
return welcomePageBuildItem; | ||
} | ||
|
||
private WelcomeData createWelcomeData(CurateOutcomeBuildItem curateOutcomeBuildItem, | ||
ExtensionsBuildItem extensionsBuildItem) { | ||
|
||
WorkspaceModule workspaceModule = curateOutcomeBuildItem.getApplicationModel().getApplicationModule(); | ||
|
||
WelcomeData welcomeData = new WelcomeData(); | ||
welcomeData.configFile = getConfigFile(workspaceModule); | ||
welcomeData.sourceDir = getSourceDir(workspaceModule); | ||
welcomeData.resourcesDir = getResourcesDir(workspaceModule); | ||
|
||
List<Extension> selectedExtensions = getSelectedExtensions(workspaceModule, extensionsBuildItem); | ||
for (Extension extension : selectedExtensions) { | ||
welcomeData.addSelectedExtension(extension.getName(), extension.getDescription(), extension.getGuide()); | ||
if (extension.getCodestart() != null) { | ||
// TODO: Get the codestarts ? | ||
//extension.getCodestart().getArtifact() | ||
//extension.getCodestart().getName() | ||
//extension.getCodestart().getLanguages() | ||
} | ||
} | ||
|
||
return welcomeData; | ||
} | ||
|
||
private String getConfigFile(WorkspaceModule workspaceModule) { | ||
File moduleDir = workspaceModule.getModuleDir(); | ||
if (moduleDir != null) { | ||
String root = moduleDir.toPath().toString(); | ||
Collection<SourceDir> resourcesDirs = workspaceModule.getMainSources().getResourceDirs(); | ||
if (resourcesDirs != null && !resourcesDirs.isEmpty()) { | ||
Path resourceDirs = resourcesDirs.iterator().next().getDir(); | ||
Path propertiesFile = resourceDirs.resolve("application.properties"); | ||
if (Files.exists(propertiesFile)) { | ||
return propertiesFile.toString().substring((int) root.length() + 1); | ||
} | ||
Path propertiesYaml = resourceDirs.resolve("application.yaml"); | ||
if (Files.exists(propertiesYaml)) { | ||
return propertiesYaml.toString().substring((int) root.length() + 1); | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private String getSourceDir(WorkspaceModule workspaceModule) { | ||
File moduleDir = workspaceModule.getModuleDir(); | ||
if (moduleDir != null) { | ||
String root = moduleDir.toPath().toString(); | ||
Collection<SourceDir> sourceDirs = workspaceModule.getMainSources().getSourceDirs(); | ||
if (sourceDirs != null && !sourceDirs.isEmpty()) { | ||
String sourceDir = sourceDirs.iterator().next().getDir().toString(); | ||
return sourceDir.substring((int) root.length() + 1); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private String getResourcesDir(WorkspaceModule workspaceModule) { | ||
File moduleDir = workspaceModule.getModuleDir(); | ||
if (moduleDir != null) { | ||
String root = moduleDir.toPath().toString(); | ||
Collection<SourceDir> resourcesDirs = workspaceModule.getMainSources().getResourceDirs(); | ||
if (resourcesDirs != null && !resourcesDirs.isEmpty()) { | ||
String resourceDirs = resourcesDirs.iterator().next().getDir().toString(); | ||
return resourceDirs.substring((int) root.length() + 1); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private List<Extension> getSelectedExtensions(WorkspaceModule workspaceModule, | ||
ExtensionsBuildItem extensionsBuildItem) { | ||
|
||
Map<String, Extension> extensionMap = getExtensionMap(extensionsBuildItem); | ||
|
||
List<Extension> selectedDependency = workspaceModule.getDirectDependencies() | ||
.stream() | ||
.filter((dependency) -> { | ||
return dependency.isJar() | ||
&& (dependency.getScope() == null || !dependency.getScope().equals("test")) | ||
&& !dependency.getGroupId().startsWith("org.mvnpm") | ||
&& !dependency.getGroupId().startsWith("org.webjars"); | ||
}).map((t) -> { | ||
String key = t.getGroupId() + ":" + t.getArtifactId(); | ||
return extensionMap.get(key); | ||
}).collect(Collectors.toList()); | ||
|
||
return selectedDependency; | ||
} | ||
|
||
private Map<String, Extension> getExtensionMap(ExtensionsBuildItem extensionsBuildItem) { | ||
Map<String, Extension> all = new HashMap<>(); | ||
extensionsBuildItem.getActiveExtensions().forEach((t) -> { | ||
String gav[] = t.getArtifact().split(":"); | ||
all.put(gav[0] + ":" + gav[1], t); | ||
}); | ||
extensionsBuildItem.getInactiveExtensions().forEach((t) -> { | ||
String gav[] = t.getArtifact().split(":"); | ||
all.put(gav[0] + ":" + gav[1], t); | ||
}); | ||
return all; | ||
} | ||
|
||
} |
Oops, something went wrong.