-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
304 additions
and
29 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
24 changes: 0 additions & 24 deletions
24
src/main/java/coffee/synyx/frontpage/installer/PluginConfigurationProperties.java
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
src/main/java/coffee/synyx/frontpage/plugin/management/AvailablePluginAssets.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,23 @@ | ||
package coffee.synyx.frontpage.plugin.management; | ||
|
||
/** | ||
* @author Tobias Schneider | ||
*/ | ||
class AvailablePluginAssets { | ||
|
||
private final String name; | ||
private final String url; | ||
|
||
AvailablePluginAssets(String name, String url) { | ||
this.name = name; | ||
this.url = url; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/coffee/synyx/frontpage/plugin/management/AvailablePlugins.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,25 @@ | ||
package coffee.synyx.frontpage.plugin.management; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author Tobias Schneider | ||
*/ | ||
public class AvailablePlugins { | ||
|
||
private final String name; | ||
private final List<AvailablePluginAssets> versions; | ||
|
||
public AvailablePlugins(String name, List<AvailablePluginAssets> versions) { | ||
this.name = name; | ||
this.versions = versions; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public List<AvailablePluginAssets> getVersions() { | ||
return versions; | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
src/main/java/coffee/synyx/frontpage/plugin/management/PluginConfigurationProperties.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,51 @@ | ||
package coffee.synyx.frontpage.plugin.management; | ||
|
||
import org.hibernate.validator.constraints.NotEmpty; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author Tobias Schneider | ||
*/ | ||
@Validated | ||
@ConfigurationProperties("frontpage.plugins") | ||
public class PluginConfigurationProperties { | ||
|
||
@NotEmpty | ||
private String directory = "./plugins"; | ||
|
||
private List<Resource> resource; | ||
|
||
@Validated | ||
public static class Resource { | ||
|
||
@NotEmpty | ||
private String repositoryName; | ||
|
||
public String getRepositoryName() { | ||
return repositoryName; | ||
} | ||
|
||
public void setRepositoryName(String repositoryName) { | ||
this.repositoryName = repositoryName; | ||
} | ||
} | ||
|
||
public String getDirectory() { | ||
return directory; | ||
} | ||
|
||
public void setDirectory(String directory) { | ||
this.directory = directory; | ||
} | ||
|
||
public List<Resource> getResource() { | ||
return resource; | ||
} | ||
|
||
public void setResource(List<Resource> resource) { | ||
this.resource = resource; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...nstaller/PluginInstallationException.java → ...nagement/PluginInstallationException.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
2 changes: 1 addition & 1 deletion
2
...age/installer/PluginInstallerService.java → ...in/management/PluginInstallerService.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
49 changes: 49 additions & 0 deletions
49
src/main/java/coffee/synyx/frontpage/plugin/management/PluginManagementController.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,49 @@ | ||
package coffee.synyx.frontpage.plugin.management; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
@Controller | ||
public class PluginManagementController { | ||
|
||
private final PluginManagementService pluginManagementService; | ||
private final PluginInstallerService pluginInstallerService; | ||
|
||
@Autowired | ||
public PluginManagementController(PluginManagementService pluginManagementService, PluginInstallerService pluginInstallerService) { | ||
|
||
this.pluginManagementService = pluginManagementService; | ||
this.pluginInstallerService = pluginInstallerService; | ||
} | ||
|
||
@GetMapping("/plugins-install") | ||
public String getPlugins(Model model) { | ||
|
||
List<AvailablePlugins> availablePlugins = emptyList(); | ||
|
||
Optional<List<AvailablePlugins>> listOfAvailablePlugins = pluginManagementService.getListOfAvailablePlugins(); | ||
if (listOfAvailablePlugins.isPresent()) { | ||
availablePlugins = listOfAvailablePlugins.get(); | ||
} | ||
|
||
model.addAttribute("availablePlugins", availablePlugins); | ||
return "management/plugins"; | ||
} | ||
|
||
@PutMapping("/plugins-install") | ||
public String installPlugin(@RequestParam String url) { | ||
|
||
pluginInstallerService.installPlugin(url); | ||
|
||
return "redirect:/plugins-install"; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/coffee/synyx/frontpage/plugin/management/PluginManagementException.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,11 @@ | ||
package coffee.synyx.frontpage.plugin.management; | ||
|
||
/** | ||
* @author Tobias Schneider | ||
*/ | ||
public class PluginManagementException extends RuntimeException { | ||
|
||
PluginManagementException(String message) { | ||
super(message); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/coffee/synyx/frontpage/plugin/management/PluginManagementService.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,80 @@ | ||
package coffee.synyx.frontpage.plugin.management; | ||
|
||
import coffee.synyx.frontpage.plugin.management.PluginConfigurationProperties.Resource; | ||
import org.kohsuke.github.GHRelease; | ||
import org.kohsuke.github.GitHub; | ||
import org.kohsuke.github.GitHubBuilder; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static java.lang.String.format; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
/** | ||
* @author Tobias Schneider | ||
*/ | ||
@Service | ||
public class PluginManagementService { | ||
|
||
private final PluginConfigurationProperties pluginConfigurationProperties; | ||
private final GitHubBuilder gitHubBuilder; | ||
|
||
@Autowired | ||
public PluginManagementService(PluginConfigurationProperties pluginConfigurationProperties, GitHubBuilder gitHubBuilder) { | ||
|
||
this.pluginConfigurationProperties = pluginConfigurationProperties; | ||
this.gitHubBuilder = gitHubBuilder; | ||
} | ||
|
||
|
||
Optional<List<AvailablePlugins>> getListOfAvailablePlugins() { | ||
|
||
List<Resource> pluginResources = pluginConfigurationProperties.getResource(); | ||
|
||
if (pluginResources == null) { | ||
return Optional.empty(); | ||
} | ||
|
||
List<AvailablePlugins> availablePlugins = new ArrayList<>(); | ||
|
||
for (Resource pluginResource : pluginResources) { | ||
GHRelease latestRelease = getLatestRelease(pluginResource); | ||
List<AvailablePluginAssets> latestReleaseAssets = getAvailablePluginAssets(latestRelease); | ||
|
||
availablePlugins.add(new AvailablePlugins(pluginResource.getRepositoryName(), latestReleaseAssets)); | ||
} | ||
|
||
return Optional.of(availablePlugins); | ||
} | ||
|
||
private List<AvailablePluginAssets> getAvailablePluginAssets(GHRelease release) { | ||
try { | ||
|
||
if (release == null) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
return release.getAssets() | ||
.stream() | ||
.map(ghAsset -> new AvailablePluginAssets(ghAsset.getName(), ghAsset.getBrowserDownloadUrl())) | ||
.collect(toList()); | ||
} catch (IOException e) { | ||
throw new PluginManagementException(""); | ||
} | ||
} | ||
|
||
private GHRelease getLatestRelease(Resource resource) { | ||
try { | ||
GitHub github = gitHubBuilder.build(); | ||
return github.getRepository(resource.getRepositoryName()).getLatestRelease(); | ||
} catch (IOException e) { | ||
throw new PluginManagementException(format("Could not retrieve lists of release from %s", resource.getRepositoryName())); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...staller/SimplePluginInstallerService.java → ...agement/SimplePluginInstallerService.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" | ||
lang="en" | ||
layout:decorator="layout"> | ||
|
||
<body> | ||
<section layout:fragment="frontpage-main" class="frontpage--plugin-container"> | ||
|
||
<th:block th:each="availablePlugin : ${availablePlugins}"> | ||
|
||
<h1 th:text="${availablePlugin.name}">pluginTitle</h1> | ||
|
||
<th:block th:each="version : ${availablePlugin.versions}"> | ||
|
||
<span th:text="${version.name}"></span> | ||
|
||
<form style="display: inline-block" th:action="@{/plugins-install}" th:method="put"> | ||
<input type="hidden" name="url" th:value="${version.url}"/> | ||
<button type="submit" th:title="${version.name}">Install</button> | ||
</form> | ||
</th:block> | ||
|
||
</th:block> | ||
|
||
</section> | ||
|
||
</body> | ||
</html> |
2 changes: 1 addition & 1 deletion
2
...aller/SimplePluginInstallerServiceIT.java → ...ement/SimplePluginInstallerServiceIT.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