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
32d2fc25
Commit
32d2fc25
authored
May 06, 2014
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
1fc6bbda
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
106 additions
and
145 deletions
+106
-145
AbstractDependencyFilterMojo.java
...ingframework/boot/maven/AbstractDependencyFilterMojo.java
+31
-22
Exclude.java
...src/main/java/org/springframework/boot/maven/Exclude.java
+4
-4
ExcludeFilter.java
...in/java/org/springframework/boot/maven/ExcludeFilter.java
+13
-13
RepackageMojo.java
...in/java/org/springframework/boot/maven/RepackageMojo.java
+2
-6
RunMojo.java
...src/main/java/org/springframework/boot/maven/RunMojo.java
+5
-7
DependencyFilterMojoTests.java
...springframework/boot/maven/DependencyFilterMojoTests.java
+17
-20
ExcludeFilterTests.java
...va/org/springframework/boot/maven/ExcludeFilterTests.java
+25
-17
RepackageMojoTests.java
...va/org/springframework/boot/maven/RepackageMojoTests.java
+0
-44
Verify.java
.../src/test/java/org/springframework/boot/maven/Verify.java
+9
-12
No files found.
spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractDependencyFilterMojo.java
View file @
32d2fc25
...
@@ -26,21 +26,22 @@ import org.apache.maven.plugin.MojoExecutionException;
...
@@ -26,21 +26,22 @@ import org.apache.maven.plugin.MojoExecutionException;
import
org.apache.maven.plugins.annotations.Parameter
;
import
org.apache.maven.plugins.annotations.Parameter
;
import
org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException
;
import
org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException
;
import
org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter
;
import
org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter
;
import
org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter
;
import
org.apache.maven.shared.artifact.filter.collection.FilterArtifacts
;
import
org.apache.maven.shared.artifact.filter.collection.FilterArtifacts
;
import
org.apache.maven.shared.artifact.filter.collection.GroupIdFilter
;
import
org.apache.maven.shared.artifact.filter.collection.GroupIdFilter
;
/**
/**
* A base mojo filtering the dependencies of the project.
* A base mojo filtering the dependencies of the project.
*
*
* @author Stephane Nicoll
* @author Stephane Nicoll
* @since 1.1
* @since 1.1
*/
*/
public
abstract
class
AbstractDependencyFilterMojo
extends
AbstractMojo
{
public
abstract
class
AbstractDependencyFilterMojo
extends
AbstractMojo
{
/**
/**
* Collection of artifact definitions to exclude. The {@link Exclude}
* Collection of artifact definitions to exclude. The {@link Exclude}
element defines
*
element defines a {@code groupId} and {@code artifactId} mandatory
*
a {@code groupId} and {@code artifactId} mandatory properties and an optional
*
properties and an optional
{@code classifier} property.
* {@code classifier} property.
* @since 1.1
* @since 1.1
*/
*/
@Parameter
@Parameter
...
@@ -51,15 +52,14 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
...
@@ -51,15 +52,14 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
* @since 1.1
* @since 1.1
*/
*/
@Parameter
(
property
=
"excludeGroupIds"
,
defaultValue
=
""
)
@Parameter
(
property
=
"excludeGroupIds"
,
defaultValue
=
""
)
pr
otected
String
excludeGroupIds
;
pr
ivate
String
excludeGroupIds
;
/**
/**
* Comma separated list of artifact names to exclude.
* Comma separated list of artifact names to exclude.
* @since 1.1
* @since 1.1
*/
*/
@Parameter
(
property
=
"excludeArtifactIds"
,
defaultValue
=
""
)
@Parameter
(
property
=
"excludeArtifactIds"
,
defaultValue
=
""
)
protected
String
excludeArtifactIds
;
private
String
excludeArtifactIds
;
protected
void
setExcludes
(
List
<
Exclude
>
excludes
)
{
protected
void
setExcludes
(
List
<
Exclude
>
excludes
)
{
this
.
excludes
=
excludes
;
this
.
excludes
=
excludes
;
...
@@ -74,8 +74,8 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
...
@@ -74,8 +74,8 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
}
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
protected
Set
<
Artifact
>
filterDependencies
(
Set
<
Artifact
>
dependencies
,
FilterArtifacts
filters
)
protected
Set
<
Artifact
>
filterDependencies
(
Set
<
Artifact
>
dependencies
,
throws
MojoExecutionException
{
FilterArtifacts
filters
)
throws
MojoExecutionException
{
try
{
try
{
return
filters
.
filter
(
dependencies
);
return
filters
.
filter
(
dependencies
);
}
}
...
@@ -84,28 +84,37 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
...
@@ -84,28 +84,37 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
}
}
}
}
protected
void
initializeFilterArtifacts
(
FilterArtifacts
filters
)
{
/**
filters
.
addFilter
(
new
ArtifactIdFilter
(
""
,
cleanConfigItem
(
this
.
excludeArtifactIds
)));
* Return artifact filters configured for this MOJO.
filters
.
addFilter
(
new
GroupIdFilter
(
""
,
cleanConfigItem
(
this
.
excludeGroupIds
)));
* @param additionalFilters optional additional filters to apply
* @return the filters
*/
protected
final
FilterArtifacts
getFilters
(
ArtifactsFilter
...
additionalFilters
)
{
FilterArtifacts
filters
=
new
FilterArtifacts
();
for
(
ArtifactsFilter
additionalFilter
:
additionalFilters
)
{
filters
.
addFilter
(
additionalFilter
);
}
filters
.
addFilter
(
new
ArtifactIdFilter
(
""
,
cleanFilterConfig
(
this
.
excludeArtifactIds
)));
filters
.
addFilter
(
new
GroupIdFilter
(
""
,
cleanFilterConfig
(
this
.
excludeGroupIds
)));
if
(
this
.
excludes
!=
null
)
{
if
(
this
.
excludes
!=
null
)
{
filters
.
addFilter
(
new
ExcludeFilter
(
this
.
excludes
));
filters
.
addFilter
(
new
ExcludeFilter
(
this
.
excludes
));
}
}
return
filters
;
}
}
private
String
cleanFilterConfig
(
String
content
)
{
static
String
cleanConfigItem
(
String
content
)
{
if
(
content
==
null
||
content
.
trim
().
isEmpty
())
{
if
(
content
==
null
||
content
.
trim
().
isEmpty
())
{
return
""
;
return
""
;
}
}
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
cleaned
=
new
StringBuilder
();
StringTokenizer
st
=
new
StringTokenizer
(
content
,
","
);
StringTokenizer
tokenizer
=
new
StringTokenizer
(
content
,
","
);
while
(
st
.
hasMoreElements
())
{
while
(
tokenizer
.
hasMoreElements
())
{
String
t
=
st
.
nextToken
();
cleaned
.
append
(
tokenizer
.
nextToken
().
trim
());
sb
.
append
(
t
.
trim
());
if
(
tokenizer
.
hasMoreElements
())
{
if
(
st
.
hasMoreElements
())
{
cleaned
.
append
(
","
);
sb
.
append
(
","
);
}
}
}
}
return
sb
.
toString
();
return
cleaned
.
toString
();
}
}
}
}
spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Exclude.java
View file @
32d2fc25
...
@@ -20,7 +20,7 @@ import org.apache.maven.plugins.annotations.Parameter;
...
@@ -20,7 +20,7 @@ import org.apache.maven.plugins.annotations.Parameter;
/**
/**
* A model for a dependency to exclude.
* A model for a dependency to exclude.
*
*
* @author Stephane Nicoll
* @author Stephane Nicoll
* @since 1.1
* @since 1.1
*/
*/
...
@@ -45,7 +45,7 @@ public class Exclude {
...
@@ -45,7 +45,7 @@ public class Exclude {
private
String
classifier
;
private
String
classifier
;
public
String
getGroupId
()
{
public
String
getGroupId
()
{
return
groupId
;
return
this
.
groupId
;
}
}
public
void
setGroupId
(
String
groupId
)
{
public
void
setGroupId
(
String
groupId
)
{
...
@@ -53,7 +53,7 @@ public class Exclude {
...
@@ -53,7 +53,7 @@ public class Exclude {
}
}
public
String
getArtifactId
()
{
public
String
getArtifactId
()
{
return
artifactId
;
return
this
.
artifactId
;
}
}
public
void
setArtifactId
(
String
artifactId
)
{
public
void
setArtifactId
(
String
artifactId
)
{
...
@@ -61,7 +61,7 @@ public class Exclude {
...
@@ -61,7 +61,7 @@ public class Exclude {
}
}
public
String
getClassifier
()
{
public
String
getClassifier
()
{
return
classifier
;
return
this
.
classifier
;
}
}
public
void
setClassifier
(
String
classifier
)
{
public
void
setClassifier
(
String
classifier
)
{
...
...
spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ExcludeFilter.java
View file @
32d2fc25
...
@@ -26,25 +26,25 @@ import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterExceptio
...
@@ -26,25 +26,25 @@ import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterExceptio
/**
/**
* An {@link org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter
* An {@link org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter
* ArtifactsFilter} that filters out any artifact matching a configurable list
* ArtifactsFilter} that filters out any artifact matching a configurable list
of
*
of
{@link Exclude} instances.
* {@link Exclude} instances.
*
*
* @author Stephane Nicoll
* @author Stephane Nicoll
* @since 1.1
* @since 1.1
*/
*/
public
class
ExcludeFilter
extends
AbstractArtifactsFilter
{
public
class
ExcludeFilter
extends
AbstractArtifactsFilter
{
private
final
List
<
Exclude
>
excludes
;
private
final
List
<
Exclude
>
excludes
;
/**
/**
* Create a new instance with the list of {@link Exclude}
* Create a new instance with the list of {@link Exclude} instance(s) to use.
* instance(s) to use.
*/
*/
public
ExcludeFilter
(
List
<
Exclude
>
excludes
)
{
public
ExcludeFilter
(
List
<
Exclude
>
excludes
)
{
this
.
excludes
=
excludes
;
this
.
excludes
=
excludes
;
}
}
@Override
@Override
@SuppressWarnings
(
"rawtypes"
)
public
Set
filter
(
Set
artifacts
)
throws
ArtifactFilterException
{
public
Set
filter
(
Set
artifacts
)
throws
ArtifactFilterException
{
Set
<
Artifact
>
result
=
new
HashSet
<
Artifact
>();
Set
<
Artifact
>
result
=
new
HashSet
<
Artifact
>();
for
(
Object
a
:
artifacts
)
{
for
(
Object
a
:
artifacts
)
{
...
@@ -57,11 +57,11 @@ public class ExcludeFilter extends AbstractArtifactsFilter{
...
@@ -57,11 +57,11 @@ public class ExcludeFilter extends AbstractArtifactsFilter{
}
}
/**
/**
* Check if the specified {@link Artifact} matches one of the
* Check if the specified {@link Artifact} matches one of the
known excludes. Returns
*
known excludes. Returns
{@code true} if it should be excluded
* {@code true} if it should be excluded
*/
*/
private
boolean
matchExclude
(
Artifact
artifact
)
{
private
boolean
matchExclude
(
Artifact
artifact
)
{
for
(
Exclude
exclude
:
excludes
)
{
for
(
Exclude
exclude
:
this
.
excludes
)
{
if
(
match
(
artifact
,
exclude
))
{
if
(
match
(
artifact
,
exclude
))
{
return
true
;
return
true
;
}
}
...
@@ -70,8 +70,8 @@ public class ExcludeFilter extends AbstractArtifactsFilter{
...
@@ -70,8 +70,8 @@ public class ExcludeFilter extends AbstractArtifactsFilter{
}
}
/**
/**
* Check if the specified {@link Artifact} matches the specified
* Check if the specified {@link Artifact} matches the specified
{@link Exclude}.
*
{@link Exclude}.
Returns {@code true} if it should be excluded
* Returns {@code true} if it should be excluded
*/
*/
private
boolean
match
(
Artifact
artifact
,
Exclude
exclude
)
{
private
boolean
match
(
Artifact
artifact
,
Exclude
exclude
)
{
if
(!
exclude
.
getGroupId
().
equals
(
artifact
.
getGroupId
()))
{
if
(!
exclude
.
getGroupId
().
equals
(
artifact
.
getGroupId
()))
{
...
@@ -80,8 +80,8 @@ public class ExcludeFilter extends AbstractArtifactsFilter{
...
@@ -80,8 +80,8 @@ public class ExcludeFilter extends AbstractArtifactsFilter{
if
(!
exclude
.
getArtifactId
().
equals
(
artifact
.
getArtifactId
()))
{
if
(!
exclude
.
getArtifactId
().
equals
(
artifact
.
getArtifactId
()))
{
return
false
;
return
false
;
}
}
return
exclude
.
getClassifier
()
==
null
||
return
(
exclude
.
getClassifier
()
==
null
||
artifact
.
getClassifier
()
!=
null
artifact
.
getClassifier
()
!=
null
&&
exclude
.
getClassifier
().
equals
(
artifact
.
getClassifier
(
));
&&
exclude
.
getClassifier
().
equals
(
artifact
.
getClassifier
()
));
}
}
...
...
spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java
View file @
32d2fc25
...
@@ -23,7 +23,6 @@ import java.util.concurrent.TimeUnit;
...
@@ -23,7 +23,6 @@ import java.util.concurrent.TimeUnit;
import
java.util.jar.JarFile
;
import
java.util.jar.JarFile
;
import
org.apache.maven.artifact.Artifact
;
import
org.apache.maven.artifact.Artifact
;
import
org.apache.maven.plugin.AbstractMojo
;
import
org.apache.maven.plugin.MojoExecutionException
;
import
org.apache.maven.plugin.MojoExecutionException
;
import
org.apache.maven.plugin.MojoFailureException
;
import
org.apache.maven.plugin.MojoFailureException
;
import
org.apache.maven.plugins.annotations.Component
;
import
org.apache.maven.plugins.annotations.Component
;
...
@@ -33,8 +32,6 @@ import org.apache.maven.plugins.annotations.Parameter;
...
@@ -33,8 +32,6 @@ import org.apache.maven.plugins.annotations.Parameter;
import
org.apache.maven.plugins.annotations.ResolutionScope
;
import
org.apache.maven.plugins.annotations.ResolutionScope
;
import
org.apache.maven.project.MavenProject
;
import
org.apache.maven.project.MavenProject
;
import
org.apache.maven.project.MavenProjectHelper
;
import
org.apache.maven.project.MavenProjectHelper
;
import
org.apache.maven.shared.artifact.filter.collection.FilterArtifacts
;
import
org.springframework.boot.loader.tools.Layout
;
import
org.springframework.boot.loader.tools.Layout
;
import
org.springframework.boot.loader.tools.Layouts
;
import
org.springframework.boot.loader.tools.Layouts
;
import
org.springframework.boot.loader.tools.Libraries
;
import
org.springframework.boot.loader.tools.Libraries
;
...
@@ -139,9 +136,8 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
...
@@ -139,9 +136,8 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
repackager
.
setLayout
(
this
.
layout
.
layout
());
repackager
.
setLayout
(
this
.
layout
.
layout
());
}
}
FilterArtifacts
filters
=
new
FilterArtifacts
();
Set
<
Artifact
>
artifacts
=
filterDependencies
(
this
.
project
.
getArtifacts
(),
initializeFilterArtifacts
(
filters
);
getFilters
());
Set
<
Artifact
>
artifacts
=
filterDependencies
(
this
.
project
.
getArtifacts
(),
filters
);
Libraries
libraries
=
new
ArtifactsLibraries
(
artifacts
);
Libraries
libraries
=
new
ArtifactsLibraries
(
artifacts
);
try
{
try
{
...
...
spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java
View file @
32d2fc25
...
@@ -38,7 +38,6 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
...
@@ -38,7 +38,6 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
import
org.apache.maven.project.MavenProject
;
import
org.apache.maven.project.MavenProject
;
import
org.apache.maven.shared.artifact.filter.collection.AbstractArtifactFeatureFilter
;
import
org.apache.maven.shared.artifact.filter.collection.AbstractArtifactFeatureFilter
;
import
org.apache.maven.shared.artifact.filter.collection.FilterArtifacts
;
import
org.apache.maven.shared.artifact.filter.collection.FilterArtifacts
;
import
org.springframework.boot.loader.tools.FileUtils
;
import
org.springframework.boot.loader.tools.FileUtils
;
import
org.springframework.boot.loader.tools.JavaExecutable
;
import
org.springframework.boot.loader.tools.JavaExecutable
;
import
org.springframework.boot.loader.tools.MainClassFinder
;
import
org.springframework.boot.loader.tools.MainClassFinder
;
...
@@ -46,7 +45,7 @@ import org.springframework.boot.loader.tools.RunProcess;
...
@@ -46,7 +45,7 @@ import org.springframework.boot.loader.tools.RunProcess;
/**
/**
* Run an executable archive application.
* Run an executable archive application.
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
...
@@ -256,11 +255,9 @@ public class RunMojo extends AbstractDependencyFilterMojo {
...
@@ -256,11 +255,9 @@ public class RunMojo extends AbstractDependencyFilterMojo {
urls
.
add
(
this
.
classesDirectory
.
toURI
().
toURL
());
urls
.
add
(
this
.
classesDirectory
.
toURI
().
toURL
());
}
}
private
void
addDependencies
(
List
<
URL
>
urls
)
throws
MalformedURLException
,
MojoExecutionException
{
private
void
addDependencies
(
List
<
URL
>
urls
)
throws
MalformedURLException
,
FilterArtifacts
filters
=
new
FilterArtifacts
();
MojoExecutionException
{
filters
.
addFilter
(
new
TestArtifactFilter
());
FilterArtifacts
filters
=
getFilters
(
new
TestArtifactFilter
());
initializeFilterArtifacts
(
filters
);
Set
<
Artifact
>
artifacts
=
filterDependencies
(
this
.
project
.
getArtifacts
(),
filters
);
Set
<
Artifact
>
artifacts
=
filterDependencies
(
this
.
project
.
getArtifacts
(),
filters
);
for
(
Artifact
artifact
:
artifacts
)
{
for
(
Artifact
artifact
:
artifacts
)
{
if
(
artifact
.
getFile
()
!=
null
)
{
if
(
artifact
.
getFile
()
!=
null
)
{
...
@@ -274,6 +271,7 @@ public class RunMojo extends AbstractDependencyFilterMojo {
...
@@ -274,6 +271,7 @@ public class RunMojo extends AbstractDependencyFilterMojo {
super
(
""
,
Artifact
.
SCOPE_TEST
);
super
(
""
,
Artifact
.
SCOPE_TEST
);
}
}
@Override
protected
String
getArtifactFeature
(
Artifact
artifact
)
{
protected
String
getArtifactFeature
(
Artifact
artifact
)
{
return
artifact
.
getScope
();
return
artifact
.
getScope
();
}
}
...
...
spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java
View file @
32d2fc25
...
@@ -16,10 +16,6 @@
...
@@ -16,10 +16,6 @@
package
org
.
springframework
.
boot
.
maven
;
package
org
.
springframework
.
boot
.
maven
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.HashSet
;
...
@@ -29,11 +25,15 @@ import java.util.Set;
...
@@ -29,11 +25,15 @@ import java.util.Set;
import
org.apache.maven.artifact.Artifact
;
import
org.apache.maven.artifact.Artifact
;
import
org.apache.maven.plugin.MojoExecutionException
;
import
org.apache.maven.plugin.MojoExecutionException
;
import
org.apache.maven.plugin.MojoFailureException
;
import
org.apache.maven.plugin.MojoFailureException
;
import
org.apache.maven.shared.artifact.filter.collection.FilterArtifacts
;
import
org.junit.Test
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
/**
*
*
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
public
class
DependencyFilterMojoTests
{
public
class
DependencyFilterMojoTests
{
...
@@ -41,19 +41,16 @@ public class DependencyFilterMojoTests {
...
@@ -41,19 +41,16 @@ public class DependencyFilterMojoTests {
@Test
@Test
public
void
filterDependencies
()
throws
MojoExecutionException
{
public
void
filterDependencies
()
throws
MojoExecutionException
{
TestableDependencyFilterMojo
mojo
=
new
TestableDependencyFilterMojo
(
TestableDependencyFilterMojo
mojo
=
new
TestableDependencyFilterMojo
(
Collections
.<
Exclude
>
emptyList
(),
"com.foo"
,
"exclude-id"
);
Collections
.<
Exclude
>
emptyList
(),
"com.foo"
,
"exclude-id"
);
Artifact
artifact
=
createArtifact
(
"com.bar"
,
"one"
);
Artifact
artifact
=
createArtifact
(
"com.bar"
,
"one"
);
Set
<
Artifact
>
artifacts
=
mojo
.
filterDependencies
(
createArtifact
(
"com.foo"
,
"one"
),
Set
<
Artifact
>
artifacts
=
mojo
.
filterDependencies
(
createArtifact
(
"com.foo"
,
"two"
),
createArtifact
(
"com.foo"
,
"one"
),
createArtifact
(
"com.foo"
,
"two"
),
createArtifact
(
"com.bar"
,
"exclude-id"
),
createArtifact
(
"com.bar"
,
"exclude-id"
),
artifact
);
artifact
);
assertEquals
(
"wrong filtering of artifacts"
,
1
,
artifacts
.
size
());
assertEquals
(
"wrong filtering of artifacts"
,
1
,
artifacts
.
size
());
assertSame
(
"Wrong filtered artifact"
,
artifact
,
artifacts
.
iterator
().
next
());
assertSame
(
"Wrong filtered artifact"
,
artifact
,
artifacts
.
iterator
().
next
());
}
}
private
Artifact
createArtifact
(
String
groupId
,
String
artifactId
)
{
private
Artifact
createArtifact
(
String
groupId
,
String
artifactId
)
{
Artifact
a
=
mock
(
Artifact
.
class
);
Artifact
a
=
mock
(
Artifact
.
class
);
given
(
a
.
getGroupId
()).
willReturn
(
groupId
);
given
(
a
.
getGroupId
()).
willReturn
(
groupId
);
...
@@ -61,20 +58,20 @@ public class DependencyFilterMojoTests {
...
@@ -61,20 +58,20 @@ public class DependencyFilterMojoTests {
return
a
;
return
a
;
}
}
private
static
class
TestableDependencyFilterMojo
extends
AbstractDependencyFilterMojo
{
private
static
class
TestableDependencyFilterMojo
extends
AbstractDependencyFilterMojo
{
private
TestableDependencyFilterMojo
(
List
<
Exclude
>
excludes
,
String
excludeGroupIds
,
String
excludeArtifactIds
)
{
private
TestableDependencyFilterMojo
(
List
<
Exclude
>
excludes
,
String
excludeGroupIds
,
String
excludeArtifactIds
)
{
setExcludes
(
excludes
);
setExcludes
(
excludes
);
setExcludeGroupIds
(
excludeGroupIds
);
setExcludeGroupIds
(
excludeGroupIds
);
setExcludeArtifactIds
(
excludeArtifactIds
);
setExcludeArtifactIds
(
excludeArtifactIds
);
}
}
public
Set
<
Artifact
>
filterDependencies
(
Artifact
...
artifacts
)
throws
MojoExecutionException
{
public
Set
<
Artifact
>
filterDependencies
(
Artifact
...
artifacts
)
throws
MojoExecutionException
{
Set
<
Artifact
>
input
=
new
HashSet
<
Artifact
>(
Arrays
.
asList
(
artifacts
));
Set
<
Artifact
>
input
=
new
HashSet
<
Artifact
>(
Arrays
.
asList
(
artifacts
));
FilterArtifacts
filters
=
new
FilterArtifacts
();
return
filterDependencies
(
input
,
getFilters
());
initializeFilterArtifacts
(
filters
);
return
filterDependencies
(
input
,
filters
);
}
}
@Override
@Override
...
...
spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ExcludeFilterTests.java
View file @
32d2fc25
...
@@ -16,10 +16,6 @@
...
@@ -16,10 +16,6 @@
package
org
.
springframework
.
boot
.
maven
;
package
org
.
springframework
.
boot
.
maven
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
mockito
.
BDDMockito
.*;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.HashSet
;
...
@@ -29,23 +25,32 @@ import org.apache.maven.artifact.Artifact;
...
@@ -29,23 +25,32 @@ import org.apache.maven.artifact.Artifact;
import
org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException
;
import
org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException
;
import
org.junit.Test
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
/**
*
* Tests for {@link ExcludeFilter}.
*
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
@SuppressWarnings
(
"rawtypes"
)
public
class
ExcludeFilterTests
{
public
class
ExcludeFilterTests
{
@Test
@Test
public
void
excludeSimple
()
throws
ArtifactFilterException
{
public
void
excludeSimple
()
throws
ArtifactFilterException
{
ExcludeFilter
filter
=
new
ExcludeFilter
(
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
)));
ExcludeFilter
filter
=
new
ExcludeFilter
(
Arrays
.
asList
(
createExclude
(
"com.foo"
,
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
createArtifact
(
"com.foo"
,
"bar"
)));
"bar"
)));
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
createArtifact
(
"com.foo"
,
"bar"
)));
assertEquals
(
"Should have been filtered"
,
0
,
result
.
size
());
assertEquals
(
"Should have been filtered"
,
0
,
result
.
size
());
}
}
@Test
@Test
public
void
excludeGroupIdNoMatch
()
throws
ArtifactFilterException
{
public
void
excludeGroupIdNoMatch
()
throws
ArtifactFilterException
{
ExcludeFilter
filter
=
new
ExcludeFilter
(
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
)));
ExcludeFilter
filter
=
new
ExcludeFilter
(
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
)));
Artifact
artifact
=
createArtifact
(
"com.baz"
,
"bar"
);
Artifact
artifact
=
createArtifact
(
"com.baz"
,
"bar"
);
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
assertEquals
(
"Should not have been filtered"
,
1
,
result
.
size
());
assertEquals
(
"Should not have been filtered"
,
1
,
result
.
size
());
...
@@ -54,7 +59,8 @@ public class ExcludeFilterTests {
...
@@ -54,7 +59,8 @@ public class ExcludeFilterTests {
@Test
@Test
public
void
excludeArtifactIdNoMatch
()
throws
ArtifactFilterException
{
public
void
excludeArtifactIdNoMatch
()
throws
ArtifactFilterException
{
ExcludeFilter
filter
=
new
ExcludeFilter
(
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
)));
ExcludeFilter
filter
=
new
ExcludeFilter
(
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
)));
Artifact
artifact
=
createArtifact
(
"com.foo"
,
"biz"
);
Artifact
artifact
=
createArtifact
(
"com.foo"
,
"biz"
);
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
assertEquals
(
"Should not have been filtered"
,
1
,
result
.
size
());
assertEquals
(
"Should not have been filtered"
,
1
,
result
.
size
());
...
@@ -63,14 +69,17 @@ public class ExcludeFilterTests {
...
@@ -63,14 +69,17 @@ public class ExcludeFilterTests {
@Test
@Test
public
void
excludeClassifier
()
throws
ArtifactFilterException
{
public
void
excludeClassifier
()
throws
ArtifactFilterException
{
ExcludeFilter
filter
=
new
ExcludeFilter
(
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
,
"jdk5"
)));
ExcludeFilter
filter
=
new
ExcludeFilter
(
Arrays
.
asList
(
createExclude
(
"com.foo"
,
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
createArtifact
(
"com.foo"
,
"bar"
,
"jdk5"
)));
"bar"
,
"jdk5"
)));
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
createArtifact
(
"com.foo"
,
"bar"
,
"jdk5"
)));
assertEquals
(
"Should have been filtered"
,
0
,
result
.
size
());
assertEquals
(
"Should have been filtered"
,
0
,
result
.
size
());
}
}
@Test
@Test
public
void
excludeClassifierNoTargetClassifier
()
throws
ArtifactFilterException
{
public
void
excludeClassifierNoTargetClassifier
()
throws
ArtifactFilterException
{
ExcludeFilter
filter
=
new
ExcludeFilter
(
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
,
"jdk5"
)));
ExcludeFilter
filter
=
new
ExcludeFilter
(
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
,
"jdk5"
)));
Artifact
artifact
=
createArtifact
(
"com.foo"
,
"bar"
);
Artifact
artifact
=
createArtifact
(
"com.foo"
,
"bar"
);
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
assertEquals
(
"Should not have been filtered"
,
1
,
result
.
size
());
assertEquals
(
"Should not have been filtered"
,
1
,
result
.
size
());
...
@@ -79,7 +88,8 @@ public class ExcludeFilterTests {
...
@@ -79,7 +88,8 @@ public class ExcludeFilterTests {
@Test
@Test
public
void
excludeClassifierNoMatch
()
throws
ArtifactFilterException
{
public
void
excludeClassifierNoMatch
()
throws
ArtifactFilterException
{
ExcludeFilter
filter
=
new
ExcludeFilter
(
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
,
"jdk5"
)));
ExcludeFilter
filter
=
new
ExcludeFilter
(
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
,
"jdk5"
)));
Artifact
artifact
=
createArtifact
(
"com.foo"
,
"bar"
,
"jdk6"
);
Artifact
artifact
=
createArtifact
(
"com.foo"
,
"bar"
,
"jdk6"
);
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
assertEquals
(
"Should not have been filtered"
,
1
,
result
.
size
());
assertEquals
(
"Should not have been filtered"
,
1
,
result
.
size
());
...
@@ -89,8 +99,7 @@ public class ExcludeFilterTests {
...
@@ -89,8 +99,7 @@ public class ExcludeFilterTests {
@Test
@Test
public
void
excludeMulti
()
throws
ArtifactFilterException
{
public
void
excludeMulti
()
throws
ArtifactFilterException
{
ExcludeFilter
filter
=
new
ExcludeFilter
(
Arrays
.
asList
(
ExcludeFilter
filter
=
new
ExcludeFilter
(
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
),
createExclude
(
"com.foo"
,
"bar"
),
createExclude
(
"com.foo"
,
"bar2"
),
createExclude
(
"com.foo"
,
"bar2"
),
createExclude
(
"org.acme"
,
"app"
)));
createExclude
(
"org.acme"
,
"app"
)));
Set
<
Artifact
>
artifacts
=
new
HashSet
<
Artifact
>();
Set
<
Artifact
>
artifacts
=
new
HashSet
<
Artifact
>();
artifacts
.
add
(
createArtifact
(
"com.foo"
,
"bar"
));
artifacts
.
add
(
createArtifact
(
"com.foo"
,
"bar"
));
...
@@ -102,7 +111,6 @@ public class ExcludeFilterTests {
...
@@ -102,7 +111,6 @@ public class ExcludeFilterTests {
assertSame
(
anotherAcme
,
result
.
iterator
().
next
());
assertSame
(
anotherAcme
,
result
.
iterator
().
next
());
}
}
private
Exclude
createExclude
(
String
groupId
,
String
artifactId
,
String
classifier
)
{
private
Exclude
createExclude
(
String
groupId
,
String
artifactId
,
String
classifier
)
{
Exclude
e
=
new
Exclude
();
Exclude
e
=
new
Exclude
();
e
.
setGroupId
(
groupId
);
e
.
setGroupId
(
groupId
);
...
...
spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/RepackageMojoTests.java
deleted
100644 → 0
View file @
1fc6bbda
/*
* Copyright 2012-2014 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
*
* http://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
.
maven
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
org.junit.Test
;
/**
*
* @author Stephane Nicoll
*/
public
class
RepackageMojoTests
{
@Test
public
void
cleanConfigItemWithSpaces
()
{
assertEquals
(
"foo,bar,biz"
,
RepackageMojo
.
cleanConfigItem
(
"foo, bar , biz"
));
}
@Test
public
void
cleanNullConfigItemWith
()
{
assertEquals
(
""
,
RepackageMojo
.
cleanConfigItem
(
null
));
}
@Test
public
void
cleanEmptyConfigItemWith
()
{
assertEquals
(
""
,
RepackageMojo
.
cleanConfigItem
(
""
));
}
}
spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java
View file @
32d2fc25
...
@@ -81,8 +81,8 @@ public class Verify {
...
@@ -81,8 +81,8 @@ public class Verify {
public
void
assertHasNoEntryNameStartingWith
(
String
entry
)
{
public
void
assertHasNoEntryNameStartingWith
(
String
entry
)
{
for
(
String
name
:
this
.
content
.
keySet
())
{
for
(
String
name
:
this
.
content
.
keySet
())
{
if
(
name
.
startsWith
(
entry
))
{
if
(
name
.
startsWith
(
entry
))
{
throw
new
IllegalStateException
(
"Entry starting with "
throw
new
IllegalStateException
(
"Entry starting with "
+
entry
+
entry
+
" should not have been found"
);
+
" should not have been found"
);
}
}
}
}
}
}
...
@@ -98,7 +98,7 @@ public class Verify {
...
@@ -98,7 +98,7 @@ public class Verify {
public
InputStream
getEntryContent
(
String
entry
)
throws
IOException
{
public
InputStream
getEntryContent
(
String
entry
)
throws
IOException
{
ZipEntry
zipEntry
=
getEntry
(
entry
);
ZipEntry
zipEntry
=
getEntry
(
entry
);
if
(
zipEntry
==
null
)
{
if
(
zipEntry
==
null
)
{
throw
new
IllegalArgumentException
(
"No entry with name ["
+
entry
+
"]"
);
throw
new
IllegalArgumentException
(
"No entry with name ["
+
entry
+
"]"
);
}
}
return
this
.
zipFile
.
getInputStream
(
zipEntry
);
return
this
.
zipFile
.
getInputStream
(
zipEntry
);
}
}
...
@@ -127,13 +127,13 @@ public class Verify {
...
@@ -127,13 +127,13 @@ public class Verify {
}
}
}
}
protected
void
verifyZipEntries
(
ArchiveVerifier
verifier
)
protected
void
verifyZipEntries
(
ArchiveVerifier
verifier
)
throws
Exception
{
throws
Exception
{
verifyManifest
(
verifier
);
verifyManifest
(
verifier
);
}
}
private
void
verifyManifest
(
ArchiveVerifier
verifier
)
throws
Exception
{
private
void
verifyManifest
(
ArchiveVerifier
verifier
)
throws
Exception
{
Manifest
manifest
=
new
Manifest
(
verifier
.
getEntryContent
(
"META-INF/MANIFEST.MF"
));
Manifest
manifest
=
new
Manifest
(
verifier
.
getEntryContent
(
"META-INF/MANIFEST.MF"
));
verifyManifest
(
manifest
);
verifyManifest
(
manifest
);
}
}
...
@@ -151,8 +151,7 @@ public class Verify {
...
@@ -151,8 +151,7 @@ public class Verify {
}
}
@Override
@Override
protected
void
verifyZipEntries
(
ArchiveVerifier
verifier
)
protected
void
verifyZipEntries
(
ArchiveVerifier
verifier
)
throws
Exception
{
throws
Exception
{
super
.
verifyZipEntries
(
verifier
);
super
.
verifyZipEntries
(
verifier
);
verifier
.
assertHasEntryNameStartingWith
(
"lib/spring-context"
);
verifier
.
assertHasEntryNameStartingWith
(
"lib/spring-context"
);
verifier
.
assertHasEntryNameStartingWith
(
"lib/spring-core"
);
verifier
.
assertHasEntryNameStartingWith
(
"lib/spring-core"
);
...
@@ -179,13 +178,11 @@ public class Verify {
...
@@ -179,13 +178,11 @@ public class Verify {
}
}
@Override
@Override
protected
void
verifyZipEntries
(
ArchiveVerifier
verifier
)
protected
void
verifyZipEntries
(
ArchiveVerifier
verifier
)
throws
Exception
{
throws
Exception
{
super
.
verifyZipEntries
(
verifier
);
super
.
verifyZipEntries
(
verifier
);
verifier
.
assertHasEntryNameStartingWith
(
"WEB-INF/lib/spring-context"
);
verifier
.
assertHasEntryNameStartingWith
(
"WEB-INF/lib/spring-context"
);
verifier
.
assertHasEntryNameStartingWith
(
"WEB-INF/lib/spring-core"
);
verifier
.
assertHasEntryNameStartingWith
(
"WEB-INF/lib/spring-core"
);
verifier
.
assertHasEntryNameStartingWith
(
verifier
.
assertHasEntryNameStartingWith
(
"WEB-INF/lib-provided/javax.servlet-api-3.0.1.jar"
);
"WEB-INF/lib-provided/javax.servlet-api-3.0.1.jar"
);
assertTrue
(
"Unpacked launcher classes"
,
verifier
.
hasEntry
(
"org/"
assertTrue
(
"Unpacked launcher classes"
,
verifier
.
hasEntry
(
"org/"
+
"springframework/boot/loader/JarLauncher.class"
));
+
"springframework/boot/loader/JarLauncher.class"
));
assertTrue
(
"Own classes"
,
verifier
.
hasEntry
(
"WEB-INF/classes/org/"
assertTrue
(
"Own classes"
,
verifier
.
hasEntry
(
"WEB-INF/classes/org/"
...
...
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