Skip to content

Commit 9d151f5

Browse files
committed
docs: requirements file support for maven plugin
1 parent 2e03393 commit 9d151f5

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
4+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
6+
The Universal Permissive License (UPL), Version 1.0
7+
8+
Subject to the condition set forth below, permission is hereby granted to any
9+
person obtaining a copy of this software, associated documentation and/or
10+
data (collectively the "Software"), free of charge and under any and all
11+
copyright rights in the Software, and any and all patent rights owned or
12+
freely licensable by each licensor hereunder covering either (i) the
13+
unmodified Software as contributed to or provided by such licensor, or (ii)
14+
the Larger Works (as defined below), to deal in both
15+
16+
(a) the Software, and
17+
18+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
19+
one is included with the Software each a "Larger Work" to which the Software
20+
is contributed by such licensors),
21+
22+
without restriction, including without limitation the rights to copy, create
23+
derivative works of, display, perform, and distribute the Software and make,
24+
use, sell, offer for sale, import, export, have made, and have sold the
25+
Software and the Larger Work(s), and to sublicense the foregoing rights on
26+
either these or other terms.
27+
28+
This license is subject to the following condition:
29+
30+
The above copyright notice and either this complete permission notice or at a
31+
minimum a reference to the UPL must be included in all copies or substantial
32+
portions of the Software.
33+
34+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40+
SOFTWARE.
41+
-->
42+
<project xmlns="http://maven.apache.org/POM/4.0.0"
43+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
45+
<modelVersion>4.0.0</modelVersion>
46+
47+
<groupId>org.apache.maven.plugin.my.unit</groupId>
48+
<artifactId>project-prepare-venv</artifactId>
49+
<version>1.0-SNAPSHOT</version>
50+
<packaging>jar</packaging>
51+
<name>Test MyMojo</name>
52+
53+
<dependencies>
54+
<dependency>
55+
<groupId>junit</groupId>
56+
<artifactId>junit</artifactId>
57+
<version>3.8.1</version>
58+
<scope>test</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.graalvm.polyglot</groupId>
62+
<artifactId>python</artifactId>
63+
<version>${env.GRAALPY_VERSION}</version>
64+
<type>pom</type>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.graalvm.python</groupId>
68+
<artifactId>python-launcher</artifactId>
69+
<version>${env.GRAALPY_VERSION}</version>
70+
</dependency>
71+
</dependencies>
72+
73+
<build>
74+
<plugins>
75+
<plugin>
76+
<groupId>org.graalvm.python</groupId>
77+
<artifactId>graalpy-maven-plugin</artifactId>
78+
<version>${env.GRAALPY_VERSION}</version>
79+
<executions>
80+
<execution>
81+
<goals>
82+
<goal>process-graalpy-resources</goal>
83+
</goals>
84+
</execution>
85+
</executions>
86+
<configuration>
87+
<requirementsFile>requirements.txt</requirementsFile>
88+
</configuration>
89+
</plugin>
90+
</plugins>
91+
</build>
92+
</project>

integration-tests/test_maven_plugin.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,51 @@ def test_multiple_namespaced_vfs(self):
835835
assert return_code == 0, log
836836

837837

838+
def test_requirements_txt_packages(self):
839+
with util.TemporaryTestDirectory() as dir:
840+
target_name = "requirements_packages"
841+
target_dir = os.path.join(str(dir), target_name)
842+
pom_template = os.path.join(
843+
os.path.dirname(__file__),
844+
"prepare_venv_requirements_pom.xml",
845+
)
846+
self.generate_app(dir, target_dir, target_name, pom_template)
847+
848+
requirements_txt = os.path.join(target_dir, "requirements.txt")
849+
if not os.path.exists(requirements_txt):
850+
with open(requirements_txt, "w", encoding="utf-8") as f:
851+
f.write("pyfiglet==1.0.2\n")
852+
853+
mvnw_cmd = util.get_mvn_wrapper(target_dir, self.env)
854+
855+
cmd = mvnw_cmd + ["process-resources"]
856+
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
857+
util.check_ouput("BUILD SUCCESS", out)
858+
assert return_code == 0
859+
860+
cmd = mvnw_cmd + ["org.graalvm.python:graalpy-maven-plugin:lock-packages"]
861+
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
862+
863+
util.check_ouput("BUILD SUCCESS", out)
864+
assert return_code == 0
865+
866+
util.check_ouput(
867+
"In order to run the lock-packages goal there have to be python packages declared in the graalpy-maven-plugin configuration",
868+
out,
869+
contains=False,
870+
)
871+
872+
# lock-файл створився
873+
lock_file = os.path.join(target_dir, "graalpy.lock")
874+
assert os.path.exists(lock_file)
875+
876+
# 3) перевіряємо, що в lock-файлі є хоча б один пакет з requirements.txt
877+
with open(lock_file, encoding="utf-8") as f:
878+
lock_content = f.read()
879+
880+
# підстав назву пакета з requirements.txt
881+
assert "pyfiglet==" in lock_content
882+
838883
if __name__ == "__main__":
839884
run_path = os.path.join(os.path.abspath(__file__), 'run.py')
840885
print(f"Run this file using the run.py driver ({run_path})")

0 commit comments

Comments
 (0)