Browse Source

修改支持跟新github

master
小令童鞋 9 months ago
parent
commit
deace660f3
7 changed files with 100 additions and 21 deletions
  1. +2
    -1
      .gitignore
  2. +18
    -0
      build.sh
  3. +40
    -2
      pom.xml
  4. +11
    -2
      src/main/java/com/zeekling/Main.java
  5. +3
    -1
      src/main/java/com/zeekling/util/GitHubs.java
  6. +22
    -15
      src/main/resources/log4j.properties
  7. +4
    -0
      start.sh

+ 2
- 1
.gitignore View File

@ -48,4 +48,5 @@ tags
target
*.iml
gradle
logs
logs
build

+ 18
- 0
build.sh View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
rm -rf ./build
if [ ! -d "./build" ]
then
mkdir build
fi
mvn clean
mvn install -Dmaven.test.skip=true
cp -r ./target/github_zeekling-1.0.jar ./build/
cp -r ./start.sh ./build/
cp -r ./src/main/resources/blog.properties ./build/
cp -r ./src/main/resources/log4j.properties ./build/
cp -r ./target/lib ./build/

+ 40
- 2
pom.xml View File

@ -6,7 +6,7 @@
<groupId>com.zeekling</groupId>
<artifactId>github_zeekling</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>
<dependencies>
@ -49,7 +49,13 @@
<artifactId>rome</artifactId>
<version>1.6.0</version>
</dependency>
<!-- Thanks for using https://jar-download.com -->
<dependency>
<groupId>sunjce_provider</groupId>
<artifactId>sunjce_provider</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/lib/sunjce_provider.jar</systemPath>
</dependency>
</dependencies>
@ -64,6 +70,38 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.zeekling.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

+ 11
- 2
src/main/java/com/zeekling/Main.java View File

@ -2,6 +2,8 @@ package com.zeekling;
import com.zeekling.blog.BlogUpdateService;
import com.zeekling.blog.BlogUpdateServiceImpl;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
/**
* @author zeekling [lingzhaohui@zeekling.cn]
@ -11,10 +13,17 @@ import com.zeekling.blog.BlogUpdateServiceImpl;
*/
public class Main {
private static final Logger LOGGER = LogManager.getLogger(Main.class);
public static void main(String[] args) {
BlogUpdateService updateService = new BlogUpdateServiceImpl("/home/zeek/project/github_zeekling/src/main/resources/blog.properties");
String configPath = System.getProperty("configPath");
BlogUpdateService updateService = new BlogUpdateServiceImpl(configPath);
int res = updateService.update();
System.out.println(res);
if (res == 0){
LOGGER.info("update github success!");
return;
}
LOGGER.error("update github failed!");
}
}

+ 3
- 1
src/main/java/com/zeekling/util/GitHubs.java View File

@ -50,6 +50,7 @@ public final class GitHubs {
final HttpResponse res = HttpRequest.get("https://hacpai.com/github/repos?id=" + githubUserId).trustAllCerts(true).
connectionTimeout(3000).timeout(7000).header("User-Agent", GitHubConstants.USER_AGENT).send();
if (200 != res.statusCode()) {
LOGGER.error("error code:" + res.statusCode());
return null;
}
res.charset("UTF-8");
@ -176,12 +177,13 @@ public final class GitHubs {
final HttpResponse response = HttpRequest.get("https://api.github.com/user").header("Authorization", "token " + pat).
connectionTimeout(7000).timeout(30000).header("User-Agent", GitHubConstants.USER_AGENT).send();
if (200 != response.statusCode()) {
LOGGER.error("error code:" + response.statusCode());
return null;
}
response.charset("UTF-8");
return new JSONObject(response.bodyText());
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Gets GitHub user info failed: " + e.getMessage());
LOGGER.log(Level.ERROR, "Gets GitHub user info failed: " + e);
return null;
}
}


+ 22
- 15
src/main/resources/log4j.properties View File

@ -1,24 +1,31 @@
### 设置###
log4j.rootLogger = debug,stdout,D,E
log4j.rootLogger=INFO,stdout,R, E
### 输出信息到控制抬 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n
### 输出DEBUG 级别以上的日志到=./logs/debug.log ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = ./logs/debug.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
log4j.appender.file = org.apache.log4j.FileAppender
log4j.appender.file.File = ./logs/spider.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n
### 输出ERROR 级别以上的日志到=./logs/error.log ###
### 输出到日志文件 ###
# 每天生成一个新的日志文件
log4j.appender.R = org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File = ./logs/log.log
log4j.appender.R.Append = true
# DEBUG级别及以上的日志信息输出到./logs/log.log中
log4j.appender.R.Threshold = DEBUG
log4j.appender.R.layout = org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} [%t] [%c] [%p] - %m%n
### 保存异常信息到单独文件 ###
# 每天生成一个新的日志文件
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =./logs/error.log
log4j.appender.E.File = ./logs/error.log
log4j.appender.E.Append = true
# ERROR级别及以上的日志信息输出到./logs/log.log中
log4j.appender.E.Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
log4j.appender.E.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} [%t] [%c] [%p] - %m%n

+ 4
- 0
start.sh View File

@ -0,0 +1,4 @@
#!/bin/bash
java -Djava.ext.dirs=./lib -DconfigPath=./blog.properties -cp github_zeekling-1.0.jar com.zeekling.Main

Loading…
Cancel
Save