4 Replies Latest reply on Nov 7, 2016 9:16 AM by Mylos Kathos

    Developing a simple Add-on

    Mylos Kathos Master

      Hi all,

      I'd like to develop a basic add-on which will let me customize my web application web.xml by including automatically security constraints, taken from user input. So far I've found an example which adds libraries to your pom.xml through the DependencyInstaller and DependencyResolver.

       

      public class HelloWorldUICommand extends AbstractProjectCommand {
          
          @Inject ProjectFactory projectFactory;
      
          @Inject @WithAttributes(label = "Name", required = true, description = "Enter your name")  
          UIInput<String> input;
          
          @Inject DependencyInstaller dependencyInstaller;
      
          @Inject DependencyResolver dependencyResolver;    
          
          @Inject @WithAttributes(label = "Version", required = true, description = "Select the version of PicketLink") 
          private UISelectOne<Coordinate> version;    
          
          @Override
          public void initializeUI(UIBuilder builder) throws Exception {
              builder.add(input);
              
              DependencyQuery query = DependencyQueryBuilder
                      .create("org.picketlink:picketlink-api")
                      .setFilter(new NonSnapshotDependencyFilter());
      
              List<Coordinate> coordinates = dependencyResolver.resolveVersions(query);
              version.setValueChoices(coordinates);
              builder.add(version);        
          }
      
          @Override
          public Result execute(UIExecutionContext context) throws Exception {
              DependencyBuilder builder = DependencyBuilder.create();
              builder.setCoordinate(version.getValue());
      
              dependencyInstaller.install(getSelectedProject(context), builder);
              
              return Results.success("Hello World");
          }
      
          @Override
          protected boolean isProjectRequired() {
              return true;
          }
      
          @Override
          protected ProjectFactory getProjectFactory() {
              return projectFactory;
          }
      }
      

      I wonder if there is also a specific class to modify a web project's XML files, or any other way to customize it from the add-on.

      Many thanks

      Mylos