Skip to content

Commit

Permalink
feat: use google checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyQQQQ committed Jan 13, 2018
1 parent 8436506 commit 9637bc0
Show file tree
Hide file tree
Showing 149 changed files with 9,396 additions and 9,072 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ language: java
jdk: oraclejdk8

script:
- ./gradlew check
- ./gradlew test
36 changes: 36 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version '1.0.0'
apply plugin: 'java'
apply plugin: 'com.google.protobuf'
apply plugin: 'application'
apply plugin: 'checkstyle'

sourceCompatibility = 1.8
mainClassName = 'org.tron.example.Tron'
Expand All @@ -21,6 +22,19 @@ buildscript {
}
}

def versions = [
checkstyle: '8.7',
]

configurations {
checkstyleConfig

}

configurations.getByName('checkstyleConfig') {
transitive = false
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.9.5'
Expand Down Expand Up @@ -80,8 +94,30 @@ dependencies {
compile group: 'com.alibaba', name: 'fastjson', version: '1.2.44'

compile group: 'com.google.inject', name: 'guice', version: '4.1.0'

checkstyleConfig "com.puppycrawl.tools:checkstyle:${versions.checkstyle}"

}

task lint(type: Checkstyle) {
// Cleaning the old log because of the creation of the new ones (not sure if totaly needed)
delete fileTree(dir: "${project.rootDir}/app/build/reports")
source 'src'
include '**/*.java'
exclude '**/gen/**'
// empty classpath
classpath = files()
//Failing the build
ignoreFailures = false
}

checkstyle {
toolVersion = "${versions.checkstyle}"
config = resources.text.fromArchiveEntry(configurations.checkstyleConfig, 'google_checks.xml')
}



tasks.matching { it instanceof Test }.all {
testLogging.events = ["failed", "passed", "skipped"]
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Jan 06 16:37:04 CST 2018
#Thu Jan 11 19:13:19 CET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-rc-2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-rc-2-all.zip
53 changes: 26 additions & 27 deletions src/main/java/org/tron/application/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,30 @@

public class Application {

private Injector injector;
private ServiceContainer services;

private static final Logger logger = LoggerFactory.getLogger("Application");

public Application(Injector injector) {
this.injector = injector;
this.services = new ServiceContainer();
}

public Injector getInjector() {
return injector;
}

public void addService(Service service) {
this.services.add(service);
}

public void run() {
this.services.start();
}

public void shutdown() {
logger.info("shutting down");
this.services.stop();
System.exit(0);
}
private static final Logger logger = LoggerFactory.getLogger("Application");
private Injector injector;
private ServiceContainer services;

public Application(Injector injector) {
this.injector = injector;
this.services = new ServiceContainer();
}

public Injector getInjector() {
return injector;
}

public void addService(Service service) {
this.services.add(service);
}

public void run() {
this.services.start();
}

public void shutdown() {
logger.info("shutting down");
this.services.stop();
System.exit(0);
}
}
50 changes: 25 additions & 25 deletions src/main/java/org/tron/application/ApplicationFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@

public class ApplicationFactory {

/**
* Build a Guice instance
*
* @return Guice
*/
public Injector buildGuice() {
return Guice.createInjector(
new Module());
}
/**
* Build a Guice instance
*
* @return Guice
*/
public Injector buildGuice() {
return Guice.createInjector(
new Module());
}

/**
* Build a new application
*
* @return
*/
public Application build() {
return new Application(buildGuice());
}
/**
* Build a new application
*
* @return
*/
public Application build() {
return new Application(buildGuice());
}

/**
* Build a new cli application
*
* @return
*/
public CliApplication buildCli() {
return new CliApplication(buildGuice());
}
/**
* Build a new cli application
*
* @return
*/
public CliApplication buildCli() {
return new CliApplication(buildGuice());
}
}
21 changes: 11 additions & 10 deletions src/main/java/org/tron/application/CliApplication.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package org.tron.application;

import com.google.inject.Injector;

import org.tron.peer.Peer;

public class CliApplication extends Application {

private Peer peer;
private Peer peer;

public CliApplication(Injector injector) {
super(injector);
}
public CliApplication(Injector injector) {
super(injector);
}

public Peer getPeer() {
return peer;
}
public Peer getPeer() {
return peer;
}

public void setPeer(Peer peer) {
this.peer = peer;
}
public void setPeer(Peer peer) {
this.peer = peer;
}
}
78 changes: 39 additions & 39 deletions src/main/java/org/tron/application/Module.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
package org.tron.application;

import static org.tron.core.Constant.BLOCK_DB_NAME;
import static org.tron.core.Constant.TRANSACTION_DB_NAME;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import javax.inject.Named;

import org.tron.consensus.client.Client;
import org.tron.consensus.server.Server;
import org.tron.core.Constant;
import org.tron.storage.leveldb.LevelDbDataSourceImpl;

import javax.inject.Named;

import static org.tron.core.Constant.BLOCK_DB_NAME;
import static org.tron.core.Constant.TRANSACTION_DB_NAME;

public class Module extends AbstractModule {

@Override
protected void configure() {

}

@Provides
@Singleton
public Client buildClient() {
return new Client();
}

@Provides
@Singleton
public Server buildServer() {
return new Server();
}

@Provides
@Singleton
@Named("transaction")
public LevelDbDataSourceImpl buildTransactionDb() {
LevelDbDataSourceImpl db = new LevelDbDataSourceImpl(Constant.NORMAL,TRANSACTION_DB_NAME);
db.initDB();
return db;
}

@Provides
@Singleton
@Named("block")
public LevelDbDataSourceImpl buildBlockDb() {
LevelDbDataSourceImpl db = new LevelDbDataSourceImpl(Constant.NORMAL,BLOCK_DB_NAME);
db.initDB();
return db;
}
@Override
protected void configure() {

}

@Provides
@Singleton
public Client buildClient() {
return new Client();
}

@Provides
@Singleton
public Server buildServer() {
return new Server();
}

@Provides
@Singleton
@Named("transaction")
public LevelDbDataSourceImpl buildTransactionDb() {
LevelDbDataSourceImpl db = new LevelDbDataSourceImpl(Constant.NORMAL, TRANSACTION_DB_NAME);
db.initDB();
return db;
}

@Provides
@Singleton
@Named("block")
public LevelDbDataSourceImpl buildBlockDb() {
LevelDbDataSourceImpl db = new LevelDbDataSourceImpl(Constant.NORMAL, BLOCK_DB_NAME);
db.initDB();
return db;
}
}
5 changes: 3 additions & 2 deletions src/main/java/org/tron/application/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public interface Service {

void start();
void stop();
void start();

void stop();
}
46 changes: 22 additions & 24 deletions src/main/java/org/tron/application/ServiceContainer.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
package org.tron.application;

import java.util.ArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;

public class ServiceContainer implements Service {

private ArrayList<Service> services;
private static final Logger logger = LoggerFactory.getLogger("Services");
private ArrayList<Service> services;

private static final Logger logger = LoggerFactory.getLogger("Services");
public ServiceContainer() {
this.services = new ArrayList<>();
}

public ServiceContainer() {
this.services = new ArrayList<>();
}

public void add(Service service) {
this.services.add(service);
}
public void add(Service service) {
this.services.add(service);
}

@Override
public void start() {
logger.debug("Starting services");
for (Service service : this.services) {
logger.debug("Starting " + service.getClass().getSimpleName());
service.start();
}
@Override
public void start() {
logger.debug("Starting services");
for (Service service : this.services) {
logger.debug("Starting " + service.getClass().getSimpleName());
service.start();
}
}

@Override
public void stop() {
for (Service service : this.services) {
logger.debug("Stopping " + service.getClass().getSimpleName());
service.stop();
}
@Override
public void stop() {
for (Service service : this.services) {
logger.debug("Stopping " + service.getClass().getSimpleName());
service.stop();
}
}
}
Loading

0 comments on commit 9637bc0

Please sign in to comment.