Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module loading improvements #1302

Open
wants to merge 1 commit into
base: nightly
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2019-2024 CloudNetService team & contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package eu.cloudnetservice.driver.module;

import lombok.NonNull;

/**
* Represents an exception thrown when there are cyclic dependencies between modules
*
* @since 4.0
*/
public class ModuleCyclicDependenciesException extends RuntimeException {

private final String[] dependencyPath;

public ModuleCyclicDependenciesException(@NonNull String[] dependencyPath) {
this.dependencyPath = dependencyPath;
}

@Override
public String getMessage() {
return "Cyclic dependencies detected: " + String.join(" -> ", this.dependencyPath);
}

public @NonNull String[] dependencyPath() {
return this.dependencyPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,42 @@ public class ModuleDependencyOutdatedException extends RuntimeException {
* @throws NullPointerException if requiringModule, dependency or semverIndex is null.
*/
public ModuleDependencyOutdatedException(
@NonNull ModuleWrapper requiringModule,
@NonNull ModuleConfiguration requiringModule,
@NonNull ModuleDependency dependency,
@NonNull String semverIndex,
int required,
int actual
) {
this(requiringModule.group(), requiringModule.name(), dependency, semverIndex, required, actual);
}

/**
* Creates a new instance of this ModuleDependencyOutdatedException.
*
* @param requiringModuleGroup the group of the module which requires the dependency.
* @param requiringModuleName the name of the module which requires the dependency.
* @param dependency the dependency which is outdated.
* @param semverIndex the semver index name: major, minor, patch
* @param required the required version of the semver index.
* @param actual the actual running version of the semver index.
* @throws NullPointerException if requiringModuleGroup, requiringModuleName, dependency or semverIndex is null.
*/
public ModuleDependencyOutdatedException(
@NonNull String requiringModuleGroup,
@NonNull String requiringModuleName,
@NonNull ModuleDependency dependency,
@NonNull String semverIndex,
int required,
int actual
) {
super(String.format(
"Module %s:%s requires minimum %s version %d of %s:%s but is currently %d",
requiringModule.module().group(), requiringModule.module().name(),
requiringModuleGroup, requiringModuleName,
semverIndex,
required,
dependency.group(), dependency.name(),
actual
));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public interface ModuleProvider {
* @param url the url to load the module from.
* @return the loaded module or null if checks failed or a module from this url is already loaded.
* @throws ModuleConfigurationNotFoundException if the file associated with the url doesn't contain a module.json.
* @throws ModuleDependencyNotFoundException if a dependency module is not loaded.
* @throws NullPointerException if required properties are missing in dependency or repository
* information.
* @throws AssertionError if any exception occurs during the load of the module.
Expand All @@ -152,11 +153,12 @@ public interface ModuleProvider {
* Loads all modules which files are located at the module directory.
*
* @return the same instance of the class, for chaining.
* @throws ModuleCyclicDependenciesException if cyclic dependencies are detected
* @see ModuleWrapper#moduleLifeCycle()
* @see ModuleLifeCycle#canChangeTo(ModuleLifeCycle)
*/
@NonNull
ModuleProvider loadAll();
ModuleProvider loadAll() throws ModuleCyclicDependenciesException;

/**
* Starts all modules which are loaded by this provided and can change to the started state.
Expand Down
Loading