Skip to content

Commit

Permalink
maven reorg, recorder page initial
Browse files Browse the repository at this point in the history
  • Loading branch information
bs committed Apr 30, 2019
1 parent 413a796 commit 033fc52
Show file tree
Hide file tree
Showing 162 changed files with 1,640 additions and 341 deletions.
File renamed without changes.
30 changes: 30 additions & 0 deletions drift-core/drift-core-domain/drift-core-domain.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.springframework:spring-context-support:4.3.11.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:4.3.11.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:4.3.11.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:4.3.11.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.3.11.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:4.3.11.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.8" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.10" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.1.11" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>
55 changes: 55 additions & 0 deletions drift-core/drift-core-domain/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>io.drift</groupId>
<artifactId>drift-core</artifactId>
<version>0.0.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>drift-core-domain</artifactId>
<packaging>jar</packaging>
<name>Drift :: Core :: Domain</name>

<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.giffing.wicket.spring.boot.starter</groupId>
<artifactId>wicket-spring-boot-starter</artifactId>
<version>1.0.10</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.drift.core.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class DriftAnnotationPostProcessor implements BeanPostProcessor {

private final DriftEngine driftEngine;

public DriftAnnotationPostProcessor(DriftEngine driftEngine) {
this.driftEngine = driftEngine;
}


@Override
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
return bean;
}

@Override
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
if (bean instanceof EnginePlugin) {
EnginePlugin plugin = (EnginePlugin) bean;
driftEngine.registerPlugin(plugin);
}

return bean;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package io.drift.core.config;

import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.context.annotation.*;

import io.drift.core.api.FocalArea;

@Configuration
@ComponentScan(basePackageClasses = DriftCoreConfig.class)
public class DriftCoreConfig {

@Bean
public static BeanFactoryPostProcessor driftScopeBeanFactoryPostProcessor() {
return new DriftScopeBeanFactoryPostProcessor();
}

// @DriftSessionScoped
@Scope(value = DriftSessionScope.DRIFT_SESSION_SCOPE, proxyMode = ScopedProxyMode.TARGET_CLASS)
@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package io.drift.core.config;

import io.drift.core.api.Flow;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class DriftEngine {

private List<Flow> flows = new ArrayList<Flow>();

public DriftEngine() {
init();
}

private void init() {
}

public List<Flow> getFlows() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

@Component
public class DriftScopeBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.drift.core.lifecycle;

import java.util.HashMap;
import java.util.Map;

abstract public class AbstractScope implements Scope {

private Map<Class, Object> objects = new HashMap<>();

protected Object getOrCreate(BeanDescriptor descriptor) {
Object object = objects.get(descriptor.getBeanClass());
if (object == null) {
object = create(descriptor);
objects.put(descriptor.getBeanClass(), object);
}
return object;

}

protected Object create(BeanDescriptor descriptor) {
return descriptor.getConstructor().create();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.drift.core.lifecycle;

@FunctionalInterface
public interface BeanConstructor {
Object create();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.drift.core.lifecycle;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BeanContainer {

private Map<Class, BeanDescriptor> descriptors = new HashMap<>();

private List<Scope> scopes = new ArrayList<>();

public Object getBean(Class _class) {
BeanDescriptor descriptor = descriptors.get(_class);
return descriptor.getScope().getBean(descriptor);
}

public void registerModule(Module module) {
module.registerTo(this);
}

public void registerBean(BeanDescriptor descriptor) {
descriptors.put(descriptor.getBeanClass(), descriptor);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.drift.core.lifecycle;

public class BeanDescriptor {

private BeanConstructor constructor;

private Scope scope;

private Class beanClass;

public BeanDescriptor(Class beanClass, Scope scope, BeanConstructor constructor) {
this.constructor = constructor;
this.scope = scope;
this.beanClass = beanClass;
}

public BeanConstructor getConstructor() {
return constructor;
}

public Class getBeanClass() {
return beanClass;
}

public Scope getScope() {
return scope;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.drift.core.lifecycle;

public class FlowScope extends AbstractScope implements Scope {
@Override
public Object getBean(BeanDescriptor descriptor) {
return create(descriptor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.drift.core.lifecycle;

public interface Module {
void registerTo(BeanContainer beanContainer);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.drift.core.lifecycle;

public class RequestScope extends AbstractScope implements Scope {
@Override
public Object getBean(BeanDescriptor descriptor) {
return create(descriptor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.drift.core.lifecycle;

public interface Scope {
Object getBean(BeanDescriptor descriptor);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.drift.core.lifecycle;

public class SingletonScope extends AbstractScope implements Scope {

@Override
public Object getBean(BeanDescriptor descriptor) {
return getOrCreate(descriptor);
}

}
7 changes: 7 additions & 0 deletions drift-core/drift-core-domain/src/site/_site.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<project name="drift-core">
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.7</version>
</skin>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.drift.core.lifecycle;

public class ConfigBean {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.drift.core.lifecycle;

public class FlowScopedBean {

private SingletonScopedBean singletonScopedBean;

public FlowScopedBean(SingletonScopedBean singletonScopedBean) {
this.singletonScopedBean = singletonScopedBean;
}

public void doSomething() {
singletonScopedBean.doSomething();
}

public SingletonScopedBean getSingletonScopedBean() {
return singletonScopedBean;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.drift.core.lifecycle;

import junit.framework.TestCase;
import org.junit.Assert;

public class LifeCycleTest extends TestCase {

private BeanContainer beanContainer;

protected void setUp() {
beanContainer = new BeanContainer();
beanContainer.registerModule(new Module1());
}

public void testBeanCreation() {

SingletonScopedBean singletonScopedBean = (SingletonScopedBean) beanContainer.getBean(SingletonScopedBean.class);
Assert.assertNotNull(singletonScopedBean);

FlowScopedBean flowScopedBean = (FlowScopedBean) beanContainer.getBean(FlowScopedBean.class);
Assert.assertNotNull(flowScopedBean);
Assert.assertNotNull(flowScopedBean.getSingletonScopedBean());

RequestScopedBean requestScopedBean = (RequestScopedBean) beanContainer.getBean(RequestScopedBean.class);
Assert.assertNotNull(requestScopedBean.getFlowScopedBean());
Assert.assertNotNull(requestScopedBean.getFlowScopedBean().getSingletonScopedBean());

}

public void testSingletonScope() {
SingletonScopedBean singletonScopedBean = (SingletonScopedBean) beanContainer.getBean(SingletonScopedBean.class);
SingletonScopedBean singletonScopedBean2 = (SingletonScopedBean) beanContainer.getBean(SingletonScopedBean.class);
Assert.assertEquals(singletonScopedBean, singletonScopedBean2);

FlowScopedBean flowScopedBean = (FlowScopedBean) beanContainer.getBean(FlowScopedBean.class);
FlowScopedBean flowScopedBean2 = (FlowScopedBean) beanContainer.getBean(FlowScopedBean.class);
Assert.assertNotEquals(flowScopedBean, flowScopedBean2);
Assert.assertEquals(singletonScopedBean, flowScopedBean.getSingletonScopedBean());

RequestScopedBean requestScopedBean = (RequestScopedBean) beanContainer.getBean(RequestScopedBean.class);
RequestScopedBean requestScopedBean2 = (RequestScopedBean) beanContainer.getBean(RequestScopedBean.class);
Assert.assertNotEquals(requestScopedBean, requestScopedBean2);
Assert.assertEquals(singletonScopedBean, requestScopedBean.getFlowScopedBean().getSingletonScopedBean());



}

public void testStoreBackedBean() {



}

}
Loading

0 comments on commit 033fc52

Please sign in to comment.