From 6fc699ff7406628271bbab7038b552481653436e Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 31 Mar 2011 15:09:23 -0700 Subject: [PATCH 01/25] - making context richer - simplifying Jelly view and submission handling --- core/src/main/java/hudson/model/View.java | 35 +++++++++---------- .../main/java/hudson/model/ViewProperty.java | 6 +++- .../hudson/model/ViewPropertyDescriptor.java | 5 ++- .../hudson/model/View/configure.jelly | 15 +------- 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/core/src/main/java/hudson/model/View.java b/core/src/main/java/hudson/model/View.java index 81c4eb3074..ed40898026 100644 --- a/core/src/main/java/hudson/model/View.java +++ b/core/src/main/java/hudson/model/View.java @@ -29,6 +29,8 @@ import hudson.ExtensionPoint; import hudson.Util; import hudson.model.Descriptor.FormException; import hudson.model.Node.Mode; +import hudson.model.labels.LabelAtomProperty; +import hudson.model.labels.LabelAtomPropertyDescriptor; import hudson.scm.ChangeLogSet.Entry; import hudson.search.CollectionSearchIndex; import hudson.search.SearchIndexBuilder; @@ -205,6 +207,19 @@ public abstract class View extends AbstractModelObject implements AccessControll return properties; } + /** + * Returns all the {@link LabelAtomPropertyDescriptor}s that can be potentially configured + * on this label. + */ + public List getApplicablePropertyDescriptors() { + List r = new ArrayList(); + for (ViewPropertyDescriptor pd : ViewProperty.all()) { + if (pd.isEnabledFor(this)) + r.add(pd); + } + return r; + } + public void save() throws IOException { // persistence is a part of the owner // due to initialization timing issue, it can be null when this method is called @@ -620,25 +635,7 @@ public abstract class View extends AbstractModelObject implements AccessControll JSONObject json = req.getSubmittedForm(); - List props = new ArrayList(); - int i = 0; - for (ViewPropertyDescriptor d: ViewProperty.all()) { - ViewProperty p = properties.get(d.clazz); - - JSONObject o = json.optJSONObject("viewProperty" + (i++)); - if (o != null) { - if (p != null) { - p = p.reconfigure(req, o); - } else { - p = d.newInstance(req, o); - } - } - - if (p != null) { - props.add(p); - } - } - properties.replaceBy(props); + properties.rebuild(req, req.getSubmittedForm(), getApplicablePropertyDescriptors()); save(); diff --git a/core/src/main/java/hudson/model/ViewProperty.java b/core/src/main/java/hudson/model/ViewProperty.java index 74cdb40a67..2c576a652e 100644 --- a/core/src/main/java/hudson/model/ViewProperty.java +++ b/core/src/main/java/hudson/model/ViewProperty.java @@ -25,9 +25,14 @@ package hudson.model; import hudson.DescriptorExtensionList; import hudson.ExtensionPoint; +import hudson.console.ConsoleAnnotator; +import hudson.console.ConsoleAnnotatorFactory; import net.sf.json.JSONObject; import org.kohsuke.stapler.StaplerRequest; +import java.util.ArrayList; +import java.util.List; + /** * Extensible property of {@link View}. * @@ -68,5 +73,4 @@ public class ViewProperty implements Describable, ExtensionPoint { public ViewProperty reconfigure(StaplerRequest req, JSONObject form) throws Descriptor.FormException { return getDescriptor().newInstance(req, form); } - } diff --git a/core/src/main/java/hudson/model/ViewPropertyDescriptor.java b/core/src/main/java/hudson/model/ViewPropertyDescriptor.java index b7c474b47f..f073050f57 100644 --- a/core/src/main/java/hudson/model/ViewPropertyDescriptor.java +++ b/core/src/main/java/hudson/model/ViewPropertyDescriptor.java @@ -67,8 +67,11 @@ public abstract class ViewPropertyDescriptor extends Descriptor { *

* This mechanism is useful if the availability of the property is * contingent of some other settings. + * + * @param view + * View for which this property is considered. Never null. */ - public boolean isEnabled() { + public boolean isEnabledFor(View view) { return true; } } diff --git a/core/src/main/resources/hudson/model/View/configure.jelly b/core/src/main/resources/hudson/model/View/configure.jelly index acee8d3038..a648febb2a 100644 --- a/core/src/main/resources/hudson/model/View/configure.jelly +++ b/core/src/main/resources/hudson/model/View/configure.jelly @@ -51,20 +51,7 @@ THE SOFTWARE. - - - - - - - - - - - - - - + From ef7b9d84fdaa9ec35213a5c324e397ff389dd561 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 31 Mar 2011 15:50:41 -0700 Subject: [PATCH 02/25] generalized the reconfigure concept. --- .../model/ReconfigurableDescribable.java | 81 +++++++++++++++++++ .../main/java/hudson/model/ViewProperty.java | 4 +- .../java/hudson/util/DescribableList.java | 20 ++++- 3 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 core/src/main/java/hudson/model/ReconfigurableDescribable.java diff --git a/core/src/main/java/hudson/model/ReconfigurableDescribable.java b/core/src/main/java/hudson/model/ReconfigurableDescribable.java new file mode 100644 index 0000000000..7738089b1d --- /dev/null +++ b/core/src/main/java/hudson/model/ReconfigurableDescribable.java @@ -0,0 +1,81 @@ +/* + * The MIT License + * + * Copyright (c) 2011, CloudBees, Inc. + * + * 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 hudson.model; + +import hudson.model.Descriptor.FormException; +import hudson.slaves.NodeProperty; +import net.sf.json.JSONObject; +import org.kohsuke.stapler.StaplerRequest; + +/** + * Marks modern {@link Describable}s that allow the current instances to pass information down to the next + * instance when the configuration is submitted. + * + *

+ * As the generics signature implies, it isn't up to individual {@link Describable} implementation to + * implement this. Rather, it is up to the designer of an extension point to mark the extension point + * as {@link ReconfigurableDescribable}, as it requires coordination at the owner of the extension point. + * + *

Use Cases

+ *

Invisible Property

+ *

+ * This mechanism can be used to create an entirely invisible {@link Describable}, which is handy + * for {@link NodeProperty}, {@link JobProperty}, etc. To do so, define a descriptor with null + * {@linkplain Descriptor#getDisplayName() display name} and empty config.jelly to prevent it from + * showing up in the config UI, then implement {@link #reconfigure(StaplerRequest, JSONObject)} + * and simply return {@code this}. + * + *

Passing some values without going through clients

+ *

+ * Sometimes your {@link Describable} object may have some expensive objects that you might want to + * hand over to the next instance. This hook lets you do that. + * + * @author Kohsuke Kawaguchi + * @since 1.406 + */ +public interface ReconfigurableDescribable> extends Describable { + + /** + * When a parent/owner object of a Describable gets a config form submission and instances are + * recreated, this method is invoked on the existing instance (meaning the 'this' reference + * points to the existing instance) to create a new instance to be added to the parent/owner object. + * + *

+ * The default implementation of this should be the following: + *

+     * return form==null ? null : getDescriptor().newInstance(req, form);
+     * 
+ * + * @param req + * The current HTTP request being processed. + * @param form + * JSON fragment that corresponds to this describable object. + * If the newly submitted form doesn't include a fragment for this describable + * (meaning the user has de-selected your descriptor), then this argument is null. + * + * @return + * The new instance. To not to create an instance of a describable, return null. + */ + T reconfigure(StaplerRequest req, JSONObject form) throws FormException; +} diff --git a/core/src/main/java/hudson/model/ViewProperty.java b/core/src/main/java/hudson/model/ViewProperty.java index 2c576a652e..4820d3affc 100644 --- a/core/src/main/java/hudson/model/ViewProperty.java +++ b/core/src/main/java/hudson/model/ViewProperty.java @@ -50,7 +50,7 @@ import java.util.List; * @author Stephen Connolly * @since 1.406 */ -public class ViewProperty implements Describable, ExtensionPoint { +public class ViewProperty implements ReconfigurableDescribable, ExtensionPoint { /** * The view object that owns this property. * This value will be set by the core code. @@ -71,6 +71,6 @@ public class ViewProperty implements Describable, ExtensionPoint { } public ViewProperty reconfigure(StaplerRequest req, JSONObject form) throws Descriptor.FormException { - return getDescriptor().newInstance(req, form); + return form==null ? null : getDescriptor().newInstance(req, form); } } diff --git a/core/src/main/java/hudson/util/DescribableList.java b/core/src/main/java/hudson/util/DescribableList.java index 52eecdd985..6e7c9270a6 100644 --- a/core/src/main/java/hudson/util/DescribableList.java +++ b/core/src/main/java/hudson/util/DescribableList.java @@ -36,8 +36,10 @@ import hudson.model.DependencyGraph; import hudson.model.Describable; import hudson.model.Descriptor; import hudson.model.Descriptor.FormException; +import hudson.model.ReconfigurableDescribable; import hudson.model.Saveable; import net.sf.json.JSONObject; +import org.apache.avalon.framework.configuration.Reconfigurable; import org.kohsuke.stapler.StaplerRequest; import java.io.IOException; @@ -141,11 +143,23 @@ public class DescribableList, D extends Descriptor> List newList = new ArrayList(); for (Descriptor d : descriptors) { + T existing = get((D)d); String name = d.getJsonSafeClassName(); - if (json.has(name)) { - T instance = d.newInstance(req, json.getJSONObject(name)); - newList.add(instance); + JSONObject o = json.optJSONObject(name); + + T instance = null; + if (o!=null) { + if (existing instanceof ReconfigurableDescribable) + instance = (T)((ReconfigurableDescribable)existing).reconfigure(req,o); + else + instance = d.newInstance(req, o); + } else { + if (existing instanceof ReconfigurableDescribable) + instance = (T)((ReconfigurableDescribable)existing).reconfigure(req,null); } + + if (instance!=null) + newList.add(instance); } replaceBy(newList); From a66959d76db62f06c65ee0e5d66a398a5ca5787f Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 31 Mar 2011 16:15:25 -0700 Subject: [PATCH 03/25] degrade to rowSet, which works nicely with descriptorList --- .../resources/lib/form/optionalBlock.jelly | 48 ++++++++++++------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/core/src/main/resources/lib/form/optionalBlock.jelly b/core/src/main/resources/lib/form/optionalBlock.jelly index 5602254766..37039e0e2a 100644 --- a/core/src/main/resources/lib/form/optionalBlock.jelly +++ b/core/src/main/resources/lib/form/optionalBlock.jelly @@ -35,6 +35,10 @@ THE SOFTWARE. Human readable text that follows the checkbox. + + If this field is null, the checkbox degrades to a <f:rowSet>, which provides + a grouping at JSON level but on the UI there's no checkbox (and you always see + the body of it.) Used for databinding. TBD. Either this or @name/@title combo is required. @@ -59,21 +63,31 @@ THE SOFTWARE. value="${descriptor.getHelpFile(attrs.field)}" /> - - - - - - - Help for feature: ${title} - - - - - - - - - + + + + + + + + + Help for feature: ${title} + + + + + + + + + + + + + + + + + \ No newline at end of file From ebd6981dd1dfbfec1dbb795f742b7da9dae12373 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 31 Mar 2011 16:27:42 -0700 Subject: [PATCH 04/25] This concept is unique to View, so I think it's fair to implement this by default --- core/src/main/java/hudson/model/ViewPropertyDescriptor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/model/ViewPropertyDescriptor.java b/core/src/main/java/hudson/model/ViewPropertyDescriptor.java index f073050f57..da0e0bbb51 100644 --- a/core/src/main/java/hudson/model/ViewPropertyDescriptor.java +++ b/core/src/main/java/hudson/model/ViewPropertyDescriptor.java @@ -53,7 +53,9 @@ public abstract class ViewPropertyDescriptor extends Descriptor { * @return null * if the implementation choose not to add any property object for such view. */ - public abstract ViewProperty newInstance(View view); + public ViewProperty newInstance(View view) { + return null; + } /** * Whether or not the described property is enabled in the current context. From 982be4783c2d151ae9e3c186ab254229239588fc Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 31 Mar 2011 16:45:33 -0700 Subject: [PATCH 05/25] added a convenience method --- test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index d44b8635a6..e5a7a7aeed 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -787,6 +787,11 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { return (C)computerConnectorTester.connector; } + protected V configRoundtrip(V view) throws Exception { + submit(createWebClient().getPage(view, "configure").getFormByName("viewConfig")); + return view; + } + /** * Asserts that the outcome of the build is a specific outcome. From 2b5c2cc6dfa7b4076302c9a4126bf460cebeb795 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 31 Mar 2011 17:02:26 -0700 Subject: [PATCH 06/25] Use CSS to create space instead of nbsp --- core/src/main/resources/lib/form/checkbox.jelly | 5 +---- core/src/main/resources/lib/form/radioBlock.jelly | 1 - core/src/main/resources/lib/hudson/newFromList/form.jelly | 2 -- war/src/main/webapp/css/style.css | 4 ++++ 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/core/src/main/resources/lib/form/checkbox.jelly b/core/src/main/resources/lib/form/checkbox.jelly index c587791405..2b6e2f6e0b 100644 --- a/core/src/main/resources/lib/form/checkbox.jelly +++ b/core/src/main/resources/lib/form/checkbox.jelly @@ -59,9 +59,6 @@ THE SOFTWARE. checkUrl="${attrs.checkUrl}" json="${attrs.json}" checked="${(attrs.checked ?: instance[attrs.field] ?: attrs.default) ? 'true' : null}"/> - + \ No newline at end of file diff --git a/core/src/main/resources/lib/form/radioBlock.jelly b/core/src/main/resources/lib/form/radioBlock.jelly index 2d59dc32ec..e042ffafe5 100644 --- a/core/src/main/resources/lib/form/radioBlock.jelly +++ b/core/src/main/resources/lib/form/radioBlock.jelly @@ -52,7 +52,6 @@ THE SOFTWARE. - diff --git a/core/src/main/resources/lib/hudson/newFromList/form.jelly b/core/src/main/resources/lib/hudson/newFromList/form.jelly index 1598e08341..387d6a3a2a 100644 --- a/core/src/main/resources/lib/hudson/newFromList/form.jelly +++ b/core/src/main/resources/lib/hudson/newFromList/form.jelly @@ -45,7 +45,6 @@ THE SOFTWARE. - @@ -56,7 +55,6 @@ THE SOFTWARE. - diff --git a/war/src/main/webapp/css/style.css b/war/src/main/webapp/css/style.css index 0fb7965faf..39f9673140 100644 --- a/war/src/main/webapp/css/style.css +++ b/war/src/main/webapp/css/style.css @@ -456,6 +456,10 @@ div.behavior-loading { filter: alpha(opacity=50); } +LABEL.attach-previous { + margin-left: 0.5em; +} + /* ======================== error/warning message (mainly in the form.) Use them on block elements ======================== */ .error { color: #CC0000; From 9905132fff6153050ea77b077b8542ea790fbc58 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 31 Mar 2011 17:02:41 -0700 Subject: [PATCH 07/25] Added a test case for ViewProperty --- .../java/hudson/model/ViewPropertyTest.java | 71 +++++++++++++++++++ .../ViewPropertyImpl/config.jelly | 5 ++ 2 files changed, 76 insertions(+) create mode 100644 test/src/test/java/hudson/model/ViewPropertyTest.java create mode 100644 test/src/test/resources/hudson/model/ViewPropertyTest/ViewPropertyImpl/config.jelly diff --git a/test/src/test/java/hudson/model/ViewPropertyTest.java b/test/src/test/java/hudson/model/ViewPropertyTest.java new file mode 100644 index 0000000000..db682a8a0c --- /dev/null +++ b/test/src/test/java/hudson/model/ViewPropertyTest.java @@ -0,0 +1,71 @@ +/* + * The MIT License + * + * Copyright (c) 2011, CloudBees, Inc. + * + * 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 hudson.model; + +import com.gargoylesoftware.htmlunit.html.HtmlForm; +import com.gargoylesoftware.htmlunit.html.HtmlLabel; +import org.jvnet.hudson.test.HudsonTestCase; +import org.jvnet.hudson.test.TestExtension; +import org.kohsuke.stapler.DataBoundConstructor; + +/** + * @author Kohsuke Kawaguchi + */ +public class ViewPropertyTest extends HudsonTestCase { + public void testRoundtrip() throws Exception { + ListView foo = new ListView("foo"); + hudson.addView(foo); + + // make sure it renders as optionalBlock + HtmlForm f = createWebClient().getPage(foo, "configure").getFormByName("viewConfig"); + ((HtmlLabel)f.selectSingleNode(".//LABEL[text()='Debug Property']")).click(); + submit(f); + ViewPropertyImpl vp = foo.getProperties().get(ViewPropertyImpl.class); + assertEquals("Duke",vp.name); + + // make sure it roundtrips correctly + vp.name = "Kohsuke"; + configRoundtrip(foo); + ViewPropertyImpl vp2 = foo.getProperties().get(ViewPropertyImpl.class); + assertNotSame(vp,vp2); + assertEqualDataBoundBeans(vp,vp2); + } + + public static class ViewPropertyImpl extends ViewProperty { + public String name; + + @DataBoundConstructor + public ViewPropertyImpl(String name) { + this.name = name; + } + + @TestExtension + public static class DescriptorImpl extends ViewPropertyDescriptor { + @Override + public String getDisplayName() { + return "Debug Property"; + } + } + } +} diff --git a/test/src/test/resources/hudson/model/ViewPropertyTest/ViewPropertyImpl/config.jelly b/test/src/test/resources/hudson/model/ViewPropertyTest/ViewPropertyImpl/config.jelly new file mode 100644 index 0000000000..777a376b64 --- /dev/null +++ b/test/src/test/resources/hudson/model/ViewPropertyTest/ViewPropertyImpl/config.jelly @@ -0,0 +1,5 @@ + + + + + From 8fcb00f2dd71fd0dcaace1cdcbd8c1fdb9376dbd Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 31 Mar 2011 17:08:55 -0700 Subject: [PATCH 08/25] added a test case for invisible ViewProperty --- .../java/hudson/model/ViewPropertyTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/src/test/java/hudson/model/ViewPropertyTest.java b/test/src/test/java/hudson/model/ViewPropertyTest.java index db682a8a0c..cb04bf277a 100644 --- a/test/src/test/java/hudson/model/ViewPropertyTest.java +++ b/test/src/test/java/hudson/model/ViewPropertyTest.java @@ -25,9 +25,12 @@ package hudson.model; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlLabel; +import hudson.model.Descriptor.FormException; +import net.sf.json.JSONObject; import org.jvnet.hudson.test.HudsonTestCase; import org.jvnet.hudson.test.TestExtension; import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.StaplerRequest; /** * @author Kohsuke Kawaguchi @@ -68,4 +71,37 @@ public class ViewPropertyTest extends HudsonTestCase { } } } + + public void testInvisibleProperty() throws Exception { + ListView foo = new ListView("foo"); + hudson.addView(foo); + + // test the rendering (or the lack thereof) of an invisible property + configRoundtrip(foo); + assertNull(foo.getProperties().get(InvisiblePropertyImpl.class)); + + // do the same but now with a configured instance + InvisiblePropertyImpl vp = new InvisiblePropertyImpl(); + foo.getProperties().add(vp); + configRoundtrip(foo); + assertSame(vp,foo.getProperties().get(InvisiblePropertyImpl.class)); + } + + public static class InvisiblePropertyImpl extends ViewProperty { + InvisiblePropertyImpl() { + } + + @Override + public ViewProperty reconfigure(StaplerRequest req, JSONObject form) throws FormException { + return this; + } + + @TestExtension + public static class DescriptorImpl extends ViewPropertyDescriptor { + @Override + public String getDisplayName() { + return null; + } + } + } } From 5e3c88727e39416edf883f8697a3d034339fc3fe Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 31 Mar 2011 17:24:06 -0700 Subject: [PATCH 09/25] noting legacy stuff --- core/src/main/java/hudson/model/Job.java | 1 + core/src/main/resources/hudson/model/Job/configure.jelly | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/model/Job.java b/core/src/main/java/hudson/model/Job.java index 8991cf7c25..5c1a9aa012 100644 --- a/core/src/main/java/hudson/model/Job.java +++ b/core/src/main/java/hudson/model/Job.java @@ -139,6 +139,7 @@ public abstract class Job, RunT extends Run> properties = new CopyOnWriteList>(); protected Job(ItemGroup parent, String name) { diff --git a/core/src/main/resources/hudson/model/Job/configure.jelly b/core/src/main/resources/hudson/model/Job/configure.jelly index 5b28d467c0..cdef885d32 100644 --- a/core/src/main/resources/hudson/model/Job/configure.jelly +++ b/core/src/main/resources/hudson/model/Job/configure.jelly @@ -52,7 +52,7 @@ THE SOFTWARE. - + From e6b90c74f3ae2afaa9cf711c66e79dfd8067be75 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 31 Mar 2011 18:18:38 -0700 Subject: [PATCH 10/25] - modified to use for better reuse&consistency. - support invisible JobProperty --- core/src/main/java/hudson/model/Job.java | 22 ++++++++----------- .../main/java/hudson/model/JobProperty.java | 9 +++++++- .../hudson/model/Job/configure.jelly | 12 +--------- .../resources/lib/form/descriptorList.jelly | 5 ++++- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/hudson/model/Job.java b/core/src/main/java/hudson/model/Job.java index 5c1a9aa012..2a02712d6a 100644 --- a/core/src/main/java/hudson/model/Job.java +++ b/core/src/main/java/hudson/model/Job.java @@ -26,6 +26,7 @@ package hudson.model; import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST; import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT; +import com.google.common.collect.Iterables; import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import hudson.ExtensionPoint; import hudson.PermalinkList; @@ -46,6 +47,7 @@ import hudson.util.ChartUtil; import hudson.util.ColorPalette; import hudson.util.CopyOnWriteList; import hudson.util.DataSetBuilder; +import hudson.util.DescribableList; import hudson.util.IOException2; import hudson.util.RunList; import hudson.util.ShiftedCategoryAxis; @@ -936,25 +938,19 @@ public abstract class Job, RunT extends Run, JobPropertyDescriptor> t = new DescribableList, JobPropertyDescriptor>(NOOP,getAllProperties()); + t.rebuild(req,json.optJSONObject("properties"),JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass())); + properties.clear(); + for (JobProperty p : t) { + p.setOwner(this); + properties.add(p); } submit(req, rsp); diff --git a/core/src/main/java/hudson/model/JobProperty.java b/core/src/main/java/hudson/model/JobProperty.java index 3d0292315f..f22835ce51 100644 --- a/core/src/main/java/hudson/model/JobProperty.java +++ b/core/src/main/java/hudson/model/JobProperty.java @@ -26,6 +26,7 @@ package hudson.model; import hudson.ExtensionPoint; import hudson.Launcher; import hudson.Plugin; +import hudson.model.Descriptor.FormException; import hudson.model.queue.SubTask; import hudson.tasks.BuildStep; import hudson.tasks.Builder; @@ -36,6 +37,8 @@ import java.io.IOException; import java.util.Collection; import java.util.Collections; +import net.sf.json.JSONObject; +import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.export.ExportedBean; /** @@ -69,7 +72,7 @@ import org.kohsuke.stapler.export.ExportedBean; * @since 1.72 */ @ExportedBean -public abstract class JobProperty> implements Describable>, BuildStep, ExtensionPoint { +public abstract class JobProperty> implements ReconfigurableDescribable>, BuildStep, ExtensionPoint { /** * The {@link Job} object that owns this property. * This value will be set by the Hudson code. @@ -169,6 +172,10 @@ public abstract class JobProperty> implements Describable reconfigure(StaplerRequest req, JSONObject form) throws FormException { + return form==null ? null : getDescriptor().newInstance(req,form); + } + /** * Contributes {@link SubTask}s to {@link AbstractProject#getSubTasks()} * diff --git a/core/src/main/resources/hudson/model/Job/configure.jelly b/core/src/main/resources/hudson/model/Job/configure.jelly index cdef885d32..67d67d77a3 100644 --- a/core/src/main/resources/hudson/model/Job/configure.jelly +++ b/core/src/main/resources/hudson/model/Job/configure.jelly @@ -53,17 +53,7 @@ THE SOFTWARE. - - - - - - - - - - - + diff --git a/core/src/main/resources/lib/form/descriptorList.jelly b/core/src/main/resources/lib/form/descriptorList.jelly index 5edae295bd..3a3d1b7457 100644 --- a/core/src/main/resources/lib/form/descriptorList.jelly +++ b/core/src/main/resources/lib/form/descriptorList.jelly @@ -50,6 +50,9 @@ THE SOFTWARE. the type for which descriptors will be configured. default to ${it.class} + + If specified, instead of a sequence of <f:optionalBlock>s, draw a sequence of <rowSet>s. + @@ -73,7 +76,7 @@ THE SOFTWARE. + title="${attrs.forceRowSet!=null?null:d.displayName}" checked="${instances.get(d)!=null}"> From ea0295b5096a3cc76297e7d7030b54d44f3dc472 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 31 Mar 2011 18:19:13 -0700 Subject: [PATCH 11/25] added test cases --- .../java/hudson/model/JobPropertyTest.java | 75 ++++++++++++++++--- .../JobPropertyWithConfigImpl/config.jelly | 5 ++ 2 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 test/src/test/resources/hudson/model/JobPropertyTest/JobPropertyWithConfigImpl/config.jelly diff --git a/test/src/test/java/hudson/model/JobPropertyTest.java b/test/src/test/java/hudson/model/JobPropertyTest.java index 3d76df4502..9e8db1df75 100644 --- a/test/src/test/java/hudson/model/JobPropertyTest.java +++ b/test/src/test/java/hudson/model/JobPropertyTest.java @@ -1,7 +1,7 @@ /* * The MIT License * - * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt + * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt, CloudBees, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,13 +27,20 @@ import com.gargoylesoftware.htmlunit.WebAssert; import com.gargoylesoftware.htmlunit.html.HtmlPage; import hudson.matrix.MatrixProject; import hudson.maven.MavenModuleSet; +import hudson.model.Descriptor.FormException; +import net.sf.json.JSONObject; +import org.jvnet.hudson.test.Bug; import org.jvnet.hudson.test.HudsonTestCase; +import org.jvnet.hudson.test.TestExtension; +import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.StaplerRequest; public class JobPropertyTest extends HudsonTestCase { /** * Asserts that rfe#2398 is fixed. */ + @Bug(2398) public void testJobPropertySummaryIsShownInMavenModuleSetIndexPage() throws Exception { assertJobPropertySummaryIsShownInIndexPage(MavenModuleSet.DESCRIPTOR); } @@ -54,7 +61,6 @@ public class JobPropertyTest extends HudsonTestCase { } public static class JobPropertyImpl extends JobProperty> { - public static DescriptorImpl DESCRIPTOR = new DescriptorImpl(); private final String propertyString; public JobPropertyImpl(String propertyString) { this.propertyString = propertyString; @@ -64,13 +70,8 @@ public class JobPropertyTest extends HudsonTestCase { return propertyString; } - @Override - public JobPropertyDescriptor getDescriptor() { - return DESCRIPTOR; - } - - @SuppressWarnings("unchecked") - private static class DescriptorImpl extends JobPropertyDescriptor { + @TestExtension + public static class DescriptorImpl extends JobPropertyDescriptor { @Override public boolean isApplicable(Class jobType) { return false; @@ -82,4 +83,60 @@ public class JobPropertyTest extends HudsonTestCase { } } } + + /** + * Make sure that the UI rendering works as designed. + */ + public void testConfigRoundtrip() throws Exception { + FreeStyleProject p = createFreeStyleProject(); + JobPropertyWithConfigImpl before = new JobPropertyWithConfigImpl("Duke"); + p.addProperty(before); + configRoundtrip(p); + JobPropertyWithConfigImpl after = p.getProperty(JobPropertyWithConfigImpl.class); + assertNotSame(after,before); + assertEqualDataBoundBeans(before, after); + } + + public static class JobPropertyWithConfigImpl extends JobProperty> { + public String name; + + @DataBoundConstructor + public JobPropertyWithConfigImpl(String name) { + this.name = name; + } + + @TestExtension("testConfigRoundtrip") + public static class DescriptorImpl extends JobPropertyDescriptor { + @Override + public String getDisplayName() { return null; } + } + } + + + + public void testInvisibleProperty() throws Exception { + FreeStyleProject p = createFreeStyleProject(); + InvisibleImpl before = new InvisibleImpl(); + p.addProperty(before); + configRoundtrip(p); + InvisibleImpl after = p.getProperty(InvisibleImpl.class); + assertSame(after,before); + } + + public static class InvisibleImpl extends JobProperty> { + public String name; + + InvisibleImpl() {} + + @Override + public JobProperty reconfigure(StaplerRequest req, JSONObject form) throws FormException { + return this; + } + + @TestExtension("testInvisibleProperty") + public static class DescriptorImpl extends JobPropertyDescriptor { + @Override + public String getDisplayName() { return null; } + } + } } diff --git a/test/src/test/resources/hudson/model/JobPropertyTest/JobPropertyWithConfigImpl/config.jelly b/test/src/test/resources/hudson/model/JobPropertyTest/JobPropertyWithConfigImpl/config.jelly new file mode 100644 index 0000000000..8dc663c544 --- /dev/null +++ b/test/src/test/resources/hudson/model/JobPropertyTest/JobPropertyWithConfigImpl/config.jelly @@ -0,0 +1,5 @@ + + + + + From f2ebd01bbdb1c4c965fc15345ffa89b7264f6872 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 1 Apr 2011 09:51:52 -0700 Subject: [PATCH 12/25] Node now supports ReconfigurableDescribable --- core/src/main/java/hudson/model/Computer.java | 2 +- core/src/main/java/hudson/model/Node.java | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index e37f696f3e..59bf7f476f 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -1029,7 +1029,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces final Hudson app = Hudson.getInstance(); - Node result = getNode().getDescriptor().newInstance(req, req.getSubmittedForm()); + Node result = getNode().reconfigure(req, req.getSubmittedForm()); // replace the old Node object by the new one synchronized (app) { diff --git a/core/src/main/java/hudson/model/Node.java b/core/src/main/java/hudson/model/Node.java index a0546893f8..c79d336907 100644 --- a/core/src/main/java/hudson/model/Node.java +++ b/core/src/main/java/hudson/model/Node.java @@ -30,6 +30,7 @@ import hudson.ExtensionPoint; import hudson.FilePath; import hudson.FileSystemProvisioner; import hudson.Launcher; +import hudson.model.Descriptor.FormException; import hudson.model.Queue.Task; import hudson.model.labels.LabelAtom; import hudson.model.queue.CauseOfBlockage; @@ -56,7 +57,9 @@ import java.util.Set; import java.util.List; import java.util.logging.Logger; +import net.sf.json.JSONObject; import org.kohsuke.stapler.Stapler; +import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.export.ExportedBean; import org.kohsuke.stapler.export.Exported; @@ -71,7 +74,7 @@ import org.kohsuke.stapler.export.Exported; * @see NodeDescriptor */ @ExportedBean -public abstract class Node extends AbstractModelObject implements Describable, ExtensionPoint, AccessControlled { +public abstract class Node extends AbstractModelObject implements ReconfigurableDescribable, ExtensionPoint, AccessControlled { private static final Logger LOGGER = Logger.getLogger(Node.class.getName()); @@ -362,6 +365,10 @@ public abstract class Node extends AbstractModelObject implements Describable Date: Fri, 1 Apr 2011 14:22:41 -0700 Subject: [PATCH 13/25] added a convenience method --- .../java/org/jvnet/hudson/test/HudsonTestCase.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index e5a7a7aeed..711d291313 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -787,6 +787,16 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { return (C)computerConnectorTester.connector; } + protected User configRoundtrip(User u) throws Exception { + submit(createWebClient().goTo(u.getUrl()+"/configure").getFormByName("config")); + return u; + } + + protected N configRoundtrip(N node) throws Exception { + submit(createWebClient().goTo("/computer/"+node.getNodeName()+"/configure").getFormByName("config")); + return (N)hudson.getNode(node.getNodeName()); + } + protected V configRoundtrip(V view) throws Exception { submit(createWebClient().getPage(view, "configure").getFormByName("viewConfig")); return view; From 88ea8de45f5d6ae846d64d7cad9b8432fb111357 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 1 Apr 2011 14:25:46 -0700 Subject: [PATCH 14/25] added a mechanism for creating invisible node properties --- core/pom.xml | 2 +- core/src/main/java/hudson/model/Node.java | 30 ++++++- .../main/java/hudson/slaves/NodeProperty.java | 10 ++- .../java/hudson/slaves/NodePropertyTest.java | 81 +++++++++++++++++++ .../PropertyImpl/config.jelly | 5 ++ 5 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 test/src/test/java/hudson/slaves/NodePropertyTest.java create mode 100644 test/src/test/resources/hudson/slaves/NodePropertyTest/PropertyImpl/config.jelly diff --git a/core/pom.xml b/core/pom.xml index f8b3788390..a8ce5808ca 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -382,7 +382,7 @@ THE SOFTWARE. org.kohsuke.stapler stapler-jelly - 1.155 + 1.161 commons-jelly diff --git a/core/src/main/java/hudson/model/Node.java b/core/src/main/java/hudson/model/Node.java index c79d336907..4d75381c96 100644 --- a/core/src/main/java/hudson/model/Node.java +++ b/core/src/main/java/hudson/model/Node.java @@ -51,6 +51,7 @@ import hudson.util.TagCloud; import hudson.util.TagCloud.WeightFunction; import java.io.IOException; +import java.lang.reflect.Type; import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -58,6 +59,7 @@ import java.util.List; import java.util.logging.Logger; import net.sf.json.JSONObject; +import org.kohsuke.stapler.BindInterceptor; import org.kohsuke.stapler.Stapler; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.export.ExportedBean; @@ -365,8 +367,32 @@ public abstract class Node extends AbstractModelObject implements Reconfigurable return getACL().hasPermission(permission); } - public Node reconfigure(StaplerRequest req, JSONObject form) throws FormException { - return form==null ? null : getDescriptor().newInstance(req, form); + public Node reconfigure(final StaplerRequest req, JSONObject form) throws FormException { + if (form==null) return null; + + final JSONObject jsonForProperties = form.optJSONObject("nodeProperties"); + BindInterceptor old = req.setBindListener(new BindInterceptor() { + @Override + public Object onConvert(Type targetType, Class targetTypeErasure, Object jsonSource) { + if (jsonForProperties!=jsonSource) return DEFAULT; + + try { + DescribableList, NodePropertyDescriptor> tmp = new DescribableList, NodePropertyDescriptor>(Saveable.NOOP,getNodeProperties().toList()); + tmp.rebuild(req, jsonForProperties, NodeProperty.all()); + return tmp.toList(); + } catch (FormException e) { + throw new IllegalArgumentException(e); + } catch (IOException e) { + throw new IllegalArgumentException(e); + } + } + }); + + try { + return getDescriptor().newInstance(req, form); + } finally { + req.setBindListener(old); + } } public abstract NodeDescriptor getDescriptor(); diff --git a/core/src/main/java/hudson/slaves/NodeProperty.java b/core/src/main/java/hudson/slaves/NodeProperty.java index 1319238887..59322ea832 100644 --- a/core/src/main/java/hudson/slaves/NodeProperty.java +++ b/core/src/main/java/hudson/slaves/NodeProperty.java @@ -26,6 +26,8 @@ package hudson.slaves; import hudson.ExtensionPoint; import hudson.Launcher; import hudson.DescriptorExtensionList; +import hudson.model.Descriptor.FormException; +import hudson.model.ReconfigurableDescribable; import hudson.model.queue.CauseOfBlockage; import hudson.scm.SCM; import hudson.model.AbstractBuild; @@ -35,6 +37,8 @@ import hudson.model.Environment; import hudson.model.Hudson; import hudson.model.Node; import hudson.model.Queue.Task; +import net.sf.json.JSONObject; +import org.kohsuke.stapler.StaplerRequest; import java.io.IOException; import java.util.List; @@ -63,7 +67,7 @@ import java.util.List; * * @since 1.286 */ -public abstract class NodeProperty implements Describable>, ExtensionPoint { +public abstract class NodeProperty implements ReconfigurableDescribable>, ExtensionPoint { protected transient N node; @@ -109,6 +113,10 @@ public abstract class NodeProperty implements Describable reconfigure(StaplerRequest req, JSONObject form) throws FormException { + return form==null ? null : getDescriptor().newInstance(req, form); + } + /** * Lists up all the registered {@link NodeDescriptor}s in the system. */ diff --git a/test/src/test/java/hudson/slaves/NodePropertyTest.java b/test/src/test/java/hudson/slaves/NodePropertyTest.java new file mode 100644 index 0000000000..b8be591998 --- /dev/null +++ b/test/src/test/java/hudson/slaves/NodePropertyTest.java @@ -0,0 +1,81 @@ +package hudson.slaves; + +import com.gargoylesoftware.htmlunit.html.HtmlForm; +import com.gargoylesoftware.htmlunit.html.HtmlLabel; +import hudson.model.Descriptor.FormException; +import hudson.model.Slave; +import net.sf.json.JSONObject; +import org.jvnet.hudson.test.HudsonTestCase; +import org.jvnet.hudson.test.TestExtension; +import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.StaplerRequest; + +/** + * @author Kohsuke Kawaguchi + */ +public class NodePropertyTest extends HudsonTestCase { + public void testInvisibleProperty() throws Exception { + DumbSlave s = createSlave(); + InvisibleProperty before = new InvisibleProperty(); + s.getNodeProperties().add(before); + assertFalse(before.reconfigured); + + + DumbSlave s2 = configRoundtrip(s); + assertNotSame(s,s2); + InvisibleProperty after = s2.getNodeProperties().get(InvisibleProperty.class); + + assertSame(before,after); + assertTrue(after.reconfigured); + } + + public static class InvisibleProperty extends NodeProperty { + boolean reconfigured = false; + @Override + public NodeProperty reconfigure(StaplerRequest req, JSONObject form) throws FormException { + reconfigured = true; + return this; + } + + @TestExtension + public static class DescriptorImpl extends NodePropertyDescriptor { + @Override + public String getDisplayName() { + return null; + } + } + } + + public void testBasicConfigRoundtrip() throws Exception { + DumbSlave s = createSlave(); + HtmlForm f = createWebClient().goTo("/computer/" + s.getNodeName() + "/configure").getFormByName("config"); + ((HtmlLabel)f.selectSingleNode(".//LABEL[text()='Some Property']")).click(); + submit(f); + PropertyImpl p = hudson.getNode(s.getNodeName()).getNodeProperties().get(PropertyImpl.class); + assertEquals("Duke",p.name); + + p.name = "Kohsuke"; + configRoundtrip(s); + + PropertyImpl p2 = hudson.getNode(s.getNodeName()).getNodeProperties().get(PropertyImpl.class); + assertNotSame(p,p2); + assertEqualDataBoundBeans(p,p2); + } + + public static class PropertyImpl extends NodeProperty { + public String name; + + @DataBoundConstructor + public PropertyImpl(String name) { + this.name = name; + } + + @TestExtension("testBasicConfigRoundtrip") + public static class DescriptorImpl extends NodePropertyDescriptor { + @Override + public String getDisplayName() { + return "Some Property"; + } + } + } +} diff --git a/test/src/test/resources/hudson/slaves/NodePropertyTest/PropertyImpl/config.jelly b/test/src/test/resources/hudson/slaves/NodePropertyTest/PropertyImpl/config.jelly new file mode 100644 index 0000000000..4bcbab93c4 --- /dev/null +++ b/test/src/test/resources/hudson/slaves/NodePropertyTest/PropertyImpl/config.jelly @@ -0,0 +1,5 @@ + + + + + From 36cfac2fdd63828b29d98d47aeda2dacab9a0f99 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 1 Apr 2011 15:06:48 -0700 Subject: [PATCH 15/25] recording changes in ad343a68075e64ee91bf66d84a8dea727f60bf84 --- changelog.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog.html b/changelog.html index 086f4e6f3c..af19d42f47 100644 --- a/changelog.html +++ b/changelog.html @@ -67,6 +67,10 @@ Upcoming changes Added an extension point to allow associating custom properties with views.
  • Actions can now override their rendering in the parent model object. +
  • + Added a mechanism for plugins to write an invisible job property +
  • + Added a mechanism for plugins to write an invisible node property From 2960207cb89687d8a69061f17d73b86eba1df278 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 1 Apr 2011 15:13:56 -0700 Subject: [PATCH 16/25] needs to have @title due to f8e136ed4902d6c625fa4a7b9bfc7c99cfbb46c8 --- .../lib/form/AdvancedButtonTest/testNestedOptionalBlock.jelly | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/test/resources/lib/form/AdvancedButtonTest/testNestedOptionalBlock.jelly b/test/src/test/resources/lib/form/AdvancedButtonTest/testNestedOptionalBlock.jelly index 227cfd1504..14179ade02 100644 --- a/test/src/test/resources/lib/form/AdvancedButtonTest/testNestedOptionalBlock.jelly +++ b/test/src/test/resources/lib/form/AdvancedButtonTest/testNestedOptionalBlock.jelly @@ -36,7 +36,7 @@ THE SOFTWARE. - + From 2ae9e56b8d93b508c704a3eea2390e0a0c173377 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 1 Apr 2011 15:23:59 -0700 Subject: [PATCH 17/25] crap, merge error --- core/src/main/java/hudson/model/Node.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/model/Node.java b/core/src/main/java/hudson/model/Node.java index 4d75381c96..9d4f7f9d4d 100644 --- a/core/src/main/java/hudson/model/Node.java +++ b/core/src/main/java/hudson/model/Node.java @@ -367,7 +367,7 @@ public abstract class Node extends AbstractModelObject implements Reconfigurable return getACL().hasPermission(permission); } - public Node reconfigure(final StaplerRequest req, JSONObject form) throws FormException { + public Node reconfigure(StaplerRequest req, JSONObject form) throws FormException { if (form==null) return null; final JSONObject jsonForProperties = form.optJSONObject("nodeProperties"); From 2b7ebb54375c73b35e091769aa916a5627842396 Mon Sep 17 00:00:00 2001 From: Seiji Sogabe Date: Sat, 2 Apr 2011 08:14:01 +0900 Subject: [PATCH 18/25] fix compilation error. --- core/src/main/java/hudson/model/Node.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/model/Node.java b/core/src/main/java/hudson/model/Node.java index 9d4f7f9d4d..4d75381c96 100644 --- a/core/src/main/java/hudson/model/Node.java +++ b/core/src/main/java/hudson/model/Node.java @@ -367,7 +367,7 @@ public abstract class Node extends AbstractModelObject implements Reconfigurable return getACL().hasPermission(permission); } - public Node reconfigure(StaplerRequest req, JSONObject form) throws FormException { + public Node reconfigure(final StaplerRequest req, JSONObject form) throws FormException { if (form==null) return null; final JSONObject jsonForProperties = form.optJSONObject("nodeProperties"); From 642632d16bc8c682d9e5fd9abd3eb68300aa7891 Mon Sep 17 00:00:00 2001 From: Paul Sandoz Date: Tue, 5 Apr 2011 10:20:44 +0200 Subject: [PATCH 19/25] Use LinkedBlockingQueue to support unbounded requests. Previously this was limited to the max thread pool size (of ten). --- .../java/org/jvnet/hudson/test/HudsonTestCase.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index 0e540ec85e..b264e53c16 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -128,14 +128,7 @@ import java.util.List; import java.util.Locale; import java.util.Set; import java.util.UUID; -import java.util.concurrent.Callable; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.SynchronousQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.jar.Manifest; import java.util.logging.Filter; import java.util.logging.Level; @@ -447,7 +440,8 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { context.setMimeTypes(MIME_TYPES); SocketConnector connector = new SocketConnector(); - server.setThreadPool(new ThreadPoolImpl(new ThreadPoolExecutor(1, 10, 10L, TimeUnit.SECONDS, new SynchronousQueue(),new ThreadFactory() { + + server.setThreadPool(new ThreadPoolImpl(new ThreadPoolExecutor(10, 10, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue(),new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("Jetty Thread Pool"); From f105becb14eb8de748be8906f5abe6b66709ac54 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 1 Apr 2011 21:33:29 -0700 Subject: [PATCH 20/25] added another convenience method --- .../main/java/org/jvnet/hudson/test/HudsonTestCase.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index b264e53c16..91a20b6ab7 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -685,11 +685,14 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { */ public DumbSlave createSlave(String labels, EnvVars env) throws Exception { synchronized (hudson) { - // this synchronization block is so that we don't end up adding the same slave name more than once. - int sz = hudson.getNodes().size(); + return createSlave("slave" + sz,labels,env); + } + } - DumbSlave slave = new DumbSlave("slave" + sz, "dummy", + public DumbSlave createSlave(String nodeName, String labels, EnvVars env) throws Exception { + synchronized (hudson) { + DumbSlave slave = new DumbSlave(nodeName, "dummy", createTmpDir().getPath(), "1", Mode.NORMAL, labels==null?"":labels, createComputerLauncher(env), RetentionStrategy.NOOP, Collections.EMPTY_LIST); hudson.addNode(slave); return slave; From 3cd9ad4c22f40ebbf7c0526ba451a7921fc5d1de Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 14 Apr 2011 15:44:38 -0700 Subject: [PATCH 21/25] using newer versions with the license definition in POM --- core/pom.xml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 53e0d2bbcd..0c6ca3dfde 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -348,9 +348,9 @@ THE SOFTWARE. ${project.version} - org.jvnet.hudson + org.jenkins-ci crypto-util - 1.0 + 1.1 org.jvnet.hudson @@ -685,9 +685,9 @@ THE SOFTWARE. 1.14 - org.jvnet.hudson + org.jenkins-ci memory-monitor - 1.3 + 1.4 com.octo.captcha @@ -778,17 +778,17 @@ THE SOFTWARE. net.java.sezpoz sezpoz - 1.7 + 1.9 - org.jvnet.hudson + org.jenkins-ci jinterop-wmi - 1.0 + 1.1 - org.jvnet.hudson + org.jenkins-ci windows-remote-command - 1.0 + 1.3 org.kohsuke.metainf-services From 2eae2b1cde8bb45c9229242c2a8872c6ac44739b Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 14 Apr 2011 17:45:17 -0700 Subject: [PATCH 22/25] removed the user of graph layouter, which was experimental anyway --- core/pom.xml | 5 - .../java/hudson/model/DependencyGraph.java | 200 ++++++++---------- 2 files changed, 91 insertions(+), 114 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 0c6ca3dfde..af385810fa 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -438,11 +438,6 @@ THE SOFTWARE. localizer 1.10 - - org.kohsuke - graph-layouter - 1.0 - antlr antlr diff --git a/core/src/main/java/hudson/model/DependencyGraph.java b/core/src/main/java/hudson/model/DependencyGraph.java index 430a8ac073..4ac9ff8675 100644 --- a/core/src/main/java/hudson/model/DependencyGraph.java +++ b/core/src/main/java/hudson/model/DependencyGraph.java @@ -28,14 +28,7 @@ import hudson.security.ACL; import hudson.security.NotSerilizableSecurityContext; import org.acegisecurity.context.SecurityContext; import org.acegisecurity.context.SecurityContextHolder; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.StaplerResponse; -import org.kohsuke.graph_layouter.Layout; -import org.kohsuke.graph_layouter.Navigator; -import org.kohsuke.graph_layouter.Direction; -import javax.servlet.ServletOutputStream; -import javax.imageio.ImageIO; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -49,17 +42,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.Stack; -import java.io.IOException; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Rectangle; -import java.awt.Graphics2D; -import java.awt.Color; -import java.awt.Point; -import java.awt.HeadlessException; -import java.awt.FontMetrics; -import java.awt.geom.AffineTransform; -import java.awt.image.BufferedImage; /** * Maintains the build dependencies between {@link AbstractProject}s @@ -298,97 +280,97 @@ public final class DependencyGraph implements Comparator { return Collections.unmodifiableMap(m); } - /** - * Experimental visualization of project dependencies. - */ - public void doGraph( StaplerRequest req, StaplerResponse rsp ) throws IOException { - // Require admin permission for now (avoid exposing project names with restricted permissions) - Hudson.getInstance().checkPermission(Hudson.ADMINISTER); - try { - - // creates a dummy graphics just so that we can measure font metrics - BufferedImage emptyImage = new BufferedImage(1,1, BufferedImage.TYPE_INT_RGB ); - Graphics2D graphics = emptyImage.createGraphics(); - graphics.setFont(FONT); - final FontMetrics fontMetrics = graphics.getFontMetrics(); - - // TODO: timestamp check - Layout layout = new Layout(new Navigator() { - public Collection vertices() { - // only include projects that have some dependency - List r = new ArrayList(); - for (AbstractProject p : Hudson.getInstance().getAllItems(AbstractProject.class)) { - if(!getDownstream(p).isEmpty() || !getUpstream(p).isEmpty()) - r.add(p); - } - return r; - } - - public Collection edge(AbstractProject p) { - return getDownstream(p); - } - - public Dimension getSize(AbstractProject p) { - int w = fontMetrics.stringWidth(p.getDisplayName()) + MARGIN*2; - return new Dimension(w, fontMetrics.getHeight() + MARGIN*2); - } - }, Direction.LEFTRIGHT); - - Rectangle area = layout.calcDrawingArea(); - area.grow(4,4); // give it a bit of margin - BufferedImage image = new BufferedImage(area.width, area.height, BufferedImage.TYPE_INT_RGB ); - Graphics2D g2 = image.createGraphics(); - g2.setTransform(AffineTransform.getTranslateInstance(-area.x,-area.y)); - g2.setPaint(Color.WHITE); - g2.fill(area); - g2.setFont(FONT); - - g2.setPaint(Color.BLACK); - for( AbstractProject p : layout.vertices() ) { - final Point sp = center(layout.vertex(p)); - - for (AbstractProject q : layout.edges(p)) { - Point cur=sp; - for( Point pt : layout.edge(p,q) ) { - g2.drawLine(cur.x, cur.y, pt.x, pt.y); - cur=pt; - } - - final Point ep = center(layout.vertex(q)); - g2.drawLine(cur.x, cur.y, ep.x, ep.y); - } - } - - int diff = fontMetrics.getAscent()+fontMetrics.getLeading()/2; - - for( AbstractProject p : layout.vertices() ) { - Rectangle r = layout.vertex(p); - g2.setPaint(Color.WHITE); - g2.fillRect(r.x, r.y, r.width, r.height); - g2.setPaint(Color.BLACK); - g2.drawRect(r.x, r.y, r.width, r.height); - g2.drawString(p.getDisplayName(), r.x+MARGIN, r.y+MARGIN+ diff); - } - - rsp.setContentType("image/png"); - ServletOutputStream os = rsp.getOutputStream(); - ImageIO.write(image, "PNG", os); - os.close(); - } catch(HeadlessException e) { - // not available. send out error message - rsp.sendRedirect2(req.getContextPath()+"/images/headless.png"); - } - } - - private Point center(Rectangle r) { - return new Point(r.x+r.width/2,r.y+r.height/2); - } - - private static final Font FONT = new Font("TimesRoman", Font.PLAIN, 10); - /** - * Margins between the project name and its bounding box. - */ - private static final int MARGIN = 4; +// /** +// * Experimental visualization of project dependencies. +// */ +// public void doGraph( StaplerRequest req, StaplerResponse rsp ) throws IOException { +// // Require admin permission for now (avoid exposing project names with restricted permissions) +// Hudson.getInstance().checkPermission(Hudson.ADMINISTER); +// try { +// +// // creates a dummy graphics just so that we can measure font metrics +// BufferedImage emptyImage = new BufferedImage(1,1, BufferedImage.TYPE_INT_RGB ); +// Graphics2D graphics = emptyImage.createGraphics(); +// graphics.setFont(FONT); +// final FontMetrics fontMetrics = graphics.getFontMetrics(); +// +// // TODO: timestamp check +// Layout layout = new Layout(new Navigator() { +// public Collection vertices() { +// // only include projects that have some dependency +// List r = new ArrayList(); +// for (AbstractProject p : Hudson.getInstance().getAllItems(AbstractProject.class)) { +// if(!getDownstream(p).isEmpty() || !getUpstream(p).isEmpty()) +// r.add(p); +// } +// return r; +// } +// +// public Collection edge(AbstractProject p) { +// return getDownstream(p); +// } +// +// public Dimension getSize(AbstractProject p) { +// int w = fontMetrics.stringWidth(p.getDisplayName()) + MARGIN*2; +// return new Dimension(w, fontMetrics.getHeight() + MARGIN*2); +// } +// }, Direction.LEFTRIGHT); +// +// Rectangle area = layout.calcDrawingArea(); +// area.grow(4,4); // give it a bit of margin +// BufferedImage image = new BufferedImage(area.width, area.height, BufferedImage.TYPE_INT_RGB ); +// Graphics2D g2 = image.createGraphics(); +// g2.setTransform(AffineTransform.getTranslateInstance(-area.x,-area.y)); +// g2.setPaint(Color.WHITE); +// g2.fill(area); +// g2.setFont(FONT); +// +// g2.setPaint(Color.BLACK); +// for( AbstractProject p : layout.vertices() ) { +// final Point sp = center(layout.vertex(p)); +// +// for (AbstractProject q : layout.edges(p)) { +// Point cur=sp; +// for( Point pt : layout.edge(p,q) ) { +// g2.drawLine(cur.x, cur.y, pt.x, pt.y); +// cur=pt; +// } +// +// final Point ep = center(layout.vertex(q)); +// g2.drawLine(cur.x, cur.y, ep.x, ep.y); +// } +// } +// +// int diff = fontMetrics.getAscent()+fontMetrics.getLeading()/2; +// +// for( AbstractProject p : layout.vertices() ) { +// Rectangle r = layout.vertex(p); +// g2.setPaint(Color.WHITE); +// g2.fillRect(r.x, r.y, r.width, r.height); +// g2.setPaint(Color.BLACK); +// g2.drawRect(r.x, r.y, r.width, r.height); +// g2.drawString(p.getDisplayName(), r.x+MARGIN, r.y+MARGIN+ diff); +// } +// +// rsp.setContentType("image/png"); +// ServletOutputStream os = rsp.getOutputStream(); +// ImageIO.write(image, "PNG", os); +// os.close(); +// } catch(HeadlessException e) { +// // not available. send out error message +// rsp.sendRedirect2(req.getContextPath()+"/images/headless.png"); +// } +// } +// +// private Point center(Rectangle r) { +// return new Point(r.x+r.width/2,r.y+r.height/2); +// } +// +// private static final Font FONT = new Font("TimesRoman", Font.PLAIN, 10); +// /** +// * Margins between the project name and its bounding box. +// */ +// private static final int MARGIN = 4; private static final Comparator NAME_COMPARATOR = new Comparator() { From 0ae70779bebf8bf7da38f5ea4438f08ab0458942 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 15 Apr 2011 10:15:30 -0700 Subject: [PATCH 23/25] Generate 3rd party dependency license report and make it visible from the UI. Also, for the core build, require that all the dependency licenses are available. --- core/pom.xml | 7 ++ core/src/main/java/hudson/PluginWrapper.java | 9 ++ .../hudson/PluginManager/installed.jelly | 4 +- .../PluginWrapper/3rdPartyLicenses.jelly | 44 +++++++++ .../PluginWrapper/3rdPartyLicenses.properties | 1 + .../resources/hudson/model/Hudson/about.jelly | 43 +++++++++ .../hudson/model/Hudson/about.properties | 4 + .../lib/hudson/3rdPartyLicenses.jelly | 57 ++++++++++++ licenseCompleter.groovy | 92 +++++++++++++++++++ maven-plugin/pom.xml | 11 ++- pom.xml | 17 ++++ 11 files changed, 286 insertions(+), 3 deletions(-) create mode 100644 core/src/main/resources/hudson/PluginWrapper/3rdPartyLicenses.jelly create mode 100644 core/src/main/resources/hudson/PluginWrapper/3rdPartyLicenses.properties create mode 100644 core/src/main/resources/hudson/model/Hudson/about.jelly create mode 100644 core/src/main/resources/hudson/model/Hudson/about.properties create mode 100644 core/src/main/resources/lib/hudson/3rdPartyLicenses.jelly create mode 100644 licenseCompleter.groovy diff --git a/core/pom.xml b/core/pom.xml index af385810fa..a7ea2914f7 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -225,6 +225,13 @@ THE SOFTWARE. + + com.cloudbees + maven-license-plugin + + target/classes/META-INF/licenses.xml + + diff --git a/core/src/main/java/hudson/PluginWrapper.java b/core/src/main/java/hudson/PluginWrapper.java index 55e038bb93..168edc426b 100644 --- a/core/src/main/java/hudson/PluginWrapper.java +++ b/core/src/main/java/hudson/PluginWrapper.java @@ -397,6 +397,15 @@ public class PluginWrapper implements Comparable { return manifest.getMainAttributes().getValue("Plugin-Class"); } + public boolean hasLicensesXml() { + try { + new URL(baseResourceURL,"WEB-INF/licenses.xml").openStream().close(); + return true; + } catch (IOException e) { + return false; + } + } + /** * Makes sure that all the dependencies exist, and then accept optional dependencies * as real dependencies. diff --git a/core/src/main/resources/hudson/PluginManager/installed.jelly b/core/src/main/resources/hudson/PluginManager/installed.jelly index 877fc30137..1cf0928d7a 100644 --- a/core/src/main/resources/hudson/PluginManager/installed.jelly +++ b/core/src/main/resources/hudson/PluginManager/installed.jelly @@ -67,7 +67,9 @@ THE SOFTWARE. - ${p.version} + + ${p.version} + diff --git a/core/src/main/resources/hudson/PluginWrapper/3rdPartyLicenses.jelly b/core/src/main/resources/hudson/PluginWrapper/3rdPartyLicenses.jelly new file mode 100644 index 0000000000..1c6e4fa397 --- /dev/null +++ b/core/src/main/resources/hudson/PluginWrapper/3rdPartyLicenses.jelly @@ -0,0 +1,44 @@ + + + + + + +

    ${%about(it.longName+' '+it.version)}

    + +

    ${%3rd Party Dependencies}

    + + + + + + +

    ${%No information recorded}

    +
    +
    +
    +
    +
    +
    diff --git a/core/src/main/resources/hudson/PluginWrapper/3rdPartyLicenses.properties b/core/src/main/resources/hudson/PluginWrapper/3rdPartyLicenses.properties new file mode 100644 index 0000000000..d01c4dc500 --- /dev/null +++ b/core/src/main/resources/hudson/PluginWrapper/3rdPartyLicenses.properties @@ -0,0 +1 @@ +about=About {0} \ No newline at end of file diff --git a/core/src/main/resources/hudson/model/Hudson/about.jelly b/core/src/main/resources/hudson/model/Hudson/about.jelly new file mode 100644 index 0000000000..4e374b7d16 --- /dev/null +++ b/core/src/main/resources/hudson/model/Hudson/about.jelly @@ -0,0 +1,43 @@ + + + + + + + +

    ${%about(it.VERSION)}

    +

    + ${%blurb} +

    + +

    + ${%dependencies} +

    + + + +
    +
    +
    diff --git a/core/src/main/resources/hudson/model/Hudson/about.properties b/core/src/main/resources/hudson/model/Hudson/about.properties new file mode 100644 index 0000000000..4f677ba18d --- /dev/null +++ b/core/src/main/resources/hudson/model/Hudson/about.properties @@ -0,0 +1,4 @@ +about=About Jenkins {0} +blurb=Jenkins is a community-developed open-source continuous integration server. + +dependencies=Jenkins depends on the following 3rd party libraries. \ No newline at end of file diff --git a/core/src/main/resources/lib/hudson/3rdPartyLicenses.jelly b/core/src/main/resources/lib/hudson/3rdPartyLicenses.jelly new file mode 100644 index 0000000000..4279924160 --- /dev/null +++ b/core/src/main/resources/lib/hudson/3rdPartyLicenses.jelly @@ -0,0 +1,57 @@ + + + + + + + + + + + + + +
    ${%Name}${%Maven ID}${%License}
    +
    + + + + ${attrs.name} + + + ${attrs.groupId}:${attrs.artifactId}:${attrs.version} + + + + + + + + + ${attrs.name}
    +
    +
    + +
    diff --git a/licenseCompleter.groovy b/licenseCompleter.groovy new file mode 100644 index 0000000000..252f005e1a --- /dev/null +++ b/licenseCompleter.groovy @@ -0,0 +1,92 @@ + +def apacheLicense = license("The Apache Software License, Version 2.0","http://www.apache.org/licenses/LICENSE-2.0.txt") +def cddl = license("CDDL","http://www.sun.com/cddl/") +def lgpl = license("LGPL 2.1","http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html") +def mitLicense = license("MIT License","http://www.opensource.org/licenses/mit-license.php") +def jenkinsLicense = license("MIT License","http://jenkins-ci.org/mit-license") + + +match("asm:*") { + rewriteLicense([], license("BSD License","http://asm.ow2.org/license.html")) +} + +// Apache components +// logkit is a part of Avalon +match(["org.apache.ant:*","commons-jelly:*","log4j:*","avalon-framework:*","logkit:logkit","oro:oro","org.jvnet.hudson:commons-jelly","org.jvnet.hudson:commons-jelly-tags-define","slide:slide-webdavlib"]) { + rewriteLicense([], apacheLicense) +} + +// GlassFish components are dual-licensed between CDDL and GPL+Classpath Exception +// we elect to take them under CDDL. +match(["javax.mail:*","org.jvnet.hudson:activation","org.jvnet:tiger-types","javax.servlet:jstl"]) { + rewriteLicense([], cddl) +} + +match("antlr:*") { + rewriteLicense([], license("BSD License","http://www.antlr.org/license.html")) +} + +match("jaxen:jaxen") { + rewriteLicense([], license("BSD License","http://jaxen.codehaus.org/license.html")) +} + +match("args4j:args4j") { + rewriteLicense([], mitLicense) +} + +match("*:dom4j") { + rewriteLicense([],license("BSD License","http://dom4j.sourceforge.net/dom4j-1.6.1/license.html")) +} + +match(["org.codehaus.groovy:*"]) { + // see http://groovy.codehaus.org/License+Information + // see http://jmdns.sourceforge.net/license.html + rewriteLicense([],apacheLicense) +} + +match("*:stapler-adjunct-timeline") { + rewriteLicense([],license("BSD License","http://simile.mit.edu/license.html")) +} + +match("*:txw2") { + // see http://java.net/projects/jaxb/sources/version2/content/trunk/txw2/license.txt?rev=3611 + rewriteLicense([],cddl) +} + +match(["org.kohsuke.jinterop:j-interop","org.kohsuke.jinterop:j-interopdeps"]) { + rewriteLicense([],license("LGPL v3","http://www.j-interop.org/license.html")) +} + +// these are our own modules that have license in the trunk but not in these released versions +// as we upgrade them, we should just pick up the license info from POM +match(["org.jenkins-ci.modules:instance-identity","org.jvnet.hudson:task-reactor","org.jvnet.hudson:annotation-indexer","*:jinterop-wmi","*:maven2.1-interceptor","*:hudson-maven-embedder"]) { + rewriteLicense([],jenkinsLicense) +} + +match("*:jna") { + rewriteLicense([],lgpl) +} + +match(["org.jvnet.localizer:localizer","*:trilead-putty-extension"]) { + // see http://java.net/projects/localizer + // see http://java.net/projects/trilead-putty-extension/ + rewriteLicense([],mitLicense); +} + +match("org.codehaus.plexus:plexus-interactivity-api") { + rewriteLicense([],mitLicense) +} + +match("de.zeigermann.xml:xml-im-exporter:1.1") { + rewriteLicense([],license("BSD License","http://xml-im-exporter.cvs.sourceforge.net/viewvc/xml-im-exporter/xml-im-exporter/Copying.txt?revision=1.3&view=markup")) +} + + + +// +// Choose from multi-licensed modules +//========================================================================== + +match("*:jna-posix") { + accept("GNU Lesser General Public License Version 2.1") +} diff --git a/maven-plugin/pom.xml b/maven-plugin/pom.xml index b597d8c4a8..ca0e8e5330 100644 --- a/maven-plugin/pom.xml +++ b/maven-plugin/pom.xml @@ -193,7 +193,7 @@ THE SOFTWARE. org.jenkins-ci.lib lib-jenkins-maven-artifact-manager - 1.1 + 1.2 commons-io @@ -288,13 +288,20 @@ THE SOFTWARE. generate - + Messages.properties target/generated-sources/localizer + + com.cloudbees + maven-license-plugin + + target/${project.artifactId}/WEB-INF/licenses.xml + + org.jvnet.maven-antrun-extended-plugin maven-antrun-extended-plugin diff --git a/pom.xml b/pom.xml index 1021d4667a..e5c85545b6 100644 --- a/pom.xml +++ b/pom.xml @@ -161,6 +161,23 @@ THE SOFTWARE. + + com.cloudbees + maven-license-plugin + 1.0 + + + + process + + compile + + true + ../licenseCompleter.groovy + + + + From 1419749eb6f999c22e061bfd6b9a60d3eba3f30d Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 15 Apr 2011 14:28:37 -0700 Subject: [PATCH 24/25] hooked up the 3rd party license ack to the UI --- core/src/main/java/hudson/AboutJenkins.java | 30 +++++++++++++++++++ .../about.jelly => AboutJenkins/index.jelly} | 6 ++-- .../index.properties} | 0 .../main/resources/hudson/Messages.properties | 2 ++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 core/src/main/java/hudson/AboutJenkins.java rename core/src/main/resources/hudson/{model/Hudson/about.jelly => AboutJenkins/index.jelly} (91%) rename core/src/main/resources/hudson/{model/Hudson/about.properties => AboutJenkins/index.properties} (100%) diff --git a/core/src/main/java/hudson/AboutJenkins.java b/core/src/main/java/hudson/AboutJenkins.java new file mode 100644 index 0000000000..e8136e1f5d --- /dev/null +++ b/core/src/main/java/hudson/AboutJenkins.java @@ -0,0 +1,30 @@ +package hudson; + +import hudson.model.ManagementLink; + +/** + * Show "About Jenkins" link. + * + * @author Kohsuke Kawaguchi + */ +@Extension +public class AboutJenkins extends ManagementLink { + @Override + public String getIconFileName() { + return "help.png"; + } + + @Override + public String getUrlName() { + return "about"; + } + + public String getDisplayName() { + return Messages.AboutJenkins_DisplayName(); + } + + @Override + public String getDescription() { + return Messages.AboutJenkins_Description(); + } +} diff --git a/core/src/main/resources/hudson/model/Hudson/about.jelly b/core/src/main/resources/hudson/AboutJenkins/index.jelly similarity index 91% rename from core/src/main/resources/hudson/model/Hudson/about.jelly rename to core/src/main/resources/hudson/AboutJenkins/index.jelly index 4e374b7d16..2e3fb75453 100644 --- a/core/src/main/resources/hudson/model/Hudson/about.jelly +++ b/core/src/main/resources/hudson/AboutJenkins/index.jelly @@ -24,10 +24,10 @@ THE SOFTWARE. - - + + -

    ${%about(it.VERSION)}

    +

    ${%about(app.VERSION)}

    ${%blurb}

    diff --git a/core/src/main/resources/hudson/model/Hudson/about.properties b/core/src/main/resources/hudson/AboutJenkins/index.properties similarity index 100% rename from core/src/main/resources/hudson/model/Hudson/about.properties rename to core/src/main/resources/hudson/AboutJenkins/index.properties diff --git a/core/src/main/resources/hudson/Messages.properties b/core/src/main/resources/hudson/Messages.properties index c0d3d797b5..c4edc3a6d9 100644 --- a/core/src/main/resources/hudson/Messages.properties +++ b/core/src/main/resources/hudson/Messages.properties @@ -50,3 +50,5 @@ Util.pastTime={0} FilePath.TildaDoesntWork=''~'' is only supported in a Unix shell and nowhere else. PluginManager.DisplayName=Plugin Manager +AboutJenkins.DisplayName=About Jenkins +AboutJenkins.Description=See the version and license information From ff1f60905e977503c2006278ed85264520c2b049 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 15 Apr 2011 14:55:12 -0700 Subject: [PATCH 25/25] integrated the license.xml generation process into plugin builds --- licenseCompleter.groovy | 189 +++++++++++++++++++++------------------- plugins/pom.xml | 44 ++++++++++ pom.xml | 4 +- 3 files changed, 146 insertions(+), 91 deletions(-) diff --git a/licenseCompleter.groovy b/licenseCompleter.groovy index 252f005e1a..1d2b550e23 100644 --- a/licenseCompleter.groovy +++ b/licenseCompleter.groovy @@ -1,92 +1,103 @@ - -def apacheLicense = license("The Apache Software License, Version 2.0","http://www.apache.org/licenses/LICENSE-2.0.txt") -def cddl = license("CDDL","http://www.sun.com/cddl/") -def lgpl = license("LGPL 2.1","http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html") -def mitLicense = license("MIT License","http://www.opensource.org/licenses/mit-license.php") -def jenkinsLicense = license("MIT License","http://jenkins-ci.org/mit-license") +/* + This script auguments the missing license information in our dependencies. +*/ +complete { + // license constants + def apacheLicense = license("The Apache Software License, Version 2.0","http://www.apache.org/licenses/LICENSE-2.0.txt") + def cddl = license("CDDL","http://www.sun.com/cddl/") + def lgpl = license("LGPL 2.1","http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html") + def mitLicense = license("MIT License","http://www.opensource.org/licenses/mit-license.php") + def jenkinsLicense = license("MIT License","http://jenkins-ci.org/mit-license") -match("asm:*") { - rewriteLicense([], license("BSD License","http://asm.ow2.org/license.html")) -} - -// Apache components -// logkit is a part of Avalon -match(["org.apache.ant:*","commons-jelly:*","log4j:*","avalon-framework:*","logkit:logkit","oro:oro","org.jvnet.hudson:commons-jelly","org.jvnet.hudson:commons-jelly-tags-define","slide:slide-webdavlib"]) { - rewriteLicense([], apacheLicense) -} - -// GlassFish components are dual-licensed between CDDL and GPL+Classpath Exception -// we elect to take them under CDDL. -match(["javax.mail:*","org.jvnet.hudson:activation","org.jvnet:tiger-types","javax.servlet:jstl"]) { - rewriteLicense([], cddl) -} - -match("antlr:*") { - rewriteLicense([], license("BSD License","http://www.antlr.org/license.html")) -} - -match("jaxen:jaxen") { - rewriteLicense([], license("BSD License","http://jaxen.codehaus.org/license.html")) -} - -match("args4j:args4j") { - rewriteLicense([], mitLicense) -} - -match("*:dom4j") { - rewriteLicense([],license("BSD License","http://dom4j.sourceforge.net/dom4j-1.6.1/license.html")) -} - -match(["org.codehaus.groovy:*"]) { - // see http://groovy.codehaus.org/License+Information - // see http://jmdns.sourceforge.net/license.html - rewriteLicense([],apacheLicense) -} - -match("*:stapler-adjunct-timeline") { - rewriteLicense([],license("BSD License","http://simile.mit.edu/license.html")) -} - -match("*:txw2") { - // see http://java.net/projects/jaxb/sources/version2/content/trunk/txw2/license.txt?rev=3611 - rewriteLicense([],cddl) -} - -match(["org.kohsuke.jinterop:j-interop","org.kohsuke.jinterop:j-interopdeps"]) { - rewriteLicense([],license("LGPL v3","http://www.j-interop.org/license.html")) -} - -// these are our own modules that have license in the trunk but not in these released versions -// as we upgrade them, we should just pick up the license info from POM -match(["org.jenkins-ci.modules:instance-identity","org.jvnet.hudson:task-reactor","org.jvnet.hudson:annotation-indexer","*:jinterop-wmi","*:maven2.1-interceptor","*:hudson-maven-embedder"]) { - rewriteLicense([],jenkinsLicense) -} - -match("*:jna") { - rewriteLicense([],lgpl) -} - -match(["org.jvnet.localizer:localizer","*:trilead-putty-extension"]) { - // see http://java.net/projects/localizer - // see http://java.net/projects/trilead-putty-extension/ - rewriteLicense([],mitLicense); -} - -match("org.codehaus.plexus:plexus-interactivity-api") { - rewriteLicense([],mitLicense) -} - -match("de.zeigermann.xml:xml-im-exporter:1.1") { - rewriteLicense([],license("BSD License","http://xml-im-exporter.cvs.sourceforge.net/viewvc/xml-im-exporter/xml-im-exporter/Copying.txt?revision=1.3&view=markup")) -} - - - -// -// Choose from multi-licensed modules -//========================================================================== - -match("*:jna-posix") { - accept("GNU Lesser General Public License Version 2.1") + match("asm:*") { + rewriteLicense([], license("BSD License","http://asm.ow2.org/license.html")) + } + + // Apache components + // logkit is a part of Avalon + match(["org.apache.ant:*","commons-jelly:*","log4j:*","avalon-framework:*","logkit:logkit","oro:oro","org.jvnet.hudson:commons-jelly","org.jvnet.hudson:commons-jelly-tags-define","slide:slide-webdavlib"]) { + rewriteLicense([], apacheLicense) + } + + // GlassFish components are dual-licensed between CDDL and GPL+Classpath Exception + // we elect to take them under CDDL. + match(["javax.mail:*","org.jvnet.hudson:activation","org.jvnet:tiger-types","javax.servlet:jstl"]) { + rewriteLicense([], cddl) + } + + match("antlr:*") { + rewriteLicense([], license("BSD License","http://www.antlr.org/license.html")) + } + + match("jaxen:jaxen") { + rewriteLicense([], license("BSD License","http://jaxen.codehaus.org/license.html")) + } + + match("args4j:args4j") { + rewriteLicense([], mitLicense) + } + + match("*:dom4j") { + rewriteLicense([],license("BSD License","http://dom4j.sourceforge.net/dom4j-1.6.1/license.html")) + } + + match(["org.codehaus.groovy:*"]) { + // see http://groovy.codehaus.org/License+Information + // see http://jmdns.sourceforge.net/license.html + rewriteLicense([],apacheLicense) + } + + match("*:stapler-adjunct-timeline") { + rewriteLicense([],license("BSD License","http://simile.mit.edu/license.html")) + } + + match("*:txw2") { + // see http://java.net/projects/jaxb/sources/version2/content/trunk/txw2/license.txt?rev=3611 + rewriteLicense([],cddl) + } + + match(["org.kohsuke.jinterop:j-interop","org.kohsuke.jinterop:j-interopdeps"]) { + rewriteLicense([],license("LGPL v3","http://www.j-interop.org/license.html")) + } + + // these are our own modules that have license in the trunk but not in these released versions + // as we upgrade them, we should just pick up the license info from POM + match(["org.jenkins-ci.modules:instance-identity","org.jvnet.hudson:task-reactor","org.jvnet.hudson:annotation-indexer","*:jinterop-wmi","*:maven2.1-interceptor","*:hudson-maven-embedder"]) { + rewriteLicense([],jenkinsLicense) + } + + match("*:jna") { + rewriteLicense([],lgpl) + } + + match(["org.jvnet.localizer:localizer","*:trilead-putty-extension"]) { + // see http://java.net/projects/localizer + // see http://java.net/projects/trilead-putty-extension/ + rewriteLicense([],mitLicense); + } + + match("org.codehaus.plexus:plexus-interactivity-api") { + rewriteLicense([],mitLicense) + } + + match("de.zeigermann.xml:xml-im-exporter:1.1") { + rewriteLicense([],license("BSD License","http://xml-im-exporter.cvs.sourceforge.net/viewvc/xml-im-exporter/xml-im-exporter/Copying.txt?revision=1.3&view=markup")) + } + + match("*:sezpoz") { + // GPL-phobia people react to "GPL" strongly, so accept sezpoz under CDDL + rewriteLicense([license("CDDL or GPL 2 with Classpath Exception",null)],cddl); + } + + + + + // + // Choose from multi-licensed modules + //========================================================================== + + match("*:jna-posix") { + accept("GNU Lesser General Public License Version 2.1") + } } diff --git a/plugins/pom.xml b/plugins/pom.xml index 03c8f1dec0..7c2e351cf4 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -192,6 +192,50 @@ + + com.cloudbees + maven-license-plugin + 1.1 + + + + process + + compile + + + target/${project.artifactId}/WEB-INF/licenses.xml + + if (e.value.packaging=="hpi") + plugins.add(e.key.id) + } + + // filter out dependencies that don't belong to this plugin + models.entrySet().removeAll(models.entrySet().findAll { e -> + def a = e.key; + + if (a.dependencyTrail.size()>0 && plugins.contains(a.dependencyTrail[1])) + return true; // ignore transitive dependencies through other plugins + + // if the dependency goes through jenkins core, we don't need to bundle it in the war + // because jenkins-core comes in the scope, I think this is a bug in Maven that it puts such + // dependencies into the artifact list. + if (a.dependencyTrail.find { trail -> trail.contains(":hudson-core:") || trail.contains(":jenkins-core:") }) + return true; + + return false; + }) + } + ]]> + + + + diff --git a/pom.xml b/pom.xml index e5c85545b6..5c92c50147 100644 --- a/pom.xml +++ b/pom.xml @@ -164,7 +164,7 @@ THE SOFTWARE. com.cloudbees maven-license-plugin - 1.0 + 1.1 @@ -173,7 +173,7 @@ THE SOFTWARE. compile true - ../licenseCompleter.groovy +