-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a sample addon to showcase addon development
- Loading branch information
Showing
13 changed files
with
745 additions
and
1 deletion.
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,4 @@ | ||
*.pdfmarks | ||
*.iml | ||
*.ipr | ||
*.iws |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
== Installing Forge | ||
|
||
[[installing-forge]] | ||
|
||
=== Installing Forge CLI | ||
It's very simple install Forge CLI. | ||
|
Binary file not shown.
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,18 @@ | ||
.classpath | ||
.project | ||
.settings | ||
.DS_Store | ||
dependency-reduced-pom.xml | ||
target/ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
*.swp | ||
/*/src/main/java/META-INF | ||
.gitignore.swp | ||
docs/reference/src/main/docbook/en-US/version_info.xml | ||
.idea | ||
.forge_settings | ||
.factorypath | ||
atlassian-ide-plugin.xml | ||
.externalToolBuilders |
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,62 @@ | ||
== envers | ||
:idprefix: id_ | ||
(choose one, do not modify, then add a second sentence with a brief description, starting with - "The envers addon enables blah blah...) | ||
This addon provides *standalone* functionality, and *exports services* for use in other addons. | ||
This addon provides *standalone* functionality. | ||
This addon *exports services* for use in other addons. | ||
This addon *provides classes* for use in other addons. | ||
This addon is a 'Furnace container' that provides *lifecycle* and *service registry* support for dependent addons. | ||
|
||
=== Dependencies: None (or) | ||
=== Depends on | ||
[options="header"] | ||
|=== | ||
|Addon |Exported |Optional | ||
|DEP1 | ||
|yes | ||
|no | ||
|DEP2 | ||
|yes | ||
|yes | ||
|=== | ||
|
||
== Setup | ||
This Addon requires the following installation steps. | ||
=== Add configuration to pom.xml | ||
To use this addon, you must add it as a dependency in the *pom.xml* of your `forge-addon` classified artifact: | ||
(Make sure the dependency is put all the way to the left, and uses 3 spaces for indentation of GAV) | ||
[source,xml] | ||
---- | ||
<dependency> | ||
<groupId>org.jboss.forge.addons.envers</groupId> | ||
<artifactId>envers</artifactId> | ||
<classifier>forge-addon</classifier> | ||
<version>${version}</version> | ||
</dependency> | ||
---- | ||
== Features | ||
ABCFactory for simple ABC blah:: | ||
Allows for blah blah | ||
+ | ||
[source,java] | ||
---- | ||
@Inject private ABCFactory factory; | ||
ABC abc = factory.createABC(); | ||
---- | ||
+ | ||
[TIP] | ||
==== | ||
If your addon uses a container that does not support "@Inject" annotations, services such as the `ABCFactory` may also be | ||
accessed via the `AddonRegistry`: | ||
---- | ||
Imported<ABCFactory> imported = addonRegistry.getServices(ABCFactory.class); | ||
ABCFactory factory = imported.get(); | ||
---- | ||
==== | ||
Creating a new XYZ instance:: | ||
Causes XYZ to occur | ||
+ | ||
[source,java] | ||
---- | ||
XYZ xyz = factory.createXYZ(); | ||
---- |
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,95 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.jboss.forge.addons.envers</groupId> | ||
<artifactId>envers</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
<version.furnace>2.12.0.Final</version.furnace> | ||
</properties> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.forge</groupId> | ||
<artifactId>forge-bom</artifactId> | ||
<version>${version.furnace}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.forge.furnace.container</groupId> | ||
<artifactId>cdi</artifactId> | ||
<classifier>forge-addon</classifier> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.furnace.test</groupId> | ||
<artifactId>furnace-test-harness</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.furnace.test</groupId> | ||
<artifactId>arquillian-furnace-classpath</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>javaee</artifactId> | ||
<classifier>forge-addon</classifier> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<finalName>envers</finalName> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>create-forge-addon</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
<configuration> | ||
<classifier>forge-addon</classifier> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<profiles> | ||
<profile> | ||
<id>release</id> | ||
<activation /> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jboss.forge.furnace</groupId> | ||
<artifactId>furnace-maven-plugin</artifactId> | ||
<version>${version.furnace}</version> | ||
<executions> | ||
<execution> | ||
<id>generate-dot</id> | ||
<phase>prepare-package</phase> | ||
<goals> | ||
<goal>generate-dot</goal> | ||
</goals> | ||
<configuration> | ||
<attach>true</attach> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
12 changes: 12 additions & 0 deletions
12
...orge-hol/envers-addon/src/main/java/org/jboss/forge/addons/envers/commands/Constants.java
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,12 @@ | ||
package org.jboss.forge.addons.envers.commands; | ||
|
||
/** | ||
* @author Ivan St. Ivanov | ||
*/ | ||
public class Constants | ||
{ | ||
static final String AUDITED_ANNOTATION = "org.hibernate.envers.Audited"; | ||
static final String HIBERNATE_GROUP_ID = "org.hibernate"; | ||
static final String ENVERS_ARTIFACT_ID = "hibernate-envers"; | ||
|
||
} |
104 changes: 104 additions & 0 deletions
104
...-addon/src/main/java/org/jboss/forge/addons/envers/commands/EnversAuditEntityCommand.java
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,104 @@ | ||
package org.jboss.forge.addons.envers.commands; | ||
|
||
import org.jboss.forge.addon.dependencies.builder.DependencyBuilder; | ||
import org.jboss.forge.addon.parser.java.resources.JavaResource; | ||
import org.jboss.forge.addon.projects.ProjectFactory; | ||
import org.jboss.forge.addon.projects.facets.DependencyFacet; | ||
import org.jboss.forge.addon.projects.ui.AbstractProjectCommand; | ||
import org.jboss.forge.addon.ui.context.UIBuilder; | ||
import org.jboss.forge.addon.ui.context.UIContext; | ||
import org.jboss.forge.addon.ui.context.UIExecutionContext; | ||
import org.jboss.forge.addon.ui.context.UIValidationContext; | ||
import org.jboss.forge.addon.ui.facets.HintsFacet; | ||
import org.jboss.forge.addon.ui.hints.InputType; | ||
import org.jboss.forge.addon.ui.input.UIInput; | ||
import org.jboss.forge.addon.ui.metadata.UICommandMetadata; | ||
import org.jboss.forge.addon.ui.metadata.WithAttributes; | ||
import org.jboss.forge.addon.ui.result.Result; | ||
import org.jboss.forge.addon.ui.result.Results; | ||
import org.jboss.forge.addon.ui.util.Categories; | ||
import org.jboss.forge.addon.ui.util.Metadata; | ||
import org.jboss.forge.roaster.model.source.JavaClassSource; | ||
|
||
import javax.inject.Inject; | ||
import javax.persistence.Entity; | ||
import java.io.FileNotFoundException; | ||
|
||
import static org.jboss.forge.addons.envers.commands.Constants.*; | ||
|
||
public class EnversAuditEntityCommand extends AbstractProjectCommand | ||
{ | ||
|
||
@Inject | ||
@WithAttributes(label = "Entity to audit", required = true) | ||
private UIInput<JavaResource> auditEntity; | ||
|
||
@Override | ||
public UICommandMetadata getMetadata(UIContext context) | ||
{ | ||
return Metadata.forCommand(EnversAuditEntityCommand.class).name( | ||
"Envers: Audit entity").category(Categories.create("Auditing")); | ||
} | ||
|
||
@Override | ||
public void initializeUI(UIBuilder builder) throws Exception | ||
{ | ||
auditEntity.getFacet(HintsFacet.class).setInputType(InputType.JAVA_CLASS_PICKER); | ||
Object selection = builder.getUIContext().getInitialSelection().get(); | ||
if (selection instanceof JavaResource) | ||
auditEntity.setDefaultValue((JavaResource) selection); | ||
builder.add(auditEntity); | ||
} | ||
|
||
@Override | ||
public Result execute(UIExecutionContext context) throws Exception | ||
{ | ||
JavaResource javaResource = auditEntity.getValue().reify(JavaResource.class); | ||
JavaClassSource javaClass = javaResource.getJavaType(); | ||
if (!javaClass.hasAnnotation(AUDITED_ANNOTATION)) { | ||
javaClass.addAnnotation(AUDITED_ANNOTATION); | ||
} | ||
javaResource.setContents(javaClass); | ||
return Results | ||
.success("Entity " + javaClass.getQualifiedName() + " was successfully audited"); | ||
} | ||
|
||
@Override | ||
public void validate(UIValidationContext validator) | ||
{ | ||
super.validate(validator); | ||
try | ||
{ | ||
if (!auditEntity.getValue().reify(JavaResource.class).getJavaType().hasAnnotation(Entity.class)) | ||
{ | ||
validator.addValidationError(auditEntity, "The selected class has to be JPA entity"); | ||
} | ||
} | ||
catch (FileNotFoundException e) | ||
{ | ||
validator.addValidationError(auditEntity, "You must select existing JPA entity to audit"); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isEnabled(UIContext context) | ||
{ | ||
return getSelectedProject(context).getFacet(DependencyFacet.class).hasEffectiveDependency( | ||
DependencyBuilder.create(HIBERNATE_GROUP_ID).setArtifactId(ENVERS_ARTIFACT_ID)); | ||
} | ||
|
||
@Override | ||
protected boolean isProjectRequired() | ||
{ | ||
return true; | ||
} | ||
|
||
@Inject | ||
private ProjectFactory projectFactory; | ||
|
||
@Override | ||
protected ProjectFactory getProjectFactory() | ||
{ | ||
return projectFactory; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...envers-addon/src/main/java/org/jboss/forge/addons/envers/commands/EnversSetupCommand.java
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,66 @@ | ||
package org.jboss.forge.addons.envers.commands; | ||
|
||
import org.jboss.forge.addon.dependencies.Dependency; | ||
import org.jboss.forge.addon.dependencies.builder.DependencyBuilder; | ||
import org.jboss.forge.addon.facets.constraints.FacetConstraint; | ||
import org.jboss.forge.addon.projects.ProjectFacet; | ||
import org.jboss.forge.addon.projects.ProjectFactory; | ||
import org.jboss.forge.addon.projects.dependencies.DependencyInstaller; | ||
import org.jboss.forge.addon.projects.ui.AbstractProjectCommand; | ||
import org.jboss.forge.addon.ui.context.UIBuilder; | ||
import org.jboss.forge.addon.ui.context.UIContext; | ||
import org.jboss.forge.addon.ui.context.UIExecutionContext; | ||
import org.jboss.forge.addon.ui.metadata.UICommandMetadata; | ||
import org.jboss.forge.addon.ui.result.Result; | ||
import org.jboss.forge.addon.ui.result.Results; | ||
import org.jboss.forge.addon.ui.util.Categories; | ||
import org.jboss.forge.addon.ui.util.Metadata; | ||
|
||
import javax.inject.Inject; | ||
|
||
import static org.jboss.forge.addons.envers.commands.Constants.*; | ||
|
||
@FacetConstraint(ProjectFacet.class) | ||
public class EnversSetupCommand extends AbstractProjectCommand | ||
{ | ||
|
||
@Inject | ||
private DependencyInstaller dependencyInstaller; | ||
|
||
@Override | ||
public UICommandMetadata getMetadata(UIContext context) | ||
{ | ||
return Metadata.forCommand(EnversSetupCommand.class).name( | ||
"Envers: Setup").category(Categories.create("Auditing")); | ||
} | ||
|
||
@Override | ||
public void initializeUI(UIBuilder builder) throws Exception | ||
{ | ||
} | ||
|
||
@Override | ||
public Result execute(UIExecutionContext context) throws Exception | ||
{ | ||
Dependency dependency = DependencyBuilder | ||
.create(HIBERNATE_GROUP_ID) | ||
.setArtifactId(ENVERS_ARTIFACT_ID) | ||
.setVersion("4.3.6.Final") | ||
.setScopeType("provided"); | ||
dependencyInstaller.install(getSelectedProject(context), dependency); | ||
return Results.success("Envers was successfully setup for the current project!"); | ||
} | ||
|
||
@Override | ||
protected boolean isProjectRequired() { | ||
return true; | ||
} | ||
|
||
@Inject | ||
private ProjectFactory projectFactory; | ||
|
||
@Override | ||
protected ProjectFactory getProjectFactory() { | ||
return projectFactory; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ials/forge-hol/envers-addon/src/main/java/org/jboss/forge/addons/envers/package-info.java
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 @@ | ||
package org.jboss.forge.addons.envers; |
2 changes: 2 additions & 0 deletions
2
tutorials/forge-hol/envers-addon/src/main/resources/META-INF/beans.xml
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,2 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bean-discovery-mode="all" version="1.1" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"/> |
5 changes: 5 additions & 0 deletions
5
.../forge-hol/envers-addon/src/test/java/org/jboss/forge/addons/envers/AbstractTestCase.java
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,5 @@ | ||
package org.jboss.forge.addons.envers; | ||
|
||
public abstract class AbstractTestCase | ||
{ | ||
} |