Skip to content

Commit

Permalink
Consolidate ImageFormat enum definitions (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
TadCordle authored Jun 6, 2018
1 parent 5d7588c commit c478c21
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2018 Google LLC. all rights reserved.
*
* 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.image;

import com.google.cloud.tools.jib.image.json.BuildableManifestTemplate;
import com.google.cloud.tools.jib.image.json.OCIManifestTemplate;
import com.google.cloud.tools.jib.image.json.V22ManifestTemplate;

/** Enumeration of {@link BuildableManifestTemplate}s. */
public enum ImageFormat {
Docker(V22ManifestTemplate.class),
OCI(OCIManifestTemplate.class);

private final Class<? extends BuildableManifestTemplate> manifestTemplateClass;

ImageFormat(Class<? extends BuildableManifestTemplate> manifestTemplateClass) {
this.manifestTemplateClass = manifestTemplateClass;
}

public Class<? extends BuildableManifestTemplate> getManifestTemplateClass() {
return manifestTemplateClass;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

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

import com.google.cloud.tools.jib.image.ImageFormat;
import com.google.cloud.tools.jib.image.json.BuildableManifestTemplate;
import com.google.cloud.tools.jib.image.json.OCIManifestTemplate;
import com.google.cloud.tools.jib.image.json.V22ManifestTemplate;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -58,24 +56,6 @@
*/
public class JibExtension {

// TODO: Consolidate with BuildImageMojo#ImageFormat.
/** Enumeration of {@link BuildableManifestTemplate}s. */
@VisibleForTesting
enum ImageFormat {
Docker(V22ManifestTemplate.class),
OCI(OCIManifestTemplate.class);

private final Class<? extends BuildableManifestTemplate> manifestTemplateClass;

ImageFormat(Class<? extends BuildableManifestTemplate> manifestTemplateClass) {
this.manifestTemplateClass = manifestTemplateClass;
}

private Class<? extends BuildableManifestTemplate> getManifestTemplateClass() {
return manifestTemplateClass;
}
}

// Defines default configuration values.
private static final String DEFAULT_FROM_IMAGE = "gcr.io/distroless/java";
private static final List<String> DEFAULT_JVM_FLAGS = Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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

import com.google.cloud.tools.jib.image.ImageFormat;
import com.google.cloud.tools.jib.image.json.OCIManifestTemplate;
import com.google.cloud.tools.jib.image.json.V22ManifestTemplate;
import java.util.Arrays;
Expand Down Expand Up @@ -110,7 +111,7 @@ public void testArgs() {
public void testFormat() {
Assert.assertEquals(V22ManifestTemplate.class, testJibExtension.getFormat());

testJibExtension.setFormat(JibExtension.ImageFormat.OCI);
testJibExtension.setFormat(ImageFormat.OCI);
Assert.assertEquals(OCIManifestTemplate.class, testJibExtension.getFormat());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
import com.google.cloud.tools.jib.frontend.BuildStepsRunner;
import com.google.cloud.tools.jib.frontend.CacheDirectoryCreationException;
import com.google.cloud.tools.jib.frontend.HelpfulSuggestions;
import com.google.cloud.tools.jib.image.ImageFormat;
import com.google.cloud.tools.jib.image.ImageReference;
import com.google.cloud.tools.jib.image.json.BuildableManifestTemplate;
import com.google.cloud.tools.jib.image.json.OCIManifestTemplate;
import com.google.cloud.tools.jib.image.json.V22ManifestTemplate;
import com.google.cloud.tools.jib.registry.RegistryClient;
import com.google.cloud.tools.jib.registry.credentials.RegistryCredentials;
import com.google.common.annotations.VisibleForTesting;
Expand All @@ -45,22 +43,6 @@ public class BuildImageMojo extends JibPluginConfiguration {

@VisibleForTesting static final String GOAL_NAME = "build";

/** Enumeration of {@link BuildableManifestTemplate}s. */
public enum ImageFormat {
Docker(V22ManifestTemplate.class),
OCI(OCIManifestTemplate.class);

private final Class<? extends BuildableManifestTemplate> manifestTemplateClass;

ImageFormat(Class<? extends BuildableManifestTemplate> manifestTemplateClass) {
this.manifestTemplateClass = manifestTemplateClass;
}

private Class<? extends BuildableManifestTemplate> getManifestTemplateClass() {
return manifestTemplateClass;
}
}

/** {@code User-Agent} header suffix to send to the registry. */
private static final String USER_AGENT_SUFFIX = "jib-maven-plugin";

Expand Down

0 comments on commit c478c21

Please sign in to comment.