Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #749, add an example plugin that edits the default perspective de…
…finition.
- Loading branch information
Showing
6 changed files
with
236 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,130 @@ | ||
<?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/maven-v4_0_0.xsd"> | ||
<parent> | ||
<groupId>io.hawt</groupId> | ||
<artifactId>hawtio-plugin-examples</artifactId> | ||
<version>1.2-SNAPSHOT</version> | ||
<relativePath>..</relativePath> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>custom-perspective</artifactId> | ||
<packaging>war</packaging> | ||
<name>${project.artifactId}</name> | ||
<description>hawtio :: Example Custom Perspective plugin</description> | ||
|
||
<properties> | ||
<!-- filtered plugin properties --> | ||
<plugin-context>/hawtio/custom-perspective</plugin-context> | ||
<plugin-name>${project.artifactId}</plugin-name> | ||
<plugin-domain /> | ||
<plugin-scripts>app/js/simplePlugin.js</plugin-scripts> | ||
|
||
<fuse.osgi.import> | ||
javax.servlet.*, | ||
org.slf4j;resolution:=optional, | ||
!org.slf4j.impl, | ||
*;resolution:=optional | ||
</fuse.osgi.import> | ||
<fuse.osgi.export/> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>io.hawt</groupId> | ||
<artifactId>hawtio-plugin-mbean</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<version>${servlet-api-version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j-version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
|
||
<plugins> | ||
|
||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<version>${maven-bundle-plugin-version}</version> | ||
<executions> | ||
<execution> | ||
<id>bundle-manifest</id> | ||
<phase>process-classes</phase> | ||
<goals> | ||
<goal>manifest</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<manifestLocation>${webapp-outdir}/META-INF</manifestLocation> | ||
<supportedProjectTypes> | ||
<supportedProjectType>jar</supportedProjectType> | ||
<supportedProjectType>bundle</supportedProjectType> | ||
<supportedProjectType>war</supportedProjectType> | ||
</supportedProjectTypes> | ||
<instructions> | ||
<Webapp-Context>${plugin-context}</Webapp-Context> | ||
<Web-ContextPath>${plugin-context}</Web-ContextPath> | ||
|
||
<Embed-Directory>WEB-INF/lib</Embed-Directory> | ||
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> | ||
<Embed-Transitive>true</Embed-Transitive> | ||
|
||
<Export-Package>${fuse.osgi.export}</Export-Package> | ||
<Import-Package>${fuse.osgi.import}</Import-Package> | ||
<!-- | ||
<DynamicImport-Package>${fuse.osgi.dynamic}</DynamicImport-Package> | ||
<Private-Package>${fuse.osgi.private.pkg}</Private-Package> | ||
--> | ||
|
||
<Bundle-ClassPath>.,WEB-INF/classes</Bundle-ClassPath> | ||
|
||
<Bundle-Name>${project.description}</Bundle-Name> | ||
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName> | ||
<Implementation-Title>HawtIO</Implementation-Title> | ||
<Implementation-Version>${project.version}</Implementation-Version> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>${war-plugin-version}</version> | ||
<configuration> | ||
<outputFileNameMapping>@{artifactId}@-@{baseVersion}@@{dashClassifier?}@.@{extension}@</outputFileNameMapping> | ||
<packagingExcludes>**/classes/OSGI-INF/**</packagingExcludes> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
<archive> | ||
<manifestFile>${webapp-outdir}/META-INF/MANIFEST.MF</manifestFile> | ||
</archive> | ||
<webResources> | ||
<resource> | ||
<filtering>true</filtering> | ||
<directory>src/main/resources</directory> | ||
<includes> | ||
<include>**/*.*</include> | ||
</includes> | ||
</resource> | ||
</webResources> | ||
</configuration> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
</project> |
34 changes: 34 additions & 0 deletions
34
...om-perspective/src/main/java/io/hawt/example/customperspective/PluginContextListener.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,34 @@ | ||
package io.hawt.example.customperspective; | ||
|
||
import io.hawt.web.plugin.HawtioPlugin; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.servlet.ServletContextEvent; | ||
import javax.servlet.ServletContextListener; | ||
|
||
/** | ||
* A context listener to manage this plugin's MBean registration | ||
*/ | ||
public class PluginContextListener implements ServletContextListener { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(PluginContextListener.class); | ||
|
||
HawtioPlugin plugin; | ||
|
||
public void contextInitialized(ServletContextEvent servletContextEvent) { | ||
plugin = new HawtioPlugin(); | ||
plugin.setContext("/hawtio/custom-perspective"); | ||
plugin.setName("custom-perspective"); | ||
plugin.setScripts("app/js/plugin.js"); | ||
plugin.setDomain(null); | ||
plugin.init(); | ||
LOG.info("Initialized custom perspective plugin"); | ||
} | ||
|
||
public void contextDestroyed(ServletContextEvent servletContextEvent) { | ||
plugin.destroy(); | ||
LOG.info("Destroying custom perspective plugin"); | ||
} | ||
|
||
} |
Empty file.
16 changes: 16 additions & 0 deletions
16
hawtio-plugin-examples/custom-perspective/src/main/webapp/WEB-INF/web.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,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee | ||
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" | ||
version="2.4"> | ||
|
||
<description>hawtio</description> | ||
<display-name>hawt.io example custom perspective plugin</display-name> | ||
|
||
<listener> | ||
<listener-class>io.hawt.example.customperspective.PluginContextListener</listener-class> | ||
</listener> | ||
|
||
</web-app> | ||
|
55 changes: 55 additions & 0 deletions
55
hawtio-plugin-examples/custom-perspective/src/main/webapp/app/js/plugin.js
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,55 @@ | ||
|
||
|
||
var CustomPerspective = (function() { | ||
|
||
/** | ||
* Initialize the plugin and create a logger for it so it's easy to find it's log | ||
* statements in the console | ||
*/ | ||
var pluginName = "CustomPerspective"; | ||
var log = Logger.get(pluginName); | ||
var plugin = angular.module(pluginName, ['perspective']); | ||
|
||
/** | ||
* The plugin's main entry point. | ||
*/ | ||
plugin.run( function(workspace) { | ||
log.info("Custom perspective plugin installed"); | ||
|
||
log.debug("Current metadata: ", window['Perspective']['metadata']); | ||
log.debug("Top level tabs:"); | ||
|
||
workspace.topLevelTabs.forEach(function(tab) { | ||
log.debug("Tab content:", tab['content'], " id: ", tab['id'], " href: ", tab.href()); | ||
}); | ||
|
||
/** | ||
* By default tabs are pulled from the "container" perspective, here | ||
* we can define includes or excludes to customize the available tabs | ||
* in hawtio. Use "href" to match from the start of a URL and "rhref" | ||
* to match a URL via regex string. | ||
*/ | ||
window['Perspective']['metadata'] = { | ||
container: { | ||
label: "Container", | ||
lastPage: "#/help", | ||
topLevelTabs: { | ||
excludes: [ | ||
{ | ||
href: "#/dashboard" | ||
}, | ||
{ | ||
href: "#/jvm" | ||
} | ||
] | ||
} | ||
} | ||
}; | ||
|
||
log.debug("Perspective definition now: ", window['Perspective']['metadata']); | ||
|
||
}); | ||
|
||
hawtioPluginLoader.addModule(pluginName); | ||
|
||
})(); |
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
<modules> | ||
<module>simple-plugin</module> | ||
<module>custom-perspective</module> | ||
</modules> | ||
|
||
</project> |