From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id DAF8D138334 for ; Sun, 3 Nov 2019 11:26:58 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id AB7CBE08AD; Sun, 3 Nov 2019 11:26:57 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 82F9DE08AD for ; Sun, 3 Nov 2019 11:26:57 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5975034C78A for ; Sun, 3 Nov 2019 11:26:56 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 784878A4 for ; Sun, 3 Nov 2019 11:26:53 +0000 (UTC) From: "Miroslav Šulc" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Miroslav Šulc" Message-ID: <1572780367.af344112881d635949535ba6a5fc9e11ad284dc5.fordfrog@gentoo> Subject: [gentoo-commits] proj/java-ebuilder:master commit in: src/main/java/org/gentoo/java/ebuilder/maven/ X-VCS-Repository: proj/java-ebuilder X-VCS-Files: src/main/java/org/gentoo/java/ebuilder/maven/JavaVersion.java src/main/java/org/gentoo/java/ebuilder/maven/MavenParser.java src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java X-VCS-Directories: src/main/java/org/gentoo/java/ebuilder/maven/ X-VCS-Committer: fordfrog X-VCS-Committer-Name: Miroslav Šulc X-VCS-Revision: af344112881d635949535ba6a5fc9e11ad284dc5 X-VCS-Branch: master Date: Sun, 3 Nov 2019 11:26:53 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: c65de822-9721-4045-ab4b-2befbc8aeb08 X-Archives-Hash: 80074bbd38d15acd4580f193458d3be1 commit: af344112881d635949535ba6a5fc9e11ad284dc5 Author: Miroslav Šulc gentoo org> AuthorDate: Sun Nov 3 11:26:07 2019 +0000 Commit: Miroslav Šulc gentoo org> CommitDate: Sun Nov 3 11:26:07 2019 +0000 URL: https://gitweb.gentoo.org/proj/java-ebuilder.git/commit/?id=af344112 encapsulated java version in new container Signed-off-by: Miroslav Šulc gentoo.org> .../gentoo/java/ebuilder/maven/JavaVersion.java | 87 ++++++++++++++++++++++ .../gentoo/java/ebuilder/maven/MavenParser.java | 10 ++- .../gentoo/java/ebuilder/maven/MavenProject.java | 12 +-- 3 files changed, 99 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/gentoo/java/ebuilder/maven/JavaVersion.java b/src/main/java/org/gentoo/java/ebuilder/maven/JavaVersion.java new file mode 100644 index 0000000..5aa600d --- /dev/null +++ b/src/main/java/org/gentoo/java/ebuilder/maven/JavaVersion.java @@ -0,0 +1,87 @@ +package org.gentoo.java.ebuilder.maven; + +import java.text.MessageFormat; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Java versionNumber container. + * + * @author fordfrog + */ +public class JavaVersion { + + /** + * Pattern for parsing Java versionNumber. + */ + private static final Pattern PATTERN_VERSION + = Pattern.compile("^(?:1\\.)(\\d+)$"); + /** + * Java versionNumber number. + */ + private final int versionNumber; + /** + * Java version string. + */ + private final String versionString; + + /** + * Creates new instance of JavaVersion. Parses the version string and uses + * the main Java version. Terminates if the version is not valid. + * + * @param versionString version string + */ + public JavaVersion(final String versionString) { + this.versionString = versionString; + + final Matcher matcher = PATTERN_VERSION.matcher(versionString); + + if (!matcher.matches()) { + throw new IllegalArgumentException(MessageFormat.format( + "Java version \"{0}\" is not valid!", versionString)); + } + + versionNumber = Integer.parseInt(matcher.group(1), 10); + } + + /** + * Compares this JavaVersion to the passed JavaVersion. + * + * @param javaVersion JavaVersion to compare to. + * + * @return -1 if this versionNumber is lower, 1 if this versionNumber is + * higher and 0 if both are equal + */ + public int compareTo(final JavaVersion javaVersion) { + if (javaVersion.getVersionNumber() > versionNumber) { + return -1; + } else if (javaVersion.getVersionNumber() < versionNumber) { + return 1; + } else { + return 0; + } + } + + /** + * Getter for {@link #versionNumber}. + * + * @return {@link #versionNumber} + */ + public int getVersionNumber() { + return versionNumber; + } + + /** + * Getter for {@link #versionString}. + * + * @return {@link #versionString} + */ + public String getVersionString() { + return versionString; + } + + @Override + public String toString() { + return versionString; + } +} diff --git a/src/main/java/org/gentoo/java/ebuilder/maven/MavenParser.java b/src/main/java/org/gentoo/java/ebuilder/maven/MavenParser.java index 942ee27..7c9d162 100644 --- a/src/main/java/org/gentoo/java/ebuilder/maven/MavenParser.java +++ b/src/main/java/org/gentoo/java/ebuilder/maven/MavenParser.java @@ -208,7 +208,7 @@ public class MavenParser { case "source": if ("maven-compiler-plugin".equals(artifactId)) { mavenProject.setSourceVersion( - reader.getElementText()); + new JavaVersion(reader.getElementText())); } else { consumeElement(reader); } @@ -217,7 +217,7 @@ public class MavenParser { case "target": if ("maven-compiler-plugin".equals(artifactId)) { mavenProject.setTargetVersion( - reader.getElementText()); + new JavaVersion(reader.getElementText())); } else { consumeElement(reader); } @@ -572,10 +572,12 @@ public class MavenParser { if (reader.isStartElement()) { switch (reader.getLocalName()) { case "maven.compiler.source": - mavenProject.setSourceVersion(reader.getElementText()); + mavenProject.setSourceVersion( + new JavaVersion(reader.getElementText())); break; case "maven.compiler.target": - mavenProject.setTargetVersion(reader.getElementText()); + mavenProject.setTargetVersion( + new JavaVersion(reader.getElementText())); break; case "project.build.sourceEncoding": mavenProject.setSourceEncoding(reader.getElementText()); diff --git a/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java b/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java index 6cead37..07fa60e 100644 --- a/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java +++ b/src/main/java/org/gentoo/java/ebuilder/maven/MavenProject.java @@ -68,11 +68,11 @@ public class MavenProject { /** * Source compile version. */ - private String sourceVersion = "1.8"; + private JavaVersion sourceVersion = new JavaVersion("1.8"); /** * Target compile version. */ - private String targetVersion = "1.8"; + private JavaVersion targetVersion = new JavaVersion("1.8"); /** * Test resource directories. */ @@ -382,7 +382,7 @@ public class MavenProject { * * @return {@link #sourceVersion} */ - public String getSourceVersion() { + public JavaVersion getSourceVersion() { return sourceVersion; } @@ -391,7 +391,7 @@ public class MavenProject { * * @param sourceVersion {@link #sourceVersion} */ - public void setSourceVersion(final String sourceVersion) { + public void setSourceVersion(final JavaVersion sourceVersion) { this.sourceVersion = sourceVersion; } @@ -400,7 +400,7 @@ public class MavenProject { * * @return {@link #targetVersion} */ - public String getTargetVersion() { + public JavaVersion getTargetVersion() { return targetVersion; } @@ -409,7 +409,7 @@ public class MavenProject { * * @param targetVersion {@link #targetVersion} */ - public void setTargetVersion(final String targetVersion) { + public void setTargetVersion(final JavaVersion targetVersion) { this.targetVersion = targetVersion; }