Skip to content

Commit

Permalink
Additional cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Clayton Walker committed Jan 23, 2024
1 parent ae60d85 commit 7276c95
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,10 @@ public void apply(Project project) {
task.setDescription("Builds a container image to a tarball.");
});

tasks
.register(SKAFFOLD_FILES_TASK_V2_NAME, FilesTaskV2.class)
.configure(task -> task.setJibExtension(jibExtension));
tasks
.register(SKAFFOLD_INIT_TASK_NAME, InitTask.class)
.configure(task -> task.setJibExtension(jibExtension));
tasks.register(SKAFFOLD_FILES_TASK_V2_NAME, FilesTaskV2.class, jibExtension);
tasks.register(SKAFFOLD_INIT_TASK_NAME, InitTask.class, jibExtension);
TaskProvider<SyncMapTask> syncMapTask =
tasks.register(
SKAFFOLD_SYNC_MAP_TASK_NAME,
SyncMapTask.class,
task -> task.setJibExtension(jibExtension));
tasks.register(SKAFFOLD_SYNC_MAP_TASK_NAME, SyncMapTask.class, jibExtension);

// A check to catch older versions of Jib. This can be removed once we are certain people
// are using Jib 1.3.1 or later.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.google.cloud.tools.jib.gradle.ExtraDirectoryParameters;
import com.google.cloud.tools.jib.gradle.JibExtension;
import com.google.cloud.tools.jib.plugins.common.SkaffoldFilesOutput;
import com.google.common.base.Preconditions;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -30,7 +29,7 @@
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import javax.inject.Inject;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
Expand All @@ -52,11 +51,11 @@ public class FilesTaskV2 extends DefaultTask {

private final SkaffoldFilesOutput skaffoldFilesOutput = new SkaffoldFilesOutput();

@Nullable private JibExtension jibExtension;
private final JibExtension jibExtension;

public FilesTaskV2 setJibExtension(JibExtension jibExtension) {
@Inject
public FilesTaskV2(JibExtension jibExtension) {
this.jibExtension = jibExtension;
return this;
}

/**
Expand All @@ -66,7 +65,6 @@ public FilesTaskV2 setJibExtension(JibExtension jibExtension) {
*/
@TaskAction
public void listFiles() throws IOException {
Preconditions.checkNotNull(jibExtension);
Project project = getProject();

// If this is not the root project, add the root project's build.gradle and settings.gradle
Expand Down Expand Up @@ -187,8 +185,6 @@ private void addProjectFiles(Project project) {
* @return the set of project dependencies
*/
private Set<ProjectDependency> findProjectDependencies(Project project) {
Preconditions.checkNotNull(jibExtension);

Set<ProjectDependency> projectDependencies = new HashSet<>();
Deque<Project> projects = new ArrayDeque<>();
projects.push(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

import com.google.cloud.tools.jib.gradle.JibExtension;
import com.google.cloud.tools.jib.plugins.common.SkaffoldInitOutput;
import com.google.common.base.Preconditions;
import java.io.IOException;
import javax.annotation.Nullable;
import javax.inject.Inject;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.tasks.TaskAction;
Expand All @@ -32,11 +31,11 @@
*/
public class InitTask extends DefaultTask {

@Nullable private JibExtension jibExtension;
private final JibExtension jibExtension;

public InitTask setJibExtension(JibExtension jibExtension) {
@Inject
public InitTask(JibExtension jibExtension) {
this.jibExtension = jibExtension;
return this;
}

/**
Expand All @@ -52,7 +51,7 @@ public void listModulesAndTargets() throws IOException {
return;
}
SkaffoldInitOutput skaffoldInitOutput = new SkaffoldInitOutput();
skaffoldInitOutput.setImage(Preconditions.checkNotNull(jibExtension).getTo().getImage());
skaffoldInitOutput.setImage(jibExtension.getTo().getImage());
if (!project.equals(project.getRootProject())) {
skaffoldInitOutput.setProject(project.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import com.google.cloud.tools.jib.plugins.common.ContainerizingMode;
import com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException;
import com.google.cloud.tools.jib.plugins.common.PluginConfigurationProcessor;
import com.google.common.base.Preconditions;
import javax.annotation.Nullable;
import javax.inject.Inject;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.tasks.TaskAction;
Expand All @@ -37,18 +36,16 @@
*/
public class SyncMapTask extends DefaultTask {

@Nullable private JibExtension jibExtension;
private final JibExtension jibExtension;

public SyncMapTask setJibExtension(JibExtension jibExtension) {
@Inject
public SyncMapTask(JibExtension jibExtension) {
this.jibExtension = jibExtension;
return this;
}

/** Task Action, lists files and container targets. */
@TaskAction
public void listFilesAndTargets() {
Preconditions.checkNotNull(jibExtension);

try (TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider()) {
GradleProjectProperties projectProperties =
GradleProjectProperties.getForProject(
Expand Down

0 comments on commit 7276c95

Please sign in to comment.