ArtifactListeners
ArtifactListeners allow you to attach logic that runs each time a file is expanded.
- artifactListeners.xml
- MyListener.java
Add a DataResource file to your expansion-resource:
<dataResource type="expansionControl::ArtifactListener">
<artifactListener name="MyListener">
<attachTo name="before-write"/> <!-- before-write or after-write -->
<implementation>net.demo.MyListener</implementation>
<!-- Next are some optional attributes to filter when to run the listener -->
<layerType name="LOGIC_LAYER"/> <!-- optional, filters logic layer artifacts -->
<technology name="EJB3"/> <!-- optional, filters Ejb3 artifacts -->
<fileExtensions>java, kt</fileExtensions> <!-- optional, filters .java or .kt files -->
</artifactListener>
</dataResource>
Provide a java class that implements the ArtifactListener
interface:
import net.democritus.elements.ArtifactComposite;
import net.democritus.expander.listeners.ArtifactListener;
import net.democritus.expander.listeners.ArtifactWriteParameters;
public class MyListener implements ArtifactListener {
@Override
public void perform(ArtifactWriteParameters parameters) {
CompositeExpansionContext<?> expansionContext = parameters.getExpansionContext();
ArtifactComposite artifact = parameters.getArtifact();
Path artifactFile = parameters.getArtifactFile();
// Do something with the information available.
}
}