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

Deprecate <extraDirectory> config in Maven #1626

Merged
merged 35 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a9d24ed
Allow specifying multiple extra directories
chanseokoh Apr 3, 2019
da5d56d
Fix compilation error
chanseokoh Apr 3, 2019
790e16a
Fix bugs and tests
chanseokoh Apr 3, 2019
f42c6c7
Fix bug
chanseokoh Apr 3, 2019
688e171
Add integration test
chanseokoh Apr 4, 2019
dac967c
Allow specifying multiple extra directories
chanseokoh Apr 4, 2019
b4bd674
Implement correct list input parameter in Maven
chanseokoh Apr 5, 2019
43d04dd
Fix tests
chanseokoh Apr 5, 2019
2c72778
Fix mishanlding of <extraDirectory><path> in Maven
chanseokoh Apr 5, 2019
1227cb2
Fix bug in _skaffold-files-v2 goal
chanseokoh Apr 5, 2019
3723799
Fix test
chanseokoh Apr 5, 2019
f4527e8
Renmae methods
chanseokoh Apr 5, 2019
7544622
Merge branch 'master' into i1020-extra-directories-1
chanseokoh Apr 5, 2019
b5dc356
Fix Gradle
chanseokoh Apr 5, 2019
1615d18
Merge branch 'master' into i1020-extra-directories-1
chanseokoh Apr 10, 2019
d6f6a63
Add tests
chanseokoh Apr 10, 2019
a0d2271
Use StringBuilder
chanseokoh Apr 10, 2019
c5c8bb8
Remove debug code
chanseokoh Apr 12, 2019
abbba03
Feedback
chanseokoh Apr 12, 2019
a1196a8
Deprecate <extraDirectory> in Maven
chanseokoh Apr 12, 2019
d02f668
Refactor
chanseokoh Apr 12, 2019
4e69a49
More changes
chanseokoh Apr 15, 2019
85f7039
wip
chanseokoh Apr 16, 2019
eb7f5fb
Merge branch 'master' into i1020-extra-directories-rename
chanseokoh Apr 16, 2019
60fc1ee
Merge branch 'master' into i1020-extra-directories-rename
chanseokoh Apr 17, 2019
072a947
No warn internal MojoFiles V1; fail build if both specified in MojoFi…
chanseokoh Apr 17, 2019
e18ebde
Check new property in FilesMojoV2 / fail build if both used / no warning
chanseokoh Apr 17, 2019
a4422f8
Fail build if both old and new configs are used
chanseokoh Apr 17, 2019
90b8b4d
Update comment
chanseokoh Apr 17, 2019
8a04576
Update error messages
chanseokoh Apr 18, 2019
94827ac
Merge remote-tracking branch 'origin/master' into i1020-extra-directo…
chanseokoh Apr 23, 2019
e769a74
Handle properties correctly in FilesMojoV2
chanseokoh Apr 23, 2019
771128a
Merge branch 'master' into i1020-extra-directories-rename
chanseokoh Apr 23, 2019
c24673e
Add more tests
chanseokoh Apr 24, 2019
ebe29ab
Add tests
chanseokoh Apr 24, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public ToAuthConfiguration() {
}
}

/** Used to configure {@code extraDirectory.permissions} parameter. */
/** Used to configure {@code extraDirectories.permissions} parameter. */
public static class PermissionConfiguration {

@Nullable @Parameter private String file;
Expand Down Expand Up @@ -183,29 +183,38 @@ public static class ContainerParameters {
@Nullable @Parameter private String workingDirectory;
}

/** Configuration for the {@code extraDirectories} parameter. */
public static class ExtraDirectoriesParameters {

@Parameter private List<File> paths = Collections.emptyList();

@Parameter private List<PermissionConfiguration> permissions = Collections.emptyList();

public List<File> getPaths() {
return paths;
}
}

/** Configuration for the {@code extraDirectory} parameter. */
@Deprecated
public static class ExtraDirectoryParameters {

// retained for backward-compatibility for <extraDirectory><path>...<path></extraDirectory>
@Deprecated @Nullable @Parameter private File path;

@Parameter private List<File> paths = Collections.emptyList();

@Parameter private List<PermissionConfiguration> permissions = Collections.emptyList();
@Deprecated @Parameter
private List<PermissionConfiguration> permissions = Collections.emptyList();

/**
* Allows users to configure {@code path} using just {@code <extraDirectory>} instead of {@code
* <extraDirectory><path>}.
*
* @param path the value to set {@code path} to
*/
// Allows users to configure a single path using just <extraDirectory> instead of
// <extraDirectory><path>.
@Deprecated
public void set(File path) {
this.paths = Collections.singletonList(path);
this.path = path;
}

@Deprecated
public List<File> getPaths() {
return path != null ? Collections.singletonList(path) : paths;
return path == null ? Collections.emptyList() : Collections.singletonList(path);
}
}

Expand All @@ -224,7 +233,11 @@ public List<File> getPaths() {
@Parameter private ContainerParameters container = new ContainerParameters();

// this parameter is cloned in FilesMojo
@Parameter private ExtraDirectoryParameters extraDirectory = new ExtraDirectoryParameters();
@Deprecated @Parameter
private ExtraDirectoryParameters extraDirectory = new ExtraDirectoryParameters();

// this parameter is cloned in FilesMojo
@Parameter private ExtraDirectoriesParameters extraDirectories = new ExtraDirectoriesParameters();

@Parameter(
defaultValue = "false",
Expand Down Expand Up @@ -512,12 +525,38 @@ String getFormat() {
*/
List<Path> getExtraDirectories() {
// TODO: Should inform user about nonexistent directory if using custom directory.
String property = getProperty(PropertyNames.EXTRA_DIRECTORY_PATH);
String deprecatedProperty = getProperty(PropertyNames.EXTRA_DIRECTORY_PATH);
String newProperty = getProperty(PropertyNames.EXTRA_DIRECTORIES_PATHS);

List<File> deprecatedPaths = extraDirectory.getPaths();
List<File> newPaths = extraDirectories.getPaths();

if (deprecatedProperty != null) {
getLog()
.warn(
"The property 'jib.extraDirectory.path' is deprecated; "
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved
+ "use 'jib.extraDirectories.paths' instead");
}
if (!deprecatedPaths.isEmpty()) {
loosebazooka marked this conversation as resolved.
Show resolved Hide resolved
getLog().warn("<extraDirectory> is deprecated; use <extraDirectories> with <paths><path>");
}
if (deprecatedProperty != null && newProperty != null) {
throw new IllegalArgumentException(
"You cannot configure both 'jib.extraDirectory.path' and 'jib.extraDirectories.paths'");
}
if (!deprecatedPaths.isEmpty() && !newPaths.isEmpty()) {
throw new IllegalArgumentException(
"You cannot configure both <extraDirectory> and <extraDirectories>");
}

String property = newProperty != null ? newProperty : deprecatedProperty;
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved
if (property != null) {
List<String> paths = ConfigurationPropertyValidator.parseListProperty(property);
return paths.stream().map(Paths::get).collect(Collectors.toList());
}
return extraDirectory.getPaths().stream().map(File::toPath).collect(Collectors.toList());

List<File> paths = !newPaths.isEmpty() ? newPaths : deprecatedPaths;
return paths.stream().map(File::toPath).collect(Collectors.toList());
}

/**
Expand All @@ -526,15 +565,40 @@ List<Path> getExtraDirectories() {
* @return the configured extra layer file permissions
*/
List<PermissionConfiguration> getExtraDirectoryPermissions() {
String property = getProperty(PropertyNames.EXTRA_DIRECTORY_PERMISSIONS);
String deprecatedProperty = getProperty(PropertyNames.EXTRA_DIRECTORY_PERMISSIONS);
String newProperty = getProperty(PropertyNames.EXTRA_DIRECTORIES_PERMISSIONS);

List<PermissionConfiguration> deprecatedPermissions = extraDirectory.permissions;
List<PermissionConfiguration> newPermissions = extraDirectories.permissions;

if (deprecatedProperty != null) {
getLog()
.warn(
"The property 'jib.extraDirectory.permissions' is deprecated; "
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved
+ "use 'jib.extraDirectories.permissions' instead");
}
if (deprecatedProperty != null && newProperty != null) {
throw new IllegalArgumentException(
"You cannot configure both 'jib.extraDirectory.permissions' and "
+ "'jib.extraDirectories.permissions'");
}
if (!deprecatedPermissions.isEmpty() && !newPermissions.isEmpty()) {
throw new IllegalArgumentException(
"You cannot configure both <extraDirectory> and <extraDirectories>");
}

String property = newProperty != null ? newProperty : deprecatedProperty;
if (property != null) {
return ConfigurationPropertyValidator.parseMapProperty(property)
.entrySet()
.stream()
.map(entry -> new PermissionConfiguration(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
}
return extraDirectory.permissions;

return !extraDirectories.getPaths().isEmpty()
? extraDirectories.permissions
: extraDirectory.permissions;
}

boolean getAllowInsecureRegistries() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@

package com.google.cloud.tools.jib.maven.skaffold;

import com.google.cloud.tools.jib.maven.JibPluginConfiguration.ExtraDirectoriesParameters;
import com.google.cloud.tools.jib.maven.JibPluginConfiguration.ExtraDirectoryParameters;
import com.google.cloud.tools.jib.maven.MavenProjectProperties;
import com.google.cloud.tools.jib.plugins.common.ConfigurationPropertyValidator;
import com.google.cloud.tools.jib.plugins.common.PropertyNames;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
Expand All @@ -44,6 +47,7 @@
import org.apache.maven.project.DependencyResolutionResult;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectDependenciesResolver;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.graph.DependencyFilter;

/**
Expand Down Expand Up @@ -78,7 +82,11 @@ public class FilesMojo extends AbstractMojo {
@Nullable @Component private ProjectDependenciesResolver projectDependenciesResolver;

// This parameter is cloned from JibPluginConfiguration
@Parameter private ExtraDirectoryParameters extraDirectory = new ExtraDirectoryParameters();
@Deprecated @Parameter
private ExtraDirectoryParameters extraDirectory = new ExtraDirectoryParameters();

// This parameter is cloned from JibPluginConfiguration
@Parameter private ExtraDirectoriesParameters extraDirectories = new ExtraDirectoriesParameters();

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Expand Down Expand Up @@ -143,7 +151,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
resolutionResult
.getDependencies()
.stream()
.map(org.eclipse.aether.graph.Dependency::getArtifact)
.map(Dependency::getArtifact)
.filter(org.eclipse.aether.artifact.Artifact::isSnapshot)
.map(org.eclipse.aether.artifact.Artifact::getFile)
.forEach(System.out::println);
Expand All @@ -153,8 +161,32 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

private List<Path> resolveExtraDirectories() {
List<File> paths = extraDirectory.getPaths();
private List<Path> resolveExtraDirectories() throws MojoExecutionException {
// TODO: Should inform user about nonexistent directory if using custom directory.
String deprecatedProperty =
MavenProjectProperties.getProperty(PropertyNames.EXTRA_DIRECTORY_PATH, project, session);
String newProperty =
MavenProjectProperties.getProperty(PropertyNames.EXTRA_DIRECTORIES_PATHS, project, session);

List<File> deprecatedPaths = extraDirectory.getPaths();
List<File> newPaths = extraDirectories.getPaths();

if (deprecatedProperty != null && newProperty != null) {
throw new MojoExecutionException(
"You cannot configure both 'jib.extraDirectory.path' and 'jib.extraDirectories.paths'");
}
if (!deprecatedPaths.isEmpty() && !newPaths.isEmpty()) {
throw new MojoExecutionException(
"You cannot configure both <extraDirectory> and <extraDirectories>");
}

String property = newProperty != null ? newProperty : deprecatedProperty;
if (property != null) {
List<String> paths = ConfigurationPropertyValidator.parseListProperty(property);
return paths.stream().map(Paths::get).map(Path::toAbsolutePath).collect(Collectors.toList());
}

List<File> paths = !newPaths.isEmpty() ? newPaths : deprecatedPaths;
if (paths.isEmpty()) {
Path projectBase =
Preconditions.checkNotNull(project).getBasedir().getAbsoluteFile().toPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.tools.jib.maven.skaffold;

import com.google.cloud.tools.jib.maven.MavenProjectProperties;
import com.google.cloud.tools.jib.plugins.common.ConfigurationPropertyValidator;
import com.google.cloud.tools.jib.plugins.common.PropertyNames;
import com.google.cloud.tools.jib.plugins.common.SkaffoldFilesOutput;
import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -167,34 +168,54 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

private List<Path> resolveExtraDirectories(MavenProject project) {
private List<Path> resolveExtraDirectories(MavenProject project) throws MojoExecutionException {
// Try getting extra directory from project/session properties
String extraDirectoryProperty =
String deprecatedProperty =
MavenProjectProperties.getProperty(PropertyNames.EXTRA_DIRECTORY_PATH, project, session);
if (extraDirectoryProperty != null) {
return Collections.singletonList(Paths.get(extraDirectoryProperty));
String newProperty =
MavenProjectProperties.getProperty(PropertyNames.EXTRA_DIRECTORIES_PATHS, project, session);

if (deprecatedProperty != null && newProperty != null) {
throw new MojoExecutionException(
"You cannot configure both 'jib.extraDirectory.path' and 'jib.extraDirectories.paths'");
}

String property = newProperty != null ? newProperty : deprecatedProperty;
if (property != null) {
List<String> paths = ConfigurationPropertyValidator.parseListProperty(property);
return paths.stream().map(Paths::get).collect(Collectors.toList());
}

// Try getting extra directory from project pom
Plugin jibMavenPlugin = project.getPlugin(MavenProjectProperties.PLUGIN_KEY);
if (jibMavenPlugin != null) {
Xpp3Dom pluginConfiguration = (Xpp3Dom) jibMavenPlugin.getConfiguration();
if (pluginConfiguration != null) {

Xpp3Dom extraDirectoryConfiguration = pluginConfiguration.getChild("extraDirectory");
if (extraDirectoryConfiguration != null) {
Xpp3Dom pathChild = extraDirectoryConfiguration.getChild("path");
if (pathChild != null) {
// <extraDirectory><path>...</path></extraDirectory>
return Collections.singletonList(Paths.get(pathChild.getValue()));
}
Xpp3Dom pathsChild = extraDirectoryConfiguration.getChild("paths");
if (pathsChild != null) {
// <extraDirectory><paths><path>...<path><path>...<path></paths></extraDirectory>
return Arrays.stream(pathsChild.getChildren())
Xpp3Dom extraDirectoriesConfiguration = pluginConfiguration.getChild("extraDirectories");
if (extraDirectoryConfiguration != null && extraDirectoriesConfiguration != null) {
throw new MojoExecutionException(
"You cannot configure both <extraDirectory> and <extraDirectories>");
}

if (extraDirectoriesConfiguration != null) {
Xpp3Dom child = extraDirectoriesConfiguration.getChild("paths");
if (child != null) {
// <extraDirectories><paths><path>...</path><path>...</path></paths></extraDirectories>
return Arrays.stream(child.getChildren())
.map(Xpp3Dom::getValue)
.map(Paths::get)
.collect(Collectors.toList());
}
}

if (extraDirectoryConfiguration != null) {
Xpp3Dom child = extraDirectoryConfiguration.getChild("path");
if (child != null) {
// <extraDirectory><path>...</path></extraDirectory>
return Collections.singletonList(Paths.get(child.getValue()));
}
// <extraDirectory>...</extraDirectory>
String value = extraDirectoryConfiguration.getValue();
if (value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ public void testSystemProperties() {
sessionProperties.put("jib.container.workingDirectory", "working directory");
Assert.assertEquals("working directory", testPluginConfiguration.getWorkingDirectory());

sessionProperties.put("jib.extraDirectory.path", "custom-jib");
sessionProperties.put("jib.extraDirectories.paths", "custom-jib");
Assert.assertEquals(
Arrays.asList(Paths.get("custom-jib")), testPluginConfiguration.getExtraDirectories());
sessionProperties.put("jib.extraDirectory.permissions", "/test/file1=123,/another/file=456");
sessionProperties.put("jib.extraDirectories.permissions", "/test/file1=123,/another/file=456");
List<PermissionConfiguration> permissions =
testPluginConfiguration.getExtraDirectoryPermissions();
Assert.assertEquals("/test/file1", permissions.get(0).getFile().get());
Expand Down Expand Up @@ -173,12 +173,12 @@ public void testPomProperties() {
project.getProperties().setProperty("jib.container.workingDirectory", "working directory");
Assert.assertEquals("working directory", testPluginConfiguration.getWorkingDirectory());

project.getProperties().setProperty("jib.extraDirectory.path", "custom-jib");
project.getProperties().setProperty("jib.extraDirectories.paths", "custom-jib");
Assert.assertEquals(
Arrays.asList(Paths.get("custom-jib")), testPluginConfiguration.getExtraDirectories());
project
.getProperties()
.setProperty("jib.extraDirectory.permissions", "/test/file1=123,/another/file=456");
.setProperty("jib.extraDirectories.permissions", "/test/file1=123,/another/file=456");
List<PermissionConfiguration> permissions =
testPluginConfiguration.getExtraDirectoryPermissions();
Assert.assertEquals("/test/file1", permissions.get(0).getFile().get());
Expand All @@ -200,4 +200,36 @@ public void testEmptyOrNullTags() {
Assert.assertEquals("jib.to.tags has empty tag", ex.getMessage());
}
}

@Test
public void testDeprecatedSystemProperties() {
sessionProperties.put("jib.extraDirectory.path", "custom-jib");
Assert.assertEquals(
Arrays.asList(Paths.get("custom-jib")), testPluginConfiguration.getExtraDirectories());
sessionProperties.put("jib.extraDirectory.permissions", "/test/file13=650,/another/file24=777");
List<PermissionConfiguration> permissions =
testPluginConfiguration.getExtraDirectoryPermissions();
Assert.assertEquals("/test/file13", permissions.get(0).getFile().get());
Assert.assertEquals("650", permissions.get(0).getMode().get());
Assert.assertEquals("/another/file24", permissions.get(1).getFile().get());
Assert.assertEquals("777", permissions.get(1).getMode().get());
}

@Test
public void testDeprecatedProperties() {
Properties projectProperties = project.getProperties();

projectProperties.setProperty("jib.extraDirectory.path", "this-is-extra");
Assert.assertEquals(
Arrays.asList(Paths.get("this-is-extra")), testPluginConfiguration.getExtraDirectories());

projectProperties.setProperty(
"jib.extraDirectory.permissions", "/test/file1=654,/dir/file2=321");
List<PermissionConfiguration> permissions =
testPluginConfiguration.getExtraDirectoryPermissions();
Assert.assertEquals("/test/file1", permissions.get(0).getFile().get());
Assert.assertEquals("654", permissions.get(0).getMode().get());
Assert.assertEquals("/dir/file2", permissions.get(1).getFile().get());
Assert.assertEquals("321", permissions.get(1).getMode().get());
}
}
Loading