This repository has been archived by the owner on Mar 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
163 additions
and
16 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
27 changes: 27 additions & 0 deletions
27
api/src/main/java/fr/atlasworld/network/api/file/FileOwner.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,27 @@ | ||
package fr.atlasworld.network.api.file; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Member of AtlasNetworks file api, This is not a file system owner! | ||
* <p> | ||
* FileOwner are used by the cleanup system to prevent deletion of used files or directories. | ||
* File can be registered by a module when its activating. | ||
* @see fr.atlasworld.network.api.file.FileManager | ||
*/ | ||
public interface FileOwner { | ||
|
||
/** | ||
* Unique ID of the owner, your module ID is being used here. | ||
*/ | ||
@NotNull | ||
String ownerId(); | ||
|
||
/** | ||
* Checks if this owner allows other owners to read/write to file registered by him by default. | ||
* AtlasNetwork Core System will always have access to the owner's files. | ||
*/ | ||
boolean allowsExternalOwnerUsage(); | ||
|
||
|
||
} |
35 changes: 35 additions & 0 deletions
35
api/src/main/java/fr/atlasworld/network/api/file/RegisteredFile.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,35 @@ | ||
package fr.atlasworld.network.api.file; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Registered File information. | ||
*/ | ||
public interface RegisteredFile { | ||
|
||
/** | ||
* Retrieve the file owner. | ||
* @return null if the file does not have an owner. | ||
*/ | ||
@Nullable | ||
FileOwner getOwner(); | ||
|
||
/** | ||
* Get the file. | ||
*/ | ||
@NotNull | ||
File sourceFile(); | ||
|
||
/** | ||
* Checks if reading the file is allowed. | ||
*/ | ||
boolean readAllowed(); | ||
|
||
/** | ||
* Checks if writing to the file is allowed. | ||
*/ | ||
boolean writeAllowed(); | ||
} |
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 |
---|---|---|
@@ -1,14 +1,25 @@ | ||
package fr.atlasworld.network.core; | ||
|
||
import fr.atlasworld.network.api.AtlasNetworkServer; | ||
import fr.atlasworld.network.api.file.FileManager; | ||
import fr.atlasworld.network.boot.LaunchArgs; | ||
import fr.atlasworld.network.core.module.ModuleManager; | ||
|
||
public class AtlasNetwork { | ||
public class AtlasNetwork implements AtlasNetworkServer { | ||
private final FileManager fileManager; | ||
|
||
private AtlasNetwork(final LaunchArgs args) { | ||
ModuleManager moduleManager = ModuleManager.init(args); | ||
moduleManager.load(); | ||
|
||
//Module Manager -> Load Modules -> Done Later once AtlasNetwork is initialized | ||
moduleManager.initialize(); | ||
|
||
|
||
} | ||
|
||
@Override | ||
public FileManager getFileManager() { | ||
return | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/fr/atlasworld/network/core/file/SystemFileManager.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,52 @@ | ||
package fr.atlasworld.network.core.file; | ||
|
||
import fr.atlasworld.network.api.file.FileManager; | ||
import fr.atlasworld.network.api.file.configuration.ConfigurationFile; | ||
import fr.atlasworld.network.api.file.configuration.ConfigurationReader; | ||
import fr.atlasworld.network.api.file.configuration.ConfigurationSchema; | ||
import fr.atlasworld.network.api.file.exception.unchecked.FileRegistrationException; | ||
import fr.atlasworld.network.api.module.Module; | ||
import fr.atlasworld.network.boot.LaunchArgs; | ||
|
||
import java.io.File; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class SystemFileManager implements FileManager { | ||
private final Map<File, Module> registeredFilesMap = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public void registerModuleFile(Module module, File file) throws FileRegistrationException { | ||
this.registeredFilesMap.containsKey(file) | ||
} | ||
|
||
@Override | ||
public <T extends ConfigurationFile> ConfigurationReader<T> registerConfiguration(Module module, ConfigurationSchema<T> schema) throws FileRegistrationException { | ||
String filename = schema.filepath().endsWith(".json") ? schema.filepath() : schema.filepath() + ".json"; | ||
File configurationFile = SystemFileManager.getConfigurationFile(filename); | ||
|
||
this.registerModuleFile(module, configurationFile); // Try to register the file | ||
|
||
|
||
} | ||
|
||
// Static fields | ||
public static final File WORKING_DIRECTORY = new File(System.getProperty("user.dir")); | ||
|
||
public static File getDataDirectory() { | ||
return LaunchArgs.getArguments().getDataDirectory(); | ||
} | ||
|
||
public static File getModuleDirectory() { | ||
return LaunchArgs.getArguments().getModuleDirectory(); | ||
} | ||
|
||
public static File getConfigurationDirectory() { | ||
return LaunchArgs.getArguments().getConfigurationDirectory(); | ||
} | ||
|
||
public static File getConfigurationFile(String name) { | ||
return new File(getConfigurationDirectory(), name); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/fr/atlasworld/network/core/module/lifecycle/ModuleActivateContextImpl.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 |
---|---|---|
@@ -1,6 +1,17 @@ | ||
package fr.atlasworld.network.core.module.lifecycle; | ||
|
||
import fr.atlasworld.network.api.AtlasNetworkServer; | ||
import fr.atlasworld.network.api.module.lifecycle.ModuleActivationContext; | ||
|
||
public class ModuleActivateContextImpl implements ModuleActivationContext { | ||
private final AtlasNetworkServer server; | ||
|
||
public ModuleActivateContextImpl(AtlasNetworkServer server) { | ||
this.server = server; | ||
} | ||
|
||
@Override | ||
public AtlasNetworkServer getServer() { | ||
return this.server; | ||
} | ||
} |
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