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

Add environment hook for CLASSPATH #27

Merged
merged 1 commit into from
Jul 9, 2021
Merged
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
16 changes: 16 additions & 0 deletions colcon_gradle/task/gradle/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
from distutils import dir_util
import glob
import os
from pathlib import Path
import shutil

from colcon_core.environment import create_environment_scripts
from colcon_core.logging import colcon_logger
from colcon_core.plugin_system import satisfies_version
from colcon_core.shell import create_environment_hook
from colcon_core.shell import get_command_environment
from colcon_core.task import run
from colcon_core.task import TaskExtensionPoint
Expand Down Expand Up @@ -62,6 +64,20 @@ async def build( # noqa: D102
logger.info(
"Building Gradle package in '{args.path}'".format_map(locals()))

if additional_hooks is None:
additional_hooks = []

# add jars and classes to CLASSPATH with wildcards
# https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html#A1100762
additional_hooks += create_environment_hook(
'classpath_jars', Path(args.install_base), pkg.name,
'CLASSPATH', os.path.join('share', pkg.name, 'java', '*'),
mode='prepend')
additional_hooks += create_environment_hook(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we also need the directory?
I think that the wildcard is enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the the docs, I'm lead to believe we need both the path and the wildcard to account for class files AND jars:

A class path entry that contains an asterisk () does not match class files. To match both classes and JAR files in a single directory mydir, use either mydir:mydir/ or mydir/*:mydir. The order chosen determines whether the classes and resources in mydir are loaded before JAR files in mydir or vice versa.

'classpath_classes', Path(args.install_base), pkg.name,
'CLASSPATH', os.path.join('share', pkg.name, 'java'),
mode='prepend')

try:
env = await get_command_environment(
'build', args.build_base, self.context.dependencies)
Expand Down