From a7aa429ad9eafac9f94e18ec4ab1be821914569e Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Mon, 15 Aug 2016 09:46:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=81=D0=BC=D0=BE?= =?UTF-8?q?=D1=82=D1=80=D0=B5=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D1=83=D0=BA?= =?UTF-8?q?=D1=82=D1=83=D1=80=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Изменено название: ArcadexSystem -> ASys. Изменены корневые пакеты: eu.arcadex.system -> asys Проект полностью переходит на модульную структуру. Удаляется модуль Core. --- API/pom.xml | 54 +++++++ README.md | 4 +- build_files/pom.xml | 22 --- configuration/pom.xml | 15 -- core/pom.xml | 39 ----- .../java/eu/arcadex/system/core/ASysCore.java | 93 ----------- .../system/core/ASysCoreActivator.java | 30 ---- .../eu/arcadex/system/core/api/ICore.java | 9 -- database/pom.xml | 17 -- filesystem/pom.xml | 16 -- filesystem/src/main/java/FileSystemLib.java | 145 ------------------ filesystem/src/main/java/UnzipUtility.java | 69 --------- netty_api/pom.xml | 22 --- pom.xml | 63 -------- screen/pom.xml | 16 -- screen/src/main/java/ScreenLib.java | 65 -------- server_manager/pom.xml | 33 ---- web_api/pom.xml | 32 ---- 18 files changed, 56 insertions(+), 688 deletions(-) create mode 100644 API/pom.xml delete mode 100644 build_files/pom.xml delete mode 100644 configuration/pom.xml delete mode 100644 core/pom.xml delete mode 100644 core/src/main/java/eu/arcadex/system/core/ASysCore.java delete mode 100644 core/src/main/java/eu/arcadex/system/core/ASysCoreActivator.java delete mode 100644 core/src/main/java/eu/arcadex/system/core/api/ICore.java delete mode 100644 database/pom.xml delete mode 100644 filesystem/pom.xml delete mode 100644 filesystem/src/main/java/FileSystemLib.java delete mode 100755 filesystem/src/main/java/UnzipUtility.java delete mode 100644 netty_api/pom.xml delete mode 100644 pom.xml delete mode 100644 screen/pom.xml delete mode 100644 screen/src/main/java/ScreenLib.java delete mode 100644 server_manager/pom.xml delete mode 100644 web_api/pom.xml diff --git a/API/pom.xml b/API/pom.xml new file mode 100644 index 0000000..cb6d68f --- /dev/null +++ b/API/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + ASys API + + + + DmitriyMX + mail@dmiriymx.ru + + + + + UTF-8 + 1.8 + + + asys + api + 0.1 + bundle + + + ${project.groupId}.${project.artifactId}-${project.version} + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + ${java.version} + ${java.version} + ${project.build.sourceEncoding} + + + + org.apache.felix + maven-bundle-plugin + 3.0.1 + true + + + ${project.name} + ${project.groupId}.${project.artifactId} + asys.api + * + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 2a230aa..387f6ef 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# ArcadexSystem: Core +# ASys -Ядро системы +Модульная система управления серверами Minecraft. Основана на технологии [OSGi](https://www.osgi.org/). diff --git a/build_files/pom.xml b/build_files/pom.xml deleted file mode 100644 index 8236080..0000000 --- a/build_files/pom.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - arcadexsystem - eu.arcadex.system - ${global.version} - - 4.0.0 - - build_files - jar - - - - eu.arcadex.system - filesystem - ${global.version} - - - \ No newline at end of file diff --git a/configuration/pom.xml b/configuration/pom.xml deleted file mode 100644 index 93a3806..0000000 --- a/configuration/pom.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - arcadexsystem - eu.arcadex.system - ${global.version} - - 4.0.0 - - configuration - jar - - \ No newline at end of file diff --git a/core/pom.xml b/core/pom.xml deleted file mode 100644 index 194b27b..0000000 --- a/core/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - 4.0.0 - Core - - core - 0.1-SNAPSHOT - bundle - - - arcadexsystem - eu.arcadex.system - ${global.version} - - - - ${groupId}.${artifactId}-${version} - - - org.apache.felix - maven-bundle-plugin - 2.3.5 - true - - - Arcadex System: ${name} ${version} - ${groupId}.${artifactId} - eu.arcadex.system.core.ASysCoreActivator - eu.arcadex.system.core.api - * - - - - - - \ No newline at end of file diff --git a/core/src/main/java/eu/arcadex/system/core/ASysCore.java b/core/src/main/java/eu/arcadex/system/core/ASysCore.java deleted file mode 100644 index 0662951..0000000 --- a/core/src/main/java/eu/arcadex/system/core/ASysCore.java +++ /dev/null @@ -1,93 +0,0 @@ -package eu.arcadex.system.core; - -import eu.arcadex.system.core.api.ICore; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * @author DmitriyMX - * 2016 - */ -class ASysCore implements ICore { - private Logger logger = LoggerFactory.getLogger(ASysCore.class.getName()); - private BundleContext bundleContext; - private List modules; - - ASysCore(BundleContext bundleContext) { - this.bundleContext = bundleContext; - } - - void init() { - // Загрузка библиотек - logger.trace("Load libraries"); - startBundles(loadJars("lib")); - - // Загрузка модулей - logger.trace("Load modules"); - modules = loadJars("modules"); - startBundles(modules); - } - - private List loadJars(String directory) { - List bundlesList = new ArrayList<>(); - - File libsDir = new File(directory); - String[] jarsList = libsDir.list(); - for (String jar : jarsList) { - if (!jar.endsWith(".jar")) continue; - try { - logger.trace("Load jar \"{}/{}\"", directory, jar); - Bundle bundle = bundleContext.installBundle(String.format("file:%s/%s", directory, jar)); - bundlesList.add(bundle); - } catch (BundleException e) { - logger.error(String.format("Error load jar \"%s/%s\"", directory, jar), e); - } - } - - return bundlesList; - } - - private void startBundles(List bundleList) { - for (Bundle bundle : bundleList) { - try { - logger.trace("Start module \"{}\"", bundle.getSymbolicName()); - bundle.start(); - } catch (BundleException e) { - logger.error(String.format("Error start bundle \"%s\"", bundle.getSymbolicName()), e); - } - } - } - - private void stopBundles(List bundleList) { - for (Bundle bundle : bundleList) { - try { - bundle.stop(); - } catch (BundleException e) { - logger.error(String.format("Error stop bundle \"%s\"", bundle.getSymbolicName()), e); - } - } - } - - @Override - public void reloadMoludes() { - logger.trace("Reload modules - start"); - - // Остановка модулей - stopBundles(modules); - - // Загрузка модулей по-новой - modules = loadJars("modules"); - - // Запуск модулей - startBundles(modules); - - logger.trace("Reload modules - end"); - } -} diff --git a/core/src/main/java/eu/arcadex/system/core/ASysCoreActivator.java b/core/src/main/java/eu/arcadex/system/core/ASysCoreActivator.java deleted file mode 100644 index b6e315e..0000000 --- a/core/src/main/java/eu/arcadex/system/core/ASysCoreActivator.java +++ /dev/null @@ -1,30 +0,0 @@ -package eu.arcadex.system.core; - -import eu.arcadex.system.core.api.ICore; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -/** - * @author DmitriyMX - * 2016 - */ -public class ASysCoreActivator implements BundleActivator { - private ServiceRegistration service; - - @Override - public void start(BundleContext bundleContext) throws Exception { - ASysCore core = new ASysCore(bundleContext); - - // Регистрация сервиса доступа к Ядру - service = bundleContext.registerService(ICore.class.getName(), core, null); - - // Инициализация Ядра - core.init(); - } - - @Override - public void stop(BundleContext bundleContext) throws Exception { - service.unregister(); - } -} diff --git a/core/src/main/java/eu/arcadex/system/core/api/ICore.java b/core/src/main/java/eu/arcadex/system/core/api/ICore.java deleted file mode 100644 index da2da0d..0000000 --- a/core/src/main/java/eu/arcadex/system/core/api/ICore.java +++ /dev/null @@ -1,9 +0,0 @@ -package eu.arcadex.system.core.api; - -/** - * @author DmitriyMX - * 2016 - */ -public interface ICore { - void reloadMoludes(); -} diff --git a/database/pom.xml b/database/pom.xml deleted file mode 100644 index bed81fa..0000000 --- a/database/pom.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - arcadexsystem - eu.arcadex.system - ${global.version} - - - 4.0.0 - - database - jar - - - \ No newline at end of file diff --git a/filesystem/pom.xml b/filesystem/pom.xml deleted file mode 100644 index f9fe83c..0000000 --- a/filesystem/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - arcadexsystem - eu.arcadex.system - ${global.version} - - 4.0.0 - - filesystem - jar - - - \ No newline at end of file diff --git a/filesystem/src/main/java/FileSystemLib.java b/filesystem/src/main/java/FileSystemLib.java deleted file mode 100644 index ba9bfdc..0000000 --- a/filesystem/src/main/java/FileSystemLib.java +++ /dev/null @@ -1,145 +0,0 @@ -import java.io.*; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; - -/** - * File System proxy lib - *

- * Created by daniil on 02.04.16. - */ -public class FileSystemLib { - /** - * Copy data from InputStream to OutputStream - * - * @param from Input Stream - * @param to Output Stream - * @return size of copied data - * @throws IOException - */ - protected static long copy(InputStream from, OutputStream to) throws IOException { - assert from != null; - assert to != null; - byte[] buf = new byte[4096]; - long total = 0L; - - while (true) { - int r = from.read(buf); - if (r == -1) { - return total; - } - - to.write(buf, 0, r); - total += (long) r; - } - } - - /** - * Copy file or directory from one direction to another - * - * @param from File to copy - * @param to Destination - * @param replace replace the destination file if present? - * @throws IOException - */ - public void copy(Path from, Path to, boolean replace) throws IOException { - assert from != null; - assert to != null; - - if (!replace) - Files.copy(from, to); - else - Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING); - } - - /** - * Delete file - * - * @param file file to delete - * @throws IOException, FileNotFoundException - */ - public void delete(File file) throws IOException { - assert file != null; - - if (!file.exists()) - throw new FileNotFoundException("Unable to delete nonexistent file"); - if (!file.delete()) - throw new IOException("Unable to delete this file"); - } - - /** - * Create a symlink - * - * @param linkFile Where symlink should be created - * @param actualFile Where should it point to - * @throws IOException - */ - public void createSymlink(Path linkFile, Path actualFile) throws IOException { - assert linkFile != null; - assert actualFile != null; - - if (!actualFile.toFile().exists()) - throw new FileNotFoundException("Couldn't find symlink destination"); - - Files.createSymbolicLink(linkFile, actualFile); - } - - public void restoreFromResources(String resourceName, File destination, boolean replace) throws IOException { - assert resourceName != null; - assert destination != null; - - if (destination.exists() && !replace) - return; - try { - if (!destination.createNewFile()) - throw new IOException("Unable to create new file"); - - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(resourceName); - OutputStream os = new FileOutputStream(destination)) { - copy(is, os); - } - } catch (IOException e) { - throw new IOException("Unable to restore file from resource"); - } - } - - /** - * Get FileReader for the file - *

- * We need this to make the code testable - * - * @param file file to read - * @return FileReader - * @throws FileNotFoundException - */ - public Reader getReader(File file) throws FileNotFoundException { - assert file != null; - - return new FileReader(file); - } - - /** - * Get FileWriter for the file - *

- * We need this to make the code testable - * - * @param file file to write to - * @return FileWriter - * @throws IOException - */ - public Writer getWriter(File file) throws IOException { - return new FileWriter(file); - } - - /** - * Unzip archive to directory - * - * @param archive archive to extract - * @param directory destination - * @throws IOException - */ - public void unzip(String archive, String directory) throws IOException { - UnzipUtility zip = new UnzipUtility(); - zip.unzip(archive, directory); - } -} diff --git a/filesystem/src/main/java/UnzipUtility.java b/filesystem/src/main/java/UnzipUtility.java deleted file mode 100755 index a3a37ec..0000000 --- a/filesystem/src/main/java/UnzipUtility.java +++ /dev/null @@ -1,69 +0,0 @@ -import java.io.*; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -/** - * This utility extracts files and directories of a standard zip file to - * a destination directory. - * - * @author www.codejava.net - */ -public class UnzipUtility { - /** - * Size of the buffer to read/write data - */ - private static final int BUFFER_SIZE = 4096; - - /** - * Extracts a zip file specified by the zipFilePath to a directory specified by - * destDirectory (will be created if does not exists) - * - * @param zipFilePath path of the archive - * @param destDirectory where to extract to - * @throws IOException - */ - public void unzip(String zipFilePath, String destDirectory) throws IOException { - File destDir = new File(destDirectory); - if (!destDir.exists()) { - if (!destDir.mkdir()) - throw new IOException("Unable to create a root directory to unzip the archive"); - } - ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath)); - ZipEntry entry = zipIn.getNextEntry(); - // iterates over entries in the zip file - while (entry != null) { - String filePath = destDirectory + File.separator + entry.getName(); - if (!entry.isDirectory()) { - // if the entry is a file, extracts it - extractFile(zipIn, filePath); - } else { - // if the entry is a directory, make the directory - File dir = new File(filePath); - - if (!dir.mkdir()) { - throw new IOException("Unable to create a directory to unzip the directory"); - } - } - zipIn.closeEntry(); - entry = zipIn.getNextEntry(); - } - zipIn.close(); - } - - /** - * Extracts a zip entry (file entry) - * - * @param zipIn ZipInputStream - * @param filePath Where to extract to - * @throws IOException - */ - private void extractFile(ZipInputStream zipIn, String filePath) throws IOException { - BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); - byte[] bytesIn = new byte[BUFFER_SIZE]; - int read; - while ((read = zipIn.read(bytesIn)) != -1) { - bos.write(bytesIn, 0, read); - } - bos.close(); - } -} \ No newline at end of file diff --git a/netty_api/pom.xml b/netty_api/pom.xml deleted file mode 100644 index 6578653..0000000 --- a/netty_api/pom.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - arcadexsystem - eu.arcadex.system - ${global.version} - - 4.0.0 - - netty_api - jar - - - - eu.arcadex.system - database - ${global.version} - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 492fa31..0000000 --- a/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - 4.0.0 - Arcadex System - - - 0.1 - UTF-8 - - - eu.arcadex.system - arcadexsystem - pom - ${global.version} - - - core - configuration - database - filesystem - screen - build_files - netty_api - web_api - server_manager - - - - - SonatypeRepo - https://oss.sonatype.org/content/repositories/snapshots - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.5 - - 1.8 - 1.8 - - - - - - - - org.slf4j - slf4j-api - 1.7.20 - - - org.osgi - org.osgi.core - 6.0.0 - - - \ No newline at end of file diff --git a/screen/pom.xml b/screen/pom.xml deleted file mode 100644 index 2bd99c6..0000000 --- a/screen/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - arcadexsystem - eu.arcadex.system - ${global.version} - - 4.0.0 - - screen - jar - - - \ No newline at end of file diff --git a/screen/src/main/java/ScreenLib.java b/screen/src/main/java/ScreenLib.java deleted file mode 100644 index 9405982..0000000 --- a/screen/src/main/java/ScreenLib.java +++ /dev/null @@ -1,65 +0,0 @@ -import java.io.IOException; -import java.nio.file.Path; - -/** - * Realization of class dedicated to the control - * of GNU Screen sessions - *

