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

#663 - copy migrator jar to app folder

parent 2876be33
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ import org.springframework.web.context.request.WebRequest; ...@@ -19,6 +19,7 @@ import org.springframework.web.context.request.WebRequest;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.IOException;
@Controller @Controller
...@@ -96,7 +97,7 @@ public class MigrationController extends BaseController ...@@ -96,7 +97,7 @@ public class MigrationController extends BaseController
// TODO: run non-blocking and redirect to progress page // TODO: run non-blocking and redirect to progress page
migrationService.runMigration(migrationArguments); migrationService.runMigration(migrationArguments);
} }
catch(MigrationException e) catch(MigrationException | IOException e)
{ {
WebRequestUtils.putNotification(request, new Notification(Localization.getString("notification.migration.error", e.getMessage()), NotificationType.ERROR)); WebRequestUtils.putNotification(request, new Notification(Localization.getString("notification.migration.error", e.getMessage()), NotificationType.ERROR));
return ReturnValues.MIGRATION_SETTINGS; return ReturnValues.MIGRATION_SETTINGS;
......
...@@ -18,9 +18,11 @@ import java.io.IOException; ...@@ -18,9 +18,11 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
@Service @Service
...@@ -30,6 +32,7 @@ public class MigrationService ...@@ -30,6 +32,7 @@ public class MigrationService
public static final String PREVIOUS_DATABASE_FILE_NAME = "budgetmaster.mv.db"; public static final String PREVIOUS_DATABASE_FILE_NAME = "budgetmaster.mv.db";
public static final String PREVIOUS_DATABASE_FILE_NAME_WITHOUT_EXTENSION = "budgetmaster"; public static final String PREVIOUS_DATABASE_FILE_NAME_WITHOUT_EXTENSION = "budgetmaster";
private static final String BUDGET_MASTER_MIGRATOR_JAR = "BudgetMasterDatabaseMigrator.jar";
private final SettingsService settingsService; private final SettingsService settingsService;
private final Path applicationSupportFolder; private final Path applicationSupportFolder;
private final AccountRepository accountRepository; private final AccountRepository accountRepository;
...@@ -111,21 +114,42 @@ public class MigrationService ...@@ -111,21 +114,42 @@ public class MigrationService
return Files.exists(getDatabaseFromPreviousVersionPath()); return Files.exists(getDatabaseFromPreviousVersionPath());
} }
public String runMigration(MigrationArguments migrationArguments) throws MigrationException public String runMigration(MigrationArguments migrationArguments) throws MigrationException, IOException
{ {
// TODO: extract BudgetMasterMigrator.jar from resources to tmp folder final Path migratorPath = extractMigrator();
try
{
return runMigrator(migratorPath, migrationArguments);
}
finally
{
Files.deleteIfExists(migratorPath);
}
}
private Path extractMigrator() throws MigrationException
{
final Path destinationPath = applicationSupportFolder.resolve(BUDGET_MASTER_MIGRATOR_JAR);
return runMigrator(migrationArguments); try
{
Files.copy(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(BUDGET_MASTER_MIGRATOR_JAR)), destinationPath, StandardCopyOption.REPLACE_EXISTING);
return destinationPath;
}
catch(IOException e)
{
throw new MigrationException(MessageFormat.format("Could not copy migrator to {0}", destinationPath), e);
}
} }
private String runMigrator(MigrationArguments migrationArguments) throws MigrationException private String runMigrator(Path migratorPath, MigrationArguments migrationArguments) throws MigrationException
{ {
final String javaCommand = determineJavaCommand(); final String javaCommand = determineJavaCommand();
final List<String> command = new ArrayList<>(); final List<String> command = new ArrayList<>();
command.add(MessageFormat.format("\"{0}\"", javaCommand)); command.add(MessageFormat.format("\"{0}\"", javaCommand));
command.add("-jar"); command.add("-jar");
command.add("C:/Programmierung/BudgetMaster/BudgetMasterDatabaseMigrator/target/BudgetMasterDatabaseMigrator-v2.10.0.jar"); command.add(migratorPath.toString());
command.addAll(migrationArguments.getArguments()); command.addAll(migrationArguments.getArguments());
LOGGER.debug("Starting migration with command: {}", command); LOGGER.debug("Starting migration with command: {}", command);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment