File tree Expand file tree Collapse file tree 2 files changed +12
-10
lines changed
arduino-core/src/cc/arduino/contributions Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change 3232import com .github .zafarkhaja .semver .Version ;
3333
3434import java .io .File ;
35+ import java .util .Optional ;
3536
3637public abstract class DownloadableContribution {
3738
@@ -66,10 +67,10 @@ public void setDownloadedFile(File downloadedFile) {
6667 }
6768
6869 public String getParsedVersion () {
69- Version version = VersionHelper .valueOf (getVersion ());
70- if (version == null ) {
71- return null ;
70+ Optional < Version > version = VersionHelper .valueOf (getVersion ());
71+ if (version . isPresent () ) {
72+ return version . get (). toString () ;
7273 }
73- return version . toString () ;
74+ return null ;
7475 }
7576}
Original file line number Diff line number Diff line change 2929
3030package cc .arduino .contributions ;
3131
32+ import java .util .Optional ;
33+
3234import com .github .zafarkhaja .semver .Version ;
3335
3436public class VersionHelper {
3537
36- public static Version valueOf (String ver ) {
38+ public static Optional < Version > valueOf (String ver ) {
3739 if (ver == null ) {
38- return null ;
40+ return Optional . empty () ;
3941 }
4042 try {
4143 // Allow x.y-something, assuming x.y.0-something
@@ -49,18 +51,17 @@ public static Version valueOf(String ver) {
4951 }
5052 String [] parts = version .split ("\\ ." );
5153 if (parts .length >= 3 ) {
52- return Version .valueOf (ver );
54+ return Optional . of ( Version .valueOf (ver ) );
5355 }
5456 if (parts .length == 2 ) {
5557 version += ".0" ;
5658 }
5759 if (parts .length == 1 ) {
5860 version += ".0.0" ;
5961 }
60- return Version .valueOf (version + extra );
62+ return Optional . of ( Version .valueOf (version + extra ) );
6163 } catch (Exception e ) {
62- System .err .println ("Invalid version found: " + ver );
63- return null ;
64+ return Optional .empty ();
6465 }
6566 }
6667
You can’t perform that action at this time.
0 commit comments