From 1a4decd658241e003d93d343c6fdb5146b3027e0 Mon Sep 17 00:00:00 2001 From: Alexander Suter Date: Mon, 22 Jul 2024 16:34:10 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=B5=F0=9F=90=B6=F0=9F=90=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ivy/maven/deploy/AbstractDeployMojo.java | 12 ++++++++---- .../ivy/maven/deploy/DeployToEngineMojo.java | 14 +++++--------- .../ivy/maven/deploy/DeployToTestEngineMojo.java | 8 ++------ .../deploy/DeploymentOptionsFileFactory.java | 4 ++-- 4 files changed, 17 insertions(+), 21 deletions(-) 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 8d658b31..78771d9e 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/deploy/AbstractDeployMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/deploy/AbstractDeployMojo.java @@ -227,7 +227,7 @@ protected final boolean checkSkip() { 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); @@ -236,7 +236,7 @@ protected final File createDeployOptionsFile(DeploymentOptionsFileFactory option try { String yamlOptions = YamlOptionsFactory.toYaml(this); if (StringUtils.isNotBlank(yamlOptions)) { - return optionsFileFactory.createFromConfiguration(yamlOptions).toFile(); + return optionsFileFactory.createFromConfiguration(yamlOptions); } } catch (IOException ex) { throw new MojoExecutionException("Failed to generate YAML option", ex); @@ -244,8 +244,12 @@ 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)); + } + + private static File toFile(Path file) { + return file == null ? null : file.toFile(); } protected final void deployToDirectory(Path resolvedOptionsFile, Path deployDir) 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 79dbe6ff..2a16986c 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/deploy/DeployToEngineMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/deploy/DeployToEngineMojo.java @@ -145,7 +145,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } } - private void deployWithOptions(File resolvedOptionsFile) throws MojoExecutionException { + private void deployWithOptions(Path resolvedOptionsFile) throws MojoExecutionException { getLog().info("Deploying project " + deployFile.getFileName()); if (DeployMethod.DIRECTORY.equals(deployMethod)) { deployToDirectory(resolvedOptionsFile); @@ -158,7 +158,7 @@ private void deployWithOptions(File resolvedOptionsFile) throws MojoExecutionExc } } - private void deployToDirectory(File resolvedOptionsFile) throws MojoExecutionException { + private void deployToDirectory(Path resolvedOptionsFile) throws MojoExecutionException { var deployDir = getDeployDirectory(); if (deployEngineDirectory == null) { getLog().warn("Skipping deployment, target engine could not be evaluated." + @@ -172,14 +172,10 @@ private void deployToDirectory(File resolvedOptionsFile) throws MojoExecutionExc return; } checkDirParams(); - deployToDirectory(toPath(resolvedOptionsFile), deployDir.toPath()); + deployToDirectory(resolvedOptionsFile, deployDir.toPath()); } - private Path toPath(File file) { - return file == null ? null : file.toPath(); - } - - private void deployToRestService(File resolvedOptionsFile) throws MojoExecutionException { + private void deployToRestService(Path resolvedOptionsFile) throws MojoExecutionException { checkHttpParams(); Server server = session.getSettings().getServer(deployServerId); @@ -187,7 +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"); } - var httpDeployer = new HttpDeployer(secDispatcher, server, deployEngineUrl, deployToEngineApplication, deployFile, resolvedOptionsFile.toPath()); + var httpDeployer = new HttpDeployer(secDispatcher, server, deployEngineUrl, deployToEngineApplication, deployFile, resolvedOptionsFile); httpDeployer.deploy(getLog()); } 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 7db79b86..3f4d1eeb 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/deploy/DeployToTestEngineMojo.java +++ b/src/main/java/ch/ivyteam/ivy/maven/deploy/DeployToTestEngineMojo.java @@ -151,16 +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 { var deployDir = getEngineDir(project).toPath().resolve(DeployToEngineMojo.DEPLOY_DEFAULT); - deployToDirectory(toPath(resolvedOptionsFile), deployDir); + deployToDirectory(resolvedOptionsFile, deployDir); } finally { removeTemporaryDeploymentOptionsFile(resolvedOptionsFile); } } - - private Path toPath(File file) { - return file == null ? null : file.toPath(); - } } 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 102632ba..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 @@ -22,7 +22,7 @@ public DeploymentOptionsFileFactory(Path deployableArtifact) { this.deployableArtifact = deployableArtifact; } - public File createFromTemplate(Path optionsFile, MavenProject project, MavenSession session, + public Path createFromTemplate(Path optionsFile, MavenProject project, MavenSession session, MavenFileFilter fileFilter) throws MojoExecutionException { if (!isOptionsFile(optionsFile.toFile())) { return null; @@ -36,7 +36,7 @@ public File createFromTemplate(Path optionsFile, MavenProject project, MavenSess } catch (MavenFilteringException ex) { throw new MojoExecutionException("Failed to resolve templates in options file", ex); } - return targetFile.toFile(); + return targetFile; } private static boolean isOptionsFile(File optionsFile) {