Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apollo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
apollo
Commits
a5f5092f
Unverified
Commit
a5f5092f
authored
May 01, 2019
by
Jason Song
Committed by
GitHub
May 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add txt file format
parent
dd0a5678
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
4 deletions
+68
-4
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/TxtConfigFile.java
...a/com/ctrip/framework/apollo/internals/TxtConfigFile.java
+15
-0
apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigFactory.java
.../com/ctrip/framework/apollo/spi/DefaultConfigFactory.java
+3
-0
apollo-client/src/test/java/com/ctrip/framework/apollo/internals/TxtConfigFileTest.java
...m/ctrip/framework/apollo/internals/TxtConfigFileTest.java
+43
-0
apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigFileFormat.java
...m/ctrip/framework/apollo/core/enums/ConfigFileFormat.java
+4
-2
apollo-portal/src/main/resources/static/namespace.html
apollo-portal/src/main/resources/static/namespace.html
+2
-1
apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js
...ces/static/scripts/directive/namespace-panel-directive.js
+1
-1
No files found.
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/TxtConfigFile.java
0 → 100644
View file @
a5f5092f
package
com
.
ctrip
.
framework
.
apollo
.
internals
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
public
class
TxtConfigFile
extends
PlainTextConfigFile
{
public
TxtConfigFile
(
String
namespace
,
ConfigRepository
configRepository
)
{
super
(
namespace
,
configRepository
);
}
@Override
public
ConfigFileFormat
getConfigFileFormat
()
{
return
ConfigFileFormat
.
TXT
;
}
}
apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigFactory.java
View file @
a5f5092f
...
@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.spi;
...
@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.spi;
import
com.ctrip.framework.apollo.ConfigService
;
import
com.ctrip.framework.apollo.ConfigService
;
import
com.ctrip.framework.apollo.PropertiesCompatibleConfigFile
;
import
com.ctrip.framework.apollo.PropertiesCompatibleConfigFile
;
import
com.ctrip.framework.apollo.internals.PropertiesCompatibleFileConfigRepository
;
import
com.ctrip.framework.apollo.internals.PropertiesCompatibleFileConfigRepository
;
import
com.ctrip.framework.apollo.internals.TxtConfigFile
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -55,6 +56,8 @@ public class DefaultConfigFactory implements ConfigFactory {
...
@@ -55,6 +56,8 @@ public class DefaultConfigFactory implements ConfigFactory {
return
new
YamlConfigFile
(
namespace
,
configRepository
);
return
new
YamlConfigFile
(
namespace
,
configRepository
);
case
YML:
case
YML:
return
new
YmlConfigFile
(
namespace
,
configRepository
);
return
new
YmlConfigFile
(
namespace
,
configRepository
);
case
TXT:
return
new
TxtConfigFile
(
namespace
,
configRepository
);
}
}
return
null
;
return
null
;
...
...
apollo-client/src/test/java/com/ctrip/framework/apollo/internals/TxtConfigFileTest.java
0 → 100644
View file @
a5f5092f
package
com
.
ctrip
.
framework
.
apollo
.
internals
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
mockito
.
Mockito
.
when
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
java.util.Properties
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
TxtConfigFileTest
{
private
String
someNamespace
;
@Mock
private
ConfigRepository
configRepository
;
@Before
public
void
setUp
()
throws
Exception
{
someNamespace
=
"someName"
;
}
@Test
public
void
testWhenHasContent
()
throws
Exception
{
Properties
someProperties
=
new
Properties
();
String
key
=
ConfigConsts
.
CONFIG_FILE_CONTENT_KEY
;
String
someValue
=
"someValue"
;
someProperties
.
setProperty
(
key
,
someValue
);
when
(
configRepository
.
getConfig
()).
thenReturn
(
someProperties
);
TxtConfigFile
configFile
=
new
TxtConfigFile
(
someNamespace
,
configRepository
);
assertEquals
(
ConfigFileFormat
.
TXT
,
configFile
.
getConfigFileFormat
());
assertEquals
(
someNamespace
,
configFile
.
getNamespace
());
assertTrue
(
configFile
.
hasContent
());
assertEquals
(
someValue
,
configFile
.
getContent
());
}
}
apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigFileFormat.java
View file @
a5f5092f
...
@@ -6,7 +6,7 @@ import com.ctrip.framework.apollo.core.utils.StringUtils;
...
@@ -6,7 +6,7 @@ import com.ctrip.framework.apollo.core.utils.StringUtils;
* @author Jason Song(song_s@ctrip.com)
* @author Jason Song(song_s@ctrip.com)
*/
*/
public
enum
ConfigFileFormat
{
public
enum
ConfigFileFormat
{
Properties
(
"properties"
),
XML
(
"xml"
),
JSON
(
"json"
),
YML
(
"yml"
),
YAML
(
"yaml"
);
Properties
(
"properties"
),
XML
(
"xml"
),
JSON
(
"json"
),
YML
(
"yml"
),
YAML
(
"yaml"
)
,
TXT
(
"txt"
)
;
private
String
value
;
private
String
value
;
...
@@ -22,7 +22,7 @@ public enum ConfigFileFormat {
...
@@ -22,7 +22,7 @@ public enum ConfigFileFormat {
if
(
StringUtils
.
isEmpty
(
value
))
{
if
(
StringUtils
.
isEmpty
(
value
))
{
throw
new
IllegalArgumentException
(
"value can not be empty"
);
throw
new
IllegalArgumentException
(
"value can not be empty"
);
}
}
switch
(
value
)
{
switch
(
value
.
toLowerCase
()
)
{
case
"properties"
:
case
"properties"
:
return
Properties
;
return
Properties
;
case
"xml"
:
case
"xml"
:
...
@@ -33,6 +33,8 @@ public enum ConfigFileFormat {
...
@@ -33,6 +33,8 @@ public enum ConfigFileFormat {
return
YML
;
return
YML
;
case
"yaml"
:
case
"yaml"
:
return
YAML
;
return
YAML
;
case
"txt"
:
return
TXT
;
}
}
throw
new
IllegalArgumentException
(
value
+
" can not map enum"
);
throw
new
IllegalArgumentException
(
value
+
" can not map enum"
);
}
}
...
...
apollo-portal/src/main/resources/static/namespace.html
View file @
a5f5092f
...
@@ -57,7 +57,7 @@
...
@@ -57,7 +57,7 @@
<li>
<li>
通过创建一个私有的Namespace可以实现分组管理配置
通过创建一个私有的Namespace可以实现分组管理配置
</li>
</li>
<li>
私有Namespace的格式可以是xml、yml、yaml、json. 您可以通过apollo-client中ConfigFile接口来获取非properties格式Namespace的内容
</li>
<li>
私有Namespace的格式可以是xml、yml、yaml、json
、txt
. 您可以通过apollo-client中ConfigFile接口来获取非properties格式Namespace的内容
</li>
<li>
1.3.0及以上版本的apollo-client针对yaml/yml提供了更好的支持,可以通过ConfigService.getConfig("someNamespace.yml")直接获取Config对象,也可以通过@EnableApolloConfig("someNamespace.yml")或apollo.bootstrap.namespaces=someNamespace.yml注入yml配置到Spring/Spring Boot中去
</li>
<li>
1.3.0及以上版本的apollo-client针对yaml/yml提供了更好的支持,可以通过ConfigService.getConfig("someNamespace.yml")直接获取Config对象,也可以通过@EnableApolloConfig("someNamespace.yml")或apollo.bootstrap.namespaces=someNamespace.yml注入yml配置到Spring/Spring Boot中去
</li>
</ul>
</ul>
</div>
</div>
...
@@ -113,6 +113,7 @@
...
@@ -113,6 +113,7 @@
<option
value=
"json"
>
json
</option>
<option
value=
"json"
>
json
</option>
<option
value=
"yml"
>
yml
</option>
<option
value=
"yml"
>
yml
</option>
<option
value=
"yaml"
>
yaml
</option>
<option
value=
"yaml"
>
yaml
</option>
<option
value=
"txt"
>
txt
</option>
</select>
</select>
</div>
</div>
...
...
apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js
View file @
a5f5092f
...
@@ -92,7 +92,7 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
...
@@ -92,7 +92,7 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
//namespace view name hide suffix
//namespace view name hide suffix
namespace
.
viewName
=
namespace
.
baseInfo
.
namespaceName
.
replace
(
"
.xml
"
,
""
).
replace
(
namespace
.
viewName
=
namespace
.
baseInfo
.
namespaceName
.
replace
(
"
.xml
"
,
""
).
replace
(
"
.properties
"
,
""
).
replace
(
"
.json
"
,
""
).
replace
(
"
.yml
"
,
""
)
"
.properties
"
,
""
).
replace
(
"
.json
"
,
""
).
replace
(
"
.yml
"
,
""
)
.
replace
(
"
.yaml
"
,
""
);
.
replace
(
"
.yaml
"
,
""
)
.
replace
(
"
.txt
"
,
""
)
;
}
}
function
init
()
{
function
init
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment