Skip to content

Commit

Permalink
Update 0.2.1 and refactor some APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
mercyblitz committed Sep 15, 2018
1 parent a29bf24 commit 1145260
Show file tree
Hide file tree
Showing 20 changed files with 161 additions and 35 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.2.0</version>
<version>0.2.1-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.api.config.annotation;
package com.alibaba.nacos.api.annotation;

import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.naming.NamingService;

Expand All @@ -28,17 +27,16 @@
* @author <a href="mailto:[email protected]">Mercy</a>
* @see ConfigService
* @see NamingService
* @see PropertyKeyConst
* @since 0.1.0
* @see NacosProperties
* @since 0.2.1
*/
@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface NacosInjected {

/**
* The {@link NacosProperties} attribute, If not specified, it will use
* global Nacos Properties global Nacos Properties}.
* The {@link NacosProperties} attribute, If not specified, it will use global Nacos Properties.
*
* @return the default value is {@link NacosProperties}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.api.config.annotation;
package com.alibaba.nacos.api.annotation;

import com.alibaba.nacos.api.PropertyKeyConst;

Expand All @@ -25,7 +25,7 @@
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @see PropertyKeyConst
* @since 0.1.0
* @since 0.2.1
*/
@Target(ElementType.ANNOTATION_TYPE)
@Retention(RetentionPolicy.RUNTIME)
Expand Down Expand Up @@ -77,60 +77,108 @@
*/
String ENCODE = "encode";

/**
* The placeholder of endpoint, the value is <code>"${nacos.endpoint:}"</code>
*/
String ENDPOINT_PLACEHOLDER = "${" + PREFIX + ENDPOINT + ":}";

/**
* The placeholder of endpoint, the value is <code>"${nacos.namespace:}"</code>
*/
String NAMESPACE_PLACEHOLDER = "${" + PREFIX + NAMESPACE + ":}";

/**
* The placeholder of endpoint, the value is <code>"${nacos.access-key:}"</code>
*/
String ACCESS_KEY_PLACEHOLDER = "${" + PREFIX + ACCESS_KEY + ":}";

/**
* The placeholder of endpoint, the value is <code>"${nacos.secret-key:}"</code>
*/
String SECRET_KEY_PLACEHOLDER = "${" + PREFIX + SECRET_KEY + ":}";

/**
* The placeholder of endpoint, the value is <code>${nacos.server-addr:}"</code>
*/
String SERVER_ADDR_PLACEHOLDER = "${" + PREFIX + SERVER_ADDR + ":}";

/**
* The placeholder of endpoint, the value is ${nacos.context-path:}"
*/
String CONTEXT_PATH_PLACEHOLDER = "${" + PREFIX + CONTEXT_PATH + ":}";

/**
* The placeholder of endpoint, the value is <code>"${nacos.cluster-name:}"</code>
*/
String CLUSTER_NAME_PLACEHOLDER = "${" + PREFIX + CLUSTER_NAME + ":}";

/**
* The placeholder of {@link NacosProperties#ENCODE encode}, the value is <code>"${nacos.encode:UTF-8}"</code>
*/
String ENCODE_PLACEHOLDER = "${" + PREFIX + ENCODE + ":UTF-8}";

/**
* The property of "endpoint"
*
* @return empty as default value
* @see #ENDPOINT_PLACEHOLDER
*/
String endpoint() default "${" + PREFIX + ENDPOINT + ":}";
String endpoint() default ENDPOINT_PLACEHOLDER;

/**
* The property of "namespace"
*
* @return empty as default value
* @see #NAMESPACE_PLACEHOLDER
*/
String namespace() default "${" + PREFIX + NAMESPACE + ":}";
String namespace() default NAMESPACE_PLACEHOLDER;

/**
* The property of "access-key"
*
* @return empty as default value
* @see #ACCESS_KEY_PLACEHOLDER
*/
String accessKey() default "${" + PREFIX + ACCESS_KEY + ":}";
String accessKey() default ACCESS_KEY_PLACEHOLDER;

/**
* The property of "secret-key"
*
* @return empty as default value
* @see #SECRET_KEY_PLACEHOLDER
*/
String secretKey() default "${" + PREFIX + SECRET_KEY + ":}";
String secretKey() default SECRET_KEY_PLACEHOLDER;

/**
* The property of "server-addr"
*
* @return empty as default value
* @see #SERVER_ADDR_PLACEHOLDER
*/
String serverAddr() default "${" + PREFIX + SERVER_ADDR + ":}";
String serverAddr() default SERVER_ADDR_PLACEHOLDER;

/**
* The property of "context-path"
*
* @return empty as default value
* @see #CONTEXT_PATH_PLACEHOLDER
*/
String contextPath() default "${" + PREFIX + CONTEXT_PATH + ":}";
String contextPath() default CONTEXT_PATH_PLACEHOLDER;

/**
* The property of "cluster-name"
*
* @return empty as default value
* @see #CLUSTER_NAME_PLACEHOLDER
*/
String clusterName() default "${" + PREFIX + CLUSTER_NAME + ":}";
String clusterName() default CLUSTER_NAME_PLACEHOLDER;

/**
* The property of "encode"
*
* @return "UTF-8" as default value
* @see #ENCODE_PLACEHOLDER
*/
String encode() default "${" + PREFIX + ENCODE + ":UTF-8}";
String encode() default ENCODE_PLACEHOLDER;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.alibaba.nacos.api.config.annotation;

import com.alibaba.nacos.api.annotation.NacosProperties;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.config.convert.NacosConfigConverter;

Expand All @@ -27,7 +28,7 @@
* Annotation that marks a method as a listener for Nacos Config change.
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @since 0.1.0
* @since 0.2.0
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.alibaba.nacos.api.config.annotation;

import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.annotation.NacosProperties;
import com.alibaba.nacos.api.common.Constants;

import java.lang.annotation.*;
Expand All @@ -29,7 +30,7 @@
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @see PropertyKeyConst
* @since 0.1.0
* @since 0.2.0
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author <a href="mailto:[email protected]">Mercy</a>
* @see NacosConfigurationProperties
* @see NacosProperty
* @since 0.1.0
* @since 0.2.0
*/
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @author <a href="mailto:[email protected]">Mercy</a>
* @see NacosConfigurationProperties
* @see NacosIgnore
* @since 0.1.0
* @since 0.2.0
*/
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Annotation which extends value to support auto-refresh
*
* @author <a href="mailto:[email protected]">hxy1991</a>
* @since 0.1.0
* @since 0.2.0
*/
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @param <T> the target type that wanted
* @author <a href="mailto:[email protected]">Mercy</a>
* @since 0.1.0
* @since 0.2.0
*/
public interface NacosConfigConverter<T> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.alibaba.nacos.api.annotation;

import org.junit.Assert;
import org.junit.Test;
import org.springframework.mock.env.MockEnvironment;

import static com.alibaba.nacos.api.annotation.NacosProperties.*;

/**
* {@link NacosProperties} Test
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @since 0.2.1
*/
public class NacosPropertiesTest {

@Test
public void testPlaceholders() {
Assert.assertEquals("${nacos.endpoint:}", ENDPOINT_PLACEHOLDER);
Assert.assertEquals("${nacos.namespace:}", NAMESPACE_PLACEHOLDER);
Assert.assertEquals("${nacos.access-key:}", ACCESS_KEY_PLACEHOLDER);
Assert.assertEquals("${nacos.secret-key:}", SECRET_KEY_PLACEHOLDER);
Assert.assertEquals("${nacos.server-addr:}", SERVER_ADDR_PLACEHOLDER);
Assert.assertEquals("${nacos.context-path:}", CONTEXT_PATH_PLACEHOLDER);
Assert.assertEquals("${nacos.cluster-name:}", CLUSTER_NAME_PLACEHOLDER);
Assert.assertEquals("${nacos.encode:UTF-8}", ENCODE_PLACEHOLDER);
}

@Test
public void testResolvePlaceholders() {
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "nacos.endpoint", "test-value", "test-value");
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "", "test-value", "");

testResolvePlaceholder(NAMESPACE_PLACEHOLDER, "nacos.namespace", "test-value", "test-value");
testResolvePlaceholder(NAMESPACE_PLACEHOLDER, "", "test-value", "");

testResolvePlaceholder(ACCESS_KEY_PLACEHOLDER, "nacos.access-key", "test-value", "test-value");
testResolvePlaceholder(ACCESS_KEY_PLACEHOLDER, "", "test-value", "");

testResolvePlaceholder(SECRET_KEY_PLACEHOLDER, "nacos.secret-key", "test-value", "test-value");
testResolvePlaceholder(SECRET_KEY_PLACEHOLDER, "", "test-value", "");

testResolvePlaceholder(SERVER_ADDR_PLACEHOLDER, "nacos.server-addr", "test-value", "test-value");
testResolvePlaceholder(SERVER_ADDR_PLACEHOLDER, "", "test-value", "");

testResolvePlaceholder(CONTEXT_PATH_PLACEHOLDER, "nacos.context-path", "test-value", "test-value");
testResolvePlaceholder(CONTEXT_PATH_PLACEHOLDER, "", "test-value", "");

testResolvePlaceholder(CLUSTER_NAME_PLACEHOLDER, "nacos.cluster-name", "test-value", "test-value");
testResolvePlaceholder(CLUSTER_NAME_PLACEHOLDER, "", "test-value", "");

testResolvePlaceholder(ENCODE_PLACEHOLDER, "nacos.encode", "test-value", "test-value");
testResolvePlaceholder(ENCODE_PLACEHOLDER, "", "test-value", "UTF-8");
}

private void testResolvePlaceholder(String placeholder, String propertyName, String propertyValue, String expectValue) {
MockEnvironment environment = new MockEnvironment();
environment.setProperty(propertyName, propertyValue);
String resolvedValue = environment.resolvePlaceholders(placeholder);
Assert.assertEquals(expectValue, resolvedValue);
}
}
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.2.0</version>
<version>0.2.1-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.2.0</version>
<version>0.2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.2.0</version>
<version>0.2.1-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.2.0</version>
<version>0.2.1-SNAPSHOT</version>
</parent>
<artifactId>nacos-console</artifactId>
<!--<packaging>war</packaging>-->
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.2.0</version>
<version>0.2.1-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.2.0</version>
<version>0.2.1-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.2.0</version>
<version>0.2.1-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion naming/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.2.0</version>
<version>0.2.1-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Loading

0 comments on commit 1145260

Please sign in to comment.