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

Update maven extraDirectory config parameter to include path and permissions field #1195

Merged
merged 12 commits into from
Oct 29, 2018

Conversation

TadCordle
Copy link
Contributor

@TadCordle TadCordle commented Oct 25, 2018

Fixes #794.

Adds/changes the <extraDirectory> configuration:

  • Can still configure extra directory using <extraDirectory>${project.basedir}/path/to/extra/directory</extraDirectory>
  • Can also configure the extra directory/permissions using new <extraDirector><path> and <extraDirectory><permissions> fields

e.g.

<configuration>
  ...
  <extraDirectory>
    <path>${project.basedir}/src/main/jib-custom</path>
    <permissions>
      <permission>
        <file>/foo</file>
        <mode>755</mode>
      </permission>
      <permission>
        <file>/bar/cat</file>
        <mode>777</mode>
      </permission>
    </permissions>
  </extraDirectory>
</configuration>

Copy link
Member

@briandealwis briandealwis left a 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));
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed #1200 and #1201 for these 2 comments.

this.mode = mode;
}

@Nullable
Copy link
Contributor

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",
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@TadCordle TadCordle Oct 29, 2018

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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,
Copy link
Contributor

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
Copy link
Member

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();
Copy link
Member

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.

Copy link
Contributor

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();
Copy link
Member

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(
() ->
Copy link
Member

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.

Copy link
Contributor

@coollog coollog left a 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<>();
Copy link
Contributor

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
Copy link
Contributor

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;

Copy link
Contributor

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

// this parameter is cloned in FilesMojo
@Nullable
@Parameter(
defaultValue = "${project.basedir}/src/main/jib",
Copy link
Contributor

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
Copy link
Contributor

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<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto type nit

@TadCordle TadCordle merged commit 0174a49 into master Oct 29, 2018
@TadCordle TadCordle deleted the file-permissions-maven branch October 29, 2018 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants