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

Remove deprecated extraDirectory config #2108

Merged
merged 4 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ In Maven, you can use the `maven-resources-plugin` to copy files to your extra d
<artifact>jib-maven-plugin</artifact>
...
<configuration>
<extraDirectory>${project.basedir}/target/extra-directory/</extraDirectory>
<extraDirectories>
<paths>
<path>${project.basedir}/target/extra-directory/</path>
</paths>
</extraDirectories>
</configuration>
</plugin>
...
Expand Down Expand Up @@ -331,7 +335,7 @@ mvn compile resources:copy-resources jib:build
The same can be accomplished in Gradle by using a `Copy` task. In your `build.gradle`:

```groovy
jib.extraDirectory = file('build/extra-directory')
jib.extraDirectories = file('build/extra-directory')

task setupExtraDir(type: Copy) {
from file('build/generated/files')
Expand Down
2 changes: 2 additions & 0 deletions jib-gradle-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ All notable changes to this project will be documented in this file.

### Changed

- Removed deprecated `jib.extraDirectory` configuration in favor of `jib.extraDirectories`. ([#1691](https://github.com/GoogleContainerTools/jib/issues/1691))

### Fixed

## 1.8.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,6 @@ static String readDigestFile(Path digestPath) throws IOException, DigestExceptio
return DescriptorDigest.fromDigest(digest).toString();
}

private static void assertExtraDirectoryDeprecationWarning(String buildFile)
throws DigestException, IOException, InterruptedException {
String targetImage = "localhost:6000/simpleimage:gradle" + System.nanoTime();
BuildResult buildResult =
JibRunHelper.buildToDockerDaemon(simpleTestProject, targetImage, buildFile);
Assert.assertEquals(
"Hello, world. \n1970-01-01T00:00:01Z\nrw-r--r--\nrw-r--r--\nfoo\ncat\n"
+ "1970-01-01T00:00:01Z\n1970-01-01T00:00:01Z\n",
new Command("docker", "run", "--rm", targetImage).run());
Assert.assertThat(
buildResult.getOutput(),
CoreMatchers.containsString(
"'jib.extraDirectory', 'jib.extraDirectory.path', and 'jib.extraDirectory.permissions' "
+ "are deprecated; use 'jib.extraDirectories.paths' and "
+ "'jib.extraDirectories.permissions'"));
}

private static String buildAndRunComplex(
String imageReference, String username, String password, LocalRegistry targetRegistry)
throws IOException, InterruptedException {
Expand Down Expand Up @@ -318,24 +301,6 @@ public void testDockerDaemon_simpleWithIncompatibleJava11()
}
}

@Test
public void testDockerDaemon_simple_deprecatedExtraDirectory()
throws DigestException, IOException, InterruptedException {
assertExtraDirectoryDeprecationWarning("build-extra-dir-deprecated.gradle");
}

@Test
public void testDockerDaemon_simple_deprecatedExtraDirectory2()
throws DigestException, IOException, InterruptedException {
assertExtraDirectoryDeprecationWarning("build-extra-dir-deprecated2.gradle");
}

@Test
public void testDockerDaemon_simple_deprecatedExtraDirectory3()
throws DigestException, IOException, InterruptedException {
assertExtraDirectoryDeprecationWarning("build-extra-dir-deprecated3.gradle");
}

@Test
public void testDockerDaemon_simple_multipleExtraDirectories()
throws DigestException, IOException, InterruptedException {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@
public class ExtraDirectoriesParameters {

private final Project project;
@Deprecated private final JibExtension jibExtension;

private List<Path> paths;
private Map<String, String> permissions = Collections.emptyMap();

@Inject
public ExtraDirectoriesParameters(Project project, JibExtension jibExtension) {
public ExtraDirectoriesParameters(Project project) {
this.project = project;
this.jibExtension = jibExtension;
paths =
Collections.singletonList(
project.getProjectDir().toPath().resolve("src").resolve("main").resolve("jib"));
Expand All @@ -59,9 +57,7 @@ public List<String> getPathStrings() {
public List<Path> getPaths() {
// Gradle warns about @Input annotations on File objects, so we have to expose a getter for a
// String to make them go away.
String deprecatedProperty = System.getProperty(PropertyNames.EXTRA_DIRECTORY_PATH);
String newProperty = System.getProperty(PropertyNames.EXTRA_DIRECTORIES_PATHS);
String property = newProperty != null ? newProperty : deprecatedProperty;
String property = System.getProperty(PropertyNames.EXTRA_DIRECTORIES_PATHS);
if (property != null) {
List<String> pathStrings = ConfigurationPropertyValidator.parseListProperty(property);
return pathStrings.stream().map(Paths::get).collect(Collectors.toList());
Expand All @@ -76,17 +72,10 @@ public List<Path> getPaths() {
* @param paths paths to set.
*/
public void setPaths(Object paths) {
jibExtension.extraDirectoriesConfigured = true;
this.paths =
project.files(paths).getFiles().stream().map(File::toPath).collect(Collectors.toList());
}

@Deprecated
public void setPath(File path) {
jibExtension.extraDirectoryConfigured = true;
this.paths = Collections.singletonList(path.toPath());
}

/**
* Gets the permissions for files in the extra layer on the container. Maps from absolute path on
* the container to a 3-digit octal string representation of the file permission bits (e.g. {@code
Expand All @@ -96,9 +85,7 @@ public void setPath(File path) {
*/
@Input
public Map<String, String> getPermissions() {
String deprecatedProperty = System.getProperty(PropertyNames.EXTRA_DIRECTORY_PERMISSIONS);
String newProperty = System.getProperty(PropertyNames.EXTRA_DIRECTORIES_PERMISSIONS);
String property = newProperty != null ? newProperty : deprecatedProperty;
String property = System.getProperty(PropertyNames.EXTRA_DIRECTORIES_PERMISSIONS);
if (property != null) {
return ConfigurationPropertyValidator.parseMapProperty(property);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.google.cloud.tools.jib.gradle;

import com.google.cloud.tools.jib.plugins.common.PropertyNames;
import java.io.File;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.model.ObjectFactory;
Expand Down Expand Up @@ -81,16 +80,13 @@ public class JibExtension {
private final Property<Boolean> allowInsecureRegistries;
private final Property<String> containerizingMode;

@Deprecated boolean extraDirectoryConfigured;
@Deprecated boolean extraDirectoriesConfigured;

public JibExtension(Project project) {
ObjectFactory objectFactory = project.getObjects();

from = objectFactory.newInstance(BaseImageParameters.class);
to = objectFactory.newInstance(TargetImageParameters.class);
container = objectFactory.newInstance(ContainerParameters.class);
extraDirectories = objectFactory.newInstance(ExtraDirectoriesParameters.class, project, this);
extraDirectories = objectFactory.newInstance(ExtraDirectoriesParameters.class, project);
dockerClient = objectFactory.newInstance(DockerClientParameters.class);
outputPaths = objectFactory.newInstance(OutputPathsParameters.class, project);

Expand All @@ -114,14 +110,7 @@ public void container(Action<? super ContainerParameters> action) {
action.execute(container);
}

@Deprecated
public void extraDirectory(Action<? super ExtraDirectoriesParameters> action) {
extraDirectoryConfigured = true;
action.execute(extraDirectories);
}

public void extraDirectories(Action<? super ExtraDirectoriesParameters> action) {
extraDirectoriesConfigured = true;
action.execute(extraDirectories);
}

Expand All @@ -133,13 +122,6 @@ public void outputPaths(Action<? super OutputPathsParameters> action) {
action.execute(outputPaths);
}

@Deprecated
// for the deprecated "jib.extraDirectory" config parameter
public void setExtraDirectory(File extraDirectory) {
extraDirectoryConfigured = true;
extraDirectories.setPath(extraDirectory);
}

public void setAllowInsecureRegistries(boolean allowInsecureRegistries) {
this.allowInsecureRegistries.set(allowInsecureRegistries);
}
Expand All @@ -166,13 +148,6 @@ public ContainerParameters getContainer() {
return container;
}

@Deprecated
@Nested
@Optional
public ExtraDirectoriesParameters getExtraDirectory() {
return extraDirectories;
}

@Nested
@Optional
public ExtraDirectoriesParameters getExtraDirectories() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.google.api.client.http.HttpTransport;
import com.google.cloud.tools.jib.api.AbsoluteUnixPath;
import com.google.cloud.tools.jib.api.FilePermissions;
import com.google.cloud.tools.jib.plugins.common.PropertyNames;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
Expand Down Expand Up @@ -77,22 +76,6 @@ static void disableHttpLogging() {

@Deprecated
static void checkDeprecatedUsage(JibExtension jibExtension, Logger logger) {
if (jibExtension.extraDirectoryConfigured
|| System.getProperty(PropertyNames.EXTRA_DIRECTORY_PATH) != null
|| System.getProperty(PropertyNames.EXTRA_DIRECTORY_PERMISSIONS) != null) {
logger.warn(
"'jib.extraDirectory', 'jib.extraDirectory.path', and 'jib.extraDirectory.permissions' "
+ "are deprecated; use 'jib.extraDirectories.paths' and "
+ "'jib.extraDirectories.permissions'");

if (jibExtension.extraDirectoriesConfigured
|| System.getProperty(PropertyNames.EXTRA_DIRECTORIES_PATHS) != null
|| System.getProperty(PropertyNames.EXTRA_DIRECTORIES_PERMISSIONS) != null) {
throw new IllegalArgumentException(
"You cannot configure both 'jib.extraDirectory.path' and 'jib.extraDirectories.paths'");
}
}

if (jibExtension.getContainer().getUseCurrentTimestamp()) {
if (!jibExtension.getContainer().getCreationTime().equals("EPOCH")) {
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,33 +147,13 @@ public void testExtraDirectories_default() {
Collections.emptyMap(), testJibExtension.getExtraDirectories().getPermissions());
}

@Test
public void testExtraDirectories_deprecatedConfig() {
testJibExtension.extraDirectory(
extraDirectory -> {
extraDirectory.setPath(Paths.get("test", "path").toFile());
extraDirectory.setPermissions(ImmutableMap.of("file1", "123", "file2", "456"));
});
Assert.assertTrue(testJibExtension.extraDirectoryConfigured);
Assert.assertFalse(testJibExtension.extraDirectoriesConfigured);

Assert.assertEquals(
Arrays.asList(Paths.get("test", "path")),
testJibExtension.getExtraDirectories().getPaths());
Assert.assertEquals(
ImmutableMap.of("file1", "123", "file2", "456"),
testJibExtension.getExtraDirectories().getPermissions());
}

@Test
public void testExtraDirectories() {
testJibExtension.extraDirectories(
extraDirectories -> {
extraDirectories.setPaths("test/path");
extraDirectories.setPermissions(ImmutableMap.of("file1", "123", "file2", "456"));
});
Assert.assertFalse(testJibExtension.extraDirectoryConfigured);
Assert.assertTrue(testJibExtension.extraDirectoriesConfigured);

Assert.assertEquals(
Arrays.asList(Paths.get(fakeProject.getProjectDir().getPath(), "test", "path")),
Expand Down Expand Up @@ -357,16 +337,4 @@ public void testProperties() {
fakeProject.getProjectDir().toPath().resolve(Paths.get("tar/path")),
testJibExtension.getOutputPaths().getTarPath());
}

@Test
public void testDeprecatedProperties() {
System.setProperty("jib.extraDirectory.path", "/foo,/bar/baz");
Assert.assertEquals(
Arrays.asList(Paths.get("/foo"), Paths.get("/bar/baz")),
testJibExtension.getExtraDirectories().getPaths());
System.setProperty("jib.extraDirectory.permissions", "/foo/bar=707,/baz=456");
Assert.assertEquals(
ImmutableMap.of("/foo/bar", "707", "/baz", "456"),
testJibExtension.getExtraDirectories().getPermissions());
}
}
Loading