These are two hobby projects that are proof of concepts. A build tool and a web framework. After using Node, Groovy and Scala quiet a bit over the last few years, I wanted to take some lessons learned from those languages and frameworks to write a simple light weight framework with java 8’s new features.
So, A goal from the start was to use one configuration file, which took me down a path of writing my own
build tool. It’s done in yaml, a more readable and compact format than xml, yet still declarative instead of using a groovy or ruby dsl. Even the title of the file tells you what kind of project is in that directory.
Over the years java has become very dependent on annotations and refection so you could say the approach I’ve taken with this framework could be called compiler first or maybe retro development.
The compiler is your first defense again bugs, but java libraries and project seem to have become very comfortable with the annotation first programming. It’s not necessarily bad, but why not take advantage of the compiler and catch bugs earlier in the development process. Fewer annotations means less refection and better performance as well. And thanks to some new features of java8 can can be much easier now.
Fabricate is a declaritve domain specific build tool using Yaml, and written in java. It’s based on the idea the type of project should determine the specific build tasks. The project is an application in of itself. Adding modules extends if functionality. Life cycle management.
Follow
the instructions found here.
Either Create a project by cloning the sample project
archetype:
name: java-lib
organization: org.m410.fabricate
version: 0.2-SNAPSHOT
application:
name: demo-lib
org: org.m410.demo
version: 0.2-SNAPSHOT
description: Sample java library
dependencies:
- { scope: compile, org: org.apache.commons, name: commons-lang3, rev: 3.3.2 }
testing(org.m410.fabricate:fab-junit:0.2-SNAPSHOT):
Fabricate can extend functionality with modules, modules add functionality like build tasks, application resources and dependencies.
Domain drivin means application properties can affect and be affected by the build process. The build tool is an extension of the application you are trying to create.
There is just one configuration file for the entire project. One of the major goals was to consolidate configuration. Other than source code, the only other configuration file that is needed is the build configuration file. For example, there is no need to create and maintain the persistence.xml and web.xml file.
// Application Assembly Class
public final class DemoApplication extends Application implements JpaModule {
PersonDao personDao = new PersonDaoImpl();
PersonService personService = new PersonServiceImpl(personDao);
@Override public List<HttpCtrl> makeControllers(Configuration c) {
return ImmutableList.of( new PersonController(personService));
}
}
// Example Controller
public final class PersonController extends Controller {
private final PersonService personService;
public PersonController(PersonService service) {
super("persons");
this.personService = service;
}
@Override public List<? extends HttpActionDefinition> actions() {
return ImmutableList.of(
get("", list),
post("", save),
);
}
Action list = req -> respond().asJson(personService.list());
Action save = request -> {
personService.save(gson.fromJson(request.bodyAsString(), Person.class));
return respond().asJson(ImmutableMap.of("success", true));
};
}
Garden is a web framework built on top of Fab(ricate). It’s a Restful, Action based framework with built in support for xml, json, binary files, security, transactions, authentication and authorization.
Garden does not use byte code manipulation, but it can rapidly recompile and reload in development mode. Saving a lot of time in the round trip development life cycle with a minimum of dependencies and overhead.
Garden also takes advantage of fab(ricate)s modular architecture to easily add functionality and dependencies. Like JPA, JMS and many other service providers.
Some other modules in the works.
Garden was the inspiration for fab(ricate) so of course it uses the single configuration file for all management. With easy environment switching.
The application class is the central wiring point for the app. It handles service wiring, imported service, startup and shutdown.
// Application Assembly Class
public final class DemoApplication extends Application implements JpaModule {
PersonDao personDao = new PersonDaoImpl();
PersonService personService = new PersonServiceImpl(personDao);
@Override public List<HttpCtrl> makeControllers(Configuration c) {
return ImmutableList.of( new PersonController(personService));
}
}
public class MyController extends Controller implements Authorizable {
public MyController() {
super("basepath");
this.roles = Arrays.asList("ADMIN","USER");
this.useSsl = Securable.State.Only;
}
public List<ActionDefinition> actions() {
return ImmutableList.of(
get("{id:\\d+}", view).contentTypes("text/html").roles("ADMIN")
);
}
Action view = req -> respond().withModel("name","value").withView("/view.jsp");
}
A controller is a basic building block of web development. In the example you can see transaction, content type, and http method, and authorization usage.