Skip to content

Commit 34d5dcf

Browse files
committed
U rename rpm package on linux
1 parent 48b3153 commit 34d5dcf

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/main/java/fvarrui/maven/plugin/javapackager/PackageMojo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ private void generateRpmPackage() throws MojoExecutionException {
274274

275275
// rename generated rpm package
276276
File rpmFile = new File(assetsFolder, name + "-" + version + "-2.x86_64.rpm");
277-
rpmFile.renameTo(new File(assetsFolder, name + "_" + version + ".rpm"));
277+
String newName = name + "_" + version + ".rpm";
278+
FileUtils.rename(rpmFile, newName);
278279

279280
}
280281

src/main/java/fvarrui/maven/plugin/javapackager/utils/FileUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.apache.commons.io.IOUtils;
1919
import org.apache.commons.lang.StringUtils;
20+
import org.apache.commons.lang.SystemUtils;
2021
import org.apache.maven.plugin.MojoExecutionException;
2122

2223

@@ -149,5 +150,17 @@ public static void removeFolder(File folder) throws MojoExecutionException {
149150
throw new MojoExecutionException("Could not remove folder " + folder, e);
150151
}
151152
}
153+
154+
public static void rename(File file, String newName) throws MojoExecutionException {
155+
Logger.info("Changing name of [" + file + "] to [" + newName + "]");
156+
try {
157+
if (SystemUtils.IS_OS_LINUX)
158+
ProcessUtils.execute("mv", file, newName);
159+
else
160+
file.renameTo(new File(newName)); // FIXME this doesn't work on linux, I don't know why
161+
} catch (MojoExecutionException e) {
162+
throw new MojoExecutionException("File [" + file + "] couldn't be renamed to [" + newName + "]", e);
163+
}
164+
}
152165

153166
}

0 commit comments

Comments
 (0)