org.apache.maven.plugins.annotations.Mojo Java Examples

The following examples show how to use org.apache.maven.plugins.annotations.Mojo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MojoDescriptorGleaner.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
private Set<TypeElement> getAnnotatedTypes(RoundEnvironment roundEnv) {
  Set<TypeElement> types = new HashSet<>();
  roundEnv.getElementsAnnotatedWith(Mojo.class).forEach(type -> types.add((TypeElement) type));
  addAnnotatedMembers(types, roundEnv, Parameter.class);
  addAnnotatedMembers(types, roundEnv, Component.class);
  return types;
}
 
Example #2
Source File: MojoDescriptorGleaner.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Set<String> getSupportedAnnotationTypes() {
  Set<String> types = new HashSet<>();
  types.add(Mojo.class.getName());
  types.add(Parameter.class.getName());
  types.add(Component.class.getName());
  return types;
}
 
Example #3
Source File: MojoDescriptorGleaner.java    From takari-lifecycle with Eclipse Public License 1.0 4 votes vote down vote up
MojoDescriptor processType(TypeElement type) {
  MojoDescriptor descriptor = new MojoDescriptor();

  descriptor.setImplementation(type.getQualifiedName().toString());
  descriptor.setSuperclasses(getSuperclasses(type, new ArrayList<String>()));

  Mojo mojo = type.getAnnotation(Mojo.class);
  if (mojo != null) {
    // mojo is null for classes that have @Parameter/@Component element annotations

    descriptor.setLanguage("java");
    descriptor.setGoal(mojo.name());
    descriptor.setExecutionStrategy(mojo.executionStrategy());
    descriptor.setRequiresProject(mojo.requiresProject());
    descriptor.setRequiresReports(mojo.requiresReports());
    descriptor.setAggregator(mojo.aggregator());
    descriptor.setRequiresDirectInvocation(mojo.requiresDirectInvocation());
    descriptor.setRequiresOnline(mojo.requiresOnline());
    descriptor.setInheritedByDefault(mojo.inheritByDefault());
    if (!isEmpty(mojo.configurator())) {
      descriptor.setConfigurator(mojo.configurator());
    }
    descriptor.setThreadSafe(mojo.threadSafe());
    descriptor.setPhase(mojo.defaultPhase().id());
    descriptor.setRequiresDependencyResolution(mojo.requiresDependencyResolution().id());
    descriptor.setRequiresDependencyCollection(mojo.requiresDependencyCollection().id());
    descriptor.setInstantiationStrategy(mojo.instantiationStrategy().id());

    if (getElementUtils().isDeprecated(type)) {
      descriptor.setDeprecated("No reason given"); // TODO parse javadoc
    }
    // This is not ideal
    // the proper way would be to add support for processorPath to compiler plugin
    // which would allow us to do this as part of takari-builder annotation processing
    // without adding takari-builder-apt to the compile classpath
    // we intend to do this properly... soon
    if (isTakariBuilderMojo(type)) {
      descriptor.setTakariBuilder(true);
    }
    descriptor.setDescription(getDescription(type));
  }

  processTypeFields(type, descriptor);

  Sorting.sortParameters(descriptor.getParameters());
  Sorting.sortRequirements(descriptor.getRequirements());

  return descriptor;
}