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
abc1e5de
Commit
abc1e5de
authored
May 30, 2014
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix ifAnyMissingClasses to return false if no classes are missing
Fixes #1003
parent
329175b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
142 additions
and
1 deletion
+142
-1
DependencyCustomizer.java
...ringframework/boot/cli/compiler/DependencyCustomizer.java
+1
-1
DependencyCustomizerTests.java
...ramework/boot/cli/compiler/DependencyCustomizerTests.java
+141
-0
No files found.
spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyCustomizer.java
View file @
abc1e5de
...
...
@@ -96,7 +96,7 @@ public class DependencyCustomizer {
return
true
;
}
}
return
DependencyCustomizer
.
this
.
canAdd
()
;
return
false
;
}
};
}
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/DependencyCustomizerTests.java
0 → 100644
View file @
abc1e5de
/*
* 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
.
cli
.
compiler
;
import
groovy.lang.Grab
;
import
groovy.lang.GroovyClassLoader
;
import
java.util.List
;
import
org.codehaus.groovy.ast.AnnotationNode
;
import
org.codehaus.groovy.ast.ClassNode
;
import
org.codehaus.groovy.ast.ModuleNode
;
import
org.codehaus.groovy.ast.expr.ConstantExpression
;
import
org.codehaus.groovy.control.SourceUnit
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesResolver
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
* Tests for {@link DependencyCustomizer}
*
* @author Andy Wilkinson
*/
public
class
DependencyCustomizerTests
{
private
final
ModuleNode
moduleNode
=
new
ModuleNode
((
SourceUnit
)
null
);
private
final
ClassNode
classNode
=
new
ClassNode
(
DependencyCustomizerTests
.
class
);
@Mock
private
ArtifactCoordinatesResolver
resolver
;
private
DependencyCustomizer
dependencyCustomizer
;
@Before
public
void
setUp
()
{
MockitoAnnotations
.
initMocks
(
this
);
when
(
this
.
resolver
.
getGroupId
(
"spring-boot-starter-logging"
)).
thenReturn
(
"org.springframework.boot"
);
when
(
this
.
resolver
.
getVersion
(
"spring-boot-starter-logging"
)).
thenReturn
(
"1.2.3"
);
this
.
moduleNode
.
addClass
(
this
.
classNode
);
this
.
dependencyCustomizer
=
new
DependencyCustomizer
(
new
GroovyClassLoader
(
getClass
().
getClassLoader
()),
this
.
moduleNode
,
this
.
resolver
);
}
@Test
public
void
basicAdd
()
{
this
.
dependencyCustomizer
.
add
(
"spring-boot-starter-logging"
);
List
<
AnnotationNode
>
grabAnnotations
=
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
));
assertEquals
(
1
,
grabAnnotations
.
size
());
AnnotationNode
annotationNode
=
grabAnnotations
.
get
(
0
);
assertGrabAnnotation
(
annotationNode
,
"org.springframework.boot"
,
"spring-boot-starter-logging"
,
true
);
}
@Test
public
void
anyMissingClassesWithMissingClassesPerformsAdd
()
{
this
.
dependencyCustomizer
.
ifAnyMissingClasses
(
"does.not.Exist"
).
add
(
"spring-boot-starter-logging"
);
assertEquals
(
1
,
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
)).
size
());
}
@Test
public
void
anyMissingClassesWithMixtureOfClassesPerformsAdd
()
{
this
.
dependencyCustomizer
.
ifAnyMissingClasses
(
getClass
().
getName
(),
"does.not.Exist"
).
add
(
"spring-boot-starter-logging"
);
assertEquals
(
1
,
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
)).
size
());
}
@Test
public
void
anyMissingClassesWithNoMissingClassesDoesNotPerformAdd
()
{
this
.
dependencyCustomizer
.
ifAnyMissingClasses
(
getClass
().
getName
()).
add
(
"spring-boot-starter-logging"
);
assertEquals
(
0
,
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
)).
size
());
}
@Test
public
void
allMissingClassesWithNoMissingClassesDoesNotPerformAdd
()
{
this
.
dependencyCustomizer
.
ifAllMissingClasses
(
getClass
().
getName
()).
add
(
"spring-boot-starter-logging"
);
assertEquals
(
0
,
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
)).
size
());
}
@Test
public
void
allMissingClassesWithMixtureOfClassesDoesNotPerformAdd
()
{
this
.
dependencyCustomizer
.
ifAllMissingClasses
(
getClass
().
getName
(),
"does.not.Exist"
).
add
(
"spring-boot-starter-logging"
);
assertEquals
(
0
,
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
)).
size
());
}
@Test
public
void
allMissingClassesWithAllClassesMissingPerformsAdd
()
{
this
.
dependencyCustomizer
.
ifAllMissingClasses
(
"does.not.Exist"
,
"does.not.exist.Either"
).
add
(
"spring-boot-starter-logging"
);
assertEquals
(
1
,
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
)).
size
());
}
@Test
public
void
nonTransitiveAdd
()
{
this
.
dependencyCustomizer
.
add
(
"spring-boot-starter-logging"
,
false
);
List
<
AnnotationNode
>
grabAnnotations
=
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
));
assertEquals
(
1
,
grabAnnotations
.
size
());
AnnotationNode
annotationNode
=
grabAnnotations
.
get
(
0
);
assertGrabAnnotation
(
annotationNode
,
"org.springframework.boot"
,
"spring-boot-starter-logging"
,
false
);
}
private
void
assertGrabAnnotation
(
AnnotationNode
annotationNode
,
String
group
,
String
module
,
boolean
transitive
)
{
assertEquals
(
group
,
getMemberValue
(
annotationNode
,
"group"
));
assertEquals
(
module
,
getMemberValue
(
annotationNode
,
"module"
));
assertEquals
(
transitive
,
getMemberValue
(
annotationNode
,
"transitive"
));
}
private
Object
getMemberValue
(
AnnotationNode
annotationNode
,
String
member
)
{
return
((
ConstantExpression
)
annotationNode
.
getMember
(
member
)).
getValue
();
}
}
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