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

Initial Testing Setup #19

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
23 changes: 14 additions & 9 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion mayflower/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,21 @@ dependencies {
api("io.micronaut", "micronaut-context")

compileOnly(libs.paper)
}

testAnnotationProcessor("io.micronaut:micronaut-inject-java")
testAnnotationProcessor(project(":mayflower"))
testAnnotationProcessor(libs.paper)

testImplementation(libs.paper)
testImplementation("com.github.seeseemelk", "MockBukkit-v1.19", "2.144.4")
testImplementation("org.junit.jupiter", "junit-jupiter", "5.8.2")
testImplementation("org.assertj", "assertj-core", "3.22.0")
testImplementation("ch.qos.logback", "logback-classic", "1.4.5")
testImplementation("com.gitlab.taucher2003.t2003-utils", "log", "1.1-alpha.20")
}

tasks {
test {
useJUnitPlatform()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2023 original authors
*
* 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 io.github.madethoughts.mayflower.configuration;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

/**
Implementations of this interface are config migrations, which will update the config from one to the next specific
version. After all migrations, the config is written back to the file.
@see Migration
*/
@FunctionalInterface
public interface ConfigMigration {
/**
@param config The current configuration, returned from {@link JavaPlugin#getConfig()} and modified by previous
migrations. The default version of this {@link FileConfiguration} is the jar's one. That one generated at
compile time from your {@link PluginConfig} classes.
*/
void migrate(FileConfiguration config);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2023 original authors
*
* 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 io.github.madethoughts.mayflower.configuration;

import io.github.madethoughts.mayflower.plugin.MayflowerPlugin;
import io.micronaut.context.env.PropertySource;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Iterator;

/**
Loads values from the plugin config.
*/
public class ConfigPropertySource implements PropertySource {
private final MayflowerPlugin mayflowerPlugin;

/**
@param mayflowerPlugin The {@link MayflowerPlugin} instance
*/
public ConfigPropertySource(MayflowerPlugin mayflowerPlugin) {
this.mayflowerPlugin = mayflowerPlugin;
}

@Override
public String getName() {
return "Plugin config";
}

@Override
public @Nullable Object get(String key) {
if (!key.startsWith(PluginConfig.PLUGIN_PREFIX)) return null;
// normally we have to subtract one from the position, but we need to remove the . after the plugin prefix,
// so we're actually adding one position if we don't subtract one
return mayflowerPlugin.getConfig().get(key.substring(PluginConfig.PLUGIN_PREFIX.length()));
}

@NotNull
@Override
public Iterator<String> iterator() {
return mayflowerPlugin.getConfig().getKeys(true)
.stream()
.map("plugin.%s"::formatted)
.iterator();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2023 original authors
*
* 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 io.github.madethoughts.mayflower.configuration;

import io.micronaut.context.annotation.AliasFor;
import io.micronaut.core.bind.annotation.Bindable;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
This annotation defines the default value of a configuration entry.
It's the same as using {@link Bindable#defaultValue()}
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.ANNOTATION_TYPE, ElementType.PARAMETER, ElementType.METHOD})
@Bindable
public @interface Default {
/**
@return The default value
*/
@AliasFor(annotation = Bindable.class, member = "defaultValue")
String value();
}
Loading