This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
o first version of Sonatype's decoupled JSR330 support for Hudson
- Loading branch information
Jason van Zyl
committed
Feb 10, 2011
0 parents
commit 2bebeb2
Showing
47 changed files
with
4,074 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,5 @@ | ||
target/ | ||
.project | ||
.classpath | ||
.settings/ | ||
bin/ |
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,143 @@ | ||
# Description | ||
|
||
Smoothie: Hudson JSR330 integration for Hudson | ||
|
||
Smoothie (_a blend of guice for hudson_) was designed to allow plugin components written with **JSR-330** annotations | ||
to be used as Hudson extension points while leaving existing `@Extension` mechanism AS-IS. | ||
|
||
Aside from installing the custom `PluginStrategy` (and its dependencies) into the `hudson.war` | ||
there are no changes to `hudson-core` required. | ||
|
||
## Building | ||
|
||
### Requirements | ||
|
||
* [Maven](http://maven.apache.org) 3.0+ | ||
* [Java](http://java.sun.com/) 6+ (1.6.0_19+) | ||
|
||
Check-out and build: | ||
|
||
git clone git@github.com:sonatype/matrix-smoothie.git | ||
cd matrix-smoothie | ||
mvn install | ||
|
||
## Installing | ||
|
||
An example of a modified `hudson.war` is generated in the `matrix-smoothie-webapp` module. | ||
|
||
### Install dependencies | ||
|
||
Several jars need to be added to the `hudson.war`: | ||
|
||
Copy matrix-smoothie/target/matrix-smoothie-*.jar into hudson.war/WEB-INF/lib | ||
Copy matrix-smoothie-webapp/target/dependency/* into into hudson.war/WEB-INF/lib | ||
|
||
### Configure Hudson to use Smoothie | ||
|
||
Configure system properties: | ||
|
||
hudson.PluginStrategy=com.sonatype.matrix.smoothie.internal.plugin.DelegatingPluginStrategy | ||
|
||
## Usage | ||
|
||
### Use JSR-330 annotations to mark components | ||
|
||
A simple component: | ||
|
||
@Named | ||
@Singleton | ||
public class MyPageDecorator extends PageDecorator { | ||
// ... | ||
} | ||
|
||
Descriptors (and some other extensions) require additional `@Typed` meta-data: | ||
|
||
public class MyScm extends SCM { | ||
// ... | ||
|
||
@Named | ||
@Singleton | ||
@Typed(hudson.model.Descriptor.class) | ||
public static final class DescriptorImpl extends SCMDescriptor<MyScm> { | ||
// ... | ||
} | ||
} | ||
|
||
## Advanced Usage | ||
|
||
### Configure Aspect for Plugin development | ||
|
||
To enable the injection of `hudson.model.Describable` instances, | ||
configure your HPI plugin to weave the `matrix-smoothie` aspect: | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>aspectj-maven-plugin</artifactId> | ||
<version>1.3</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.aspectj</groupId> | ||
<artifactId>aspectjtools</artifactId> | ||
<version>1.6.10</version> | ||
</dependency> | ||
</dependencies> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>compile</goal> | ||
<goal>test-compile</goal> | ||
</goals> | ||
<configuration> | ||
<Xlint>ignore</Xlint> | ||
<XaddSerialVersionUID>true</XaddSerialVersionUID> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
<aspectLibraries> | ||
<aspectLibrary> | ||
<groupId>org.sonatype.matrix</groupId> | ||
<artifactId>matrix-smoothie</artifactId> | ||
<version>1.1-SNAPSHOT</version> | ||
</aspectLibrary> | ||
</aspectLibraries> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
This will enable **setter** injection on Describable instances: | ||
|
||
public class MyScm extends SCM { | ||
// ... | ||
private transient MyScmBacking backing; | ||
@Inject | ||
public void setMyScmBacking(MyScmBacking backing) { | ||
this.backing = backing; | ||
} | ||
@Named | ||
@Singleton | ||
@Typed(hudson.model.Descriptor.class) | ||
public static final class DescriptorImpl extends SCMDescriptor<MyScm> { | ||
// ... | ||
} | ||
} | ||
|
||
Remember to make fields holding onto injected resources in Describable instances **transient**. | ||
When the object is deserialized Smoothie will re-inject the instance. | ||
|
||
Constructor injection is **NOT** available for Describable instances. | ||
|
||
## Trying it out | ||
|
||
java -DHUDSON_HOME=target/hudson \ | ||
-Dhudson.PluginStrategy=com.sonatype.matrix.smoothie.internal.plugin.DelegatingPluginStrategy \ | ||
-jar matrix-smoothie-webapp/target/smoothie-hudson.war | ||
|
||
This should add a new smoothie-enabled management link and a new smoothie builder, both to simply say hello | ||
by delegation to an injected component. |
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,21 @@ | ||
The MIT License | ||
|
||
Copyright (c) ${year} Sonatype, Inc. All rights reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,82 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
The MIT License | ||
Copyright (c) 2010 Sonatype, Inc. All rights reserved. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
--> | ||
|
||
<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"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.sonatype.matrix</groupId> | ||
<artifactId>matrix-smoothie-parent</artifactId> | ||
<version>1.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>org.sonatype.matrix</groupId> | ||
<artifactId>matrix-smoothie-example-plugin</artifactId> | ||
<name>Matrix Smoothie Example Plugin</name> | ||
<packaging>hpi</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.sonatype.matrix</groupId> | ||
<artifactId>matrix-smoothie</artifactId> | ||
<version>1.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jvnet.hudson.main</groupId> | ||
<artifactId>hudson-core</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>aspectj-maven-plugin</artifactId> | ||
<configuration> | ||
<aspectLibraries> | ||
<aspectLibrary> | ||
<groupId>org.sonatype.matrix</groupId> | ||
<artifactId>matrix-smoothie</artifactId> | ||
</aspectLibrary> | ||
</aspectLibraries> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
89 changes: 89 additions & 0 deletions
89
...xample-plugin/src/main/java/com/sonatype/matrix/plugins/exampleplugin/ExampleBuilder.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,89 @@ | ||
/** | ||
* The MIT License | ||
* | ||
* Copyright (c) 2010 Sonatype, Inc. All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package com.sonatype.matrix.plugins.exampleplugin; | ||
|
||
import hudson.Launcher; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.BuildListener; | ||
import hudson.model.Descriptor; | ||
import hudson.tasks.BuildStepDescriptor; | ||
import hudson.tasks.Builder; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import javax.enterprise.inject.Typed; | ||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Example Smoothie {@link Builder}. | ||
* | ||
* @author <a href="mailto:jason@planet57.com">Jason Dillon</a> | ||
* @since 1.1 | ||
*/ | ||
public class ExampleBuilder | ||
extends Builder | ||
{ | ||
// Make sure injected component references are transient, due to use of XStream for configuration persistence | ||
private transient Speaker speaker; | ||
|
||
@DataBoundConstructor | ||
public ExampleBuilder() { | ||
// blah | ||
} | ||
|
||
// This requires the matrix-smoothie aspect to be weaved for injection. | ||
|
||
@Inject | ||
public void setSpeaker(final Speaker speaker) { | ||
assert speaker != null; | ||
this.speaker = speaker; | ||
} | ||
|
||
@Override | ||
public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener) throws InterruptedException, IOException { | ||
listener.getLogger().println(speaker.speak()); | ||
return true; | ||
} | ||
|
||
@Named | ||
@Singleton | ||
@Typed(Descriptor.class) | ||
public static class DescriptorImpl | ||
extends BuildStepDescriptor<Builder> | ||
{ | ||
@Override | ||
public boolean isApplicable(final Class<? extends AbstractProject> type) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Say hello"; | ||
} | ||
} | ||
} |
Oops, something went wrong.