// Path: src/main/java/com/edorasware/one/initializr/util/Version.java
// public static class Qualifier implements Serializable {
// 
// 	public Qualifier(String qualifier) {
// 		this.qualifier = qualifier;
// 	}
// 
// 	private String qualifier;
// 	private Integer version;
// 
// 	public String getQualifier() {
// 		return qualifier;
// 	}
// 
// 	public void setQualifier(String qualifier) {
// 		this.qualifier = qualifier;
// 	}
// 
// 	public Integer getVersion() {
// 		return version;
// 	}
// 
// 	public void setVersion(Integer version) {
// 		this.version = version;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return "Qualifier ["
// 				+ (qualifier != null ? "qualifier=" + qualifier + ", " : "")
// 				+ (version != null ? "version=" + version : "") + "]";
// 	}
// 
// 	@Override
// 	public int hashCode() {
// 		final int prime = 31;
// 		int result = 1;
// 		result = prime * result + ((qualifier == null) ? 0 : qualifier.hashCode());
// 		result = prime * result + ((version == null) ? 0 : version.hashCode());
// 		return result;
// 	}
// 
// 	@Override
// 	public boolean equals(Object obj) {
// 		if (this == obj)
// 			return true;
// 		if (obj == null)
// 			return false;
// 		if (getClass() != obj.getClass())
// 			return false;
// 		Qualifier other = (Qualifier) obj;
// 		if (qualifier == null) {
// 			if (other.qualifier != null)
// 				return false;
// 		}
// 		else if (!qualifier.equals(other.qualifier))
// 			return false;
// 		if (version == null) {
// 			if (other.version != null)
// 				return false;
// 		}
// 		else if (!version.equals(other.version))
// 			return false;
// 		return true;
// 	}
// }


import com.edorasware.one.initializr.util.Version.Qualifier;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/*
 * Copyright 2012-2017 the original author or authors.
 *
 * 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.edorasware.one.initializr.util;



/**
 * Parser for {@link Version} and {@link VersionRange} that allows to resolve the minor
 * and patch value against a configurable list of "latest versions".
 * <p>
 * For example a parser that is configured with {@code 1.3.7.RELEASE} and
 * {@code 1.4.2.RELEASE} as latest versions can parse {@code 1.3.x.RELEASE} to
 * {@code 1.3.7.RELEASE}. Note that the qualifier is important here:
 * {@code 1.3.8.BUILD-SNAPSHOT} would be parsed as {@code 1.3.999.BUILD-SNAPSHOT} as the
 * parser doesn't know the latest {@code BUILD-SNAPSHOT} in the {@code 1.3.x} release
 * line.
 *
 * @author Stephane Nicoll
 */
public class VersionParser {

	public static final VersionParser DEFAULT = new VersionParser(Collections.emptyList());

	private static final Pattern VERSION_REGEX =
			Pattern.compile("^(\\d+)\\.(\\d+|x)\\.(\\d+|x)(?:-([^0-9]+)(\\d+)?(-\\d+)?(-SNAPSHOT)?)?$");

	private static final Pattern RANGE_REGEX =
			Pattern.compile("(\\(|\\[)(.*),(.*)(\\)|\\])");

	private final List<Version> latestVersions;

	public VersionParser(List<Version> latestVersions) {
		this.latestVersions = latestVersions;
	}

