Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: test with plugin from maven-central #17

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ log4j.rootLogger=INFO, CONSOLE

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%p] %d %t %c - %m%n
log4j.appender.CONSOLE.layout.ConversionPattern=[%p] %c - %m%n

log4j2.formatMsgNoLookups=True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@
import org.testcontainers.utility.MountableFile;

/**
* In this test this plugin is build locally and used in maven project to obtain dependencies over HTTP/3.
* This test uses two docker containers:<p>
* 1) {@link ArtipieHTTP3IT#artipie} is container with latest artipie version running on ubuntu 22.04 and java 21<p>
* 2) {@link ArtipieHTTP3IT#mavenClient} is ubuntu 22.04 based container with this plugin built with maven 3.9.5 under java 21,
* 1) {@link ArtipieAndLocalPluginHTTP3IT#artipie} is container with latest artipie version running on ubuntu 22.04 and java 21<p>
* 2) {@link ArtipieAndLocalPluginHTTP3IT#mavenClient} is ubuntu 22.04 based container with this plugin built with maven 3.9.5 under java 21,
* see ./Dockerfile<p>
*
* The containers are connected via docker {@link Network} with alias 'artipie'. Artipie container
* runs HTTP3 maven-proxy repository available at <code>https://artipie:8091/my-maven-proxy/</code>.
* <p>
* Test maven project {@code ./resources/com/example/maven-http3} which uses this plugin is added to
* {@link ArtipieHTTP3IT#mavenClient} and built with maven settings
* {@link ArtipieAndLocalPluginHTTP3IT#mavenClient} and built with maven settings
* {@code ./resources/com/example/maven-http3/maven-settings.xml}. The dependencies of this project
* are obtained from Artipie via HTTP3.
*
*/
public class ArtipieHTTP3IT {
public class ArtipieAndLocalPluginHTTP3IT {

private static final Logger LOGGER = LoggerFactory.getLogger(ArtipieHTTP3IT.class);
private static final Logger LOGGER = LoggerFactory.getLogger(ArtipieAndLocalPluginHTTP3IT.class);

private GenericContainer<?> mavenClient;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package com.artipie.aether.transport.http3;

import java.io.IOException;
import java.util.function.Consumer;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.Container;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.output.OutputFrame;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.images.builder.ImageFromDockerfile;
import org.testcontainers.utility.MountableFile;

/**
* In this test we use this plugin from maven central to build test maven project and obtain
* dependencies from artipie via HTTP/3 protocol.
* Various maven repositories configuration settings are tested.
*/
public class ArtipieAndPluginFromCentralIT {

private static final Logger LOGGER =
LoggerFactory.getLogger(ArtipieAndPluginFromCentralIT.class);

private GenericContainer<?> mavenClient;

private GenericContainer<?> artipie;

private final Consumer<OutputFrame> artipieLog =
new Slf4jLogConsumer(LoggerFactory.getLogger("ARTIPIE"));

private Network net;

@BeforeEach
void init() throws IOException, InterruptedException {
this.net = Network.newNetwork();
this.artipie = new GenericContainer<>("artipie/artipie-ubuntu:latest")
.withNetwork(this.net)
.withNetworkAliases("artipie")
.withLogConsumer(this.artipieLog)
.withClasspathResourceMapping(
"artipie.yaml", "/etc/artipie/artipie.yml", BindMode.READ_ONLY
)
.withClasspathResourceMapping(
"my-maven-proxy.yaml", "/var/artipie/repo/my-maven-proxy.yaml", BindMode.READ_ONLY
)
.withWorkingDirectory("/w");
this.mavenClient = new GenericContainer<>(
new ImageFromDockerfile("maven-client").withFileFromClasspath(
"Dockerfile", "ArtipieAndPluginFromCentralIT/Dockerfile"
)
)
.withNetwork(this.net)
.withCommand("tail", "-f", "/dev/null")
.withWorkingDirectory("/w");
this.mavenClient.start();
this.artipie.start();
this.mavenClient.execInContainer("sleep", "5");
}

/**
* Here artipie HTTP/3 repository is specified in maven settings.xml file. Maven client uses this
* repository to download dependencies only (not plugins). Thus, maven client does the following:<p/>
* 1) downloads maven-resolver-transport-http3 and its deps from central directly<p/>
* 2) once downloaded, maven-resolver-transport-http3 plugin is activated and
* project dependencies are downloaded from repository, specified in settings.xml file via HTTP/3<p/>
* 3) maven client needs some other plugins to build the project, and it tries to obtain them
* from central still using maven-resolver-transport-http3, and plugin
* performs requests to central via HTTP/1.1<p/>
*/
@Test
void buildsWithMavenProfile() throws IOException, InterruptedException {
this.putClasspathResourceToClient("ArtipieAndPluginFromCentralIT/com/example/test-maven-profile/maven-settings.xml", "/w/settings.xml");
this.putClasspathResourceToClient("ArtipieAndPluginFromCentralIT/com/example/test-maven-profile/pom.xml", "/w/pom.xml");
final Container.ExecResult exec = this.mavenClient.execInContainer(
"mvn", "install", "-DskipTests", "-s", "settings.xml", "-Daether.connector.https.securityMode=insecure"
);
String res = String.join("\n", exec.getStdout(), exec.getStderr());
LOGGER.info(res);
MatcherAssert.assertThat("Maven install status is not successful", exec.getExitCode() == 0);
MatcherAssert.assertThat(
res,
Matchers.stringContainsInOrder(
"Downloaded from central: https://repo.maven.apache.org/maven2/com/artipie/maven/resolver/maven-resolver-transport-http3",
"BUILD SUCCESS",
"Request over HTTP/3.0 done, method=GET, resp status=200, url=https://artipie:8091/my-maven-proxy/args4j/args4j/2.33/args4j-2.33.jar",
"Request over HTTP/3.0 done, method=GET, resp status=200, url=https://artipie:8091/my-maven-proxy/org/springframework/spring-web/6.1.0/spring-web-6.1.0.jar",
"Request over HTTP/1.1 done, method=GET, resp status=200, url=https://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/3.6.0/maven-archiver-3.6.0.pom"
)
);
}

/**
* Here repository is specified in pom.xml file, maven client work logic is the same as in
* {@link ArtipieAndPluginFromCentralIT#buildsWithMavenProfile()}.
*/
@Test
void buildsWithPomRepo() throws IOException, InterruptedException {
this.putClasspathResourceToClient("ArtipieAndPluginFromCentralIT/com/example/test-pom-repo/pom.xml", "/w/pom.xml");
final Container.ExecResult exec = this.mavenClient.execInContainer(
"mvn", "install", "-Daether.connector.https.securityMode=insecure"
);
String res = String.join("\n", exec.getStdout(), exec.getStderr());
LOGGER.info(res);
MatcherAssert.assertThat("Maven install status is not successful", exec.getExitCode() == 0);
MatcherAssert.assertThat(
res,
Matchers.stringContainsInOrder(
"Downloaded from central: https://repo.maven.apache.org/maven2/com/artipie/maven/resolver/maven-resolver-transport-http3",
"BUILD SUCCESS",
"Request over HTTP/3.0 done, method=GET, resp status=200, url=https://artipie:8091/my-maven-proxy/args4j/args4j/2.33/args4j-2.33.jar",
"Request over HTTP/3.0 done, method=GET, resp status=200, url=https://artipie:8091/my-maven-proxy/org/springframework/spring-web/6.1.0/spring-web-6.1.0.jar",
"Request over HTTP/1.1 done, method=GET, resp status=200, url=https://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/3.6.0/maven-archiver-3.6.0.pom"
)
);
}

/**
* In this example project we specify both repositories for plugins and dependencies in pom.xml.
* In the case, when maven client is not able to download plugin from custom repo, it switches
* to central. Thus, maven client does the following:<p/>
* 1) tries to get maven-resolver-transport-http3 plugin from artipie via HTTP/1.1, but fails
* and switches to central<p/>
* 2) once downloaded, maven-resolver-transport-http3 plugin is activated and
* all other dependencies and plugins are downloaded from artipie via HTTP/3
*/
@Test
void buildsWithPomPluginRepo() throws IOException, InterruptedException {
this.putClasspathResourceToClient("ArtipieAndPluginFromCentralIT/com/example/test-pom-plugin-repo/pom.xml", "/w/pom.xml");
final Container.ExecResult exec = this.mavenClient.execInContainer(
"mvn", "install", "-Daether.connector.https.securityMode=insecure"
);
String res = String.join("\n", exec.getStdout(), exec.getStderr());
LOGGER.info(res);
MatcherAssert.assertThat("Maven install status is not successful", exec.getExitCode() == 0);
MatcherAssert.assertThat(
res,
Matchers.stringContainsInOrder(
"Downloaded from central: https://repo.maven.apache.org/maven2/com/artipie/maven/resolver/maven-resolver-transport-http3",
"BUILD SUCCESS",
"Request over HTTP/3.0 done, method=GET, resp status=200, url=https://artipie:8091/my-maven-proxy/args4j/args4j/2.33/args4j-2.33.jar",
"Request over HTTP/3.0 done, method=GET, resp status=200, url=https://artipie:8091/my-maven-proxy/org/springframework/spring-web/6.1.0/spring-web-6.1.0.jar",
"Request over HTTP/3.0 done, method=GET, resp status=200, url=https://artipie:8091/my-maven-proxy/org/apache/maven/maven-archiver/3.6.0/maven-archiver-3.6.0.pom"
)
);
}

@AfterEach
void close() {
this.artipie.stop();
this.mavenClient.stop();
this.net.close();
}

private void putClasspathResourceToClient(final String res, final String path) {
final MountableFile file = MountableFile.forClasspathResource(res);
this.mavenClient.copyFileToContainer(file, path);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Ubuntu 16.04
# Oracle Java 21 64 bit
# Maven 3.9.5

FROM ubuntu:22.04

# this is a non-interactive automated build - avoid some warning messages
ENV DEBIAN_FRONTEND noninteractive

# update dpkg repositories
RUN apt-get update

# install wget
RUN apt-get install -y wget

# get maven 3.3.9
RUN wget --no-verbose -O /tmp/apache-maven-3.9.5.tar.gz https://dlcdn.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz

# install maven
RUN tar xzf /tmp/apache-maven-3.9.5.tar.gz -C /opt/
RUN ln -s /opt/apache-maven-3.9.5 /opt/maven
RUN ln -s /opt/maven/bin/mvn /usr/local/bin
RUN rm -f /tmp/apache-maven-3.9.5.tar.gz
ENV MAVEN_HOME /opt/maven

# remove download archive files
RUN apt-get clean

# set shell variables for java installation
ENV java_version 21
ENV filename jdk-21_linux-x64_bin.tar.gz
ENV downloadlink https://download.oracle.com/java/21/latest/$filename

# download java, accepting the license agreement
RUN wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" -O /tmp/$filename $downloadlink

# unpack java
RUN mkdir /opt/java-oracle/ && mkdir /opt/java-oracle/jdk21/ && tar -zxf /tmp/$filename -C /opt/java-oracle/jdk21/ --strip-components 1
ENV JAVA_HOME /opt/java-oracle/jdk21
ENV PATH $JAVA_HOME/bin:$PATH

# configure symbolic links for the java and javac executables
RUN update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 20000 && update-alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 20000

# check maven
RUN mvn --version

CMD [""]
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0"?>
<!--
The MIT License (MIT)

Copyright (c) 2020 artipie.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<settings>
<profiles>
<profile>
<id>artipie-proxy</id>
<repositories>
<repository>
<id>my-maven</id>
<url>https://artipie:8091/my-maven-proxy/</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artipie-proxy</activeProfile>
</activeProfiles>
</settings>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0"?>
<!--
The MIT License (MIT)

Copyright (c) 2020 artipie.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>test-maven-profile</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>Pom with dependencies</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>

<dependency>
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
<version>2.33</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.1.0</version>
</dependency>

</dependencies>
<build>
<extensions>
<extension>
<groupId>com.artipie.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http3</artifactId>
<version>LATEST</version>
</extension>
</extensions>
</build>

</project>
Loading
Loading