------ Using Maven File Management API In A MOJO ------ Vincent Siveton ------ November 2007 ------ ~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html Using Maven File Management API In A MOJO This part explains how to use the Maven File Management API in a Maven Plugin. * Add File Management API dependency The first step is to add the File Management API as a Maven dependency, i.e. in the <<>>: +-----+ ... org.apache.maven.shared file-management ${project.version} ... ... +-----+ * Add FileSet in a MOJO The second step is to create your MOJO and add a <<>> object: +-----+ /** * My MOJO */ @Mojo( name = "myGoal" ) public class MyMojo extends AbstractMojo { /** * A list of fileSet rules to select files and directories. */ @Parameter private FileSet[] filesets; /** * A specific fileSet rule to select files and directories. */ @Parameter private FileSet fileset; ... } +-----+ To use the <<>> object, you need to instantiate the <<>>. +-----+ FileSetManager fileSetManager = new FileSetManager(); String[] includedFiles = fileSetManager.getIncludedFiles( fileset ); String[] includedDir = fileSetManager.getIncludedDirectories( fileset ); String[] excludedFiles = fileSetManager.getExcludedFiles( fileset ); String[] excludedDir = fileSetManager.getExcludedDirectories( fileset ); fileSetManager.delete( fileset ); +-----+ * Configure your Maven Plugin The last step is the Maven Plugin configuration. +-----+ ... your-plugin-groupId your-plugin-artifactId your-plugin-version some/relative/path **/*.txt **/log.log false some/relative/path **/*.txt **/log.log false ... ... ... +-----+