Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-60290

Maven Archetypes "Hello World Plugin" Generates Broken Code

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • archetypes
    • None

      When generating a "Hello World" plugin using the maven archetypes the CLI generates broken code. On a line 60 an undeclared symbol is referenced, `Messages` (also on line 62, 64 and 76). Combined with the lack of useful documentation around Jenkins and its ecosystem this lead to a lot of wasted time for me the other day. 

      Corrected code:

      @Extension
      public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
      
          public FormValidation doCheckName(@QueryParameter String value, @QueryParameter boolean useFrench)
                  throws IOException, ServletException {
              ResourceBundle messages = ResourceBundle.getBundle("HelloWorldBuilder.Messages");
              if (value.length() == 0)
                  return FormValidation.error(messages.getString("HelloWorldBuilder.DescriptorImpl.errors.missingName"));
              if (value.length() < 4)
                  return FormValidation.warning(messages.getString("HelloWorldBuilder.DescriptorImpl.warnings.tooShort"));
              if (!useFrench && value.matches(".*[éáàç].*")) {
                  return FormValidation.warning(messages.getString("HelloWorldBuilder.DescriptorImpl.warnings.reallyFrench"));
              }
              return FormValidation.ok();
          }
      
          @Override
          public boolean isApplicable(Class<? extends AbstractProject> aClass) {
              return true;
          }
      
          @Override
          public String getDisplayName() {
              ResourceBundle nessages = ResourceBundle.getBundle("HelloWorldBuilder.Messages");
              return nessages.getString("HelloWorldBuilder.DescriptorImpl.DisplayName");
          }
      
      }
      

            Unassigned Unassigned
            kylie_a Kylie Auld
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: