Skip to content

Commit

Permalink
Initial docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubenicos committed Aug 17, 2023
1 parent 0b53581 commit c6af9da
Show file tree
Hide file tree
Showing 6 changed files with 539 additions and 1 deletion.
34 changes: 34 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Deploy Docs

on: [workflow_dispatch]

jobs:
docs:
if: ${{ github.repository_owner == 'saicone' }}

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Deploy default docs to Github repository
uses: JamesIves/github-pages-deploy-action@v4.4.1
with:
folder: docs/default
ssh-key: ${{ secrets.DOCS_DEPLOY_KEY }}
git-config-name: github-actions[bot]
git-config-email: 41898282+github-actions[bot]@users.noreply.github.com
repository-name: saicone/docs
branch: main
target-folder: docs/ezlib

- name: Deploy ES docs to Github repository
uses: JamesIves/github-pages-deploy-action@v4.4.1
with:
folder: docs/es
ssh-key: ${{ secrets.DOCS_DEPLOY_KEY }}
git-config-name: github-actions[bot]
git-config-email: 41898282+github-actions[bot]@users.noreply.github.com
repository-name: saicone/docs
branch: main
target-folder: i18n/es/docusaurus-plugin-content-docs/current/ezlib
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ shadowJar {
## Features

### Easy dependency builder
Ezlib allow you to append dependencies into parent class loader and specify repository after load method.
Ezlib allow you to append dependencies into parent class loader and specify repository before load method.
```java
Ezlib ezlib = new Ezlib();
ezlib.init();
Expand Down
164 changes: 164 additions & 0 deletions docs/default/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
---
sidebar_position: 1
title: Ezlib
description: Runtime library/dependency loader & relocator for Java in a single class
---

Welcome to Ezlib wiki, here you will find information about the use of this lightweight library.

## Introduction

Ezib is a library created to provide an easy way to load dependencies of Java projects at runtime, including support for package relocation.

## Requirements

* Minimum **Java 8**

## Dependency

![version](https://img.shields.io/github/v/tag/saicone/ezlib?label=current%20version&style=for-the-badge)

Ezlib it's completely shadeable in your project.

So you can copy the [Ezlib class](https://github.com/saicone/ezlib/blob/master/src/main/java/com/saicone/ezlib/Ezlib.java) or add it as implementación.

```mdx-code-block
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
<Tabs>
<TabItem value="groovy" label="build.gradle" default>
```groovy
plugins {
id 'com.github.johnrengelman.shadow' version '8.1.1'
}
repositories {
maven { url 'https://jitpack.io' }
}
// Use only ezlib
dependencies {
implementation 'com.saicone.ezlib:ezlib:VERSION'
}
// Use ezlib loader instead
dependencies {
implementation 'com.saicone.ezlib:loader:VERSION'
// Use annotations
compileOnly 'com.saicone.ezlib:annotations:VERSION'
annotationProcessor 'com.saicone.ezlib:annotations:VERSION'
}
jar.dependsOn (shadowJar)
shadowJar {
relocate 'com.saicone.ezlib', project.group + '.ezlib'
}
```

</TabItem>
<TabItem value="kotlin" label="build.gradle.kts">

```kotlin
plugins {
id("com.github.johnrengelman.shadow") version "8.1.1"
}

repositories {
maven("https://jitpack.io")
}

// Use only ezlib
dependencies {
implementation("com.saicone.ezlib:ezlib:VERSION")
}

// Use ezlib loader instead
dependencies {
implementation("com.saicone.ezlib:loader:VERSION")
// Use annotations
compileOnly("com.saicone.ezlib:annotations:VERSION")
annotationProcessor("com.saicone.ezlib:annotations:VERSION")
}

tasks {
jar {
dependsOn(tasks.shadowJar)
}

shadowJar {
relocate("com.saicone.ezlib", "${project.group}.ezlib")
}
}
```

</TabItem>
<TabItem value="maven" label="pom.xml">

```xml
<repositories>
<repository>
<id>Jitpack</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
<!-- Use ezlib -->
<dependency>
<groupId>com.saicone.ezlib</groupId>
<artifactId>ezlib</artifactId>
<version>VERSION</version>
<scope>compile</scope>
</dependency>
<!-- Use ezlib loader -->
<dependency>
<groupId>com.saicone.ezlib</groupId>
<artifactId>loader</artifactId>
<version>VERSION</version>
<scope>compile</scope>
</dependency>
<!-- Use annotations -->
<dependency>
<groupId>com.saicone.ezlib</groupId>
<artifactId>annotations</artifactId>
<version>VERSION</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<artifactSet>
<includes>
<include>com.saicone.ezlib:ezlib</include>
<include>com.saicone.ezlib:loader</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>com.saicone.ezlib</pattern>
<shadedPattern>${project.groupId}.ezlib</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</build>
```

</TabItem>
</Tabs>
88 changes: 88 additions & 0 deletions docs/default/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
sidebar_position: 2
title: Usage
description: How to use Ezlib
---

:::info

Ezlib uses a gradle-like dependency format to load them.

:::

## Basic

Ezlib provides an easy method to load all needed dependencies at runtime into class loaders.

Here is an example to load dependencies into a child class loader.

```java
// Create ezlib with default "libs" folder
Ezlib ezlib = new Ezlib();
// Or specify a folder
Ezlib ezlib = new Ezlib(new File("folder/path"));

// Initialize ezlib
ezlib.init();

// Load from maven repository into child class loader
ezlib.dependency("commons-io:commons-io:2.11.0").load();

// Load from specified repository
ezlib.dependency("com.saicone.rtag:rtag:1.3.0").repository("https://jitpack.io/").load();

// You can change default repository
ezlib.setDefaultRepository("repo URL");
```

## Parent ClassLoader

Ezlib allow you to append dependencies into parent class loader and specify repository before load method.

```java
Ezlib ezlib = new Ezlib();
// Initialize ezlib
ezlib.init();

// Load from maven repository into parent class loader
ezlib.dependency("commons-io:commons-io:2.11.0").parent(true).load();

// Load from specified repository
ezlib.dependency("com.saicone.rtag:rtag:1.1.0")
.repository("https://jitpack.io/")
.parent(false)
.load();
```

## Relocation

Ezlib uses [jar-relocator](https://github.com/lucko/jar-relocator), so you can load dependencies with package relocation.

Here an example with Redis library and all the needed dependencies.

```java
Map<String, String> map = new HashMap();
map.put("com.google.gson", "myproject.path.libs.gson");
map.put("org.apache.commons.pool2", "myproject.path.libs.pool2");
map.put("org.json", "myproject.path.libs.json");
map.put("org.slf4j", "myproject.path.libs.slf4j");
map.put("redis.clients.jedis", "myproject.path.libs.jedis");

Ezlib ezlib = new Ezlib();
ezlib.init();

// Load all the needed dependencies first
ezlib.dependency("com.google.gson:gson:2.8.9").relocations(map).parent(true).load();
ezlib.dependency("org.apache.commons:commons-pool2:2.11.1").relocations(map).parent(true).load();
ezlib.dependency("org.json:json:20211205").relocations(map).parent(true).load();
ezlib.dependency("org.slf4j:slf4j-api:1.7.32").relocations(map).parent(true).load();

// Then load redis dependency
ezlib.dependency("redis.clients:jedis:4.2.2").relocations(map).parent(true).load();
```

:::warning

Make sure to relocate the imports during compile time, while excluding the class that you use to load the dependencies because the strings will be relocated too.

:::
Loading

0 comments on commit c6af9da

Please sign in to comment.