forked from keycloak/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use provided scope for maven-plugin dependencies
* use provided scope for maven dependencies As the maven-plugin-plugin suggests, dependencies to the maven runtime should be in provided scope. This gets rid of the according warning which was written during build. Before Maven 3.9, plexus-utils was injected in the classpath at runtime. As of Maven 3.9 this is not the case anymore which broke the plugin due to a usage of said dependency. The only usage is replaced by a visitor to copy files. Closes keycloak#30542 Signed-off-by: Michael Warnecke <WarneckeMichael@web.de> * Guides need to see maven's Log class Signed-off-by: Michael Warnecke <WarneckeMichael@web.de> --------- Signed-off-by: Michael Warnecke <WarneckeMichael@web.de>
- Loading branch information
1 parent
fa47d1a
commit c5fc9f2
Showing
5 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
docs/maven-plugin/src/main/java/org/keycloak/guides/maven/DirectoryCopyVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.keycloak.guides.maven; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileVisitResult; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.SimpleFileVisitor; | ||
import java.nio.file.StandardCopyOption; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
|
||
public class DirectoryCopyVisitor extends SimpleFileVisitor<Path> { | ||
|
||
private Path targetDir; | ||
private Path sourceDir; | ||
|
||
public DirectoryCopyVisitor(Path targetDir) { | ||
this.targetDir = targetDir; | ||
} | ||
|
||
@Override | ||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { | ||
if (sourceDir == null) { | ||
sourceDir = dir; | ||
} else { | ||
Path relativePath = sourceDir.relativize(dir); | ||
Files.createDirectories(targetDir.resolve(relativePath)); | ||
} | ||
|
||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
@Override | ||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { | ||
Path relativePath = sourceDir.relativize(file); | ||
Files.copy(file, targetDir.resolve(relativePath), StandardCopyOption.REPLACE_EXISTING); | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
docs/maven-plugin/src/test/java/org/keycloak/guides/maven/DirectoryCopyVisitorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.keycloak.guides.maven; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
class DirectoryCopyVisitorTest { | ||
|
||
@TempDir | ||
Path temp; | ||
|
||
private Path srcDir; | ||
private Path targetDir; | ||
|
||
@BeforeEach | ||
void setUpDirectories() throws IOException { | ||
srcDir = temp.resolve("source"); | ||
targetDir = temp.resolve("target"); | ||
Files.createDirectories(srcDir); | ||
Files.createDirectories(targetDir); | ||
} | ||
|
||
@Test | ||
void copyDirectoriesMultipleLevels() throws IOException { | ||
Path level1 = srcDir.resolve("level1"); | ||
Path level2a = level1.resolve("level2a"); | ||
Path level2b = level1.resolve("level2b"); | ||
Path level3 = level2a.resolve("level3"); | ||
Files.createDirectories(level3); | ||
Files.createDirectories(level2b); | ||
Files.createFile(srcDir.resolve("rootfile")); | ||
Files.createFile(level1.resolve("l1file")); | ||
Files.createFile(level2b.resolve("l2filea")); | ||
Files.createFile(level2b.resolve("l2fileb")); | ||
|
||
Files.walkFileTree(srcDir, new DirectoryCopyVisitor(targetDir)); | ||
|
||
assertEquals(List.of("level1", "rootfile"), listDirContent(targetDir)); | ||
assertEquals(List.of("l1file", "level2a", "level2b"), listDirContent(targetDir.resolve("level1"))); | ||
assertEquals(List.of("level3"), listDirContent(targetDir.resolve("level1").resolve("level2a"))); | ||
assertEquals(List.of(), listDirContent(targetDir.resolve("level1").resolve("level2a").resolve("level3"))); | ||
assertEquals(List.of("l2filea", "l2fileb"), listDirContent(targetDir.resolve("level1").resolve("level2b"))); | ||
} | ||
|
||
private List<String> listDirContent(Path path) throws IOException { | ||
return Files.list(path).map(Path::getFileName).map(Path::toString).sorted().toList(); | ||
} | ||
} |