Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
d3f0f04f
Commit
d3f0f04f
authored
May 28, 2021
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.4.x'
Closes gh-26703
parents
54c31941
49d3ecc2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
47 deletions
+59
-47
ImageName.java
...mework/boot/buildpack/platform/docker/type/ImageName.java
+14
-9
ImageReference.java
...k/boot/buildpack/platform/docker/type/ImageReference.java
+28
-7
Regex.java
...gframework/boot/buildpack/platform/docker/type/Regex.java
+8
-30
ImageReferenceTests.java
...t/buildpack/platform/docker/type/ImageReferenceTests.java
+9
-1
No files found.
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImageName.java
View file @
d3f0f04f
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -16,9 +16,6 @@
package
org
.
springframework
.
boot
.
buildpack
.
platform
.
docker
.
type
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
org.springframework.util.Assert
;
/**
...
...
@@ -32,8 +29,6 @@ import org.springframework.util.Assert;
*/
public
class
ImageName
{
private
static
final
Pattern
PATTERN
=
Regex
.
IMAGE_NAME
.
compile
();
private
static
final
String
DEFAULT_DOMAIN
=
"docker.io"
;
private
static
final
String
OFFICIAL_REPOSITORY_NAME
=
"library"
;
...
...
@@ -132,12 +127,22 @@ public class ImageName {
*/
public
static
ImageName
of
(
String
value
)
{
Assert
.
hasText
(
value
,
"Value must not be empty"
);
Matcher
matcher
=
PATTERN
.
matcher
(
value
);
Assert
.
isTrue
(
matcher
.
matches
(),
String
domain
=
parseDomain
(
value
);
String
path
=
(
domain
!=
null
)
?
value
.
substring
(
domain
.
length
()
+
1
)
:
value
;
Assert
.
isTrue
(
Regex
.
PATH
.
matcher
(
path
).
matches
(),
()
->
"Unable to parse name \""
+
value
+
"\". "
+
"Image name must be in the form '[domainHost:port/][path/]name', "
+
"with 'path' and 'name' containing only [a-z0-9][.][_][-]"
);
return
new
ImageName
(
matcher
.
group
(
"domain"
),
matcher
.
group
(
"path"
));
return
new
ImageName
(
domain
,
path
);
}
static
String
parseDomain
(
String
value
)
{
int
firstSlash
=
value
.
indexOf
(
'/'
);
String
candidate
=
(
firstSlash
!=
-
1
)
?
value
.
substring
(
0
,
firstSlash
)
:
null
;
if
(
candidate
!=
null
&&
Regex
.
DOMAIN
.
matcher
(
candidate
).
matches
())
{
return
candidate
;
}
return
null
;
}
}
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImageReference.java
View file @
d3f0f04f
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -33,8 +33,6 @@ import org.springframework.util.ObjectUtils;
*/
public
final
class
ImageReference
{
private
static
final
Pattern
PATTERN
=
Regex
.
IMAGE_REFERENCE
.
compile
();
private
static
final
Pattern
JAR_VERSION_PATTERN
=
Pattern
.
compile
(
"^(.*)(\\-\\d+)$"
);
private
static
final
String
LATEST
=
"latest"
;
...
...
@@ -225,13 +223,36 @@ public final class ImageReference {
*/
public
static
ImageReference
of
(
String
value
)
{
Assert
.
hasText
(
value
,
"Value must not be null"
);
Matcher
matcher
=
PATTERN
.
matcher
(
value
);
Assert
.
isTrue
(
matcher
.
matches
(),
String
domain
=
ImageName
.
parseDomain
(
value
);
String
path
=
(
domain
!=
null
)
?
value
.
substring
(
domain
.
length
()
+
1
)
:
value
;
String
digest
=
null
;
int
digestSplit
=
path
.
indexOf
(
"@"
);
if
(
digestSplit
!=
-
1
)
{
String
remainder
=
path
.
substring
(
digestSplit
+
1
);
Matcher
matcher
=
Regex
.
DIGEST
.
matcher
(
remainder
);
if
(
matcher
.
find
())
{
digest
=
remainder
.
substring
(
0
,
matcher
.
end
());
remainder
=
remainder
.
substring
(
matcher
.
end
());
path
=
path
.
substring
(
0
,
digestSplit
)
+
remainder
;
}
}
String
tag
=
null
;
int
tagSplit
=
path
.
lastIndexOf
(
":"
);
if
(
tagSplit
!=
-
1
)
{
String
remainder
=
path
.
substring
(
tagSplit
+
1
);
Matcher
matcher
=
Regex
.
TAG
.
matcher
(
remainder
);
if
(
matcher
.
find
())
{
tag
=
remainder
.
substring
(
0
,
matcher
.
end
());
remainder
=
remainder
.
substring
(
matcher
.
end
());
path
=
path
.
substring
(
0
,
tagSplit
)
+
remainder
;
}
}
Assert
.
isTrue
(
Regex
.
PATH
.
matcher
(
path
).
matches
(),
()
->
"Unable to parse image reference \""
+
value
+
"\". "
+
"Image reference must be in the form '[domainHost:port/][path/]name[:tag][@digest]', "
+
"with 'path' and 'name' containing only [a-z0-9][.][_][-]"
);
ImageName
name
=
new
ImageName
(
matcher
.
group
(
"domain"
),
matcher
.
group
(
"path"
)
);
return
new
ImageReference
(
name
,
matcher
.
group
(
"tag"
),
matcher
.
group
(
"digest"
)
);
ImageName
name
=
new
ImageName
(
domain
,
path
);
return
new
ImageReference
(
name
,
tag
,
digest
);
}
/**
...
...
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/Regex.java
View file @
d3f0f04f
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -36,7 +36,7 @@ import java.util.regex.Pattern;
*/
final
class
Regex
implements
CharSequence
{
private
static
final
Regex
DOMAIN
;
static
final
Pattern
DOMAIN
;
static
{
Regex
component
=
Regex
.
oneOf
(
"[a-zA-Z0-9]"
,
"[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]"
);
Regex
dotComponent
=
Regex
.
group
(
"[.]"
,
component
);
...
...
@@ -44,7 +44,7 @@ final class Regex implements CharSequence {
Regex
dottedDomain
=
Regex
.
group
(
component
,
dotComponent
.
oneOrMoreTimes
());
Regex
dottedDomainAndPort
=
Regex
.
group
(
component
,
dotComponent
.
oneOrMoreTimes
(),
colonPort
);
Regex
nameAndPort
=
Regex
.
group
(
component
,
colonPort
);
DOMAIN
=
Regex
.
oneOf
(
dottedDomain
,
nameAndPort
,
dottedDomainAndPort
,
"localhost"
);
DOMAIN
=
Regex
.
oneOf
(
dottedDomain
,
nameAndPort
,
dottedDomainAndPort
,
"localhost"
)
.
compile
()
;
}
private
static
final
Regex
PATH_COMPONENT
;
...
...
@@ -55,36 +55,18 @@ final class Regex implements CharSequence {
PATH_COMPONENT
=
Regex
.
of
(
segment
,
Regex
.
group
(
separatedSegment
).
zeroOrOnce
());
}
private
static
final
Regex
PATH
;
static
final
Pattern
PATH
;
static
{
Regex
component
=
PATH_COMPONENT
;
Regex
slashComponent
=
Regex
.
group
(
"[/]"
,
component
);
Regex
slashComponents
=
Regex
.
group
(
slashComponent
.
oneOrMoreTimes
());
PATH
=
Regex
.
of
(
component
,
slashComponents
.
zeroOrOnce
());
PATH
=
Regex
.
of
(
component
,
slashComponents
.
zeroOrOnce
())
.
compile
()
;
}
static
final
Regex
IMAGE_NAME
;
static
{
Regex
domain
=
DOMAIN
.
capturedAs
(
"domain"
);
Regex
domainSlash
=
Regex
.
group
(
domain
,
"[/]"
);
Regex
path
=
PATH
.
capturedAs
(
"path"
);
Regex
optionalDomainSlash
=
domainSlash
.
zeroOrOnce
();
IMAGE_NAME
=
Regex
.
of
(
optionalDomainSlash
,
path
);
}
private
static
final
Regex
TAG_REGEX
=
Regex
.
of
(
"[\\w][\\w.-]{0,127}"
);
private
static
final
Regex
DIGEST_REGEX
=
Regex
.
of
(
"[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][[A-Fa-f0-9]]{32,}"
);
static
final
Pattern
TAG
=
Regex
.
of
(
"^[\\w][\\w.-]{0,127}"
).
compile
();
static
final
Regex
IMAGE_REFERENCE
;
static
{
Regex
tag
=
TAG_REGEX
.
capturedAs
(
"tag"
);
Regex
digest
=
DIGEST_REGEX
.
capturedAs
(
"digest"
);
Regex
atDigest
=
Regex
.
group
(
"[@]"
,
digest
);
Regex
colonTag
=
Regex
.
group
(
"[:]"
,
tag
);
IMAGE_REFERENCE
=
Regex
.
of
(
IMAGE_NAME
,
colonTag
.
zeroOrOnce
(),
atDigest
.
zeroOrOnce
());
}
static
final
Pattern
DIGEST
=
Regex
.
of
(
"^[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][[A-Fa-f0-9]]{32,}"
)
.
compile
();
private
final
String
value
;
...
...
@@ -100,10 +82,6 @@ final class Regex implements CharSequence {
return
new
Regex
(
this
.
value
+
"?"
);
}
private
Regex
capturedAs
(
String
name
)
{
return
new
Regex
(
"(?<"
+
name
+
">"
+
this
+
")"
);
}
Pattern
compile
()
{
return
Pattern
.
compile
(
"^"
+
this
.
value
+
"$"
);
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageReferenceTests.java
View file @
d3f0f04f
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -171,6 +171,14 @@ class ImageReferenceTests {
"docker.io/library/ubuntu:bionic@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d"
);
}
@Test
void
ofWhenHasIllegalCharacter
()
{
assertThatIllegalArgumentException
()
.
isThrownBy
(()
->
ImageReference
.
of
(
"registry.example.com/example/example-app:1.6.0-dev.2.uncommitted+wip.foo.c75795d"
))
.
withMessageContaining
(
"Unable to parse image reference"
);
}
@Test
void
forJarFile
()
{
assertForJarFile
(
"spring-boot.2.0.0.BUILD-SNAPSHOT.jar"
,
"library/spring-boot"
,
"2.0.0.BUILD-SNAPSHOT"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment