CodeCommand.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright © 2019-2022 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.cli.command;
  20. import java.io.File;
  21. import org.eclipse.jgit.api.Git;
  22. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;
  24. import com.l2jserver.cli.model.CloneType;
  25. import com.l2jserver.cli.util.LoggerProgressMonitor;
  26. import picocli.CommandLine.Command;
  27. import picocli.CommandLine.Option;
  28. /**
  29. * Code command.
  30. * @author Zoey76
  31. * @author HorridoJoho
  32. * @version 1.0.0
  33. */
  34. @Command(name = "code", aliases = "c")
  35. public class CodeCommand extends AbstractCommand {
  36. private static final Logger LOG = LoggerFactory.getLogger(CodeCommand.class);
  37. private static final LoggerProgressMonitor LOGGER_PROGRESS_MONITOR = new LoggerProgressMonitor(LOG);
  38. @Option(names = {
  39. "--login-repository",
  40. "-lsrepo"
  41. }, defaultValue = DEFAULT_LOGIN_REPO, description = "Login repository")
  42. private String loginRepository = DEFAULT_LOGIN_REPO;
  43. @Option(names = {
  44. "--game-repository",
  45. "-gsrepo"
  46. }, defaultValue = DEFAULT_GAME_REPO, description = "Game repository")
  47. private String gameRepository = DEFAULT_GAME_REPO;
  48. @Option(names = {
  49. "--datapack-repository",
  50. "-dprepo"
  51. }, defaultValue = DEFAULT_DATAPACK_REPO, description = "Datapack repository")
  52. private String datapackRepository = DEFAULT_DATAPACK_REPO;
  53. @Option(names = {
  54. "--login-directory",
  55. "-lsdir"
  56. }, defaultValue = DEFAULT_LOGIN_SOURCE_DIR, description = "Login directory")
  57. private String loginDirectory = DEFAULT_LOGIN_SOURCE_DIR;
  58. @Option(names = {
  59. "--game-directory",
  60. "-gsdir"
  61. }, defaultValue = DEFAULT_GAME_SOURCE_DIR, description = "Game directory")
  62. private String gameDirectory = DEFAULT_GAME_SOURCE_DIR;
  63. @Option(names = {
  64. "--datapack-directory",
  65. "-dpdir"
  66. }, defaultValue = DEFAULT_DATAPACK_SOURCE_DIR, description = "DataPack directory")
  67. private String datapackDirectory = DEFAULT_DATAPACK_SOURCE_DIR;
  68. @Option(names = "--clone", defaultValue = "ALL", description = "Clone ALL|LOGIN|GAME|DATAPACK")
  69. private CloneType cloneType = CloneType.ALL;
  70. @Override
  71. public void run() {
  72. try {
  73. switch (cloneType) {
  74. case ALL: {
  75. LOG.info("Cloning L2J Loginserver");
  76. cloneRepository(loginRepository, loginDirectory);
  77. LOG.info("Cloning L2J Gameserver");
  78. cloneRepository(gameRepository, gameDirectory);
  79. LOG.info("Cloning L2J DataPack");
  80. cloneRepository(datapackRepository, datapackDirectory);
  81. break;
  82. }
  83. case LOGIN: {
  84. LOG.info("Cloning L2J Loginserver");
  85. cloneRepository(loginRepository, loginDirectory);
  86. break;
  87. }
  88. case GAME: {
  89. LOG.info("Cloning L2J Gameserver");
  90. cloneRepository(gameRepository, gameDirectory);
  91. break;
  92. }
  93. case DATAPACK: {
  94. LOG.info("Cloning L2J DataPack");
  95. cloneRepository(datapackRepository, datapackDirectory);
  96. break;
  97. }
  98. }
  99. } catch (Exception ex) {
  100. LOG.error("Unable to get the code!", ex);
  101. }
  102. }
  103. private void cloneRepository(String repository, String directoryStr) {
  104. try {
  105. File directory = new File(directoryStr);
  106. if (directory.exists()) {
  107. Git.open(directory).pull();
  108. } else {
  109. Git.cloneRepository() //
  110. .setURI(repository) //
  111. .setDirectory(directory) //
  112. .setProgressMonitor(LOGGER_PROGRESS_MONITOR) //
  113. .call();
  114. }
  115. } catch (Exception ex) {
  116. LOG.error("Unable to get the code!", ex);
  117. }
  118. }
  119. }