Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #69 from gadton/master
Browse files Browse the repository at this point in the history
Add <skip> to execution #68
  • Loading branch information
alexnederlof authored Oct 11, 2020
2 parents 9f3f332 + c4e3277 commit 3dfcda7
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 14 deletions.
20 changes: 19 additions & 1 deletion src/main/java/com/alexnederlof/jasperreport/JasperReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public class JasperReporter extends AbstractMojo {
@Parameter(defaultValue = "true")
private boolean xmlValidation;

/**
* Set this to "true" to bypass compiling reports. Default value is false.
*
*/
@Parameter( defaultValue = "false" )
private boolean skip;

/**
* If verbose is on the plug-in will report which reports it is compiling
* and which files are being skipped.
Expand Down Expand Up @@ -183,7 +190,13 @@ public JasperReporter() {
public void execute() throws MojoExecutionException {
log = getLog();

if (verbose) {
if ( isSkip() )
{
log.info( "Compiling Jasper reports is skipped." );
return;
}

if (verbose) {
logConfiguration(log);
}

Expand Down Expand Up @@ -436,4 +449,9 @@ else if (sourceScanner.equals(SimpleSourceInclusionScanner.class.getName())) {
throw new MojoExecutionException("sourceScanner not supported: \'" + sourceScanner + "\'.");
}
}

private boolean isSkip()
{
return skip;
}
}
38 changes: 25 additions & 13 deletions src/test/java/com/alexnederlof/jasperreport/JasperReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,34 @@ private String getNameWithoutSuffix(File file, String suffix) {
.indexOf(suffix));
}

/**
* Test that an invalid Jasper file should stop the build completely by throwing an
* {@link MojoExecutionException}.
*
* @throws Exception
* When an unexpected error occurs.
*/
public void testInvalidFilesStopBuild() throws Exception {
setupSourceAndDestinationFolder("/brokenReports", "/brokenReports_out");
try {
getAndExecuteMojo(getBasedir() + "/src/test/resources/testBrokenReportsPom.xml");
fail("An exception should have been thrown");
}
catch (MojoExecutionException e) {
assertEquals(JasperReporter.ERROR_JRE_COMPILE_ERROR, e.getMessage());
}
}

/**
* Test that an invalid Jasper file should stop the build completely by throwing an
* {@link MojoExecutionException}.
* Test that skipping the plugin does not compile any Jasper file.
*
* @throws Exception
* When an unexpected error occurs.
* @throws Exception
* When an unexpected error occurs.
*/
public void testInvalidFilesStopBuild() throws Exception {
setupSourceAndDestinationFolder("/brokenReports", "/brokenReports_out");
try {
getAndExecuteMojo(getBasedir() + "/src/test/resources/testBrokenReportsPom.xml");
fail("An exception should have been thrown");
}
catch (MojoExecutionException e) {
assertEquals(JasperReporter.ERROR_JRE_COMPILE_ERROR, e.getMessage());
}
public void testSkipDoesntCompile() throws Exception {
setupSourceAndDestinationFolder("/sampleReports", "/skipReports_out");
getAndExecuteMojo(getBasedir() + "/src/test/resources/testSkipSampleReportsPom.xml");
assertFalse("Output folder should not exist", destinationFolder.exists());
}

/**
Expand Down
37 changes: 37 additions & 0 deletions src/test/resources/testSkipSampleReportsPom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!-- 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. -->

<project>
<build>
<plugins>
<plugin>
<artifactId>jasperreports-plugin</artifactId>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>true</skip>
<xmlValidation>true</xmlValidation>
<numberOfThreads>4</numberOfThreads>
<outputFileExt>.jasper</outputFileExt>
<sourceFileExt>.jrxml</sourceFileExt>
<sourceDirectory>target/test-classes/exampleFolders/sampleReports</sourceDirectory>
<outputDirectory>target/unitTestReports/sampleReports_out</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit 3dfcda7

Please sign in to comment.