	/**
	 * Parse the string representation of a {@link Version}. Throws an
	 * {@link InvalidVersionException} if the version could not be parsed.
	 * @param text the version text
	 * @return a Version instance for the specified version text
	 * @throws InvalidVersionException if the version text could not be parsed
	 * @see #safeParse(String)
	 */
	public Version parse(String text) {
		Assert.notNull(text, "Text must not be null");
		Matcher matcher = VERSION_REGEX.matcher(text.trim());
		if (!matcher.matches()) {
			throw new InvalidVersionException("Could not determine version based on '"
					+ text + "': version format " + "is Minor.Major.Patch-Qualifier-StarterVersion-StarterQualifier "
					+ "(e.g. 2.0.0-M6-1-SNAPSHOT)");
		}
		Integer major = Integer.valueOf(matcher.group(1));
		String minor = matcher.group(2);
		String patch = matcher.group(3);
// Path: src/main/java/com/edorasware/one/initializr/util/Version.java
// public static class Qualifier implements Serializable {
// 
// 	public Qualifier(String qualifier) {
// 		this.qualifier = qualifier;
// 	}
// 
// 	private String qualifier;
// 	private Integer version;
// 
// 	public String getQualifier() {
// 		return qualifier;
// 	}
// 
// 	public void setQualifier(String qualifier) {
// 		this.qualifier = qualifier;
// 	}
// 
// 	public Integer getVersion() {
// 		return version;
// 	}
// 
// 	public void setVersion(Integer version) {
// 		this.version = version;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return "Qualifier ["
// 				+ (qualifier != null ? "qualifier=" + qualifier + ", " : "")
// 				+ (version != null ? "version=" + version : "") + "]";
// 	}
// 
// 	@Override
// 	public int hashCode() {
// 		final int prime = 31;
// 		int result = 1;
// 		result = prime * result + ((qualifier == null) ? 0 : qualifier.hashCode());
// 		result = prime * result + ((version == null) ? 0 : version.hashCode());
// 		return result;
// 	}
// 
// 	@Override
// 	public boolean equals(Object obj) {
// 		if (this == obj)
// 			return true;
// 		if (obj == null)
// 			return false;
// 		if (getClass() != obj.getClass())
// 			return false;
// 		Qualifier other = (Qualifier) obj;
// 		if (qualifier == null) {
// 			if (other.qualifier != null)
// 				return false;
// 		}
// 		else if (!qualifier.equals(other.qualifier))
// 			return false;
// 		if (version == null) {
// 			if (other.version != null)
// 				return false;
// 		}
// 		else if (!version.equals(other.version))
// 			return false;
// 		return true;
// 	}
// }


// Path: src/main/java/com/edorasware/one/initializr/util/VersionParser.java
import com.edorasware.one.initializr.util.Version.Qualifier;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/*
 * Copyright 2012-2017 the original author or authors.
 *
 * 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.edorasware.one.initializr.util;



/**
 * Parser for {@link Version} and {@link VersionRange} that allows to resolve the minor
 * and patch value against a configurable list of "latest versions".
 * <p>
 * For example a parser that is configured with {@code 1.3.7.RELEASE} and
 * {@code 1.4.2.RELEASE} as latest versions can parse {@code 1.3.x.RELEASE} to
 * {@code 1.3.7.RELEASE}. Note that the qualifier is important here:
 * {@code 1.3.8.BUILD-SNAPSHOT} would be parsed as {@code 1.3.999.BUILD-SNAPSHOT} as the
 * parser doesn't know the latest {@code BUILD-SNAPSHOT} in the {@code 1.3.x} release
 * line.
 *
 * @author Stephane Nicoll
 */
public class VersionParser {

	public static final VersionParser DEFAULT = new VersionParser(Collections.emptyList());

	private static final Pattern VERSION_REGEX =
			Pattern.compile("^(\\d+)\\.(\\d+|x)\\.(\\d+|x)(?:-([^0-9]+)(\\d+)?(-\\d+)?(-SNAPSHOT)?)?$");

	private static final Pattern RANGE_REGEX =
			Pattern.compile("(\\(|\\[)(.*),(.*)(\\)|\\])");

	private final List<Version> latestVersions;

	public VersionParser(List<Version> latestVersions) {
		this.latestVersions = latestVersions;
	}

	/**
	 * Parse the string representation of a {@link Version}. Throws an
	 * {@link InvalidVersionException} if the version could not be parsed.
	 * @param text the version text
	 * @return a Version instance for the specified version text
	 * @throws InvalidVersionException if the version text could not be parsed
	 * @see #safeParse(String)
	 */
	public Version parse(String text) {
		Assert.notNull(text, "Text must not be null");
		Matcher matcher = VERSION_REGEX.matcher(text.trim());
		if (!matcher.matches()) {
			throw new InvalidVersionException("Could not determine version based on '"
					+ text + "': version format " + "is Minor.Major.Patch-Qualifier-StarterVersion-StarterQualifier "
					+ "(e.g. 2.0.0-M6-1-SNAPSHOT)");
		}
		Integer major = Integer.valueOf(matcher.group(1));
		String minor = matcher.group(2);
		String patch = matcher.group(3);
		Qualifier qualifier = null;