Introduction to Pants Build Tool (#14517)

* Introduction to Pants Build Tool

* Introduction to Pants Build Tool

* Introduction to Pants Build Tool

* Introduction to Pants Build Tool

* Introduction to Pants Build Tool
This commit is contained in:
Michael Olayemi 2023-08-09 14:35:00 +00:00 committed by GitHub
parent 4945be2fd6
commit 4b99565de3
13 changed files with 183 additions and 0 deletions

5
pants/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.idea/
.pants.d/
.pids/
dist/
pants.toml.bak

View File

@ -0,0 +1,5 @@
jvm_artifact(
group="com.google.guava",
artifact="guava",
version="18.0",
)

63
pants/3rdparty/jvm/default.lock vendored Normal file
View File

@ -0,0 +1,63 @@
# This lockfile was autogenerated by Pants. To regenerate, run:
#
# pants generate-lockfiles
#
# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
# {
# "version": 1,
# "generated_with_requirements": [
# "com.google.guava:guava:18.0,url=not_provided,jar=not_provided",
# "junit:junit:4.13.2,url=not_provided,jar=not_provided"
# ]
# }
# --- END PANTS LOCKFILE METADATA ---
[[entries]]
directDependencies = []
dependencies = []
file_name = "com.google.guava_guava_18.0.jar"
[entries.coord]
group = "com.google.guava"
artifact = "guava"
version = "18.0"
packaging = "jar"
[entries.file_digest]
fingerprint = "d664fbfc03d2e5ce9cab2a44fb01f1d0bf9dfebeccc1a473b1f9ea31f79f6f99"
serialized_bytes_length = 2256213
[[entries]]
file_name = "junit_junit_4.13.2.jar"
[[entries.directDependencies]]
group = "org.hamcrest"
artifact = "hamcrest-core"
version = "1.3"
packaging = "jar"
[[entries.dependencies]]
group = "org.hamcrest"
artifact = "hamcrest-core"
version = "1.3"
packaging = "jar"
[entries.coord]
group = "junit"
artifact = "junit"
version = "4.13.2"
packaging = "jar"
[entries.file_digest]
fingerprint = "8e495b634469d64fb8acfa3495a065cbacc8a0fff55ce1e31007be4c16dc57d3"
serialized_bytes_length = 384581
[[entries]]
directDependencies = []
dependencies = []
file_name = "org.hamcrest_hamcrest-core_1.3.jar"
[entries.coord]
group = "org.hamcrest"
artifact = "hamcrest-core"
version = "1.3"
packaging = "jar"
[entries.file_digest]
fingerprint = "66fdef91e9739348df7a096aa384a5685f4e875584cce89386a7a47251c4d8e9"
serialized_bytes_length = 45024

5
pants/3rdparty/jvm/junit/junit/BUILD vendored Normal file
View File

@ -0,0 +1,5 @@
jvm_artifact(
group="junit",
artifact="junit",
version="4.13.2"
)

7
pants/bsp-groups.toml Normal file
View File

@ -0,0 +1,7 @@
[groups.default]
addresses = [
"src/jvm::",
"tests/jvm::",
]
resolve = "jvm:jvm-default"

22
pants/pants.toml Normal file
View File

@ -0,0 +1,22 @@
[GLOBAL]
backend_packages = [
"pants.backend.experimental.java",
"pants.backend.experimental.java.lint.google_java_format"
]
pants_version = "2.16.0"
[source]
root_patterns = [
"/src/*",
"/tests/*",
]
[jvm]
jdk = 1.8
[test]
timeout_default = 60
timeout_maximum = 120
[experimental-bsp]
groups_config_files = ["bsp-groups.toml"]

View File

@ -0,0 +1,15 @@
java_sources(
dependencies=[
"src/resources/com/baeldung/hellopant:word",
],
)
deploy_jar(
name="HelloPant",
main="com.baeldung.hellopant",
dependencies=[
":hellopant",
],
)

View File

@ -0,0 +1,20 @@
package com.baeldung.hellopant;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import java.io.IOException;
import java.util.List;
public class Hello {
public static void main(String[] args) throws IOException {
System.out.println("Hello World!");
final List<String> names = Lists.newArrayList("John", null, "Jane", "Adam", "Tom");
final String result = Joiner.on(",").skipNulls().join(names);
System.out.println(result);
}
}

View File

@ -0,0 +1 @@
resources(name = "word", sources=["word.txt"])

View File

@ -0,0 +1 @@
from Us

View File

@ -0,0 +1,8 @@
junit_tests(
name="tests",
timeout=120,
dependencies=[
"src/resources/com/baeldung/hellopant:word",
],
)

View File

@ -0,0 +1,30 @@
package com.baeldung.hellopant;
import static org.junit.Assert.assertEquals;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import java.io.IOException;
import java.util.List;
import org.junit.Test;
public class GuavaUnitTest {
@Test
public void whenConvertListToStringAndSkipNull_thenConverted() {
final List<String> names = Lists.newArrayList("John", null, "Jane", "Adam", "Tom");
final String result = Joiner.on(",").skipNulls().join(names);
assertEquals(result, "John,Jane,Adam,Tom");
}
@Test
public void whenGettingTextFromAResourceFile_thenJoined() throws IOException {
String world = Resources.toString(Resources.getResource(GuavaUnitTest.class, "word.txt"), Charsets.UTF_8).strip();
String result = Joiner.on(" ").join("Hello", world);
assertEquals(result, "Hello from Us");
}
}

View File

@ -355,6 +355,7 @@
<!-- <module>guest</module> --> <!-- not to be built as its for guest articles -->
<!-- <module>lagom</module> --> <!-- Not a maven project -->
<!-- <module>pants</module> --> <!-- Not a maven project -->
<module>libraries-jdk8</module>