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
c282f01d
Commit
c282f01d
authored
Mar 27, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhance bomr to handle libraries that use a version property
Closes gh-20478
parent
443abd41
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
213 additions
and
14 deletions
+213
-14
UpgradeApplicator.java
...pringframework/boot/build/bom/bomr/UpgradeApplicator.java
+78
-0
UpgradeBom.java
...a/org/springframework/boot/build/bom/bomr/UpgradeBom.java
+5
-14
UpgradeApplicatorTests.java
...framework/boot/build/bom/bomr/UpgradeApplicatorTests.java
+75
-0
bom.gradle
buildSrc/src/test/resources/bom.gradle
+51
-0
gradle.properties
buildSrc/src/test/resources/gradle.properties
+4
-0
No files found.
buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeApplicator.java
0 → 100644
View file @
c282f01d
/*
* Copyright 2012-2020 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
*
* https://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
org
.
springframework
.
boot
.
build
.
bom
.
bomr
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.StandardOpenOption
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* {@code UpgradeApplicator} is used to apply an {@link Upgrade}. Modifies the bom
* configuration in the build file or a version property in {@code gradle.properties}.
*
* @author Andy Wilkinson
*/
class
UpgradeApplicator
{
private
final
Path
buildFile
;
private
final
Path
gradleProperties
;
UpgradeApplicator
(
Path
buildFile
,
Path
gradleProperties
)
{
this
.
buildFile
=
buildFile
;
this
.
gradleProperties
=
gradleProperties
;
}
Path
apply
(
Upgrade
upgrade
)
throws
IOException
{
String
buildFileContents
=
new
String
(
Files
.
readAllBytes
(
this
.
buildFile
),
StandardCharsets
.
UTF_8
);
Matcher
matcher
=
Pattern
.
compile
(
"library\\(\""
+
upgrade
.
getLibrary
().
getName
()
+
"\", \"(.+)\"\\)"
)
.
matcher
(
buildFileContents
);
if
(!
matcher
.
find
())
{
throw
new
IllegalStateException
(
"Failed to find definition for library '"
+
upgrade
.
getLibrary
().
getName
()
+
"' in bom '"
+
this
.
buildFile
+
"'"
);
}
String
version
=
matcher
.
group
(
1
);
if
(
version
.
startsWith
(
"${"
)
&&
version
.
endsWith
(
"}"
))
{
updateGradleProperties
(
upgrade
,
version
);
return
this
.
gradleProperties
;
}
else
{
updateBuildFile
(
upgrade
,
buildFileContents
);
return
this
.
buildFile
;
}
}
private
void
updateGradleProperties
(
Upgrade
upgrade
,
String
version
)
throws
IOException
{
String
property
=
version
.
substring
(
2
,
version
.
length
()
-
1
);
String
gradlePropertiesContents
=
new
String
(
Files
.
readAllBytes
(
this
.
gradleProperties
),
StandardCharsets
.
UTF_8
);
String
modified
=
gradlePropertiesContents
.
replace
(
property
+
"="
+
upgrade
.
getLibrary
().
getVersion
(),
property
+
"="
+
upgrade
.
getVersion
());
Files
.
write
(
this
.
gradleProperties
,
modified
.
getBytes
(
StandardCharsets
.
UTF_8
),
StandardOpenOption
.
CREATE
);
}
private
void
updateBuildFile
(
Upgrade
upgrade
,
String
buildFileContents
)
throws
IOException
{
String
modified
=
buildFileContents
.
replace
(
"library(\""
+
upgrade
.
getLibrary
().
getName
()
+
"\", \""
+
upgrade
.
getLibrary
().
getVersion
()
+
"\")"
,
"library(\""
+
upgrade
.
getLibrary
().
getName
()
+
"\", \""
+
upgrade
.
getVersion
()
+
"\")"
);
Files
.
write
(
this
.
buildFile
,
modified
.
getBytes
(
StandardCharsets
.
UTF_8
),
StandardOpenOption
.
CREATE
);
}
}
buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeBom.java
View file @
c282f01d
...
@@ -20,10 +20,7 @@ import java.io.File;
...
@@ -20,10 +20,7 @@ import java.io.File;
import
java.io.FileReader
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.Reader
;
import
java.io.Reader
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.nio.file.StandardOpenOption
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
...
@@ -84,14 +81,16 @@ public class UpgradeBom extends DefaultTask {
...
@@ -84,14 +81,16 @@ public class UpgradeBom extends DefaultTask {
new
MavenMetadataVersionResolver
(
Arrays
.
asList
(
"https://repo1.maven.org/maven2/"
)),
new
MavenMetadataVersionResolver
(
Arrays
.
asList
(
"https://repo1.maven.org/maven2/"
)),
this
.
bom
.
getUpgrade
().
getPolicy
(),
getServices
().
get
(
UserInputHandler
.
class
))
this
.
bom
.
getUpgrade
().
getPolicy
(),
getServices
().
get
(
UserInputHandler
.
class
))
.
resolveUpgrades
(
this
.
bom
.
getLibraries
());
.
resolveUpgrades
(
this
.
bom
.
getLibraries
());
Path
buildFile
=
getProject
().
getBuildFile
().
toPath
();
Path
gradleProperties
=
new
File
(
getProject
().
getRootProject
().
getProjectDir
(),
"gradle.properties"
).
toPath
();
UpgradeApplicator
upgradeApplicator
=
new
UpgradeApplicator
(
buildFile
,
gradleProperties
);
for
(
Upgrade
upgrade
:
upgrades
)
{
for
(
Upgrade
upgrade
:
upgrades
)
{
String
title
=
"Upgrade to "
+
upgrade
.
getLibrary
().
getName
()
+
" "
+
upgrade
.
getVersion
();
String
title
=
"Upgrade to "
+
upgrade
.
getLibrary
().
getName
()
+
" "
+
upgrade
.
getVersion
();
System
.
out
.
println
(
title
);
System
.
out
.
println
(
title
);
try
{
try
{
Path
buildFile
=
getProject
().
getBuildFile
().
toPath
();
Path
modified
=
upgradeApplicator
.
apply
(
upgrade
);
applyChanges
(
upgrade
,
buildFile
);
int
issueNumber
=
repository
.
openIssue
(
title
,
issueLabels
,
milestone
);
int
issueNumber
=
repository
.
openIssue
(
title
,
issueLabels
,
milestone
);
if
(
new
ProcessBuilder
().
command
(
"git"
,
"add"
,
buildFile
.
toFile
().
getAbsolutePath
()).
start
()
if
(
new
ProcessBuilder
().
command
(
"git"
,
"add"
,
modified
.
toFile
().
getAbsolutePath
()).
start
()
.
waitFor
()
!=
0
)
{
.
waitFor
()
!=
0
)
{
throw
new
IllegalStateException
(
"git add failed"
);
throw
new
IllegalStateException
(
"git add failed"
);
}
}
...
@@ -122,14 +121,6 @@ public class UpgradeBom extends DefaultTask {
...
@@ -122,14 +121,6 @@ public class UpgradeBom extends DefaultTask {
}
}
}
}
private
void
applyChanges
(
Upgrade
upgrade
,
Path
buildFile
)
throws
IOException
{
String
contents
=
new
String
(
Files
.
readAllBytes
(
buildFile
),
StandardCharsets
.
UTF_8
);
String
modified
=
contents
.
replace
(
"library(\""
+
upgrade
.
getLibrary
().
getName
()
+
"\", \""
+
upgrade
.
getLibrary
().
getVersion
()
+
"\")"
,
"library(\""
+
upgrade
.
getLibrary
().
getName
()
+
"\", \""
+
upgrade
.
getVersion
()
+
"\")"
);
Files
.
write
(
buildFile
,
modified
.
getBytes
(
StandardCharsets
.
UTF_8
),
StandardOpenOption
.
CREATE
);
}
private
Milestone
determineMilestone
(
GitHubRepository
repository
)
{
private
Milestone
determineMilestone
(
GitHubRepository
repository
)
{
if
(
this
.
milestone
==
null
)
{
if
(
this
.
milestone
==
null
)
{
return
null
;
return
null
;
...
...
buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/UpgradeApplicatorTests.java
0 → 100644
View file @
c282f01d
/*
* Copyright 2020 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
*
* https://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
org
.
springframework
.
boot
.
build
.
bom
.
bomr
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.util.Properties
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.springframework.boot.build.bom.Library
;
import
org.springframework.boot.build.bom.bomr.version.DependencyVersion
;
import
org.springframework.util.FileCopyUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link UpgradeApplicator}.
*
* @author Andy Wilkinson
*/
class
UpgradeApplicatorTests
{
@TempDir
File
temp
;
@Test
void
whenUpgradeIsAppliedToLibraryWithVersionThenBomIsUpdated
()
throws
IOException
{
File
bom
=
new
File
(
this
.
temp
,
"bom.gradle"
);
FileCopyUtils
.
copy
(
new
File
(
"src/test/resources/bom.gradle"
),
bom
);
File
gradleProperties
=
new
File
(
this
.
temp
,
"gradle.properties"
);
FileCopyUtils
.
copy
(
new
File
(
"src/test/resources/gradle.properties"
),
gradleProperties
);
new
UpgradeApplicator
(
bom
.
toPath
(),
gradleProperties
.
toPath
())
.
apply
(
new
Upgrade
(
new
Library
(
"ActiveMQ"
,
DependencyVersion
.
parse
(
"5.15.11"
),
null
,
null
),
DependencyVersion
.
parse
(
"5.16"
)));
String
bomContents
=
new
String
(
Files
.
readAllBytes
(
bom
.
toPath
()),
StandardCharsets
.
UTF_8
);
assertThat
(
bomContents
).
contains
(
"library(\"ActiveMQ\", \"5.16\")"
);
}
@Test
void
whenUpgradeIsAppliedToLibraryWithVersionPropertyThenGradlePropertiesIsUpdated
()
throws
IOException
{
File
bom
=
new
File
(
this
.
temp
,
"bom.gradle"
);
FileCopyUtils
.
copy
(
new
File
(
"src/test/resources/bom.gradle"
),
bom
);
File
gradleProperties
=
new
File
(
this
.
temp
,
"gradle.properties"
);
FileCopyUtils
.
copy
(
new
File
(
"src/test/resources/gradle.properties"
),
gradleProperties
);
new
UpgradeApplicator
(
bom
.
toPath
(),
gradleProperties
.
toPath
())
.
apply
(
new
Upgrade
(
new
Library
(
"Kotlin"
,
DependencyVersion
.
parse
(
"1.3.70"
),
null
,
null
),
DependencyVersion
.
parse
(
"1.3.71"
)));
Properties
properties
=
new
Properties
();
try
(
InputStream
in
=
new
FileInputStream
(
gradleProperties
))
{
properties
.
load
(
in
);
}
assertThat
(
properties
).
containsEntry
(
"kotlinVersion"
,
"1.3.71"
);
}
}
buildSrc/src/test/resources/bom.gradle
0 → 100644
View file @
c282f01d
bom
{
library
(
"ActiveMQ"
,
"5.15.11"
)
{
group
(
"org.apache.activemq"
)
{
modules
=
[
"activemq-amqp"
,
"activemq-blueprint"
,
"activemq-broker"
,
"activemq-camel"
,
"activemq-client"
,
"activemq-console"
{
exclude
group:
"commons-logging"
,
module:
"commons-logging"
},
"activemq-http"
,
"activemq-jaas"
,
"activemq-jdbc-store"
,
"activemq-jms-pool"
,
"activemq-kahadb-store"
,
"activemq-karaf"
,
"activemq-leveldb-store"
{
exclude
group:
"commons-logging"
,
module:
"commons-logging"
},
"activemq-log4j-appender"
,
"activemq-mqtt"
,
"activemq-openwire-generator"
,
"activemq-openwire-legacy"
,
"activemq-osgi"
,
"activemq-partition"
,
"activemq-pool"
,
"activemq-ra"
,
"activemq-run"
,
"activemq-runtime-config"
,
"activemq-shiro"
,
"activemq-spring"
{
exclude
group:
"commons-logging"
,
module:
"commons-logging"
},
"activemq-stomp"
,
"activemq-web"
]
}
}
library
(
"Kotlin"
,
"${kotlinVersion}"
)
{
group
(
"org.jetbrains.kotlin"
)
{
imports
=
[
"kotlin-bom"
]
plugins
=
[
"kotlin-maven-plugin"
]
}
}
}
buildSrc/src/test/resources/gradle.properties
0 → 100644
View file @
c282f01d
a
=
alpha
b
=
bravo
kotlinVersion
=
1.3.70
t
=
tango
\ No newline at end of file
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