-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to configure skaffold data exported from jib to skaffold (#…
…2292) * Allow gradle users to configure skaffold data
- Loading branch information
1 parent
a6aa257
commit d6bcf77
Showing
29 changed files
with
746 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...e-plugin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/SkaffoldParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2020 Google LLC. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.google.cloud.tools.jib.gradle.skaffold; | ||
|
||
import com.google.common.base.Preconditions; | ||
import javax.inject.Inject; | ||
import org.gradle.api.Action; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.model.ObjectFactory; | ||
import org.gradle.api.tasks.Nested; | ||
|
||
/** Skaffold specific JibExtension parameters. */ | ||
public class SkaffoldParameters { | ||
|
||
private final SkaffoldWatchParameters watch; | ||
private final SkaffoldSyncParameters sync; | ||
|
||
@Inject | ||
public SkaffoldParameters(Project project) { | ||
ObjectFactory objectFactory = project.getObjects(); | ||
|
||
watch = objectFactory.newInstance(SkaffoldWatchParameters.class, project); | ||
sync = objectFactory.newInstance(SkaffoldSyncParameters.class, project); | ||
|
||
Preconditions.checkNotNull(watch); | ||
} | ||
|
||
public void watch(Action<? super SkaffoldWatchParameters> action) { | ||
action.execute(watch); | ||
} | ||
|
||
public void sync(Action<? super SkaffoldSyncParameters> action) { | ||
action.execute(sync); | ||
} | ||
|
||
@Nested | ||
public SkaffoldWatchParameters getWatch() { | ||
return watch; | ||
} | ||
|
||
@Nested | ||
public SkaffoldSyncParameters getSync() { | ||
return sync; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...ugin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/SkaffoldSyncParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2020 Google LLC. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.google.cloud.tools.jib.gradle.skaffold; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import javax.inject.Inject; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.tasks.Internal; | ||
|
||
/** Skaffold specific JibExtension parameters for configuring files to sync. */ | ||
public class SkaffoldSyncParameters { | ||
private final Project project; | ||
|
||
private Set<Path> excludes = Collections.emptySet(); | ||
|
||
@Inject | ||
public SkaffoldSyncParameters(Project project) { | ||
this.project = project; | ||
} | ||
|
||
/** | ||
* Get the excludes directive for sync functionality in skaffold. | ||
* | ||
* @return a set of absolute paths | ||
*/ | ||
@Internal | ||
public Set<Path> getExcludes() { | ||
return excludes; | ||
} | ||
|
||
/** | ||
* Sets excludes. {@code excludes} can be any suitable object describing file paths convertible by | ||
* {@link Project#files} (such as {@link File}, {@code List<File>}, or {@code List<String>}). | ||
* | ||
* @param paths paths to set on excludes | ||
*/ | ||
public void setExcludes(Object paths) { | ||
this.excludes = | ||
project | ||
.files(paths) | ||
.getFiles() | ||
.stream() | ||
.map(File::toPath) | ||
.map(Path::toAbsolutePath) | ||
.collect(Collectors.toSet()); | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
...gin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/SkaffoldWatchParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright 2020 Google LLC. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.google.cloud.tools.jib.gradle.skaffold; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import javax.inject.Inject; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.tasks.Internal; | ||
|
||
/** Skaffold specific JibExtension parameters for configuring files to watch. */ | ||
public class SkaffoldWatchParameters { | ||
|
||
private final Project project; | ||
|
||
private Set<Path> buildIncludes = Collections.emptySet(); | ||
private Set<Path> includes = Collections.emptySet(); | ||
private Set<Path> excludes = Collections.emptySet(); | ||
|
||
@Inject | ||
public SkaffoldWatchParameters(Project project) { | ||
this.project = project; | ||
} | ||
|
||
/** | ||
* A set of absolute paths to include with skaffold watching. | ||
* | ||
* @return a set of absolute paths | ||
*/ | ||
@Internal | ||
public Set<Path> getBuildIncludes() { | ||
return buildIncludes; | ||
} | ||
|
||
/** | ||
* Sets includes. {@code includes} can be any suitable object describing file paths convertible by | ||
* {@link Project#files} (such as {@link File}, {@code List<File>}, or {@code List<String>}). | ||
* | ||
* @param paths paths to set on includes | ||
*/ | ||
public void setBuildIncludes(Object paths) { | ||
this.buildIncludes = | ||
project | ||
.files(paths) | ||
.getFiles() | ||
.stream() | ||
.map(File::toPath) | ||
.map(Path::toAbsolutePath) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
/** | ||
* A set of absolute paths to include with skaffold watching. | ||
* | ||
* @return a set of absolute paths | ||
*/ | ||
@Internal | ||
public Set<Path> getIncludes() { | ||
return includes; | ||
} | ||
|
||
/** | ||
* Sets includes. {@code includes} can be any suitable object describing file paths convertible by | ||
* {@link Project#files} (such as {@link File}, {@code List<File>}, or {@code List<String>}). | ||
* | ||
* @param paths paths to set on includes | ||
*/ | ||
public void setIncludes(Object paths) { | ||
this.includes = | ||
project | ||
.files(paths) | ||
.getFiles() | ||
.stream() | ||
.map(File::toPath) | ||
.map(Path::toAbsolutePath) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
/** | ||
* A set of absolute paths to exclude from skaffold watching. | ||
* | ||
* @return a set of absolute paths | ||
*/ | ||
@Internal | ||
public Set<Path> getExcludes() { | ||
// Gradle warns about @Input annotations on File objects, so we have to expose a getter for a | ||
// String to make them go away. | ||
return excludes; | ||
} | ||
|
||
/** | ||
* Sets excludes. {@code excludes} can be any suitable object describing file paths convertible by | ||
* {@link Project#files} (such as {@link File}, {@code List<File>}, or {@code List<String>}). | ||
* | ||
* @param paths paths to set on excludes | ||
*/ | ||
public void setExcludes(Object paths) { | ||
this.excludes = | ||
project | ||
.files(paths) | ||
.getFiles() | ||
.stream() | ||
.map(File::toPath) | ||
.map(Path::toAbsolutePath) | ||
.collect(Collectors.toSet()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.