From ba288cee61877182102ae1088043249b6edd221d Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Mon, 4 Apr 2005 16:02:48 +0000 Subject: [PATCH] use a regex to parse for more consistency git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163768 13f79535-47bb-0310-9956-ffa450edef68 --- .../metadata/SnapshotArtifactMetadata.java | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java index 858f9bf541..5726d6e1bf 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java @@ -31,6 +31,8 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Contains the information stored for a snapshot. @@ -54,6 +56,8 @@ public class SnapshotArtifactMetadata private long lastModified = 0; + private static final Pattern VERSION_FILE_PATTERN = Pattern.compile( "^(.*)-([0-9]{8}.[0-9]{6})-([0-9]+)$" ); + public SnapshotArtifactMetadata( Artifact artifact ) { super( artifact, artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "." + SNAPSHOT_VERSION_FILE ); @@ -169,28 +173,16 @@ public class SnapshotArtifactMetadata String version = FileUtils.fileRead( file ); lastModified = file.lastModified(); -/* TODO: try this - if( version.matches( "/^(.*)-([0-9]{8}.[0-9]{6})-([0-9]+)$/" )) + Matcher matcher = VERSION_FILE_PATTERN.matcher( version ); + if ( matcher.matches() ) { - + timestamp = matcher.group( 2 ); + buildNumber = Integer.valueOf( matcher.group( 3 ) ).intValue(); } -*/ - - int index = version.lastIndexOf( "-" ); - if ( version.indexOf( "SNAPSHOT" ) >= 0 || index < 0 ) + else { timestamp = null; buildNumber = 0; - return; - } - - timestamp = version.substring( 0, index ); - buildNumber = Integer.valueOf( version.substring( index + 1 ) ).intValue(); - index = timestamp.lastIndexOf( "-" ); - if ( index >= 0 ) - { - // ignore starting version part, will be prepended later - timestamp = timestamp.substring( index + 1 ); } }