Skip to content

Commit

Permalink
Remove the concept of Component
Browse files Browse the repository at this point in the history
  • Loading branch information
minborg committed Sep 28, 2016
1 parent d01c542 commit e6eceb3
Show file tree
Hide file tree
Showing 54 changed files with 247 additions and 516 deletions.
Expand Up @@ -47,7 +47,7 @@ public static Stream<Method> traverseMethods(Class<?> clazz) {
}

public static Stream<Class<?>> traverseAncestors(Class<?> clazz) {
if (clazz.getSuperclass() == null) {
if (clazz.getSuperclass() == null) { // We have reached Object.class
return Stream.of(clazz);
} else {
return Stream.concat(
Expand Down
Expand Up @@ -23,7 +23,6 @@
import com.speedment.generator.translator.TranslatorKey;
import com.speedment.common.injector.annotation.InjectKey;
import com.speedment.runtime.annotation.Api;
import com.speedment.runtime.component.Component;
import com.speedment.runtime.config.trait.HasMainInterface;
import com.speedment.runtime.config.trait.HasName;
import com.speedment.runtime.exception.SpeedmentException;
Expand All @@ -40,12 +39,7 @@
*/
@Api(version = "3.0")
@InjectKey(CodeGenerationComponent.class)
public interface CodeGenerationComponent extends Component {

@Override
default Class<CodeGenerationComponent> getComponentClass() {
return CodeGenerationComponent.class;
}
public interface CodeGenerationComponent {

/**
* Puts a new {@code TranslatorConstructor} for the given class/key pair. If
Expand Down
Expand Up @@ -20,7 +20,6 @@
import com.speedment.generator.event.Event;
import com.speedment.common.injector.annotation.InjectKey;
import com.speedment.runtime.annotation.Api;
import com.speedment.runtime.component.Component;

import java.util.function.Consumer;

Expand All @@ -36,12 +35,8 @@
*/
@Api(version = "3.0")
@InjectKey(EventComponent.class)
public interface EventComponent extends Component {
public interface EventComponent {

@Override
public default Class<? extends Component> getComponentClass() {
return EventComponent.class;
}

/**
* Notifies all listeners for this type of event.
Expand Down
Expand Up @@ -17,7 +17,6 @@
package com.speedment.generator.component;

import com.speedment.common.injector.annotation.InjectKey;
import com.speedment.runtime.component.Component;
import java.nio.file.Path;

/**
Expand All @@ -28,12 +27,8 @@
* @since 3.0.0
*/
@InjectKey(PathComponent.class)
public interface PathComponent extends Component {
public interface PathComponent {

@Override
default Class<? extends Component> getComponentClass() {
return PathComponent.class;
}

/**
* Returns the base directory of the project (the same folder as the
Expand Down
Expand Up @@ -18,7 +18,6 @@

import com.speedment.common.injector.annotation.InjectKey;
import com.speedment.runtime.annotation.Api;
import com.speedment.runtime.component.Component;
import com.speedment.runtime.config.Column;
import com.speedment.runtime.config.mapper.TypeMapper;
import com.speedment.runtime.internal.config.mapper.IdentityTypeMapper;
Expand All @@ -35,12 +34,7 @@
*/
@Api(version = "3.0")
@InjectKey(TypeMapperComponent.class)
public interface TypeMapperComponent extends Component {

@Override
default Class<TypeMapperComponent> getComponentClass() {
return TypeMapperComponent.class;
}
public interface TypeMapperComponent {

/**
* Installs the specified type mapper in this component.
Expand Down
@@ -1,14 +1,5 @@
/**
* The {@link com.speedment.runtime.component.Component Components} of the
* {@link com.speedment.runtime.Speedment Speedment} platform. These are
* modularized units of logic that together make up Speedment.
* The generator's components.
* <p>
* A general description of the component system can be found here:
* <a href="http://minborgsjavapot.blogspot.com/2016/02/plugin-your-own-components-with-java-8.html">
* Plugin Your Own Components with Java 8
* </a> by Per-Åke Minborg
* <p>
* This package is part of the API. Modifications to classes here should only
* (if ever) be done in major releases.
*/
package com.speedment.generator.component;
Expand Up @@ -21,6 +21,7 @@
import com.speedment.common.codegen.model.File;
import com.speedment.generator.internal.translator.TranslatorManagerImpl;
import com.speedment.runtime.Speedment;
import com.speedment.runtime.component.ProjectComponent;
import com.speedment.runtime.config.Column;
import com.speedment.runtime.config.Dbms;
import com.speedment.runtime.config.PrimaryKeyColumn;
Expand All @@ -35,7 +36,6 @@

import java.util.Optional;
import java.util.stream.Stream;

import static java.util.stream.Collectors.joining;

/**
Expand Down Expand Up @@ -83,12 +83,12 @@ public void simpleModelTestSetUp() {

speedment = new DefaultApplicationBuilder(SimpleMetadata.class)
.withBundle(GeneratorBundle.class)
.withInjectable(SilentTranslatorManager.class)
.withComponent(SilentTranslatorManager.class)
.withSkipCheckDatabaseConnectivity()
.withSkipValidateRuntimeConfig()
.build();

project = speedment.project();
project = speedment.getOrThrow(ProjectComponent.class).getProject();
dbms = project.dbmses().findAny().get();
schema = dbms.schemas().findAny().get();
table = schema.tables().filter(t -> TABLE_NAME.equals(t.getName())).findAny().get();
Expand Down
Expand Up @@ -20,6 +20,7 @@
import com.speedment.generator.translator.TranslatorManager;
import com.speedment.runtime.ApplicationBuilder;
import com.speedment.runtime.Speedment;
import com.speedment.runtime.component.ProjectComponent;
import com.speedment.runtime.config.Project;
import com.speedment.runtime.exception.SpeedmentException;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -61,7 +62,7 @@ public void execute(Speedment speedment) throws MojoExecutionException, MojoFail

if (hasConfigFile()) {
try {
final Project project = speedment.project();
final Project project = speedment.getOrThrow(ProjectComponent.class).getProject();
speedment.getOrThrow(TranslatorManager.class).clearExistingFiles(project);
} catch (final SpeedmentException ex) {
final String err = "Error parsing configFile file.";
Expand Down
Expand Up @@ -20,6 +20,7 @@
import com.speedment.generator.translator.TranslatorManager;
import com.speedment.runtime.ApplicationBuilder;
import com.speedment.runtime.Speedment;
import com.speedment.runtime.component.ProjectComponent;
import com.speedment.runtime.config.Project;
import com.speedment.runtime.exception.SpeedmentException;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -60,7 +61,7 @@ public void execute(Speedment speedment) throws MojoExecutionException, MojoFail

if (hasConfigFile()) {
try {
final Project project = speedment.project();
final Project project = speedment.getOrThrow(ProjectComponent.class).getProject();
speedment.getOrThrow(TranslatorManager.class).accept(project);
} catch (final SpeedmentException ex) {
final String err = "Error parsing configFile file.";
Expand Down
Expand Up @@ -29,10 +29,7 @@
import com.speedment.common.injector.annotation.WithState;
import com.speedment.runtime.ApplicationBuilder;
import com.speedment.runtime.Speedment;
import com.speedment.runtime.component.Component;
import com.speedment.runtime.config.mapper.TypeMapper;
import com.speedment.runtime.internal.DefaultApplicationBuilder;
import com.speedment.runtime.internal.DefaultApplicationMetadata;
import com.speedment.tool.internal.component.UserInterfaceComponentImpl;

import org.apache.maven.plugin.AbstractMojo;
Expand Down Expand Up @@ -84,7 +81,7 @@ protected AbstractSpeedmentMojo(Consumer<ApplicationBuilder<?, ?>> configurer) {
public final void execute() throws MojoExecutionException, MojoFailureException {

final ApplicationBuilder<?, ?> builder = createBuilder();
builder.withInjectable(MavenPathComponent.class);
builder.withComponent(MavenPathComponent.class);
configurer.accept(builder);
if (debug()) {
builder.withLoggingOf(ApplicationBuilder.LogType.APPLICATION_BUILDER);
Expand Down Expand Up @@ -176,13 +173,15 @@ protected final boolean hasConfigFile(File file) {
result
.withBundle(GeneratorBundle.class)
.withBundle(ToolBundle.class)
.with(CodeGenerationComponentImpl.class)
.with(UserInterfaceComponentImpl.class)
.with(MavenPathComponent.class);
.withComponent(CodeGenerationComponentImpl.class)
.withComponent(UserInterfaceComponentImpl.class)
.withComponent(MavenPathComponent.class);

// Add any extra type mappers requested by the user
TypeMapperInstaller.mappings = typeMappers(); // <-- Hack to pass type mappers to class with default constructor.
result.withInjectable(TypeMapperInstaller.class);


result.withComponent(TypeMapperInstaller.class);

// Add extra components requested by the user
final String[] components = components();
Expand All @@ -191,18 +190,13 @@ protected final boolean hasConfigFile(File file) {
try {
final Class<?> uncasted = Class.forName(component);

if (Component.class.isAssignableFrom(uncasted)) {
@SuppressWarnings("unchecked")
final Class<? extends Component> casted
= (Class<? extends Component>) uncasted;
result.with(casted);
} else if (InjectBundle.class.isAssignableFrom(uncasted)) {
if (InjectBundle.class.isAssignableFrom(uncasted)) {
@SuppressWarnings("unchecked")
final Class<? extends InjectBundle> casted
= (Class<? extends InjectBundle>) uncasted;
result.withBundle(casted);
} else {
result.withInjectable(uncasted);
result.withComponent(uncasted);
}

} catch (final ClassNotFoundException ex) {
Expand Down
Expand Up @@ -51,13 +51,4 @@ public Path packageLocation() {
return baseDir().resolve(project.getPackageLocation());
}

@Override
public Software asSoftware() {
return AbstractSoftware.with("Maven Path Component", "3.0.0", APACHE_2);
}

@Override
public boolean isInternal() {
return true;
}
}
Expand Up @@ -34,7 +34,6 @@
import com.speedment.plugins.enums.internal.ui.CommaSeparatedStringEditor;
import com.speedment.runtime.config.Column;
import com.speedment.runtime.config.Table;
import com.speedment.runtime.internal.component.AbstractComponent;
import com.speedment.runtime.internal.license.AbstractSoftware;
import static com.speedment.runtime.license.OpenSourceLicense.APACHE_2;
import com.speedment.runtime.license.Software;
Expand All @@ -55,7 +54,7 @@
* @since 1.0.0
*/
@InjectKey(EnumGeneratorComponent.class)
public final class EnumGeneratorComponent extends AbstractComponent {
public final class EnumGeneratorComponent {

public static InjectBundle include() {
return InjectBundle.of(
Expand All @@ -78,18 +77,4 @@ void installDecorators(Injector injector,

}

@Override
public Class<EnumGeneratorComponent> getComponentClass() {
return EnumGeneratorComponent.class;
}

@Override
public Software asSoftware() {
return AbstractSoftware.with(
"Enum Generator",
"1.0.0",
"Generate enum implementations for columns marked as ENUM in the database.",
APACHE_2
);
}
}
Expand Up @@ -39,7 +39,6 @@
import com.speedment.plugins.reactor.translator.ReactorTranslatorKey;
import com.speedment.runtime.config.Project;
import com.speedment.runtime.config.Table;
import com.speedment.runtime.internal.component.AbstractComponent;
import static com.speedment.runtime.license.OpenSourceLicense.APACHE_2;
import com.speedment.tool.component.PropertyEditorComponent;
import com.speedment.tool.component.UserInterfaceComponent;
Expand All @@ -51,7 +50,7 @@
* @since 1.1.0
*/
@InjectKey(ReactorComponent.class)
public final class ReactorComponent extends AbstractComponent {
public final class ReactorComponent {

public static InjectBundle include() {
return InjectBundle.of(
Expand Down Expand Up @@ -82,15 +81,4 @@ void setup(
editors.install(TableProperty.class, MERGE_ON, MergeOnEditor::new);
}

@Override
public Class<ReactorComponent> getComponentClass() {
return ReactorComponent.class;
}

@Override
public Software asSoftware() {
return AbstractSoftware.with(
"Reactor Plugin", "1.1.0", APACHE_2
);
}
}
Expand Up @@ -27,11 +27,6 @@
import com.speedment.plugins.spring.internal.SpringTranslatorKey;
import com.speedment.runtime.config.Project;
import com.speedment.runtime.config.Table;
import com.speedment.runtime.internal.component.AbstractComponent;
import com.speedment.runtime.internal.license.AbstractSoftware;
import com.speedment.runtime.license.Software;

import static com.speedment.runtime.license.OpenSourceLicense.APACHE_2;

/**
* Plugs into the Speedment platform, generating Spring annotated classes as
Expand All @@ -48,7 +43,7 @@
* @author Emil Forslund
* @since 1.0.0
*/
public final class SpringGeneratorComponent extends AbstractComponent {
public final class SpringGeneratorComponent {

@ExecuteBefore(RESOLVED)
void onResolve(@WithState(RESOLVED) CodeGenerationComponent code) {
Expand All @@ -73,13 +68,4 @@ void onResolve(@WithState(RESOLVED) CodeGenerationComponent code) {
);
}

@Override
public Class<SpringGeneratorComponent> getComponentClass() {
return SpringGeneratorComponent.class;
}

@Override
public Software asSoftware() {
return AbstractSoftware.with("Spring Generator", "1.0.0", APACHE_2);
}
}
1 change: 0 additions & 1 deletion runtime/dependency-reduced-pom.xml
Expand Up @@ -29,7 +29,6 @@
com.speedment.runtime.license.*,
com.speedment.runtime.manager.*,
com.speedment.runtime.stream.*,
com.speedment.runtime.transaction.*,
com.speedment.runtime.util.*,
com.speedment.runtime,
com.speedment.common.injector,
Expand Down

0 comments on commit e6eceb3

Please sign in to comment.