Plugin Development

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Plugin Development

Thomas Hart
Hi @all,

i try to write my first hudson (version 1.159) plugin. But i can't get
it run. Maybe someone can give me a hint, whats wrong.
The only log statement i see is "start MyPublisher" from the
PluginImpl#start Method. The Method MyPublisher#perform is never called,
when a build ends.

Thanks,
Thomas

Here the code:
public class PluginImpl extends Plugin {
     private final static Logger LOG =
Logger.getLogger(PluginImpl.class.getName());
     public void start() throws Exception {
         LOG.info("start MyPublisher"); //$NON-NLS-1$
         BuildStep.PUBLISHERS.addNotifier(MyPublisher.DESCRIPTOR);
     }
}

public class MyPublisher extends Publisher {
     private final static Logger LOG = Logger.getLogger(MyPublisher.class
         .getName());

     public boolean perform(Build build, Launcher launcher,
         BuildListener listener) throws InterruptedException, IOException {
     LOG.info("perform> ");

     return true;
     }

     public DescriptorImpl getDescriptor() {
     LOG.info("getDescriptor> ");
     new Exception().printStackTrace();

     return DESCRIPTOR;
     }

     public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();

     public static final class DescriptorImpl extends
         BuildStepDescriptor<Publisher> {
     private DescriptorImpl() {
         super(MyPublisher.class);
     }

     public String getDisplayName() {
         return "MyPublisher";
     }

     public String getHelpFile() {
         return "/help.html";
     }

     public Publisher newInstance(StaplerRequest req, JSONObject formData)
         throws FormException {
         LOG.info("newInstance> ");
         return new MyPublisher();
     }

     @Override
     public boolean isApplicable(Class<? extends AbstractProject> arg0) {
         LOG.info("isApplicable> arg: " + arg0);
         return true;
     }
     }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Plugin Development

Kohsuke Kawaguchi
Administrator
Thomas Hart wrote:
> Hi @all,
>
> i try to write my first hudson (version 1.159) plugin. But i can't get
> it run. Maybe someone can give me a hint, whats wrong.
> The only log statement i see is "start MyPublisher" from the
> PluginImpl#start Method. The Method MyPublisher#perform is never called,
> when a build ends.

Are you configuring your job on Hudson to use your publisher?


>
> Thanks,
> Thomas
>
> Here the code:
> public class PluginImpl extends Plugin {
>      private final static Logger LOG =
> Logger.getLogger(PluginImpl.class.getName());
>      public void start() throws Exception {
>          LOG.info("start MyPublisher"); //$NON-NLS-1$
>          BuildStep.PUBLISHERS.addNotifier(MyPublisher.DESCRIPTOR);
>      }
> }
>
> public class MyPublisher extends Publisher {
>      private final static Logger LOG = Logger.getLogger(MyPublisher.class
>          .getName());
>
>      public boolean perform(Build build, Launcher launcher,
>          BuildListener listener) throws InterruptedException, IOException {
>      LOG.info("perform> ");
>
>      return true;
>      }
>
>      public DescriptorImpl getDescriptor() {
>      LOG.info("getDescriptor> ");
>      new Exception().printStackTrace();
>
>      return DESCRIPTOR;
>      }
>
>      public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
>
>      public static final class DescriptorImpl extends
>          BuildStepDescriptor<Publisher> {
>      private DescriptorImpl() {
>          super(MyPublisher.class);
>      }
>
>      public String getDisplayName() {
>          return "MyPublisher";
>      }
>
>      public String getHelpFile() {
>          return "/help.html";
>      }
>
>      public Publisher newInstance(StaplerRequest req, JSONObject formData)
>          throws FormException {
>          LOG.info("newInstance> ");
>          return new MyPublisher();
>      }
>
>      @Override
>      public boolean isApplicable(Class<? extends AbstractProject> arg0) {
>          LOG.info("isApplicable> arg: " + arg0);
>          return true;
>      }
>      }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

--
Kohsuke Kawaguchi
Sun Microsystems                   [hidden email]

smime.p7s (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Plugin Development

Thomas Hart
Kohsuke Kawaguchi schrieb:
> Thomas Hart wrote:
>> Hi @all,
>>
>> i try to write my first hudson (version 1.159) plugin. But i can't
>> get it run. Maybe someone can give me a hint, whats wrong.
>> The only log statement i see is "start MyPublisher" from the
>> PluginImpl#start Method. The Method MyPublisher#perform is never
>> called, when a build ends.
> Are you configuring your job on Hudson to use your publisher?
In the Job Config isn't the Checkbox for MyPublisher. But i looked in
the Jira plugin source code and found that for maven projects a
MavenReporters.LIST exist:
BuildStep.PUBLISHERS.addNotifier(MyPublisher.DESCRIPTOR);
MavenReporters.LIST.add(MyMavenReporter.DescriptorImpl.DESCRIPTOR);
Is there a different between maven jobs and other jobs?

Thanks,
Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Plugin Development

Kohsuke Kawaguchi
Administrator
Thomas Hart wrote:

> Kohsuke Kawaguchi schrieb:
>> Thomas Hart wrote:
>>> Hi @all,
>>>
>>> i try to write my first hudson (version 1.159) plugin. But i can't
>>> get it run. Maybe someone can give me a hint, whats wrong.
>>> The only log statement i see is "start MyPublisher" from the
>>> PluginImpl#start Method. The Method MyPublisher#perform is never
>>> called, when a build ends.
>> Are you configuring your job on Hudson to use your publisher?
> In the Job Config isn't the Checkbox for MyPublisher. But i looked in
> the Jira plugin source code and found that for maven projects a
> MavenReporters.LIST exist:
> BuildStep.PUBLISHERS.addNotifier(MyPublisher.DESCRIPTOR);
> MavenReporters.LIST.add(MyMavenReporter.DescriptorImpl.DESCRIPTOR);
> Is there a different between maven jobs and other jobs?
Yeah, unfortunately two job types use different extension points.

I'm trying to reconcile this so that you can also use Publisher for
Maven job types, too, but that's not completed yet.


--
Kohsuke Kawaguchi
Sun Microsystems                   [hidden email]

smime.p7s (4K) Download Attachment