Skip to content

Commit

Permalink
Merge pull request #4 from JervyShi/add_ci
Browse files Browse the repository at this point in the history
add travis ci support
  • Loading branch information
JervyShi authored Feb 10, 2019
2 parents b9e7ffb + ff90bd7 commit 46897f3
Show file tree
Hide file tree
Showing 17 changed files with 774 additions and 103 deletions.
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: java

jdk:
- oraclejdk8

before_install:
- cp ./tools/ci/.travis.settings.xml $HOME/.m2/settings.xml
&& mvn -version

install:
- mvn clean install -Pci-install -B -U -e
- sh ./tools/check_format.sh

script:
- travis_retry mvn clean package -Pci-test

after_success:
- bash <(curl -s https://codecov.io/bash)
136 changes: 96 additions & 40 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
<distribution>repo</distribution>
</license>
</licenses>

<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<module.jacoco.skip>false</module.jacoco.skip>
<skipTests>false</skipTests>
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -72,63 +74,117 @@
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.8</version>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>3.0</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco.exec</destFile>
</configuration>
</execution>
<execution>
<id>default-prepare-agent-integration</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco-it.exec</destFile>
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>default-report</id>
<phase>generate-sources</phase>
<goals>
<goal>report</goal>
<goal>remove</goal>
<goal>format</goal>
</goals>
</execution>
</executions>
<configuration>
<quiet>true</quiet>
<header>${user.dir}/tools/codestyle/HEADER</header>
<includes>
<include>**/src/main/java/**</include>
<include>**/src/test/java/**</include>
</includes>
<strictCheck>true</strictCheck>
<mapping>
<java>SLASHSTAR_STYLE</java>
</mapping>
</configuration>
</plugin>

<plugin>
<groupId>com.googlecode.maven-java-formatter-plugin</groupId>
<artifactId>maven-java-formatter-plugin</artifactId>
<version>0.4</version>
<executions>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
<goal>format</goal>
</goals>
</execution>
</executions>
<configuration>
<configFile>${user.dir}/tools/codestyle/formatter.xml</configFile>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
<testFailureIgnore>true</testFailureIgnore>
<skipTests>${skipTests}</skipTests>
<includes>
<include>**/*Test.java</include>
</includes>
<forkMode>once</forkMode>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.4</version>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.0.2</version>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<skip>${module.jacoco.skip}</skip>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>test</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>jdk8</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<properties>
<maven.javadoc.failOnError>false</maven.javadoc.failOnError>
<maven.javadoc.quiet>true</maven.javadoc.quiet>
</properties>
</profile>
<profile>
<id>ci-install</id>
<properties>
<skipTests>true</skipTests>
<maven.javadoc.skip>false</maven.javadoc.skip>
<module.jacoco.skip>true</module.jacoco.skip>
</properties>
</profile>
<profile>
<id>ci-test</id>
<properties>
<dependency.test.skip>false</dependency.test.skip>
<maven.javadoc.skip>true</maven.javadoc.skip>
<module.jacoco.skip>false</module.jacoco.skip>
</properties>
</profile>
<profile>
<id>release</id>
<properties>
<maven.javadoc.quite>true</maven.javadoc.quite>
<maven.javadoc.skip>false</maven.javadoc.skip>
</properties>
</profile>
</profiles>
</project>
40 changes: 17 additions & 23 deletions src/main/java/name/jervyshi/nacos/NacosProcess.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package name.jervyshi.nacos;

import static org.slf4j.LoggerFactory.getLogger;

import java.io.File;
import java.lang.ProcessBuilder.Redirect;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;

import name.jervyshi.nacos.infra.NacosWaiter;
Expand All @@ -22,10 +32,6 @@ public class NacosProcess implements AutoCloseable {
/** logger */
private static final Logger logger = getLogger(NacosProcess.class);

private Path downloadPath;

private File shutdownScript;

private String host;

private int port;
Expand All @@ -35,15 +41,10 @@ public class NacosProcess implements AutoCloseable {
/**
* Instantiates a new Nacos process.
*
* @param downloadPath the download path
* @param shutdownScript the shutdown script
* @param host the host
* @param port the port
*/
public NacosProcess(Path downloadPath, File shutdownScript, String host, int port,
Process process) {
this.downloadPath = downloadPath;
this.shutdownScript = shutdownScript;
public NacosProcess(String host, int port, Process process) {
this.host = host;
this.port = port;
this.process = process;
Expand All @@ -53,13 +54,6 @@ public NacosProcess(Path downloadPath, File shutdownScript, String host, int por
public void close() throws Exception {
logger.info("Stopping nacos server");
process.destroy();
List<String> command = new ArrayList<>();
command.add(shutdownScript.getAbsolutePath());
Process innerProcess = new ProcessBuilder().directory(downloadPath.toFile())
.command(command).inheritIO().redirectOutput(Redirect.PIPE).start();

// TODO log process result
innerProcess.getInputStream();
if (new NacosWaiter(host, port).avoidUntilNacosServerStopped()) {
logger.info("Stopped nacos server");
} else {
Expand Down
79 changes: 43 additions & 36 deletions src/main/java/name/jervyshi/nacos/NacosStarter.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package name.jervyshi.nacos;

import java.io.File;
import java.io.IOException;
import java.lang.ProcessBuilder.Redirect;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

import org.slf4j.Logger;
Expand Down Expand Up @@ -74,22 +86,32 @@ public NacosProcess start() {
downloadAndUnpackBinary();
}

File scriptFile = getNacosStartUpScript();

List<String> command = new ArrayList<>();
command.add(scriptFile.getAbsolutePath());
if (!isWindows()) {
command.add("-m");
command.add("standalone");
if (isWindows()) {
command.add(Paths.get(System.getenv("JAVA_HOME"), "bin", "java.exe")
.toAbsolutePath().toString());
} else {
command.add(Paths.get(System.getenv("JAVA_HOME"), "bin", "java")
.toAbsolutePath().toString());
}
Process innerProcess = new ProcessBuilder().directory(downloadPath.toFile())
.command(command).inheritIO().redirectOutput(Redirect.PIPE).start();
command.add("-Dnacos.standalone=true");
command.add("-Dnacos.home=" + getAbsolutePath("nacos"));
command.add("-jar");
command.add(getAbsolutePath("nacos", "target", "nacos-server.jar"));
command.add(
"--spring.config.location=classpath:/,classpath:/config/,file:./,file:./config/,file:"
+ getAbsolutePath("nacos", "conf") + File.separator);
command.add(
"--logging.config=" + getAbsolutePath("nacos", "conf", "nacos-logback.xml"));

Process innerProcess = new ProcessBuilder()
.directory(Paths.get(getAbsolutePath("nacos")).toFile()).command(command)
.inheritIO().redirectOutput(Redirect.PIPE).start();

// TODO log process result
innerProcess.getInputStream();

nacosProcess = new NacosProcess(downloadPath, getNacosShutdownScript(), host, port,
innerProcess);
nacosProcess = new NacosProcess(host, port, innerProcess);

logger.info("Starting nacos server on port: {}", port);
new NacosWaiter(host, port).avoidUntilNacosServerStarted();
Expand All @@ -112,37 +134,19 @@ private void downloadAndUnpackBinary() throws IOException {

logger.info("Unzip nacos archive files into: {}", downloadPath);
ZipUtil.unzip(archive.getAbsolutePath(), downloadPath.toAbsolutePath().toString());

if (!isWindows()) {
Set<PosixFilePermission> permissions = new HashSet<>();
permissions.add(PosixFilePermission.OWNER_READ);
permissions.add(PosixFilePermission.OWNER_WRITE);
permissions.add(PosixFilePermission.OWNER_EXECUTE);
permissions.add(PosixFilePermission.GROUP_READ);
permissions.add(PosixFilePermission.OTHERS_READ);

Files.setPosixFilePermissions(getNacosStartUpScript().toPath(), permissions);
Files.setPosixFilePermissions(getNacosShutdownScript().toPath(), permissions);
}
}

private boolean isWindows() {
return OsResolver.resolve().contains("windows");
}

private boolean isBinaryDownloaded() {
return getNacosStartUpScript().exists();
return getNacosServerJar().exists();
}

private File getNacosStartUpScript() {
String scriptName = isWindows() ? "startup.cmd" : "startup.sh";
Path path = Paths.get(downloadPath.toAbsolutePath().toString(), "nacos", "bin", scriptName);
return path.toFile();
}

private File getNacosShutdownScript() {
String scriptName = isWindows() ? "shutdown.cmd" : "shutdown.sh";
Path path = Paths.get(downloadPath.toAbsolutePath().toString(), "nacos", "bin", scriptName);
private File getNacosServerJar() {
Path path = Paths.get(downloadPath.toAbsolutePath().toString(), "nacos", "target",
"nacos-server.jar");
return path.toFile();
}

Expand All @@ -153,4 +157,7 @@ private void checkInitialState() {
}
}

private String getAbsolutePath(String... item) {
return Paths.get(downloadPath.toAbsolutePath().toString(), item).toString();
}
}
Loading

0 comments on commit 46897f3

Please sign in to comment.