-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a :report goal to generate plugin executions list in HTML
It will be added to Project Reports in Maven site. Fixes #76
- Loading branch information
Showing
10 changed files
with
409 additions
and
3 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
157 changes: 157 additions & 0 deletions
157
src/main/java/org/codehaus/mojo/buildplan/ListReportMojo.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,157 @@ | ||
/* | ||
* Copyright (C) 2012 Jean-Christophe Gay ([email protected]) | ||
* | ||
* 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 org.codehaus.mojo.buildplan; | ||
|
||
|
||
import static org.codehaus.mojo.buildplan.display.TableColumn.ARTIFACT_ID; | ||
import static org.codehaus.mojo.buildplan.display.TableColumn.GOAL; | ||
import static org.codehaus.mojo.buildplan.display.TableColumn.LIFECYCLE; | ||
import static org.codehaus.mojo.buildplan.display.TableColumn.PHASE; | ||
|
||
import java.util.Locale; | ||
import org.apache.maven.doxia.sink.Sink; | ||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.lifecycle.DefaultLifecycles; | ||
import org.apache.maven.lifecycle.LifecycleExecutor; | ||
import org.apache.maven.lifecycle.MavenExecutionPlan; | ||
import org.apache.maven.plugin.MojoExecution; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugin.logging.Log; | ||
import org.apache.maven.plugins.annotations.Component; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.reporting.AbstractMavenReport; | ||
import org.apache.maven.reporting.MavenReportException; | ||
import org.codehaus.mojo.buildplan.display.MojoExecutionDisplay; | ||
import org.codehaus.mojo.buildplan.display.TableColumn; | ||
|
||
/** | ||
* Report plugin executions for the current project. | ||
*/ | ||
@Mojo(name = "report", | ||
defaultPhase = LifecyclePhase.SITE) | ||
public class ListReportMojo extends AbstractMavenReport { | ||
|
||
@Component | ||
private LifecycleExecutor lifecycleExecutor; | ||
|
||
@Component(role = DefaultLifecycles.class) | ||
DefaultLifecycles defaultLifecycles; | ||
|
||
@Parameter(defaultValue = "${session}", readonly = true) | ||
private MavenSession session; | ||
|
||
@Override | ||
protected void executeReport(Locale locale) throws MavenReportException { | ||
|
||
MavenExecutionPlan plan; | ||
try { | ||
plan = calculateExecutionPlan(); | ||
} catch (MojoFailureException e) { | ||
throw new MavenReportException("Cannot calculate execution plan...", e); | ||
} | ||
|
||
Log logger = getLog(); | ||
logger.info("Generating " + getOutputName() + ".html" | ||
+ " for " + project.getName() + " " + project.getVersion()); | ||
|
||
// Get the Maven Doxia Sink, which will be used to generate the | ||
// various elements of the document | ||
Sink mainSink = getSink(); | ||
if (mainSink == null) { | ||
throw new MavenReportException("Could not get the Doxia sink"); | ||
} | ||
|
||
// Page title | ||
mainSink.head(); | ||
mainSink.title(); | ||
mainSink.text("Build Plan for " + project.getName() + " " + project.getVersion()); | ||
mainSink.title_(); | ||
mainSink.head_(); | ||
|
||
mainSink.body(); | ||
|
||
mainSink.header(); | ||
mainSink.rawText("<h1 id=\"titleContent\">" + getDescription(locale) + "</h1>"); | ||
mainSink.header_(); | ||
|
||
mainSink.table(); | ||
|
||
mainSink.tableRow(); | ||
tableHead(mainSink, LIFECYCLE); | ||
tableHead(mainSink, PHASE); | ||
tableHead(mainSink, ARTIFACT_ID); | ||
tableHead(mainSink, GOAL); | ||
tableHead(mainSink, ARTIFACT_ID); | ||
mainSink.tableRow_(); | ||
|
||
for (MojoExecution execution : plan.getMojoExecutions()) { | ||
MojoExecutionDisplay display = new MojoExecutionDisplay(execution); | ||
mainSink.tableRow(); | ||
tableCell(mainSink, display.getLifecycle(defaultLifecycles)); | ||
tableCell(mainSink, display.getPhase()); | ||
tableCell(mainSink, display.getArtifactId()); | ||
tableCell(mainSink, display.getGoal()); | ||
tableCell(mainSink, display.getExecutionId()); | ||
mainSink.tableRow_(); | ||
} | ||
|
||
mainSink.table_(); | ||
|
||
mainSink.body_(); | ||
} | ||
|
||
private void tableCell(Sink mainSink, String content) { | ||
mainSink.tableCell(); | ||
mainSink.text(content); | ||
mainSink.tableCell_(); | ||
} | ||
|
||
private void tableHead(Sink mainSink, TableColumn lifecycle) { | ||
mainSink.tableHeaderCell(); | ||
mainSink.text(lifecycle.title()); | ||
mainSink.tableHeaderCell_(); | ||
} | ||
|
||
@Override | ||
public String getOutputName() { | ||
return "buildplan-report"; | ||
} | ||
|
||
@Override | ||
public String getName(Locale locale) { | ||
return "Build Plan"; | ||
} | ||
|
||
@Override | ||
public String getDescription(Locale locale) { | ||
return "List plugin executions for " + currentProject(); | ||
} | ||
|
||
private String currentProject() { | ||
return session.getCurrentProject().getGroupId() + ":" + session.getCurrentProject() | ||
.getArtifactId(); | ||
} | ||
|
||
protected MavenExecutionPlan calculateExecutionPlan() throws MojoFailureException { | ||
try { | ||
return lifecycleExecutor.calculateExecutionPlan(session, "deploy"); | ||
} catch (Exception e) { | ||
throw new MojoFailureException(String.format("Cannot calculate Maven execution plan, caused by: %s", e.getMessage()), e); | ||
} | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions
92
src/test/java/org/codehaus/mojo/buildplan/ListReportIT.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,92 @@ | ||
/* | ||
* Copyright (C) 2012 Jean-Christophe Gay ([email protected]) | ||
* | ||
* 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 org.codehaus.mojo.buildplan; | ||
|
||
import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat; | ||
|
||
import com.soebes.itf.jupiter.extension.MavenGoal; | ||
import com.soebes.itf.jupiter.extension.MavenJupiterExtension; | ||
import com.soebes.itf.jupiter.extension.MavenTest; | ||
import com.soebes.itf.jupiter.maven.MavenExecutionResult; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
|
||
@MavenJupiterExtension | ||
class ListReportIT { | ||
|
||
@MavenTest | ||
@MavenGoal("site") | ||
void generate_report_for_multimodule_project(MavenExecutionResult result) { | ||
assertThat(result).isSuccessful() | ||
.project() | ||
.withFile("site/buildplan-report.html") | ||
.content() | ||
.satisfies(html -> { | ||
Document document = Jsoup.parse(html); | ||
assertThat(document.title()).isEqualTo("list-multimodule – Build Plan for list-multimodule 1.0-SNAPSHOT"); | ||
assertThat(document.select("#titleContent").text()).isEqualTo("List plugin executions for org.codehaus.mojo.buildplan:list-multimodule"); | ||
assertThat(document.select("table.bodyTable").outerHtml()).isEqualTo("<table border=\"0\" class=\"bodyTable\">\n" | ||
+ " <tbody>\n" | ||
+ " <tr class=\"a\">\n" | ||
+ " <th>LIFECYCLE</th>\n" | ||
+ " <th>PHASE</th>\n" | ||
+ " <th>PLUGIN</th>\n" | ||
+ " <th>GOAL</th>\n" | ||
+ " <th>PLUGIN</th>\n" | ||
+ " </tr>\n" | ||
+ " <tr class=\"b\">\n" | ||
+ " <td>default</td>\n" | ||
+ " <td>install</td>\n" | ||
+ " <td>maven-install-plugin</td>\n" | ||
+ " <td>install</td>\n" | ||
+ " <td>default-install</td>\n" | ||
+ " </tr>\n" | ||
+ " <tr class=\"a\">\n" | ||
+ " <td>default</td>\n" | ||
+ " <td>deploy</td>\n" | ||
+ " <td>maven-deploy-plugin</td>\n" | ||
+ " <td>deploy</td>\n" | ||
+ " <td>default-deploy</td>\n" | ||
+ " </tr>\n" | ||
+ " </tbody>\n" | ||
+ "</table>"); | ||
}); | ||
|
||
assertThat(result) | ||
.project() | ||
.withModule("module-a") | ||
.withFile("site/buildplan-report.html") | ||
.content() | ||
.satisfies(html -> { | ||
Document document = Jsoup.parse(html); | ||
assertThat(document.title()).isEqualTo("list-multimodule-module-a – Build Plan for list-multimodule-module-a 1.0-SNAPSHOT"); | ||
assertThat(document.select("#titleContent").text()).isEqualTo("List plugin executions for org.codehaus.mojo.buildplan:list-multimodule-module-a"); | ||
assertThat(document.select("table.bodyTable").outerHtml()).isNotEmpty(); | ||
}); | ||
|
||
assertThat(result) | ||
.project() | ||
.withModule("module-b") | ||
.withFile("site/buildplan-report.html") | ||
.content() | ||
.satisfies(html -> { | ||
Document document = Jsoup.parse(html); | ||
assertThat(document.title()).isEqualTo("list-multimodule-module-b – Build Plan for list-multimodule-module-b 1.0-SNAPSHOT"); | ||
assertThat(document.select("#titleContent").text()).isEqualTo("List plugin executions for org.codehaus.mojo.buildplan:list-multimodule-module-b"); | ||
assertThat(document.select("table.bodyTable").outerHtml()).isNotEmpty(); | ||
}); | ||
} | ||
} |
Oops, something went wrong.