Skip to content

Commit 2d5a4fc

Browse files
committed
initial version of the copy-rename-maven-plugin
1 parent 20356e4 commit 2d5a4fc

File tree

10 files changed

+868
-1
lines changed

10 files changed

+868
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ pom.xml.releaseBackup
44
pom.xml.versionsBackup
55
pom.xml.next
66
release.properties
7+
.project
8+
.classpath
9+
.settings/

README.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
1-
rename-maven-plugin
1+
copy-rename-maven-plugin
22
===================
3+
4+
The copy-rename-maven-plugin helps in copying files or renaming files or directories during the Maven build lifecycle.
5+
6+
[![Build Status](https://buildhive.cloudbees.com/job/ianbrandt/job/copy-rename-maven-plugin/badge/icon)](https://buildhive.cloudbees.com/job/ianbrandt/job/copy-rename-maven-plugin/)
7+
8+
9+
### How do I use it? ###
10+
11+
Had over to the [Project Website](http://coderplus.github.io/copy-rename-maven-plugin/) for usage instructions
12+
13+
### How can I help the project? ###
14+
15+
Thanks for asking...
16+
17+
* If you use this plugin
18+
* Test this out. [File an issue](https://github.com/coderplus/copy-rename-maven-plugin/issues) if it doesn't work for you. File an issue if you think it should do something more, or something different.
19+
* If you would like to contribute
20+
* Do let me know and you can always fork the project.
21+

pom.xml

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="ISO-8859-1"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>org.sonatype.oss</groupId>
8+
<artifactId>oss-parent</artifactId>
9+
<version>9</version>
10+
</parent>
11+
12+
<groupId>com.coderplus.maven.plugins</groupId>
13+
<artifactId>copy-rename-maven-plugin</artifactId>
14+
<version>1.0-SNAPSHOT</version>
15+
<packaging>maven-plugin</packaging>
16+
17+
<name>Copy Rename Maven Plugin</name>
18+
<url>http://coderplus.github.io/copy-rename-maven-plugin</url>
19+
<description>This plugin helps in copying files or renaming files or directories during the Maven build lifecycle.</description>
20+
<inceptionYear>2014</inceptionYear>
21+
22+
<licenses>
23+
<license>
24+
<name>MIT License</name>
25+
<url>http://www.opensource.org/licenses/mit-license.php</url>
26+
<distribution>repo</distribution>
27+
</license>
28+
</licenses>
29+
30+
<developers>
31+
<developer>
32+
<name>Aneesh Joseph</name>
33+
<email>admin@coderplus.com</email>
34+
<roles>
35+
<role>Developer</role>
36+
</roles>
37+
</developer>
38+
</developers>
39+
40+
<properties>
41+
<maven.version>2.0.9</maven.version>
42+
<maven.plugin.plugin.version>3.2</maven.plugin.plugin.version>
43+
<maven.compiler.source>1.5</maven.compiler.source>
44+
<maven.compiler.target>1.5</maven.compiler.target>
45+
</properties>
46+
47+
<prerequisites>
48+
<maven>${maven.version}</maven>
49+
</prerequisites>
50+
51+
<scm>
52+
<connection>scm:git:git@github.com:coderplus/copy-rename-maven-plugin.git</connection>
53+
<url>scm:git:git@github.com:coderplus/copy-rename-maven-plugin.git</url>
54+
<developerConnection>scm:git:git@github.com:coderplus/copy-rename-maven-plugin.git</developerConnection>
55+
</scm>
56+
57+
<issueManagement>
58+
<url>https://github.com/coderplus/m2e-maven-dependency-plugin/issues</url>
59+
</issueManagement>
60+
61+
62+
<dependencies>
63+
<dependency>
64+
<groupId>org.apache.maven</groupId>
65+
<artifactId>maven-model</artifactId>
66+
<version>${maven.version}</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.apache.maven</groupId>
70+
<artifactId>maven-project</artifactId>
71+
<version>${maven.version}</version>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.apache.maven</groupId>
75+
<artifactId>maven-core</artifactId>
76+
<version>${maven.version}</version>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.apache.maven</groupId>
80+
<artifactId>maven-plugin-api</artifactId>
81+
<version>${maven.version}</version>
82+
</dependency>
83+
<dependency>
84+
<groupId>org.apache.maven</groupId>
85+
<artifactId>maven-artifact</artifactId>
86+
<version>${maven.version}</version>
87+
</dependency>
88+
<dependency>
89+
<groupId>org.apache.maven.plugin-tools</groupId>
90+
<artifactId>maven-plugin-annotations</artifactId>
91+
<version>${maven.plugin.plugin.version}</version>
92+
<scope>provided</scope>
93+
</dependency>
94+
<dependency>
95+
<groupId>org.codehaus.plexus</groupId>
96+
<artifactId>plexus-utils</artifactId>
97+
<version>1.5.8</version>
98+
</dependency>
99+
<dependency>
100+
<groupId>org.sonatype.plexus</groupId>
101+
<artifactId>plexus-build-api</artifactId>
102+
<version>0.0.7</version>
103+
</dependency>
104+
</dependencies>
105+
106+
<build>
107+
<pluginManagement>
108+
<plugins>
109+
<plugin>
110+
<groupId>org.apache.maven.plugins</groupId>
111+
<artifactId>maven-plugin-plugin</artifactId>
112+
<version>${maven.plugin.plugin.version}</version>
113+
</plugin>
114+
</plugins>
115+
</pluginManagement>
116+
<plugins>
117+
<plugin>
118+
<groupId>org.apache.maven.plugins</groupId>
119+
<artifactId>maven-plugin-plugin</artifactId>
120+
<configuration>
121+
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
122+
</configuration>
123+
<executions>
124+
<execution>
125+
<id>mojo-descriptor</id>
126+
<goals>
127+
<goal>descriptor</goal>
128+
</goals>
129+
</execution>
130+
</executions>
131+
</plugin>
132+
</plugins>
133+
</build>
134+
135+
<reporting>
136+
<plugins>
137+
<plugin>
138+
<groupId>org.apache.maven.plugins</groupId>
139+
<artifactId>maven-plugin-plugin</artifactId>
140+
<version>${maven.plugin.plugin.version}</version>
141+
</plugin>
142+
</plugins>
143+
</reporting>
144+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package com.coderplus.plugins;
2+
3+
/*
4+
* The MIT License
5+
*
6+
* Copyright (c) 2004
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
9+
* this software and associated documentation files (the "Software"), to deal in
10+
* the Software without restriction, including without limitation the rights to
11+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12+
* of the Software, and to permit persons to whom the Software is furnished to do
13+
* so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
* SOFTWARE.
25+
*/
26+
27+
import java.io.File;
28+
import java.io.IOException;
29+
import java.util.List;
30+
31+
import org.apache.maven.plugin.AbstractMojo;
32+
import org.apache.maven.plugin.MojoExecutionException;
33+
import org.apache.maven.plugins.annotations.Component;
34+
import org.apache.maven.plugins.annotations.LifecyclePhase;
35+
import org.apache.maven.plugins.annotations.Mojo;
36+
import org.apache.maven.plugins.annotations.Parameter;
37+
import org.apache.maven.project.MavenProject;
38+
import org.sonatype.plexus.build.incremental.BuildContext;
39+
import org.codehaus.plexus.util.FileUtils;
40+
41+
42+
/**
43+
* Copy files during build
44+
*
45+
* @author <a href="aneesh@coderplus.com">Aneesh Joseph</a>
46+
* @since 1.0
47+
*/
48+
@Mojo( name = "copy", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true )
49+
public class CopyMojo
50+
extends AbstractMojo
51+
{
52+
/**
53+
* The file which has to be copied
54+
*
55+
* @since 1.0
56+
*/
57+
@Parameter( required = false )
58+
private File sourceFile;
59+
/**
60+
* The target file to which the file should be copied(this shouldn't be a directory but a file which does or does not exist)
61+
*
62+
* @since 1.0
63+
*/
64+
@Parameter( required = false )
65+
private File destinationFile;
66+
67+
/**
68+
* Collection of FileSets to work on (FileSet contains sourceFile and destinationFile). See <a href="./usage.html">Usage</a> for details.
69+
*
70+
* @since 1.0
71+
*/
72+
@Parameter( required = false )
73+
private List<FileSet> fileSets;
74+
75+
/**
76+
* Overwrite files
77+
*
78+
* @since 1.0
79+
*/
80+
@Parameter( property = "copy.overWrite", defaultValue = "true" )
81+
boolean overWrite;
82+
83+
/**
84+
* Ignore File Not Found errors during incremental build
85+
*
86+
* @since 1.0
87+
*/
88+
@Parameter( property = "copy.ignoreFileNotFoundOnIncremental", defaultValue = "true" )
89+
boolean ignoreFileNotFoundOnIncremental;
90+
91+
92+
/**
93+
* @since 1.0
94+
*/
95+
@Component
96+
private MavenProject project;
97+
98+
@Component
99+
private BuildContext buildContext;
100+
101+
public void execute() throws MojoExecutionException
102+
{
103+
getLog().debug("Executing the copy-rename-maven-plugin");
104+
if(fileSets!= null && fileSets.size() > 0){
105+
for(FileSet fileSet: fileSets){
106+
File srcFile = fileSet.getSourceFile();
107+
File destFile = fileSet.getDestinationFile();
108+
if(srcFile!=null){
109+
copy(srcFile,destFile);
110+
}
111+
}
112+
} else if(sourceFile!= null){
113+
copy(sourceFile,destinationFile);
114+
} else{
115+
getLog().info("No Files to process");
116+
}
117+
}
118+
119+
private void copy(File srcFile,File destFile) throws MojoExecutionException{
120+
121+
if(!srcFile.exists()){
122+
if(ignoreFileNotFoundOnIncremental && buildContext.isIncremental()){
123+
getLog().warn("sourceFile "+srcFile.getAbsolutePath()+ " not found during incremental build");
124+
} else {
125+
getLog().error("sourceFile "+srcFile.getAbsolutePath()+ " does not exist");
126+
}
127+
} else if(srcFile.isDirectory()){
128+
getLog().error("sourceFile "+srcFile.getAbsolutePath()+ " is not a file");
129+
} else if(destFile == null){
130+
getLog().error("destinationFile not specified");
131+
} else if(destFile.exists() && destFile.isFile() && !overWrite){
132+
getLog().error(destFile.getAbsolutePath()+" already exists and overWrite not set");
133+
} else{
134+
try {
135+
if(buildContext.isIncremental() && destFile.exists() && !buildContext.hasDelta(srcFile) && FileUtils.contentEquals(srcFile, destFile)){
136+
getLog().info("No changes detected in "+srcFile.getAbsolutePath());
137+
return;
138+
}
139+
FileUtils.copyFile(srcFile, destFile);
140+
getLog().info("Copied "+ srcFile.getAbsolutePath()+ " to "+ destFile.getAbsolutePath());
141+
buildContext.refresh(destFile);
142+
} catch (IOException e) {
143+
throw new MojoExecutionException("could not copy "+srcFile.getAbsolutePath()+" to "+destFile.getAbsolutePath());
144+
}
145+
}
146+
147+
148+
}
149+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.coderplus.plugins;
2+
/*
3+
* The MIT License
4+
*
5+
* Copyright (c) 2004
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
8+
* this software and associated documentation files (the "Software"), to deal in
9+
* the Software without restriction, including without limitation the rights to
10+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
11+
* of the Software, and to permit persons to whom the Software is furnished to do
12+
* so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
import java.io.File;
26+
27+
public class FileSet {
28+
29+
private File sourceFile;
30+
private File destinationFile;
31+
32+
public File getSourceFile() {
33+
return sourceFile;
34+
}
35+
public void setSourceFile(File sourceFile) {
36+
this.sourceFile = sourceFile;
37+
}
38+
public File getDestinationFile() {
39+
return destinationFile;
40+
}
41+
public void setDestinationFile(File destinationFile) {
42+
this.destinationFile = destinationFile;
43+
}
44+
}

0 commit comments

Comments
 (0)