001package org.apache.maven.lifecycle.internal; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.maven.plugin.MojoExecution; 023import org.apache.maven.project.MavenProject; 024 025/** 026 * @since 3.0 027 * @author Benjamin Bentmann 028 * @author Kristian Rosenvold 029 * <p/> 030 * NOTE: This class is not part of any public api and can be changed or deleted without prior notice. 031 */ 032public class PhaseRecorder 033{ 034 private String lastLifecyclePhase; 035 036 private final MavenProject project; 037 038 public PhaseRecorder( MavenProject project ) 039 { 040 this.project = project; 041 } 042 043 public void observeExecution( MojoExecution mojoExecution ) 044 { 045 String lifecyclePhase = mojoExecution.getLifecyclePhase(); 046 047 if ( lifecyclePhase != null ) 048 { 049 if ( lastLifecyclePhase == null ) 050 { 051 lastLifecyclePhase = lifecyclePhase; 052 } 053 else if ( !lifecyclePhase.equals( lastLifecyclePhase ) ) 054 { 055 project.addLifecyclePhase( lastLifecyclePhase ); 056 lastLifecyclePhase = lifecyclePhase; 057 } 058 } 059 060 if ( lastLifecyclePhase != null ) 061 { 062 project.addLifecyclePhase( lastLifecyclePhase ); 063 } 064 } 065 066 public boolean isDifferentPhase( MojoExecution nextMojoExecution ) 067 { 068 String lifecyclePhase = nextMojoExecution.getLifecyclePhase(); 069 if ( lifecyclePhase == null ) 070 { 071 return lastLifecyclePhase != null; 072 } 073 return !lifecyclePhase.equals( lastLifecyclePhase ); 074 075 } 076 077 078}