Skip to content

Commit

Permalink
Merge pull request #3 from breadrock1/fix/fix-native-lib-including
Browse files Browse the repository at this point in the history
Fix: Unpack and load native libraries
  • Loading branch information
breadrock1 authored Jul 9, 2024
2 parents 435927f + a75b741 commit 1b5596e
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 152 deletions.
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

0 comments on commit 1b5596e

Please sign in to comment.