001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.tools.plugin.extractor.annotations.datamodel;
020
021import java.lang.annotation.Annotation;
022import java.util.Objects;
023
024import org.apache.maven.plugins.annotations.Execute;
025import org.apache.maven.plugins.annotations.LifecyclePhase;
026
027/**
028 * @author Olivier Lamy
029 * @since 3.0
030 */
031public class ExecuteAnnotationContent implements Execute {
032    private String goal;
033
034    private String lifecycle;
035
036    private LifecyclePhase phase;
037
038    private String customPhase;
039
040    @Override
041    public LifecyclePhase phase() {
042        return this.phase;
043    }
044
045    @Override
046    public String customPhase() {
047        return customPhase;
048    }
049
050    @Override
051    public String goal() {
052        return this.goal;
053    }
054
055    @Override
056    public String lifecycle() {
057        return this.lifecycle;
058    }
059
060    public void phase(String phase) {
061        if (phase != null && !phase.isEmpty()) {
062            for (LifecyclePhase p : LifecyclePhase.values()) {
063                if (Objects.equals(phase, p.id()) || Objects.equals(phase, p.name())) {
064                    this.phase = p;
065                    this.customPhase = null;
066                    return;
067                }
068            }
069            this.phase = null;
070            this.customPhase = phase;
071        } else {
072            this.phase = null;
073            this.customPhase = null;
074        }
075        this.phase = LifecyclePhase.valueOf(phase);
076    }
077
078    public void customPhase(String customPhase) {
079        this.customPhase = customPhase;
080    }
081
082    public void goal(String goal) {
083        this.goal = goal;
084    }
085
086    public void lifecycle(String lifecycle) {
087        this.lifecycle = lifecycle;
088    }
089
090    @Override
091    public Class<? extends Annotation> annotationType() {
092        return null;
093    }
094
095    @Override
096    public String toString() {
097        final StringBuilder sb = new StringBuilder();
098        sb.append("ExecuteAnnotationContent");
099        sb.append("{goal='").append(goal).append('\'');
100        sb.append(", lifecycle='").append(lifecycle).append('\'');
101        sb.append(", phase=").append(phase);
102        sb.append(", customPhase=").append(customPhase);
103        sb.append('}');
104        return sb.toString();
105    }
106}