diff --git a/pom.xml b/pom.xml index bd8cc32..98020fd 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,4 @@ - - + - 4.0.0 - maven-plugins org.apache.maven.plugins - 36 + maven-plugins + 39 maven-resources-plugin @@ -33,16 +31,20 @@ under the License. maven-plugin Apache Maven Resources Plugin - - The Resources Plugin handles the copying of project resources to the output + The Resources Plugin handles the copying of project resources to the output directory. There are two different kinds of resources: main resources and test resources. The difference is that the main resources are the resources associated with the main source code while the test resources are associated with the test source code. Thus, this allows the separation of resources for the main source code and its - unit tests. - + unit tests. 2001 + + + Graham Leggett + + + ${mavenVersion} @@ -50,8 +52,8 @@ under the License. scm:git:https://gitbox.apache.org/repos/asf/maven-resources-plugin.git scm:git:https://gitbox.apache.org/repos/asf/maven-resources-plugin.git - https://github.com/apache/maven-resources-plugin/tree/${project.scm.tag} HEAD + https://github.com/apache/maven-resources-plugin/tree/${project.scm.tag} JIRA @@ -75,12 +77,6 @@ under the License. 2022-07-23T17:49:18Z - - - Graham Leggett - - - org.apache.maven @@ -123,6 +119,11 @@ under the License. 0.3.5 provided + + org.codehaus.plexus + plexus-utils + 3.5.1 + org.apache.maven.shared maven-filtering @@ -160,21 +161,29 @@ under the License. 4.13.2 test - - org.codehaus.plexus - plexus-utils - 3.5.1 - test - org.apache.maven.resolver maven-resolver-api 1.6.3 test - + + + + org.apache.rat + apache-rat-plugin + + + + src/it/** + + + + + + run-its diff --git a/src/it/includeEmptyDirs/README.md b/src/it/includeEmptyDirs/README.md new file mode 100644 index 0000000..0cca7c3 --- /dev/null +++ b/src/it/includeEmptyDirs/README.md @@ -0,0 +1,3 @@ +Note: this file uses ".git" named files as placeholders, that are part of "default excludes" in plexus-utils. +Before, this IT used ".gitattributes" file, but it was removed from set of default excludes by this +commit: https://github.com/codehaus-plexus/plexus-utils/commit/e8a8433894eae9e8f82cbba4b903508362e9322a diff --git a/src/it/includeEmptyDirs/src/main/resources/empty-dir-child/child/.gitattributes b/src/it/includeEmptyDirs/src/main/resources/empty-dir-child/child/._placeholder similarity index 100% rename from src/it/includeEmptyDirs/src/main/resources/empty-dir-child/child/.gitattributes rename to src/it/includeEmptyDirs/src/main/resources/empty-dir-child/child/._placeholder diff --git a/src/it/includeEmptyDirs/src/main/resources/empty-dir/.gitattributes b/src/it/includeEmptyDirs/src/main/resources/empty-dir/._placeholder similarity index 100% rename from src/it/includeEmptyDirs/src/main/resources/empty-dir/.gitattributes rename to src/it/includeEmptyDirs/src/main/resources/empty-dir/._placeholder diff --git a/src/main/java/org/apache/maven/plugins/resources/CopyResourcesMojo.java b/src/main/java/org/apache/maven/plugins/resources/CopyResourcesMojo.java index feee9d3..1e62e0b 100644 --- a/src/main/java/org/apache/maven/plugins/resources/CopyResourcesMojo.java +++ b/src/main/java/org/apache/maven/plugins/resources/CopyResourcesMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.resources; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,73 +16,64 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.resources; + +import java.io.File; +import java.util.List; import org.apache.maven.model.Resource; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import java.io.File; -import java.util.List; - /** * Copy resources of the configured plugin attribute resources - * + * * @author Olivier Lamy * @since 2.3 */ -@Mojo( name = "copy-resources", threadSafe = true ) -public class CopyResourcesMojo - extends ResourcesMojo -{ - +@Mojo(name = "copy-resources", threadSafe = true) +public class CopyResourcesMojo extends ResourcesMojo { + /** * The output directory into which to copy the resources. */ - @Parameter( required = true ) + @Parameter(required = true) private File outputDirectory; /** * The list of resources we want to transfer. See the Maven Model for a * description of how to code the resources element. */ - @Parameter( required = true ) + @Parameter(required = true) private List resources; - /** {@inheritDoc} */ - public File getOutputDirectory() - { + public File getOutputDirectory() { return outputDirectory; } /** {@inheritDoc} */ - public void setOutputDirectory( File outputDirectory ) - { + public void setOutputDirectory(File outputDirectory) { this.outputDirectory = outputDirectory; } /** {@inheritDoc} */ - public List getResources() - { + public List getResources() { return resources; } /** {@inheritDoc} */ - public void setResources( List resources ) - { + public void setResources(List resources) { this.resources = resources; } /** {@inheritDoc} */ - public List getFilters() - { + public List getFilters() { return filters; } /** {@inheritDoc} */ - public void setFilters( List filters ) - { + public void setFilters(List filters) { this.filters = filters; - } - + } } diff --git a/src/main/java/org/apache/maven/plugins/resources/MavenBuildTimestamp.java b/src/main/java/org/apache/maven/plugins/resources/MavenBuildTimestamp.java index bf33f17..fb2f8f7 100644 --- a/src/main/java/org/apache/maven/plugins/resources/MavenBuildTimestamp.java +++ b/src/main/java/org/apache/maven/plugins/resources/MavenBuildTimestamp.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.resources; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.resources; import java.text.SimpleDateFormat; import java.util.Date; @@ -28,8 +27,7 @@ /** * This class is duplicated from maven-model-builder from maven core. (See MRESOURCES-99). */ -public class MavenBuildTimestamp -{ +public class MavenBuildTimestamp { /** * ISO 8601-compliant timestamp for machine readability */ @@ -43,71 +41,59 @@ public class MavenBuildTimestamp /** * The default time zone {@code Etc/UTC}. */ - public static final TimeZone DEFAULT_BUILD_TIME_ZONE = TimeZone.getTimeZone( "Etc/UTC" ); + public static final TimeZone DEFAULT_BUILD_TIME_ZONE = TimeZone.getTimeZone("Etc/UTC"); private String formattedTimestamp; /** * Create an instance. */ - public MavenBuildTimestamp() - { - this( new Date() ); + public MavenBuildTimestamp() { + this(new Date()); } /** * @param time The time to use. */ - public MavenBuildTimestamp( Date time ) - { - this( time, DEFAULT_BUILD_TIMESTAMP_FORMAT ); + public MavenBuildTimestamp(Date time) { + this(time, DEFAULT_BUILD_TIMESTAMP_FORMAT); } /** * @param time The time to use. * @param properties the properties which can be define. can be {@code null} */ - public MavenBuildTimestamp( Date time, Properties properties ) - { - this( time, properties != null ? properties.getProperty( BUILD_TIMESTAMP_FORMAT_PROPERTY ) : null ); + public MavenBuildTimestamp(Date time, Properties properties) { + this(time, properties != null ? properties.getProperty(BUILD_TIMESTAMP_FORMAT_PROPERTY) : null); } /** * @param time The time to use. * @param timestampFormat The format for {@link SimpleDateFormat}. */ - public MavenBuildTimestamp( Date time, String timestampFormat ) - { + public MavenBuildTimestamp(Date time, String timestampFormat) { SimpleDateFormat dateFormat; - if ( timestampFormat == null ) - { - dateFormat = new SimpleDateFormat( DEFAULT_BUILD_TIMESTAMP_FORMAT ); - } - else - { - dateFormat = new SimpleDateFormat( timestampFormat ); + if (timestampFormat == null) { + dateFormat = new SimpleDateFormat(DEFAULT_BUILD_TIMESTAMP_FORMAT); + } else { + dateFormat = new SimpleDateFormat(timestampFormat); } - dateFormat.setCalendar( new GregorianCalendar() ); - dateFormat.setTimeZone( DEFAULT_BUILD_TIME_ZONE ); + dateFormat.setCalendar(new GregorianCalendar()); + dateFormat.setTimeZone(DEFAULT_BUILD_TIME_ZONE); - if ( time == null ) - { - formattedTimestamp = dateFormat.format( new Date() ); - } - else - { - formattedTimestamp = dateFormat.format( time ); + if (time == null) { + formattedTimestamp = dateFormat.format(new Date()); + } else { + formattedTimestamp = dateFormat.format(time); } - } /** * @return The formatted time stamp. */ - public String formattedTimestamp() - { + public String formattedTimestamp() { return formattedTimestamp; } } diff --git a/src/main/java/org/apache/maven/plugins/resources/Resource.java b/src/main/java/org/apache/maven/plugins/resources/Resource.java index 696b550..9f9c219 100644 --- a/src/main/java/org/apache/maven/plugins/resources/Resource.java +++ b/src/main/java/org/apache/maven/plugins/resources/Resource.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.resources; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,15 +16,14 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.resources; /** * @author Olivier Lamy * @since 2.3 * */ -public class Resource - extends org.apache.maven.model.Resource -{ +public class Resource extends org.apache.maven.model.Resource { // nothing to do here just a class prevent users adding an implementation attribute // in the mojo configuration } diff --git a/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java b/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java index 6be6608..e622efc 100644 --- a/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java +++ b/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.resources; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.resources; import java.io.File; import java.util.ArrayList; @@ -51,15 +50,13 @@ * @author Andreas Hoheneder * @author William Ferguson */ -@Mojo( name = "resources", defaultPhase = LifecyclePhase.PROCESS_RESOURCES, requiresProject = true, threadSafe = true ) -public class ResourcesMojo - extends AbstractMojo -{ +@Mojo(name = "resources", defaultPhase = LifecyclePhase.PROCESS_RESOURCES, requiresProject = true, threadSafe = true) +public class ResourcesMojo extends AbstractMojo { /** * The character encoding to use when reading and writing filtered resources. */ - @Parameter( defaultValue = "${project.build.sourceEncoding}" ) + @Parameter(defaultValue = "${project.build.sourceEncoding}") protected String encoding; /** @@ -74,19 +71,19 @@ public class ResourcesMojo /** * The output directory into which to copy the resources. */ - @Parameter( defaultValue = "${project.build.outputDirectory}", required = true ) + @Parameter(defaultValue = "${project.build.outputDirectory}", required = true) private File outputDirectory; /** * The list of resources we want to transfer. */ - @Parameter( defaultValue = "${project.resources}", required = true ) + @Parameter(defaultValue = "${project.resources}", required = true) private List resources; /** * */ - @Parameter( defaultValue = "${project}", readonly = true, required = true ) + @Parameter(defaultValue = "${project}", readonly = true, required = true) protected MavenProject project; /** @@ -96,7 +93,7 @@ public class ResourcesMojo * @see ResourcesMojo#filters * @since 2.4 */ - @Parameter( defaultValue = "${project.build.filters}", readonly = true ) + @Parameter(defaultValue = "${project.build.filters}", readonly = true) protected List buildFilters; /** @@ -122,25 +119,25 @@ public class ResourcesMojo * @see ResourcesMojo#filters * @since 2.4 */ - @Parameter( defaultValue = "true" ) + @Parameter(defaultValue = "true") protected boolean useBuildFilters; /** * */ - @Component( role = MavenResourcesFiltering.class, hint = "default" ) + @Component(role = MavenResourcesFiltering.class, hint = "default") protected MavenResourcesFiltering mavenResourcesFiltering; /** * */ - @Component( role = MavenResourcesFiltering.class ) + @Component(role = MavenResourcesFiltering.class) protected Map mavenResourcesFilteringMap; /** * */ - @Parameter( defaultValue = "${session}", readonly = true, required = true ) + @Parameter(defaultValue = "${session}", readonly = true, required = true) protected MavenSession session; /** @@ -158,7 +155,7 @@ public class ResourcesMojo * * @since 2.3 */ - @Parameter( defaultValue = "false" ) + @Parameter(defaultValue = "false") private boolean overwrite; /** @@ -166,7 +163,7 @@ public class ResourcesMojo * * @since 2.3 */ - @Parameter( defaultValue = "false" ) + @Parameter(defaultValue = "false") protected boolean includeEmptyDirs; /** @@ -182,7 +179,7 @@ public class ResourcesMojo * * @since 2.4 */ - @Parameter( defaultValue = "true" ) + @Parameter(defaultValue = "true") protected boolean escapeWindowsPaths; /** @@ -214,7 +211,7 @@ public class ResourcesMojo * * @since 2.4 */ - @Parameter( defaultValue = "true" ) + @Parameter(defaultValue = "true") protected boolean useDefaultDelimiters; /** @@ -235,7 +232,7 @@ public class ResourcesMojo *
  • Mac: **/.DS_Store
  • *
  • Serena Dimension: **/.metadata, **/.metadata/**
  • *
  • Mercurial: **/.hg, **/.hg/**
  • - *
  • GIT: **/.git, **/.gitignore, **/.gitattributes, **/.git/**
  • + *
  • Git: **/.git, **/.git/**
  • *
  • Bitkeeper: **/BitKeeper, **/BitKeeper/**, **/ChangeSet, * **/ChangeSet/**
  • *
  • Darcs: **/_darcs, **/_darcs/**, **/.darcsrepo, @@ -244,7 +241,7 @@ public class ResourcesMojo * * @since 3.0.0 */ - @Parameter( defaultValue = "true" ) + @Parameter(defaultValue = "true") protected boolean addDefaultExcludes; /** @@ -269,7 +266,7 @@ public class ResourcesMojo * * @since 2.5 */ - @Parameter( defaultValue = "false" ) + @Parameter(defaultValue = "false") private boolean supportMultiLineFiltering; /** @@ -277,7 +274,7 @@ public class ResourcesMojo * * @since 3.0.0 */ - @Parameter( defaultValue = "false" ) + @Parameter(defaultValue = "false") private boolean fileNameFiltering; /** @@ -286,72 +283,68 @@ public class ResourcesMojo * * @since 3.0.0 */ - @Parameter( property = "maven.resources.skip", defaultValue = "false" ) + @Parameter(property = "maven.resources.skip", defaultValue = "false") private boolean skip; /** * {@inheritDoc} */ - public void execute() - throws MojoExecutionException - { - if ( isSkip() ) - { - getLog().info( "Skipping the execution." ); + public void execute() throws MojoExecutionException { + if (isSkip()) { + getLog().info("Skipping the execution."); return; } - if ( StringUtils.isBlank( encoding ) && isFilteringEnabled( getResources() ) ) - { - getLog().warn( "File encoding has not been set, using platform encoding " - + System.getProperty( "file.encoding" ) - + ". Build is platform dependent!" ); - getLog().warn( "See https://maven.apache.org/general.html#encoding-warning" ); + if (StringUtils.isBlank(encoding) && isFilteringEnabled(getResources())) { + getLog().warn("File encoding has not been set, using platform encoding " + + System.getProperty("file.encoding") + + ". Build is platform dependent!"); + getLog().warn("See https://maven.apache.org/general.html#encoding-warning"); } - try - { + try { List combinedFilters = getCombinedFiltersList(); - MavenResourcesExecution mavenResourcesExecution = - new MavenResourcesExecution( getResources(), getOutputDirectory(), project, encoding, - combinedFilters, - Collections.emptyList(), session ); + MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution( + getResources(), + getOutputDirectory(), + project, + encoding, + combinedFilters, + Collections.emptyList(), + session); - mavenResourcesExecution.setEscapeWindowsPaths( escapeWindowsPaths ); + mavenResourcesExecution.setEscapeWindowsPaths(escapeWindowsPaths); // never include project build filters in this call, since we've already accounted for the POM build filters // above, in getCombinedFiltersList(). - mavenResourcesExecution.setInjectProjectBuildFilters( false ); + mavenResourcesExecution.setInjectProjectBuildFilters(false); - mavenResourcesExecution.setEscapeString( escapeString ); - mavenResourcesExecution.setOverwrite( overwrite ); - mavenResourcesExecution.setIncludeEmptyDirs( includeEmptyDirs ); - mavenResourcesExecution.setSupportMultiLineFiltering( supportMultiLineFiltering ); - mavenResourcesExecution.setFilterFilenames( fileNameFiltering ); - mavenResourcesExecution.setAddDefaultExcludes( addDefaultExcludes ); + mavenResourcesExecution.setEscapeString(escapeString); + mavenResourcesExecution.setOverwrite(overwrite); + mavenResourcesExecution.setIncludeEmptyDirs(includeEmptyDirs); + mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering); + mavenResourcesExecution.setFilterFilenames(fileNameFiltering); + mavenResourcesExecution.setAddDefaultExcludes(addDefaultExcludes); // Handle subject of MRESOURCES-99 Properties additionalProperties = addSeveralSpecialProperties(); - mavenResourcesExecution.setAdditionalProperties( additionalProperties ); + mavenResourcesExecution.setAdditionalProperties(additionalProperties); // if these are NOT set, just use the defaults, which are '${*}' and '@'. - mavenResourcesExecution.setDelimiters( delimiters, useDefaultDelimiters ); + mavenResourcesExecution.setDelimiters(delimiters, useDefaultDelimiters); // Handle MRESOURCES-171 - mavenResourcesExecution.setPropertiesEncoding( propertiesEncoding ); + mavenResourcesExecution.setPropertiesEncoding(propertiesEncoding); - if ( nonFilteredFileExtensions != null ) - { - mavenResourcesExecution.setNonFilteredFileExtensions( nonFilteredFileExtensions ); + if (nonFilteredFileExtensions != null) { + mavenResourcesExecution.setNonFilteredFileExtensions(nonFilteredFileExtensions); } - mavenResourcesFiltering.filterResources( mavenResourcesExecution ); + mavenResourcesFiltering.filterResources(mavenResourcesExecution); - executeUserFilterComponents( mavenResourcesExecution ); - } - catch ( MavenFilteringException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); + executeUserFilterComponents(mavenResourcesExecution); + } catch (MavenFilteringException e) { + throw new MojoExecutionException(e.getMessage(), e); } } @@ -369,14 +362,14 @@ public void execute() * * @return the new instance with those properties. */ - private Properties addSeveralSpecialProperties() - { + private Properties addSeveralSpecialProperties() { String timeStamp = new MavenBuildTimestamp().formattedTimestamp(); Properties additionalProperties = new Properties(); - additionalProperties.put( "maven.build.timestamp", timeStamp ); - if ( project.getBasedir() != null ) - { - additionalProperties.put( "project.baseUri", project.getBasedir().getAbsoluteFile().toURI().toString() ); + additionalProperties.put("maven.build.timestamp", timeStamp); + if (project.getBasedir() != null) { + additionalProperties.put( + "project.baseUri", + project.getBasedir().getAbsoluteFile().toURI().toString()); } return additionalProperties; @@ -388,39 +381,29 @@ private Properties addSeveralSpecialProperties() * @throws MavenFilteringException in case of failure. * @since 2.5 */ - protected void executeUserFilterComponents( MavenResourcesExecution mavenResourcesExecution ) - throws MojoExecutionException, MavenFilteringException - { - - if ( mavenFilteringHints != null ) - { - for ( String hint : mavenFilteringHints ) - { - MavenResourcesFiltering userFilterComponent = mavenResourcesFilteringMap.get( hint ); - if ( userFilterComponent != null ) - { - getLog().debug( "added user filter component with hint: " + hint ); - mavenFilteringComponents.add( userFilterComponent ); - } - else - { + protected void executeUserFilterComponents(MavenResourcesExecution mavenResourcesExecution) + throws MojoExecutionException, MavenFilteringException { + + if (mavenFilteringHints != null) { + for (String hint : mavenFilteringHints) { + MavenResourcesFiltering userFilterComponent = mavenResourcesFilteringMap.get(hint); + if (userFilterComponent != null) { + getLog().debug("added user filter component with hint: " + hint); + mavenFilteringComponents.add(userFilterComponent); + } else { throw new MojoExecutionException( "User filter with hint `" + hint + "` requested, but not present. Discovered filters are: " - + mavenResourcesFilteringMap.keySet() ); + + mavenResourcesFilteringMap.keySet()); } } - } - else - { - getLog().debug( "no user filter components" ); + } else { + getLog().debug("no user filter components"); } - if ( mavenFilteringComponents != null && !mavenFilteringComponents.isEmpty() ) - { - getLog().debug( "execute user filters" ); - for ( MavenResourcesFiltering filter : mavenFilteringComponents ) - { - filter.filterResources( mavenResourcesExecution ); + if (mavenFilteringComponents != null && !mavenFilteringComponents.isEmpty()) { + getLog().debug("execute user filters"); + for (MavenResourcesFiltering filter : mavenFilteringComponents) { + filter.filterResources(mavenResourcesExecution); } } } @@ -428,22 +411,17 @@ protected void executeUserFilterComponents( MavenResourcesExecution mavenResourc /** * @return The combined filters. */ - protected List getCombinedFiltersList() - { - if ( filters == null || filters.isEmpty() ) - { + protected List getCombinedFiltersList() { + if (filters == null || filters.isEmpty()) { return useBuildFilters ? buildFilters : null; - } - else - { + } else { List result = new ArrayList<>(); - if ( useBuildFilters && buildFilters != null && !buildFilters.isEmpty() ) - { - result.addAll( buildFilters ); + if (useBuildFilters && buildFilters != null && !buildFilters.isEmpty()) { + result.addAll(buildFilters); } - result.addAll( filters ); + result.addAll(filters); return result; } @@ -455,14 +433,10 @@ protected List getCombinedFiltersList() * @param theResources The set of resources to check for filtering, may be null. * @return true if at least one resource uses filtering, false otherwise. */ - private boolean isFilteringEnabled( Collection theResources ) - { - if ( theResources != null ) - { - for ( Resource resource : theResources ) - { - if ( resource.isFiltering() ) - { + private boolean isFilteringEnabled(Collection theResources) { + if (theResources != null) { + for (Resource resource : theResources) { + if (resource.isFiltering()) { return true; } } @@ -473,121 +447,105 @@ private boolean isFilteringEnabled( Collection theResources ) /** * @return {@link #resources} */ - public List getResources() - { + public List getResources() { return resources; } /** * @param resources set {@link #resources} */ - public void setResources( List resources ) - { + public void setResources(List resources) { this.resources = resources; } /** * @return {@link #outputDirectory} */ - public File getOutputDirectory() - { + public File getOutputDirectory() { return outputDirectory; } /** * @param outputDirectory the output folder. */ - public void setOutputDirectory( File outputDirectory ) - { + public void setOutputDirectory(File outputDirectory) { this.outputDirectory = outputDirectory; } /** * @return {@link #overwrite} */ - public boolean isOverwrite() - { + public boolean isOverwrite() { return overwrite; } /** * @param overwrite true to overwrite false otherwise. */ - public void setOverwrite( boolean overwrite ) - { + public void setOverwrite(boolean overwrite) { this.overwrite = overwrite; } /** * @return {@link #includeEmptyDirs} */ - public boolean isIncludeEmptyDirs() - { + public boolean isIncludeEmptyDirs() { return includeEmptyDirs; } /** * @param includeEmptyDirs true/false. */ - public void setIncludeEmptyDirs( boolean includeEmptyDirs ) - { + public void setIncludeEmptyDirs(boolean includeEmptyDirs) { this.includeEmptyDirs = includeEmptyDirs; } /** * @return {@link #filters} */ - public List getFilters() - { + public List getFilters() { return filters; } /** * @param filters The filters to use. */ - public void setFilters( List filters ) - { + public void setFilters(List filters) { this.filters = filters; } /** * @return {@link #delimiters} */ - public LinkedHashSet getDelimiters() - { + public LinkedHashSet getDelimiters() { return delimiters; } /** * @param delimiters The delimiters to use. */ - public void setDelimiters( LinkedHashSet delimiters ) - { + public void setDelimiters(LinkedHashSet delimiters) { this.delimiters = delimiters; } /** * @return {@link #useDefaultDelimiters} */ - public boolean isUseDefaultDelimiters() - { + public boolean isUseDefaultDelimiters() { return useDefaultDelimiters; } /** * @param useDefaultDelimiters true to use {@code ${*}} */ - public void setUseDefaultDelimiters( boolean useDefaultDelimiters ) - { + public void setUseDefaultDelimiters(boolean useDefaultDelimiters) { this.useDefaultDelimiters = useDefaultDelimiters; } /** * @return {@link #skip} */ - public boolean isSkip() - { + public boolean isSkip() { return skip; } - } diff --git a/src/main/java/org/apache/maven/plugins/resources/TestResourcesMojo.java b/src/main/java/org/apache/maven/plugins/resources/TestResourcesMojo.java index 7c2fef7..f7a1ada 100644 --- a/src/main/java/org/apache/maven/plugins/resources/TestResourcesMojo.java +++ b/src/main/java/org/apache/maven/plugins/resources/TestResourcesMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.resources; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,10 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.resources; + +import java.io.File; +import java.util.List; import org.apache.maven.model.Resource; import org.apache.maven.plugin.MojoExecutionException; @@ -25,9 +27,6 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import java.io.File; -import java.util.List; - /** * Copy resources for the test source code to the test output directory. * Always uses the project.build.testResources element to specify the resources to copy. @@ -35,21 +34,22 @@ * @author Michal Maczka * @author Jason van Zyl */ -@Mojo( name = "testResources", defaultPhase = LifecyclePhase.PROCESS_TEST_RESOURCES, requiresProject = true, - threadSafe = true ) -public class TestResourcesMojo - extends ResourcesMojo -{ +@Mojo( + name = "testResources", + defaultPhase = LifecyclePhase.PROCESS_TEST_RESOURCES, + requiresProject = true, + threadSafe = true) +public class TestResourcesMojo extends ResourcesMojo { /** * The output directory into which to copy the resources. */ - @Parameter( defaultValue = "${project.build.testOutputDirectory}", required = true ) + @Parameter(defaultValue = "${project.build.testOutputDirectory}", required = true) private File outputDirectory; /** * The list of resources we want to transfer. */ - @Parameter( defaultValue = "${project.testResources}", required = true ) + @Parameter(defaultValue = "${project.testResources}", required = true) private List resources; /** @@ -57,47 +57,37 @@ public class TestResourcesMojo * Its use is NOT RECOMMENDED, but quite convenient on occasion. * @since 2.6 */ - @Parameter( property = "maven.test.skip", defaultValue = "false" ) + @Parameter(property = "maven.test.skip", defaultValue = "false") private boolean skip; /** * {@inheritDoc} */ - public void execute() - throws MojoExecutionException - { - if ( skip ) - { - getLog().info( "Not copying test resources" ); - } - else - { + public void execute() throws MojoExecutionException { + if (skip) { + getLog().info("Not copying test resources"); + } else { super.execute(); } } /** {@inheritDoc} */ - public File getOutputDirectory() - { + public File getOutputDirectory() { return outputDirectory; } /** {@inheritDoc} */ - public void setOutputDirectory( File outputDirectory ) - { + public void setOutputDirectory(File outputDirectory) { this.outputDirectory = outputDirectory; } /** {@inheritDoc} */ - public List getResources() - { + public List getResources() { return resources; } /** {@inheritDoc} */ - public void setResources( List resources ) - { + public void setResources(List resources) { this.resources = resources; } - } diff --git a/src/test/java/org/apache/maven/plugins/resources/AbstractPropertyUtilsTest.java b/src/test/java/org/apache/maven/plugins/resources/AbstractPropertyUtilsTest.java index 4fd8c56..2f7579b 100644 --- a/src/test/java/org/apache/maven/plugins/resources/AbstractPropertyUtilsTest.java +++ b/src/test/java/org/apache/maven/plugins/resources/AbstractPropertyUtilsTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.resources; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.resources; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -33,9 +31,7 @@ /** * Base class for propertyutils test case */ -public abstract class AbstractPropertyUtilsTest - extends AbstractMojoTestCase -{ +public abstract class AbstractPropertyUtilsTest extends AbstractMojoTestCase { protected File propertyFile; protected File validationFile; @@ -46,34 +42,29 @@ public abstract class AbstractPropertyUtilsTest protected abstract File getValidationFile(); - protected void setUp() - throws Exception - { + protected void setUp() throws Exception { super.setUp(); // load data propertyFile = getPropertyFile(); - assertNotNull( propertyFile ); + assertNotNull(propertyFile); validationFile = getValidationFile(); - assertNotNull( validationFile ); + assertNotNull(validationFile); - loadValidationProperties( validationFile ); + loadValidationProperties(validationFile); } - protected boolean validateProperties( Properties prop ) - { + protected boolean validateProperties(Properties prop) { boolean bRetVal = false; Enumeration propKeys = prop.keys(); String key; - while ( propKeys.hasMoreElements() ) - { + while (propKeys.hasMoreElements()) { key = (String) propKeys.nextElement(); - bRetVal = prop.getProperty( key ).equals( validationProp.getProperty( key ) ); - if ( !bRetVal ) - { + bRetVal = prop.getProperty(key).equals(validationProp.getProperty(key)); + if (!bRetVal) { break; } } @@ -87,25 +78,19 @@ protected boolean validateProperties( Properties prop ) * * @param validationPropFile */ - private void loadValidationProperties( File validationPropFile ) - { + private void loadValidationProperties(File validationPropFile) { validationProp = new Properties(); InputStream in = null; - try - { - in = Files.newInputStream( validationPropFile.toPath() ); - validationProp.load( in ); + try { + in = Files.newInputStream(validationPropFile.toPath()); + validationProp.load(in); in.close(); in = null; - } - catch ( IOException ex ) - { + } catch (IOException ex) { // TODO: do error handling - } - finally - { - IOUtil.close( in ); + } finally { + IOUtil.close(in); } } } diff --git a/src/test/java/org/apache/maven/plugins/resources/BasicPropertyUtilsTest.java b/src/test/java/org/apache/maven/plugins/resources/BasicPropertyUtilsTest.java index 35473b9..9d31283 100644 --- a/src/test/java/org/apache/maven/plugins/resources/BasicPropertyUtilsTest.java +++ b/src/test/java/org/apache/maven/plugins/resources/BasicPropertyUtilsTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.resources; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,38 +16,33 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.resources; import java.io.File; import java.util.Properties; import org.apache.maven.shared.filtering.PropertyUtils; -public class BasicPropertyUtilsTest - extends AbstractPropertyUtilsTest -{ - final static protected String validationFileName = - "/target/test-classes/unit/propertiesutils-test/basic_validation.properties"; +public class BasicPropertyUtilsTest extends AbstractPropertyUtilsTest { + protected static final String validationFileName = + "/target/test-classes/unit/propertiesutils-test/basic_validation.properties"; - final static protected String propFileName = "/target/test-classes/unit/propertiesutils-test/basic.properties"; + protected static final String propFileName = "/target/test-classes/unit/propertiesutils-test/basic.properties"; - protected File getPropertyFile() - { - File propFile = new File( getBasedir(), propFileName ); + protected File getPropertyFile() { + File propFile = new File(getBasedir(), propFileName); - if ( !propFile.exists() ) - { + if (!propFile.exists()) { propFile = null; } return propFile; } - protected File getValidationFile() - { - File validationFile = new File( getBasedir(), validationFileName ); + protected File getValidationFile() { + File validationFile = new File(getBasedir(), validationFileName); - if ( !validationFile.exists() ) - { + if (!validationFile.exists()) { validationFile = null; } @@ -61,13 +54,11 @@ protected File getValidationFile() * * @throws Exception */ - public void testBasicLoadProperty_FF() - throws Exception - { - Properties prop = PropertyUtils.loadPropertyFile( propertyFile, false, false ); + public void testBasicLoadProperty_FF() throws Exception { + Properties prop = PropertyUtils.loadPropertyFile(propertyFile, false, false); - assertNotNull( prop ); - assertTrue( validateProperties( prop ) ); + assertNotNull(prop); + assertTrue(validateProperties(prop)); } /** @@ -75,13 +66,11 @@ public void testBasicLoadProperty_FF() * * @throws Exception */ - public void testBasicLoadProperty_TF() - throws Exception - { - Properties prop = PropertyUtils.loadPropertyFile( propertyFile, true, false ); + public void testBasicLoadProperty_TF() throws Exception { + Properties prop = PropertyUtils.loadPropertyFile(propertyFile, true, false); - assertNotNull( prop ); - assertTrue( validateProperties( prop ) ); + assertNotNull(prop); + assertTrue(validateProperties(prop)); } /** @@ -89,14 +78,12 @@ public void testBasicLoadProperty_TF() * * @throws Exception */ - public void testBasicLoadProperty_TT() - throws Exception - { - Properties prop = PropertyUtils.loadPropertyFile( propertyFile, true, true ); - - validationProp.putAll( System.getProperties() ); - assertNotNull( prop ); - assertTrue( validateProperties( prop ) ); + public void testBasicLoadProperty_TT() throws Exception { + Properties prop = PropertyUtils.loadPropertyFile(propertyFile, true, true); + + validationProp.putAll(System.getProperties()); + assertNotNull(prop); + assertTrue(validateProperties(prop)); } /** @@ -104,14 +91,11 @@ public void testBasicLoadProperty_TT() * * @throws Exception */ - public void testNonExistentProperty() - throws Exception - { - Properties prop = PropertyUtils.loadPropertyFile( propertyFile, true, true ); - - validationProp.putAll( System.getProperties() ); - assertNotNull( prop ); - assertNull( prop.getProperty( "does_not_exist" ) ); - } + public void testNonExistentProperty() throws Exception { + Properties prop = PropertyUtils.loadPropertyFile(propertyFile, true, true); + validationProp.putAll(System.getProperties()); + assertNotNull(prop); + assertNull(prop.getProperty("does_not_exist")); + } } diff --git a/src/test/java/org/apache/maven/plugins/resources/CopyResourcesMojoTest.java b/src/test/java/org/apache/maven/plugins/resources/CopyResourcesMojoTest.java index 5d12f90..e951fc1 100644 --- a/src/test/java/org/apache/maven/plugins/resources/CopyResourcesMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/resources/CopyResourcesMojoTest.java @@ -1,14 +1,3 @@ -package org.apache.maven.plugins.resources; - -import java.io.File; -import java.util.Collections; - -import org.apache.maven.model.Resource; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.apache.maven.plugins.resources.ResourcesMojo; -import org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub; -import org.codehaus.plexus.util.FileUtils; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,7 +7,7 @@ * "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 + * 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 @@ -27,54 +16,53 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.resources; + +import java.io.File; +import java.util.Collections; + +import org.apache.maven.model.Resource; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub; +import org.codehaus.plexus.util.FileUtils; /** * @author Olivier Lamy * @version $Id$ */ -public class CopyResourcesMojoTest - extends AbstractMojoTestCase -{ +public class CopyResourcesMojoTest extends AbstractMojoTestCase { - protected final static String defaultPomFilePath = "/target/test-classes/unit/resources-test/plugin-config.xml"; + protected static final String defaultPomFilePath = "/target/test-classes/unit/resources-test/plugin-config.xml"; - File outputDirectory = new File( getBasedir(), "/target/copyResourcesTests" ); + File outputDirectory = new File(getBasedir(), "/target/copyResourcesTests"); - protected void setUp() - throws Exception - { + protected void setUp() throws Exception { super.setUp(); - if ( !outputDirectory.exists() ) - { + if (!outputDirectory.exists()) { outputDirectory.mkdirs(); - } - else - { - FileUtils.cleanDirectory( outputDirectory ); + } else { + FileUtils.cleanDirectory(outputDirectory); } } - public void testCopyWithoutFiltering() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); + public void testCopyWithoutFiltering() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); - mojo.setOutputDirectory( outputDirectory ); + mojo.setOutputDirectory(outputDirectory); Resource resource = new Resource(); - resource.setDirectory( getBasedir() + "/src/test/unit-files/copy-resources-test/no-filter" ); - resource.setFiltering( false ); + resource.setDirectory(getBasedir() + "/src/test/unit-files/copy-resources-test/no-filter"); + resource.setFiltering(false); - mojo.setResources( Collections.singletonList( resource ) ); + mojo.setResources(Collections.singletonList(resource)); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "CopyResourcesMojoTest" ); - File targetFile = new File( getBasedir(), "/target/copyResourcesTests" ); - project.setBaseDir( targetFile ); - setVariableValueToObject( mojo, "project", project ); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("CopyResourcesMojoTest"); + File targetFile = new File(getBasedir(), "/target/copyResourcesTests"); + project.setBaseDir(targetFile); + setVariableValueToObject(mojo, "project", project); mojo.execute(); - assertTrue( new File( targetFile, "config.properties" ).exists() ); + assertTrue(new File(targetFile, "config.properties").exists()); } - } diff --git a/src/test/java/org/apache/maven/plugins/resources/PropertyUtilsExceptionTest.java b/src/test/java/org/apache/maven/plugins/resources/PropertyUtilsExceptionTest.java index a0c00a9..18f5aa1 100644 --- a/src/test/java/org/apache/maven/plugins/resources/PropertyUtilsExceptionTest.java +++ b/src/test/java/org/apache/maven/plugins/resources/PropertyUtilsExceptionTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.resources; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.resources; import java.io.File; import java.io.FileNotFoundException; @@ -25,18 +24,15 @@ import org.apache.maven.shared.filtering.PropertyUtils; import org.junit.Test; -public class PropertyUtilsExceptionTest -{ +public class PropertyUtilsExceptionTest { /** * load property test case can be adjusted by modifying the basic.properties and basic_validation properties * * @throws Exception */ - @Test( expected = FileNotFoundException.class ) - public void loadPropertyFileShouldFailWithFileNotFoundException() - throws Exception - { - PropertyUtils.loadPropertyFile( new File( "NON_EXISTENT_FILE" ), true, true ); + @Test(expected = FileNotFoundException.class) + public void loadPropertyFileShouldFailWithFileNotFoundException() throws Exception { + PropertyUtils.loadPropertyFile(new File("NON_EXISTENT_FILE"), true, true); } } diff --git a/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoTest.java b/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoTest.java index 6820aed..cfac851 100644 --- a/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.resources; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.resources; import java.io.BufferedReader; import java.io.File; @@ -35,523 +34,480 @@ import org.apache.maven.model.Resource; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub; -import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.util.FileUtils; -import org.eclipse.aether.RepositorySystemSession; -public class ResourcesMojoTest - extends AbstractMojoTestCase -{ - protected final static String defaultPomFilePath = "/target/test-classes/unit/resources-test/plugin-config.xml"; +public class ResourcesMojoTest extends AbstractMojoTestCase { + protected static final String defaultPomFilePath = "/target/test-classes/unit/resources-test/plugin-config.xml"; /** * test mojo lookup, test harness should be working fine * * @throws Exception */ - public void testHarnessEnvironment() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); + public void testHarnessEnvironment() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); - assertNotNull( mojo ); + assertNotNull(mojo); } /** * @throws Exception */ - public void testResourceDirectoryStructure() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourceDirectoryStructure" ); - List resources = project.getBuild() - .getResources(); - - assertNotNull( mojo ); - - project.addFile( "file4.txt" ); - project.addFile( "package/file3.nottest" ); - project.addFile( "notpackage/file1.include" ); - project.addFile( "package/test/file1.txt" ); - project.addFile( "notpackage/test/file2.txt" ); + public void testResourceDirectoryStructure() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceDirectoryStructure"); + List resources = project.getBuild().getResources(); + + assertNotNull(mojo); + + project.addFile("file4.txt"); + project.addFile("package/file3.nottest"); + project.addFile("notpackage/file1.include"); + project.addFile("package/test/file1.txt"); + project.addFile("notpackage/test/file2.txt"); project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "buildFilters", Collections.emptyList() ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "buildFilters", Collections.emptyList()); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); mojo.execute(); String resourcesDir = project.getOutputDirectory(); - assertTrue( FileUtils.fileExists( resourcesDir + "/file4.txt" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/package/file3.nottest" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/notpackage/file1.include" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/package/test" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/notpackage/test" ) ); + assertTrue(FileUtils.fileExists(resourcesDir + "/file4.txt")); + assertTrue(FileUtils.fileExists(resourcesDir + "/package/file3.nottest")); + assertTrue(FileUtils.fileExists(resourcesDir + "/notpackage/file1.include")); + assertTrue(FileUtils.fileExists(resourcesDir + "/package/test")); + assertTrue(FileUtils.fileExists(resourcesDir + "/notpackage/test")); } /** * @throws Exception */ - public void testResourceDirectoryStructure_RelativePath() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourceDirectoryStructure_RelativePath" ); - List resources = project.getBuild() - .getResources(); - - assertNotNull( mojo ); - - project.setOutputDirectory( "../relative_dir" ); - project.addFile( "file4.txt" ); - project.addFile( "package/file3.nottest" ); - project.addFile( "notpackage/file1.include" ); - project.addFile( "package/test/file1.txt" ); - project.addFile( "notpackage/test/file2.txt" ); + public void testResourceDirectoryStructure_RelativePath() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceDirectoryStructure_RelativePath"); + List resources = project.getBuild().getResources(); + + assertNotNull(mojo); + + project.setOutputDirectory("../relative_dir"); + project.addFile("file4.txt"); + project.addFile("package/file3.nottest"); + project.addFile("notpackage/file1.include"); + project.addFile("package/test/file1.txt"); + project.addFile("notpackage/test/file2.txt"); project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "buildFilters", Collections.emptyList() ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject(mojo, "buildFilters", Collections.emptyList()); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); mojo.execute(); String resourcesDir = project.getOutputDirectory(); - assertTrue( FileUtils.fileExists( resourcesDir + "/file4.txt" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/package/file3.nottest" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/notpackage/file1.include" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/package/test" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/notpackage/test" ) ); + assertTrue(FileUtils.fileExists(resourcesDir + "/file4.txt")); + assertTrue(FileUtils.fileExists(resourcesDir + "/package/file3.nottest")); + assertTrue(FileUtils.fileExists(resourcesDir + "/notpackage/file1.include")); + assertTrue(FileUtils.fileExists(resourcesDir + "/package/test")); + assertTrue(FileUtils.fileExists(resourcesDir + "/notpackage/test")); } /** * @throws Exception */ - public void testResourceEncoding() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "encoding" ); - List resources = project.getBuild() - .getResources(); - - assertNotNull( mojo ); - - project.addFile( "file4.txt" ); - project.setResourceFiltering( 0, true ); + public void testResourceEncoding() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("encoding"); + List resources = project.getBuild().getResources(); + + assertNotNull(mojo); + + project.addFile("file4.txt"); + project.setResourceFiltering(0, true); project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "encoding", "UTF-8" ); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "buildFilters", Collections.emptyList() ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); + setVariableValueToObject(mojo, "encoding", "UTF-8"); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "buildFilters", Collections.emptyList()); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); mojo.execute(); String resourcesDir = project.getOutputDirectory(); - assertTrue( FileUtils.fileExists( resourcesDir + "/file4.txt" ) ); + assertTrue(FileUtils.fileExists(resourcesDir + "/file4.txt")); } /** * @throws Exception */ - public void testResourceInclude() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourceInclude" ); - List resources = project.getBuild() - .getResources(); - - assertNotNull( mojo ); - - project.addFile( "file1.include" ); - project.addFile( "file2.exclude" ); - project.addFile( "file3.nottest" ); - project.addFile( "file4.txt" ); - project.addFile( "package/file1.include" ); - project.addFile( "package/file2.exclude" ); - project.addFile( "package/file3.nottest" ); - project.addFile( "package/file4.txt" ); - project.addFile( "notpackage/file1.include" ); - project.addFile( "notpackage/file2.exclude" ); - project.addFile( "notpackage/file3.nottest" ); - project.addFile( "notpackage/file4.txt" ); - project.addFile( "package/test/file1.txt" ); - project.addFile( "package/nottest/file2.txt" ); - project.addFile( "notpackage/test/file1.txt" ); - project.addFile( "notpackage/nottest/file.txt" ); + public void testResourceInclude() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceInclude"); + List resources = project.getBuild().getResources(); + + assertNotNull(mojo); + + project.addFile("file1.include"); + project.addFile("file2.exclude"); + project.addFile("file3.nottest"); + project.addFile("file4.txt"); + project.addFile("package/file1.include"); + project.addFile("package/file2.exclude"); + project.addFile("package/file3.nottest"); + project.addFile("package/file4.txt"); + project.addFile("notpackage/file1.include"); + project.addFile("notpackage/file2.exclude"); + project.addFile("notpackage/file3.nottest"); + project.addFile("notpackage/file4.txt"); + project.addFile("package/test/file1.txt"); + project.addFile("package/nottest/file2.txt"); + project.addFile("notpackage/test/file1.txt"); + project.addFile("notpackage/nottest/file.txt"); project.setupBuildEnvironment(); - project.addInclude( "*.include" ); - project.addInclude( "**/test" ); - project.addInclude( "**/test/file*" ); - project.addInclude( "**/package/*.include" ); - - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "buildFilters", Collections.emptyList() ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); + project.addInclude("*.include"); + project.addInclude("**/test"); + project.addInclude("**/test/file*"); + project.addInclude("**/package/*.include"); + + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject(mojo, "buildFilters", Collections.emptyList()); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); mojo.execute(); String resourcesDir = project.getOutputDirectory(); - assertTrue( FileUtils.fileExists( resourcesDir + "/package/test" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/file1.include" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/package/file1.include" ) ); - assertFalse( FileUtils.fileExists( resourcesDir + "/notpackage/file1.include" ) ); - assertFalse( FileUtils.fileExists( resourcesDir + "/notpackage/nottest/file.txt" ) ); + assertTrue(FileUtils.fileExists(resourcesDir + "/package/test")); + assertTrue(FileUtils.fileExists(resourcesDir + "/file1.include")); + assertTrue(FileUtils.fileExists(resourcesDir + "/package/file1.include")); + assertFalse(FileUtils.fileExists(resourcesDir + "/notpackage/file1.include")); + assertFalse(FileUtils.fileExists(resourcesDir + "/notpackage/nottest/file.txt")); } /** * @throws Exception */ - public void testResourceExclude() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourceExclude" ); - List resources = project.getBuild() - .getResources(); - - assertNotNull( mojo ); - - project.addFile( "file1.include" ); - project.addFile( "file2.exclude" ); - project.addFile( "file3.nottest" ); - project.addFile( "file4.txt" ); - project.addFile( "package/file1.include" ); - project.addFile( "package/file2.exclude" ); - project.addFile( "package/file3.nottest" ); - project.addFile( "package/file4.txt" ); - project.addFile( "notpackage/file1.include" ); - project.addFile( "notpackage/file2.exclude" ); - project.addFile( "notpackage/file3.nottest" ); - project.addFile( "notpackage/file4.txt" ); - project.addFile( "package/test/file1.txt" ); - project.addFile( "package/nottest/file2.txt" ); - project.addFile( "notpackage/test/file1.txt" ); - project.addFile( "notpackage/nottest/file.txt" ); + public void testResourceExclude() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceExclude"); + List resources = project.getBuild().getResources(); + + assertNotNull(mojo); + + project.addFile("file1.include"); + project.addFile("file2.exclude"); + project.addFile("file3.nottest"); + project.addFile("file4.txt"); + project.addFile("package/file1.include"); + project.addFile("package/file2.exclude"); + project.addFile("package/file3.nottest"); + project.addFile("package/file4.txt"); + project.addFile("notpackage/file1.include"); + project.addFile("notpackage/file2.exclude"); + project.addFile("notpackage/file3.nottest"); + project.addFile("notpackage/file4.txt"); + project.addFile("package/test/file1.txt"); + project.addFile("package/nottest/file2.txt"); + project.addFile("notpackage/test/file1.txt"); + project.addFile("notpackage/nottest/file.txt"); project.setupBuildEnvironment(); - project.addExclude( "**/*.exclude" ); - project.addExclude( "**/nottest*" ); - project.addExclude( "**/notest" ); - project.addExclude( "**/notpackage*" ); - project.addExclude( "**/notpackage*/**" ); - - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "buildFilters", Collections.emptyList() ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); + project.addExclude("**/*.exclude"); + project.addExclude("**/nottest*"); + project.addExclude("**/notest"); + project.addExclude("**/notpackage*"); + project.addExclude("**/notpackage*/**"); + + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject(mojo, "buildFilters", Collections.emptyList()); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); mojo.execute(); String resourcesDir = project.getOutputDirectory(); - assertTrue( FileUtils.fileExists( resourcesDir + "/package/test" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/file1.include" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/package/file1.include" ) ); - assertFalse( FileUtils.fileExists( resourcesDir + "/notpackage/file1.include" ) ); - assertFalse( FileUtils.fileExists( resourcesDir + "/notpackage/nottest/file.txt" ) ); + assertTrue(FileUtils.fileExists(resourcesDir + "/package/test")); + assertTrue(FileUtils.fileExists(resourcesDir + "/file1.include")); + assertTrue(FileUtils.fileExists(resourcesDir + "/package/file1.include")); + assertFalse(FileUtils.fileExists(resourcesDir + "/notpackage/file1.include")); + assertFalse(FileUtils.fileExists(resourcesDir + "/notpackage/nottest/file.txt")); } /** * @throws Exception */ - public void testResourceTargetPath() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourceTargetPath" ); - List resources = project.getBuild() - .getResources(); - - assertNotNull( mojo ); - - project.setTargetPath( "org/apache/maven/plugin/test" ); - - project.addFile( "file4.txt" ); - project.addFile( "package/file3.nottest" ); - project.addFile( "notpackage/file1.include" ); - project.addFile( "package/test/file1.txt" ); - project.addFile( "notpackage/test/file2.txt" ); + public void testResourceTargetPath() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceTargetPath"); + List resources = project.getBuild().getResources(); + + assertNotNull(mojo); + + project.setTargetPath("org/apache/maven/plugin/test"); + + project.addFile("file4.txt"); + project.addFile("package/file3.nottest"); + project.addFile("notpackage/file1.include"); + project.addFile("package/test/file1.txt"); + project.addFile("notpackage/test/file2.txt"); project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "buildFilters", Collections.emptyList() ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject(mojo, "buildFilters", Collections.emptyList()); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); mojo.execute(); String resourcesDir = project.getOutputDirectory(); - assertTrue( FileUtils.fileExists( resourcesDir + "/org/apache/maven/plugin/test/file4.txt" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/org/apache/maven/plugin/test/package/file3.nottest" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/org/apache/maven/plugin/test/notpackage/file1.include" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/org/apache/maven/plugin/test/package/test" ) ); - assertTrue( FileUtils.fileExists( resourcesDir + "/org/apache/maven/plugin/test/notpackage/test" ) ); + assertTrue(FileUtils.fileExists(resourcesDir + "/org/apache/maven/plugin/test/file4.txt")); + assertTrue(FileUtils.fileExists(resourcesDir + "/org/apache/maven/plugin/test/package/file3.nottest")); + assertTrue(FileUtils.fileExists(resourcesDir + "/org/apache/maven/plugin/test/notpackage/file1.include")); + assertTrue(FileUtils.fileExists(resourcesDir + "/org/apache/maven/plugin/test/package/test")); + assertTrue(FileUtils.fileExists(resourcesDir + "/org/apache/maven/plugin/test/notpackage/test")); } /** * @throws Exception */ - public void testResourceSystemProperties_Filtering() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourceSystemProperties_Filtering" ); - List resources = project.getBuild() - .getResources(); - - assertNotNull( mojo ); - - project.addFile( "file4.txt", "current-working-directory = ${user.dir}" ); - project.setResourceFiltering( 0, true ); + public void testResourceSystemProperties_Filtering() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceSystemProperties_Filtering"); + List resources = project.getBuild().getResources(); + + assertNotNull(mojo); + + project.addFile("file4.txt", "current-working-directory = ${user.dir}"); + project.setResourceFiltering(0, true); project.setupBuildEnvironment(); // setVariableValueToObject(mojo,"encoding","UTF-8"); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "buildFilters", Collections.emptyList() ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); - setVariableValueToObject( mojo, "escapeWindowsPaths", Boolean.TRUE ); - + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "buildFilters", Collections.emptyList()); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); + setVariableValueToObject(mojo, "escapeWindowsPaths", Boolean.TRUE); + MavenExecutionRequest request = new DefaultMavenExecutionRequest(); - request.setSystemProperties( System.getProperties() ); + request.setSystemProperties(System.getProperties()); - MavenSession mavenSession = new MavenSession( null, null, request, null ); - setVariableValueToObject( mojo, "session", mavenSession ); + MavenSession mavenSession = new MavenSession(null, null, request, null); + setVariableValueToObject(mojo, "session", mavenSession); mojo.execute(); String resourcesDir = project.getOutputDirectory(); - File userDir = new File( System.getProperty( "user.dir" ) ); - assertTrue( userDir.exists() ); + File userDir = new File(System.getProperty("user.dir")); + assertTrue(userDir.exists()); Properties props = new Properties(); - try ( FileInputStream inStream = new FileInputStream( new File( resourcesDir, "file4.txt" ) ) ) - { - props.load( inStream ); + try (FileInputStream inStream = new FileInputStream(new File(resourcesDir, "file4.txt"))) { + props.load(inStream); } - File fileFromFiltering = new File( props.getProperty( "current-working-directory" ) ); + File fileFromFiltering = new File(props.getProperty("current-working-directory")); - assertTrue( fileFromFiltering.getAbsolutePath() + " does not exist.", fileFromFiltering.exists() ); - assertEquals( userDir.getAbsolutePath(), fileFromFiltering.getAbsolutePath() ); + assertTrue(fileFromFiltering.getAbsolutePath() + " does not exist.", fileFromFiltering.exists()); + assertEquals(userDir.getAbsolutePath(), fileFromFiltering.getAbsolutePath()); } /** * @throws Exception */ - public void testResourceProjectProperties_Filtering() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourceProjectProperties_Filtering" ); - List resources = project.getBuild() - .getResources(); - - assertNotNull( mojo ); - - project.addFile( "file4.txt", "current working directory = ${user.dir}" ); - project.setResourceFiltering( 0, true ); - project.addProperty( "user.dir", "FPJ kami!!!" ); + public void testResourceProjectProperties_Filtering() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceProjectProperties_Filtering"); + List resources = project.getBuild().getResources(); + + assertNotNull(mojo); + + project.addFile("file4.txt", "current working directory = ${user.dir}"); + project.setResourceFiltering(0, true); + project.addProperty("user.dir", "FPJ kami!!!"); project.setupBuildEnvironment(); // setVariableValueToObject(mojo,"encoding","UTF-8"); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "buildFilters", Collections.emptyList() ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "buildFilters", Collections.emptyList()); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); mojo.execute(); String resourcesDir = project.getOutputDirectory(); String checkString = "current working directory = FPJ kami!!!"; - assertContent( resourcesDir + "/file4.txt", checkString ); + assertContent(resourcesDir + "/file4.txt", checkString); } /** * @throws Exception */ - public void testProjectProperty_Filtering_PropertyDestination() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); + public void testProjectProperty_Filtering_PropertyDestination() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); MavenProjectResourcesStub project = - new MavenProjectResourcesStub( "resourcePojectProperty_Filtering_PropertyDestination" ); - List resources = project.getBuild() - .getResources(); + new MavenProjectResourcesStub("resourcePojectProperty_Filtering_PropertyDestination"); + List resources = project.getBuild().getResources(); - assertNotNull( mojo ); + assertNotNull(mojo); - project.addFile( "file4.properties", "current working directory=${description}" ); - project.setResourceFiltering( 0, true ); + project.addFile("file4.properties", "current working directory=${description}"); + project.setResourceFiltering(0, true); project.setupBuildEnvironment(); // setup dummy property - project.setDescription( "c:\\\\org\\apache\\test" ); + project.setDescription("c:\\\\org\\apache\\test"); // setVariableValueToObject(mojo,"encoding","UTF-8"); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "buildFilters", Collections.emptyList() ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); - setVariableValueToObject( mojo, "escapeWindowsPaths", Boolean.TRUE ); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "buildFilters", Collections.emptyList()); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); + setVariableValueToObject(mojo, "escapeWindowsPaths", Boolean.TRUE); mojo.execute(); String resourcesDir = project.getOutputDirectory(); String checkString = "current working directory=c:\\\\org\\\\apache\\\\test"; - assertContent( resourcesDir + "/file4.properties", checkString ); + assertContent(resourcesDir + "/file4.properties", checkString); } /** * @throws Exception */ - public void testPropertyFiles_Filtering() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourcePropertyFiles_Filtering" ); - List resources = project.getBuild() - .getResources(); + public void testPropertyFiles_Filtering() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourcePropertyFiles_Filtering"); + List resources = project.getBuild().getResources(); LinkedList filterList = new LinkedList<>(); - assertNotNull( mojo ); + assertNotNull(mojo); - project.addFile( "file4.properties", "current working directory=${dir}" ); - project.addFile( "filter.properties", "dir:testdir" ); - project.setResourceFiltering( 0, true ); + project.addFile("file4.properties", "current working directory=${dir}"); + project.addFile("filter.properties", "dir:testdir"); + project.setResourceFiltering(0, true); project.setupBuildEnvironment(); - filterList.add( project.getResourcesDirectory() + "filter.properties" ); + filterList.add(project.getResourcesDirectory() + "filter.properties"); // setVariableValueToObject(mojo,"encoding","UTF-8"); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "buildFilters", filterList ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "buildFilters", filterList); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); mojo.execute(); String resourcesDir = project.getOutputDirectory(); String checkString = "current working directory=testdir"; - assertContent( resourcesDir + "/file4.properties", checkString ); + assertContent(resourcesDir + "/file4.properties", checkString); } /** * @throws Exception */ - public void testPropertyFiles_Extra() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourcePropertyFiles_Extra" ); - List resources = project.getBuild() - .getResources(); + public void testPropertyFiles_Extra() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourcePropertyFiles_Extra"); + List resources = project.getBuild().getResources(); LinkedList filterList = new LinkedList<>(); - assertNotNull( mojo ); + assertNotNull(mojo); - project.addFile( "extra.properties", "current working directory=${dir}" ); - project.addFile( "filter.properties", "dir:testdir" ); - project.setResourceFiltering( 0, true ); + project.addFile("extra.properties", "current working directory=${dir}"); + project.addFile("filter.properties", "dir:testdir"); + project.setResourceFiltering(0, true); project.setupBuildEnvironment(); - filterList.add( project.getResourcesDirectory() + "filter.properties" ); + filterList.add(project.getResourcesDirectory() + "filter.properties"); // setVariableValueToObject(mojo,"encoding","UTF-8"); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "filters", filterList ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "filters", filterList); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); mojo.execute(); String resourcesDir = project.getOutputDirectory(); String checkString = "current working directory=testdir"; - assertContent( resourcesDir + "/extra.properties", checkString ); + assertContent(resourcesDir + "/extra.properties", checkString); } /** * @throws Exception */ - public void testPropertyFiles_MainAndExtra() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourcePropertyFiles_MainAndExtra" ); - List resources = project.getBuild() - .getResources(); + public void testPropertyFiles_MainAndExtra() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourcePropertyFiles_MainAndExtra"); + List resources = project.getBuild().getResources(); LinkedList filterList = new LinkedList<>(); LinkedList extraFilterList = new LinkedList<>(); - assertNotNull( mojo ); + assertNotNull(mojo); - project.addFile( "main-extra.properties", "current working directory=${dir}; old working directory=${dir2}" ); - project.addFile( "filter.properties", "dir:testdir" ); - project.addFile( "extra-filter.properties", "dir2:testdir2" ); - project.setResourceFiltering( 0, true ); + project.addFile("main-extra.properties", "current working directory=${dir}; old working directory=${dir2}"); + project.addFile("filter.properties", "dir:testdir"); + project.addFile("extra-filter.properties", "dir2:testdir2"); + project.setResourceFiltering(0, true); project.cleanBuildEnvironment(); project.setupBuildEnvironment(); - filterList.add( project.getResourcesDirectory() + "filter.properties" ); - extraFilterList.add( project.getResourcesDirectory() + "extra-filter.properties" ); + filterList.add(project.getResourcesDirectory() + "filter.properties"); + extraFilterList.add(project.getResourcesDirectory() + "extra-filter.properties"); // setVariableValueToObject(mojo,"encoding","UTF-8"); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "buildFilters", filterList ); - setVariableValueToObject( mojo, "filters", extraFilterList ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "buildFilters", filterList); + setVariableValueToObject(mojo, "filters", extraFilterList); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); mojo.execute(); String resourcesDir = project.getOutputDirectory(); String checkString = "current working directory=testdir; old working directory=testdir2"; - File file = new File( resourcesDir, "main-extra.properties" ); - assertContent( file.getAbsolutePath(), checkString ); + File file = new File(resourcesDir, "main-extra.properties"); + assertContent(file.getAbsolutePath(), checkString); } /** @@ -560,134 +516,118 @@ public void testPropertyFiles_MainAndExtra() * * @throws Exception */ - public void testPropertyFiles_Filtering_TokensInFilters() - throws Exception - { - final File testPom = new File( getBasedir(), defaultPomFilePath ); - final ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); + public void testPropertyFiles_Filtering_TokensInFilters() throws Exception { + final File testPom = new File(getBasedir(), defaultPomFilePath); + final ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); final MavenProjectResourcesStub project = - new MavenProjectResourcesStub( "resourcePropertyFiles_Filtering_TokensInFilters" ); - final List resources = project.getBuild() - .getResources(); + new MavenProjectResourcesStub("resourcePropertyFiles_Filtering_TokensInFilters"); + final List resources = project.getBuild().getResources(); final LinkedList filterList = new LinkedList<>(); - assertNotNull( mojo ); + assertNotNull(mojo); - project.addFile( "file4.properties", "current working directory=${filter.token}" ); - project.addFile( "filter.properties", "filter.token=${pom-property}" ); - project.setResourceFiltering( 0, true ); - project.addProperty( "pom-property", "foobar" ); + project.addFile("file4.properties", "current working directory=${filter.token}"); + project.addFile("filter.properties", "filter.token=${pom-property}"); + project.setResourceFiltering(0, true); + project.addProperty("pom-property", "foobar"); project.setupBuildEnvironment(); - filterList.add( project.getResourcesDirectory() + "filter.properties" ); + filterList.add(project.getResourcesDirectory() + "filter.properties"); // setVariableValueToObject(mojo,"encoding","UTF-8"); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "buildFilters", filterList ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "buildFilters", filterList); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); mojo.execute(); final String resourcesDir = project.getOutputDirectory(); final String checkString = "current working directory=foobar"; - assertContent( resourcesDir + "/file4.properties", checkString ); + assertContent(resourcesDir + "/file4.properties", checkString); } - public void testWindowsPathEscapingDisabled() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "windows-paths" ); - List resources = project.getBuild() - .getResources(); + public void testWindowsPathEscapingDisabled() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("windows-paths"); + List resources = project.getBuild().getResources(); - assertNotNull( mojo ); + assertNotNull(mojo); - project.getProperties() - .setProperty( "basePath", "C:\\Users\\Administrator" ); - project.getProperties() - .setProperty( "docsPath", "${basePath}\\Documents" ); + project.getProperties().setProperty("basePath", "C:\\Users\\Administrator"); + project.getProperties().setProperty("docsPath", "${basePath}\\Documents"); - project.addFile( "path-listing.txt", "base path is ${basePath}\ndocuments path is ${docsPath}" ); - project.setResourceFiltering( 0, true ); + project.addFile("path-listing.txt", "base path is ${basePath}\ndocuments path is ${docsPath}"); + project.setResourceFiltering(0, true); project.cleanBuildEnvironment(); project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "buildFilters", Collections.emptyList() ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); - setVariableValueToObject( mojo, "escapeWindowsPaths", Boolean.FALSE ); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "buildFilters", Collections.emptyList()); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); + setVariableValueToObject(mojo, "escapeWindowsPaths", Boolean.FALSE); mojo.execute(); String resourcesDir = project.getOutputDirectory(); - assertTrue( FileUtils.fileExists( new File( resourcesDir, "path-listing.txt" ).getAbsolutePath() ) ); + assertTrue(FileUtils.fileExists(new File(resourcesDir, "path-listing.txt").getAbsolutePath())); - assertEquals( "base path is C:\\Users\\Administrator\ndocuments path is C:\\Users\\Administrator\\Documents", - FileUtils.fileRead( new File( resourcesDir, "path-listing.txt" ) ) ); + assertEquals( + "base path is C:\\Users\\Administrator\ndocuments path is C:\\Users\\Administrator\\Documents", + FileUtils.fileRead(new File(resourcesDir, "path-listing.txt"))); } - public void testWindowsPathEscapingEnabled() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom ); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "windows-paths" ); - List resources = project.getBuild() - .getResources(); + public void testWindowsPathEscapingEnabled() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("windows-paths"); + List resources = project.getBuild().getResources(); - assertNotNull( mojo ); + assertNotNull(mojo); - project.getProperties() - .setProperty( "basePath", "C:\\Users\\Administrator" ); - project.getProperties() - .setProperty( "docsPath", "${basePath}\\Documents" ); + project.getProperties().setProperty("basePath", "C:\\Users\\Administrator"); + project.getProperties().setProperty("docsPath", "${basePath}\\Documents"); - project.addFile( "path-listing.txt", "base path is ${basePath}\ndocuments path is ${docsPath}" ); - project.setResourceFiltering( 0, true ); + project.addFile("path-listing.txt", "base path is ${basePath}\ndocuments path is ${docsPath}"); + project.setResourceFiltering(0, true); project.cleanBuildEnvironment(); project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild() - .getOutputDirectory() ) ); - setVariableValueToObject( mojo, "buildFilters", Collections.emptyList() ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); + setVariableValueToObject(mojo, "buildFilters", Collections.emptyList()); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); - setVariableValueToObject( mojo, "escapeWindowsPaths", Boolean.TRUE ); + setVariableValueToObject(mojo, "escapeWindowsPaths", Boolean.TRUE); mojo.execute(); String resourcesDir = project.getOutputDirectory(); - assertTrue( FileUtils.fileExists( new File( resourcesDir, "path-listing.txt" ).getAbsolutePath() ) ); + assertTrue(FileUtils.fileExists(new File(resourcesDir, "path-listing.txt").getAbsolutePath())); assertEquals( - "base path is C:\\\\Users\\\\Administrator\ndocuments path is C:\\\\Users\\\\Administrator\\\\Documents", - FileUtils.fileRead( new File( resourcesDir, "path-listing.txt" ) ) ); + "base path is C:\\\\Users\\\\Administrator\ndocuments path is C:\\\\Users\\\\Administrator\\\\Documents", + FileUtils.fileRead(new File(resourcesDir, "path-listing.txt"))); } /** * Ensures the file exists and its first line equals the given data. */ - private void assertContent( String fileName, String data ) - throws IOException - { - assertTrue( FileUtils.fileExists( fileName ) ); - try( BufferedReader reader = new BufferedReader( new FileReader( fileName ) ) ) - { - assertEquals( data, reader.readLine() ); + private void assertContent(String fileName, String data) throws IOException { + assertTrue(FileUtils.fileExists(fileName)); + try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) { + assertEquals(data, reader.readLine()); } } - } diff --git a/src/test/java/org/apache/maven/plugins/resources/TestResourcesTest.java b/src/test/java/org/apache/maven/plugins/resources/TestResourcesTest.java index 28948bf..13acc44 100644 --- a/src/test/java/org/apache/maven/plugins/resources/TestResourcesTest.java +++ b/src/test/java/org/apache/maven/plugins/resources/TestResourcesTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.resources; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.resources; import java.io.File; import java.util.Collections; @@ -28,14 +27,10 @@ import org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub; import org.codehaus.plexus.util.FileUtils; -public class TestResourcesTest - extends AbstractMojoTestCase -{ - protected final static String defaultPomFilePath = "/target/test-classes/unit/resources-test/plugin-config.xml"; +public class TestResourcesTest extends AbstractMojoTestCase { + protected static final String defaultPomFilePath = "/target/test-classes/unit/resources-test/plugin-config.xml"; - protected void setUp() - throws Exception - { + protected void setUp() throws Exception { super.setUp(); } @@ -44,48 +39,45 @@ protected void setUp() * * @throws Exception */ - public void testHarnessEnvironment() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "testResources", testPom ); + public void testHarnessEnvironment() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + ResourcesMojo mojo = (ResourcesMojo) lookupMojo("testResources", testPom); - assertNotNull( mojo ); + assertNotNull(mojo); } /** * @throws Exception */ - public void testTestResourceDirectoryCreation() - throws Exception - { - File testPom = new File( getBasedir(), defaultPomFilePath ); - TestResourcesMojo mojo = (TestResourcesMojo) lookupMojo( "testResources", testPom ); - MavenProjectResourcesStub project = new MavenProjectResourcesStub( "testResourceDirectoryStructure" ); + public void testTestResourceDirectoryCreation() throws Exception { + File testPom = new File(getBasedir(), defaultPomFilePath); + TestResourcesMojo mojo = (TestResourcesMojo) lookupMojo("testResources", testPom); + MavenProjectResourcesStub project = new MavenProjectResourcesStub("testResourceDirectoryStructure"); List resources = project.getBuild().getResources(); - assertNotNull( mojo ); + assertNotNull(mojo); - project.addFile( "file4.txt" ); - project.addFile( "package/file3.nottest" ); - project.addFile( "notpackage/file1.include" ); - project.addFile( "package/test/file1.txt" ); - project.addFile( "notpackage/test/file2.txt" ); + project.addFile("file4.txt"); + project.addFile("package/file3.nottest"); + project.addFile("notpackage/file1.include"); + project.addFile("package/test/file1.txt"); + project.addFile("notpackage/test/file2.txt"); project.setupBuildEnvironment(); - setVariableValueToObject( mojo, "project", project ); - setVariableValueToObject( mojo, "resources", resources ); - setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getTestOutputDirectory() ) ); - setVariableValueToObject( mojo, "buildFilters", Collections.emptyList() ); - setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE ); + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "resources", resources); + setVariableValueToObject( + mojo, "outputDirectory", new File(project.getBuild().getTestOutputDirectory())); + setVariableValueToObject(mojo, "buildFilters", Collections.emptyList()); + setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE); mojo.execute(); String resorucesDir = project.getTestOutputDirectory(); - assertTrue( FileUtils.fileExists( resorucesDir + "/file4.txt" ) ); - assertTrue( FileUtils.fileExists( resorucesDir + "/package/file3.nottest" ) ); - assertTrue( FileUtils.fileExists( resorucesDir + "/notpackage/file1.include" ) ); - assertTrue( FileUtils.fileExists( resorucesDir + "/package/test" ) ); - assertTrue( FileUtils.fileExists( resorucesDir + "/notpackage/test" ) ); + assertTrue(FileUtils.fileExists(resorucesDir + "/file4.txt")); + assertTrue(FileUtils.fileExists(resorucesDir + "/package/file3.nottest")); + assertTrue(FileUtils.fileExists(resorucesDir + "/notpackage/file1.include")); + assertTrue(FileUtils.fileExists(resorucesDir + "/package/test")); + assertTrue(FileUtils.fileExists(resorucesDir + "/notpackage/test")); } } diff --git a/src/test/java/org/apache/maven/plugins/resources/filters/ItFilter.java b/src/test/java/org/apache/maven/plugins/resources/filters/ItFilter.java index a1865e4..c0ebd2d 100644 --- a/src/test/java/org/apache/maven/plugins/resources/filters/ItFilter.java +++ b/src/test/java/org/apache/maven/plugins/resources/filters/ItFilter.java @@ -39,50 +39,42 @@ */ @Singleton @Named("itFilter") -public class ItFilter - implements MavenResourcesFiltering -{ +public class ItFilter implements MavenResourcesFiltering { - - /** + /** * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#getDefaultNonFilteredFileExtensions() */ - public List getDefaultNonFilteredFileExtensions() - { + public List getDefaultNonFilteredFileExtensions() { // no op return Collections.emptyList(); } - /** + /** * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#filteredFileExtension(String, List) */ - public boolean filteredFileExtension( String fileName, List userNonFilteredFileExtensions ) - { + public boolean filteredFileExtension(String fileName, List userNonFilteredFileExtensions) { return false; } - /** + /** * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#filterResources(org.apache.maven.shared.filtering.MavenResourcesExecution) */ - public void filterResources( MavenResourcesExecution mavenResourcesExecution ) - throws MavenFilteringException - { + public void filterResources(MavenResourcesExecution mavenResourcesExecution) throws MavenFilteringException { System.out.println("ItFilter filterResources"); - try - { - File f = new File( mavenResourcesExecution.getOutputDirectory(), "foo.txt" ); + try { + File f = new File(mavenResourcesExecution.getOutputDirectory(), "foo.txt"); List lines = new ArrayList<>(); - - lines.add( "foo" ); - lines.add( "version="+mavenResourcesExecution.getMavenProject().getVersion() ); - lines.add( "toto=" + mavenResourcesExecution.getMavenSession().getSystemProperties().getProperty( "toto" ) ); - FileUtils.writeLines( f, lines ); - } - catch ( IOException e ) - { - throw new MavenFilteringException( e.getMessage(), e ); - } + lines.add("foo"); + lines.add("version=" + mavenResourcesExecution.getMavenProject().getVersion()); + lines.add("toto=" + + mavenResourcesExecution + .getMavenSession() + .getSystemProperties() + .getProperty("toto")); + FileUtils.writeLines(f, lines); + } catch (IOException e) { + throw new MavenFilteringException(e.getMessage(), e); + } } - } diff --git a/src/test/java/org/apache/maven/plugins/resources/stub/MavenProjectBasicStub.java b/src/test/java/org/apache/maven/plugins/resources/stub/MavenProjectBasicStub.java index 8893cbf..77ee4f3 100644 --- a/src/test/java/org/apache/maven/plugins/resources/stub/MavenProjectBasicStub.java +++ b/src/test/java/org/apache/maven/plugins/resources/stub/MavenProjectBasicStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.resources.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.resources.stub; import java.io.File; import java.util.Properties; @@ -26,9 +25,7 @@ import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.FileUtils; -public class MavenProjectBasicStub - extends MavenProjectStub -{ +public class MavenProjectBasicStub extends MavenProjectStub { protected String identifier; protected String testRootDir; @@ -37,74 +34,59 @@ public class MavenProjectBasicStub protected String description; - public MavenProjectBasicStub( String id ) - { + public MavenProjectBasicStub(String id) { properties = new Properties(); identifier = id; testRootDir = PlexusTestCase.getBasedir() + "/target/test-classes/unit/test-dir/" + identifier; - if ( !FileUtils.fileExists( testRootDir ) ) - { - FileUtils.mkdir( testRootDir ); + if (!FileUtils.fileExists(testRootDir)) { + FileUtils.mkdir(testRootDir); } } - public String getName() - { + public String getName() { return "Test Project " + identifier; } - public void setDescription( String desc ) - { + public void setDescription(String desc) { description = desc; } - public String getDescription() - { - if ( description == null ) - { + public String getDescription() { + if (description == null) { return "this is a test project"; - } - else - { + } else { return description; } } - public File getBasedir() - { + public File getBasedir() { // create an isolated environment // see setupTestEnvironment for details - return new File( testRootDir ); + return new File(testRootDir); } - public String getGroupId() - { + public String getGroupId() { return "org.apache.maven.plugin.test"; } - public String getArtifactId() - { + public String getArtifactId() { return "maven-resource-plugin-test#" + identifier; } - public String getPackaging() - { + public String getPackaging() { return "org.apache.maven.plugin.test"; } - public String getVersion() - { + public String getVersion() { return identifier; } - public void addProperty( String key, String value ) - { - properties.put( key, value ); + public void addProperty(String key, String value) { + properties.put(key, value); } - public Properties getProperties() - { + public Properties getProperties() { return properties; } } diff --git a/src/test/java/org/apache/maven/plugins/resources/stub/MavenProjectBuildStub.java b/src/test/java/org/apache/maven/plugins/resources/stub/MavenProjectBuildStub.java index a3712c9..490fcc9 100644 --- a/src/test/java/org/apache/maven/plugins/resources/stub/MavenProjectBuildStub.java +++ b/src/test/java/org/apache/maven/plugins/resources/stub/MavenProjectBuildStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.resources.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.resources.stub; import java.io.File; import java.io.FileOutputStream; @@ -28,9 +27,7 @@ import org.apache.maven.model.Build; import org.codehaus.plexus.util.FileUtils; -public class MavenProjectBuildStub - extends MavenProjectBasicStub -{ +public class MavenProjectBuildStub extends MavenProjectBasicStub { protected Build build; protected String srcDirectory; @@ -57,10 +54,8 @@ public class MavenProjectBuildStub protected HashMap dataMap; - public MavenProjectBuildStub( String key ) - throws Exception - { - super( key ); + public MavenProjectBuildStub(String key) throws Exception { + super(key); build = new Build(); fileList = new ArrayList<>(); @@ -69,58 +64,47 @@ public MavenProjectBuildStub( String key ) setupBuild(); } - public void addDirectory( String name ) - { - if ( isValidPath( name ) ) - { - directoryList.add( name ); + public void addDirectory(String name) { + if (isValidPath(name)) { + directoryList.add(name); } } - public void setOutputDirectory( String dir ) - { + public void setOutputDirectory(String dir) { outputDirectory = buildDirectory + "/" + dir; - build.setOutputDirectory( outputDirectory ); + build.setOutputDirectory(outputDirectory); } - public void addFile( String name ) - { - if ( isValidPath( name ) ) - { - fileList.add( name ); + public void addFile(String name) { + if (isValidPath(name)) { + fileList.add(name); } } - public void addFile( String name, String data ) - { - File fileName = new File( name ); + public void addFile(String name, String data) { + File fileName = new File(name); - addFile( name ); - dataMap.put( fileName.getName(), data ); + addFile(name); + dataMap.put(fileName.getName(), data); } - public String getOutputDirectory() - { + public String getOutputDirectory() { return outputDirectory; } - public String getTestOutputDirectory() - { + public String getTestOutputDirectory() { return testOutputDirectory; } - public String getResourcesDirectory() - { + public String getResourcesDirectory() { return resourcesDirectory; } - public String getTestResourcesDirectory() - { + public String getTestResourcesDirectory() { return testResourcesDirectory; } - public Build getBuild() - { + public Build getBuild() { return build; } @@ -133,20 +117,17 @@ public Build getBuild() * @param path * @return */ - private boolean isValidPath( String path ) - { + private boolean isValidPath(String path) { boolean bRetVal = true; - if ( path.startsWith( "c:" ) || path.startsWith( ".." ) || path.startsWith( "/" ) || path.startsWith( "\\" ) ) - { + if (path.startsWith("c:") || path.startsWith("..") || path.startsWith("/") || path.startsWith("\\")) { bRetVal = false; } return bRetVal; } - private void setupBuild() - { + private void setupBuild() { // check getBasedir method for the exact path // we need to recreate the dir structure in // an isolated environment @@ -157,142 +138,114 @@ private void setupBuild() resourcesDirectory = srcDirectory + "/main/resources/"; testResourcesDirectory = srcDirectory + "/test/resources/"; - build.setDirectory( buildDirectory ); - build.setOutputDirectory( outputDirectory ); - build.setTestOutputDirectory( testOutputDirectory ); + build.setDirectory(buildDirectory); + build.setOutputDirectory(outputDirectory); + build.setTestOutputDirectory(testOutputDirectory); } - public void cleanBuildEnvironment() - throws Exception - { - if ( FileUtils.fileExists( resourcesDirectory ) ) - { - FileUtils.deleteDirectory( resourcesDirectory ); + public void cleanBuildEnvironment() throws Exception { + if (FileUtils.fileExists(resourcesDirectory)) { + FileUtils.deleteDirectory(resourcesDirectory); } - if ( FileUtils.fileExists( testResourcesDirectory ) ) - { - FileUtils.deleteDirectory( testResourcesDirectory ); + if (FileUtils.fileExists(testResourcesDirectory)) { + FileUtils.deleteDirectory(testResourcesDirectory); } - if ( FileUtils.fileExists( outputDirectory ) ) - { - FileUtils.deleteDirectory( outputDirectory ); + if (FileUtils.fileExists(outputDirectory)) { + FileUtils.deleteDirectory(outputDirectory); } - if ( FileUtils.fileExists( testOutputDirectory ) ) - { - FileUtils.deleteDirectory( testOutputDirectory ); + if (FileUtils.fileExists(testOutputDirectory)) { + FileUtils.deleteDirectory(testOutputDirectory); } } - public void setupBuildEnvironment() - throws Exception - { + public void setupBuildEnvironment() throws Exception { // populate dummy resources and dummy test resources // setup src dir - if ( !FileUtils.fileExists( resourcesDirectory ) ) - { - FileUtils.mkdir( resourcesDirectory ); + if (!FileUtils.fileExists(resourcesDirectory)) { + FileUtils.mkdir(resourcesDirectory); } - if ( !FileUtils.fileExists( testResourcesDirectory ) ) - { - FileUtils.mkdir( testResourcesDirectory ); + if (!FileUtils.fileExists(testResourcesDirectory)) { + FileUtils.mkdir(testResourcesDirectory); } - createDirectories( resourcesDirectory, testResourcesDirectory ); - createFiles( resourcesDirectory, testResourcesDirectory ); + createDirectories(resourcesDirectory, testResourcesDirectory); + createFiles(resourcesDirectory, testResourcesDirectory); // setup target dir - if ( !FileUtils.fileExists( outputDirectory ) ) - { - FileUtils.mkdir( outputDirectory ); + if (!FileUtils.fileExists(outputDirectory)) { + FileUtils.mkdir(outputDirectory); } - if ( !FileUtils.fileExists( testOutputDirectory ) ) - { - FileUtils.mkdir( testOutputDirectory ); + if (!FileUtils.fileExists(testOutputDirectory)) { + FileUtils.mkdir(testOutputDirectory); } } - private void createDirectories( String parent, String testparent ) - { + private void createDirectories(String parent, String testparent) { File currentDirectory; - for ( String directory : directoryList ) - { - currentDirectory = new File( parent, "/" + directory ); + for (String directory : directoryList) { + currentDirectory = new File(parent, "/" + directory); - if ( !currentDirectory.exists() ) - { + if (!currentDirectory.exists()) { currentDirectory.mkdirs(); } // duplicate dir structure in test resources - currentDirectory = new File( testparent, "/" + directory ); + currentDirectory = new File(testparent, "/" + directory); - if ( !currentDirectory.exists() ) - { + if (!currentDirectory.exists()) { currentDirectory.mkdirs(); } } } - private void createFiles( String parent, String testparent ) throws IOException - { + private void createFiles(String parent, String testparent) throws IOException { File currentFile; - for ( String file : fileList ) - { - currentFile = new File( parent, file ); + for (String file : fileList) { + currentFile = new File(parent, file); // create the necessary parent directories // before we create the files - if ( !currentFile.getParentFile().exists() ) - { + if (!currentFile.getParentFile().exists()) { currentFile.getParentFile().mkdirs(); } - if ( !currentFile.exists() ) - { - try - { + if (!currentFile.exists()) { + try { currentFile.createNewFile(); - populateFile( currentFile ); - } - catch ( IOException io ) - { - //TODO: handle exception + populateFile(currentFile); + } catch (IOException io) { + // TODO: handle exception } } // duplicate file in test resources - currentFile = new File( testparent, file ); + currentFile = new File(testparent, file); - if ( !currentFile.getParentFile().exists() ) - { + if (!currentFile.getParentFile().exists()) { currentFile.getParentFile().mkdirs(); } - if ( !currentFile.exists() ) - { + if (!currentFile.exists()) { currentFile.createNewFile(); - populateFile( currentFile ); + populateFile(currentFile); } } } - private void populateFile( File file ) throws IOException - { - String data = dataMap.get( file.getName() ); + private void populateFile(File file) throws IOException { + String data = dataMap.get(file.getName()); - if ( ( data != null ) && file.exists() ) - { - try ( FileOutputStream outputStream = new FileOutputStream( file ) ) - { - outputStream.write( data.getBytes() ); + if ((data != null) && file.exists()) { + try (FileOutputStream outputStream = new FileOutputStream(file)) { + outputStream.write(data.getBytes()); } } } diff --git a/src/test/java/org/apache/maven/plugins/resources/stub/MavenProjectResourcesStub.java b/src/test/java/org/apache/maven/plugins/resources/stub/MavenProjectResourcesStub.java index b55ef71..e0c5420 100644 --- a/src/test/java/org/apache/maven/plugins/resources/stub/MavenProjectResourcesStub.java +++ b/src/test/java/org/apache/maven/plugins/resources/stub/MavenProjectResourcesStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.resources.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,108 +16,91 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.resources.stub; import java.io.File; import org.apache.maven.model.Resource; -public class MavenProjectResourcesStub - extends MavenProjectBuildStub -{ - +public class MavenProjectResourcesStub extends MavenProjectBuildStub { + private File baseDir; - public MavenProjectResourcesStub( String id ) - throws Exception - { - super( id ); + public MavenProjectResourcesStub(String id) throws Exception { + super(id); setupResources(); setupTestResources(); } - public void addInclude( String pattern ) - { - build.getResources().get( 0 ).addInclude( pattern ); + public void addInclude(String pattern) { + build.getResources().get(0).addInclude(pattern); } - public void addExclude( String pattern ) - { - build.getResources().get( 0 ).addExclude( pattern ); + public void addExclude(String pattern) { + build.getResources().get(0).addExclude(pattern); } - public void addTestInclude( String pattern ) - { - build.getTestResources().get( 0 ).addInclude( pattern ); + public void addTestInclude(String pattern) { + build.getTestResources().get(0).addInclude(pattern); } - public void addTestExclude( String pattern ) - { - build.getTestResources().get( 0 ).addExclude( pattern ); + public void addTestExclude(String pattern) { + build.getTestResources().get(0).addExclude(pattern); } - public void setTargetPath( String path ) - { - build.getResources().get( 0 ).setTargetPath( path ); + public void setTargetPath(String path) { + build.getResources().get(0).setTargetPath(path); } - public void setTestTargetPath( String path ) - { - build.getTestResources().get( 0 ).setTargetPath( path ); + public void setTestTargetPath(String path) { + build.getTestResources().get(0).setTargetPath(path); } - public void setDirectory( String dir ) - { - build.getResources().get( 0 ).setDirectory( dir ); + public void setDirectory(String dir) { + build.getResources().get(0).setDirectory(dir); } - public void setTestDirectory( String dir ) - { - build.getTestResources().get( 0 ).setDirectory( dir ); + public void setTestDirectory(String dir) { + build.getTestResources().get(0).setDirectory(dir); } - public void setResourceFiltering( int nIndex, boolean filter ) - { - if ( build.getResources().size() > nIndex ) - { - build.getResources().get( nIndex ).setFiltering( filter ); + public void setResourceFiltering(int nIndex, boolean filter) { + if (build.getResources().size() > nIndex) { + build.getResources().get(nIndex).setFiltering(filter); } } - private void setupResources() - { + private void setupResources() { Resource resource = new Resource(); // see MavenProjectBasicStub for details // of getBasedir // setup default resources - resource.setDirectory( getBasedir().getPath() + "/src/main/resources" ); - resource.setFiltering( false ); - resource.setTargetPath( null ); - build.addResource( resource ); + resource.setDirectory(getBasedir().getPath() + "/src/main/resources"); + resource.setFiltering(false); + resource.setTargetPath(null); + build.addResource(resource); } - private void setupTestResources() - { + private void setupTestResources() { Resource resource = new Resource(); // see MavenProjectBasicStub for details // of getBasedir // setup default test resources - resource.setDirectory( getBasedir().getPath() + "/src/test/resources" ); - resource.setFiltering( false ); - resource.setTargetPath( null ); - build.addTestResource( resource ); + resource.setDirectory(getBasedir().getPath() + "/src/test/resources"); + resource.setFiltering(false); + resource.setTargetPath(null); + build.addTestResource(resource); } - public File getBaseDir() - { + public File getBaseDir() { return baseDir == null ? super.getBasedir() : baseDir; } - public void setBaseDir( File baseDir ) - { + public void setBaseDir(File baseDir) { this.baseDir = baseDir; } }