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

Copy essential classes into jib-build-plan #2328

Merged
merged 26 commits into from
Mar 16, 2020

Conversation

chanseokoh
Copy link
Member

@chanseokoh chanseokoh commented Mar 13, 2020

Continuing to set up the "Build Plan" project foundation for the Jib extension framework.

  • AbsoluteUnixPath
  • RelativeUnixPath
  • UnixPathParser (this ones goes into internal package from filesystem)
  • Port
  • ImageFormat
  • FilePermissions
  • FileEntry (renamed from LayerEntry)
  • FileEntriesLayer (renamed from LayerConfiguration)

LayerObject is a new one. Base class of FileEntriesLayer (and potentially ArchiveFileLayer in the future).

There are minor changes (mostly naming changes but not all). See the diff:

diff -ru jib-core/src/main/java/com/google/cloud/tools/jib/api/AbsoluteUnixPath.java jib-build-plan/src/main/java/com/google/cloud/tools/jib/buildplan/AbsoluteUnixPath.java
--- jib-core/src/main/java/com/google/cloud/tools/jib/api/AbsoluteUnixPath.java	2020-03-13 11:42:24.222021777 -0400
+++ jib-build-plan/src/main/java/com/google/cloud/tools/jib/buildplan/AbsoluteUnixPath.java	2020-03-13 11:42:30.297945936 -0400
@@ -14,9 +14,9 @@
  * the License.
  */
 
-package com.google.cloud.tools.jib.api;
+package com.google.cloud.tools.jib.buildplan;
 
-import com.google.cloud.tools.jib.filesystem.UnixPathParser;
+import com.google.cloud.tools.jib.buildplan.internal.UnixPathParser;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
diff -ru jib-core/src/main/java/com/google/cloud/tools/jib/api/FilePermissions.java jib-build-plan/src/main/java/com/google/cloud/tools/jib/buildplan/FilePermissions.java
--- jib-core/src/main/java/com/google/cloud/tools/jib/api/FilePermissions.java	2020-03-13 11:44:24.200586671 -0400
+++ jib-build-plan/src/main/java/com/google/cloud/tools/jib/buildplan/FilePermissions.java	2020-03-13 11:49:35.228995240 -0400
@@ -14,7 +14,7 @@
  * the License.
  */
 
-package com.google.cloud.tools.jib.api;
+package com.google.cloud.tools.jib.buildplan;
 
 import java.nio.file.attribute.PosixFilePermission;
 import java.util.Collections;
diff -ru jib-core/src/main/java/com/google/cloud/tools/jib/api/ImageFormat.java jib-build-plan/src/main/java/com/google/cloud/tools/jib/buildplan/ImageFormat.java
--- jib-core/src/main/java/com/google/cloud/tools/jib/api/ImageFormat.java	2020-03-13 10:42:11.506385420 -0400
+++ jib-build-plan/src/main/java/com/google/cloud/tools/jib/buildplan/ImageFormat.java	2020-03-13 11:42:30.297945936 -0400
@@ -14,7 +14,7 @@
  * the License.
  */
 
-package com.google.cloud.tools.jib.api;
+package com.google.cloud.tools.jib.buildplan;
 
 /** Indicates the format of the image. */
 public enum ImageFormat {
diff -ru jib-core/src/main/java/com/google/cloud/tools/jib/api/Port.java jib-build-plan/src/main/java/com/google/cloud/tools/jib/buildplan/Port.java
--- jib-core/src/main/java/com/google/cloud/tools/jib/api/Port.java	2020-03-13 11:42:24.222021777 -0400
+++ jib-build-plan/src/main/java/com/google/cloud/tools/jib/buildplan/Port.java	2020-03-13 11:42:30.297945936 -0400
@@ -14,7 +14,7 @@
  * the License.
  */
 
-package com.google.cloud.tools.jib.api;
+package com.google.cloud.tools.jib.buildplan;
 
 import java.util.Objects;
 import javax.annotation.concurrent.Immutable;
diff -ru jib-core/src/main/java/com/google/cloud/tools/jib/api/RelativeUnixPath.java jib-build-plan/src/main/java/com/google/cloud/tools/jib/buildplan/RelativeUnixPath.java
--- jib-core/src/main/java/com/google/cloud/tools/jib/api/RelativeUnixPath.java	2020-03-13 11:42:24.222021777 -0400
+++ jib-build-plan/src/main/java/com/google/cloud/tools/jib/buildplan/RelativeUnixPath.java	2020-03-13 11:42:30.297945936 -0400
@@ -14,9 +14,9 @@
  * the License.
  */
 
-package com.google.cloud.tools.jib.api;
+package com.google.cloud.tools.jib.buildplan;
 
-import com.google.cloud.tools.jib.filesystem.UnixPathParser;
+import com.google.cloud.tools.jib.buildplan.internal.UnixPathParser;
 import java.util.ArrayList;
 import java.util.List;
 import javax.annotation.concurrent.Immutable;
--- jib-core/src/main/java/com/google/cloud/tools/jib/api/LayerEntry.java	2020-03-13 11:42:24.222021777 -0400
+++ jib-build-plan/src/main/java/com/google/cloud/tools/jib/buildplan/FileEntry.java	2020-03-13 11:42:30.297945936 -0400
@@ -14,7 +14,7 @@
  * the License.
  */
 
-package com.google.cloud.tools.jib.api;
+package com.google.cloud.tools.jib.buildplan;
 
 import java.nio.file.Path;
 import java.time.Instant;
@@ -28,7 +28,7 @@
  * <p>This class is immutable and thread-safe.
  */
 @Immutable
-public class LayerEntry {
+public class FileEntry {
 
   private final Path sourceFile;
   private final AbsoluteUnixPath extractionPath;
@@ -39,11 +39,11 @@
    * Instantiates with a source file and the path to place the source file in the container file
    * system.
    *
-   * <p>For example, {@code new LayerEntry(Paths.get("HelloWorld.class"),
+   * <p>For example, {@code new FileEntry(Paths.get("HelloWorld.class"),
    * AbsoluteUnixPath.get("/app/classes/HelloWorld.class"))} adds a file {@code HelloWorld.class} to
    * the container file system at {@code /app/classes/HelloWorld.class}.
    *
-   * <p>For example, {@code new LayerEntry(Paths.get("com"),
+   * <p>For example, {@code new FileEntry(Paths.get("com"),
    * AbsoluteUnixPath.get("/app/classes/com"))} adds a directory to the container file system at
    * {@code /app/classes/com}. This does <b>not</b> add the contents of {@code com/}.
    *
@@ -52,7 +52,7 @@
    * <ul>
    *   <li>Entry source files can be either files or directories.
    *   <li>Adding a directory does not include the contents of the directory. Each file under a
-   *       directory must be added as a separate {@link LayerEntry}.
+   *       directory must be added as a separate {@link FileEntry}.
    * </ul>
    *
    * @param sourceFile the source file to add to the layer
@@ -61,7 +61,7 @@
    * @param permissions the file permissions on the container
    * @param modificationTime the file modification time
    */
-  public LayerEntry(
+  public FileEntry(
       Path sourceFile,
       AbsoluteUnixPath extractionPath,
       FilePermissions permissions,
@@ -115,14 +115,14 @@
     if (this == other) {
       return true;
     }
-    if (!(other instanceof LayerEntry)) {
+    if (!(other instanceof FileEntry)) {
       return false;
     }
-    LayerEntry otherLayerEntry = (LayerEntry) other;
-    return sourceFile.equals(otherLayerEntry.sourceFile)
-        && extractionPath.equals(otherLayerEntry.extractionPath)
-        && Objects.equals(permissions, otherLayerEntry.permissions)
-        && Objects.equals(modificationTime, otherLayerEntry.modificationTime);
+    FileEntry otherFileEntry = (FileEntry) other;
+    return sourceFile.equals(otherFileEntry.sourceFile)
+        && extractionPath.equals(otherFileEntry.extractionPath)
+        && Objects.equals(permissions, otherFileEntry.permissions)
+        && Objects.equals(modificationTime, otherFileEntry.modificationTime);
   }
 
   @Override
--- jib-core/src/main/java/com/google/cloud/tools/jib/api/LayerConfiguration.java	2020-03-13 11:42:33.145910387 -0400
+++ jib-build-plan/src/main/java/com/google/cloud/tools/jib/buildplan/FileEntriesLayer.java	2020-03-13 11:48:49.389524443 -0400
@@ -14,9 +14,8 @@
  * the License.
  */
 
-package com.google.cloud.tools.jib.api;
+package com.google.cloud.tools.jib.buildplan;
 
-import com.google.common.collect.ImmutableList;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -30,13 +29,13 @@
 
 /** Configures how to build a layer in the container image. Instantiate with {@link #builder}. */
 @Immutable
-public class LayerConfiguration {
+public class FileEntriesLayer extends LayerObject {
 
-  /** Builds a {@link LayerConfiguration}. */
+  /** Builds a {@link FileEntriesLayer}. */
   public static class Builder {
 
     private String name = "";
-    private List<LayerEntry> entries = new ArrayList<>();
+    private List<FileEntry> entries = new ArrayList<>();
 
     private Builder() {}
 
@@ -57,7 +56,7 @@
      * @param entries file entries in the layer
      * @return this
      */
-    public Builder setEntries(List<LayerEntry> entries) {
+    public Builder setEntries(List<FileEntry> entries) {
       this.entries = new ArrayList<>(entries);
       return this;
     }
@@ -68,7 +67,7 @@
      * @param entry the layer entry to add
      * @return this
      */
-    public Builder addEntry(LayerEntry entry) {
+    public Builder addEntry(FileEntry entry) {
       entries.add(entry);
       return this;
     }
@@ -158,7 +157,7 @@
         AbsoluteUnixPath pathInContainer,
         FilePermissions permissions,
         Instant modificationTime) {
-      return addEntry(new LayerEntry(sourceFile, pathInContainer, permissions, modificationTime));
+      return addEntry(new FileEntry(sourceFile, pathInContainer, permissions, modificationTime));
     }
 
     /**
@@ -241,12 +240,12 @@
     }
 
     /**
-     * Returns the built {@link LayerConfiguration}.
+     * Returns the built {@link FileEntriesLayer}.
      *
-     * @return the built {@link LayerConfiguration}
+     * @return the built {@link FileEntriesLayer}
      */
-    public LayerConfiguration build() {
-      return new LayerConfiguration(name, entries);
+    public FileEntriesLayer build() {
+      return new FileEntriesLayer(name, entries);
     }
   }
 
@@ -267,7 +266,7 @@
           (sourcePath, destinationPath) -> DEFAULT_MODIFICATION_TIME;
 
   /**
-   * Gets a new {@link Builder} for {@link LayerConfiguration}.
+   * Gets a new {@link Builder} for {@link FileEntriesLayer}.
    *
    * @return a new {@link Builder}
    */
@@ -276,15 +275,16 @@
   }
 
   private final String name;
-  private final List<LayerEntry> entries;
+  private final List<FileEntry> entries;
 
   /**
    * Use {@link #builder} to instantiate.
    *
    * @param name an optional name for the layer
-   * @param entries the list of {@link LayerEntry}s
+   * @param entries the list of {@link FileEntry}s
    */
-  private LayerConfiguration(String name, List<LayerEntry> entries) {
+  private FileEntriesLayer(String name, List<FileEntry> entries) {
+    super(LayerObject.Type.FILE_ENTRIES);
     this.name = name;
     this.entries = entries;
   }
@@ -303,8 +303,8 @@
    *
    * @return the list of entries
    */
-  public ImmutableList<LayerEntry> getLayerEntries() {
-    return ImmutableList.copyOf(entries);
+  public List<FileEntry> getEntries() {
+    return new ArrayList<>(entries);
   }
 
   public Builder toBuilder() {
diff -ru jib-core/src/main/java/com/google/cloud/tools/jib/filesystem/UnixPathParser.java jib-build-plan/src/main/java/com/google/cloud/tools/jib/buildplan/internal/UnixPathParser.java
--- jib-core/src/main/java/com/google/cloud/tools/jib/filesystem/UnixPathParser.java	2020-03-13 11:42:24.222021777 -0400
+++ jib-build-plan/src/main/java/com/google/cloud/tools/jib/buildplan/internal/UnixPathParser.java	2020-03-13 11:42:30.297945936 -0400
@@ -14,7 +14,7 @@
  * the License.
  */
 
-package com.google.cloud.tools.jib.filesystem;
+package com.google.cloud.tools.jib.buildplan.internal;
 
 import java.util.ArrayList;
 import java.util.List;

@loosebazooka
Copy link
Member

loosebazooka commented Mar 13, 2020

Looks fine, but I wonder: how does this affect existing jib-core users?

@chanseokoh
Copy link
Member Author

chanseokoh commented Mar 13, 2020

This PR doesn't change anything in jib-core, so nothing. In the future, however, I imagine corresponding classes in jib-core will become a proxy, passing through arguments into these classes in jib-build-plan. Even then, I don't think we'll change the jib-core surface (although we'll mark them deprecated and encourage jib-core users to use the classes in jib-build-plan).

Does this make sense? Any other thoughts?

Copy link
Member

@loosebazooka loosebazooka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you're copying classes... right.

@chanseokoh
Copy link
Member Author

Merging this now. I'll move the classes to a different package .api.buildplan (in the same jib-build-plan subproject) in the next PR. Also, I'll just have jib-core use these classes directory as discussed (i.e., breaking changes in jib-core).

@chanseokoh chanseokoh merged commit 907c51c into master Mar 16, 2020
@chanseokoh chanseokoh deleted the plugin-extension-1-diff-inc branch March 16, 2020 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants