Skip to content

Commit

Permalink
fix: add license headers, add comments, and fix issues
Browse files Browse the repository at this point in the history
fix: add license headers, add comments, and fix issues
  • Loading branch information
Vortezz authored Aug 25, 2024
2 parents f1bf63d + ec9716f commit 4b52315
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 521 deletions.
38 changes: 1 addition & 37 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
.idea
39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

[![Release version](https://img.shields.io/nexus/maven-releases/fr.ekalia.injector/ekalia-injector?server=https%3A%2F%2Fnexus.ekalia.fr&label=Release&color=green&link=https%3A%2F%2Fnexus.ekalia.fr%2F%23browse%2Fbrowse%3Amaven-release%3Afr%252Fekalia%252Finjector%252Fekalia-injector)](https://nexus.ekalia.fr/#browse/browse:maven-releases:fr%2Fekalia%2Finjector%2Fekalia-injector) [![Snapshot Version](https://img.shields.io/nexus/maven-snapshots/fr.ekalia.injector/ekalia-injector?server=https%3A%2F%2Fnexus.ekalia.fr&label=Snapshot&color=blue&link=https%3A%2F%2Fnexus.ekalia.fr%2F%23browse%2Fbrowse%3Amaven-public%3Afr%252Fekalia%252Finjector%252Fekalia-injector)](https://nexus.ekalia.fr/#browse/browse:maven-snapshots:fr%2Fekalia%2Finjector%2Fekalia-injector)

This is an object injector for Java programs that is used to inject objects into static fields of classes, instead of
passing them as arguments to constructors. This is useful when you have a lot of classes that need to access the same
object, but you don't want to pass it as an argument to every constructor.
This is an object injector for Java programs that is used to inject objects into static fields of classes, instead of passing them as arguments to constructors. This is useful when you have a lot of classes that need to access the same object, but you don't want to pass it as an argument to every constructor.

## Installation

Expand Down Expand Up @@ -38,6 +36,7 @@ If you use Maven you should use the following code :

If you use Gradle you should use the following code :

Groovy:
```groovy
repositories {
maven {
Expand All @@ -50,6 +49,17 @@ dependencies {
}
```

Kts:
```groovy
repositories {
maven("https://nexus.ekalia.fr/repository/maven-public/")
}
dependencies {
compileOnly("fr.ekalia.injector:ekalia-injector:latest")
}
```

## Use injector

In order to use the injector, you need to create an instance of the `Injector` class.
Expand All @@ -67,14 +77,11 @@ injector.addClassLoader(myClassLoader);
Then you can start the injector:

```java
injector.startInjection(currentClassLoader, "my.really.cool.package");
injector.

startInjection(myClassLoader, "my.really.cool.package","my.other.cool.package");
ClassLoader currentClassLoader = this.getClass().getClassLoader();
injector.startInjection(currentClassLoader, "my.really.cool.package", "my.other.cool.package");
```

When you start the injector, it will scan all the classes in the class loaders and inject the provided classes into the
fields of the classes that have the `@Inject` annotation.
When you start the injector, it will scan all the classes in the class loaders and inject the provided classes into the fields of the classes that have the `@Inject` annotation.

### Provide a class

Expand All @@ -101,8 +108,7 @@ If you want to provide the class manually, you can use the `registerInjection` m
injector.registerInjection(myProvidedClassInstance);
```

If you want to set a priority (see below for explanations about priority) for the provided class, you can use the
`registerInjection` method like this:
If you want to set a priority (see below for explanations about priority) for the provided class, you can use the `registerInjection` method like this:

```java
injector.registerInjection(myProvidedClassInstance, InjectPriority.HIGH);
Expand All @@ -116,7 +122,7 @@ To mark a field for injection, you need to use the `@Inject` annotation like thi
public class MyClass {

@Inject
private MyProvidedClass myProvidedClass;
private static MyProvidedClass myProvidedClass;

// ...
}
Expand All @@ -126,8 +132,7 @@ When you start the injector, it will automatically inject the provided class int

### Priority

The injector uses priorities to determine which provided class to inject into a field. The default priority is
`InjectPriority.NORMAL`.
The injector uses priorities to determine which provided class to inject into a field. The default priority is `InjectPriority.NORMAL`.

The priorities are:

Expand All @@ -137,8 +142,7 @@ The priorities are:
- `InjectPriority.HIGH`
- `InjectPriority.HIGHEST`

The order of priorities is from **lowest** to **highest**: if a field has multiple provided classes with different
priorities, the one with the lowest priority will be injected.
The order of priorities is from **lowest** to **highest**: if a field has multiple provided classes with different priorities, the one with the highest priority will be injected.

You can set the priority of a provided class when you register it with the injector or in the `@Provides` annotation:

Expand All @@ -151,8 +155,7 @@ public class MyProvidedClass {

## Contributing

Issues and pull requests are welcome. For major changes, please open an issue first to discuss what you would like to
change.
Issues and pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

## License

Expand Down
31 changes: 20 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
/*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id("java")
id("java-library")
id("net.linguica.maven-settings") version "0.5"
id("maven-publish")
}
Expand All @@ -11,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.3" + if (isRelease) "" else "-SNAPSHOT"

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

Expand Down Expand Up @@ -46,15 +63,7 @@ publishing {
}

dependencies {
implementation("io.github.classgraph:classgraph:4.8.174")
implementation("org.apache.logging.log4j:log4j-core:2.23.1")
api("io.github.classgraph:classgraph:4.8.174")
implementation("org.apache.logging.log4j:log4j-api:2.23.1")
implementation("org.jetbrains:annotations:24.0.0")

testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
compileOnly("org.jetbrains:annotations:24.0.0")
}

tasks.test {
useJUnitPlatform()
}
Empty file modified gradlew
100644 → 100755
Empty file.
16 changes: 16 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
/*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

rootProject.name = "ekalia-injector"

Loading

0 comments on commit 4b52315

Please sign in to comment.