diff --git a/Dockerfile b/Dockerfile index a0e853a1..1bfd9479 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ FROM maven:3.9.8-eclipse-temurin-21 -RUN addgroup --gid 1000 build && adduser --uid 1000 --gid 1000 --disabled-password --gecos "" build && \ - curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && \ +RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && \ chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null && \ apt update && \ diff --git a/src/main/java/ch/ivyteam/ivy/maven/AbstractEngineMojo.java b/src/main/java/ch/ivyteam/ivy/maven/AbstractEngineMojo.java index c0bce918..ef837b92 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/AbstractEngineMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/AbstractEngineMojo.java @@ -17,6 +17,8 @@ package ch.ivyteam.ivy.maven; import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; @@ -55,7 +57,7 @@ public abstract class AbstractEngineMojo extends AbstractMojo { * If the Engine does not yet exist, it can be automatically downloaded. */ @Parameter(property = ENGINE_DIRECTORY_PROPERTY) - public File engineDirectory; + public Path engineDirectory; /** * Location where ivy engines in required version can be extracted to. @@ -63,7 +65,7 @@ public abstract class AbstractEngineMojo extends AbstractMojo { * If the Engine does not yet exist, it can be automatically downloaded. */ @Parameter(defaultValue = "${settings.localRepository}/.cache/ivy", property = "ivy.engine.cache.directory") - public File engineCacheDirectory; + public Path engineCacheDirectory; /** * The ivy Engine version or version-range that must be used. Must be equal or @@ -95,11 +97,11 @@ public AbstractEngineMojo() { * 'directory' could be yet invalid! * @return the raw engine directory */ - protected final File getRawEngineDirectory() { + protected final Path getRawEngineDirectory() { return engineDirectory; } - protected final File identifyAndGetEngineDirectory() throws MojoExecutionException { + protected final Path identifyAndGetEngineDirectory() throws MojoExecutionException { if (!isEngineDirectoryIdentified()) { engineDirectory = findMatchingEngineInCacheDirectory(); } @@ -110,19 +112,19 @@ protected final boolean isEngineDirectoryIdentified() { return engineDirectory != null; } - protected final File findMatchingEngineInCacheDirectory() throws MojoExecutionException { - if (engineCacheDirectory == null || !engineCacheDirectory.exists()) { + protected final Path findMatchingEngineInCacheDirectory() throws MojoExecutionException { + if (engineCacheDirectory == null || !Files.exists(engineCacheDirectory)) { return null; } File engineDirToTake = null; ArtifactVersion versionOfEngineToTake = null; - for (File engineDirCandidate : engineCacheDirectory.listFiles()) { + for (File engineDirCandidate : engineCacheDirectory.toFile().listFiles()) { if (!engineDirCandidate.isDirectory()) { continue; } - ArtifactVersion candidateVersion = getInstalledEngineVersion(engineDirCandidate); + ArtifactVersion candidateVersion = getInstalledEngineVersion(engineDirCandidate.toPath()); if (candidateVersion == null || !getIvyVersionRange().containsVersion(candidateVersion)) { continue; } @@ -131,10 +133,14 @@ protected final File findMatchingEngineInCacheDirectory() throws MojoExecutionEx versionOfEngineToTake = candidateVersion; } } - return engineDirToTake; + return toPath(engineDirToTake); } - protected final ArtifactVersion getInstalledEngineVersion(File engineDir) throws MojoExecutionException { + private Path toPath(File file) { + return file == null ? null : file.toPath(); + } + + protected final ArtifactVersion getInstalledEngineVersion(Path engineDir) throws MojoExecutionException { try { return new EngineVersionEvaluator(getLog(), engineDir).evaluateVersion(); } catch (Exception ex) { diff --git a/src/main/java/ch/ivyteam/ivy/maven/IarPackagingMojo.java b/src/main/java/ch/ivyteam/ivy/maven/IarPackagingMojo.java index b0d2b427..8fb57c31 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/IarPackagingMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/IarPackagingMojo.java @@ -18,6 +18,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Path; import org.apache.commons.lang3.ArrayUtils; import org.apache.maven.artifact.Artifact; @@ -106,20 +107,20 @@ public static interface Defaults { @Override public void execute() throws MojoExecutionException, MojoFailureException { String iarName = project.getArtifactId() + "-" + project.getVersion() + ".iar"; - File iar = new File(project.getBuild().getDirectory(), iarName); + var iar = Path.of(project.getBuild().getDirectory()).resolve(iarName); createIvyArchive(project.getBasedir(), iar); Artifact artifact = project.getArtifact(); - artifact.setFile(iar); + artifact.setFile(iar.toFile()); project.setArtifact(artifact); getLog().info("Attached " + artifact + "."); } - private void createIvyArchive(File projectDir, File targetIar) throws MojoExecutionException { + private void createIvyArchive(File projectDir, Path targetIar) throws MojoExecutionException { ZipArchiver archiver = new ZipArchiver(); archiver.setDuplicateBehavior(Archiver.DUPLICATES_SKIP); - archiver.setDestFile(targetIar); - FileSetConverter fsConverter = new FileSetConverter(project.getBasedir()); + archiver.setDestFile(targetIar.toFile()); + FileSetConverter fsConverter = new FileSetConverter(project.getBasedir().toPath()); for (org.codehaus.plexus.archiver.FileSet fs : fsConverter.toPlexusFileSets(iarFileSets)) { archiver.addFileSet(fs); } @@ -129,7 +130,7 @@ private void createIvyArchive(File projectDir, File targetIar) throws MojoExecut try { archiver.createArchive(); } catch (ArchiverException | IOException ex) { - throw new MojoExecutionException("Failed to create IAR: " + targetIar.getAbsolutePath(), ex); + throw new MojoExecutionException("Failed to create IAR: " + targetIar.toAbsolutePath(), ex); } } diff --git a/src/main/java/ch/ivyteam/ivy/maven/InstallEngineMojo.java b/src/main/java/ch/ivyteam/ivy/maven/InstallEngineMojo.java index 64e80dfc..2ecff4ce 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/InstallEngineMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/InstallEngineMojo.java @@ -16,9 +16,10 @@ package ch.ivyteam.ivy.maven; -import java.io.File; import java.io.IOException; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -159,7 +160,12 @@ private void ensureEngineIsInstalled() throws MojoExecutionException { handleNoInstalledEngine(); } else { if (engineDirectoryIsEmpty()) { - getRawEngineDirectory().mkdirs(); + var rawEngineDir = getRawEngineDirectory(); + try { + Files.createDirectories(rawEngineDir); + } catch (IOException ex) { + throw new MojoExecutionException("Could not create directories " + rawEngineDir, ex); + } } ArtifactVersion installedEngineVersion = getInstalledEngineVersion(getRawEngineDirectory()); @@ -187,7 +193,7 @@ private void downloadAndInstallEngine(boolean cleanEngineDir) throws MojoExecuti if (autoInstallEngine) { getLog().info("Will automatically download Engine now."); final EngineDownloader engineDownloader = getDownloader(); - File downloadZip = engineDownloader.downloadEngine(); + var downloadZip = engineDownloader.downloadEngine(); if (cleanEngineDir) { removeOldEngineContent(); @@ -195,14 +201,22 @@ private void downloadAndInstallEngine(boolean cleanEngineDir) throws MojoExecuti if (!isEngineDirectoryIdentified()) { String engineZipFileName = engineDownloader.getZipFileNameFromDownloadLocation(); - engineDirectory = new File(engineCacheDirectory, ivyEngineVersionOfZip(engineZipFileName)); - engineDirectory.mkdirs(); + engineDirectory = engineCacheDirectory.resolve(ivyEngineVersionOfZip(engineZipFileName)); + try { + Files.createDirectories(engineDirectory); + } catch (IOException ex) { + throw new MojoExecutionException("Could not create directories " + engineDirectory, ex); + } } unpackEngine(downloadZip); if (!downloadUsingMaven) { - downloadZip.delete(); + try { + Files.delete(downloadZip); + } catch (IOException ex) { + throw new MojoExecutionException("Could not delete file " + downloadZip.toAbsolutePath(), ex); + } } ArtifactVersion installedEngineVersion = getInstalledEngineVersion(getRawEngineDirectory()); @@ -246,30 +260,32 @@ static String ivyEngineVersionOfZip(String engineZipFileName) { } private void removeOldEngineContent() throws MojoExecutionException { + var dir = getRawEngineDirectory(); try { - FileUtils.cleanDirectory(getRawEngineDirectory()); + if (dir != null) { + FileUtils.cleanDirectory(dir.toFile()); + } } catch (IOException ex) { throw new MojoExecutionException( - "Failed to clean outdated ivy Engine directory '" + getRawEngineDirectory() + "'.", ex); + "Failed to clean outdated ivy Engine directory '" + dir + "'.", ex); } } private boolean engineDirectoryIsEmpty() { - return !getRawEngineDirectory().isDirectory() || ArrayUtils.isEmpty(getRawEngineDirectory().listFiles()); + return !Files.isDirectory(getRawEngineDirectory()) || ArrayUtils.isEmpty(getRawEngineDirectory().toFile().listFiles()); } - private void unpackEngine(File downloadZip) throws MojoExecutionException { - String targetLocation = getRawEngineDirectory().getAbsolutePath(); - getLog().info("Unpacking engine " + downloadZip.getAbsolutePath() + " to " + targetLocation); - try (var engineZip = new ZipFile(downloadZip)) { + private void unpackEngine(Path downloadZip) throws MojoExecutionException { + String targetLocation = getRawEngineDirectory().toAbsolutePath().toString(); + getLog().info("Unpacking engine " + downloadZip.toAbsolutePath() + " to " + targetLocation); + try (var engineZip = new ZipFile(downloadZip.toFile())) { engineZip.extractAll(targetLocation); } catch (IOException ex) { throw new MojoExecutionException("Failed to unpack downloaded engine '" + downloadZip + "'.", ex); } } - File getDownloadDirectory() { - return SystemUtils.getJavaIoTmpDir(); + Path getDownloadDirectory() { + return SystemUtils.getJavaIoTmpDir().toPath(); } - } diff --git a/src/main/java/ch/ivyteam/ivy/maven/MavenDependencyMojo.java b/src/main/java/ch/ivyteam/ivy/maven/MavenDependencyMojo.java index c8d84aa1..65f78ad3 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/MavenDependencyMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/MavenDependencyMojo.java @@ -16,7 +16,6 @@ package ch.ivyteam.ivy.maven; -import java.io.File; import java.io.IOException; import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; @@ -35,7 +34,7 @@ /** * Copy maven * dependencies to a specific folder. - * + * *

* To reduce the size of your ivy archives, make sure that your dependencies are * configured correctly: @@ -45,7 +44,7 @@ *

  • Exclude transient * dependencies which are already delivered by the core
  • * - * + * * @since 9.2.0 */ @Mojo(name = MavenDependencyMojo.GOAL, requiresDependencyResolution = ResolutionScope.COMPILE) @@ -79,15 +78,15 @@ protected void engineExec(MavenProjectBuilderProxy projectBuilder) throws Except getLog().info("Maven dependecies: " + copied + " copied."); } - private int copyDependency(Path mvnLibDir, List deps) { + private int copyDependency(Path mvnLibDir, List deps) { var count = 0; for (var dep : deps) { try { - Files.copy(dep.toPath(), mvnLibDir.resolve(dep.getName())); - getLog().debug("Copied dependency: " + dep.getName()); + Files.copy(dep, mvnLibDir.resolve(dep.getFileName().toString())); + getLog().debug("Copied dependency: " + dep.getFileName()); count++; } catch (FileAlreadyExistsException ex) { - getLog().debug("Ignore dependecy '" + dep.getName() + "' as it already exists at: " + mvnLibDir); + getLog().debug("Ignore dependecy '" + dep.getFileName() + "' as it already exists at: " + mvnLibDir); } catch (IOException ex) { getLog().warn("Couldn't copy depedency '" + deps + "' to: " + mvnLibDir, ex); } diff --git a/src/main/java/ch/ivyteam/ivy/maven/ShareEngineCoreClasspathMojo.java b/src/main/java/ch/ivyteam/ivy/maven/ShareEngineCoreClasspathMojo.java index d0bd3523..b6b347e3 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/ShareEngineCoreClasspathMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/ShareEngineCoreClasspathMojo.java @@ -16,10 +16,8 @@ package ch.ivyteam.ivy.maven; -import java.io.File; -import java.util.List; +import java.util.stream.Collectors; -import org.apache.commons.lang3.StringUtils; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -32,33 +30,26 @@ /** * Shares the Engine core classpath with the property: * ivy.engine.core.classpath. - * + * * @since 6.2.0 */ @Mojo(name = ShareEngineCoreClasspathMojo.GOAL) public class ShareEngineCoreClasspathMojo extends AbstractEngineMojo { + public static final String GOAL = "share-engine-core-classpath"; - public static final String IVY_ENGINE_CORE_CLASSPATH_PROPERTY = "ivy.engine.core.classpath"; // Duplicated - // for - // the - // comment, - // JavaDoc - // value - // didn't - // work. + public static final String IVY_ENGINE_CORE_CLASSPATH_PROPERTY = "ivy.engine.core.classpath"; @Parameter(property = "project", required = true, readonly = true) MavenProject project; @Override public void execute() throws MojoExecutionException, MojoFailureException { - List ivyEngineClassPathFiles = EngineClassLoaderFactory - .getIvyEngineClassPathFiles(identifyAndGetEngineDirectory()); - String propertyValue = StringUtils.join(ivyEngineClassPathFiles, ","); - - MavenProperties properties = new MavenProperties(project, getLog()); - properties.setMavenProperty(IVY_ENGINE_CORE_CLASSPATH_PROPERTY, propertyValue); + var value = EngineClassLoaderFactory.getIvyEngineClassPathFiles(identifyAndGetEngineDirectory()) + .stream() + .map(p -> p.toAbsolutePath().toString()) + .collect(Collectors.joining(",")); + var properties = new MavenProperties(project, getLog()); + properties.setMavenProperty(IVY_ENGINE_CORE_CLASSPATH_PROPERTY, value); } - } diff --git a/src/main/java/ch/ivyteam/ivy/maven/compile/AbstractEngineInstanceMojo.java b/src/main/java/ch/ivyteam/ivy/maven/compile/AbstractEngineInstanceMojo.java index 23165649..2efc446a 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/compile/AbstractEngineInstanceMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/compile/AbstractEngineInstanceMojo.java @@ -16,7 +16,7 @@ package ch.ivyteam.ivy.maven.compile; -import java.io.File; +import java.nio.file.Path; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.plugin.MojoExecutionException; @@ -42,7 +42,7 @@ public abstract class AbstractEngineInstanceMojo extends AbstractEngineMojo { * temporary deployed. */ @Parameter(defaultValue = "${project.build.directory}/ivyBuildApp") - protected File buildApplicationDirectory; + protected Path buildApplicationDirectory; /** * Defines the timeout how long to wait for an engine start to compile. @@ -80,7 +80,7 @@ public final void execute() throws MojoExecutionException, MojoFailureException protected MavenProjectBuilderProxy getMavenProjectBuilder() throws Exception { EngineClassLoaderFactory classLoaderFactory = getEngineClassloaderFactory(); - File engineDir = identifyAndGetEngineDirectory(); + var engineDir = identifyAndGetEngineDirectory(); if (builder == null) { builder = new MavenProjectBuilderProxy( classLoaderFactory, @@ -92,7 +92,7 @@ protected MavenProjectBuilderProxy getMavenProjectBuilder() throws Exception { classLoaderFactory.writeEngineClasspathJar(engineDir); // share engine directory as property for custom follow up plugins: if (engineDir != null) { - project.getProperties().put(AbstractEngineMojo.ENGINE_DIRECTORY_PROPERTY, engineDir.getAbsolutePath()); + project.getProperties().put(AbstractEngineMojo.ENGINE_DIRECTORY_PROPERTY, engineDir.toAbsolutePath().toString()); } return builder; } diff --git a/src/main/java/ch/ivyteam/ivy/maven/compile/AbstractProjectCompileMojo.java b/src/main/java/ch/ivyteam/ivy/maven/compile/AbstractProjectCompileMojo.java index 6fef6b4e..c35e540f 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/compile/AbstractProjectCompileMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/compile/AbstractProjectCompileMojo.java @@ -18,6 +18,8 @@ import java.io.File; import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -60,7 +62,7 @@ public abstract class AbstractProjectCompileMojo extends AbstractEngineInstanceM * @since 8.0.3 */ @Parameter(property = "ivy.compiler.settings", defaultValue = ".settings/org.eclipse.jdt.core.prefs") - File compilerSettings; + Path compilerSettings; /** * Define compiler options.
    @@ -88,13 +90,14 @@ protected Map getOptions() { private String getDependencyClasspath() { return StringUtils.join(getDependencies("jar").stream() + .map(Path::toFile) .map(jar -> jar.getAbsolutePath()) .collect(Collectors.toList()), File.pathSeparatorChar); } private File getCompilerSettings() { - if (compilerSettings.exists()) { - return compilerSettings; + if (Files.exists(compilerSettings)) { + return compilerSettings.toFile(); } else if (compilerWarnings) { getLog().warn("Could not locate compiler settings file: " + compilerSettings + " continuing with default compiler settings"); @@ -102,7 +105,7 @@ private File getCompilerSettings() { return null; } - protected final List getDependencies(String type) { + protected final List getDependencies(String type) { return MavenRuntime.getDependencies(project, type); } diff --git a/src/main/java/ch/ivyteam/ivy/maven/compile/CompileProjectMojo.java b/src/main/java/ch/ivyteam/ivy/maven/compile/CompileProjectMojo.java index 6eaab398..ce6c840b 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/compile/CompileProjectMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/compile/CompileProjectMojo.java @@ -18,9 +18,10 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.Collection; -import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -32,7 +33,7 @@ /** * Compiles an ivy Project with an ivyEngine. - * + * * @author Reguel Wermelinger * @since 6.0.0 */ @@ -64,8 +65,8 @@ protected void engineExec(MavenProjectBuilderProxy projectBuilder) throws Except } getLog().info("Compiling ivy Project..."); - List iarDependencies = getDependencies("iar"); - List iarJars = projectBuilder.createIarJars(iarDependencies); + var iarDependencies = getDependencies("iar").stream().map(Path::toFile).collect(Collectors.toList()); + var iarJars = projectBuilder.createIarJars(iarDependencies); Map options = getOptions(); projectBuilder.compile(project.getBasedir(), iarJars, options); @@ -74,16 +75,14 @@ protected void engineExec(MavenProjectBuilderProxy projectBuilder) throws Except } else { projectBuilder.validate(project.getBasedir(), iarDependencies, options); } - - writeDependencyIarJar(iarJars); + writeDependencyIarJar(iarJars.stream().map(File::toPath).collect(Collectors.toList())); } - private void writeDependencyIarJar(Collection iarJarDepenencies) throws IOException { + private void writeDependencyIarJar(Collection iarJarDepenencies) throws IOException { if (iarJarDepenencies == null) { // no dependencies return; } - File jar = new SharedFile(project).getIarDependencyClasspathJar(); + var jar = new SharedFile(project).getIarDependencyClasspathJar(); new ClasspathJar(jar).createFileEntries(iarJarDepenencies); } - } diff --git a/src/main/java/ch/ivyteam/ivy/maven/compile/CompileTestProjectMojo.java b/src/main/java/ch/ivyteam/ivy/maven/compile/CompileTestProjectMojo.java index 4e52119d..80c5ca0e 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/compile/CompileTestProjectMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/compile/CompileTestProjectMojo.java @@ -17,9 +17,12 @@ package ch.ivyteam.ivy.maven.compile; import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -32,7 +35,7 @@ /** * Compiles the test sources. - * + * * @author Reguel Wermelinger * @since 6.1.0 */ @@ -51,8 +54,7 @@ protected void engineExec(MavenProjectBuilderProxy projectBuilder) throws Except } getLog().info("Compiling test sources..."); - Map result = projectBuilder.testCompile(project.getBasedir(), getDependencyIarJars(), - getOptions()); + Map result = projectBuilder.testCompile(project.getBasedir(), getDependencyIarJars(), getOptions()); CompilerResult.store(result, project); } @@ -60,12 +62,11 @@ protected void engineExec(MavenProjectBuilderProxy projectBuilder) throws Except * @return persistent IAR-JARs from {@link CompileProjectMojo}. */ private List getDependencyIarJars() { - File iarJarClasspath = new SharedFile(project).getIarDependencyClasspathJar(); - if (!iarJarClasspath.exists()) { + var iarJarClasspath = new SharedFile(project).getIarDependencyClasspathJar(); + if (!Files.exists(iarJarClasspath)) { return Collections.emptyList(); } - List iarJars = new ClasspathJar(iarJarClasspath).getFiles(); - return iarJars; + var iarJars = new ClasspathJar(iarJarClasspath).getFiles(); + return iarJars.stream().map(Path::toFile).collect(Collectors.toList()); } - } diff --git a/src/main/java/ch/ivyteam/ivy/maven/deploy/AbstractDeployMojo.java b/src/main/java/ch/ivyteam/ivy/maven/deploy/AbstractDeployMojo.java index f8c79f7d..78771d9e 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/deploy/AbstractDeployMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/deploy/AbstractDeployMojo.java @@ -18,6 +18,8 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.ReadOnlyFileSystemException; import org.apache.commons.io.FileUtils; @@ -46,7 +48,7 @@ public abstract class AbstractDeployMojo extends AbstractIntegrationTestMojo { * from the {@link IarPackagingMojo#GOAL} is used. */ @Parameter(property = PROPERTY_IVY_DEPLOY_FILE, defaultValue = "${project.build.directory}/${project.artifactId}-${project.version}.iar") - protected File deployFile; + protected Path deployFile; /** * If set to true then test users defined in the projects are @@ -151,7 +153,7 @@ public abstract class AbstractDeployMojo extends AbstractIntegrationTestMojo { *

    * * Example options file content: - * + * *
        * deployTestUsers: auto
        *target:
    @@ -163,7 +165,7 @@ public abstract class AbstractDeployMojo extends AbstractIntegrationTestMojo {
        * Inside the options file you can use property placeholders. The options file
        * may look like this:
        * 

    - * + * *
        * deployTestUsers: ${ivy.deploy.test.users}
        *target:
    @@ -185,7 +187,7 @@ public abstract class AbstractDeployMojo extends AbstractIntegrationTestMojo {
        *      Guide
        */
       @Parameter(property = "ivy.deploy.options.file", required = false)
    -  protected File deployOptionsFile;
    +  protected Path deployOptionsFile;
     
       @Component
       private MavenFileFilter fileFilter;
    @@ -218,14 +220,14 @@ protected final boolean checkSkip() {
           getLog().info("Skipping deployment to engine.");
           return true;
         }
    -    if (!deployFile.exists()) {
    +    if (!Files.exists(deployFile)) {
           getLog().warn("Skipping deployment of '" + deployFile + "' to engine. The file does not exist.");
           return true;
         }
         return false;
       }
     
    -  protected final File createDeployOptionsFile(DeploymentOptionsFileFactory optionsFileFactory)
    +  protected final Path createDeployOptionsFile(DeploymentOptionsFileFactory optionsFileFactory)
               throws MojoExecutionException {
         if (deployOptionsFile != null) {
           return optionsFileFactory.createFromTemplate(deployOptionsFile, project, session, fileFilter);
    @@ -242,23 +244,25 @@ protected final File createDeployOptionsFile(DeploymentOptionsFileFactory option
         return null;
       }
     
    -  protected static final void removeTemporaryDeploymentOptionsFile(File deploymentOptionsFile) {
    -    FileUtils.deleteQuietly(deploymentOptionsFile);
    +  protected static final void removeTemporaryDeploymentOptionsFile(Path deploymentOptionsFile) {
    +    FileUtils.deleteQuietly(toFile(deploymentOptionsFile));
       }
     
    -  protected final void deployToDirectory(File resolvedOptionsFile, File deployDir)
    +  private static File toFile(Path file) {
    +    return file == null ? null : file.toFile();
    +  }
    +
    +  protected final void deployToDirectory(Path resolvedOptionsFile, Path deployDir)
               throws MojoExecutionException {
    -    File targetDeployableFile = createTargetDeployableFile(deployDir);
    -    String deployablePath = deployDir.toPath().relativize(targetDeployableFile.toPath()).toString();
    -    IvyDeployer deployer = new FileDeployer(deployDir, resolvedOptionsFile, deployTimeoutInSeconds,
    -            deployFile, targetDeployableFile);
    +    var targetDeployableFile = createTargetDeployableFile(deployDir);
    +    String deployablePath = deployDir.relativize(targetDeployableFile).toString();
    +    IvyDeployer deployer = new FileDeployer(deployDir, resolvedOptionsFile, deployTimeoutInSeconds, deployFile, targetDeployableFile);
         deployer.deploy(deployablePath, getLog());
       }
     
    -  private final File createTargetDeployableFile(File deployDir) {
    -    File deployApp = new File(deployDir, deployToEngineApplication);
    -    File targetDeployableFile = new File(deployApp, deployFile.getName());
    -    return targetDeployableFile;
    +  private final Path createTargetDeployableFile(Path deployDir) {
    +    return deployDir
    +            .resolve(deployToEngineApplication)
    +            .resolve(deployFile.getFileName().toString());
       }
    -
    -}
    \ No newline at end of file
    +}
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/deploy/DeployToEngineMojo.java b/src/main/java/ch/ivyteam/ivy/maven/deploy/DeployToEngineMojo.java
    index adb572de..bb5b85d6 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/deploy/DeployToEngineMojo.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/deploy/DeployToEngineMojo.java
    @@ -16,7 +16,8 @@
     
     package ch.ivyteam.ivy.maven.deploy;
     
    -import java.io.File;
    +import java.nio.file.Files;
    +import java.nio.file.Path;
     import java.nio.file.Paths;
     
     import org.apache.commons.lang3.StringUtils;
    @@ -81,7 +82,7 @@ public class DeployToEngineMojo extends AbstractDeployMojo {
        * \\myRemoteHost\myEngineShare
        */
       @Parameter(property = "ivy.deploy.engine.dir", defaultValue = DEPLOY_ENGINE_DIR_DEFAULT)
    -  File deployEngineDirectory;
    +  Path deployEngineDirectory;
     
       /**
        * The auto deployment directory of the engine. Must match the ivy engine
    @@ -136,7 +137,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
                   "The parameter 'deployToEngineApplication' for goal " + GOAL + " is missing.");
         }
     
    -    File resolvedOptionsFile = createDeployOptionsFile(new DeploymentOptionsFileFactory(deployFile));
    +    var resolvedOptionsFile = createDeployOptionsFile(new DeploymentOptionsFileFactory(deployFile));
         try {
           deployWithOptions(resolvedOptionsFile);
         } finally {
    @@ -144,8 +145,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
         }
       }
     
    -  private void deployWithOptions(File resolvedOptionsFile) throws MojoExecutionException {
    -    getLog().info("Deploying project " + deployFile.getName());
    +  private void deployWithOptions(Path resolvedOptionsFile) throws MojoExecutionException {
    +    getLog().info("Deploying project " + deployFile.getFileName());
         if (DeployMethod.DIRECTORY.equals(deployMethod)) {
           deployToDirectory(resolvedOptionsFile);
         } else if (DeployMethod.HTTP.equals(deployMethod)) {
    @@ -157,26 +158,24 @@ private void deployWithOptions(File resolvedOptionsFile) throws MojoExecutionExc
         }
       }
     
    -  private void deployToDirectory(File resolvedOptionsFile) throws MojoExecutionException {
    -    File deployDir = getDeployDirectory();
    +  private void deployToDirectory(Path resolvedOptionsFile) throws MojoExecutionException {
    +    var deployDir = getDeployDirectory();
         if (deployEngineDirectory == null) {
           getLog().warn("Skipping deployment, target engine could not be evaluated." +
                   "Please configure an existing engine to deploy to with argument .");
           return;
         }
     
    -    if (!deployDir.exists()) {
    +    if (!Files.exists(deployDir)) {
           getLog().warn("Skipping deployment to engine '" + deployEngineDirectory + "'. The directory '"
                   + deployDir + "' does not exist.");
           return;
         }
    -
         checkDirParams();
    -
         deployToDirectory(resolvedOptionsFile, deployDir);
       }
     
    -  private void deployToRestService(File resolvedOptionsFile) throws MojoExecutionException {
    +  private void deployToRestService(Path resolvedOptionsFile) throws MojoExecutionException {
         checkHttpParams();
     
         Server server = session.getSettings().getServer(deployServerId);
    @@ -184,8 +183,7 @@ private void deployToRestService(File resolvedOptionsFile) throws MojoExecutionE
           getLog().warn("Can not load credentials from settings.xml because server '" + deployServerId
                   + "' is not definied. Try to deploy with default username, password");
         }
    -    HttpDeployer httpDeployer = new HttpDeployer(secDispatcher, server,
    -            deployEngineUrl, deployToEngineApplication, deployFile, resolvedOptionsFile);
    +    var httpDeployer = new HttpDeployer(secDispatcher, server, deployEngineUrl, deployToEngineApplication, deployFile, resolvedOptionsFile);
         httpDeployer.deploy(getLog());
       }
     
    @@ -195,8 +193,8 @@ private void checkHttpParams() {
         }
         Object defaultDeployEngineDirectory = project.getProperties().get(ENGINE_DIRECTORY_PROPERTY);
         if (deployEngineDirectory != null
    -            && !deployEngineDirectory.getPath().equals(defaultDeployEngineDirectory)) {
    -      logParameterIgnoredByMethod("deployEngineDirectory", deployEngineDirectory.getPath(),
    +            && !deployEngineDirectory.toFile().getPath().equals(defaultDeployEngineDirectory)) {
    +      logParameterIgnoredByMethod("deployEngineDirectory", deployEngineDirectory.toFile().getPath(),
                   DeployMethod.HTTP);
         }
       }
    @@ -215,15 +213,14 @@ private void logParameterIgnoredByMethod(String parameter, String value, String
                 + " deployment.");
       }
     
    -  private File getDeployDirectory() throws MojoExecutionException {
    -    if (deployEngineDirectory == null || engineToTarget()) { // re-use engine
    -                                                             // used to build
    +  private Path getDeployDirectory() throws MojoExecutionException {
    +    if (deployEngineDirectory == null || engineToTarget()) { // re-use engine used to build
           deployEngineDirectory = getEngineDir(project);
         }
         if (Paths.get(deployDirectory).isAbsolute()) {
    -      return new File(deployDirectory);
    +      return Paths.get(deployDirectory);
         }
    -    return new File(deployEngineDirectory, deployDirectory);
    +    return deployEngineDirectory.resolve(deployDirectory);
       }
     
       public static interface DefaultDeployOptions {
    @@ -237,5 +234,4 @@ public static interface DeployMethod {
         String DIRECTORY = "DIRECTORY";
         String HTTP = "HTTP";
       }
    -
     }
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/deploy/DeployToTestEngineMojo.java b/src/main/java/ch/ivyteam/ivy/maven/deploy/DeployToTestEngineMojo.java
    index cb480e07..0a12cfa0 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/deploy/DeployToTestEngineMojo.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/deploy/DeployToTestEngineMojo.java
    @@ -85,7 +85,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
         var props = new MavenProperties(project, getLog());
         props.set(Property.TEST_ENGINE_APP, deployToEngineApplication);
     
    -    boolean isDefaultFile = deployFile.getName()
    +    boolean isDefaultFile = deployFile.getFileName()
                 .endsWith(project.getArtifactId() + "-" + project.getVersion() + ".iar");
         if (isDefaultFile && deployDepsAsApp) {
           provideDepsAsAppZip();
    @@ -99,36 +99,36 @@ static String toAppName(String artifact) {
       }
     
       private void provideDepsAsAppZip() {
    -    List deps = MavenRuntime.getDependencies(project, session, "iar");
    +    var deps = MavenRuntime.getDependencies(project, session, "iar");
         if (deps.isEmpty()) {
           return;
         }
     
         deps.add(deployFile);
         try {
    -      File appZip = createFullAppZip(deps);
    -      getLog().info("Using " + appZip.getName()
    -              + " with all IAR dependencies of this test project for deployments.");
    +      var appZip = createFullAppZip(deps);
    +      getLog().info("Using " + appZip.getFileName() + " with all IAR dependencies of this test project for deployments.");
           deployFile = appZip;
         } catch (ArchiverException | IOException ex) {
           getLog().error("Failed to write deployable application ", ex);
         }
       }
     
    -  File createFullAppZip(List deps) throws ArchiverException, IOException {
    -    File appZip = new File(project.getBuild().getDirectory(), deployToEngineApplication + "-app.zip");
    +  Path createFullAppZip(List deps) throws ArchiverException, IOException {
    +    var appZip = Path.of(project.getBuild().getDirectory()).resolve(deployToEngineApplication + "-app.zip");
         ZipArchiver appZipper = new ZipArchiver();
    -    appZipper.setDestFile(appZip);
    -    for (File dep : deps) {
    -      if (dep.isFile() && dep.getName().endsWith("iar")) {
    -        appZipper.addFile(dep, dep.getName());
    -      } else if (dep.isDirectory()) {
    +    appZipper.setDestFile(appZip.toFile());
    +    for (var dep : deps) {
    +      var d = dep.toFile();
    +      if (d.isFile() && d.getName().endsWith("iar")) {
    +        appZipper.addFile(d, d.getName());
    +      } else if (d.isDirectory()) {
             Optional packedIar = findPackedIar(dep);
             if (packedIar.isPresent()) {
               File iar = packedIar.get().toFile();
               appZipper.addFile(iar, iar.getName());
             } else {
    -          appZipper.addDirectory(dep, dep.getName() + "/");
    +          appZipper.addDirectory(d, d.getName() + "/");
             }
           } else {
             getLog().warn("Can not add dependency to app zip '" + dep + "'. \n "
    @@ -139,8 +139,8 @@ File createFullAppZip(List deps) throws ArchiverException, IOException {
         return appZip;
       }
     
    -  static Optional findPackedIar(File dep) throws IOException {
    -    Path target = dep.toPath().resolve("target");
    +  static Optional findPackedIar(Path dep) throws IOException {
    +    var target = dep.resolve("target");
         if (!Files.isDirectory(target)) {
           return Optional.empty();
         }
    @@ -151,13 +151,12 @@ static Optional findPackedIar(File dep) throws IOException {
       }
     
       private void deployTestApp() throws MojoExecutionException {
    -    File resolvedOptionsFile = createDeployOptionsFile(new DeploymentOptionsFileFactory(deployFile));
    +    var resolvedOptionsFile = createDeployOptionsFile(new DeploymentOptionsFileFactory(deployFile));
         try {
    -      File deployDir = new File(getEngineDir(project), DeployToEngineMojo.DEPLOY_DEFAULT);
    +      var deployDir = getEngineDir(project).resolve(DeployToEngineMojo.DEPLOY_DEFAULT);
           deployToDirectory(resolvedOptionsFile, deployDir);
         } finally {
           removeTemporaryDeploymentOptionsFile(resolvedOptionsFile);
         }
       }
    -
     }
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/EngineClassLoaderFactory.java b/src/main/java/ch/ivyteam/ivy/maven/engine/EngineClassLoaderFactory.java
    index fe89f08e..1d46d93e 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/EngineClassLoaderFactory.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/EngineClassLoaderFactory.java
    @@ -21,8 +21,9 @@
     import java.net.MalformedURLException;
     import java.net.URL;
     import java.net.URLClassLoader;
    +import java.nio.file.Files;
    +import java.nio.file.Path;
     import java.util.ArrayList;
    -import java.util.Arrays;
     import java.util.List;
     
     import org.apache.commons.io.FileUtils;
    @@ -48,23 +49,22 @@
      */
     @SuppressWarnings("deprecation")
     public class EngineClassLoaderFactory {
    +
       public interface OsgiDir {
    -    String INSTALL_AREA = "system";
    -    String PLUGINS = INSTALL_AREA + "/plugins";
    -    String LIB_BOOT = "lib/boot";
    +    Path INSTALL_AREA = Path.of("system");
    +    Path PLUGINS = INSTALL_AREA.resolve("plugins");
    +    Path LIB_BOOT = Path.of("lib/boot");
       }
     
       /** must match version in pom.xml */
       private static final String SLF4J_VERSION = "2.0.13";
     
    -  private static final List ENGINE_LIB_DIRECTORIES = Arrays.asList(
    -          OsgiDir.INSTALL_AREA + "/" + OsgiDir.LIB_BOOT,
    +  private static final List ENGINE_LIB_DIRECTORIES = List.of(
    +          OsgiDir.INSTALL_AREA.resolve(OsgiDir.LIB_BOOT),
               OsgiDir.PLUGINS,
    -          OsgiDir.INSTALL_AREA + "/configuration/org.eclipse.osgi", // unpacked
    -                                                                    // jars from
    -                                                                    // OSGI
    -                                                                    // bundles
    -          "webapps" + File.separator + "ivy" + File.separator + "WEB-INF" + File.separator + "lib");
    +          // unpacked jars from OSGI bundles
    +          OsgiDir.INSTALL_AREA.resolve("configuration").resolve("org.eclipse.osgi"),
    +          Path.of("webapps").resolve("ivy").resolve("WEB-INF").resolve("lib"));
     
       private MavenContext maven;
     
    @@ -72,70 +72,76 @@ public EngineClassLoaderFactory(MavenContext mavenContext) {
         this.maven = mavenContext;
       }
     
    -  public URLClassLoader createEngineClassLoader(File engineDirectory) throws IOException {
    -    List osgiClasspath = getOsgiBootstrapClasspath(engineDirectory);
    +  public URLClassLoader createEngineClassLoader(Path engineDirectory) throws IOException {
    +    var osgiClasspath = getOsgiBootstrapClasspath(engineDirectory);
         var filter = WildcardFileFilter.builder()
                 .setWildcards("org.eclipse.osgi_*.jar")
                 .get();
    -    addToClassPath(osgiClasspath, new File(engineDirectory, OsgiDir.PLUGINS), filter);
    +    var pluginsDir = engineDirectory.resolve(OsgiDir.PLUGINS);
    +    addToClassPath(osgiClasspath, pluginsDir, filter);
         osgiClasspath.addAll(0, getSlf4jJars());
         if (maven.log.isDebugEnabled()) {
           maven.log.debug("Configuring OSGi engine classpath:");
    -      osgiClasspath.stream().forEach(file -> maven.log.debug(" + " + file.getAbsolutePath()));
    +      osgiClasspath.stream().forEach(file -> maven.log.debug(" + " + file.toAbsolutePath()));
         }
         return new URLClassLoader(toUrls(osgiClasspath));
       }
     
    -  public List getSlf4jJars() {
    +  public List getSlf4jJars() {
         return List.of(
                 maven.getJar("org.slf4j", "slf4j-api", SLF4J_VERSION),
                 maven.getJar("org.slf4j", "slf4j-simple", SLF4J_VERSION),
                 maven.getJar("org.slf4j", "log4j-over-slf4j", SLF4J_VERSION));
       }
     
    -  public static List getOsgiBootstrapClasspath(File engineDirectory) {
    -    if (engineDirectory == null || !engineDirectory.isDirectory()) {
    +  public static List getOsgiBootstrapClasspath(Path engineDirectory) {
    +    if (engineDirectory == null || !Files.isDirectory(engineDirectory)) {
           throw new RuntimeException("The engineDirectory is missing: " + engineDirectory);
         }
    -    List classPathFiles = new ArrayList<>();
    -    addToClassPath(classPathFiles, new File(engineDirectory, OsgiDir.INSTALL_AREA + "/" + OsgiDir.LIB_BOOT),
    -            new SuffixFileFilter(".jar"));
    +    var classPathFiles = new ArrayList();
    +    var libBootDir = engineDirectory.resolve(OsgiDir.INSTALL_AREA).resolve(OsgiDir.LIB_BOOT);
    +    var jarFilter = new SuffixFileFilter(".jar");
    +    addToClassPath(classPathFiles, libBootDir, jarFilter);
         return classPathFiles;
       }
     
    -  private static void addToClassPath(List classPathFiles, File dir, IOFileFilter fileFilter) {
    -    if (dir.isDirectory()) {
    -      classPathFiles.addAll(FileUtils.listFiles(dir, fileFilter, null));
    +  private static void addToClassPath(List classPathFiles, Path dir, IOFileFilter fileFilter) {
    +    if (Files.isDirectory(dir)) {
    +      classPathFiles.addAll(FileUtils.listFiles(dir.toFile(), fileFilter, null).stream().map(f -> f.toPath()).toList());
         }
       }
     
    -  public static List getIvyEngineClassPathFiles(File engineDirectory) {
    -    List classPathFiles = new ArrayList<>();
    -    for (String libDirPath : ENGINE_LIB_DIRECTORIES) {
    -      File jarDir = new File(engineDirectory, libDirPath + File.separator);
    -      if (!jarDir.isDirectory()) {
    +  public static List getIvyEngineClassPathFiles(Path engineDirectory) {
    +    if (engineDirectory == null) {
    +      return List.of();
    +    }
    +
    +    var classPathFiles = new ArrayList();
    +    for (var libDirPath : ENGINE_LIB_DIRECTORIES) {
    +      var jarDir = engineDirectory.resolve(libDirPath);
    +      if (!Files.isDirectory(jarDir)) {
             continue;
           }
    -      classPathFiles.addAll(FileUtils.listFiles(jarDir, new String[] {"jar"}, true));
    +      classPathFiles.addAll(FileUtils.listFiles(jarDir.toFile(), new String[] {"jar"}, true).stream().map(f -> f.toPath()).toList());
         }
         return classPathFiles;
       }
     
    -  public void writeEngineClasspathJar(File engineDirectory) throws IOException {
    +  public void writeEngineClasspathJar(Path engineDirectory) throws IOException {
         writeEngineClasspathJar(getIvyEngineClassPathFiles(engineDirectory));
       }
     
    -  private void writeEngineClasspathJar(List ivyEngineClassPathFiles) throws IOException {
    -    File classPathJar = new SharedFile(maven.project).getEngineClasspathJar();
    -    ClasspathJar jar = new ClasspathJar(classPathJar);
    +  private void writeEngineClasspathJar(List ivyEngineClassPathFiles) throws IOException {
    +    var classPathJar = new SharedFile(maven.project).getEngineClasspathJar();
    +    var jar = new ClasspathJar(classPathJar);
         jar.setMainClass("ch.ivyteam.ivy.server.ServerLauncher");
         jar.createFileEntries(ivyEngineClassPathFiles);
       }
     
    -  private static URL[] toUrls(List ivyEngineClassPathFiles) throws MalformedURLException {
    +  private static URL[] toUrls(List ivyEngineClassPathFiles) throws MalformedURLException {
         var classPathUrls = new ArrayList();
    -    for (File file : ivyEngineClassPathFiles) {
    -      classPathUrls.add(file.toURI().toURL());
    +    for (var file : ivyEngineClassPathFiles) {
    +      classPathUrls.add(file.toUri().toURL());
         }
         return classPathUrls.toArray(URL[]::new);
       }
    @@ -154,14 +160,13 @@ public MavenContext(RepositorySystem repoSystem, ArtifactRepository localReposit
           this.log = log;
         }
     
    -    public File getJar(String groupId, String artifactId, String version) {
    +    public Path getJar(String groupId, String artifactId, String version) {
           Artifact artifact = repoSystem.createArtifact(groupId, artifactId, version, "jar");
           File jar = new File(localRepository.getBasedir(), localRepository.pathOf(artifact));
           if (!jar.exists()) {
             log.warn("Failed to resolve '" + artifactId + "' from local repository in '" + jar + "'.");
           }
    -      return jar;
    +      return jar.toPath();
         }
       }
    -
    -}
    \ No newline at end of file
    +}
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/EngineControl.java b/src/main/java/ch/ivyteam/ivy/maven/engine/EngineControl.java
    index 34440809..56dd386f 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/EngineControl.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/EngineControl.java
    @@ -18,8 +18,6 @@
     
     import java.io.ByteArrayOutputStream;
     import java.io.File;
    -import java.io.FileNotFoundException;
    -import java.io.FileOutputStream;
     import java.io.IOException;
     import java.io.OutputStream;
     import java.net.URI;
    @@ -28,6 +26,7 @@
     import java.net.http.HttpRequest;
     import java.net.http.HttpResponse;
     import java.net.http.HttpResponse.BodyHandlers;
    +import java.nio.file.Files;
     import java.util.concurrent.TimeUnit;
     import java.util.concurrent.TimeoutException;
     import java.util.concurrent.atomic.AtomicBoolean;
    @@ -108,21 +107,22 @@ EngineState state() {
       }
     
       private CommandLine toEngineCommand(Command command) {
    -    String classpath = context.engineClasspathJarPath;
    -    if (StringUtils.isNotBlank(context.vmOptions.additionalClasspath)) {
    -      classpath += File.pathSeparator + context.vmOptions.additionalClasspath;
    +    var classpath = context.engineClasspathJarPath.toString();
    +    if (StringUtils.isNotBlank(context.vmOptions.additionalClasspath())) {
    +      classpath += File.pathSeparator + context.vmOptions.additionalClasspath();
         }
     
    -    File osgiDir = new File(context.engineDirectory, OsgiDir.INSTALL_AREA);
    +    var osgiDir = context.engineDirectory.resolve(OsgiDir.INSTALL_AREA);
     
         CommandLine cli = new CommandLine(new File(getJavaExec()))
    -            .addArgument("-classpath").addArgument(classpath)
    +            .addArgument("-classpath")
    +            .addArgument(classpath)
                 .addArgument("-Divy.engine.testheadless=true")
                 .addArgument("-Djava.awt.headless=true")
    -            .addArgument("-Dosgi.install.area=" + osgiDir.getAbsolutePath());
    +            .addArgument("-Dosgi.install.area=" + osgiDir.toAbsolutePath());
     
    -    if (StringUtils.isNotBlank(context.vmOptions.additionalVmOptions)) {
    -      cli.addArguments(context.vmOptions.additionalVmOptions, false);
    +    if (StringUtils.isNotBlank(context.vmOptions.additionalVmOptions())) {
    +      cli.addArguments(context.vmOptions.additionalVmOptions(), false);
         }
         EngineModuleHints.loadFromJvmOptionsFile(context, cli);
     
    @@ -134,12 +134,12 @@ private CommandLine toEngineCommand(Command command) {
     
       private Executor createEngineExecutor() {
         return DefaultExecutor.builder()
    -            .setWorkingDirectory(context.engineDirectory)
    +            .setWorkingDirectory(context.engineDirectory.toFile())
                 .get();
       }
     
       private PumpStreamHandler createEngineLogStreamForwarder(Consumer logLineHandler)
    -          throws FileNotFoundException {
    +          throws IOException {
         OutputStream output = getEngineLogTarget();
         OutputStream engineLogStream = new LineOrientedOutputStreamRedirector(output) {
           @Override
    @@ -163,15 +163,17 @@ public void stop() throws IOException {
         return streamHandler;
       }
     
    -  private OutputStream getEngineLogTarget() throws FileNotFoundException {
    +  private OutputStream getEngineLogTarget() throws IOException {
         if (context.engineLogFile == null) {
           context.log.info("Do not forward engine output to a persistent location");
           return new ByteArrayOutputStream();
         }
     
    -    context.properties.setMavenProperty(Property.TEST_ENGINE_LOG, context.engineLogFile.getAbsolutePath());
    -    context.log.info("Forwarding engine logs to: " + context.engineLogFile.getAbsolutePath());
    -    return new FileOutputStream(context.engineLogFile.getAbsolutePath());
    +    var logFile = context.engineLogFile;
    +    var logFilePath = logFile.toAbsolutePath().toString();
    +    context.properties.setMavenProperty(Property.TEST_ENGINE_LOG, logFilePath);
    +    context.log.info("Forwarding engine logs to: " + logFilePath);
    +    return Files.newOutputStream(logFile);
       }
     
       private String getJavaExec() {
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/EngineModuleHints.java b/src/main/java/ch/ivyteam/ivy/maven/engine/EngineModuleHints.java
    index 26c9671d..d0b06b06 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/EngineModuleHints.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/EngineModuleHints.java
    @@ -1,8 +1,8 @@
     package ch.ivyteam.ivy.maven.engine;
     
    -import java.io.File;
     import java.io.IOException;
     import java.nio.file.Files;
    +import java.nio.file.Path;
     import java.util.List;
     import java.util.stream.Collectors;
     
    @@ -15,12 +15,12 @@ public static void loadFromJvmOptionsFile(EngineMojoContext context, CommandLine
         loadJvmOptions(context.engineDirectory, context.log).stream().forEach(option -> cli.addArgument(option));
       }
     
    -  public static String loadFromJvmOptionsFile(File identifyAndGetEngineDirectory, Log log) {
    +  public static String loadFromJvmOptionsFile(Path identifyAndGetEngineDirectory, Log log) {
         return loadJvmOptions(identifyAndGetEngineDirectory, log).stream().collect(Collectors.joining(" ", " ", " "));
       }
     
    -  private static List loadJvmOptions(File engineDir, Log log) {
    -    var jvmOptionsFile = engineDir.toPath().resolve("bin").resolve("jvm-module.options");
    +  private static List loadJvmOptions(Path engineDir, Log log) {
    +    var jvmOptionsFile = engineDir.resolve("bin").resolve("jvm-module.options");
         if (!Files.exists(jvmOptionsFile)) {
           log.warn("Couldn't load jvm module options from '" + jvmOptionsFile + "' file.");
           return List.of();
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/EngineMojoContext.java b/src/main/java/ch/ivyteam/ivy/maven/engine/EngineMojoContext.java
    index 7757cbcc..1d3f9739 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/EngineMojoContext.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/EngineMojoContext.java
    @@ -16,7 +16,8 @@
     
     package ch.ivyteam.ivy.maven.engine;
     
    -import java.io.File;
    +import java.nio.file.Files;
    +import java.nio.file.Path;
     
     import org.apache.maven.plugin.logging.Log;
     import org.apache.maven.project.MavenProject;
    @@ -26,16 +27,17 @@
     import ch.ivyteam.ivy.maven.util.SharedFile;
     
     public class EngineMojoContext {
    -  public final File engineDirectory;
    +
    +  public final Path engineDirectory;
       public final MavenProject project;
       public final Log log;
       public final EngineVmOptions vmOptions;
    -  public final String engineClasspathJarPath;
    +  public final Path engineClasspathJarPath;
       public final MavenProperties properties;
    -  public final File engineLogFile;
    +  public final Path engineLogFile;
       public final Integer timeoutInSeconds;
     
    -  public EngineMojoContext(File engineDirectory, MavenProject project, Log log, File engineLogFile,
    +  public EngineMojoContext(Path engineDirectory, MavenProject project, Log log, Path engineLogFile,
               EngineVmOptions vmOptions, Integer timeoutInSeconds) {
         this.engineDirectory = engineDirectory;
         this.project = project;
    @@ -47,28 +49,26 @@ public EngineMojoContext(File engineDirectory, MavenProject project, Log log, Fi
         this.properties = new MavenProperties(project, log);
         this.engineClasspathJarPath = setupEngineClasspathJarIfNotExists();
     
    -    if (!(new File(engineClasspathJarPath).exists())) {
    +    if (!Files.exists(engineClasspathJarPath)) {
           throw new RuntimeException("Engine ClasspathJar " + engineClasspathJarPath + " does not exist.");
         }
    -    if (!(engineDirectory.exists())) {
    +    if (!Files.exists(engineDirectory)) {
           throw new RuntimeException("Engine Directory " + engineDirectory + " does not exist.");
         }
       }
     
    -  private String setupEngineClasspathJarIfNotExists() {
    -    File classpathJar = new SharedFile(project).getEngineOSGiBootClasspathJar();
    -
    -    if (!classpathJar.exists()) {
    +  private Path setupEngineClasspathJarIfNotExists() {
    +    var classpathJar = new SharedFile(project).getEngineOSGiBootClasspathJar().toAbsolutePath();
    +    if (!Files.exists(classpathJar)) {
           try {
             log.info("Creating a classpath jar for starting the engine");
             new ClasspathJar(classpathJar)
                     .createFileEntries(EngineClassLoaderFactory.getOsgiBootstrapClasspath(engineDirectory));
           } catch (Exception ex) {
             throw new RuntimeException(
    -                "Could not create engine classpath jar: '" + classpathJar.getAbsolutePath() + "'", ex);
    +                "Could not create engine classpath jar: '" + classpathJar + "'", ex);
           }
         }
    -
    -    return classpathJar.getAbsolutePath();
    +    return classpathJar;
       }
     }
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/EngineVersionEvaluator.java b/src/main/java/ch/ivyteam/ivy/maven/engine/EngineVersionEvaluator.java
    index f77f9452..b3df05c1 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/EngineVersionEvaluator.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/EngineVersionEvaluator.java
    @@ -1,6 +1,7 @@
     package ch.ivyteam.ivy.maven.engine;
     
    -import java.io.File;
    +import java.nio.file.Files;
    +import java.nio.file.Path;
     
     import org.apache.commons.lang3.ArrayUtils;
     import org.apache.commons.lang3.StringUtils;
    @@ -11,19 +12,20 @@
     import ch.ivyteam.ivy.maven.engine.EngineClassLoaderFactory.OsgiDir;
     
     public class EngineVersionEvaluator {
    +
       public static final String LIBRARY_ID = "ch.ivyteam.util";
     
       private Log log;
    -  private File engineDir;
    +  private Path engineDir;
     
    -  public EngineVersionEvaluator(Log log, File engineDir) {
    +  public EngineVersionEvaluator(Log log, Path engineDir) {
         this.log = log;
         this.engineDir = engineDir;
       }
     
       public ArtifactVersion evaluateVersion() {
         if (!isOSGiEngine(engineDir)) {
    -      String absolutePath = engineDir == null ? "" : engineDir.getAbsolutePath();
    +      String absolutePath = engineDir == null ? "" : engineDir.toAbsolutePath().toString();
           log.info("Can not evaluate version of a non-OSGi engine in directory '" + absolutePath + "'");
           return null;
         }
    @@ -37,9 +39,9 @@ public ArtifactVersion evaluateVersion() {
         return new DefaultArtifactVersion(toReleaseVersion(version));
       }
     
    -  public static boolean isOSGiEngine(File engineDir) {
    -    File folder = new File(engineDir, OsgiDir.INSTALL_AREA);
    -    return folder.exists();
    +  public static boolean isOSGiEngine(Path engineDir) {
    +    var folder = engineDir.resolve(OsgiDir.INSTALL_AREA);
    +    return Files.exists(folder);
       }
     
       public static String toReleaseVersion(String version) { // 6.1.0.51869 ->
    @@ -52,12 +54,12 @@ public static String toReleaseVersion(String version) { // 6.1.0.51869 ->
       }
     
       private String getLibraryFileName(String libraryId) {
    -    File ivyLibs = new File(engineDir, OsgiDir.PLUGINS);
    -    if (!ivyLibs.exists()) {
    +    var ivyLibs = engineDir.resolve(OsgiDir.PLUGINS);
    +    if (!Files.exists(ivyLibs)) {
           return null;
         }
     
    -    String[] libraryNames = ivyLibs.list();
    +    String[] libraryNames = ivyLibs.toFile().list();
         if (libraryNames == null) {
           return null;
         }
    @@ -69,5 +71,4 @@ private String getLibraryFileName(String libraryId) {
         }
         return null;
       }
    -
     }
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/EngineVmOptions.java b/src/main/java/ch/ivyteam/ivy/maven/engine/EngineVmOptions.java
    index 73105956..a2fce010 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/EngineVmOptions.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/EngineVmOptions.java
    @@ -16,14 +16,6 @@
     
     package ch.ivyteam.ivy.maven.engine;
     
    -public class EngineVmOptions {
    -  public final String maxmem;
    -  public final String additionalClasspath;
    -  public final String additionalVmOptions;
    +public record EngineVmOptions(String additionalClasspath, String additionalVmOptions) {
     
    -  public EngineVmOptions(String maxmem, String additionalClasspath, String additionalVmOptions) {
    -    this.maxmem = maxmem;
    -    this.additionalClasspath = additionalClasspath;
    -    this.additionalVmOptions = additionalVmOptions;
    -  }
     }
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/MavenProjectBuilderProxy.java b/src/main/java/ch/ivyteam/ivy/maven/engine/MavenProjectBuilderProxy.java
    index a5f8d1b3..e781dd4a 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/MavenProjectBuilderProxy.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/MavenProjectBuilderProxy.java
    @@ -21,6 +21,7 @@
     import java.lang.reflect.Constructor;
     import java.lang.reflect.Method;
     import java.net.URLClassLoader;
    +import java.nio.file.Path;
     import java.util.List;
     import java.util.Map;
     import java.util.concurrent.Callable;
    @@ -37,7 +38,7 @@
     /**
      * Provides project build functionality that can only be accessed trough
      * reflection on an ivy Engine classloader.
    - * 
    + *
      * @author Reguel Wermelinger
      * @since 6.0.0
      */
    @@ -45,12 +46,12 @@ public class MavenProjectBuilderProxy {
       private static final String FQ_DELEGATE_CLASS_NAME = "ch.ivyteam.ivy.project.build.MavenProjectBuilder";
       private final Object delegate;
       private final Class delegateClass;
    -  private final File baseDirToBuildIn;
    +  private final Path baseDirToBuildIn;
       private final String engineClasspath;
       private final Log log;
     
    -  public MavenProjectBuilderProxy(EngineClassLoaderFactory classLoaderFactory, File workspace,
    -          File baseDirToBuildIn, Log log, int timeoutEngineStartInSeconds) throws Exception {
    +  public MavenProjectBuilderProxy(EngineClassLoaderFactory classLoaderFactory, Path workspace,
    +          Path baseDirToBuildIn, Log log, int timeoutEngineStartInSeconds) throws Exception {
         this.baseDirToBuildIn = baseDirToBuildIn;
         this.log = log;
     
    @@ -60,9 +61,9 @@ public MavenProjectBuilderProxy(EngineClassLoaderFactory classLoaderFactory, Fil
         delegateClass = getOsgiBundledDelegate(ivyEngineClassLoader, timeoutEngineStartInSeconds);
         Constructor constructor = delegateClass.getDeclaredConstructor(File.class);
     
    -    delegate = executeInEngineDir(() -> constructor.newInstance(workspace));
    +    delegate = executeInEngineDir(() -> constructor.newInstance(workspace.toFile()));
     
    -    List engineJars = EngineClassLoaderFactory.getIvyEngineClassPathFiles(baseDirToBuildIn);
    +    var engineJars = EngineClassLoaderFactory.getIvyEngineClassPathFiles(baseDirToBuildIn);
         engineClasspath = getEngineClasspath(engineJars);
       }
     
    @@ -105,9 +106,9 @@ private static Object findBundle(Object bundleContext, String symbolicName) thro
         throw new RuntimeException("Failed to resolve bundle with symbolice name '" + symbolicName + "'.");
       }
     
    -  private static String getEngineClasspath(List jars) {
    +  private static String getEngineClasspath(List jars) {
         return jars.stream()
    -            .map(file -> file.getAbsolutePath())
    +            .map(file -> file.toAbsolutePath().toString())
                 .collect(Collectors.joining(File.pathSeparator));
       }
     
    @@ -168,7 +169,7 @@ private Method getMethod(String name, Class... parameterTypes) {
     
       private  T executeInEngineDir(Callable function) throws Exception {
         String originalBaseDirectory = System.getProperty("user.dir");
    -    System.setProperty("user.dir", baseDirToBuildIn.getAbsolutePath());
    +    System.setProperty("user.dir", baseDirToBuildIn.toAbsolutePath().toString());
         try {
           return function.call();
         } finally {
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/OsgiRuntime.java b/src/main/java/ch/ivyteam/ivy/maven/engine/OsgiRuntime.java
    index b0b16983..47e465ae 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/OsgiRuntime.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/OsgiRuntime.java
    @@ -1,8 +1,8 @@
     package ch.ivyteam.ivy.maven.engine;
     
    -import java.io.File;
     import java.lang.reflect.Method;
     import java.net.URLClassLoader;
    +import java.nio.file.Path;
     import java.util.ArrayList;
     import java.util.Arrays;
     import java.util.LinkedHashMap;
    @@ -25,10 +25,11 @@
      * @since 7.0
      */
     class OsgiRuntime {
    -  private final File engineDir;
    +
    +  private final Path engineDir;
       private final Log log;
     
    -  OsgiRuntime(File engineDir, Log log) {
    +  OsgiRuntime(Path engineDir, Log log) {
         this.engineDir = engineDir;
         this.log = log;
       }
    @@ -96,9 +97,9 @@ private Map createOsgiConfigurationProps() {
         Map properties = new LinkedHashMap<>();
     
         properties.put("osgi.framework.useSystemProperties", Boolean.TRUE.toString());
    -    properties.put("user.dir", engineDir.getAbsolutePath());
    -    File osgiDir = new File(engineDir, OsgiDir.INSTALL_AREA);
    -    properties.put("osgi.install.area", osgiDir.getAbsolutePath());
    +    properties.put("user.dir", engineDir.toAbsolutePath().toString());
    +    var osgiDir = engineDir.resolve(OsgiDir.INSTALL_AREA);
    +    properties.put("osgi.install.area", osgiDir.toAbsolutePath().toString());
         properties.put("org.osgi.framework.bundle.parent", "framework");
         properties.put("org.osgi.framework.bootdelegation",
                 "javax.annotation,ch.ivyteam.ivy.boot.osgi.win,ch.ivyteam.ivy.jaas," // original
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/DeploymentOptionsFileFactory.java b/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/DeploymentOptionsFileFactory.java
    index 009633ed..e7c98029 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/DeploymentOptionsFileFactory.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/DeploymentOptionsFileFactory.java
    @@ -3,9 +3,9 @@
     import java.io.File;
     import java.io.IOException;
     import java.nio.charset.StandardCharsets;
    +import java.nio.file.Path;
     import java.util.Collections;
     
    -import org.apache.commons.io.FileUtils;
     import org.apache.commons.io.FilenameUtils;
     import org.apache.maven.execution.MavenSession;
     import org.apache.maven.plugin.MojoExecutionException;
    @@ -14,23 +14,24 @@
     import org.apache.maven.shared.filtering.MavenFilteringException;
     
     public class DeploymentOptionsFileFactory {
    +
       private static final String YAML = "yaml";
    -  private final File deployableArtifact;
    +  private final Path deployableArtifact;
     
    -  public DeploymentOptionsFileFactory(File deployableArtifact) {
    +  public DeploymentOptionsFileFactory(Path deployableArtifact) {
         this.deployableArtifact = deployableArtifact;
       }
     
    -  public File createFromTemplate(File optionsFile, MavenProject project, MavenSession session,
    +  public Path createFromTemplate(Path optionsFile, MavenProject project, MavenSession session,
               MavenFileFilter fileFilter) throws MojoExecutionException {
    -    if (!isOptionsFile(optionsFile)) {
    +    if (!isOptionsFile(optionsFile.toFile())) {
           return null;
         }
     
    -    String fileFormat = FilenameUtils.getExtension(optionsFile.getName());
    -    File targetFile = getTargetFile(fileFormat);
    +    String fileFormat = FilenameUtils.getExtension(optionsFile.getFileName().toString());
    +    var targetFile = getTargetFile(fileFormat);
         try {
    -      fileFilter.copyFile(optionsFile, targetFile, true, project, Collections.emptyList(), false,
    +      fileFilter.copyFile(optionsFile.toFile(), targetFile.toFile(), true, project, Collections.emptyList(), false,
                   StandardCharsets.UTF_8.name(), session);
         } catch (MavenFilteringException ex) {
           throw new MojoExecutionException("Failed to resolve templates in options file", ex);
    @@ -45,20 +46,19 @@ private static boolean isOptionsFile(File optionsFile) {
                 optionsFile.canRead();
       }
     
    -  public File createFromConfiguration(String options) throws MojoExecutionException {
    -    File yamlOptionsFile = getTargetFile(YAML);
    +  public Path createFromConfiguration(String options) throws MojoExecutionException {
    +    var yamlOptionsFile = getTargetFile(YAML);
         try {
    -      FileUtils.write(yamlOptionsFile, options, StandardCharsets.UTF_8);
    +      java.nio.file.Files.writeString(yamlOptionsFile, options);
         } catch (IOException ex) {
           throw new MojoExecutionException("Failed to write options file '" + yamlOptionsFile + "'.", ex);
         }
         return yamlOptionsFile;
       }
     
    -  private File getTargetFile(String fileFormat) {
    -    String prefix = deployableArtifact.getName() + ".options.";
    -    String targetFileName = prefix + fileFormat;
    -    return new File(deployableArtifact.getParentFile(), targetFileName);
    +  private Path getTargetFile(String fileFormat) {
    +    var prefix = deployableArtifact.getFileName().toString() + ".options.";
    +    var targetFileName = prefix + fileFormat;
    +    return deployableArtifact.resolveSibling(targetFileName);
       }
    -
     }
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/dir/DeploymentFiles.java b/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/dir/DeploymentFiles.java
    index 4da43318..a873dc28 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/dir/DeploymentFiles.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/dir/DeploymentFiles.java
    @@ -1,42 +1,50 @@
     package ch.ivyteam.ivy.maven.engine.deploy.dir;
     
    -import java.io.File;
    -import java.util.Arrays;
    -
    -import org.apache.commons.io.FileUtils;
    +import java.io.IOException;
    +import java.nio.file.Files;
    +import java.nio.file.Path;
    +import java.util.List;
     
     /**
      * Engine status files from deployment.
      */
     public class DeploymentFiles {
    +
       private static final String LOG = ".deploymentLog";
       private static final String ERROR_LOG = ".deploymentError";
     
    -  private File deployable;
    +  private final Path deployable;
     
    -  public DeploymentFiles(File deployable) {
    +  public DeploymentFiles(Path deployable) {
         this.deployable = deployable;
       }
     
    -  File getDeployCandidate() {
    +  Path getDeployCandidate() {
         return deployable;
       }
     
    -  public File log() {
    -    return getFile(LOG);
    +  public Path log() {
    +    return toFile(LOG);
       }
     
    -  public File errorLog() {
    -    return getFile(ERROR_LOG);
    +  public Path errorLog() {
    +    return toFile(ERROR_LOG);
       }
     
    -  private File getFile(String markerExtension) {
    -    return new File(deployable.getParent(), deployable.getName() + markerExtension);
    +  private Path toFile(String ext) {
    +    return deployable.resolveSibling(deployable.getFileName() + ext);
       }
     
       public void clearAll() {
    -    for (String markerExtension : Arrays.asList(LOG, ERROR_LOG)) {
    -      FileUtils.deleteQuietly(getFile(markerExtension));
    +    for (var ext : List.of(LOG, ERROR_LOG)) {
    +      var file = toFile(ext);
    +      if (Files.exists(file)) {
    +        try {
    +          Files.delete(file);
    +        } catch (IOException ex) {
    +          throw new RuntimeException("Could not delete " + file, ex);
    +        }
    +      }
         }
       }
    -}
    \ No newline at end of file
    +}
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/dir/FileDeployer.java b/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/dir/FileDeployer.java
    index 279e8720..f74e730e 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/dir/FileDeployer.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/dir/FileDeployer.java
    @@ -17,7 +17,8 @@
     
     import java.io.File;
     import java.io.IOException;
    -import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +import java.nio.file.Path;
     import java.util.concurrent.TimeUnit;
     import java.util.concurrent.TimeoutException;
     import java.util.function.Supplier;
    @@ -27,20 +28,20 @@
     import org.apache.maven.plugin.logging.Log;
     
     public class FileDeployer implements IvyDeployer {
    -  private final File deployDir;
    +
    +  private final Path deployDir;
    +  private final Path deploymentOptionsFile;
       private final Integer timeoutInSeconds;
    +  private final Path deployFile;
    +  private final Path targetDeployableFile;
     
       private Log log;
       private DeploymentFiles deploymentFiles;
     
    -  private File deployFile;
    -  private File targetDeployableFile;
    -  private File deploymentOptionsFile;
     
    -  public FileDeployer(File deployDir, File deploymentOptions, Integer deployTimeoutInSeconds, File deployFile,
    -          File targetDeployableFile) {
    +  public FileDeployer(Path deployDir, Path deploymentOptionsFile, Integer deployTimeoutInSeconds, Path deployFile, Path targetDeployableFile) {
         this.deployDir = deployDir;
    -    this.deploymentOptionsFile = deploymentOptions;
    +    this.deploymentOptionsFile = deploymentOptionsFile;
         this.timeoutInSeconds = deployTimeoutInSeconds;
     
         this.deployFile = deployFile;
    @@ -50,10 +51,9 @@ public FileDeployer(File deployDir, File deploymentOptions, Integer deployTimeou
       @Override
       @SuppressWarnings("hiding")
       public void deploy(String deployableFilePath, Log log) throws MojoExecutionException {
    -    File deployableFile = new File(deployDir, deployableFilePath);
    +    var deployableFile = deployDir.resolve(deployableFilePath);
         this.deploymentFiles = new DeploymentFiles(deployableFile);
         this.log = log;
    -
         deployInternal();
       }
     
    @@ -71,9 +71,10 @@ private void clear() {
       private void initDeployment() throws MojoExecutionException {
         try {
           if (deploymentOptionsFile != null) {
    -        File engineOption = new File(deploymentFiles.getDeployCandidate().getParentFile(),
    -                deploymentOptionsFile.getName());
    -        FileUtils.copyFile(deploymentOptionsFile, engineOption);
    +        //var engineOption = deploymentFiles.getDeployCandidate().resolveSibling(deploymentOptionsFile.getName());
    +        //Files.copy(deploymentOptionsFile.toPath(), engineOption);
    +        File engineOption = new File(deploymentFiles.getDeployCandidate().getParent().toFile(), deploymentOptionsFile.getFileName().toString());
    +        FileUtils.copyFile(deploymentOptionsFile.toFile(), engineOption);
           }
         } catch (IOException ex) {
           throw new MojoExecutionException("Failed to initialize engine deployment, could not copy options file",
    @@ -84,19 +85,18 @@ private void initDeployment() throws MojoExecutionException {
       private void copyDeployableToEngine() throws MojoExecutionException {
         try {
           log.info("Uploading file " + deployFile + " to " + targetDeployableFile);
    -      FileUtils.copyFile(deployFile, targetDeployableFile);
    +      FileUtils.copyFile(deployFile.toFile(), targetDeployableFile.toFile());
         } catch (IOException ex) {
    -      throw new MojoExecutionException("Upload of file '" + deployFile.getName() + "' to engine failed.", ex);
    +      throw new MojoExecutionException("Upload of file '" + deployFile.getFileName().toString() + "' to engine failed.", ex);
         }
       }
     
       private void determineDeployResult() throws MojoExecutionException {
    -    FileLogForwarder logForwarder = new FileLogForwarder(deploymentFiles.log(), log,
    -            new EngineLogLineHandler(log));
    +    var logForwarder = new FileLogForwarder(deploymentFiles.log(), log, new EngineLogLineHandler(log));
         try {
           logForwarder.activate();
           log.debug("Deployment candidate " + deploymentFiles.getDeployCandidate());
    -      wait(() -> !deploymentFiles.getDeployCandidate().exists(), timeoutInSeconds, TimeUnit.SECONDS);
    +      wait(() -> !Files.exists(deploymentFiles.getDeployCandidate()), timeoutInSeconds, TimeUnit.SECONDS);
         } catch (TimeoutException ex) {
           throw new MojoExecutionException("Deployment result does not exist", ex);
         } finally {
    @@ -108,14 +108,15 @@ private void determineDeployResult() throws MojoExecutionException {
       }
     
       private void failOnError() throws MojoExecutionException {
    -    if (deploymentFiles.errorLog().exists()) {
    +    var errorLog = deploymentFiles.errorLog();
    +    if (Files.exists(errorLog)) {
           try {
    -        log.error(FileUtils.readFileToString(deploymentFiles.errorLog(), StandardCharsets.UTF_8));
    +        var content = Files.readString(errorLog);
    +        log.error(content);
           } catch (IOException ex) {
             log.error("Failed to resolve deployment error cause", ex);
           }
    -      throw new MojoExecutionException(
    -              "Deployment of '" + deploymentFiles.getDeployCandidate().getName() + "' failed!");
    +      throw new MojoExecutionException("Deployment of '" + deploymentFiles.getDeployCandidate().getFileName() + "' failed!");
         }
       }
     
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/dir/FileLogForwarder.java b/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/dir/FileLogForwarder.java
    index c4596d82..d307df29 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/dir/FileLogForwarder.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/dir/FileLogForwarder.java
    @@ -19,6 +19,7 @@
     import java.io.File;
     import java.io.IOException;
     import java.io.RandomAccessFile;
    +import java.nio.file.Path;
     
     import org.apache.commons.io.filefilter.FileFilterUtils;
     import org.apache.commons.io.filefilter.IOFileFilter;
    @@ -33,7 +34,7 @@
      * @since 6.1.0
      */
     class FileLogForwarder {
    -  private final File engineLog;
    +  private final Path engineLog;
       private final Log mavenLog;
     
       private FileAlterationMonitor monitor;
    @@ -43,7 +44,7 @@ class FileLogForwarder {
        * @param engineLog the log file to watch for new lines
        * @param mavenLog the target logger
        */
    -  FileLogForwarder(File engineLog, Log mavenLog, LogLineHandler handler) {
    +  FileLogForwarder(Path engineLog, Log mavenLog, LogLineHandler handler) {
         this.engineLog = engineLog;
         this.mavenLog = mavenLog;
         this.logLineHandler = handler;
    @@ -52,8 +53,8 @@ class FileLogForwarder {
       public synchronized void activate() throws MojoExecutionException {
         IOFileFilter logFilter = FileFilterUtils.and(
                 FileFilterUtils.fileFileFilter(),
    -            FileFilterUtils.nameFileFilter(engineLog.getName()));
    -    FileAlterationObserver fileObserver = new FileAlterationObserver(engineLog.getParent(), logFilter);
    +            FileFilterUtils.nameFileFilter(engineLog.getFileName().toString()));
    +    FileAlterationObserver fileObserver = new FileAlterationObserver(engineLog.getParent().toFile(), logFilter);
         fileObserver.addListener(new LogModificationListener());
         monitor = new FileAlterationMonitor(100);
         monitor.addObserver(fileObserver);
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/http/HttpDeployer.java b/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/http/HttpDeployer.java
    index e1da85d9..44fcd5d8 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/http/HttpDeployer.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/deploy/http/HttpDeployer.java
    @@ -1,9 +1,9 @@
     package ch.ivyteam.ivy.maven.engine.deploy.http;
     
    -import java.io.File;
     import java.io.IOException;
     import java.net.URI;
     import java.net.URISyntaxException;
    +import java.nio.file.Path;
     
     import org.apache.http.HttpEntity;
     import org.apache.http.HttpHost;
    @@ -35,13 +35,13 @@ public class HttpDeployer {
       private static final String DEPLOY_URI = "/system/api/apps/";
       private String serverUrl;
       private String targetApplication;
    -  private File deployFile;
    -  private File deploymentOptions;
    +  private Path deployFile;
    +  private Path deploymentOptions;
       private Server server;
       private SecDispatcher secDispatcher;
     
       public HttpDeployer(SecDispatcher secDispatcher, Server server, String serverUrl, String targetApplication,
    -          File deployFile, File deploymentOptions) {
    +          Path deployFile, Path deploymentOptions) {
         this.secDispatcher = secDispatcher;
         this.server = server;
         this.serverUrl = serverUrl;
    @@ -75,8 +75,7 @@ private void executeRequest(Log log, CloseableHttpClient client)
           int status = response.getStatusLine().getStatusCode();
           if (status != HttpStatus.SC_OK) {
             log.error(deploymentLog);
    -        throw new MojoExecutionException("Deployment of file '" + deployFile.getName()
    -                + "' to engine failed (Status: " + status + ")");
    +        throw new MojoExecutionException("Deployment of file '" + deployFile.getFileName() + "' to engine failed (Status: " + status + ")");
           }
           log.debug(deploymentLog);
           log.info("Deployment finished");
    @@ -92,11 +91,11 @@ private String readDeploymentLog(HttpEntity resultEntity) throws IOException {
         return EntityUtils.toString(resultEntity);
       }
     
    -  private HttpEntity getRequestData(File resolvedOptionsFile) {
    +  private HttpEntity getRequestData(Path resolvedOptionsFile) {
         MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    -    builder.addPart("fileToDeploy", new FileBody(deployFile));
    +    builder.addPart("fileToDeploy", new FileBody(deployFile.toFile()));
         if (resolvedOptionsFile != null) {
    -      builder.addPart("deploymentOptions", new FileBody(resolvedOptionsFile, ContentType.TEXT_PLAIN));
    +      builder.addPart("deploymentOptions", new FileBody(resolvedOptionsFile.toFile(), ContentType.TEXT_PLAIN));
         }
         return builder.build();
       }
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/download/EngineDownloader.java b/src/main/java/ch/ivyteam/ivy/maven/engine/download/EngineDownloader.java
    index b5659803..96e0274b 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/download/EngineDownloader.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/download/EngineDownloader.java
    @@ -1,11 +1,11 @@
     package ch.ivyteam.ivy.maven.engine.download;
     
    -import java.io.File;
    +import java.nio.file.Path;
     
     import org.apache.maven.plugin.MojoExecutionException;
     
     public interface EngineDownloader {
    -  File downloadEngine() throws MojoExecutionException;
     
    +  Path downloadEngine() throws MojoExecutionException;
       String getZipFileNameFromDownloadLocation() throws MojoExecutionException;
     }
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/download/MavenEngineDownloader.java b/src/main/java/ch/ivyteam/ivy/maven/engine/download/MavenEngineDownloader.java
    index 5aa877fe..77950e99 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/download/MavenEngineDownloader.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/download/MavenEngineDownloader.java
    @@ -1,6 +1,6 @@
     package ch.ivyteam.ivy.maven.engine.download;
     
    -import java.io.File;
    +import java.nio.file.Path;
     import java.util.List;
     
     import org.apache.maven.plugin.MojoExecutionException;
    @@ -46,9 +46,9 @@ private ArtifactResult resolveArtifact() throws MojoExecutionException {
       }
     
       @Override
    -  public File downloadEngine() throws MojoExecutionException {
    +  public Path downloadEngine() throws MojoExecutionException {
         log.info("Downloading engine " + engineArtifact.getVersion() + " using maven plugin repositories");
    -    return resolveArtifact().getArtifact().getFile();
    +    return resolveArtifact().getArtifact().getFile().toPath();
       }
     
       @Override
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/download/URLEngineDownloader.java b/src/main/java/ch/ivyteam/ivy/maven/engine/download/URLEngineDownloader.java
    index b729ae10..b296d0fc 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/engine/download/URLEngineDownloader.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/download/URLEngineDownloader.java
    @@ -1,6 +1,5 @@
     package ch.ivyteam.ivy.maven.engine.download;
     
    -import java.io.File;
     import java.io.InputStream;
     import java.net.MalformedURLException;
     import java.net.URI;
    @@ -31,12 +30,12 @@ public class URLEngineDownloader implements EngineDownloader {
       private final String ivyVersion;
       private final VersionRange ivyVersionRange;
       private final Log log;
    -  private final File downloadDirectory;
    +  private final Path downloadDirectory;
       private String zipFileName = null;
       public ProxyInfoProvider proxies;
     
       public URLEngineDownloader(URL engineDownloadUrl, URL engineListPageUrl, String osArchitecture,
    -          String ivyVersion, VersionRange ivyVersionRange, Log log, File downloadDirectory,
    +          String ivyVersion, VersionRange ivyVersionRange, Log log, Path downloadDirectory,
               ProxyInfoProvider proxies) {
         this.engineDownloadUrl = engineDownloadUrl;
         this.engineListPageUrl = engineListPageUrl;
    @@ -49,7 +48,7 @@ public URLEngineDownloader(URL engineDownloadUrl, URL engineListPageUrl, String
       }
     
       @Override
    -  public File downloadEngine() throws MojoExecutionException {
    +  public Path downloadEngine() throws MojoExecutionException {
         URL downloadUrlToUse = engineDownloadUrl;
         if (downloadUrlToUse == null) {
           downloadUrlToUse = findEngineDownloadUrlFromListPage();
    @@ -72,13 +71,13 @@ private URL findEngineDownloadUrlFromListPage() throws MojoExecutionException {
         }
       }
     
    -  private File downloadEngineFromUrl(URL engineUrl) throws MojoExecutionException {
    -    File downloadZip = evaluateTargetFile(engineUrl);
    +  private Path downloadEngineFromUrl(URL engineUrl) throws MojoExecutionException {
    +    var downloadZip = evaluateTargetFile(engineUrl);
         try {
           log.info("Starting engine download from " + engineUrl);
           var repo = new Repository("engine.repo", StringUtils.substringBeforeLast(engineUrl.toExternalForm(), "/"));
           var resource = StringUtils.substringAfterLast(engineUrl.getPath(), "/");
    -      wagonDownload(repo, resource, downloadZip.toPath());
    +      wagonDownload(repo, resource, downloadZip);
           return downloadZip;
         } catch (Exception ex) {
           throw new MojoExecutionException("Failed to download engine from '" + engineUrl + "' to '"
    @@ -86,13 +85,13 @@ private File downloadEngineFromUrl(URL engineUrl) throws MojoExecutionException
         }
       }
     
    -  private File evaluateTargetFile(URL engineUrl) {
    +  private Path evaluateTargetFile(URL engineUrl) {
         zipFileName = StringUtils.substringAfterLast(engineUrl.getPath(), "/");
    -    File downloadZip = new File(downloadDirectory, zipFileName);
    +    var downloadZip = downloadDirectory.resolve(zipFileName);
         int tempFileSuffix = 0;
    -    while (downloadZip.exists()) {
    +    while (Files.exists(downloadZip)) {
           String suffixedZipFileName = zipFileName + "." + tempFileSuffix;
    -      downloadZip = new File(downloadDirectory, suffixedZipFileName);
    +      downloadZip = downloadDirectory.resolve(suffixedZipFileName);
           tempFileSuffix++;
         }
         return downloadZip;
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/test/AbstractIntegrationTestMojo.java b/src/main/java/ch/ivyteam/ivy/maven/test/AbstractIntegrationTestMojo.java
    index 4a3e2e36..1423b2b6 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/test/AbstractIntegrationTestMojo.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/test/AbstractIntegrationTestMojo.java
    @@ -1,6 +1,6 @@
     package ch.ivyteam.ivy.maven.test;
     
    -import java.io.File;
    +import java.nio.file.Path;
     import java.util.Objects;
     
     import org.apache.commons.lang3.StringUtils;
    @@ -35,7 +35,7 @@ public abstract class AbstractIntegrationTestMojo extends AbstractEngineMojo {
       @Parameter(property = "ivy.test.engine", defaultValue = TestEngineLocation.COPY_FROM_CACHE)
       String testEngine;
     
    -  public final File getEngineDir(MavenProject project) throws MojoExecutionException {
    +  public final Path getEngineDir(MavenProject project) throws MojoExecutionException {
         if (engineToTarget()) {
           return getTargetDir(project);
         }
    @@ -52,15 +52,15 @@ private boolean isLocation(String location) {
       }
     
       private boolean isCachedEngine() throws MojoExecutionException {
    -    File engineDir = identifyAndGetEngineDirectory();
    +    var engineDir = identifyAndGetEngineDirectory();
         if (engineDir == null) {
           return false;
         }
    -    return Objects.equals(engineDir.getParentFile(), engineCacheDirectory);
    +    return Objects.equals(engineDir.getParent(), engineCacheDirectory);
       }
     
    -  File getTargetDir(MavenProject project) {
    -    return new File(project.getBuild().getDirectory(), "ivyEngine");
    +  Path getTargetDir(MavenProject project) {
    +    return Path.of(project.getBuild().getDirectory()).resolve("ivyEngine");
       }
     
       static interface TestEngineLocation {
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/test/SetupIvyTestPropertiesMojo.java b/src/main/java/ch/ivyteam/ivy/maven/test/SetupIvyTestPropertiesMojo.java
    index cd24b5e4..683bcf94 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/test/SetupIvyTestPropertiesMojo.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/test/SetupIvyTestPropertiesMojo.java
    @@ -16,9 +16,10 @@
     
     package ch.ivyteam.ivy.maven.test;
     
    -import java.io.File;
     import java.io.IOException;
     import java.net.URI;
    +import java.nio.file.Files;
    +import java.nio.file.Path;
     import java.util.ArrayList;
     import java.util.List;
     import java.util.stream.Collectors;
    @@ -88,21 +89,21 @@ public void execute() throws MojoExecutionException, MojoFailureException {
     
       private void setIvyProperties(MavenProperties properties) throws MojoExecutionException {
         SharedFile shared = new SharedFile(project);
    -    File engineCp = shared.getEngineClasspathJar();
    -    if (engineCp.exists()) {
    +    var engineCp = shared.getEngineClasspathJar();
    +    if (Files.exists(engineCp)) {
           properties.setMavenProperty(Property.IVY_ENGINE_CLASSPATH, getClasspath(engineCp));
         }
     
    -    File iarCp = shared.getIarDependencyClasspathJar();
    -    if (iarCp.exists()) {
    +    var iarCp = shared.getIarDependencyClasspathJar();
    +    if (Files.exists(iarCp)) {
           properties.setMavenProperty(Property.IVY_PROJECT_IAR_CLASSPATH, getClasspath(iarCp));
         }
     
    -    File tstVmDir = createTestVmRuntime();
    -    properties.setMavenProperty(Property.IVY_TEST_VM_RUNTIME, tstVmDir.getAbsolutePath());
    +    var tstVmDir = createTestVmRuntime();
    +    properties.setMavenProperty(Property.IVY_TEST_VM_RUNTIME, tstVmDir.toAbsolutePath().toString());
       }
     
    -  private File createTestVmRuntime() throws MojoExecutionException {
    +  private Path createTestVmRuntime() throws MojoExecutionException {
         IvyTestRuntime testRuntime = new IvyTestRuntime();
         testRuntime.setProductDir(identifyAndGetEngineDirectory());
         testRuntime.setProjectLocations(getProjects());
    @@ -114,11 +115,11 @@ private File createTestVmRuntime() throws MojoExecutionException {
       }
     
       private List getProjects() {
    -    List deps = new ArrayList<>();
    -    deps.add(project.getBasedir());
    +    var deps = new ArrayList();
    +    deps.add(project.getBasedir().toPath());
         deps.addAll(MavenRuntime.getDependencies(project, session, "iar"));
         return deps.stream()
    -            .map(file -> file.toURI())
    +            .map(file -> file.toUri())
                 .collect(Collectors.toList());
       }
     
    @@ -141,16 +142,15 @@ private void setTestOutputDirectory() {
         try {
           String testOutputDirectory = CompilerResult.load(project).getTestOutputDirectory();
           if (testOutputDirectory != null) {
    -        project.getBuild().setTestOutputDirectory(
    -                new File(project.getBasedir(), testOutputDirectory).getAbsolutePath());
    +        var dir = project.getBasedir().toPath().resolve(testOutputDirectory).toAbsolutePath();
    +        project.getBuild().setTestOutputDirectory(dir.toString());
           }
         } catch (IOException ex) {
           getLog().warn("Failed to set up ${project.build.testOutputDirectory}", ex);
         }
       }
     
    -  private static String getClasspath(File jar) {
    +  private static String getClasspath(Path jar) {
         return new ClasspathJar(jar).getClasspathFiles();
       }
    -
     }
    diff --git a/src/main/java/ch/ivyteam/ivy/maven/test/StartTestEngineMojo.java b/src/main/java/ch/ivyteam/ivy/maven/test/StartTestEngineMojo.java
    index 879e8660..5c498f62 100644
    --- a/src/main/java/ch/ivyteam/ivy/maven/test/StartTestEngineMojo.java
    +++ b/src/main/java/ch/ivyteam/ivy/maven/test/StartTestEngineMojo.java
    @@ -16,7 +16,6 @@
     
     package ch.ivyteam.ivy.maven.test;
     
    -import java.io.File;
     import java.io.IOException;
     import java.nio.file.Files;
     import java.nio.file.Path;
    @@ -36,14 +35,14 @@
     
     /**
      * Starts the Axon Ivy Engine for integration testing.
    - * 
    + *
      * 

    * After starting the engine, this goal provides the url of the engine as * property test.engine.url. You can use this property to configure * your 'maven-failsafe-plugin' to work against this test engine. However, in an * iar-integration-test lifecycle this is already provided by the * 'ivy-integration-test-properties' goal. - * + * *

      * {@code
      *   maven-failsafe-plugin
    @@ -53,7 +52,7 @@
      *   
      * }
      * 
    - * + * * @since 6.2.0 */ @Mojo(name = StartTestEngineMojo.GOAL) @@ -83,7 +82,7 @@ public class StartTestEngineMojo extends AbstractIntegrationTestMojo { /** The file where the engine start is logged **/ @Parameter(property = "ivy.engine.start.log", required = false, defaultValue = "${project.build.directory}/testEngineOut.log") - File engineLogFile; + Path engineLogFile; /** The maximum amount of seconds that we wait for a engine to start */ @Parameter(property = IVY_ENGINE_START_TIMEOUT_SECONDS, defaultValue = "120") @@ -108,21 +107,24 @@ public void execute() throws MojoExecutionException, MojoFailureException { } public Executor startEngine() throws Exception { - File engineDir = identifyAndGetEngineDirectory(); + var engineDir = engineDir(); + var vmOptions = new EngineVmOptions(additionalClasspath, additionalVmOptions); + var ctx = new EngineMojoContext(engineDir, project, getLog(), engineLogFile, vmOptions, startTimeoutInSeconds); + var engineControl = new EngineControl(ctx); + return engineControl.start(); + } + private Path engineDir() throws MojoExecutionException { + var engineDir = identifyAndGetEngineDirectory(); if (engineToTarget()) { - engineDir = copyEngineToTarget(engineDir); + return copyEngineToTarget(engineDir); } - - EngineVmOptions vmOptions = new EngineVmOptions(maxmem, additionalClasspath, additionalVmOptions); - EngineControl engineControl = new EngineControl(new EngineMojoContext( - engineDir, project, getLog(), engineLogFile, vmOptions, startTimeoutInSeconds)); - return engineControl.start(); + return engineDir; } - private File copyEngineToTarget(File cachedEngineDir) { - File targetEngine = getTargetDir(project); - if (targetEngine.exists()) { + private Path copyEngineToTarget(Path cachedEngineDir) { + var targetEngine = getTargetDir(project); + if (Files.exists(targetEngine)) { getLog().warn("Skipping copy of engine to " + targetEngine + " it already exists. Use \"mvn clean\" to ensure a clean engine each cycle."); return targetEngine; @@ -132,7 +134,7 @@ private File copyEngineToTarget(File cachedEngineDir) { getLog().info("Parameter is set to " + testEngine + ", copying engine from: " + cachedEngineDir + " to " + targetEngine); - copyEngine(cachedEngineDir.toPath(), targetEngine.toPath()); + copyEngine(cachedEngineDir, targetEngine); return targetEngine; } catch (IOException ex) { getLog().warn("Could not copy engine from: " + cachedEngineDir + " to " + targetEngine, ex); @@ -153,4 +155,4 @@ private void copyFile(Path source, Path dest) { throw new RuntimeException(ex); } } -} \ No newline at end of file +} diff --git a/src/main/java/ch/ivyteam/ivy/maven/test/StopTestEngineMojo.java b/src/main/java/ch/ivyteam/ivy/maven/test/StopTestEngineMojo.java index 79f8ee7c..4715ed63 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/test/StopTestEngineMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/test/StopTestEngineMojo.java @@ -16,7 +16,8 @@ package ch.ivyteam.ivy.maven.test; -import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -30,11 +31,12 @@ /** * Stops the Axon Ivy Engine after integration testing - * + * * @since 6.2.0 */ @Mojo(name = StopTestEngineMojo.GOAL) public class StopTestEngineMojo extends AbstractIntegrationTestMojo { + public static final String GOAL = "stop-test-engine"; @Parameter(property = "project", required = true, readonly = true) @@ -78,15 +80,17 @@ public void execute() throws MojoExecutionException, MojoFailureException { } public EngineControl createEngineController() throws MojoExecutionException { - File engineDir = getEngineDir(project); - if (engineDir == null || !engineDir.exists()) { - engineDir = identifyAndGetEngineDirectory(); - } - - EngineVmOptions vmOptions = new EngineVmOptions(maxmem, additionalClasspath, additionalVmOptions); - EngineControl engineControl = new EngineControl(new EngineMojoContext( - engineDir, project, getLog(), null, vmOptions, stopTimeoutInSeconds)); - return engineControl; + var engineDir = engineDir(); + var vmOptions = new EngineVmOptions(additionalClasspath, additionalVmOptions); + var ctx = new EngineMojoContext(engineDir, project, getLog(), null, vmOptions, stopTimeoutInSeconds); + return new EngineControl(ctx); } + private Path engineDir() throws MojoExecutionException { + var engineDir = getEngineDir(project); + if (engineDir == null || !Files.exists(engineDir)) { + return identifyAndGetEngineDirectory(); + } + return engineDir; + } } diff --git a/src/main/java/ch/ivyteam/ivy/maven/test/bpm/IvyTestRuntime.java b/src/main/java/ch/ivyteam/ivy/maven/test/bpm/IvyTestRuntime.java index c713b032..12745984 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/test/bpm/IvyTestRuntime.java +++ b/src/main/java/ch/ivyteam/ivy/maven/test/bpm/IvyTestRuntime.java @@ -1,10 +1,9 @@ package ch.ivyteam.ivy.maven.test.bpm; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.List; import java.util.Properties; import java.util.stream.Collectors; @@ -12,6 +11,7 @@ import org.apache.maven.project.MavenProject; public class IvyTestRuntime { + public static final String RUNTIME_PROPS_RESOURCE = "ivyTestRuntime.properties"; public static interface Key { @@ -21,8 +21,8 @@ public static interface Key { private final Properties props = new Properties(); - public void setProductDir(File engineDir) { - props.put(Key.PRODUCT_DIR, engineDir.getAbsolutePath()); + public void setProductDir(Path engineDir) { + props.put(Key.PRODUCT_DIR, engineDir.toAbsolutePath().toString()); } public void setProjectLocations(List locations) { @@ -34,20 +34,18 @@ public void setProjectLocations(List locations) { props.setProperty(Key.PROJECT_LOCATIONS, joinedUris); } - public File store(MavenProject project) throws IOException { - File target = new File(project.getBuild().getDirectory()); - File tstVmDir = new File(target, "ivyTestVm"); - tstVmDir.mkdir(); + public Path store(MavenProject project) throws IOException { + var tstVmDir = Path.of(project.getBuild().getDirectory()).resolve("ivyTestVm"); + Files.createDirectories(tstVmDir); store(tstVmDir); return tstVmDir; } - private File store(File dir) throws IOException { - File propsFile = new File(dir, RUNTIME_PROPS_RESOURCE); - try (OutputStream os = new FileOutputStream(propsFile)) { - props.store(os, "ivy test vm runtime properties"); + private Path store(Path dir) throws IOException { + var propsFile = dir.resolve(RUNTIME_PROPS_RESOURCE); + try (var out = Files.newOutputStream(propsFile)) { + props.store(out, "ivy test vm runtime properties"); } return propsFile; } - } diff --git a/src/main/java/ch/ivyteam/ivy/maven/util/ClasspathJar.java b/src/main/java/ch/ivyteam/ivy/maven/util/ClasspathJar.java index 7529437a..18decc0f 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/util/ClasspathJar.java +++ b/src/main/java/ch/ivyteam/ivy/maven/util/ClasspathJar.java @@ -17,13 +17,12 @@ package ch.ivyteam.ivy.maven.util; import java.io.EOFException; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -39,16 +38,17 @@ /** * Jar with only a Manifest.MF that defines the classpath. - * + * * @author Reguel Wermelinger * @since 6.0.2 */ public class ClasspathJar { + private static final String MANIFEST_MF = "META-INF/MANIFEST.MF"; - private final File jar; + private final Path jar; private String mainClass; - public ClasspathJar(File jar) { + public ClasspathJar(Path jar) { this.jar = jar; } @@ -57,14 +57,14 @@ public void setMainClass(String fqClassName) { } public void create(List classpathEntries) throws IOException { - jar.getParentFile().mkdir(); - try (ZipOutputStream zipStream = new ZipOutputStream(new FileOutputStream(jar))) { - String name = StringUtils.substringBeforeLast(jar.getName(), "."); - writeManifest(name, zipStream, classpathEntries); + Files.createDirectories(jar.getParent()); + try (var out = new ZipOutputStream(Files.newOutputStream(jar))) { + String name = StringUtils.substringBeforeLast(jar.getFileName().toString(), "."); + writeManifest(name, out, classpathEntries); } } - public void createFileEntries(Collection classpathEntries) throws IOException { + public void createFileEntries(Collection classpathEntries) throws IOException { create(getClassPathUris(classpathEntries)); } @@ -83,21 +83,21 @@ private void writeManifest(String name, ZipOutputStream jarStream, List manifest.write(jarStream); } - private static List getClassPathUris(Collection classpathEntries) { + private static List getClassPathUris(Collection classpathEntries) { return classpathEntries.stream() - .map(file -> file.toURI().toASCIIString()) + .map(file -> file.toUri().toASCIIString()) .collect(Collectors.toList()); } - public List getFiles() { + public List getFiles() { String urlClasspath = getClasspathUrlEntries(); if (StringUtils.isBlank(urlClasspath)) { return Collections.emptyList(); } - List files = new ArrayList<>(); + var files = new ArrayList(); for (String entry : urlClasspath.split(" ")) { - files.add(new File(uriToAbsoluteFilePath(entry))); + files.add(Path.of(uriToAbsoluteFilePath(entry))); } return files; } @@ -115,8 +115,8 @@ private static String uriToAbsoluteFilePath(String entry) { } public String getClasspathUrlEntries() { - try (ZipInputStream is = new ZipInputStream(new FileInputStream(jar))) { - Manifest manifest = new Manifest(getInputStream(is, MANIFEST_MF)); + try (var in = new ZipInputStream(Files.newInputStream(jar))) { + Manifest manifest = new Manifest(getInputStream(in, MANIFEST_MF)); return manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH); } catch (IOException ex) { return null; diff --git a/src/main/java/ch/ivyteam/ivy/maven/util/CompilerResult.java b/src/main/java/ch/ivyteam/ivy/maven/util/CompilerResult.java index 04a2ec88..39e6850e 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/util/CompilerResult.java +++ b/src/main/java/ch/ivyteam/ivy/maven/util/CompilerResult.java @@ -16,10 +16,8 @@ package ch.ivyteam.ivy.maven.util; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; +import java.nio.file.Files; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; @@ -38,17 +36,17 @@ public static void store(Map result, MavenProject project) throw for (Entry entry : result.entrySet()) { properties.setProperty(entry.getKey(), entry.getValue().toString()); } - File propertyFile = new SharedFile(project).getCompileResultProperties(); - try (FileOutputStream fos = new FileOutputStream(propertyFile)) { - properties.store(fos, "ivy project build results"); + var propertyFile = new SharedFile(project).getCompileResultProperties(); + try (var out = Files.newOutputStream(propertyFile)) { + properties.store(out, "ivy project build results"); } } public static CompilerResult load(MavenProject project) throws IOException { - File propertyFile = new SharedFile(project).getCompileResultProperties(); + var propertyFile = new SharedFile(project).getCompileResultProperties(); Properties compileResults = new Properties(); - try (FileInputStream fis = new FileInputStream(propertyFile)) { - compileResults.load(fis); + try (var in = Files.newInputStream(propertyFile)) { + compileResults.load(in); } return new CompilerResult(compileResults); } @@ -65,5 +63,4 @@ public String getTestOutputDirectory() { } return result.getProperty(Result.TEST_OUTPUT_DIR); } - -} \ No newline at end of file +} diff --git a/src/main/java/ch/ivyteam/ivy/maven/util/FileSetConverter.java b/src/main/java/ch/ivyteam/ivy/maven/util/FileSetConverter.java index 12714d95..9bfc7dad 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/util/FileSetConverter.java +++ b/src/main/java/ch/ivyteam/ivy/maven/util/FileSetConverter.java @@ -16,7 +16,7 @@ package ch.ivyteam.ivy.maven.util; -import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -25,9 +25,10 @@ import org.codehaus.plexus.archiver.util.DefaultFileSet; public class FileSetConverter { - private File pomFileDir; - public FileSetConverter(File pomFileDir) { + private final Path pomFileDir; + + public FileSetConverter(Path pomFileDir) { this.pomFileDir = pomFileDir; } @@ -46,7 +47,7 @@ public List toPlexusFileSets( private org.codehaus.plexus.archiver.FileSet toPlexusFileset(org.apache.maven.model.FileSet mavenFs) { DefaultFileSet plexusFs = new DefaultFileSet(); - plexusFs.setDirectory(readDirectory(mavenFs)); + plexusFs.setDirectory(readDirectory(mavenFs).toFile()); plexusFs.setIncludes(mavenFs.getIncludes().toArray(new String[0])); plexusFs.setExcludes(mavenFs.getExcludes().toArray(new String[0])); plexusFs.setUsingDefaultExcludes(false); @@ -54,11 +55,10 @@ private org.codehaus.plexus.archiver.FileSet toPlexusFileset(org.apache.maven.mo return plexusFs; } - private File readDirectory(org.apache.maven.model.FileSet mavenFs) { + private Path readDirectory(org.apache.maven.model.FileSet mavenFs) { if (StringUtils.isBlank(mavenFs.getDirectory())) { return pomFileDir; } - return new File(pomFileDir, mavenFs.getDirectory()); + return pomFileDir.resolve(mavenFs.getDirectory()); } - -} \ No newline at end of file +} diff --git a/src/main/java/ch/ivyteam/ivy/maven/util/MavenDependencies.java b/src/main/java/ch/ivyteam/ivy/maven/util/MavenDependencies.java index ac67d055..da53b170 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/util/MavenDependencies.java +++ b/src/main/java/ch/ivyteam/ivy/maven/util/MavenDependencies.java @@ -1,6 +1,7 @@ package ch.ivyteam.ivy.maven.util; import java.io.File; +import java.nio.file.Path; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -30,11 +31,12 @@ public MavenDependencies type(String newTypeFilter) { return this; } - public List localTransient() { + public List localTransient() { return stream(project.getArtifacts()) .filter(this::isLocalDep) .filter(this::include) .map(Artifact::getFile) + .map(File::toPath) .filter(Objects::nonNull) .collect(Collectors.toList()); } @@ -47,10 +49,11 @@ private boolean isLocalDep(Artifact artifact) { .isEmpty(); } - public List all() { + public List all() { return stream(project.getArtifacts()) .filter(this::include) .map(this::toFile) + .map(File::toPath) .collect(Collectors.toList()); } diff --git a/src/main/java/ch/ivyteam/ivy/maven/util/MavenRuntime.java b/src/main/java/ch/ivyteam/ivy/maven/util/MavenRuntime.java index 0b8833e3..e27f6940 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/util/MavenRuntime.java +++ b/src/main/java/ch/ivyteam/ivy/maven/util/MavenRuntime.java @@ -1,17 +1,18 @@ package ch.ivyteam.ivy.maven.util; -import java.io.File; +import java.nio.file.Path; import java.util.List; import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; public class MavenRuntime { - public static List getDependencies(MavenProject project, String type) { + + public static List getDependencies(MavenProject project, String type) { return getDependencies(project, null, type); } - public static List getDependencies(MavenProject project, MavenSession session, String type) { + public static List getDependencies(MavenProject project, MavenSession session, String type) { return new MavenDependencies(project, session).type(type).all(); } } diff --git a/src/main/java/ch/ivyteam/ivy/maven/util/SharedFile.java b/src/main/java/ch/ivyteam/ivy/maven/util/SharedFile.java index 90374b02..1c9c65d8 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/util/SharedFile.java +++ b/src/main/java/ch/ivyteam/ivy/maven/util/SharedFile.java @@ -16,36 +16,36 @@ package ch.ivyteam.ivy.maven.util; -import java.io.File; +import java.nio.file.Path; import org.apache.maven.project.MavenProject; /** * A file that is used by multiple Mojos/Goals during the build lifecycle. - * + * * @since 6.0.3 */ public class SharedFile { - private File targetDir; + + private final Path targetDir; public SharedFile(MavenProject project) { - targetDir = new File(project.getBuild().getDirectory()); + targetDir = Path.of(project.getBuild().getDirectory()); } - public File getEngineOSGiBootClasspathJar() { - return new File(targetDir, "ivy.engine.osgi.boot.classpath.jar"); + public Path getEngineOSGiBootClasspathJar() { + return targetDir.resolve("ivy.engine.osgi.boot.classpath.jar"); } - public File getEngineClasspathJar() { - return new File(targetDir, "ivy.engine.classpath.jar"); + public Path getEngineClasspathJar() { + return targetDir.resolve("ivy.engine.classpath.jar"); } - public File getIarDependencyClasspathJar() { - return new File(targetDir, "ivy.project.dependency.classpath.jar"); + public Path getIarDependencyClasspathJar() { + return targetDir.resolve("ivy.project.dependency.classpath.jar"); } - public File getCompileResultProperties() { - return new File(targetDir, "ivy.project.compile.result.properties"); + public Path getCompileResultProperties() { + return targetDir.resolve("ivy.project.compile.result.properties"); } - } diff --git a/src/test/java/ch/ivyteam/ivy/maven/BaseEngineProjectMojoTest.java b/src/test/java/ch/ivyteam/ivy/maven/BaseEngineProjectMojoTest.java index a05d7379..ed2250d9 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/BaseEngineProjectMojoTest.java +++ b/src/test/java/ch/ivyteam/ivy/maven/BaseEngineProjectMojoTest.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.net.URI; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import java.util.Calendar; import java.util.Collection; @@ -72,21 +73,20 @@ private static String getLocalRepoPath() { return defaultHomePath.toString(); } - protected final static Collection findFiles(File dir, String fileExtension) { - if (!dir.exists()) { + protected final static Collection findFiles(Path dir, String fileExtension) { + if (!Files.exists(dir)) { return Collections.emptyList(); } - return FileUtils.listFiles(dir, new String[] {fileExtension}, true); + return FileUtils.listFiles(dir.toFile(), new String[] {fileExtension}, true); } - private static final File evalEngineDir(AbstractEngineMojo mojo) { - return new File(mojo.engineCacheDirectory, - System.getProperty("ivy.engine.version", AbstractEngineMojo.DEFAULT_VERSION)); + private static final Path evalEngineDir(AbstractEngineMojo mojo) { + return mojo.engineCacheDirectory.resolve(System.getProperty("ivy.engine.version", AbstractEngineMojo.DEFAULT_VERSION)); } @Rule public ProjectMojoRule installUpToDateEngineRule = new ProjectMojoRule( - new File("src/test/resources/base"), InstallEngineMojo.GOAL) { + Path.of("src/test/resources/base"), InstallEngineMojo.GOAL) { private static final String TIMESTAMP_FILE_NAME = "downloadtimestamp"; @@ -98,7 +98,7 @@ protected void before() throws Throwable { if (alternateEngineListPageUrl != null) { getMojo().engineListPageUrl = URI.create(alternateEngineListPageUrl).toURL(); } - getMojo().engineCacheDirectory = new File(CACHE_DIR); + getMojo().engineCacheDirectory = Path.of(CACHE_DIR); getMojo().ivyVersion = ENGINE_VERSION_TO_TEST; getMojo().engineDirectory = evalEngineDir(getMojo()); getMojo().useLatestMinor = true; @@ -108,15 +108,15 @@ protected void before() throws Throwable { } private void deleteOutdatedEngine() throws IOException { - File engineDir = getMojo().getRawEngineDirectory(); - if (engineDir == null || !engineDir.exists()) { + var engineDir = getMojo().getRawEngineDirectory(); + if (engineDir == null || !Files.exists(engineDir)) { return; } - File timestampFile = new File(engineDir, TIMESTAMP_FILE_NAME); - if (isOlderThan24h(timestampFile)) { + var timestampFile = engineDir.resolve(TIMESTAMP_FILE_NAME); + if (isOlderThan24h(timestampFile.toFile())) { System.out.println("Deleting cached outdated engine."); - FileUtils.deleteDirectory(engineDir); + FileUtils.deleteDirectory(engineDir.toFile()); } } @@ -139,18 +139,18 @@ private boolean isOlderThan24h(File timestampFile) { } private void addTimestampToDownloadedEngine() throws IOException { - File engineDir = getMojo().getRawEngineDirectory(); - if (engineDir == null || !engineDir.exists()) { + var engineDir = getMojo().getRawEngineDirectory(); + if (engineDir == null || !Files.exists(engineDir)) { return; } - File timestampFile = new File(engineDir, TIMESTAMP_FILE_NAME); - timestampFile.createNewFile(); + var timestampFile = engineDir.resolve(TIMESTAMP_FILE_NAME); + timestampFile.toFile().createNewFile(); } }; public static class EngineMojoRule extends ProjectMojoRule { protected EngineMojoRule(String mojoName) { - super(new File("src/test/resources/base"), mojoName); + super(Path.of("src/test/resources/base"), mojoName); } @Override @@ -160,7 +160,7 @@ protected void before() throws Throwable { } protected void configureMojo(AbstractEngineMojo newMojo) { - newMojo.engineCacheDirectory = new File(CACHE_DIR); + newMojo.engineCacheDirectory = Path.of(CACHE_DIR); newMojo.engineDirectory = evalEngineDir(getMojo()); newMojo.ivyVersion = ENGINE_VERSION_TO_TEST; } @@ -179,7 +179,7 @@ protected void before() throws Throwable { } private void provideClasspathJar() throws IOException { - File cpJar = new SharedFile(project).getEngineOSGiBootClasspathJar(); + var cpJar = new SharedFile(project).getEngineOSGiBootClasspathJar(); new ClasspathJar(cpJar).createFileEntries(EngineClassLoaderFactory .getOsgiBootstrapClasspath(installUpToDateEngineRule.getMojo().getRawEngineDirectory())); } @@ -200,5 +200,4 @@ private void sleep(long duration, TimeUnit unit) { } } } - -} \ No newline at end of file +} diff --git a/src/test/java/ch/ivyteam/ivy/maven/ProjectMojoRule.java b/src/test/java/ch/ivyteam/ivy/maven/ProjectMojoRule.java index 2e41601b..4abb013d 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/ProjectMojoRule.java +++ b/src/test/java/ch/ivyteam/ivy/maven/ProjectMojoRule.java @@ -16,9 +16,9 @@ package ch.ivyteam.ivy.maven; -import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import org.apache.commons.io.FileUtils; import org.apache.maven.plugin.Mojo; @@ -29,19 +29,20 @@ * Simple rule that can provide a real set-up MOJO that works on a copy of the * given projectDirectory. This simplifies TEST dramatically whenever your MOJO * relies on real Maven Models like (Project, Artifact, ...) - * + * * @author Reguel Wermelinger * @since 03.10.2014 * @param */ public class ProjectMojoRule extends MojoRule { - protected File projectDir; + + protected Path projectDir; private T mojo; private String mojoName; - private File templateProjectDir; + private Path templateProjectDir; public MavenProject project; - public ProjectMojoRule(File srcDir, String mojoName) { + public ProjectMojoRule(Path srcDir, String mojoName) { this.templateProjectDir = srcDir; this.mojoName = mojoName; } @@ -49,16 +50,16 @@ public ProjectMojoRule(File srcDir, String mojoName) { @Override @SuppressWarnings("unchecked") protected void before() throws Throwable { - projectDir = Files.createTempDirectory("MyBaseProject").toFile(); - FileUtils.copyDirectory(templateProjectDir, projectDir); - project = readMavenProject(projectDir); + projectDir = Files.createTempDirectory("MyBaseProject"); + FileUtils.copyDirectory(templateProjectDir.toFile(), projectDir.toFile()); + project = readMavenProject(projectDir.toFile()); mojo = (T) lookupConfiguredMojo(project, mojoName); } @Override protected void after() { try { - FileUtils.deleteDirectory(projectDir); + FileUtils.deleteDirectory(projectDir.toFile()); } catch (IOException ex) { throw new RuntimeException(ex); } diff --git a/src/test/java/ch/ivyteam/ivy/maven/TestIarPackagingMojo.java b/src/test/java/ch/ivyteam/ivy/maven/TestIarPackagingMojo.java index 469e148f..d276c098 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/TestIarPackagingMojo.java +++ b/src/test/java/ch/ivyteam/ivy/maven/TestIarPackagingMojo.java @@ -21,10 +21,9 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.StandardOpenOption; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -48,7 +47,8 @@ public class TestIarPackagingMojo { @Rule public ProjectMojoRule rule = new ProjectMojoRule( - new File("src/test/resources/base"), IarPackagingMojo.GOAL) { + Path.of("src/test/resources/base"), IarPackagingMojo.GOAL) { + @Override protected void before() throws Throwable { super.before(); @@ -56,28 +56,28 @@ protected void before() throws Throwable { } private void createEmptySrcDirs() throws IOException { - List emptySrcDirNames = Arrays.asList("src_dataClasses", "src_hd", "src_rd", "src_ws", - "src_wsproc"); - for (String emptySrcDirName : emptySrcDirNames) { - File srcDir = new File(projectDir, emptySrcDirName); - FileUtils.deleteDirectory(srcDir); - srcDir.mkdir(); + var emptySrcDirNames = List.of("src_dataClasses", "src_hd", "src_rd", "src_ws", "src_wsproc"); + for (var emptySrcDirName : emptySrcDirNames) { + var srcDir = projectDir.resolve(emptySrcDirName); + FileUtils.deleteDirectory(srcDir.toFile()); + Files.createDirectories(srcDir); } } }; /** * Happy path creation tests - * @throws Exception */ @Test public void archiveCreationDefault() throws Exception { IarPackagingMojo mojo = rule.getMojo(); - File svn = new File(mojo.project.getBasedir(), ".svn/svn.txt"); - FileUtils.write(svn, "svn", StandardCharsets.UTF_8); + var dir = mojo.project.getBasedir().toPath().resolve(".svn"); + Files.createDirectories(dir); + var svn = dir.resolve("svn.txt"); + Files.writeString(svn, "svn"); mojo.execute(); - Collection iarFiles = FileUtils.listFiles(new File(mojo.project.getBasedir(), "target"), - new String[] {"iar"}, false); + var targetDir = mojo.project.getBasedir().toPath().resolve("target").toFile(); + Collection iarFiles = FileUtils.listFiles(targetDir, new String[] {"iar"}, false); assertThat(iarFiles).hasSize(1); File iarFile = iarFiles.iterator().next(); @@ -112,7 +112,7 @@ public void archiveCreationDefault() throws Exception { public void canDefineCustomExclusions() throws Exception { IarPackagingMojo mojo = rule.getMojo(); String filterCandidate = "private/notPublic.txt"; - assertThat(new File(mojo.project.getBasedir(), filterCandidate)).exists(); + assertThat(mojo.project.getBasedir().toPath().resolve(filterCandidate)).exists(); mojo.iarExcludes = new String[] {"private", "private/**/*"}; mojo.execute(); @@ -126,13 +126,13 @@ public void canDefineCustomExclusions() throws Exception { @Test public void canDefineCustomInclusions() throws Exception { IarPackagingMojo mojo = rule.getMojo(); - File outputDir = new File(mojo.project.getBasedir(), "target"); - File customPomXml = new File(outputDir, "myCustomPom.xml"); - FileUtils.write(customPomXml, "customPomContent", StandardCharsets.UTF_8); + var outputDir = mojo.project.getBasedir().toPath().resolve("target"); + var customPomXml = outputDir.resolve("myCustomPom.xml"); + Files.writeString(customPomXml, "customPomContent"); - String relativeCustomIncludePath = "target/" + customPomXml.getName(); + String relativeCustomIncludePath = "target/" + customPomXml.getFileName().toString(); FileSet fs = new FileSet(); - fs.setIncludes(Arrays.asList(relativeCustomIncludePath)); + fs.setIncludes(List.of(relativeCustomIncludePath)); mojo.iarFileSets = new FileSet[] {fs}; mojo.execute(); @@ -145,13 +145,13 @@ public void canDefineCustomInclusions() throws Exception { @Test public void canOverwriteDefaultInclusions() throws Exception { IarPackagingMojo mojo = rule.getMojo(); - File outputDir = new File(mojo.project.getBasedir(), "target"); - File flatPomXML = new File(outputDir, "pom.xml"); - FileUtils.write(flatPomXML, "flattened", StandardCharsets.UTF_8); + var outputDir = mojo.project.getBasedir().toPath().resolve("target"); + var flatPomXML = outputDir.resolve("pom.xml"); + Files.writeString(flatPomXML, "flattened"); FileSet fs = new FileSet(); fs.setDirectory("target"); - fs.setIncludes(Arrays.asList(flatPomXML.getName())); + fs.setIncludes(List.of(flatPomXML.getFileName().toString())); mojo.iarFileSets = new FileSet[] {fs}; mojo.execute(); @@ -187,12 +187,12 @@ public void canExcludeEmptyDirectories() throws Exception { @Test public void doNotPackTargetFolderIfThereAreNoTargetClasses() throws Exception { IarPackagingMojo mojo = rule.getMojo(); - File targetClasses = new File(mojo.project.getBasedir(), "target/classes"); - FileUtils.deleteDirectory(targetClasses); + var targetClasses = mojo.project.getBasedir().toPath().resolve("target/classes"); + FileUtils.deleteDirectory(targetClasses.toFile()); mojo.execute(); - Collection iarFiles = FileUtils.listFiles(new File(mojo.project.getBasedir(), "target"), - new String[] {"iar"}, false); + var dir = mojo.project.getBasedir().toPath().resolve("target"); + Collection iarFiles = FileUtils.listFiles(dir.toFile(), new String[] {"iar"}, false); assertThat(iarFiles).hasSize(1); File iarFile = iarFiles.iterator().next(); @@ -214,8 +214,8 @@ public void includeTarget_srcHdGenerated() throws Exception { mojo.execute(); - Collection iarFiles = FileUtils.listFiles(new File(mojo.project.getBasedir(), "target"), - new String[] {"iar"}, false); + var dir = mojo.project.getBasedir().toPath().resolve("target"); + Collection iarFiles = FileUtils.listFiles(dir.toFile(), new String[] {"iar"}, false); assertThat(iarFiles).hasSize(1); File iarFile = iarFiles.iterator().next(); diff --git a/src/test/java/ch/ivyteam/ivy/maven/TestInstallEngineMojo.java b/src/test/java/ch/ivyteam/ivy/maven/TestInstallEngineMojo.java index 8bc523fc..6cb45881 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/TestInstallEngineMojo.java +++ b/src/test/java/ch/ivyteam/ivy/maven/TestInstallEngineMojo.java @@ -20,8 +20,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; @@ -29,6 +27,7 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; import org.apache.commons.io.IOUtils; import org.apache.maven.plugin.MojoExecutionException; @@ -53,7 +52,7 @@ public class TestInstallEngineMojo { @Rule public ProjectMojoRule rule = new ProjectMojoRule( - new File("src/test/resources/base"), InstallEngineMojo.GOAL) { + Path.of("src/test/resources/base"), InstallEngineMojo.GOAL) { @Override protected void before() throws Throwable { super.before(); @@ -90,10 +89,10 @@ public void testEngineDownload_defaultBehaviour() throws Exception { // test setup can not expand expression ${settings.localRepository}: so we // setup an explicit temp dir! - mojo.engineCacheDirectory = Files.createTempDirectory("tmpRepo").toFile(); + mojo.engineCacheDirectory = Files.createTempDirectory("tmpRepo"); mojo.engineListPageUrl = URI.create(mockBaseUrl + "/listPageUrl.html").toURL(); - File defaultEngineDir = new File(mojo.engineCacheDirectory, DEFAULT_VERSION); + var defaultEngineDir = mojo.engineCacheDirectory.resolve(DEFAULT_VERSION); assertThat(defaultEngineDir).doesNotExist(); assertThat(mojo.engineDownloadUrl) .as("Default config should favour to download an engine from the 'list page url'.") @@ -104,41 +103,41 @@ public void testEngineDownload_defaultBehaviour() throws Exception { assertThat(defaultEngineDir) .as("Engine must be automatically downloaded") - .exists().isDirectory(); - assertThat(defaultEngineDir) + .exists() + .isDirectory() .as("Engine directory should automatically be set to subdir of the local repository cache.") .isEqualTo(mojo.getRawEngineDirectory()); } - private static MockHttpServerResponse createFakeZipResponse(File zip) throws Exception { - var engineZipResponse = new MockHttpServerResponse(); - engineZipResponse.setMockResponseContentType("application/zip"); - FileInputStream fis = new FileInputStream(zip); - byte[] zipBytes = IOUtils.toByteArray(fis); - engineZipResponse.setMockResponseContent(zipBytes); - return engineZipResponse; + private static MockHttpServerResponse createFakeZipResponse(Path zip) throws Exception { + var response = new MockHttpServerResponse(); + response.setMockResponseContentType("application/zip"); + try (var in = Files.newInputStream(zip)) { + response.setMockResponseContent(in.readAllBytes()); + } + return response; } - private static File createFakeEngineZip(String ivyVersion) throws IOException, ZipException { - File zipDir = createFakeEngineDir(ivyVersion); - File zipFile = new File(zipDir, "fake.zip"); - try(ZipFile zip = new ZipFile(zipFile)) { - zip.createSplitZipFileFromFolder(new File(zipDir, OsgiDir.INSTALL_AREA), new ZipParameters(), false, 0); + private static Path createFakeEngineZip(String ivyVersion) throws IOException, ZipException { + var zipDir = createFakeEngineDir(ivyVersion); + var zipFile = zipDir.resolve("fake.zip"); + try (var zip = new ZipFile(zipFile.toFile())) { + zip.createSplitZipFileFromFolder(zipDir.resolve(OsgiDir.INSTALL_AREA).toFile(), new ZipParameters(), false, 0); } return zipFile; } - private static File createFakeEngineDir(String ivyVersion) throws IOException { - File fakeDir = createTempDir("fake"); - File fakeLibToDeclareVersion = new File(fakeDir, getFakeLibraryPath(ivyVersion)); - fakeLibToDeclareVersion.getParentFile().mkdirs(); - fakeLibToDeclareVersion.createNewFile(); + private static Path createFakeEngineDir(String ivyVersion) throws IOException { + var fakeDir = createTempDir("fake"); + var fakeLibToDeclareVersion = fakeDir.resolve(getFakeLibraryPath(ivyVersion)); + Files.createDirectories(fakeLibToDeclareVersion.getParent()); + Files.createFile(fakeLibToDeclareVersion); return fakeDir; } - private static File createTempDir(String namePrefix) throws IOException { - File tmpDir = Files.createTempDirectory(namePrefix).toFile(); - tmpDir.deleteOnExit(); + private static Path createTempDir(String namePrefix) throws IOException { + var tmpDir = Files.createTempDirectory(namePrefix); + tmpDir.toFile().deleteOnExit(); return tmpDir; } @@ -147,15 +146,15 @@ public void testEngineDownload_alreadyInstalledVersionWithinRange() throws Excep final String version = AbstractEngineMojo.MINIMAL_COMPATIBLE_VERSION; mojo.engineDirectory = createFakeEngineDir(version); assertThat(mojo.engineDirectory).isDirectory(); - assertThat(new File(mojo.engineDirectory, getFakeLibraryPath(version))).exists(); + assertThat(mojo.engineDirectory.resolve(getFakeLibraryPath(version))).exists(); mojo.ivyVersion = "[7.0.0,800.0.0)"; mojo.autoInstallEngine = true; mojo.engineDownloadUrl = URI.create("http://localhost/fakeUri").toURL(); mojo.execute(); - assertThat(mojo.engineDirectory.listFiles()).isNotEmpty(); - assertThat(new File(mojo.engineDirectory, getFakeLibraryPath(version))).exists(); + assertThat(mojo.engineDirectory).isNotEmptyDirectory(); + assertThat(mojo.engineDirectory.resolve(getFakeLibraryPath(version))).exists(); } @Test @@ -165,30 +164,31 @@ public void testEngineDownload_alreadyInstalledVersionTooOld() throws Exception final String outdatedVersion = "6.5.1"; mojo.engineDirectory = createFakeEngineDir(outdatedVersion); assertThat(mojo.engineDirectory).isDirectory(); - assertThat(new File(mojo.engineDirectory, getFakeLibraryPath(outdatedVersion))).exists(); + assertThat(mojo.engineDirectory.resolve(getFakeLibraryPath(outdatedVersion))).exists(); mojo.ivyVersion = "[11.3.0,11.4.0]"; mojo.autoInstallEngine = true; mojo.engineDownloadUrl = mockEngineZip(); mojo.execute(); - assertThat(mojo.engineDirectory.listFiles()).isNotEmpty(); - assertThat(new File(mojo.engineDirectory, getFakeLibraryPath(outdatedVersion))).doesNotExist(); - assertThat(new File(mojo.engineDirectory, getFakeLibraryPath(DEFAULT_VERSION))).exists(); + assertThat(mojo.engineDirectory).isNotEmptyDirectory(); + assertThat(mojo.engineDirectory.resolve(getFakeLibraryPath(outdatedVersion))).doesNotExist(); + assertThat(mojo.engineDirectory.resolve(getFakeLibraryPath(DEFAULT_VERSION))).exists(); } @Test public void testEngineDownload_ifNotExisting() throws Exception { mojo.engineDirectory = createTempDir("tmpEngine"); - assertThat(mojo.engineDirectory).isDirectory(); - assertThat(mojo.engineDirectory.listFiles()).isEmpty(); + assertThat(mojo.engineDirectory) + .isDirectory() + .isEmptyDirectory(); mojo.autoInstallEngine = true; mockServer.setMockHttpServerResponses(createFakeZipResponse(createFakeEngineZip(mojo.ivyVersion))); mojo.engineDownloadUrl = mockEngineZip(); mojo.execute(); - assertThat(mojo.engineDirectory.listFiles()).isNotEmpty(); + assertThat(mojo.engineDirectory).isNotEmptyDirectory(); } @Test @@ -198,21 +198,24 @@ public void testEngineDownload_skipNonOsgiEngineInCache() throws Exception { mojo.restrictVersionToMinimalCompatible = false; mojo.autoInstallEngine = true; - // OSGi - new File(mojo.engineCacheDirectory, "7.0.0" + File.separator + getFakeLibraryPath("7.0.0")).mkdirs(); - // non-OSGi - new File(mojo.engineCacheDirectory, "7.1.0").mkdirs(); + var osgiDir = mojo.engineCacheDirectory.resolve("7.0.0").resolve(getFakeLibraryPath("7.0.0")); + Files.createDirectories(osgiDir); + + var nonOsgiDir = mojo.engineCacheDirectory.resolve("7.1.0"); + Files.createDirectories(nonOsgiDir); mojo.execute(); - assertThat(mojo.engineDirectory.getName()).isEqualTo("7.0.0"); + assertThat(mojo.engineDirectory.getFileName().toString()).isEqualTo("7.0.0"); } @Test public void testEngineDownload_existingTmpFileNotOverwritten() throws Exception { mojo.engineDirectory = createTempDir("tmpEngine"); - File alreadyExistingFile = new File(mojo.getDownloadDirectory(), "fakeEngine.zip"); - alreadyExistingFile.createNewFile(); + var alreadyExistingFile = mojo.getDownloadDirectory().resolve("fakeEngine.zip"); + if (!Files.exists(alreadyExistingFile)) { + Files.createFile(alreadyExistingFile); + } mojo.autoInstallEngine = true; mockServer.setMockHttpServerResponses(createFakeZipResponse(createFakeEngineZip(DEFAULT_VERSION))); @@ -227,8 +230,10 @@ public void testEngineDownload_existingTmpFileNotOverwritten() throws Exception public void testEngineDownload_overProxy() throws Exception { mojo.engineDirectory = createTempDir("tmpEngine"); - File alreadyExistingFile = new File(mojo.getDownloadDirectory(), "fakeEngine.zip"); - alreadyExistingFile.createNewFile(); + var alreadyExistingFile = mojo.getDownloadDirectory().resolve("fakeEngine.zip"); + if (!Files.exists(alreadyExistingFile)) { + Files.createFile(alreadyExistingFile); + } mojo.autoInstallEngine = true; mockServer.setMockHttpServerResponses(createFakeZipResponse(createFakeEngineZip(DEFAULT_VERSION))); @@ -243,10 +248,10 @@ public void testEngineDownload_overProxy() throws Exception { } downloader.proxies = this::localTestProxy; - File downloaded = downloader.downloadEngine(); + var downloaded = downloader.downloadEngine(); assertThat(downloaded) - .as("served file via proxy") - .exists(); + .as("served file via proxy") + .exists(); } private ProxyInfo localTestProxy(@SuppressWarnings("unused") String protocol) { diff --git a/src/test/java/ch/ivyteam/ivy/maven/TestLoggerIntegration.java b/src/test/java/ch/ivyteam/ivy/maven/TestLoggerIntegration.java index 8f17f003..dfe170a5 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/TestLoggerIntegration.java +++ b/src/test/java/ch/ivyteam/ivy/maven/TestLoggerIntegration.java @@ -3,9 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.PrintStream; -import java.util.List; import org.junit.After; import org.junit.Before; @@ -14,7 +12,6 @@ import ch.ivyteam.ivy.maven.compile.CompileMojoRule; import ch.ivyteam.ivy.maven.compile.CompileProjectMojo; -import ch.ivyteam.ivy.maven.engine.EngineClassLoaderFactory; public class TestLoggerIntegration extends BaseEngineProjectMojoTest { private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); @@ -38,13 +35,12 @@ public void restoreStreams() { */ @Test public void forwardEngineLogsToMavenConsole() { - EngineClassLoaderFactory engineClassLoader = compile.getMojo().getEngineClassloaderFactory(); - List slf4jJars = engineClassLoader.getSlf4jJars(); + var engineClassLoader = compile.getMojo().getEngineClassloaderFactory(); + var slf4jJars = engineClassLoader.getSlf4jJars(); assertThat(slf4jJars).hasSize(3); - assertThat(slf4jJars.get(0).getName()).startsWith("slf4j-api-"); + assertThat(slf4jJars.get(0).getFileName().toString()).startsWith("slf4j-api-"); assertThat(outContent.toString()) .as("no warnings must be printed during slf4j library re-solving from local repo") .isEmpty(); } - } diff --git a/src/test/java/ch/ivyteam/ivy/maven/TestMavenDependencyCleanupMojo.java b/src/test/java/ch/ivyteam/ivy/maven/TestMavenDependencyCleanupMojo.java index f3e00269..2a8f119f 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/TestMavenDependencyCleanupMojo.java +++ b/src/test/java/ch/ivyteam/ivy/maven/TestMavenDependencyCleanupMojo.java @@ -18,8 +18,8 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; import java.nio.file.Files; +import java.nio.file.Path; import org.junit.Rule; import org.junit.Test; @@ -27,7 +27,7 @@ public class TestMavenDependencyCleanupMojo extends BaseEngineProjectMojoTest { @Rule public ProjectMojoRule compile = new ProjectMojoRule( - new File("src/test/resources/base"), MavenDependencyCleanupMojo.GOAL); + Path.of("src/test/resources/base"), MavenDependencyCleanupMojo.GOAL); @Test public void noMavenDepsDir() throws Exception { @@ -43,8 +43,7 @@ public void cleanupMavenDepsDir() throws Exception { var mojo = compile.getMojo(); var mvnLibDir = Files .createDirectories(mojo.project.getBasedir().toPath().resolve("lib").resolve("mvn-deps")); - var mvnDep = Files.copy(new File("src/test/resources/jjwt-0.9.1.jar").toPath(), - mvnLibDir.resolve("jjwt-0.9.1.jar")); + var mvnDep = Files.copy(Path.of("src/test/resources/jjwt-0.9.1.jar"), mvnLibDir.resolve("jjwt-0.9.1.jar")); assertThat(mvnLibDir).exists(); assertThat(mvnDep).exists(); mojo.execute(); @@ -55,13 +54,11 @@ public void cleanupMavenDepsDir() throws Exception { public void dontCleanManualLibs() throws Exception { var mojo = compile.getMojo(); var libDir = Files.createDirectories(mojo.project.getBasedir().toPath().resolve("lib")); - var dep = Files.copy(new File("src/test/resources/jjwt-0.9.1.jar").toPath(), - libDir.resolve("jjwt-0.9.1.jar")); + var dep = Files.copy(Path.of("src/test/resources/jjwt-0.9.1.jar"), libDir.resolve("jjwt-0.9.1.jar")); assertThat(libDir).exists(); assertThat(dep).exists(); mojo.execute(); assertThat(libDir).exists(); assertThat(dep).exists(); } - } diff --git a/src/test/java/ch/ivyteam/ivy/maven/TestMavenDependencyMojo.java b/src/test/java/ch/ivyteam/ivy/maven/TestMavenDependencyMojo.java index b1b8a975..b9f000ca 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/TestMavenDependencyMojo.java +++ b/src/test/java/ch/ivyteam/ivy/maven/TestMavenDependencyMojo.java @@ -18,7 +18,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -65,7 +64,7 @@ public void exportMavenDepsToLibDir() throws Exception { assertThat(mvnLibDir).doesNotExist(); Artifact artifact = new ArtifactStubFactory().createArtifact("io.jsonwebtoken", "jjwt", "0.9.1"); artifact.setDependencyTrail(List.of(mojo.project.getArtifact().toString())); - artifact.setFile(new File("src/test/resources/jjwt-0.9.1.jar")); + artifact.setFile(Path.of("src/test/resources/jjwt-0.9.1.jar").toFile()); mojo.project.setArtifacts(Set.of(artifact)); mojo.execute(); assertThat(mvnLibDir).exists(); @@ -79,7 +78,7 @@ public void onlyLocalDeps() throws Exception { var mvnLibDir = mojo.project.getBasedir().toPath().resolve("lib").resolve("mvn-deps"); assertThat(mvnLibDir).doesNotExist(); Artifact artifact = new ArtifactStubFactory().createArtifact("io.jsonwebtoken", "jjwt", "0.9.1"); - artifact.setFile(new File("src/test/resources/jjwt-0.9.1.jar")); + artifact.setFile(Path.of("src/test/resources/jjwt-0.9.1.jar").toFile()); artifact.setDependencyTrail( List.of(mojo.project.getArtifact().toString(), "other.group:other.artifact:iar:1.0.0")); mojo.project.setArtifacts(Set.of(artifact)); diff --git a/src/test/java/ch/ivyteam/ivy/maven/TestShareEngineClasspathMojo.java b/src/test/java/ch/ivyteam/ivy/maven/TestShareEngineClasspathMojo.java index 37a28235..0b04aea3 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/TestShareEngineClasspathMojo.java +++ b/src/test/java/ch/ivyteam/ivy/maven/TestShareEngineClasspathMojo.java @@ -18,9 +18,9 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import org.apache.commons.io.FileUtils; import org.apache.maven.plugin.MojoExecutionException; @@ -50,8 +50,8 @@ private String getEngineClasspathProperty() { } @Rule - public ProjectMojoRule rule = new ProjectMojoRule( - new File("src/test/resources/base"), ShareEngineCoreClasspathMojo.GOAL) { + public ProjectMojoRule rule = new ProjectMojoRule(Path.of("src/test/resources/base"), ShareEngineCoreClasspathMojo.GOAL) { + @Override protected void before() throws Throwable { super.before(); @@ -60,15 +60,15 @@ protected void before() throws Throwable { } protected void configureMojo(AbstractEngineMojo newMojo) throws IOException { - File engineDir = Files.createTempDirectory("tmpEngineDir").toFile(); + var engineDir = Files.createTempDirectory("tmpEngineDir"); newMojo.engineDirectory = engineDir; } private void writeEngineLibDir() { try { - File engineDirectory = rule.getMojo().identifyAndGetEngineDirectory(); - FileUtils.touch( - new File(engineDirectory, OsgiDir.INSTALL_AREA + "/" + OsgiDir.LIB_BOOT + "/dummy-boot.jar")); + var engineDirectory = rule.getMojo().identifyAndGetEngineDirectory(); + var dummy = engineDirectory.resolve(OsgiDir.INSTALL_AREA).resolve(OsgiDir.LIB_BOOT).resolve("dummy-boot.jar"); + FileUtils.touch(dummy.toFile()); } catch (IOException | MojoExecutionException ex) { throw new RuntimeException("Cannot create server jars", ex); } diff --git a/src/test/java/ch/ivyteam/ivy/maven/compile/TestCompileProjectMojo.java b/src/test/java/ch/ivyteam/ivy/maven/compile/TestCompileProjectMojo.java index 8d416fbb..ab4494ef 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/compile/TestCompileProjectMojo.java +++ b/src/test/java/ch/ivyteam/ivy/maven/compile/TestCompileProjectMojo.java @@ -18,8 +18,8 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; import java.nio.file.Files; +import java.nio.file.Path; import org.apache.commons.io.FileUtils; import org.junit.Rule; @@ -47,13 +47,13 @@ protected void before() throws Throwable { public void buildWithExistingProject() throws Exception { CompileProjectMojo mojo = compile.getMojo(); - File dataClassDir = new File(mojo.project.getBasedir(), "src_dataClasses"); - File wsProcDir = new File(mojo.project.getBasedir(), "src_wsproc"); - File classDir = new File(mojo.project.getBasedir(), "classes"); - FileUtils.cleanDirectory(wsProcDir); - FileUtils.cleanDirectory(dataClassDir); + var dataClassDir = mojo.project.getBasedir().toPath().resolve("src_dataClasses"); + var wsProcDir = mojo.project.getBasedir().toPath().resolve("src_wsproc"); + var classDir = mojo.project.getBasedir().toPath().resolve("classes"); + FileUtils.cleanDirectory(wsProcDir.toFile()); + FileUtils.cleanDirectory(dataClassDir.toFile()); - mojo.buildApplicationDirectory = Files.createTempDirectory("MyBuildApplication").toFile(); + mojo.buildApplicationDirectory = Files.createTempDirectory("MyBuildApplication"); mojo.execute(); assertThat(findFiles(dataClassDir, "java")).hasSize(2); @@ -79,15 +79,13 @@ public void compilerSettingsFile_notFoundWarnings() throws Exception { mojo.setLog(log); mojo.compilerWarnings = false; - mojo.compilerSettings = new File("path/to/oblivion"); + mojo.compilerSettings = Path.of("path/to/oblivion"); mojo.execute(); assertThat(log.getWarnings().toString()).doesNotContain("Could not locate compiler settings file"); mojo.compilerWarnings = true; - mojo.execute(); assertThat(log.getWarnings().toString()).contains("Could not locate compiler settings file"); } - } diff --git a/src/test/java/ch/ivyteam/ivy/maven/deploy/TestDeployToEngineMojo.java b/src/test/java/ch/ivyteam/ivy/maven/deploy/TestDeployToEngineMojo.java index 721700df..6130b838 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/deploy/TestDeployToEngineMojo.java +++ b/src/test/java/ch/ivyteam/ivy/maven/deploy/TestDeployToEngineMojo.java @@ -18,10 +18,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; -import java.io.File; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; @@ -34,13 +33,13 @@ import ch.ivyteam.ivy.maven.engine.deploy.dir.DeploymentFiles; public class TestDeployToEngineMojo { + @Test public void deployPackedIar() throws Throwable { DeployToEngineMojo mojo = rule.getMojo(); - File deployedIar = getTarget(mojo.deployFile, mojo); - File deploymentOptionsFile = new File(deployedIar.getParentFile(), - deployedIar.getName() + "options.yaml"); + var deployedIar = getTarget(mojo.deployFile, mojo); + var deploymentOptionsFile = deployedIar.resolveSibling(deployedIar.getFileName() + ".options.yaml"); assertThat(deployedIar).doesNotExist(); assertThat(deploymentOptionsFile).doesNotExist(); @@ -49,7 +48,7 @@ public void deployPackedIar() throws Throwable { Callable engineOperation = () -> { assertThat(deploymentOptionsFile).doesNotExist(); assertThat(deployedIar).exists(); - deployedIar.delete(); + Files.delete(deployedIar); return null; }; mockEngineDeployThread.execute(engineOperation); @@ -66,10 +65,9 @@ public void deployWithExistingOptionsFile() throws Throwable { rule.project.getProperties().setProperty("doDeploy.test.user", "true"); DeployToEngineMojo mojo = rule.getMojo(); - mojo.deployOptionsFile = new File("src/test/resources/options.yaml"); - File deployedIar = getTarget(mojo.deployFile, mojo); - File deploymentOptionsFile = new File(deployedIar.getParentFile(), - deployedIar.getName() + ".options.yaml"); + mojo.deployOptionsFile = Path.of("src/test/resources/options.yaml"); + var deployedIar = getTarget(mojo.deployFile, mojo); + var deploymentOptionsFile = deployedIar.resolveSibling(deployedIar.getFileName() + ".options.yaml"); assertThat(deployedIar).doesNotExist(); assertThat(deploymentOptionsFile).doesNotExist(); @@ -78,9 +76,9 @@ public void deployWithExistingOptionsFile() throws Throwable { Callable engineOperation = () -> { assertThat(deploymentOptionsFile).exists(); assertThat(deploymentOptionsFile).hasContent("deployTestUsers: true\ntarget: AUTO"); - deploymentOptionsFile.delete(); + Files.delete(deploymentOptionsFile); assertThat(deployedIar).exists(); - Files.delete(deployedIar.toPath()); + Files.delete(deployedIar); return null; }; mockEngineDeployThread.execute(engineOperation); @@ -100,9 +98,8 @@ public void deployWithOptions() throws Throwable { mojo.deployTargetState = "INACTIVE"; mojo.deployTargetFileFormat = "EXPANDED"; - File deployedIar = getTarget(mojo.deployFile, mojo); - File deploymentOptionsFile = new File(deployedIar.getParentFile(), - deployedIar.getName() + ".options.yaml"); + var deployedIar = getTarget(mojo.deployFile, mojo); + var deploymentOptionsFile = deployedIar.resolveSibling(deployedIar.getFileName() + ".options.yaml"); assertThat(deployedIar).doesNotExist(); assertThat(deploymentOptionsFile).doesNotExist(); @@ -111,14 +108,15 @@ public void deployWithOptions() throws Throwable { Callable engineOperation = () -> { assertThat(deploymentOptionsFile).exists(); assertThat(deploymentOptionsFile).hasContent( - "deployTestUsers: \"TRUE\"\n" + - "target:\n" + - " version: RELEASED\n" + - " state: INACTIVE\n" + - " fileFormat: EXPANDED"); - deploymentOptionsFile.delete(); + """ + deployTestUsers: "TRUE" + target: + version: RELEASED + state: INACTIVE + fileFormat: EXPANDED"""); + Files.delete(deploymentOptionsFile); assertThat(deployedIar).exists(); - Files.delete(deployedIar.toPath()); + Files.delete(deployedIar); return null; }; mockEngineDeployThread.execute(engineOperation); @@ -134,13 +132,13 @@ public void deployWithOptions() throws Throwable { public void failOnEngineDeployError() throws Throwable { DeployToEngineMojo mojo = rule.getMojo(); DeploymentFiles markers = new DeploymentFiles(getTarget(mojo.deployFile, mojo)); - File deployedIar = getTarget(mojo.deployFile, mojo); + var deployedIar = getTarget(mojo.deployFile, mojo); DelayedOperation mockEngineDeployThread = new DelayedOperation(500, TimeUnit.MILLISECONDS); Callable engineOperation = () -> { - FileUtils.write(markers.errorLog(), "validation errors", StandardCharsets.UTF_8); + Files.writeString(markers.errorLog(), "validation errors"); assertThat(deployedIar).exists(); - deployedIar.delete(); + Files.delete(deployedIar); return null; }; @@ -155,16 +153,16 @@ public void failOnEngineDeployError() throws Throwable { } } - private static File getTarget(File iar, DeployToEngineMojo mojo) { - File deploy = new File(mojo.deployEngineDirectory, mojo.deployDirectory); - File app = new File(deploy, mojo.deployToEngineApplication); - File deployedIar = new File(app, iar.getName()); - return deployedIar; + private static Path getTarget(Path iar, DeployToEngineMojo mojo) { + return mojo.deployEngineDirectory + .resolve(mojo.deployDirectory) + .resolve(mojo.deployToEngineApplication) + .resolve(iar.getFileName().toString()); } @Rule public ProjectMojoRule rule = new ProjectMojoRule( - new File("src/test/resources/base"), DeployToEngineMojo.GOAL) { + Path.of("src/test/resources/base"), DeployToEngineMojo.GOAL) { @Override protected void before() throws Throwable { super.before(); @@ -173,25 +171,25 @@ protected void before() throws Throwable { getMojo().deployToEngineApplication = "TestApp"; try { - getMojo().deployFile.getParentFile().mkdir(); - getMojo().deployFile.createNewFile(); + getMojo().deployFile.toFile().getParentFile().mkdir(); + getMojo().deployFile.toFile().createNewFile(); } catch (IOException ex) { - System.err.println("Failed to create IAR @ " + getMojo().deployFile.getAbsolutePath()); + System.err.println("Failed to create IAR @ " + getMojo().deployFile.toAbsolutePath()); throw ex; } } - private File createEngineDir() { - File engine = new File("target/myTestIvyEngine"); - File deploy = new File(engine, "deploy"); - deploy.mkdirs(); - return engine.getAbsoluteFile(); + private Path createEngineDir() throws IOException { + var engine = Path.of("target/myTestIvyEngine"); + var deploy = engine.resolve("deploy"); + Files.createDirectories(deploy); + return engine.toAbsolutePath(); } @Override protected void after() { super.after(); - FileUtils.deleteQuietly(getMojo().deployEngineDirectory); + FileUtils.deleteQuietly(getMojo().deployEngineDirectory.toFile()); } }; diff --git a/src/test/java/ch/ivyteam/ivy/maven/deploy/TestDeployToRunningEngine.java b/src/test/java/ch/ivyteam/ivy/maven/deploy/TestDeployToRunningEngine.java index af7125ef..7e0968cf 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/deploy/TestDeployToRunningEngine.java +++ b/src/test/java/ch/ivyteam/ivy/maven/deploy/TestDeployToRunningEngine.java @@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.linesOf; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.PrintStream; +import java.nio.file.Path; import org.apache.commons.exec.Executor; import org.apache.maven.plugin.MojoExecutionException; @@ -54,7 +54,7 @@ public void setup() throws MojoExecutionException { deployMojo.deployToEngineApplication = "MyTestApp"; deployMojo.deployEngineDirectory = mojo.getEngineDir(mojo.project); deployMojo.deployTimeoutInSeconds = 120; - deployMojo.deployFile = new File("src/test/resources/deploy-single-7.1.0-SNAPSHOT.iar"); + deployMojo.deployFile = Path.of("src/test/resources/deploy-single-7.1.0-SNAPSHOT.iar"); deployMojo.deployTestUsers = "true"; System.setOut(new PrintStream(outContent)); @@ -68,22 +68,17 @@ public void restoreStreams() { @Test public void canDeployIar() throws Exception { deployMojo.deployToEngineApplication = "Portal"; - - File deployedIar = getTarget(deployMojo.deployFile, deployMojo); - File deployedIarFlagFile = new File(deployedIar.getParent(), deployedIar.getName() + ".deployed"); - File deployedIarLogFile = new File(deployedIar.getParent(), deployedIar.getName() + ".deploymentLog"); - + var deployedIar = getTarget(deployMojo.deployFile, deployMojo); + var deployedIarFlagFile = deployedIar.resolveSibling(deployedIar.getFileName() + ".deployed"); + var deployedIarLogFile = deployedIar.resolveSibling(deployedIar.getFileName() + ".deploymentLog"); Executor startedProcess = null; try { startedProcess = mojo.startEngine(); - deployMojo.execute(); - assertThat(deployedIar).doesNotExist(); assertThat(deployedIarFlagFile).exists(); assertThat(deployedIarLogFile).exists(); - assertThat(linesOf(deployedIarLogFile)).haveAtLeast(1, - new Condition<>(s -> s.contains("Deploying users ..."), "")); + assertThat(linesOf(deployedIarLogFile)).haveAtLeast(1, new Condition<>(s -> s.contains("Deploying users ..."), "")); } finally { kill(startedProcess); } @@ -140,11 +135,11 @@ private void deployIarRemoteAndAssert() throws Exception, MojoExecutionException } } - private static File getTarget(File iar, DeployToEngineMojo mojo) { - File deploy = new File(mojo.deployEngineDirectory, mojo.deployDirectory); - File app = new File(deploy, mojo.deployToEngineApplication); - File deployedIar = new File(app, iar.getName()); - return deployedIar; + private static Path getTarget(Path iar, DeployToEngineMojo mojo) { + return mojo.deployEngineDirectory + .resolve(mojo.deployDirectory) + .resolve(mojo.deployToEngineApplication) + .resolve(iar.getFileName().toString()); } private static void kill(Executor startedProcess) { @@ -159,6 +154,6 @@ private static void kill(Executor startedProcess) { @Rule public ProjectMojoRule deployRule = new ProjectMojoRule( - new File("src/test/resources/base"), DeployToEngineMojo.GOAL); + Path.of("src/test/resources/base"), DeployToEngineMojo.GOAL); } diff --git a/src/test/java/ch/ivyteam/ivy/maven/deploy/TestDeployToTestEngineMojo.java b/src/test/java/ch/ivyteam/ivy/maven/deploy/TestDeployToTestEngineMojo.java index c6157ef9..e1e6523d 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/deploy/TestDeployToTestEngineMojo.java +++ b/src/test/java/ch/ivyteam/ivy/maven/deploy/TestDeployToTestEngineMojo.java @@ -17,7 +17,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; import java.io.IOException; import java.nio.file.FileSystem; import java.nio.file.FileSystems; @@ -45,25 +44,25 @@ public void autoAppZip() throws ArchiverException, IOException { Path reactorProject = workspace.resolve("myReactorProject"); Files.createDirectories(reactorProject); Path superPom = reactorProject.resolve("pom.xml"); - Files.copy(new File("src/test/resources/base/pom.xml").toPath(), superPom); + Files.copy(Path.of("src/test/resources/base/pom.xml"), superPom); Path builtTarget = workspace.resolve("myPackedReactorProject").resolve("target"); Files.createDirectories(builtTarget); Files.createFile(builtTarget.resolve("alreadyPacked.iar")); - File appZip = mojo.createFullAppZip(List.of( - Files.createFile(workspace.resolve("demo.iar")).toFile(), - Files.createFile(workspace.resolve("demoTest.iar")).toFile(), - reactorProject.toFile(), - builtTarget.getParent().toFile())); - assertThat(appZip.getName()).isEqualTo("myApp-app.zip"); - assertThat(DeployToTestEngineMojo.findPackedIar(builtTarget.getParent().toFile())).isPresent(); + var appZip = mojo.createFullAppZip(List.of( + Files.createFile(workspace.resolve("demo.iar")), + Files.createFile(workspace.resolve("demoTest.iar")), + reactorProject, + builtTarget.getParent())); + assertThat(appZip.getFileName().toString()).isEqualTo("myApp-app.zip"); + assertThat(DeployToTestEngineMojo.findPackedIar(builtTarget.getParent())).isPresent(); assertThat(getRootFiles(appZip)) .containsOnly("demo.iar", "demoTest.iar", "myReactorProject", "alreadyPacked.iar"); } - private static List getRootFiles(File zip) throws IOException { - java.net.URI uri = java.net.URI.create("jar:" + zip.toPath().toUri()); + private static List getRootFiles(Path zip) throws IOException { + java.net.URI uri = java.net.URI.create("jar:" + zip.toUri()); try (FileSystem zipFsCr = FileSystems.newFileSystem(uri, Collections.emptyMap())) { Path root = zipFsCr.getPath("/"); try (Stream paths = Files.list(root)) { @@ -81,6 +80,6 @@ public void appNameSanitizing() { @Rule public ProjectMojoRule deploy = new ProjectMojoRule<>( - new File("src/test/resources/base"), DeployToTestEngineMojo.TEST_GOAL); + Path.of("src/test/resources/base"), DeployToTestEngineMojo.TEST_GOAL); } diff --git a/src/test/java/ch/ivyteam/ivy/maven/engine/TestClasspathJar.java b/src/test/java/ch/ivyteam/ivy/maven/engine/TestClasspathJar.java index 87701bd3..e164197d 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/engine/TestClasspathJar.java +++ b/src/test/java/ch/ivyteam/ivy/maven/engine/TestClasspathJar.java @@ -40,16 +40,17 @@ class TestClasspathJar { void readWriteClasspath() throws IOException { var jarFile = tempDir.resolve("my.jar"); Files.createFile(jarFile); - ClasspathJar jar = new ClasspathJar(jarFile.toFile()); + var jar = new ClasspathJar(jarFile); var content = tempDir.resolve("content.jar"); Files.createFile(content); - jar.createFileEntries(List.of(content.toFile())); + jar.createFileEntries(List.of(content)); assertThat(jar.getClasspathFiles()).contains(content.getFileName().toString()); try (var in = new ZipInputStream(Files.newInputStream(jarFile))) { ZipEntry first = in.getNextEntry(); assertThat(first.getName()).isEqualTo("META-INF/MANIFEST.MF"); + String manifest = new String(in.readAllBytes(), StandardCharsets.UTF_8); assertThat(manifest) .as("Manifest should not start with a whitespace or it will not be interpreted by the JVM") diff --git a/src/test/java/ch/ivyteam/ivy/maven/engine/TestEngineVersionEvaluator.java b/src/test/java/ch/ivyteam/ivy/maven/engine/TestEngineVersionEvaluator.java index ca73b89b..f5bd6962 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/engine/TestEngineVersionEvaluator.java +++ b/src/test/java/ch/ivyteam/ivy/maven/engine/TestEngineVersionEvaluator.java @@ -18,13 +18,13 @@ class TestEngineVersionEvaluator { @Test void isOSGiEngine_invalid() { - assertThat(EngineVersionEvaluator.isOSGiEngine(tempDir.toFile())).isFalse(); + assertThat(EngineVersionEvaluator.isOSGiEngine(tempDir)).isFalse(); } @Test void isOSGiEngine_valid() throws IOException { var systemDir = tempDir.resolve(OsgiDir.INSTALL_AREA); Files.createDirectories(systemDir); - assertThat(EngineVersionEvaluator.isOSGiEngine(tempDir.toFile())).isTrue(); + assertThat(EngineVersionEvaluator.isOSGiEngine(tempDir)).isTrue(); } } diff --git a/src/test/java/ch/ivyteam/ivy/maven/engine/deploy/dir/TestFileLogForwarder.java b/src/test/java/ch/ivyteam/ivy/maven/engine/deploy/dir/TestFileLogForwarder.java index 3d91dcc8..09e960da 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/engine/deploy/dir/TestFileLogForwarder.java +++ b/src/test/java/ch/ivyteam/ivy/maven/engine/deploy/dir/TestFileLogForwarder.java @@ -40,7 +40,7 @@ void fileToMavenLog() throws Exception { var fakeEngineLog = tempDir.resolve("myProject.iar.deploymentLog"); Files.createFile(fakeEngineLog); var mavenLog = new LogCollector(); - var logForwarder = new FileLogForwarder(fakeEngineLog.toFile(), mavenLog, new EngineLogLineHandler(mavenLog)); + var logForwarder = new FileLogForwarder(fakeEngineLog, mavenLog, new EngineLogLineHandler(mavenLog)); var log = new FakeLogger(fakeEngineLog); try { diff --git a/src/test/java/ch/ivyteam/ivy/maven/log/LogCollector.java b/src/test/java/ch/ivyteam/ivy/maven/log/LogCollector.java index 401faf7f..b9fb5e65 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/log/LogCollector.java +++ b/src/test/java/ch/ivyteam/ivy/maven/log/LogCollector.java @@ -24,15 +24,16 @@ /** * Simple Test logger built to make simple assertions on occurred logs. - * + * * @author Reguel Wermelinger * @since 05.11.2014 */ public class LogCollector implements Log { - private List debuggings = new ArrayList<>(); - private List infos = new ArrayList<>(); - private List warnings = new ArrayList<>(); - private List errors = new ArrayList<>(); + + private final List debuggings = new ArrayList<>(); + private final List infos = new ArrayList<>(); + private final List warnings = new ArrayList<>(); + private final List errors = new ArrayList<>(); public static class LogEntry { private String message; diff --git a/src/test/java/ch/ivyteam/ivy/maven/test/TestEngineControlEngineDirectory.java b/src/test/java/ch/ivyteam/ivy/maven/test/TestEngineControlEngineDirectory.java index 79189429..89d7c050 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/test/TestEngineControlEngineDirectory.java +++ b/src/test/java/ch/ivyteam/ivy/maven/test/TestEngineControlEngineDirectory.java @@ -11,6 +11,7 @@ import ch.ivyteam.ivy.maven.test.AbstractIntegrationTestMojo.TestEngineLocation; public class TestEngineControlEngineDirectory extends BaseEngineProjectMojoTest { + @Rule public RunnableEngineMojoRule rule = new RunnableEngineMojoRule( StopTestEngineMojo.GOAL); @@ -33,7 +34,6 @@ public void engineControl_engineDir_isNull() throws Exception { StopTestEngineMojo mojo = new StopTestEngineMojo(); mojo.project = rule.project; mojo.engineDirectory = rule.getMojo().engineCacheDirectory; - assertThat(mojo.createEngineController()).isNotNull(); } } diff --git a/src/test/java/ch/ivyteam/ivy/maven/test/TestSetupIvyTestPropertiesMojo.java b/src/test/java/ch/ivyteam/ivy/maven/test/TestSetupIvyTestPropertiesMojo.java index ddc22a82..0c5a5ff1 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/test/TestSetupIvyTestPropertiesMojo.java +++ b/src/test/java/ch/ivyteam/ivy/maven/test/TestSetupIvyTestPropertiesMojo.java @@ -18,14 +18,13 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.net.URL; import java.net.URLClassLoader; import java.nio.file.Files; -import java.util.Arrays; +import java.nio.file.Path; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Properties; @@ -44,16 +43,16 @@ import ch.ivyteam.ivy.maven.util.SharedFile; public class TestSetupIvyTestPropertiesMojo extends BaseEngineProjectMojoTest { + @Test public void engineClasspathIsSharedAsProperty() throws Exception { - SetupIvyTestPropertiesMojo mojo = rule.getMojo(); + var mojo = rule.getMojo(); assertThat(getProperty(Property.IVY_ENGINE_CLASSPATH)) .as("used classpath has not been evaluated.") .isNullOrEmpty(); assertThat(getProperty(Property.MAVEN_TEST_ARGLINE)).isNullOrEmpty(); mojo.execute(); - assertThat(getProperty(Property.IVY_ENGINE_CLASSPATH)) .as("used classpath must be shared as property so that other mojos can access it") .isNotEmpty(); @@ -61,11 +60,10 @@ public void engineClasspathIsSharedAsProperty() throws Exception { @Test public void engineModuleHintsSharedAsProperty() throws Exception { - SetupIvyTestPropertiesMojo mojo = rule.getMojo(); + var mojo = rule.getMojo(); assertThat(getProperty(Property.MAVEN_TEST_ARGLINE)).isNullOrEmpty(); mojo.execute(); - assertThat(getProperty(Property.MAVEN_TEST_ARGLINE)).contains(" --add-opens="); } @@ -79,7 +77,7 @@ public void engineClasspathIsConfiguredForSurefire() throws Exception { MavenProject project = rule.getMojo().project; assertThat(project.getBuild().getTestOutputDirectory()) - .isEqualTo(new File(project.getBasedir(), "classes-test").getAbsolutePath()); + .isEqualTo(project.getBasedir().toPath().resolve("classes-test").toAbsolutePath().toString()); assertThat(project.getProperties().get(Property.MAVEN_TEST_ADDITIONAL_CLASSPATH)) .isEqualTo("${" + Property.IVY_TEST_VM_RUNTIME + "}," + "${" + Property.IVY_ENGINE_CLASSPATH + "}," @@ -93,22 +91,21 @@ public void ivyTestRuntimeClasspathResource() throws Exception { MavenProject project = rule.getMojo().project; String vmRtEntry = project.getProperties().getProperty(Property.IVY_TEST_VM_RUNTIME); Properties props = new Properties(); - try ( - URLClassLoader loader = new URLClassLoader(new URL[] {new File(vmRtEntry).toURI().toURL()}, null); - InputStream is = loader.getResourceAsStream(IvyTestRuntime.RUNTIME_PROPS_RESOURCE)) { + try (var loader = new URLClassLoader(new URL[] { Path.of(vmRtEntry).toUri().toURL()}, null); + var is = loader.getResourceAsStream(IvyTestRuntime.RUNTIME_PROPS_RESOURCE)) { props.load(is); } assertThat(props.getProperty(Key.PRODUCT_DIR)).isNotEmpty(); assertThat(props.getProperty(Key.PROJECT_LOCATIONS)) - .isEqualTo("<" + rule.getMojo().project.getBasedir().toURI() + ">"); + .isEqualTo("<" + rule.getMojo().project.getBasedir().toPath().toUri() + ">"); } @Test public void ivyTestRuntimeIO() throws IOException { - IvyTestRuntime rt = new IvyTestRuntime(); - rt.setProductDir(new File("/tmp/myEngine")); - File ivyTestVm = rt.store(rule.project); - assertThat(ivyTestVm.getParentFile().getName()).isEqualTo("target"); + var rt = new IvyTestRuntime(); + rt.setProductDir(Path.of("/tmp/myEngine")); + var ivyTestVm = rt.store(rule.project); + assertThat(ivyTestVm.getParent().getFileName().toString()).isEqualTo("target"); } @Rule @@ -127,10 +124,10 @@ protected void before() throws Throwable { } private void writeTestClasspathJar() throws IOException { - File classPathJar = new SharedFile(getMojo().project).getEngineClasspathJar(); - new ClasspathJar(classPathJar).createFileEntries(Arrays.asList( - Files.createTempFile("dummy", ".jar").toFile(), - Files.createTempFile("dummy2", ".jar").toFile())); + var classPathJar = new SharedFile(getMojo().project).getEngineClasspathJar(); + new ClasspathJar(classPathJar).createFileEntries(List.of( + Files.createTempFile("dummy", ".jar"), + Files.createTempFile("dummy2", ".jar"))); } private void writeTestCompileResult() throws IOException { diff --git a/src/test/java/ch/ivyteam/ivy/maven/test/TestShareIntegrationTestPropertiesMojo.java b/src/test/java/ch/ivyteam/ivy/maven/test/TestShareIntegrationTestPropertiesMojo.java index acbcd404..7ce899dc 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/test/TestShareIntegrationTestPropertiesMojo.java +++ b/src/test/java/ch/ivyteam/ivy/maven/test/TestShareIntegrationTestPropertiesMojo.java @@ -31,6 +31,7 @@ import ch.ivyteam.ivy.maven.engine.EngineControl; public class TestShareIntegrationTestPropertiesMojo extends BaseEngineProjectMojoTest { + @Rule public ProjectMojoRule setupProps = new TestProjectMojoRule(); @@ -50,12 +51,11 @@ public void shareFailsafeProps() throws MojoExecutionException, MojoFailureExcep props.setProperty(EngineControl.Property.TEST_ENGINE_LOG, "/var/logs/ivy.log"); props.setProperty(DeployToTestEngineMojo.Property.TEST_ENGINE_APP, "myTstApp"); - SetupIntegrationTestPropertiesMojo mojo = setupProps.getMojo(); + var mojo = setupProps.getMojo(); mojo.execute(); String argLine = (String) props.get(SetupIntegrationTestPropertiesMojo.FAILSAFE_ARGLINE_PROPERTY); - assertThat(argLine).startsWith( - "-Dtest.engine.url=http://127.0.0.1:9999 -Dtest.engine.log=/var/logs/ivy.log -Dtest.engine.app=myTstApp"); - assertThat(argLine).contains(" --add-opens="); + assertThat(argLine) + .startsWith("-Dtest.engine.url=http://127.0.0.1:9999 -Dtest.engine.log=/var/logs/ivy.log -Dtest.engine.app=myTstApp") + .contains(" --add-opens="); } - } diff --git a/src/test/java/ch/ivyteam/ivy/maven/test/TestStartEngine.java b/src/test/java/ch/ivyteam/ivy/maven/test/TestStartEngine.java index 9a14307a..915d0dc4 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/test/TestStartEngine.java +++ b/src/test/java/ch/ivyteam/ivy/maven/test/TestStartEngine.java @@ -18,9 +18,9 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import org.apache.commons.exec.Executor; import org.apache.commons.exec.ShutdownHookProcessDestroyer; @@ -49,7 +49,7 @@ public void canStartEngine() throws Exception { startedProcess = mojo.startEngine(); assertThat(getProperty(EngineControl.Property.TEST_ENGINE_URL)).startsWith("http://") .endsWith("/"); - assertThat(new File(getProperty(EngineControl.Property.TEST_ENGINE_LOG))).exists(); + assertThat(Path.of(getProperty(EngineControl.Property.TEST_ENGINE_LOG))).exists(); } finally { kill(startedProcess); } @@ -62,8 +62,7 @@ public void testKillEngineOnVmExit() throws Exception { try { startedProcess = mojo.startEngine(); assertThat(startedProcess.getProcessDestroyer()).isInstanceOf(ShutdownHookProcessDestroyer.class); - ShutdownHookProcessDestroyer jvmShutdownHoock = (ShutdownHookProcessDestroyer) startedProcess - .getProcessDestroyer(); + var jvmShutdownHoock = (ShutdownHookProcessDestroyer) startedProcess.getProcessDestroyer(); assertThat(jvmShutdownHoock.size()) .as("One started engine process must be killed on VM end.") .isEqualTo(1); @@ -84,7 +83,7 @@ public void testKillEngineOnVmExit() throws Exception { public void startEngine_MODIFY_EXISTING_configuredEngine() throws MojoExecutionException, IOException { StartTestEngineMojo mojo = rule.getMojo(); mojo.testEngine = TestEngineLocation.MODIFY_EXISTING; - mojo.engineDirectory = Files.createTempDirectory("test").toFile(); + mojo.engineDirectory = Files.createTempDirectory("test"); assertThat(mojo.engineToTarget()).as("MODIFY_EXISTING set and using configured engine do not copy") .isFalse(); } @@ -108,7 +107,7 @@ public void startEngine_MODIFY_EXISTING_cacheEngine() throws MojoExecutionExcept public void startEngine_COPY_FROM_TEMPLATE_configuredEngine() throws MojoExecutionException, IOException { StartTestEngineMojo mojo = rule.getMojo(); mojo.testEngine = TestEngineLocation.COPY_FROM_TEMPLATE; - mojo.engineDirectory = Files.createTempDirectory("test").toFile(); + mojo.engineDirectory = Files.createTempDirectory("test"); assertThat(mojo.engineToTarget()).as("COPY_FROM_TEMPLATE set and using configured engine do copy") .isTrue(); } @@ -132,7 +131,7 @@ public void startEngine_COPY_FROM_TEMPLATE_cacheEngine() throws MojoExecutionExc public void startEngine_COPY_FROM_CACHE_configuredEngine() throws MojoExecutionException, IOException { StartTestEngineMojo mojo = rule.getMojo(); mojo.testEngine = TestEngineLocation.COPY_FROM_CACHE; - mojo.engineDirectory = Files.createTempDirectory("test").toFile(); + mojo.engineDirectory = Files.createTempDirectory("test"); assertThat(mojo.engineToTarget()).as("COPY_FROM_CACHE set and using configured engine do not copy") .isFalse(); } @@ -150,7 +149,7 @@ public void startEngine_copyEngineToTarget() throws Exception { Executor startedProcess = null; try { mojo.testEngine = TestEngineLocation.COPY_FROM_TEMPLATE; - File engineDirTarget = mojo.getEngineDir(mojo.project); + var engineDirTarget = mojo.getEngineDir(mojo.project); assertThat(engineDirTarget.toString()).contains("/target/ivyEngine"); assertThat(engineDirTarget).doesNotExist(); @@ -169,7 +168,7 @@ public void startEngine_targetDirectoryNotClean() throws Exception { Executor startedProcess = null; try { - File engineDirTarget = mojo.getEngineDir(mojo.project); + var engineDirTarget = mojo.getEngineDir(mojo.project); assertThat(engineDirTarget.toString()).contains("/target/ivyEngine"); assertThat(engineDirTarget).doesNotExist(); @@ -194,23 +193,23 @@ public void startEngine_copiedEngine_executable() throws Exception { mojo.testEngine = TestEngineLocation.COPY_FROM_TEMPLATE; Executor startedProcess = null; try { - File cacheEngine = mojo.engineDirectory; - assertFileExecutable(new File(cacheEngine, "elasticsearch/bin/elasticsearch")); - assertFileExecutable(new File(cacheEngine, "elasticsearch/bin/elasticsearch.bat")); + var cacheEngine = mojo.engineDirectory; + assertFileExecutable(cacheEngine.resolve("elasticsearch/bin/elasticsearch")); + assertFileExecutable(cacheEngine.resolve("elasticsearch/bin/elasticsearch.bat")); startedProcess = mojo.startEngine(); - - File engineTarget = mojo.getEngineDir(mojo.project); - assertFileExecutable(new File(engineTarget, "elasticsearch/bin/elasticsearch")); - assertFileExecutable(new File(engineTarget, "elasticsearch/bin/elasticsearch.bat")); + var engineTarget = mojo.getEngineDir(mojo.project); + assertFileExecutable(engineTarget.resolve("elasticsearch/bin/elasticsearch")); + assertFileExecutable(engineTarget.resolve("elasticsearch/bin/elasticsearch.bat")); } finally { kill(startedProcess); } } - private void assertFileExecutable(File file) { - assertThat(file).exists(); - assertThat(file.canExecute()).isTrue(); + private void assertFileExecutable(Path file) { + assertThat(file) + .exists() + .isExecutable(); } private static void kill(Executor startedProcess) { @@ -232,5 +231,4 @@ protected void before() throws Throwable { getMojo().maxmem = "2048m"; } }; - }