All Downloads are FREE. Search and download functionalities are using the official Maven repository.

t3.plugin.annotations.replacement.HandleMojoReplacement Maven / Gradle / Ivy

The newest version!
/**
 * (C) Copyright 2016-2019 teecube
 * (https://teecu.be) and others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package t3.plugin.annotations.replacement;

import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import lombok.core.AnnotationValues;
import lombok.core.HandlerPriority;
import lombok.javac.JavacAnnotationHandler;
import lombok.javac.JavacNode;
import org.kohsuke.MetaInfServices;
import t3.plugin.annotations.Mojo;

import java.util.ArrayList;
import java.util.List;

/**
 * 

* This class will add a {@link org.apache.maven.plugins.annotations.Mojo} * annotation wherever a {@link t3.plugin.annotations.Mojo} is found.
*
* The annotation created is a duplicate.
*
* It allows to have both annotations: one is the standard Maven one (used by * Maven core and to generate Maven site for instance), the other is a copy with * a RUNTIME retention policy. *

* *

* This class will also add a call to "super.initStandalonePOM()" method at the * beginning of "execute()" method of the Mojo. *

* * @author Mathieu Debove <[email protected]> * */ @MetaInfServices(JavacAnnotationHandler.class) @HandlerPriority(1024) public class HandleMojoReplacement extends JavacAnnotationHandler { public String getAnnotationCanonicalName() { return Mojo.class.getCanonicalName(); } public List getReplacementClassElements() { List result = new ArrayList(); result.add("org"); result.add("apache"); result.add("maven"); result.add("plugins"); result.add("annotations"); result.add("Mojo"); return result; } @Override public void handle(final AnnotationValues annotation, final JCAnnotation ast, final JavacNode annotationNode) { // no inheritance possible // add "t3.plugin.annotations.Mojo" where "org.apache.maven.plugins.annotations.Mojo" is found AnnotationReplacementHelper.duplicateAnnotationWithAnother(annotation, ast, annotationNode, getAnnotationCanonicalName(), getReplacementClassElements(), new ArrayList()); // let's add a call to "super.initStandalonePOM" at the beginning of // "execute()" method of the Mojo List methodToAddName = new ArrayList(); methodToAddName.add("super"); methodToAddName.add("initStandalonePOM"); AnnotationReplacementHelper.addMethodCallInMethodBody(annotation, ast, annotationNode, "execute", methodToAddName, true); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy