Skip to content

Commit

Permalink
Merge pull request #278 from axonivy/XIVY-10909-proxy-r10
Browse files Browse the repository at this point in the history
XIVY-10909 proxy r10
  • Loading branch information
ivy-rew authored Mar 20, 2023
2 parents ff42ae1 + 6f9a388 commit b4d6084
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 202 deletions.
17 changes: 11 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@
<version>3.6.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down Expand Up @@ -172,12 +183,6 @@
<version>3.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${maven.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-component-test-support</artifactId>
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/ch/ivyteam/ivy/maven/InstallEngineMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.wagon.proxy.ProxyInfoProvider;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
Expand All @@ -49,7 +50,7 @@
* <p>
* Command line invocation is supported. E.g.
* </p>
*
*
* <pre>
* mvn com.axonivy.ivy.ci:project-build-plugin:9.1.0:installEngine
* -Divy.engine.directory=c:/axonviy/engine
Expand All @@ -76,15 +77,15 @@ public class InstallEngineMojo extends AbstractEngineMojo {
* it must be published manually to an accessible plugin repository. The
* expected artifact descriptor is:
* </p>
*
*
* <pre>
* groupId=com.axonivy.ivy
* artifactId=engine
* version=!ivyVersion! (e.g. 7.4.0)
* classifier=!osArchitecture! (e.g. Slim_All_x64)
* extension=zip
* </pre>
*
*
* @since 7.4
*/
@Parameter(property = "ivy.engine.download.from.maven", defaultValue = "false")
Expand Down Expand Up @@ -141,6 +142,10 @@ public class InstallEngineMojo extends AbstractEngineMojo {
@Parameter(property = "ivy.engine.auto.install", defaultValue = "true")
boolean autoInstallEngine;

@Component
@SuppressWarnings("deprecation")
org.apache.maven.artifact.manager.WagonManager wagonManager;

@Override
public void execute() throws MojoExecutionException {
getLog().info("Provide engine for ivy version " + ivyVersion);
Expand All @@ -159,7 +164,7 @@ private void ensureEngineIsInstalled() throws MojoExecutionException {
ArtifactVersion installedEngineVersion = getInstalledEngineVersion(getRawEngineDirectory());

if (installedEngineVersion == null ||
!ivyVersionRange.containsVersion(installedEngineVersion)) {
!ivyVersionRange.containsVersion(installedEngineVersion)) {
handleWrongIvyVersion(installedEngineVersion);
}
}
Expand Down Expand Up @@ -221,10 +226,12 @@ public EngineDownloader getDownloader() throws MojoExecutionException {
if (downloadUsingMaven) {
return new MavenEngineDownloader(getLog(), ivyVersion, osArchitecture, pluginRepositories,
repositorySystem, repositorySession);
} else {
return new URLEngineDownloader(engineDownloadUrl, engineListPageUrl, osArchitecture, ivyVersion,
getIvyVersionRange(), getLog(), getDownloadDirectory());
}

@SuppressWarnings("deprecation")
ProxyInfoProvider proxies = wagonManager::getProxy;
return new URLEngineDownloader(engineDownloadUrl, engineListPageUrl, osArchitecture, ivyVersion,
getIvyVersionRange(), getLog(), getDownloadDirectory(), proxies);
}

static String ivyEngineVersionOfZip(String engineZipFileName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.nio.file.Path;
import java.util.Scanner;
import java.util.regex.Pattern;

Expand All @@ -16,60 +16,77 @@
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.wagon.providers.http.HttpWagon;
import org.apache.maven.wagon.proxy.ProxyInfoProvider;
import org.apache.maven.wagon.repository.Repository;

import ch.ivyteam.ivy.maven.engine.EngineVersionEvaluator;

public class URLEngineDownloader implements EngineDownloader {

private final URL engineDownloadUrl;
private final URL engineListPageUrl;
private final String osArchitecture;
private final String ivyVersion;
private final VersionRange ivyVersionRange;
private final Log log;
private final File downloadDirectory;
private String zipFileName = null;
private URL engineDownloadUrl = null;
private URL engineListPageUrl = null;
private String osArchitecture = null;
private String ivyVersion = null;
private VersionRange ivyVersionRange;
private Log log;
private File downloadDirectory;
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, File downloadDirectory,
ProxyInfoProvider proxies) {
this.engineDownloadUrl = engineDownloadUrl;
this.engineListPageUrl = engineListPageUrl;
this.osArchitecture = osArchitecture;
this.ivyVersion = ivyVersion;
this.ivyVersionRange = ivyVersionRange;
this.log = log;
this.downloadDirectory = downloadDirectory;
this.proxies = proxies;
}

@Override
public File downloadEngine() throws MojoExecutionException {
URL downloadUrlToUse = (engineDownloadUrl != null) ? engineDownloadUrl
: findEngineDownloadUrlFromListPage();
URL downloadUrlToUse = engineDownloadUrl;
if (downloadUrlToUse == null) {
downloadUrlToUse = findEngineDownloadUrlFromListPage();
}
return downloadEngineFromUrl(downloadUrlToUse);
}

private URL findEngineDownloadUrlFromListPage() throws MojoExecutionException {
try (InputStream pageStream = new UrlRedirectionResolver().followRedirections(engineListPageUrl)) {
return findEngineDownloadUrl(pageStream);
try {
var repo = new Repository("engine.list.page", engineListPageUrl.toExternalForm());
Path index = Files.createTempFile("page", ".html");
wagonDownload(repo, "", index);
try (InputStream pageStream = Files.newInputStream(index)) {
return findEngineDownloadUrl(pageStream);
} finally {
Files.deleteIfExists(index);
}
} catch (IOException ex) {
throw new MojoExecutionException(
"Failed to find engine download link in list page " + engineListPageUrl, ex);
throw new MojoExecutionException("Failed to find engine download link in list page " + engineListPageUrl, ex);
}
}

private File downloadEngineFromUrl(URL engineUrl) throws MojoExecutionException {
File downloadZip = evaluateTargetFile(engineUrl);
try {
File downloadZip = evaluateTargetFile(engineUrl);
log.info("Starting engine download from " + engineUrl);
Files.copy(engineUrl.openStream(), downloadZip.toPath(), StandardCopyOption.REPLACE_EXISTING);
var repo = new Repository("engine.repo", StringUtils.substringBeforeLast(engineUrl.toExternalForm(), "/"));
var resource = StringUtils.substringAfterLast(engineUrl.getPath(), "/");
wagonDownload(repo, resource, downloadZip.toPath());
return downloadZip;
} catch (IOException ex) {
} catch (Exception ex) {
throw new MojoExecutionException("Failed to download engine from '" + engineUrl + "' to '"
+ downloadDirectory + "'", ex);
}
}

private File evaluateTargetFile(URL engineUrl) {
zipFileName = StringUtils.substringAfterLast(engineUrl.toExternalForm(), "/");
zipFileName = StringUtils.substringAfterLast(engineUrl.getPath(), "/");
File downloadZip = new File(downloadDirectory, zipFileName);
int tempFileSuffix = 0;
while (downloadZip.exists()) {
Expand All @@ -80,6 +97,18 @@ private File evaluateTargetFile(URL engineUrl) {
return downloadZip;
}

private void wagonDownload(Repository repo, String resource, Path target) throws MojoExecutionException {
HttpWagon wagon = new HttpWagon();
try {
wagon.connect(repo, null, proxies);
wagon.get(resource, target.toFile());
} catch (Exception ex) {
throw new MojoExecutionException("Download failed from repo " + repo + " with resource " + resource, ex);
} finally {
wagon.closeConnection();
}
}

/**
* Extracts the name of the engine zip-file from the url used to download the
* engine. The zip-file name is only known <i>after</i> downloading the
Expand Down

This file was deleted.

9 changes: 8 additions & 1 deletion src/site/apt/examples.apt
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ Snapshots
+------------------------------------------------------------------------------------+
mvn clean install -Divy.engine.list.url=https://dev.axonivy.com/download/nightly
+------------------------------------------------------------------------------------+


Proxy

If your environment enforces the usage of a proxy to access the web, configure it in your settings.xml
as described here {{https://maven.apache.org/guides/mini/guide-proxies.html}}.

The maven proxy configuration is considered, when downloading the IvyEngine to compile projects.

2 changes: 1 addition & 1 deletion src/site/apt/faq.apt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Frequently asked questions

The Axon Ivy Community is strong and able to provide solutions for daily issues.

Be part of it: {{https://answers.axonivy.com/tags/project-build-plugin/}}
Be part of it: {{https://community.axonivy.com/?q=project-build-plugin}}
2 changes: 1 addition & 1 deletion src/site/apt/index.apt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Introduction


Ivy Documentation
{{https://developer.axonivy.com/doc/latest/DesignerGuideHtml/ivy.concepts.html#ivy-ci}}
{{https://developer.axonivy.com/doc/latest/designer-guide/how-to/continuous-integration.html}}
Loading

0 comments on commit b4d6084

Please sign in to comment.