-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
953 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# stiletto | ||
Launch system that allows classes to be invoked in phases to make sure all dependencies are satisfied. | ||
|
||
## Features | ||
* Custom phases | ||
* Builder-style | ||
|
||
## Installation | ||
|
||
#### Using Maven | ||
Add the following to your `pom.xml`-file: | ||
|
||
```xml | ||
<dependency> | ||
<groupId>com.github.pyknic</groupId> | ||
<artifactId>rocket</artifactId> | ||
<version>1.0.0</version> | ||
</dependency> | ||
``` | ||
|
||
#### Using Gradle | ||
Add the following to your `build.gradle`-file: | ||
```gradle | ||
compile group: 'com.github.pyknic', name: 'rocket', version: '1.0.0' | ||
``` | ||
|
||
## Usage | ||
The launch system follows a builder pattern where the two interfaces `Rocket` and `RocketBuilder` are central. | ||
|
||
### Configuration | ||
The builder pattern allows Rocket to be built by appending types available for launching. If the dependency graph is incomplete or contains cyclic dependencies when the `RocketBuilder.build()`-method is invoked, then an `RocketException` is thrown. | ||
|
||
```java | ||
// Create a new Launcher with a number of instances. | ||
Rocket rocket = Rocket.builder(Phase.class) | ||
.with(foo) | ||
.with(bar) | ||
.with(baz) | ||
.build(); | ||
``` | ||
|
||
### Define Phases | ||
Phases are defined by creating an `enum` class and passing it to the `Rocket.builder(...)`-method. | ||
|
||
```java | ||
// Define an enum with three phases. | ||
enum Phase { | ||
INIT, | ||
UPDATE, | ||
DESTROY | ||
} | ||
``` | ||
|
||
### Add Action | ||
Actions can be added to a class by adding the `@Execute`-annotation to the method. If the method takes any parameters, they will be injected automatically. Methods with the same phase will be invoked in a order that guarantees that all the arguments have already passed that stage. | ||
|
||
```java | ||
class ExampleComponent { | ||
|
||
@Execute("init") | ||
void onInit() { | ||
... | ||
} | ||
|
||
@Execute("update") | ||
void onUpdate(OtherComponent other) { | ||
... | ||
} | ||
|
||
} | ||
``` | ||
|
||
## License | ||
Copyright 2017 Emil Forslund | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
Copyright (c) ${currentYear}, Emil Forslund. All Rights Reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); You may not | ||
use this file except in compliance with the License. You may obtain a copy of | ||
the License at: | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
License for the specific language governing permissions and limitations under | ||
the License. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.github.pyknic</groupId> | ||
<artifactId>rocket</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
|
||
<name>Rocket</name> | ||
<description> | ||
Launch system that allows classes to be invoked in phases to make sure | ||
all dependencies are satisfied. | ||
</description> | ||
<url>https://www.github.com/Pyknic/rocket/</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<licenses> | ||
<license> | ||
<name>Apache License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<organization> | ||
<name>Emil Forslund</name> | ||
<url>http://github.com/pyknic</url> | ||
</organization> | ||
|
||
<developers> | ||
<developer> | ||
<name>Emil Forslund</name> | ||
<email>emil@speedment.com</email> | ||
<organization>Speedment</organization> | ||
<organizationUrl>http://www.speedment.com</organizationUrl> | ||
</developer> | ||
</developers> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.0.0-M3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<scm> | ||
<connection>scm:git:git@github.com:pyknic/rocket.git</connection> | ||
<developerConnection>scm:git:git@github.com:pyknic/rocket.git</developerConnection> | ||
<url>git@github.com:pyknic/rocket.git</url> | ||
</scm> | ||
|
||
<distributionManagement> | ||
<snapshotRepository> | ||
<id>ossrh</id> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots</url> | ||
</snapshotRepository> | ||
<repository> | ||
<id>ossrh</id> | ||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url> | ||
</repository> | ||
</distributionManagement> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.6.1</version> | ||
<configuration> | ||
<compilerArgument>-Xlint:all</compilerArgument> | ||
<showWarnings>true</showWarnings> | ||
<showDeprecation>true</showDeprecation> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<version>3.2.0</version> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<instructions> | ||
<Export-Package> | ||
com.github.pyknic.rocket | ||
</Export-Package> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>ossrh</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.mycila</groupId> | ||
<artifactId>license-maven-plugin</artifactId> | ||
<version>3.0</version> | ||
<configuration> | ||
<header>license_header.txt</header> | ||
<properties> | ||
<currentYear>2017</currentYear> | ||
</properties> | ||
<excludes> | ||
<exclude>**/README</exclude> | ||
<exclude>**/LICENSE</exclude> | ||
<exclude>**/*.xml</exclude> | ||
<exclude>**/*.iml</exclude> | ||
<exclude>**/package-info.java</exclude> | ||
<exclude>src/test/resources/**</exclude> | ||
<exclude>src/main/resources/**</exclude> | ||
</excludes> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>format</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>3.0.1</version> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar-no-fork</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>2.10.4</version> | ||
<executions> | ||
<execution> | ||
<id>attach-javadocs</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<docfilessubdirs>true</docfilessubdirs> | ||
<excludePackageNames>com.github.pyknic.rocket.internal</excludePackageNames> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-gpg-plugin</artifactId> | ||
<version>1.6</version> | ||
<executions> | ||
<execution> | ||
<id>sign-artifacts</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>sign</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<useAgent>true</useAgent> | ||
<keyname>${gpg.keyname}</keyname> | ||
<passphrase>${gpg.passphrase}</passphrase> | ||
<executable>${gpg.executable}</executable> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.sonatype.plugins</groupId> | ||
<artifactId>nexus-staging-maven-plugin</artifactId> | ||
<version>1.6.8</version> | ||
<extensions>true</extensions> | ||
<executions> | ||
<execution> | ||
<id>default-deploy</id> | ||
<phase>deploy</phase> | ||
<goals> | ||
<goal>deploy</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<serverId>ossrh</serverId> | ||
<nexusUrl>https://oss.sonatype.org/</nexusUrl> | ||
<autoReleaseAfterClose>true</autoReleaseAfterClose> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* | ||
* Copyright (c) 2017, Emil Forslund. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); You may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.github.pyknic.rocket; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotation that signals that a method should be invoked as part of a phase in | ||
* the launcher. | ||
* | ||
* @author Emil Forslund | ||
* @since 1.0.0 | ||
*/ | ||
@Inherited | ||
@Target({ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Execute { | ||
|
||
/** | ||
* Name of the phase to execute in. This should correspond to the result of | ||
* the {@link Enum#name()} method for that phase. | ||
* | ||
* @return the phase | ||
*/ | ||
String value(); | ||
|
||
} |
Oops, something went wrong.