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
df476bed
Commit
df476bed
authored
Jan 03, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure local repository cache is always used
parent
47a0df1e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
81 additions
and
30 deletions
+81
-30
GrabCommand.java
...ava/org/springframework/boot/cli/command/GrabCommand.java
+0
-25
RepositoryConfigurationFactory.java
...ork/boot/cli/compiler/RepositoryConfigurationFactory.java
+26
-0
AetherGrapeEngine.java
...gframework/boot/cli/compiler/grape/AetherGrapeEngine.java
+5
-1
RepositoryConfiguration.java
...work/boot/cli/compiler/grape/RepositoryConfiguration.java
+32
-0
CliTester.java
...src/test/java/org/springframework/boot/cli/CliTester.java
+8
-2
GrabCommandIntegrationTests.java
...springframework/boot/cli/GrabCommandIntegrationTests.java
+1
-2
SpringCliTests.java
...est/java/org/springframework/boot/cli/SpringCliTests.java
+9
-0
No files found.
spring-boot-cli/src/main/java/org/springframework/boot/cli/command/GrabCommand.java
View file @
df476bed
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
package
org
.
springframework
.
boot
.
cli
.
command
;
package
org
.
springframework
.
boot
.
cli
.
command
;
import
java.io.File
;
import
java.util.List
;
import
java.util.List
;
import
joptsimple.OptionSet
;
import
joptsimple.OptionSet
;
...
@@ -27,7 +26,6 @@ import org.springframework.boot.cli.compiler.GroovyCompilerConfiguration;
...
@@ -27,7 +26,6 @@ import org.springframework.boot.cli.compiler.GroovyCompilerConfiguration;
import
org.springframework.boot.cli.compiler.GroovyCompilerConfigurationAdapter
;
import
org.springframework.boot.cli.compiler.GroovyCompilerConfigurationAdapter
;
import
org.springframework.boot.cli.compiler.RepositoryConfigurationFactory
;
import
org.springframework.boot.cli.compiler.RepositoryConfigurationFactory
;
import
org.springframework.boot.cli.compiler.grape.RepositoryConfiguration
;
import
org.springframework.boot.cli.compiler.grape.RepositoryConfiguration
;
import
org.springframework.util.StringUtils
;
/**
/**
* {@link Command} to grab the dependencies of one or more Groovy scripts
* {@link Command} to grab the dependencies of one or more Groovy scripts
...
@@ -57,33 +55,10 @@ public class GrabCommand extends OptionParsingCommand {
...
@@ -57,33 +55,10 @@ public class GrabCommand extends OptionParsingCommand {
System
.
setProperty
(
"grape.root"
,
"."
);
System
.
setProperty
(
"grape.root"
,
"."
);
}
}
if
(!
new
File
(
System
.
getProperty
(
"grape.root"
)).
equals
(
getM2HomeDirectory
()))
{
GrabCommand
.
addDefaultCacheAsRespository
(
repositoryConfiguration
);
}
GroovyCompiler
groovyCompiler
=
new
GroovyCompiler
(
configuration
);
GroovyCompiler
groovyCompiler
=
new
GroovyCompiler
(
configuration
);
groovyCompiler
.
compile
(
fileOptions
.
getFilesArray
());
groovyCompiler
.
compile
(
fileOptions
.
getFilesArray
());
}
}
}
}
/**
* Add the default local M2 cache directory as a remote repository. Only do this if
* the local cache location has been changed from the default.
*
* @param repositoryConfiguration
*/
public
static
void
addDefaultCacheAsRespository
(
List
<
RepositoryConfiguration
>
repositoryConfiguration
)
{
repositoryConfiguration
.
add
(
0
,
new
RepositoryConfiguration
(
"local"
,
new
File
(
getM2HomeDirectory
(),
"repository"
).
toURI
(),
true
));
}
private
static
File
getM2HomeDirectory
()
{
String
mavenRoot
=
System
.
getProperty
(
"maven.home"
);
if
(
StringUtils
.
hasLength
(
mavenRoot
))
{
return
new
File
(
mavenRoot
);
}
return
new
File
(
System
.
getProperty
(
"user.home"
),
".m2"
);
}
}
}
spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/RepositoryConfigurationFactory.java
View file @
df476bed
...
@@ -16,11 +16,13 @@
...
@@ -16,11 +16,13 @@
package
org
.
springframework
.
boot
.
cli
.
compiler
;
package
org
.
springframework
.
boot
.
cli
.
compiler
;
import
java.io.File
;
import
java.net.URI
;
import
java.net.URI
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
org.springframework.boot.cli.compiler.grape.RepositoryConfiguration
;
import
org.springframework.boot.cli.compiler.grape.RepositoryConfiguration
;
import
org.springframework.util.StringUtils
;
/**
/**
* Factory used to create {@link RepositoryConfiguration}s.
* Factory used to create {@link RepositoryConfiguration}s.
...
@@ -52,7 +54,31 @@ public final class RepositoryConfigurationFactory {
...
@@ -52,7 +54,31 @@ public final class RepositoryConfigurationFactory {
repositoryConfiguration
.
add
(
SPRING_MILESTONE
);
repositoryConfiguration
.
add
(
SPRING_MILESTONE
);
}
}
addDefaultCacheAsRespository
(
repositoryConfiguration
);
return
repositoryConfiguration
;
return
repositoryConfiguration
;
}
}
/**
* Add the default local M2 cache directory as a remote repository. Only do this if
* the local cache location has been changed from the default.
*
* @param repositoryConfiguration
*/
public
static
void
addDefaultCacheAsRespository
(
List
<
RepositoryConfiguration
>
repositoryConfiguration
)
{
RepositoryConfiguration
repository
=
new
RepositoryConfiguration
(
"local"
,
new
File
(
getM2HomeDirectory
(),
"repository"
).
toURI
(),
true
);
if
(!
repositoryConfiguration
.
contains
(
repository
))
{
repositoryConfiguration
.
add
(
0
,
repository
);
}
}
private
static
File
getM2HomeDirectory
()
{
String
mavenRoot
=
System
.
getProperty
(
"maven.home"
);
if
(
StringUtils
.
hasLength
(
mavenRoot
))
{
return
new
File
(
mavenRoot
);
}
return
new
File
(
System
.
getProperty
(
"user.home"
),
".m2"
);
}
}
}
spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java
View file @
df476bed
...
@@ -25,6 +25,7 @@ import java.net.URI;
...
@@ -25,6 +25,7 @@ import java.net.URI;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -95,7 +96,10 @@ public class AetherGrapeEngine implements GrapeEngine {
...
@@ -95,7 +96,10 @@ public class AetherGrapeEngine implements GrapeEngine {
session
.
setProxySelector
(
this
.
proxySelector
);
session
.
setProxySelector
(
this
.
proxySelector
);
this
.
session
=
session
;
this
.
session
=
session
;
this
.
repositories
=
new
ArrayList
<
RemoteRepository
>();
this
.
repositories
=
new
ArrayList
<
RemoteRepository
>();
for
(
RemoteRepository
repository
:
remoteRepositories
)
{
List
<
RemoteRepository
>
remotes
=
new
ArrayList
<
RemoteRepository
>(
remoteRepositories
);
Collections
.
reverse
(
remotes
);
// priority is reversed in addRepository
for
(
RemoteRepository
repository
:
remotes
)
{
addRepository
(
repository
);
addRepository
(
repository
);
}
}
this
.
progressReporter
=
getProgressReporter
(
session
);
this
.
progressReporter
=
getProgressReporter
(
session
);
...
...
spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/RepositoryConfiguration.java
View file @
df476bed
...
@@ -52,6 +52,12 @@ public final class RepositoryConfiguration {
...
@@ -52,6 +52,12 @@ public final class RepositoryConfiguration {
return
this
.
name
;
return
this
.
name
;
}
}
@Override
public
String
toString
()
{
return
"RepositoryConfiguration [name="
+
this
.
name
+
", uri="
+
this
.
uri
+
", snapshotsEnabled="
+
this
.
snapshotsEnabled
+
"]"
;
}
/**
/**
* @return the uri of the repository
* @return the uri of the repository
*/
*/
...
@@ -67,4 +73,30 @@ public final class RepositoryConfiguration {
...
@@ -67,4 +73,30 @@ public final class RepositoryConfiguration {
return
this
.
snapshotsEnabled
;
return
this
.
snapshotsEnabled
;
}
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
((
this
.
name
==
null
)
?
0
:
this
.
name
.
hashCode
());
return
result
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
RepositoryConfiguration
other
=
(
RepositoryConfiguration
)
obj
;
if
(
this
.
name
==
null
)
{
if
(
other
.
name
!=
null
)
return
false
;
}
else
if
(!
this
.
name
.
equals
(
other
.
name
))
return
false
;
return
true
;
}
}
}
\ No newline at end of file
spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java
View file @
df476bed
...
@@ -88,8 +88,14 @@ public class CliTester implements TestRule {
...
@@ -88,8 +88,14 @@ public class CliTester implements TestRule {
return
Executors
.
newSingleThreadExecutor
().
submit
(
new
Callable
<
T
>()
{
return
Executors
.
newSingleThreadExecutor
().
submit
(
new
Callable
<
T
>()
{
@Override
@Override
public
T
call
()
throws
Exception
{
public
T
call
()
throws
Exception
{
command
.
run
(
sources
);
ClassLoader
loader
=
Thread
.
currentThread
().
getContextClassLoader
();
return
command
;
try
{
command
.
run
(
sources
);
return
command
;
}
finally
{
Thread
.
currentThread
().
setContextClassLoader
(
loader
);
}
}
}
});
});
}
}
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/GrabCommandIntegrationTests.java
View file @
df476bed
...
@@ -54,9 +54,8 @@ public class GrabCommandIntegrationTests {
...
@@ -54,9 +54,8 @@ public class GrabCommandIntegrationTests {
// Use --autoconfigure=false to limit the amount of downloaded dependencies
// Use --autoconfigure=false to limit the amount of downloaded dependencies
String
output
=
this
.
cli
.
grab
(
"grab.groovy"
,
"--autoconfigure=false"
);
String
output
=
this
.
cli
.
grab
(
"grab.groovy"
,
"--autoconfigure=false"
);
assertTrue
(
output
.
contains
(
"Downloading: file:"
));
assertTrue
(
new
File
(
"target/repository/net/sf/jopt-simple/jopt-simple"
)
assertTrue
(
new
File
(
"target/repository/net/sf/jopt-simple/jopt-simple"
)
.
isDirectory
());
.
isDirectory
());
assertTrue
(
output
.
contains
(
"Downloading: file:"
));
}
}
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/SpringCliTests.java
View file @
df476bed
...
@@ -20,6 +20,7 @@ import java.util.Arrays;
...
@@ -20,6 +20,7 @@ import java.util.Arrays;
import
java.util.EnumSet
;
import
java.util.EnumSet
;
import
java.util.Set
;
import
java.util.Set
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -60,8 +61,16 @@ public class SpringCliTests {
...
@@ -60,8 +61,16 @@ public class SpringCliTests {
private
Set
<
Call
>
calls
=
EnumSet
.
noneOf
(
Call
.
class
);
private
Set
<
Call
>
calls
=
EnumSet
.
noneOf
(
Call
.
class
);
private
ClassLoader
loader
;
@After
public
void
close
()
{
Thread
.
currentThread
().
setContextClassLoader
(
this
.
loader
);
}
@Before
@Before
public
void
setup
()
{
public
void
setup
()
{
this
.
loader
=
Thread
.
currentThread
().
getContextClassLoader
();
MockitoAnnotations
.
initMocks
(
this
);
MockitoAnnotations
.
initMocks
(
this
);
this
.
cli
=
new
SpringCli
()
{
this
.
cli
=
new
SpringCli
()
{
...
...
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