Skip to content

Commit

Permalink
šŸµšŸ¶šŸ»
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsuter committed Jul 22, 2024
1 parent 7068a47 commit 2e38036
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
8 changes: 5 additions & 3 deletions src/main/java/ch/ivyteam/ivy/maven/AbstractEngineMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -111,13 +113,13 @@ protected final boolean isEngineDirectoryIdentified() {
}

protected final File findMatchingEngineInCacheDirectory() throws MojoExecutionException {
if (engineCacheDirectory == null || !engineCacheDirectory.exists()) {
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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/ivyteam/ivy/maven/InstallEngineMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private void downloadAndInstallEngine(boolean cleanEngineDir) throws MojoExecuti

if (!isEngineDirectoryIdentified()) {
String engineZipFileName = engineDownloader.getZipFileNameFromDownloadLocation();
engineDirectory = new File(engineCacheDirectory, ivyEngineVersionOfZip(engineZipFileName));
engineDirectory = new File(engineCacheDirectory.toFile(), ivyEngineVersionOfZip(engineZipFileName));
engineDirectory.mkdirs();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,9 +80,8 @@ protected final static Collection<File> findFiles(File dir, String fileExtension
return FileUtils.listFiles(dir, 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
Expand All @@ -98,9 +98,9 @@ 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().engineDirectory = evalEngineDir(getMojo()).toFile();
getMojo().useLatestMinor = true;
deleteOutdatedEngine();
getMojo().execute();
Expand Down Expand Up @@ -160,8 +160,8 @@ protected void before() throws Throwable {
}

protected void configureMojo(AbstractEngineMojo newMojo) {
newMojo.engineCacheDirectory = new File(CACHE_DIR);
newMojo.engineDirectory = evalEngineDir(getMojo());
newMojo.engineCacheDirectory = Path.of(CACHE_DIR);
newMojo.engineDirectory = evalEngineDir(getMojo()).toFile();
newMojo.ivyVersion = ENGINE_VERSION_TO_TEST;
}
}
Expand Down
15 changes: 7 additions & 8 deletions src/test/java/ch/ivyteam/ivy/maven/TestInstallEngineMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,23 @@ 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'.")
.isNull();
assertThat(mojo.autoInstallEngine).isTrue();

mojo.execute();

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());
.isEqualTo(mojo.getRawEngineDirectory().toPath());
}

private static MockHttpServerResponse createFakeZipResponse(File zip) throws Exception {
Expand Down Expand Up @@ -199,9 +198,9 @@ public void testEngineDownload_skipNonOsgiEngineInCache() throws Exception {
mojo.autoInstallEngine = true;

// OSGi
new File(mojo.engineCacheDirectory, "7.0.0" + File.separator + getFakeLibraryPath("7.0.0")).mkdirs();
Files.createDirectories(mojo.engineCacheDirectory.resolve("7.0.0").resolve(getFakeLibraryPath("7.0.0")));
// non-OSGi
new File(mojo.engineCacheDirectory, "7.1.0").mkdirs();
Files.createDirectories(mojo.engineCacheDirectory.resolve("7.1.0"));

mojo.execute();
assertThat(mojo.engineDirectory.getName()).isEqualTo("7.0.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void engineControl_engineDir_doesNotExist() throws Exception {
public void engineControl_engineDir_isNull() throws Exception {
StopTestEngineMojo mojo = new StopTestEngineMojo();
mojo.project = rule.project;
mojo.engineDirectory = rule.getMojo().engineCacheDirectory;
mojo.engineDirectory = rule.getMojo().engineCacheDirectory.toFile();

assertThat(mojo.createEngineController()).isNotNull();
}
Expand Down

0 comments on commit 2e38036

Please sign in to comment.