Skip to content

Commit

Permalink
Change structure of project to allow Gradle import from IDEs and chan…
Browse files Browse the repository at this point in the history
…ge build to produce Jar as library and do copy dependencies
  • Loading branch information
Maxim Amelchenko committed Dec 25, 2017
1 parent 7b074e4 commit 19e7d61
Show file tree
Hide file tree
Showing 26 changed files with 107 additions and 99 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ Written in Java 8.

Built with Gradle.

# Installation

Get the code and build:

```
git clone https://github.com/maxmale/GDH.git
cd GDH
gradle clean build
```

Get the generated Jar from the root of the project. Add it to the build path of your project and start using it.

# Usage

The basic usage of the library is spinning up verticles and initiating a key exchange between them.
Expand Down
15 changes: 6 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apply plugin: 'findbugs'
}

libsDirName = '../'
version = '0.91'
version = '0.92'
archivesBaseName = 'GDH'

repositories {
Expand Down Expand Up @@ -48,14 +48,15 @@ clean {
delete "libs/"
delete "build/"
delete "bin/"
delete "GDH-1.1.jar"
delete project.name+"-"+project.version+".jar"
}

jar {
dependsOn configurations.runtime
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes 'Main-Class': 'main.java.gdh.Main'
attributes 'Implementation-Title': project.name,
'Implementation-Version': project.version
}
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
Expand All @@ -65,14 +66,10 @@ jar {
task testSuite(type: Test) {
include '**VertxTestSuite.class'
}
task copyDeps(type: Copy) {
into 'libs'
from configurations.testRuntime
}

task deleteBuild(type: Delete) {
delete "build/"
delete "bin/"
}
copyDeps.dependsOn(testSuite)

build.dependsOn(deleteBuild)
deleteBuild.dependsOn(copyDeps)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.crypto;
package com.gdh.crypto;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.crypto;
package com.gdh.crypto;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -17,7 +17,7 @@
import javax.crypto.spec.IvParameterSpec;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import main.java.gdh.Constants;
import com.gdh.main.Constants;

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.gdh;
package com.gdh.main;

import java.io.OutputStreamWriter;
import java.io.PrintWriter;
Expand Down Expand Up @@ -37,7 +37,7 @@
*/
public class Configuration {
private String IP = "localhost";
private String port = "1080";
private String port = "1090";
private int retries = 5;
private int exchangeTimeout = 60000;
private String prime = "AD107E1E9123A9D0D660FAA79559C51FA20D64E5683B9FD1B54B1597B61D0A75E6FA141DF95A56DBAF9A3C"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.gdh;
package com.gdh.main;

public final class Constants {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.gdh;
package com.gdh.main;

import java.math.BigInteger;
import java.security.SecureRandom;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.gdh;
package com.gdh.main;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -17,9 +17,9 @@
import io.vertx.core.net.NetServer;
import io.vertx.core.net.NetServerOptions;
import io.vertx.core.net.NetSocket;
import main.java.parser.JsonMessageParser;
import main.java.parser.MessageConstructor;
import main.java.parser.MessageParser;
import com.gdh.parser.JsonMessageParser;
import com.gdh.parser.MessageConstructor;
import com.gdh.parser.MessageParser;

import java.math.BigInteger;

Expand Down Expand Up @@ -86,7 +86,7 @@ public void start(Future<Void> future) throws Exception {
conf.getLogger().info(getNode().toString() + " started listening on: " + conf.getPort());
} else {
future.fail(res.cause());
conf.getLogger().info(getNode().toString() + " startup failure: " + conf.getPort());
conf.getLogger().info(getNode().toString() + " startup failure: " + conf.getPort() + " " + res.cause().getMessage());
}
});

Expand Down Expand Up @@ -251,13 +251,13 @@ private CompletableFuture<Boolean> sendMessage(Node n, JsonObject msg) {
if (timingAndRetries[1] == conf.getRetries()) {
// No more retries left. Exit...
conf.getLogger().error(getNode().toString() + " Retry parameter exceeded " + conf.getRetries());
future.completeExceptionally(
new TimeoutException(Constants.EXCEPTIONRETRIESEXCEEDED + conf.getRetries()));
if (socket != null)
socket.close();
vertx.cancelTimer(timingAndRetries[0]);
tcpClient.close();
server.close();
future.completeExceptionally(
new TimeoutException(Constants.EXCEPTIONRETRIESEXCEEDED + conf.getRetries()));
}
}));
}));
Expand All @@ -272,7 +272,7 @@ public void stop(Future<Void> future) throws Exception {
conf.getLogger().info(getNode().toString() + " stopped listening on: " + conf.getPort());
} else {
future.fail(res.cause());
conf.getLogger().info(getNode().toString() + " stoppage failure: " + conf.getPort());
conf.getLogger().info(getNode().toString() + " stoppage failure: " + conf.getPort() + res.cause().getMessage());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.gdh;
package com.gdh.main;

import java.math.BigInteger;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.gdh;
package com.gdh.main;

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.gdh;
package com.gdh.main;

import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
Expand All @@ -19,7 +19,7 @@ public void run(GDHVertex gdh) {
}

/**
* Deploy a gdh verticle and register a handler for the result
* Deploy a com.gdh.main verticle and register a handler for the result
*
* @param gdh
* the GDHVertex to be deployed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.parser;
package com.gdh.parser;

import java.math.BigInteger;
import java.util.Iterator;
Expand All @@ -7,10 +7,10 @@

import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import main.java.gdh.Constants;
import main.java.gdh.ExchangeState;
import main.java.gdh.Group;
import main.java.gdh.Node;
import com.gdh.main.Constants;
import com.gdh.main.ExchangeState;
import com.gdh.main.Group;
import com.gdh.main.Node;

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main.java.parser;
package com.gdh.parser;

import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import main.java.gdh.Constants;
import main.java.gdh.ExchangeState;
import main.java.gdh.Group;
import main.java.gdh.Node;
import com.gdh.main.Constants;
import com.gdh.main.ExchangeState;
import com.gdh.main.Group;
import com.gdh.main.Node;

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.java.parser;
package com.gdh.parser;

public interface MessageParser {
public int parse(String msg);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package test.java.gdh;
package com.gdh.test;

import java.math.BigInteger;
import java.util.ArrayList;
Expand All @@ -16,10 +16,10 @@
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import main.java.gdh.Configuration;
import main.java.gdh.GDHVertex;
import main.java.gdh.Group;
import main.java.gdh.PrimaryVertex;
import com.gdh.main.Configuration;
import com.gdh.main.GDHVertex;
import com.gdh.main.Group;
import com.gdh.main.PrimaryVertex;

@RunWith(VertxUnitRunner.class)
public class AsyncKeyExchangeTest {
Expand Down Expand Up @@ -51,7 +51,7 @@ private void testAsyncNegotiation(int amount, TestContext context) {
for (int i = 0; i < amount; i++) {
verticles[i] = new GDHVertex();
confs[i] = new Configuration();
String port = (amount * 2) + "08" + i;
String port = (amount * 2) + "09" + i;
confs[i].setIP("localhost").setPort(port).setLogLevel(Level.DEBUG);
verticles[i].setConfiguration(confs[i]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package test.java.gdh;
package com.gdh.test;

import org.apache.log4j.ConsoleAppender;
import org.junit.Assert;
import org.junit.Test;

import main.java.gdh.Configuration;
import com.gdh.main.Configuration;

@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
public class ConfigurationTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package test.java.gdh;
package com.gdh.test;

import java.security.SecureRandom;
import java.util.Random;
Expand All @@ -9,10 +9,9 @@
import org.junit.Assert;
import org.junit.Test;

import main.java.crypto.CipherAgent;
import main.java.crypto.CipherAgentImpl;
import com.gdh.crypto.CipherAgent;
import com.gdh.crypto.CipherAgentImpl;

@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
public class EncDecTest {
@Test
public void testEncryption1() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package test.java.gdh;
package com.gdh.test;

import java.math.BigInteger;
import java.util.ArrayList;
Expand All @@ -16,11 +16,11 @@
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import main.java.gdh.Configuration;
import main.java.gdh.Constants;
import main.java.gdh.GDHVertex;
import main.java.gdh.Group;
import main.java.gdh.PrimaryVertex;
import com.gdh.main.Configuration;
import com.gdh.main.Constants;
import com.gdh.main.GDHVertex;
import com.gdh.main.Group;
import com.gdh.main.PrimaryVertex;

@RunWith(VertxUnitRunner.class)
public class ExceptionTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package test.java.gdh;
package com.gdh.test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand All @@ -19,13 +19,13 @@
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import main.java.gdh.Configuration;
import main.java.gdh.ExchangeState;
import main.java.gdh.GDHVertex;
import main.java.gdh.Group;
import main.java.gdh.Node;
import main.java.gdh.PrimaryVertex;
import main.java.parser.MessageConstructor;
import com.gdh.main.Configuration;
import com.gdh.main.ExchangeState;
import com.gdh.main.GDHVertex;
import com.gdh.main.Group;
import com.gdh.main.Node;
import com.gdh.main.PrimaryVertex;
import com.gdh.parser.MessageConstructor;

@RunWith(VertxUnitRunner.class)
public class ForgedMessagesKeyExchangeTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package test.java.gdh;
package com.gdh.test;

import java.util.TreeSet;

import org.junit.Assert;
import org.junit.Test;

import main.java.gdh.Configuration;
import main.java.gdh.Group;
import main.java.gdh.Node;
import com.gdh.main.Configuration;
import com.gdh.main.Group;
import com.gdh.main.Node;

@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
public class GroupNodeTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package test.java.gdh;
package com.gdh.test;

import java.math.BigInteger;
import java.util.ArrayList;
Expand All @@ -15,10 +15,10 @@
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import main.java.gdh.Configuration;
import main.java.gdh.GDHVertex;
import main.java.gdh.Group;
import main.java.gdh.PrimaryVertex;
import com.gdh.main.Configuration;
import com.gdh.main.GDHVertex;
import com.gdh.main.Group;
import com.gdh.main.PrimaryVertex;

@RunWith(VertxUnitRunner.class)
public class KeyExchangeTest {
Expand Down
Loading

0 comments on commit 19e7d61

Please sign in to comment.