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
12ede868
Commit
12ede868
authored
Apr 30, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent duplicate files from getting onto sources
parent
7a33afa7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
+22
-2
ResourceUtils.java
...java/org/springframework/boot/cli/util/ResourceUtils.java
+9
-2
ResourceUtilsTests.java
...org/springframework/boot/cli/util/ResourceUtilsTests.java
+13
-0
No files found.
spring-boot-cli/src/main/java/org/springframework/boot/cli/util/ResourceUtils.java
View file @
12ede868
...
@@ -115,7 +115,7 @@ public abstract class ResourceUtils {
...
@@ -115,7 +115,7 @@ public abstract class ResourceUtils {
continue
;
continue
;
}
}
}
}
result
.
add
(
resource
.
getURL
().
toExternalForm
(
));
result
.
add
(
absolutePath
(
resource
));
}
}
}
}
return
result
;
return
result
;
...
@@ -127,12 +127,19 @@ public abstract class ResourceUtils {
...
@@ -127,12 +127,19 @@ public abstract class ResourceUtils {
List
<
String
>
childFiles
=
new
ArrayList
<
String
>();
List
<
String
>
childFiles
=
new
ArrayList
<
String
>();
for
(
Resource
child
:
children
)
{
for
(
Resource
child
:
children
)
{
if
(!
child
.
getFile
().
isDirectory
())
{
if
(!
child
.
getFile
().
isDirectory
())
{
childFiles
.
add
(
child
.
getURL
().
toExternalForm
(
));
childFiles
.
add
(
absolutePath
(
child
));
}
}
}
}
return
childFiles
;
return
childFiles
;
}
}
private
static
String
absolutePath
(
Resource
resource
)
throws
IOException
{
if
(!
resource
.
getURI
().
getScheme
().
equals
(
"file"
))
{
return
resource
.
getURL
().
toExternalForm
();
}
return
resource
.
getFile
().
getAbsoluteFile
().
toURI
().
toString
();
}
private
static
String
stripLeadingSlashes
(
String
path
)
{
private
static
String
stripLeadingSlashes
(
String
path
)
{
while
(
path
.
startsWith
(
"/"
))
{
while
(
path
.
startsWith
(
"/"
))
{
path
=
path
.
substring
(
1
);
path
=
path
.
substring
(
1
);
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/util/ResourceUtilsTests.java
View file @
12ede868
...
@@ -16,6 +16,9 @@
...
@@ -16,6 +16,9 @@
package
org
.
springframework
.
boot
.
cli
.
util
;
package
org
.
springframework
.
boot
.
cli
.
util
;
import
java.io.File
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.util.List
;
import
java.util.List
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -39,6 +42,16 @@ public class ResourceUtilsTests {
...
@@ -39,6 +42,16 @@ public class ResourceUtilsTests {
assertTrue
(
urls
.
get
(
0
).
startsWith
(
"file:"
));
assertTrue
(
urls
.
get
(
0
).
startsWith
(
"file:"
));
}
}
@Test
public
void
duplicateResource
()
throws
Exception
{
URLClassLoader
loader
=
new
URLClassLoader
(
new
URL
[]
{
new
URL
(
"file:./src/test/resources/"
),
new
File
(
"src/test/resources/"
).
getAbsoluteFile
().
toURI
().
toURL
()
});
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"classpath:init.groovy"
,
loader
);
assertEquals
(
1
,
urls
.
size
());
assertTrue
(
urls
.
get
(
0
).
startsWith
(
"file:"
));
}
@Test
@Test
public
void
explicitClasspathResourceWithSlash
()
{
public
void
explicitClasspathResourceWithSlash
()
{
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"classpath:/init.groovy"
,
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"classpath:/init.groovy"
,
...
...
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