Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
ardikars committed Aug 30, 2018
2 parents a33fb94 + 3683937 commit 7bbd458
Show file tree
Hide file tree
Showing 47 changed files with 827 additions and 1,106 deletions.
2 changes: 1 addition & 1 deletion .appveyor/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ install:

build_script:
- cmd: set PATH=C:\tools\mingw64\bin;C:\Program Files (x86)\NSIS\;%PATH%
- cmd: gradlew.bat clean build -x test --info --no-daemon
- cmd: gradlew.bat clean build jacocoTestReport coveralls --info --no-daemon

#---------------------------------#
# notifications #
Expand Down
5 changes: 2 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ jobs:
- checkout
- run: 'export TERM=xterm-color'
- run: 'sudo apt-get update && sudo apt-get install gcc libpcap-dev -y'
#- run: 'ping -c 10000 google.com &'
- run: 'sudo ./gradlew clean build -x test --info --no-daemon'
- run: './gradlew clean build -x test --info --no-daemon'

deploy:
working_directory: ~/tmp/Jxnet
Expand Down Expand Up @@ -54,4 +53,4 @@ workflows:
filters:
branches:
only:
- v1
- v1
16 changes: 8 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ a.out
/jxnet-core/build
/jxnet-core/target
/jxnet-core/out
/jxnet-static/.gradle
/jxnet-static/build
/jxnet-static/target
/jxnet-static/out
/jxnet-dynamic/.gradle
/jxnet-dynamic/build
/jxnet-dynamic/target
/jxnet-dynamic/out
/jxnet-spring-boot-autoconfigure/.gradle
/jxnet-spring-boot-autoconfigure/build/
/jxnet-spring-boot-autoconfigure/target
/jxnet-spring-boot-autoconfigure/out
/jxnet-spring-boot-starter/.gradle
/jxnet-spring-boot-starter/build/
/jxnet-spring-boot-starter/target
/jxnet-spring-boot-starter/out
/jxnet-android/.gradle
/jxnet-android/build/
/jxnet-android/target
Expand Down
17 changes: 17 additions & 0 deletions .scripts/InstallCodacyDeployer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

#---------------------------------#
# general configuration #
#---------------------------------#

