Skip to content

Commit

Permalink
fix: compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
Vortezz committed Aug 25, 2024
1 parent 05573c7 commit 6711e29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ val nexusPass = System.getenv()["NEXUS_PASS"]
val isInCi = nexusUser != null && nexusPass != null

group = "fr.ekalia.injector"
version = "1.1.0" + if (isRelease) "" else "-SNAPSHOT"
version = "1.1.2" + if (isRelease) "" else "-SNAPSHOT"

System.out.println("Version: " + version + ", nexusUser null? " + (nexusUser == null) + ", nexusPass null? " + (nexusPass == null));

Expand Down
18 changes: 10 additions & 8 deletions src/main/java/fr/ekalia/injector/Injector.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2024 Ekalia <[email protected]>
*
*
* 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
*
*
* https://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.
Expand Down Expand Up @@ -34,6 +34,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
Expand Down Expand Up @@ -65,7 +66,7 @@ public Injector() {
* @param instance The instance to register.
*/
public void registerInjection(@NotNull Object instance) {
this.registerInjection(injection, InjectPriority.NORMAL);
this.registerInjection(instance, InjectPriority.NORMAL);
}

/**
Expand Down Expand Up @@ -196,7 +197,8 @@ private void loadProvidesClass(Class<?> aClass, Map<Class<?>, InjectPriority> pr
}
} catch (NoClassDefFoundError e) {
Injector.LOGGER.error(Injector.CANNOT_LOAD_PROVIDED_CLASS, aClass.getName(), e.getMessage());
} catch (Throwable t) { //NOSONAR We want to catch all exceptions and throwables as ClassGraph throws Throwables and not Exceptions
} catch (
Throwable t) { //NOSONAR We want to catch all exceptions and throwables as ClassGraph throws Throwables and not Exceptions
Injector.LOGGER.error(Injector.CANNOT_LOAD_PROVIDED_CLASS, t, aClass.getName(), t.getMessage());
}
}
Expand Down Expand Up @@ -243,12 +245,12 @@ public void injectAtRuntime(Object instance, String packageName, ClassLoader cla
@SuppressWarnings("java:S3011") // "Make sure that this accessibility update is safe here."
private void injectIntoField(Field field) throws IllegalAccessException {
if (!field.isAnnotationPresent(Inject.class)) {
continue;
return;
}

// Try to access field via reflection
if (!field.trySetAccessible()) {
continue;
return;
}

Object optimalValue = null;
Expand Down Expand Up @@ -303,8 +305,8 @@ public ClassGraph getClassGraph() {
* Get the injected object for the given class
*
* @param clazz The class type
* @param <T> The object type
* @return An {@link Optional} that contains the injected object for the given class, if present
* @param <T> The object type
*/
public <T> Optional<T> get(Class<T> clazz) {
return Optional.ofNullable(this.classes.get(clazz)).map(Tuple2::getT2).map(clazz::cast);
Expand Down

0 comments on commit 6711e29

Please sign in to comment.