Source:
<code>private void downloadAndInstallEngine(boolean cleanEngineDir) throws MojoExecutionException { EngineDownloader engineDownloader = new EngineDownloader(); if (autoInstallEngine) { getLog().info("Will automatically download Engine now."); File downloadZip = null; <START> if(downloadUsingMaven) <END> { getLog().info("Downloading engine " + ivyVersion + " using maven plugin repositories"); final ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(new DefaultArtifact(ENGINE_ZIP_GAV_GROUP, ENGINE_ZIP_GAV_ARTIFACT, osArchitecture, "zip", ivyVersion)); artifactRequest.setRepositories(pluginRepositories); try { ArtifactResult result = repositorySystem.resolveArtifact(repositorySession, artifactRequest); downloadZip = result.getArtifact().getFile(); } catch(ArtifactResolutionException e) { throw new MojoExecutionException("Failed to resolve artifact " + artifactRequest + "!", e); } } else { downloadZip = engineDownloader.downloadEngine(); } if (cleanEngineDir) { removeOldEngineContent(); } if (!isEngineDirectoryIdentified()) { String engineZipFileName; if(!downloadUsingMaven) { engineZipFileName = engineDownloader.getZipFileNameFromDownloadUrl(); } else { engineZipFileName = downloadZip.getName(); } engineDirectory = new File(engineCacheDirectory, ivyEngineVersionOfZip(engineZipFileName)); engineDirectory.mkdirs(); } unpackEngine(downloadZip); if(!downloadUsingMaven) { downloadZip.delete(); } ArtifactVersion installedEngineVersion = getInstalledEngineVersion(getRawEngineDirectory()); if (installedEngineVersion == null) { throw new MojoExecutionException("Can not determine installed engine version in directory '"+getRawEngineDirectory()+"'. " + "Possibly a non-OSGi engine."); } if (!getIvyVersionRange().containsVersion(installedEngineVersion)) { throw new MojoExecutionException("Automatic installation of an ivyEngine failed. " + "Downloaded version is '"+installedEngineVersion+"' but expecting '"+ivyVersion+"'."); } } else { throw new MojoExecutionException("Aborting class generation as no valid ivy Engine is available! " + "Use the 'autoInstallEngine' parameter for an automatic installation."); } }</code><technical_language>recommend encapsulate ZIP download maven in extra method. execution flow defines installed engine is pretty complex</technical_language>

Target:
private void downloadAndInstallEngine(boolean cleanEngineDir) throws MojoExecutionException { final EngineDownloader engineDownloader; if(downloadUsingMaven) { engineDownloader = new MavenEngineDownloader(getLog(), ivyVersion, osArchitecture, pluginRepositories, repositorySystem, repositorySession); } else { engineDownloader = new URLEngineDownloader(engineDownloadUrl, engineListPageUrl, osArchitecture, ivyVersion, getIvyVersionRange(), getLog(), getDownloadDirectory()); } if (autoInstallEngine) { getLog().info("Will automatically download Engine now."); File downloadZip = downloadZip = engineDownloader.downloadEngine(); if (cleanEngineDir) { removeOldEngineContent(); } if (!isEngineDirectoryIdentified()) { String engineZipFileName = engineDownloader.getZipFileNameFromDownloadLocation(); engineDirectory = new File(engineCacheDirectory, ivyEngineVersionOfZip(engineZipFileName)); engineDirectory.mkdirs(); } unpackEngine(downloadZip); if(!downloadUsingMaven) { downloadZip.delete(); } ArtifactVersion installedEngineVersion = getInstalledEngineVersion(getRawEngineDirectory()); if (installedEngineVersion == null) { throw new MojoExecutionException("Can not determine installed engine version in directory '"+getRawEngineDirectory()+"'. " + "Possibly a non-OSGi engine."); } if (!getIvyVersionRange().containsVersion(installedEngineVersion)) { throw new MojoExecutionException("Automatic installation of an ivyEngine failed. " + "Downloaded version is '"+installedEngineVersion+"' but expecting '"+ivyVersion+"'."); } } else { throw new MojoExecutionException("Aborting class generation as no valid ivy Engine is available! " + "Use the 'autoInstallEngine' parameter for an automatic installation."); } }