Skip to content
Snippets Groups Projects
Commit 4ac6160f authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#275 - implemented version check

parent 1a588ba2
No related branches found
No related tags found
No related merge requests found
Pipeline #319 passed
......@@ -6,7 +6,7 @@
<groupId>de.deadlocker8</groupId>
<artifactId>BudgetMaster</artifactId>
<version>2.0.0</version>
<version>2.0.0-SNAPSHOT</version>
<name>BudgetMaster</name>
<repositories>
......@@ -118,6 +118,18 @@
<artifactId>libStorage</artifactId>
</dependency>
<dependency>
<groupId>de.thecodelabs.versionizer</groupId>
<artifactId>api</artifactId>
<version>${versionizer.version}</version>
<exclusions>
<exclusion>
<groupId>de.thecodelabs</groupId>
<artifactId>libLogger-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
......@@ -184,4 +196,17 @@
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>release</id>
<name>TheCodeLabs-releases</name>
<url>https://maven.thecodelabs.de/artifactory/TheCodeLabs-release</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>TheCodeLabs-snapshots</name>
<url>https://maven.thecodelabs.de/artifactory/TheCodeLabs-snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
\ No newline at end of file
......@@ -9,6 +9,7 @@ import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import java.io.IOException;
import java.nio.file.Files;
......@@ -18,6 +19,7 @@ import java.util.Arrays;
import java.util.Locale;
@EnableScheduling
@SpringBootApplication
public class Main implements ApplicationRunner
{
......@@ -81,7 +83,8 @@ public class Main implements ApplicationRunner
LOGGER.info("=============================");
}
private static void logAppInfo(String appName, String versionName, String versionCode, String versionDate) {
private static void logAppInfo(String appName, String versionName, String versionCode, String versionDate)
{
LOGGER.info(appName + " - v" + versionName + " - (versioncode: " + versionCode + ") from " + versionDate + ")");
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ import de.deadlocker8.budgetmaster.repositories.SettingsRepository;
import de.deadlocker8.budgetmaster.services.DatabaseService;
import de.deadlocker8.budgetmaster.services.HelpersService;
import de.deadlocker8.budgetmaster.services.ImportService;
import de.deadlocker8.budgetmaster.update.BudgetMasterUpdateService;
import de.deadlocker8.budgetmaster.utils.LanguageType;
import de.deadlocker8.budgetmaster.utils.Strings;
import de.thecodelabs.utils.util.Localization;
......@@ -60,6 +61,9 @@ public class SettingsController extends BaseController
@Autowired
private ImportService importService;
@Autowired
private BudgetMasterUpdateService budgetMasterUpdateService;
private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
@RequestMapping("/settings")
......@@ -67,6 +71,7 @@ public class SettingsController extends BaseController
{
model.addAttribute("settings", settingsRepository.findOne(0));
request.removeAttribute("database", WebRequest.SCOPE_SESSION);
model.addAttribute("availableVersion", budgetMasterUpdateService.getAvailableVersion());
return "settings";
}
......@@ -241,4 +246,11 @@ public class SettingsController extends BaseController
request.removeAttribute("database", RequestAttributes.SCOPE_SESSION);
return "settings";
}
@RequestMapping("/updateSearch")
public String updateSearch()
{
budgetMasterUpdateService.getUpdateService().fetchCurrentVersion();
return "redirect:/settings";
}
}
\ No newline at end of file
package de.deadlocker8.budgetmaster.services;
import de.deadlocker8.budgetmaster.update.BudgetMasterUpdateService;
import de.deadlocker8.budgetmaster.database.accountmatches.AccountMatch;
import de.deadlocker8.budgetmaster.entities.*;
import de.deadlocker8.budgetmaster.repeating.modifier.RepeatingModifierType;
......@@ -48,6 +49,9 @@ public class HelpersService
@Autowired
private CategoryRepository categoryRepository;
@Autowired
private BudgetMasterUpdateService budgetMasterUpdateService;
public String getCurrencyString(int amount)
{
return getCurrencyString(amount / 100.0);
......@@ -283,6 +287,13 @@ public class HelpersService
public boolean isUpdateAvailable()
{
return true;
try
{
return budgetMasterUpdateService.getUpdateService().isUpdateAvailable();
}
catch(NullPointerException e)
{
return false;
}
}
}
\ No newline at end of file
package de.deadlocker8.budgetmaster.update;
import de.deadlocker8.budgetmaster.Main;
import de.deadlocker8.budgetmaster.services.SettingsService;
import de.thecodelabs.storage.settings.Storage;
import de.thecodelabs.storage.settings.StorageTypes;
import de.thecodelabs.versionizer.VersionizerItem;
import de.thecodelabs.versionizer.config.Artifact;
import de.thecodelabs.versionizer.config.Repository;
import de.thecodelabs.versionizer.model.Version;
import de.thecodelabs.versionizer.service.UpdateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationHome;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.io.File;
@Service
public class BudgetMasterUpdateService
{
private final static Logger LOGGER = LoggerFactory.getLogger(Main.class);
@Autowired
private Artifact artifact;
@Autowired
private UpdateService updateService;
@Autowired
private SettingsService settingsService;
@Autowired
private ApplicationEventPublisher applicationEventPublisher;
@Scheduled(cron = "${versionizer.service.cron}")
public void updateSearchTask()
{
if(settingsService.getSettings().isAutoUpdateCheckEnabled())
{
updateService.fetchCurrentVersion();
if(updateService.isUpdateAvailable())
{
UpdateAvailableEvent customSpringEvent = new UpdateAvailableEvent(this, updateService);
applicationEventPublisher.publishEvent(customSpringEvent);
}
}
}
@Bean
public Artifact artifact()
{
Artifact artifact = new Artifact();
// artifact.setVersion(Build.getInstance().getVersionName());
artifact.setVersion("0.0.0");
artifact.setGroupId("de.deadlocker8");
artifact.setArtifactId("BudgetMaster");
return artifact;
}
@Bean
public UpdateService updateService()
{
ClassLoader classLoader = Main.class.getClassLoader();
Repository repository = Storage.load(classLoader.getResourceAsStream("repositories.json"), StorageTypes.JSON, Repository.class);
File source = new ApplicationHome().getSource();
String executablePath = null;
if(source == null)
{
LOGGER.debug("Running from source code: Skipping update check");
}
else
{
executablePath = source.getAbsolutePath();
}
VersionizerItem versionizerItem = new VersionizerItem(repository, artifact, executablePath);
return UpdateService.startVersionizer(versionizerItem, UpdateService.Strategy.JAR, UpdateService.InteractionType.HEADLESS);
}
@Component
public class UpdateEventListener implements ApplicationListener<UpdateAvailableEvent>
{
@Override
public void onApplicationEvent(UpdateAvailableEvent updateAvailableEvent)
{
UpdateService updateService = updateAvailableEvent.getUpdateService();
Version version = updateService.getRemoteVersionForArtifact(artifact);
System.out.println(version);
}
}
public UpdateService getUpdateService()
{
return updateService;
}
public String getAvailableVersion()
{
if(updateService.getRemoteVersionForArtifact(artifact) == null)
{
return "-";
}
else
{
return "v" + updateService.getRemoteVersionForArtifact(artifact).toVersionString();
}
}
}
package de.deadlocker8.budgetmaster.update;
import de.thecodelabs.versionizer.service.UpdateService;
import org.springframework.context.ApplicationEvent;
public class UpdateAvailableEvent extends ApplicationEvent
{
private final UpdateService updateService;
UpdateAvailableEvent(Object source, UpdateService updateService)
{
super(source);
this.updateService = updateService;
}
public UpdateService getUpdateService()
{
return updateService;
}
}
......@@ -12,6 +12,8 @@ logging.level.root=INFO
logging.level.de.deadlocker8=DEBUG
versionizer.service.cron=* * * */1 * *
app.name=@project.artifactId@
app.version.code=@app.versionCode@
app.version.name=@project.version@
......
{
"url": "https://maven.thecodelabs.de/artifactory",
"repository.releases": "TheCodeLabs-release",
"repository.snapshots": "TheCodeLabs-snapshots"
}
\ No newline at end of file
......@@ -101,22 +101,22 @@
<div class="switch">
<label>
${locale.getString("settings.updates.automatic.deactivated")}
<input type="checkbox" name="autoUpdateCheckEnabled" <#if settings.isUseDarkTheme()>checked</#if>>
<input type="checkbox" name="autoUpdateCheckEnabled" <#if settings.isAutoUpdateCheckEnabled()>checked</#if>>
<span class="lever"></span>
${locale.getString("settings.updates.automatic.activated")}
</label>
</div>
</td>
<td>${locale.getString("settings.updates.current.version")}</td>
<td>v${build.getVersionName()} (${build.getVersionCode()})</td>
<td>v${build.getVersionName()}</td>
</tr>
<tr>
<td>${locale.getString("settings.updates.latest.version")}</td>
<td>v2.0.0</td>
<td>${availableVersion}</td>
</tr>
<tr>
<td colspan="2">
<a href="/updateSearch" class="waves-effect waves-light btn budgetmaster-blue-light"><i class="material-icons left">refresh</i>${locale.getString("settings.updates.search")}</a>
<a href="/updateSearch" class="waves-effect waves-light btn budgetmaster-blue"><i class="material-icons left">refresh</i>${locale.getString("settings.updates.search")}</a>
</td>
</tr>
</table>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment