Skip to content

Commit

Permalink
refactoring: pull up getMavenProjectProperties
Browse files Browse the repository at this point in the history
and test it
  • Loading branch information
stefanocke committed Feb 20, 2021
1 parent 6b6d340 commit 279418c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.google.cloud.tools.jib.plugins.common.globalconfig.InvalidGlobalConfigException;
import com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.Futures;
import java.io.IOException;
import java.nio.file.Path;
Expand Down Expand Up @@ -78,14 +77,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
getSession().getSettings(), getSettingsDecrypter());

TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
MavenProjectProperties projectProperties =
MavenProjectProperties.getForProject(
Preconditions.checkNotNull(descriptor),
getProject(),
getSession(),
getLog(),
tempDirectoryProvider,
getInjectedPluginExtensions());
MavenProjectProperties projectProperties = getMavenProjectProperties(tempDirectoryProvider);

Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.google.cloud.tools.jib.plugins.common.globalconfig.InvalidGlobalConfigException;
import com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.util.concurrent.Futures;
import java.io.IOException;
Expand Down Expand Up @@ -92,14 +91,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
getSession().getSettings(), getSettingsDecrypter());

TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
MavenProjectProperties projectProperties =
MavenProjectProperties.getForProject(
Preconditions.checkNotNull(descriptor),
getProject(),
getSession(),
getLog(),
tempDirectoryProvider,
getInjectedPluginExtensions());
MavenProjectProperties projectProperties = getMavenProjectProperties(tempDirectoryProvider);

Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.google.cloud.tools.jib.plugins.common.globalconfig.InvalidGlobalConfigException;
import com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.Futures;
import java.io.IOException;
import java.util.Optional;
Expand Down Expand Up @@ -70,14 +69,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
getSession().getSettings(), getSettingsDecrypter());

TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
MavenProjectProperties projectProperties =
MavenProjectProperties.getForProject(
Preconditions.checkNotNull(descriptor),
getProject(),
getSession(),
getLog(),
tempDirectoryProvider,
getInjectedPluginExtensions());
MavenProjectProperties projectProperties = getMavenProjectProperties(tempDirectoryProvider);

Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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

import com.google.cloud.tools.jib.filesystem.TempDirectoryProvider;
import com.google.cloud.tools.jib.maven.extension.JibMavenPluginExtension;
import com.google.cloud.tools.jib.plugins.common.AuthProperty;
import com.google.cloud.tools.jib.plugins.common.ConfigurationPropertyValidator;
Expand Down Expand Up @@ -320,7 +321,7 @@ public Optional<Object> getExtraConfiguration() {

@Nullable
@Parameter(defaultValue = "${plugin}", readonly = true)
protected PluginDescriptor descriptor;
private PluginDescriptor descriptor;

@Parameter private FromConfiguration from = new FromConfiguration();

Expand Down Expand Up @@ -829,8 +830,24 @@ void setSession(MavenSession session) {
this.session = session;
}

@VisibleForTesting
void setDescriptor(PluginDescriptor descriptor) {
this.descriptor = descriptor;
}

@Nullable
String getProperty(String propertyName) {
return MavenProjectProperties.getProperty(propertyName, project, session);
}

protected MavenProjectProperties getMavenProjectProperties(
TempDirectoryProvider tempDirectoryProvider) {
return MavenProjectProperties.getForProject(
Preconditions.checkNotNull(descriptor),
getProject(),
getSession(),
getLog(),
tempDirectoryProvider,
getInjectedPluginExtensions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException;
import com.google.cloud.tools.jib.plugins.common.PluginConfigurationProcessor;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import java.io.File;
import java.nio.file.Path;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -75,14 +74,7 @@ public void execute() throws MojoExecutionException {
}

try (TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider()) {
MavenProjectProperties projectProperties =
MavenProjectProperties.getForProject(
Preconditions.checkNotNull(descriptor),
getProject(),
getSession(),
getLog(),
tempDirectoryProvider,
getInjectedPluginExtensions());
MavenProjectProperties projectProperties = getMavenProjectProperties(tempDirectoryProvider);

MavenRawConfiguration configuration = new MavenRawConfiguration(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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

import com.google.cloud.tools.jib.filesystem.TempDirectoryProvider;
import com.google.cloud.tools.jib.maven.JibPluginConfiguration.PermissionConfiguration;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All @@ -24,8 +25,10 @@
import java.nio.file.Paths;
import java.util.List;
import java.util.Properties;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Build;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.junit.Assert;
Expand All @@ -43,13 +46,16 @@ public class JibPluginConfigurationTest {
private final MavenProject project = new MavenProject();
private final Properties sessionProperties = new Properties();
@Mock private MavenSession session;
@Mock private MavenExecutionRequest mockMavenRequest;
@Mock private Log log;
@Mock private PluginDescriptor descriptor;
@Mock private Build build;
private JibPluginConfiguration testPluginConfiguration;

@Before
public void setup() {
Mockito.when(session.getSystemProperties()).thenReturn(sessionProperties);
Mockito.when(session.getRequest()).thenReturn(mockMavenRequest);
Mockito.when(build.getDirectory()).thenReturn("/test/directory");
testPluginConfiguration =
new JibPluginConfiguration() {
Expand All @@ -65,6 +71,7 @@ public Log getLog() {
project.setFile(new File("/repository/project/pom.xml")); // sets baseDir
testPluginConfiguration.setProject(project);
testPluginConfiguration.setSession(session);
testPluginConfiguration.setDescriptor(descriptor);
}

@Test
Expand Down Expand Up @@ -343,4 +350,12 @@ public void testIsContainerizable_directory() {
projectProperties.setProperty("jib.containerize", "project2");
Assert.assertFalse(testPluginConfiguration.isContainerizable());
}

@Test
public void testGetMavenProjectProperties() {
TempDirectoryProvider tdp = new TempDirectoryProvider();
MavenProjectProperties mavenProjectProperties =
testPluginConfiguration.getMavenProjectProperties(tdp);
Assert.assertNotNull(mavenProjectProperties);
}
}

0 comments on commit 279418c

Please sign in to comment.