-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Update maven extraDirectory config parameter to include path and permissions field #1195
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be useful to support globs?
<permissions>
<permission>
<file>/*.txrt</file>
<mode>755</mode>
</permission>
<permission>
<file>/**.sh</file>
<mode>555</mode>
</permission>
</permissions>
Path getExtraDirectoryPath() { | ||
// TODO: Should inform user about nonexistent directory if using custom directory. | ||
if (System.getProperty(PropertyNames.EXTRA_DIRECTORY_PATH) != null) { | ||
return Paths.get(System.getProperty(PropertyNames.EXTRA_DIRECTORY_PATH)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should check the Maven settings and pom properties too to keep with the semantics of Maven's @Parameter(property)
values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a trivial change? It sounds like something we may want to do for all of the parameters, so maybe it should wait until another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Speaking of which, I think supporting globs would be a good idea, but I think that should wait until another PR as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/JibPluginConfiguration.java
Show resolved
Hide resolved
jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/JibPluginConfiguration.java
Show resolved
Hide resolved
this.mode = mode; | ||
} | ||
|
||
@Nullable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's start using Optional
over @Nullable
returns for all new code
// this parameter is cloned in FilesMojo | ||
@Nullable | ||
@Parameter( | ||
defaultValue = "${project.basedir}/src/main/jib", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have this default on ExtraDirectoryParameters
rather than resolved via PluginConfigurationProcessor#getExtraDirectoryPath
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I tried this I had trouble getting it to work in the nested class, but I've adjusted a lot since then so maybe I can try again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, so the issue I have here is, it seems @Parameter(defaultValue = "...")
doesn't work in nested classes, and I can't set the value on the same line as the variable declaration because I need project
to get the base directory, which is out of scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, would passing project.basedir/src/main/jib
in via a constructor work? And call new ExtraDirectoryParameters(project.basedir/src/main/jib)
(not right syntax) on line 266.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, since Maven requires/uses a default constructor. I'll try it though.
Edit: Yeah not looking promising.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that was just for objects that Maven has to create (like objects in a list), but extraDirectory
we are just constructing that explicitly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the looks of it, project
is still null
at the time we explicitly construct extraDirectory
.
MavenProject project, Path extraDirectory, AbsoluteUnixPath appRoot) throws IOException { | ||
MavenProject project, | ||
Path extraDirectory, | ||
Map<AbsoluteUnixPath, FilePermissions> permissions, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should name this extraDirectoryPermissions
or something similar since they only apply to the extra files.
@@ -122,7 +142,7 @@ private static JavaLayerConfigurations getForWarProject( | |||
Paths.get(project.getBuild().getDirectory()).resolve(project.getBuild().getFinalName()); | |||
// TODO: Replace Collections.emptyMap() with configured permissions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the comment.
@VisibleForTesting | ||
static Map<AbsoluteUnixPath, FilePermissions> convertPermissionsMap( | ||
Map<String, String> inputMap) { | ||
ImmutableMap.Builder<AbsoluteUnixPath, FilePermissions> permissionsMap = ImmutableMap.builder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we can just return a HashMap
. I see no need to prevent callers from modifying the returned map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yea, and for cases where we were to return ImmutableMap
, we should be making the return type be ImmutableMap
.
@VisibleForTesting | ||
static Map<AbsoluteUnixPath, FilePermissions> convertPermissionsList( | ||
List<PermissionConfiguration> inputList) { | ||
ImmutableMap.Builder<AbsoluteUnixPath, FilePermissions> permissionsMap = ImmutableMap.builder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, HashMap
?
return jibPluginConfiguration | ||
.getExtraDirectoryPath() | ||
.orElseGet( | ||
() -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think orElse(Preconditions...)
will work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some small nits
@@ -202,12 +202,12 @@ static FileCollection getInputFiles(File extraDirectory, Project project) { | |||
@VisibleForTesting | |||
static Map<AbsoluteUnixPath, FilePermissions> convertPermissionsMap( | |||
Map<String, String> inputMap) { | |||
ImmutableMap.Builder<AbsoluteUnixPath, FilePermissions> permissionsMap = ImmutableMap.builder(); | |||
HashMap<AbsoluteUnixPath, FilePermissions> permissionsMap = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nit: prefer Map
for type
* Validates and converts a {@code String->String} file-path-to-file-permissions map to an | ||
* equivalent {@code AbsoluteUnixPath->FilePermission} map. | ||
* | ||
* @param inputMap the map to convert |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: inputMap
should probably be more descriptive - might be good to even include an example of an entry in this map.
public static class PermissionConfiguration { | ||
|
||
@Nullable @Parameter private String file; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nit: don't need to separate these with newline
jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/JibPluginConfiguration.java
Show resolved
Hide resolved
// this parameter is cloned in FilesMojo | ||
@Nullable | ||
@Parameter( | ||
defaultValue = "${project.basedir}/src/main/jib", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that was just for objects that Maven has to create (like objects in a list), but extraDirectory
we are just constructing that explicitly?
* Validates and converts a list of {@link PermissionConfiguration} to an equivalent {@code | ||
* AbsoluteUnixPath->FilePermission} map. | ||
* | ||
* @param inputList the list to convert |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto the variable naming nit
@VisibleForTesting | ||
static Map<AbsoluteUnixPath, FilePermissions> convertPermissionsList( | ||
List<PermissionConfiguration> inputList) { | ||
HashMap<AbsoluteUnixPath, FilePermissions> permissionsMap = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto type nit
Fixes #794.
Adds/changes the
<extraDirectory>
configuration:<extraDirectory>${project.basedir}/path/to/extra/directory</extraDirectory>
<extraDirector><path>
and<extraDirectory><permissions>
fieldse.g.