Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactored to use Transient Factories

  • Loading branch information...
commit ed213ee55bcca1ed7b919951ee259abc969dd71e 1 parent 7471936
@wolfs authored
View
1  .classpath
@@ -2,6 +2,7 @@
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+ <classpathentry kind="src" path="target/generated-sources/localizer"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
View
8 src/main/java/hudson/plugins/depgraph_view/AbstractDependencyGraphAction.java
@@ -38,7 +38,7 @@
"png",SupportedImageType.of("image/png", "png"),
"svg",SupportedImageType.of("image/svg", "svg"),
"map",SupportedImageType.of("image/cmapx", "cmapx"),
- "dot",SupportedImageType.of("text/plain", "dot")
+ "gv",SupportedImageType.of("text/plain", "gv")
);
private static final Comparator<Dependency> DEP_COMPARATOR = new Comparator<Dependency>() {
@@ -79,7 +79,7 @@ public String getIconFileName() {
@Override
public String getDisplayName() {
- return "Dependency Graph";
+ return Messages.AbstractDependencyGraphAction_DependencyGraph();
}
@Override
@@ -159,6 +159,8 @@ private String escapeString(String toEscape) {
protected abstract Collection<? extends AbstractProject<?, ?>> getProjectsForDepgraph(StaplerRequest req);
+ public abstract String getTitle();
+
public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException {
String path = req.getRestOfPath();
if (path.startsWith("/graph.")) {
@@ -168,7 +170,7 @@ public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
CalculateDeps calculateDeps = new CalculateDeps(getProjectsForDepgraph(req));
String graphDot = generateDotText(calculateDeps.getProjects(), calculateDeps.getDependencies());
rsp.setContentType(imageType.contentType);
- if ("dot".equalsIgnoreCase(extension)) {
+ if ("gv".equalsIgnoreCase(extension)) {
rsp.getWriter().append(graphDot).close();
} else {
runDot(rsp.getOutputStream(), new ByteArrayInputStream(graphDot.getBytes()), imageType.dotType);
View
5 src/main/java/hudson/plugins/depgraph_view/DependencyGraphProjectAction.java
@@ -27,4 +27,9 @@ public DependencyGraphProjectAction(AbstractProject<?, ?> project) {
protected Collection<AbstractProject<?, ?>> getProjectsForDepgraph(StaplerRequest req) {
return Collections.<AbstractProject<?, ?>>singleton(project);
}
+
+ @Override
+ public String getTitle() {
+ return Messages.AbstractDependencyGraphAction_DependencyGraphOf(project.getDisplayName());
+ }
}
View
22 src/main/java/hudson/plugins/depgraph_view/DependencyGraphProjectActionFactory.java
@@ -0,0 +1,22 @@
+package hudson.plugins.depgraph_view;
+
+import hudson.Extension;
+import hudson.model.AbstractProject;
+import hudson.model.Action;
+import hudson.model.TransientProjectActionFactory;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * User: wolfs
+ * Date: 10.12.10
+ * Time: 16:28
+ */
+@Extension
+public class DependencyGraphProjectActionFactory extends TransientProjectActionFactory {
+ @Override
+ public Collection<? extends Action> createFor(AbstractProject target) {
+ return Collections.singleton(new DependencyGraphProjectAction(target));
+ }
+}
View
26 src/main/java/hudson/plugins/depgraph_view/DependencyGraphProperty.java
@@ -4,12 +4,9 @@
import hudson.Functions;
import hudson.Launcher;
import hudson.Util;
-import hudson.model.Action;
-import hudson.model.BuildListener;
-import hudson.model.JobProperty;
-import hudson.model.JobPropertyDescriptor;
-import hudson.model.AbstractBuild;
-import hudson.model.AbstractProject;
+import hudson.model.*;
+import hudson.slaves.NodeProperty;
+import hudson.slaves.NodePropertyDescriptor;
import hudson.util.FormValidation;
import java.io.IOException;
@@ -23,27 +20,14 @@
import org.kohsuke.stapler.StaplerRequest;
-public class DependencyGraphProperty extends JobProperty<AbstractProject<?,?>> {
+public class DependencyGraphProperty extends NodeProperty<Node> {
@DataBoundConstructor
public DependencyGraphProperty() {
}
- @Override
- public Collection<? extends Action> getJobActions(AbstractProject<?, ?> job) {
- return Collections.singleton(new DependencyGraphProjectAction(job));
- }
-
- @Override
- public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
- BuildListener listener) throws InterruptedException, IOException {
- return true;
- }
-
-
-
@Extension
- public static class DescriptorImpl extends JobPropertyDescriptor {
+ public static class DescriptorImpl extends NodePropertyDescriptor {
private String dotExe;
View
31 src/main/java/hudson/plugins/depgraph_view/DependencyGraphRootAction.java
@@ -1,11 +1,7 @@
package hudson.plugins.depgraph_view;
import hudson.Extension;
-import hudson.model.AbstractProject;
-import hudson.model.Hudson;
-import hudson.model.RootAction;
-import hudson.model.TopLevelItem;
-import hudson.model.View;
+import hudson.model.*;
import java.util.ArrayList;
import java.util.Collection;
@@ -13,16 +9,18 @@
import org.kohsuke.stapler.StaplerRequest;
-@Extension
+
public class DependencyGraphRootAction extends AbstractDependencyGraphAction
- implements RootAction {
+ implements Action {
+
+ private View view;
+
+ public DependencyGraphRootAction(View view) {
+ this.view = view;
+ }
@Override
protected Collection<? extends AbstractProject<?, ?>> getProjectsForDepgraph(StaplerRequest req) {
- View view = req.findAncestorObject(View.class);
- if (view == null) {
- view = Hudson.getInstance().getPrimaryView();
- }
Collection<TopLevelItem> items = view.getItems();
List<AbstractProject<?,?>> projects = new ArrayList<AbstractProject<?,?>>();
for (TopLevelItem item : items) {
@@ -33,12 +31,13 @@
return projects;
}
- public View getMainView() {
- return Hudson.getInstance().getPrimaryView();
+ @Override
+ public String getTitle() {
+ return Messages.AbstractDependencyGraphAction_DependencyGraphOf(view.getDisplayName());
}
- public View getAncestorView(StaplerRequest req) {
- return req.findAncestorObject(View.class);
- }
+ public View getView() {
+ return view;
+ }
}
View
22 src/main/java/hudson/plugins/depgraph_view/DependencyGraphViewActionFactory.java
@@ -0,0 +1,22 @@
+package hudson.plugins.depgraph_view;
+
+import hudson.Extension;
+import hudson.model.Action;
+import hudson.model.TransientViewActionFactory;
+import hudson.model.View;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * User: wolfs
+ * Date: 10.12.10
+ * Time: 15:41
+ */
+@Extension
+public class DependencyGraphViewActionFactory extends TransientViewActionFactory {
+ @Override
+ public List<Action> createFor(View v) {
+ return Collections.<Action>singletonList(new DependencyGraphRootAction(v));
+ }
+}
View
31 src/main/java/hudson/plugins/depgraph_view/ItemListenerImpl.java
@@ -1,31 +0,0 @@
-package hudson.plugins.depgraph_view;
-
-import hudson.Extension;
-import hudson.model.AbstractProject;
-import hudson.model.Hudson;
-import hudson.model.listeners.ItemListener;
-
-import java.io.IOException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-@Extension
-public class ItemListenerImpl extends ItemListener {
-
- private static final Logger LOGGER = Logger.getLogger(ItemListener.class.getName());
-
- @Override
- public void onLoaded() {
- for (AbstractProject<?,?> project : Hudson.getInstance().getAllItems(AbstractProject.class)) {
- DependencyGraphProperty property = project.getProperty(DependencyGraphProperty.class);
- if (property == null) {
- try {
- project.addProperty(new DependencyGraphProperty());
- } catch (IOException e) {
- LOGGER.log(Level.SEVERE, "Failed to persist " + project, e);
- }
- }
- }
- }
-
-}
View
9 src/main/resources/hudson/plugins/depgraph_view/DependencyGraphProjectAction/index.jelly
@@ -1,9 +1,4 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:sv="/lib/sectioned_view" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
-<l:layout title="${it.project.displayName} Dependency Graph">
-<st:include it="${it.project}" page="sidepanel.jelly" />
-<l:main-panel>
-<h2>Dependency Graph</h2>
-<img src="graph.png" lazymap="graph.map"/>
-</l:main-panel>
-</l:layout>
+<j:set var="parentObject" value="${it.project}" />
+<st:include it="${it}" page="mainPanel.jelly"/>
</j:jelly>
View
9 src/main/resources/hudson/plugins/depgraph_view/DependencyGraphRootAction/index.jelly
@@ -1,9 +1,4 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
-<l:layout title="Dependency Graph">
-<st:include it="${it.mainView}" page="sidepanel.jelly" />
-<l:main-panel>
-<h2>Dependency Graph</h2>
-<img src="graph.png" lazymap="graph.map"/>
-</l:main-panel>
-</l:layout>
+<j:set var="parentObject" value="${it.view}" />
+<st:include it="${it}" page="mainPanel.jelly"/>
</j:jelly>
Please sign in to comment.
Something went wrong with that request. Please try again.