diff --git a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/constant/PathConstants.java b/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/constant/PathConstants.java deleted file mode 100644 index 588150e1d90..00000000000 --- a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/constant/PathConstants.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 com.ctrip.framework.foundation.internals.constant; - -import com.ctrip.framework.foundation.internals.util.PathUtils; -import java.nio.file.Path; - -/** - * @author wang - */ -public interface PathConstants { - - interface ResolvedPaths { - - /** - * Default value {@code /opt/settings/server.properties} on linux or {@code - * C:/opt/settings/server.properties} on windows - */ - Path SERVER_PROPERTIES = PathUtils - .resolve(SystemPropertyKeys.APOLLO_OPT, EnvironmentKeys.APOLLO_OPT, - DefaultValuesOnLinux.APOLLO_OPT, DefaultValuesOnWindows.APOLLO_OPT) - .resolve("settings") - .resolve("server.properties"); - } - - interface DefaultValuesOnLinux { - - String APOLLO_OPT = "/opt"; - } - - interface DefaultValuesOnWindows { - - String APOLLO_OPT = "C:/opt"; - } - - /** - * key in {@link System#getProperty(String)} - */ - interface SystemPropertyKeys { - - String APOLLO_OPT = "APOLLO_OPT"; - } - - /** - * key in {@link System#getenv(String)} - */ - interface EnvironmentKeys { - - String APOLLO_OPT = "apollo.opt"; - } - -} diff --git a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/util/ConfigUtils.java b/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/util/ConfigUtils.java deleted file mode 100644 index 9e6cb004f03..00000000000 --- a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/util/ConfigUtils.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 com.ctrip.framework.foundation.internals.util; - -import com.google.common.base.Strings; - -/** - * resolve the config. - * - * @author wxq - */ -public class ConfigUtils { - - /** - * Gets the value indicated by the specified key. - * - * @param keyInSystemProperty the name of the system property - * @param keyInEnvironment the name of the environment variable - * @return the string value of the variable, or null if the variable is not defined - * in the system property or the system environment - */ - public static String getValue(String keyInSystemProperty, String keyInEnvironment) { - // Get from System Property - final String valueInSystemProperty = System.getProperty(keyInSystemProperty); - if (!Strings.isNullOrEmpty(valueInSystemProperty)) { - // return if value exists - return valueInSystemProperty; - } - - // Get from OS environment variable - final String valueInEnvironment = System.getenv(keyInEnvironment); - if (!Strings.isNullOrEmpty(valueInEnvironment)) { - // return if value exists - return valueInEnvironment; - } - - return null; - } -} diff --git a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/util/PathUtils.java b/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/util/PathUtils.java deleted file mode 100644 index 58874734f01..00000000000 --- a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/util/PathUtils.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 com.ctrip.framework.foundation.internals.util; - -import com.ctrip.framework.foundation.internals.Utils; -import com.google.common.base.Strings; -import java.nio.file.Path; -import java.nio.file.Paths; - -/** - * resolve path. - * - * @author wxq - */ -public class PathUtils { - - public static Path resolve(String keyInSystemProperty, String keyInEnvironment, - String defaultValueOnLinux, String defaultValueOnWindows) { - String value = ConfigUtils.getValue(keyInSystemProperty, keyInEnvironment); - if (!Strings.isNullOrEmpty(value)) { - return Paths.get(value); - } - - // default path - return Utils.isOSWindows() ? Paths.get(defaultValueOnWindows) : Paths.get(defaultValueOnLinux); - } -} diff --git a/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/util/ConfigUtilsTest.java b/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/util/ConfigUtilsTest.java deleted file mode 100644 index e575ca82fe6..00000000000 --- a/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/util/ConfigUtilsTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 com.ctrip.framework.foundation.internals.util; - -import static org.junit.Assert.*; - -import static com.ctrip.framework.foundation.internals.util.ConfigUtilsTest.SystemPropertyKeys.KEY; -import static com.ctrip.framework.foundation.internals.util.ConfigUtilsTest.SystemPropertyValues.CUSTOM_VALUE; - -import org.junit.After; -import org.junit.Test; - -public class ConfigUtilsTest { - - @After - public void tearDown() { - System.clearProperty(KEY); - } - - @Test - public void testGetValue_null() { - assertNull(ConfigUtils.getValue(KEY, "nothing")); - } - - @Test - public void testGetValue_custom() { - System.setProperty(KEY, CUSTOM_VALUE); - String value = ConfigUtils.getValue(KEY, "nothing"); - assertEquals(CUSTOM_VALUE, value); - } - - protected static class SystemPropertyKeys { - - static final String KEY = "system.property.key.2020.11.28"; - } - - protected static class SystemPropertyValues { - - static final String CUSTOM_VALUE = "/simple/custom/path"; - } -} diff --git a/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/util/PathUtilsTest.java b/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/util/PathUtilsTest.java deleted file mode 100644 index 4b121c37653..00000000000 --- a/apollo-core/src/test/java/com/ctrip/framework/foundation/internals/util/PathUtilsTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 com.ctrip.framework.foundation.internals.util; - -import static com.ctrip.framework.foundation.internals.util.PathUtilsTest.SystemPropertyKeys.PATH_KEY; -import static com.ctrip.framework.foundation.internals.util.PathUtilsTest.SystemPropertyValues.CUSTOM_VALUE; -import static com.ctrip.framework.foundation.internals.util.PathUtilsTest.SystemPropertyValues.DEFAULT_VALUE; -import static org.junit.Assert.*; - -import java.nio.file.Path; -import java.nio.file.Paths; -import org.junit.After; -import org.junit.Test; - -public class PathUtilsTest { - - @After - public void tearDown() { - System.clearProperty(PATH_KEY); - } - - @Test - public void testResolveWithDefaultValue() { - Path path = PathUtils.resolve(PATH_KEY, "nothing", DEFAULT_VALUE, DEFAULT_VALUE); - assertEquals(Paths.get(DEFAULT_VALUE), path); - } - - @Test - public void testResolveWithCustomValue() { - System.setProperty(PATH_KEY, CUSTOM_VALUE); - Path path = PathUtils.resolve(PATH_KEY, "nothing", DEFAULT_VALUE, DEFAULT_VALUE); - assertEquals(Paths.get(CUSTOM_VALUE), path); - } - - protected static class SystemPropertyKeys { - static final String PATH_KEY = "system.property.key.2020.11.28"; - } - - protected static class SystemPropertyValues { - static final String CUSTOM_VALUE = "/simple/custom/path"; - static final String DEFAULT_VALUE = "/simple/default/path"; - } -} \ No newline at end of file