Skip to content

Commit

Permalink
Merge pull request #77 from youngmonkeys/dev
Browse files Browse the repository at this point in the history
version 1.2.1
  • Loading branch information
tvd12 authored Dec 2, 2021
2 parents c0a0ac6 + 106cbfe commit 9f5586c
Show file tree
Hide file tree
Showing 68 changed files with 1,714 additions and 99 deletions.
2 changes: 1 addition & 1 deletion ezyfox-bean/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyfox-versions</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
</parent>
<artifactId>ezyfox-bean</artifactId>
<name>ezyfox-bean</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public interface EzyBeanContextBuilder extends EzyBuilder<EzyBeanContext> {

EzyBeanContextBuilder scan(Collection<String> packageNames);

EzyBeanContextBuilder activeProfiles(String activeProfiles);

EzyBeanContextBuilder excludePackage(String packageName);

EzyBeanContextBuilder excludePackages(String... packageNames);
Expand Down Expand Up @@ -97,10 +99,18 @@ public interface EzyBeanContextBuilder extends EzyBuilder<EzyBeanContext> {

EzyBeanContextBuilder addProperties(String file, String activeProfiles);

EzyBeanContextBuilder addProperties(Iterable<String> files);

EzyBeanContextBuilder addProperties(Iterable<String> files, String activeProfiles);

EzyBeanContextBuilder addProperties(File file);

EzyBeanContextBuilder addProperties(File file, String activeProfiles);

EzyBeanContextBuilder addProperties(Collection<File> files);

EzyBeanContextBuilder addProperties(Collection<File> files, String activeProfiles);

EzyBeanContextBuilder addProperties(InputStream inputStream);

EzyBeanContextBuilder addProperty(String key, Object value);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.tvd12.ezyfox.bean;

import java.util.Set;

public interface EzyPackagesToScanProvider {

Set<String> provide();
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public static class Builder extends EzyLoggable implements EzyBeanContextBuilder
protected Properties properties;
protected Set<String> packagesToScan;
protected Set<String> packagesToExclude;
protected Set<String> activeProfileSet;
protected Set<Class> excludeConfigurationClasses;
protected Set<Class> importClasses;
protected Set<Class> singletonClasses;
Expand Down Expand Up @@ -275,6 +276,7 @@ public Builder() {
this.properties.putAll(System.getProperties());
this.packagesToScan = new HashSet<>();
this.packagesToExclude = new HashSet<>();
this.activeProfileSet = new HashSet<>();
this.importClasses = new HashSet<>();
this.singletonClasses = new HashSet<>();
this.prototypeClasses = new HashSet<>();
Expand Down Expand Up @@ -315,7 +317,8 @@ public EzyBeanContextBuilder disableAutoConfiguration() {
*/
@Override
public EzyBeanContextBuilder scan(String packageName) {
packagesToScan.add(packageName);
if(packageName != null)
packagesToScan.add(packageName);
return this;
}

Expand Down Expand Up @@ -344,6 +347,20 @@ public EzyBeanContextBuilder scan(Collection<String> packageNames) {
return this;
}

/* (non-Javadoc)
* @see com.tvd12.ezyfox.bean.impl.EzyBeanContextBuilder#activeProfiles(java.lang.String)
*/
@Override
public EzyBeanContextBuilder activeProfiles(String activeProfiles) {
if(activeProfiles != null) {
String[] strs = activeProfiles.split(",");
for(String str : strs) {
this.activeProfileSet.add(str.trim());
}
}
return this;
}

/* (non-Javadoc)
* @see com.tvd12.ezyfox.bean.impl.EzyBeanContextBuilder#excludePackage(java.lang.String)
*/
Expand Down Expand Up @@ -684,19 +701,45 @@ public EzyBeanContextBuilder addProperties(Map properties) {

/*
* (non-Javadoc)
* @see com.tvd12.ezyfox.bean.EzyBeanContextBuilder#addProperties(java.util.String)
* @see com.tvd12.ezyfox.bean.EzyBeanContextBuilder#addProperties(java.lang.String)
*/
@Override
public EzyBeanContextBuilder addProperties(String file) {
return addProperties(file, getActiveProfiles());
}

/*
* (non-Javadoc)
* @see com.tvd12.ezyfox.bean.EzyBeanContextBuilder#addProperties(java.lang.String, java.lang.String)
*/
@Override
public EzyBeanContextBuilder addProperties(String file, String activeProfiles) {
Properties props = new MultiFileReader(activeProfiles).read(file);
return addProperties(props);
}

/*
* (non-Javadoc)
* @see com.tvd12.ezyfox.bean.EzyBeanContextBuilder#addProperties(java.lang.Iterable)
*/
@Override
public EzyBeanContextBuilder addProperties(Iterable<String> files) {
for(String file : files)
addProperties(file);
return this;
}

/*
* (non-Javadoc)
* @see com.tvd12.ezyfox.bean.EzyBeanContextBuilder#addProperties(java.lang.Iterable, java.lang.String)
*/
@Override
public EzyBeanContextBuilder addProperties(Iterable<String> files, String activeProfiles) {
for(String file : files)
addProperties(file, activeProfiles);
return this;
}

/*
* (non-Javadoc)
* @see com.tvd12.ezyfox.bean.EzyBeanContextBuilder#addProperties(java.io.File)
Expand All @@ -706,12 +749,38 @@ public EzyBeanContextBuilder addProperties(File file) {
return addProperties(file, getActiveProfiles());
}

/*
* (non-Javadoc)
* @see com.tvd12.ezyfox.bean.EzyBeanContextBuilder#addProperties(java.io.File, java.lang.String)
*/
@Override
public EzyBeanContextBuilder addProperties(File file, String activeProfiles) {
Properties props = new MultiFileReader(activeProfiles).read(file);
return addProperties(props);
}

/*
* (non-Javadoc)
* @see com.tvd12.ezyfox.bean.EzyBeanContextBuilder#addProperties(java.util.Collection)
*/
@Override
public EzyBeanContextBuilder addProperties(Collection<File> files) {
for(File file : files)
addProperties(file);
return this;
}

/*
* (non-Javadoc)
* @see com.tvd12.ezyfox.bean.EzyBeanContextBuilder#addProperties(java.util.Collection, java.lang.String)
*/
@Override
public EzyBeanContextBuilder addProperties(Collection<File> files, String activeProfiles) {
for(File file : files)
addProperties(file, activeProfiles);
return this;
}

/*
* (non-Javadoc)
* @see com.tvd12.ezyfox.bean.EzyBeanContextBuilder#addProperties(java.io.InputStream)
Expand Down Expand Up @@ -792,6 +861,7 @@ public EzySimpleBeanContext build() {
removeExcludeConfigurationClasses();
loadPropertiesBeanClasses();
loadPropertiesSources();
setVariableValues(properties);
mapProperties();
addPropertiesBeans();
singletonFactory.addSingletonClasses(singletonClasses);
Expand Down Expand Up @@ -823,7 +893,18 @@ private String getActiveProfiles() {
String activeProfiles = properties.getProperty(ACTIVE_PROFILES_KEY);
if(EzyStrings.isNoContent(activeProfiles))
activeProfiles = properties.getProperty(EZYFOX_ACTIVE_PROFILES_KEY);
return activeProfiles;
if(activeProfiles == null) {
if(activeProfileSet.size() > 0) {
return String.join(",", activeProfileSet);
}
return null;
}
else {
if(activeProfileSet.size() > 0) {
return activeProfiles + "," + String.join(",", activeProfileSet);
}
return activeProfiles;
}
}

private void removeExcludeConfigurationClasses() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ public void test() throws Exception {
EzyByMethodSingletonLoader loader = new EzyByMethodSingletonLoader(
"a",
methodA, this, EzyMaps.newHashMap(B.class, methodB));
loader.load(context);

Method getConstructorParameterTypes = EzyByMethodSingletonLoader.class
.getDeclaredMethod("getConstructorParameterTypes", Class.class);
getConstructorParameterTypes.setAccessible(true);
getConstructorParameterTypes.invoke(loader, B.class);
getConstructorParameterTypes.invoke(loader, Object.class);

loader.load(context);
}

public static class A {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.tvd12.ezyfox.bean.testing;

import java.util.Properties;

import org.testng.annotations.Test;

import com.tvd12.ezyfox.bean.EzyBeanContext;
import com.tvd12.ezyfox.bean.EzyBeanContextBuilder;
import com.tvd12.test.assertion.Asserts;
import com.tvd12.test.reflect.FieldUtil;
import com.tvd12.test.reflect.MethodUtil;

public class EzySimpleBeanContextBuilderTest {

@Test
public void activeProfilesTest() {
// given
String activeProfiles = "foo,bar";

EzyBeanContextBuilder sut = EzyBeanContext.builder()
.scan((String)null)
.addProperty(EzyBeanContext.ACTIVE_PROFILES_KEY, "hello,big,world")
.activeProfiles(activeProfiles);

// when
String actual = MethodUtil.invokeMethod("getActiveProfiles", sut);

// then
Asserts.assertEquals("hello,big,world,bar,foo", actual);
}

@Test
public void activeProfilesDefaultNullTest() {
// given
String activeProfiles = "foo,bar";

EzyBeanContextBuilder sut = EzyBeanContext.builder()
.activeProfiles(null)
.scan((String)null);

Properties properties = FieldUtil.getFieldValue(sut, "properties");
properties.clear();

sut.activeProfiles(activeProfiles);

// when
String actual = MethodUtil.invokeMethod("getActiveProfiles", sut);

// then
Asserts.assertEquals("bar,foo", actual);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tvd12.ezyfox.bean.testing;

import java.io.File;
import java.util.Arrays;
import java.util.Properties;

import org.testng.annotations.Test;
Expand All @@ -17,7 +18,9 @@ public void classpathPropertiesFile() {
System.setProperty(EzyBeanContext.ACTIVE_PROFILES_KEY, "alpha");
EzyBeanContextBuilder beanContextBuilder = EzyBeanContext.builder()
.addProperties("config/config.properties", "alpha")
.addProperties("config/config.yaml", "alpha");
.addProperties("config/config.yaml", "alpha")
.addProperties(Arrays.asList("config/config.properties"))
.addProperties(Arrays.asList("config/config.properties"), "alpha");
Asserts.assertTrue(beanContextBuilder.getProperties().size() > 0);
EzyBeanContext beanContext = beanContextBuilder.build();
Properties properties = beanContext.getProperties();
Expand All @@ -38,6 +41,8 @@ public void systemPropertiesFile() {
System.setProperty(EzyBeanContext.EZYFOX_ACTIVE_PROFILES_KEY, "alpha");
EzyBeanContext beanContext = EzyBeanContext.builder()
.addProperties(new File("test-data/v111_props1.properties"), "alpha")
.addProperties(Arrays.asList(new File("test-data/v111_props1.properties")))
.addProperties(Arrays.asList(new File("test-data/v111_props1.properties")), "alpha")
.build();
Properties properties = beanContext.getProperties();
Asserts.assertEquals("hello", properties.getProperty("v111_a"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.tvd12.ezyfox.bean.v120.testing.packet01;

import java.util.Collections;
import java.util.Set;

import com.tvd12.ezyfox.bean.EzyPackagesToScanProvider;

public class PackagesProvider implements EzyPackagesToScanProvider {

@Override
public Set<String> provide() {
return Collections.singleton("com.tvd12.ezyfox.bean.v120.testing.packet01");
}
}
2 changes: 1 addition & 1 deletion ezyfox-binding-codec/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyfox-versions</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
</parent>
<artifactId>ezyfox-binding-codec</artifactId>
<name>ezyfox-binding-codec</name>
Expand Down
2 changes: 1 addition & 1 deletion ezyfox-binding/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyfox-versions</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
</parent>
<artifactId>ezyfox-binding</artifactId>
<name>ezyfox-binding</name>
Expand Down
2 changes: 1 addition & 1 deletion ezyfox-codec/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyfox-versions</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
</parent>
<artifactId>ezyfox-codec</artifactId>
<name>ezyfox-codec</name>
Expand Down
2 changes: 1 addition & 1 deletion ezyfox-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyfox-versions</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
</parent>
<artifactId>ezyfox-common</artifactId>
<name>ezyfox-common </name>
Expand Down
Loading

0 comments on commit 9f5586c

Please sign in to comment.