Skip to content

Commit

Permalink
Change PortWithProtocol to PortsWithProtocol (GoogleContainerTools#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
TadCordle authored Jul 3, 2018
1 parent 926b491 commit cbee411
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 56 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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.configuration;

import com.google.common.base.Preconditions;

/** Holds port number and protocol for an exposed port. */
public class PortsWithProtocol {

/** Represents the protocol portion of the port. */
public enum Protocol {
TCP("tcp"),
UDP("udp");

private final String stringRepresentation;

Protocol(String stringRepresentation) {
this.stringRepresentation = stringRepresentation;
}

@Override
public String toString() {
return stringRepresentation;
}
}

/**
* Creates a new {@link PortsWithProtocol} with the specified range and protocol.
*
* @param minPort the minimum port number
* @param maxPort the maximum port number
* @param protocol the protocol
* @return the {@link PortsWithProtocol}
*/
public static PortsWithProtocol forRange(int minPort, int maxPort, Protocol protocol) {
Preconditions.checkArgument(
minPort <= maxPort, "minPort must be less than or equal to maxPort in port range");
return new PortsWithProtocol(minPort, maxPort, protocol);
}

/**
* Creates a new {@link PortsWithProtocol} with the port number and protocol.
*
* @param port the port number
* @param protocol the protocol
* @return the {@link PortsWithProtocol}
*/
public static PortsWithProtocol forSingle(int port, Protocol protocol) {
return new PortsWithProtocol(port, port, protocol);
}

private final int minPort;
private final int maxPort;
private final Protocol protocol;

public int getMinPort() {
return minPort;
}

public int getMaxPort() {
return maxPort;
}

public Protocol getProtocol() {
return protocol;
}

private PortsWithProtocol(int minPort, int maxPort, Protocol protocol) {
this.minPort = minPort;
this.maxPort = maxPort;
this.protocol = protocol;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.google.cloud.tools.jib.frontend;

import com.google.cloud.tools.jib.builder.BuildLogger;
import com.google.cloud.tools.jib.configuration.PortWithProtocol;
import com.google.cloud.tools.jib.configuration.PortsWithProtocol;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
Expand All @@ -35,7 +35,7 @@ public class ExposedPortsParser {
private static final Pattern portPattern = Pattern.compile("(\\d+)(?:-(\\d+))?(/tcp|/udp)?");

/**
* TODO: Return list of {@link PortWithProtocol}s instead of strings
* TODO: Return list of {@link PortsWithProtocol}s instead of strings
*
* <p>Converts/validates a list of ports with ranges to an expanded form without ranges.
*
Expand Down

0 comments on commit cbee411

Please sign in to comment.