Skip to content

Commit

Permalink
Merge pull request #226 from Hithran/bugfix/ISSUE-166
Browse files Browse the repository at this point in the history
Fix #166 update-file-header changes file permissions: clears executab…
  • Loading branch information
tchemit committed Feb 3, 2019
2 parents 59b3703 + 0ae6dc7 commit 42d3679
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/it/ISSUE-166/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=clean license:update-file-header
44 changes: 44 additions & 0 deletions src/it/ISSUE-166/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>ISSUE-166</artifactId>
<version>@pom.version@</version>
<inceptionYear>2019</inceptionYear>

<name>Test ISSUE-166</name>
<url>http://www.mojohaus.org</url>

<organization>
<name>MojoHaus</name>
</organization>

<licenses>
<license>
<name>The GNU Lesser General Public License, Version 3.0</name>
<url>http://www.gnu.org/licenses/lgpl-3.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<license.licenseName>gpl_v3</license.licenseName>
<license.keepBackup>true</license.keepBackup>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>@pom.version@</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
17 changes: 17 additions & 0 deletions src/it/ISSUE-166/postbuild.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.nio.file.Files
import java.nio.file.Paths

scriptWithHeader = Paths.get(basedir.getAbsolutePath(), "src", "main", "bash", "license-test.sh")
backupFile = Paths.get(basedir.getAbsolutePath(), "src", "main", "bash", "license-test.sh~")

if(!Files.isExecutable(scriptWithHeader)) {
println("Executable bit of the file $scriptWithHeader was cleared")
return false
}

if(!Files.isExecutable(backupFile)) {
println("Executable bit of the backup file $backupFile was cleared")
reutrn false
}

return true
14 changes: 14 additions & 0 deletions src/it/ISSUE-166/prebuild.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import java.nio.file.Files
import java.nio.file.Paths

// Ensure the file is executable to begin with.
scriptWithoutHeader = Paths.get(basedir.getAbsolutePath(), "src", "main", "bash", "license-test.sh")

if(!Files.isExecutable(scriptWithoutHeader))
scriptWithoutHeader.toFile().setExecutable(true, true)

if(!Files.isExecutable(scriptWithoutHeader)) {
println("File $scriptWithoutHeader is not executable")
return false
}
return true
3 changes: 3 additions & 0 deletions src/it/ISSUE-166/src/main/bash/license-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
# Some executable file
exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
Expand Down Expand Up @@ -927,7 +929,7 @@ private void finalizeFile( File file, File processFile ) throws IOException
getLog().debug( " - backup original file " + file );
}

FileUtil.renameFile( file, backupFile );
Files.copy( file.toPath(), backupFile.toPath(), StandardCopyOption.COPY_ATTRIBUTES );
}

if ( isDryRun() )
Expand All @@ -940,9 +942,10 @@ private void finalizeFile( File file, File processFile ) throws IOException
{
try
{

// replace file with the updated one
FileUtil.renameFile( processFile, file );
String updatedContent = FileUtil.readAsString( processFile, getEncoding() );
FileUtil.printString( file, updatedContent, getEncoding() );
FileUtil.deleteFile( processFile );
}
catch ( IOException e )
{
Expand Down

0 comments on commit 42d3679

Please sign in to comment.