if (Test-Path "C:\tools\codacy.jar") {
echo "Codacy is already installed"
} else {
$urlPath = "https://github.com/codacy/codacy-coverage-reporter/releases/download/4.0.2/codacy-coverage-reporter-4.0.2-assembly.jar"

# Download the file
echo "Downloading... ($urlPath)"
wget $urlPath -UseBasicParsing -OutFile "C:\tools\codacy.jar"

echo "Installing Codacy..."
echo "Codacy has been installed."
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Jxnet is a Java library for capturing and sending custom network packet buffers
Jxnet wraps a native packet capture library (libpcap/npcap) via JNI (Java Native Interface).

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4d6ca7f3d9214098b1436990ac76a6cd)](https://www.codacy.com/project/jxnet/Jxnet/dashboard?utm_source=github.com&utm_medium=referral&utm_content=jxnet/Jxnet&utm_campaign=Badge_Grade_Dashboard)
[![CircleCI](https://circleci.com/gh/jxnet/Jxnet/tree/master.svg?style=svg)](https://circleci.com/gh/jxnet/Jxnet/tree/master)
[![Coverage Status](https://coveralls.io/repos/github/jxnet/Jxnet/badge.svg?branch=)](https://coveralls.io/github/jxnet/Jxnet?branch=)
[![Build status](https://ci.appveyor.com/api/projects/status/ev4t6t1ssacwj18j?svg=true)](https://ci.appveyor.com/project/jxnet/jxnet)

[ ![Download](https://api.bintray.com/packages/ardikars/maven/com.ardikars.jxnet/images/download.svg?version=1.3.0.Final) ](https://bintray.com/ardikars/maven/com.ardikars.jxnet/1.3.0.Final/link)
Expand Down
56 changes: 36 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ buildscript {
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.2'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2'
}

}
Expand All @@ -32,6 +33,7 @@ subprojects {
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'com.github.spotbugs'
apply plugin: 'com.github.kt3k.coveralls'

group = "${GROUP}"
version = "${VERSION}"
Expand All @@ -46,8 +48,8 @@ subprojects {
}

dependencies {
compile('com.ardikars.common:common-net:1.2.0.RC1')
compile 'com.ardikars.common:common-util:1.2.0.RC1'
compile('com.ardikars.common:common-net:1.2.0.RC2')
compile 'com.ardikars.common:common-util:1.2.0.RC2'
}

configurations.archives.artifacts.with { archives ->
Expand All @@ -62,6 +64,13 @@ subprojects {

evaluationDependsOn(project.path)

jar {
manifest {
attributes 'Implementation-Title': 'Jxnet',
'Implementation-Version': version
}
}

javadoc {
def currentYear = Calendar.getInstance().get Calendar.YEAR
options.with {
Expand Down Expand Up @@ -128,10 +137,28 @@ subprojects {
toolVersion "${PMD_VERION}"
}

jacoco {
toolVersion = "${JACOCO_VERSION}"
}

jacocoTestReport {
reports {
xml.enabled true
csv.enabled false
html.destination file("${buildDir}/jacocoHtml")
}
}


test {
testLogging {
showStandardStreams = true
}
jacoco {
append = false
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
classDumpDir = file("$buildDir/jacoco/classpathdumps")
}
}

task javadocJar(type: Jar) {
Expand Down Expand Up @@ -212,30 +239,19 @@ subprojects {
file("${rootDir}/${project.name}/out").deleteDir()
}

/**
* Upload converage report
*/
tasks.coveralls {
dependsOn 'check'
}

} else {
apply plugin: 'c'
}

}

task codeCoverageReport(type: JacocoReport) {
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
subprojects.each { subproject ->
if (!(subproject.name.equals("${rootProject.name}")) && !((subproject.name).equals("jxnet-native"))) {
sourceSets subproject.sourceSets.main
}
}
reports {
xml.enabled false
html.enabled true
csv.enabled false
}
}

codeCoverageReport.dependsOn {
subprojects*.test
}

task ndkBuild(type: Exec) {
commandLine "${NDK_HOME}/ndk-build", '-C', "${TOOLS_DIR}",
"NDK_LIBS_OUT=${TOOLS_OUT}", "NDK_OUT=${TOOLS_OBJ}"
Expand Down
3 changes: 2 additions & 1 deletion gradle/configure.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ext {

NAME = 'Jxnet'
GROUP = 'com.ardikars.jxnet'
VERSION = '1.4.0.RC1'
VERSION = '1.4.0.RC2'

NDK_HOME = "${System.env.NDK_HOME}"
TOOLS_DIR = "${rootDir}/tools"
Expand All @@ -28,6 +28,7 @@ ext {
CHECKSTYLE_VERSION = '8.10.1'
SPOTBUGS_VERSION = '3.1.5'
PMD_VERION = '6.5.0'
JACOCO_VERSION = '0.8.2'

pom_project = {

Expand Down
9 changes: 9 additions & 0 deletions gradle/resources/findbugs/findbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@
<Class name="com.ardikars.jxnet.util.DefaultLibraryLoader"/>
<Bug pattern="DMI_HARDCODED_ABSOLUTE_FILENAME"/>
</Match>
<Match>
<Bug pattern="UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR"/>
</Match>
<Match>
<Bug pattern="UWF_UNWRITTEN_FIELD"/>
</Match>
<Match>
<Bug pattern="UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD"/>
</Match>
</FindBugsFilter>
Binary file added gradle/resources/pcap/icmp.pcap
Binary file not shown.
101 changes: 8 additions & 93 deletions jxnet-context/src/main/java/com/ardikars/jxnet/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,116 +17,31 @@

package com.ardikars.jxnet;

import com.ardikars.common.util.Callback;
import com.ardikars.common.util.Loader;

import java.util.logging.Logger;
import com.ardikars.common.util.Builder;
import com.ardikars.common.util.Validate;

/**
* @author Ardika Rommy Sanjaya
* @since 1.1.5
*/
public final class Application {

private static final Logger LOGGER = Logger.getLogger(Application.class.getName());

private boolean loaded;
private boolean developmentMode;

private static final Application instance = new Application();

private Context context;

public boolean isLoaded() {
return this.loaded;
}

/**
* Enable development mode will be force to use default installed library on the system.
*/
public void enableDevelopmentMode() {
this.developmentMode = true;
}

private Application() {

}

/**
* Used for bootstraping Jxnet.
* @param applicationName application name.
* @param applicationVersion application version.
* @param initializerClass initializer class.
* @param pcapBuilder pcap builder.
* @param argements additional information.
* @throws UnsatisfiedLinkError UnsatisfiedLinkError.
*/
@SuppressWarnings("PMD.AvoidUsingNativeCode")
public static void run(final String applicationName, final String applicationVersion, Class initializerClass,
final Pcap.Builder pcapBuilder,
final Object argements) {
run(applicationName, applicationVersion, initializerClass, pcapBuilder, null, argements);
}

/**
* Used for bootstraping Jxnet.
* @param applicationName application name.
* @param applicationVersion application version.
* @param initializerClass initializer class.
* @param pcapBuilder pcap builder.
* @param bpfBuilder bpf builder.
* @param argements additional information.
* @throws UnsatisfiedLinkError UnsatisfiedLinkError.
* Bootstraping application.
* @param builder pcap builder.
*/
@SuppressWarnings("PMD.AvoidUsingNativeCode")
public static void run(final String applicationName, final String applicationVersion, Class initializerClass,
final Pcap.Builder pcapBuilder, final BpfProgram.Builder bpfBuilder,
final Object argements) {

ApplicationInitializer initializer;
Loader<Void> libraryLoaders;
try {
initializer = (ApplicationInitializer) initializerClass.newInstance();
libraryLoaders = initializer.initialize(argements);
} catch (InstantiationException e) {
LOGGER.warning(e.getMessage());
return;
} catch (IllegalAccessException e) {
LOGGER.warning(e.getMessage());
return;
}

if (instance.developmentMode && !instance.loaded) {
try {
System.loadLibrary("jxnet");
instance.loaded = true;
} catch (Exception e) {
instance.loaded = false;
}
} else {
if (!instance.loaded && libraryLoaders != null) {
libraryLoaders.load(new Callback() {
@Override
public void onSuccess(Object value) {
instance.loaded = true;
Pcap pcap = pcapBuilder.build();
if (bpfBuilder != null) {
BpfProgram bpfProgram = bpfBuilder.pcap(pcap).build();
instance.context = ApplicationContext
.newApplicationContext(applicationName, applicationVersion, argements, pcap, bpfProgram);
} else {
instance.context = ApplicationContext
.newApplicationContext(applicationName, applicationVersion, argements, pcap, null);
}
}

@Override
public void onFailure(Throwable throwable) {
LOGGER.warning(throwable.getMessage());
}
});
}
}
public static void run(Builder<Pcap, Void> builder) {
Validate.notIllegalArgument(builder != null,
new IllegalArgumentException("Pcap builder should be not null."));
instance.context = new ApplicationContext(builder);
}

/**
Expand Down
Loading

0 comments on commit 7bbd458

Please sign in to comment.