From e548b4701cf11b9af8c6d97aa1be601e0253926b Mon Sep 17 00:00:00 2001 From: JervyShi Date: Sun, 10 Feb 2019 02:06:11 +0800 Subject: [PATCH 1/3] add travis ci support --- .travis.yml | 18 ++ pom.xml | 93 +++++- .../name/jervyshi/nacos/NacosProcess.java | 16 + .../name/jervyshi/nacos/NacosStarter.java | 16 + .../jervyshi/nacos/NacosStarterBuilder.java | 16 + .../exception/NacosEmbeddedException.java | 16 + .../nacos/infra/NacosBinaryDownloader.java | 18 +- .../jervyshi/nacos/infra/NacosClient.java | 16 + .../nacos/infra/NacosVersionGetter.java | 18 +- .../jervyshi/nacos/infra/NacosWaiter.java | 18 +- .../name/jervyshi/nacos/infra/OsResolver.java | 16 + .../name/jervyshi/nacos/infra/ZipUtil.java | 16 + .../name/jervyshi/nacos/NacosStarterTest.java | 18 +- tools/check_format.sh | 12 + tools/ci/.travis.settings.xml | 138 +++++++++ tools/codestyle/HEADER | 14 + tools/codestyle/formatter.xml | 279 ++++++++++++++++++ 17 files changed, 722 insertions(+), 16 deletions(-) create mode 100644 .travis.yml create mode 100644 tools/check_format.sh create mode 100644 tools/ci/.travis.settings.xml create mode 100644 tools/codestyle/HEADER create mode 100644 tools/codestyle/formatter.xml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..27d103b --- /dev/null +++ b/.travis.yml @@ -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) diff --git a/pom.xml b/pom.xml index 40a5081..f957bee 100644 --- a/pom.xml +++ b/pom.xml @@ -15,12 +15,12 @@ repo - + 1.7 1.7 - + org.slf4j @@ -71,6 +71,49 @@ + + com.mycila + license-maven-plugin + 3.0 + + + generate-sources + + remove + format + + + + + true +
${user.dir}/tools/codestyle/HEADER
+ + **/src/main/java/** + **/src/test/java/** + + true + + SLASHSTAR_STYLE + +
+
+ + + com.googlecode.maven-java-formatter-plugin + maven-java-formatter-plugin + 0.4 + + + + format + + + + + ${user.dir}/tools/codestyle/formatter.xml + UTF-8 + + org.jacoco jacoco-maven-plugin @@ -119,16 +162,42 @@ true - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.4 - - - org.sonarsource.scanner.maven - sonar-maven-plugin - 3.0.2 - + + + + jdk8 + + [1.8,) + + + false + true + + + + ci-install + + true + false + true + + + + ci-test + + false + true + false + + + + release + + true + false + + + \ No newline at end of file diff --git a/src/main/java/name/jervyshi/nacos/NacosProcess.java b/src/main/java/name/jervyshi/nacos/NacosProcess.java index c969455..9977d83 100644 --- a/src/main/java/name/jervyshi/nacos/NacosProcess.java +++ b/src/main/java/name/jervyshi/nacos/NacosProcess.java @@ -1,3 +1,19 @@ +/* + * 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; diff --git a/src/main/java/name/jervyshi/nacos/NacosStarter.java b/src/main/java/name/jervyshi/nacos/NacosStarter.java index 32b2435..ec32b08 100644 --- a/src/main/java/name/jervyshi/nacos/NacosStarter.java +++ b/src/main/java/name/jervyshi/nacos/NacosStarter.java @@ -1,3 +1,19 @@ +/* + * 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; diff --git a/src/main/java/name/jervyshi/nacos/NacosStarterBuilder.java b/src/main/java/name/jervyshi/nacos/NacosStarterBuilder.java index 797f3e7..d3fa80d 100644 --- a/src/main/java/name/jervyshi/nacos/NacosStarterBuilder.java +++ b/src/main/java/name/jervyshi/nacos/NacosStarterBuilder.java @@ -1,3 +1,19 @@ +/* + * 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.IOException; diff --git a/src/main/java/name/jervyshi/nacos/exception/NacosEmbeddedException.java b/src/main/java/name/jervyshi/nacos/exception/NacosEmbeddedException.java index 62d03fc..8925c9a 100644 --- a/src/main/java/name/jervyshi/nacos/exception/NacosEmbeddedException.java +++ b/src/main/java/name/jervyshi/nacos/exception/NacosEmbeddedException.java @@ -1,3 +1,19 @@ +/* + * 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.exception; /** diff --git a/src/main/java/name/jervyshi/nacos/infra/NacosBinaryDownloader.java b/src/main/java/name/jervyshi/nacos/infra/NacosBinaryDownloader.java index 38927ab..f177a50 100644 --- a/src/main/java/name/jervyshi/nacos/infra/NacosBinaryDownloader.java +++ b/src/main/java/name/jervyshi/nacos/infra/NacosBinaryDownloader.java @@ -1,3 +1,19 @@ +/* + * 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.infra; import java.io.File; @@ -27,7 +43,7 @@ public class NacosBinaryDownloader { /** logger */ private static final Logger logger = LoggerFactory - .getLogger(NacosBinaryDownloader.class); + .getLogger(NacosBinaryDownloader.class); /** * Gets nacos binary archive. diff --git a/src/main/java/name/jervyshi/nacos/infra/NacosClient.java b/src/main/java/name/jervyshi/nacos/infra/NacosClient.java index 84ea3ac..c973f30 100644 --- a/src/main/java/name/jervyshi/nacos/infra/NacosClient.java +++ b/src/main/java/name/jervyshi/nacos/infra/NacosClient.java @@ -1,3 +1,19 @@ +/* + * 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.infra; import java.io.IOException; diff --git a/src/main/java/name/jervyshi/nacos/infra/NacosVersionGetter.java b/src/main/java/name/jervyshi/nacos/infra/NacosVersionGetter.java index ae5d3d9..d46234e 100644 --- a/src/main/java/name/jervyshi/nacos/infra/NacosVersionGetter.java +++ b/src/main/java/name/jervyshi/nacos/infra/NacosVersionGetter.java @@ -1,3 +1,19 @@ +/* + * 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.infra; import java.io.BufferedReader; @@ -26,7 +42,7 @@ public class NacosVersionGetter { /** logger */ private static final Logger logger = LoggerFactory - .getLogger(NacosVersionGetter.class); + .getLogger(NacosVersionGetter.class); /** * Gets latest version. diff --git a/src/main/java/name/jervyshi/nacos/infra/NacosWaiter.java b/src/main/java/name/jervyshi/nacos/infra/NacosWaiter.java index 8138892..693db1f 100644 --- a/src/main/java/name/jervyshi/nacos/infra/NacosWaiter.java +++ b/src/main/java/name/jervyshi/nacos/infra/NacosWaiter.java @@ -1,3 +1,19 @@ +/* + * 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.infra; import java.io.IOException; @@ -18,7 +34,7 @@ public class NacosWaiter { /** logger */ private static final Logger logger = LoggerFactory - .getLogger(NacosWaiter.class); + .getLogger(NacosWaiter.class); private static final int DEFAULT_WAIT_TIME_IN_SECONDS = 30; diff --git a/src/main/java/name/jervyshi/nacos/infra/OsResolver.java b/src/main/java/name/jervyshi/nacos/infra/OsResolver.java index 3fd1e03..8f6db5b 100644 --- a/src/main/java/name/jervyshi/nacos/infra/OsResolver.java +++ b/src/main/java/name/jervyshi/nacos/infra/OsResolver.java @@ -1,3 +1,19 @@ +/* + * 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.infra; /** diff --git a/src/main/java/name/jervyshi/nacos/infra/ZipUtil.java b/src/main/java/name/jervyshi/nacos/infra/ZipUtil.java index 64fca5e..91291c4 100644 --- a/src/main/java/name/jervyshi/nacos/infra/ZipUtil.java +++ b/src/main/java/name/jervyshi/nacos/infra/ZipUtil.java @@ -1,3 +1,19 @@ +/* + * 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.infra; import java.io.BufferedOutputStream; diff --git a/src/test/java/name/jervyshi/nacos/NacosStarterTest.java b/src/test/java/name/jervyshi/nacos/NacosStarterTest.java index 11b91e3..eb3bbb6 100644 --- a/src/test/java/name/jervyshi/nacos/NacosStarterTest.java +++ b/src/test/java/name/jervyshi/nacos/NacosStarterTest.java @@ -1,3 +1,19 @@ +/* + * 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 org.junit.Test; @@ -17,7 +33,7 @@ public void start() throws Exception { NacosStarter nacosStarter = NacosStarterBuilder.nacosStarter().withNacosVersion("0.8.0") .build(); NacosProcess start = nacosStarter.start(); - + start.close(); } } \ No newline at end of file diff --git a/tools/check_format.sh b/tools/check_format.sh new file mode 100644 index 0000000..cd548f7 --- /dev/null +++ b/tools/check_format.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +BASEDIR=$(dirname $0) + +cd ${BASEDIR} + +# make sure git has no un commit files +if [ -n "$(git status --untracked-files=no --porcelain)" ]; then + echo "Please commit your change before run this shell, un commit files:" + git status --untracked-files=no --porcelain + exit 1 +fi \ No newline at end of file diff --git a/tools/ci/.travis.settings.xml b/tools/ci/.travis.settings.xml new file mode 100644 index 0000000..ddd1cfe --- /dev/null +++ b/tools/ci/.travis.settings.xml @@ -0,0 +1,138 @@ + + + + + + standard-with-extra-repos + + true + + + + + central + Central Repository + http://repo1.maven.org/maven2 + + true + always + + + false + always + + + + + central2 + Central Repository 2 + http://repo1.maven.apache.org/maven2 + + true + always + + + false + always + + + + + sonatype + OSS Sonatype repo (releases) + + true + always + warn + + + false + never + fail + + https://oss.sonatype.org/content/repositories/releases/ + + + + sonatype-snapshots + OSS Sonatype repo (snapshots) + + false + always + warn + + + true + never + fail + + https://oss.sonatype.org/content/repositories/snapshots/ + + + + sonatype-apache + Apache repo (releases) + + true + always + warn + + + false + never + fail + + https://repository.apache.org/releases/ + + + + apache-snapshots + ASF repo (snapshots) + + false + never + warn + + + true + always + fail + + https://repository.apache.org/snapshots/ + + + + + + central + + http://repo1.maven.org/maven2 + + true + always + + + false + always + + + + + central2 + + http://repo1.maven.apache.org/maven2 + + true + always + + + false + always + + + + + + \ No newline at end of file diff --git a/tools/codestyle/HEADER b/tools/codestyle/HEADER new file mode 100644 index 0000000..0ed96c4 --- /dev/null +++ b/tools/codestyle/HEADER @@ -0,0 +1,14 @@ +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. \ No newline at end of file diff --git a/tools/codestyle/formatter.xml b/tools/codestyle/formatter.xml new file mode 100644 index 0000000..10727d1 --- /dev/null +++ b/tools/codestyle/formatter.xml @@ -0,0 +1,279 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 93d9d5d2d1d83761cd0ba016f7a159e164b1e81e Mon Sep 17 00:00:00 2001 From: JervyShi Date: Sun, 10 Feb 2019 02:21:31 +0800 Subject: [PATCH 2/3] trigger codecov --- pom.xml | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/pom.xml b/pom.xml index f957bee..77a29eb 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,8 @@ 1.7 1.7 + false + false @@ -114,54 +116,39 @@ UTF-8 + + maven-surefire-plugin + 2.20 + + ${skipTests} + + **/*Test.java + + once + + org.jacoco jacoco-maven-plugin - 0.7.8 + + ${module.jacoco.skip} + default-prepare-agent prepare-agent - - ${project.build.directory}/jacoco.exec - - - - default-prepare-agent-integration - pre-integration-test - - prepare-agent-integration - - - ${project.build.directory}/jacoco-it.exec - failsafeArgLine - default-report + test - report - - - - default-report-integration - - report-integration + report-aggregate - - maven-surefire-plugin - 2.20 - - 1 - true - true - - From ff90bd76421c3f16cea148653beea053308a2312 Mon Sep 17 00:00:00 2001 From: JervyShi Date: Sun, 10 Feb 2019 16:51:12 +0800 Subject: [PATCH 3/3] fix ci failed --- .../name/jervyshi/nacos/NacosProcess.java | 24 +------ .../name/jervyshi/nacos/NacosStarter.java | 63 ++++++++----------- .../name/jervyshi/nacos/NacosStarterTest.java | 9 +++ 3 files changed, 37 insertions(+), 59 deletions(-) diff --git a/src/main/java/name/jervyshi/nacos/NacosProcess.java b/src/main/java/name/jervyshi/nacos/NacosProcess.java index 9977d83..c4387b5 100644 --- a/src/main/java/name/jervyshi/nacos/NacosProcess.java +++ b/src/main/java/name/jervyshi/nacos/NacosProcess.java @@ -18,12 +18,6 @@ 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; @@ -38,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; @@ -51,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; @@ -69,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 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 { diff --git a/src/main/java/name/jervyshi/nacos/NacosStarter.java b/src/main/java/name/jervyshi/nacos/NacosStarter.java index ec32b08..70f6b0f 100644 --- a/src/main/java/name/jervyshi/nacos/NacosStarter.java +++ b/src/main/java/name/jervyshi/nacos/NacosStarter.java @@ -19,14 +19,10 @@ 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; @@ -90,22 +86,32 @@ public NacosProcess start() { downloadAndUnpackBinary(); } - File scriptFile = getNacosStartUpScript(); - List 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(); @@ -128,18 +134,6 @@ private void downloadAndUnpackBinary() throws IOException { logger.info("Unzip nacos archive files into: {}", downloadPath); ZipUtil.unzip(archive.getAbsolutePath(), downloadPath.toAbsolutePath().toString()); - - if (!isWindows()) { - Set 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() { @@ -147,18 +141,12 @@ private boolean isWindows() { } 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(); } @@ -169,4 +157,7 @@ private void checkInitialState() { } } + private String getAbsolutePath(String... item) { + return Paths.get(downloadPath.toAbsolutePath().toString(), item).toString(); + } } diff --git a/src/test/java/name/jervyshi/nacos/NacosStarterTest.java b/src/test/java/name/jervyshi/nacos/NacosStarterTest.java index eb3bbb6..dda6415 100644 --- a/src/test/java/name/jervyshi/nacos/NacosStarterTest.java +++ b/src/test/java/name/jervyshi/nacos/NacosStarterTest.java @@ -16,8 +16,13 @@ */ package name.jervyshi.nacos; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.junit.Test; +import name.jervyshi.nacos.infra.NacosClient; + /** * The type Nacos starter test. * @author JervyShi @@ -34,6 +39,10 @@ public void start() throws Exception { .build(); NacosProcess start = nacosStarter.start(); + NacosClient client = new NacosClient("127.0.0.1", 8848); + assertTrue(client.isHealthy()); + start.close(); + assertFalse(client.isHealthy()); } } \ No newline at end of file