-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
374 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
maven-core/src/main/java/org/apache/maven/lifecycle/internal/PhaseComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.maven.lifecycle.internal; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
/** | ||
* Compares phases within the context of a specific lifecycle with secondary sorting based on the {@link PhaseId}. | ||
*/ | ||
public class PhaseComparator implements Comparator<String> { | ||
/** | ||
* The lifecycle phase ordering. | ||
*/ | ||
private final List<String> lifecyclePhases; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param lifecyclePhases the lifecycle phase ordering. | ||
*/ | ||
public PhaseComparator(List<String> lifecyclePhases) { | ||
this.lifecyclePhases = lifecyclePhases; | ||
} | ||
|
||
@Override | ||
public int compare(String o1, String o2) { | ||
PhaseId p1 = PhaseId.of(o1); | ||
PhaseId p2 = PhaseId.of(o2); | ||
int i1 = lifecyclePhases.indexOf(p1.phase()); | ||
int i2 = lifecyclePhases.indexOf(p2.phase()); | ||
if (i1 == -1 && i2 == -1) { | ||
// unknown phases, leave in existing order | ||
return 0; | ||
} | ||
if (i1 == -1) { | ||
// second one is known, so it comes first | ||
return 1; | ||
} | ||
if (i2 == -1) { | ||
// first one is known, so it comes first | ||
return -1; | ||
} | ||
int rv = Integer.compare(i1, i2); | ||
if (rv != 0) { | ||
return rv; | ||
} | ||
// same phase, now compare execution points | ||
i1 = p1.executionPoint().ordinal(); | ||
i2 = p2.executionPoint().ordinal(); | ||
rv = Integer.compare(i1, i2); | ||
if (rv != 0) { | ||
return rv; | ||
} | ||
// same execution point, now compare priorities (highest wins, so invert) | ||
return -Integer.compare(p1.priority(), p2.priority()); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
maven-core/src/main/java/org/apache/maven/lifecycle/internal/PhaseExecutionPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.maven.lifecycle.internal; | ||
|
||
/** | ||
* Represents where a dynamic phase should be executed within a static phase. | ||
*/ | ||
public enum PhaseExecutionPoint { | ||
/** | ||
* Execution must occur before any executions of the phase proper. Failure of any {@link #BEFORE} dynamic phase | ||
* execution will prevent the {@link #AS} phase but will not prevent any {@link #AFTER} dynamic phases. | ||
*/ | ||
BEFORE("before:"), | ||
/** | ||
* Execution is the execution of the phase proper. Failure of any {@link #AS} dynamic phase execution will fail | ||
* the phase. Any {@link #AFTER} phases will still be execution. | ||
*/ | ||
AS(""), | ||
/** | ||
* Guaranteed execution dynamic phases on completion of the static phase. All {@link #AFTER} dynamic phases will | ||
* be executed provided at least one {@link #BEFORE} or {@link #AS} dynamic phase has started execution. | ||
*/ | ||
AFTER("after:"); | ||
|
||
private final String prefix; | ||
|
||
PhaseExecutionPoint(String prefix) { | ||
this.prefix = prefix; | ||
} | ||
|
||
public String prefix() { | ||
return prefix; | ||
} | ||
} |
Oops, something went wrong.