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

Fix: Unpack and load native libraries #3

Merged
merged 6 commits into from
Jul 9, 2024
Merged
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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
**Full Changelog**: https://github.com/breadrock1/Adblock-coffee/compare/adblock-coffee-1.0.3...adblock-coffee-1.0.4
## What's Changed
* Improve: Added example by @breadrock1 in https://github.com/breadrock1/Adblock-coffee/pull/2
* Fix: Unpack and load native libraries @breadrock1 in https://github.com/breadrock1/Adblock-coffee/pull/3


**Full Changelog**: https://github.com/breadrock1/Adblock-coffee/compare/adblock-coffee-1.0.3...adblock-coffee-1.0.5
99 changes: 65 additions & 34 deletions examples/simple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<name>simple</name>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.example.simple.App</start-class>
Expand All @@ -25,43 +26,73 @@
<dependency>
<groupId>com.example.adblock</groupId>
<artifactId>adblock-coffee</artifactId>
<version>1.0.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/adblock-coffee-1.0.3.jar</systemPath>
<version>1.0.4</version>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>
com.example.simple.App
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<argLine>-Djava.library.path=${project.basedir}/target/lib/</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.example.adblock</groupId>
<artifactId>adblock-coffee</artifactId>
<version>1.0.4</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<argLine>-Djava.library.path=${project.build.directory}/lib</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>
com.example.simple.App
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
27 changes: 18 additions & 9 deletions examples/simple/src/main/java/com/example/simple/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
import java.util.ArrayList;
import java.util.List;

import com.example.adblock.AdvtBlocker;
//import com.example.adblock.AdvtBlocker;

/**
* Simple example!
*/
public class App {
static {
try {
System.loadLibrary("adblock_coffee");
System.out.println("dfgdfg");
} catch (UnsatisfiedLinkError ex) {
System.err.println(ex.getMessage());
}
}

public static void main(String[] args) {
List<String> rules = new ArrayList<>(List.of(
"-advertisement-icon.",
Expand All @@ -17,13 +26,13 @@ public static void main(String[] args) {
"-advertisement/script."
));

AdvtBlocker blocker = AdvtBlocker.createInstance(rules);
boolean result = blocker.checkUrls(
"http://example.com/-advertisement-icon.",
"http://example.com/helloworld",
"image"
);

System.out.println(result);
// AdvtBlocker blocker = AdvtBlocker.createInstance(rules);
// boolean result = blocker.checkUrls(
// "http://example.com/-advertisement-icon.",
// "http://example.com/helloworld",
// "image"
// );
//
// System.out.println(result);
}
}
Loading