- * Created by daniil on 02.04.16. - */ -public class ScreenLib { - - /** - * Start a screen with certain ID - * and execute a command inside it - * - * @param screenName Screen ID - * @param runPath Home path of started screen - * @param command Command [+args] to execute inside the screen - * @throws IOException - */ - public void startScreen(String screenName, Path runPath, String... command) throws IOException { - assert screenName != null && screenName.length() != 0; - assert runPath != null; - - // Merge two arrays - String[] commandBase = new String[command.length + 3]; - commandBase[0] = "screen"; - commandBase[1] = "-dmS"; - commandBase[2] = screenName; - - System.arraycopy(command, 0, commandBase, 3, command.length); - - ProcessBuilder processBuilder = new ProcessBuilder(commandBase); - processBuilder.directory(runPath.toFile()); - processBuilder.start(); - } - - /** - * Send command to specific screen - * - * @param screenName Screen ID - * @param command Command to send - * @throws IOException - */ - public void sendCommand(String screenName, String command) throws IOException { - assert screenName != null; - assert command != null; - - ProcessBuilder processBuilder = new ProcessBuilder("screen", "-S", screenName, "-p", "0", "-X", "stuff", String.format(command + "%n")); - processBuilder.start(); - } - - /** - * Force terminate a screen session - * - * @param screenName Screen ID - * @throws IOException - */ - public void killScreen(String screenName) throws IOException { - assert screenName != null; - - ProcessBuilder processBuilder = new ProcessBuilder("screen", "-X", "-S", screenName, "quit"); - processBuilder.start(); - } -} diff --git a/server_manager/pom.xml b/server_manager/pom.xml deleted file mode 100644 index 94c769b..0000000 --- a/server_manager/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - arcadexsystem - eu.arcadex.system - ${global.version} - - 4.0.0 - - server_manager - jar - - - - eu.arcadex.system - build_files - ${global.version} - - - eu.arcadex.system - screen - ${global.version} - - - eu.arcadex.system - netty_api - ${global.version} - - - - \ No newline at end of file diff --git a/web_api/pom.xml b/web_api/pom.xml deleted file mode 100644 index bb5d46c..0000000 --- a/web_api/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - arcadexsystem - eu.arcadex.system - ${global.version} - - 4.0.0 - - web_api - jar - - - - eu.arcadex.system - database - ${global.version} - - - eu.arcadex.system - configuration - ${global.version} - - - eu.arcadex.system - server_manager - ${global.version} - - - \ No newline at end of file