@Override protected ExitStatus run(OptionSet options) throws Exception { SourceOptions sourceOptions = new SourceOptions(options); List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); GroovyCompilerConfiguration configuration = new OptionSetGroovyCompilerConfiguration( options, this, repositoryConfiguration); if (System.getProperty("grape.root") == null) { System.setProperty("grape.root", "."); } GroovyCompiler groovyCompiler = new GroovyCompiler(configuration); groovyCompiler.compile(sourceOptions.getSourcesArray()); return ExitStatus.OK; }
@Override protected synchronized ExitStatus run(OptionSet options) throws Exception { synchronized (this.monitor) { if (this.runner != null) { throw new RuntimeException( "Already running. Please stop the current application before running another (use the 'stop' command)."); } SourceOptions sourceOptions = new SourceOptions(options); List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); repositoryConfiguration.add(0, new RepositoryConfiguration("local", new File("repository").toURI(), true)); SpringApplicationRunnerConfiguration configuration = new SpringApplicationRunnerConfigurationAdapter( options, this, repositoryConfiguration); this.runner = new SpringApplicationRunner(configuration, sourceOptions.getSourcesArray(), sourceOptions.getArgsArray()); this.runner.compileAndRun(); return ExitStatus.OK; } }
@Override protected synchronized ExitStatus run(OptionSet options) throws Exception { if (this.runner != null) { throw new RuntimeException( "Already running. Please stop the current application before running another (use the 'stop' command)."); } SourceOptions sourceOptions = new SourceOptions(options); List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); repositoryConfiguration.add(0, new RepositoryConfiguration("local", new File("repository").toURI(), true)); SpringApplicationRunnerConfiguration configuration = new SpringApplicationRunnerConfigurationAdapter( options, this, repositoryConfiguration); this.runner = new SpringApplicationRunner(configuration, sourceOptions.getSourcesArray(), sourceOptions.getArgsArray()); this.runner.compileAndRun(); return ExitStatus.OK; }
private GroovyCompiler createCompiler(OptionSet options) { List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); GroovyCompilerConfiguration configuration = new OptionSetGroovyCompilerConfiguration( options, this, repositoryConfiguration); GroovyCompiler groovyCompiler = new GroovyCompiler(configuration); groovyCompiler.getAstTransformations().add(0, new GrabAnnotationTransform()); return groovyCompiler; }
public OptionSetGroovyCompilerConfiguration(OptionSet optionSet, CompilerOptionHandler compilerOptionHandler, List<RepositoryConfiguration> repositoryConfiguration) { this.options = optionSet; this.optionHandler = compilerOptionHandler; this.repositoryConfiguration = repositoryConfiguration; }
private static GroovyCompilerConfiguration createCompilerConfiguration( OptionSet options, CompilerOptionHandler compilerOptionHandler) { List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); return new OptionSetGroovyCompilerConfiguration(options, compilerOptionHandler, repositoryConfiguration) { @Override public boolean isAutoconfigure() { return false; } }; }
/** * Create a new default repository configuration. * @return the newly-created default repository configuration */ public static List<RepositoryConfiguration> createDefaultRepositoryConfiguration() { MavenSettings mavenSettings = new MavenSettingsReader().readSettings(); List<RepositoryConfiguration> repositoryConfiguration = new ArrayList<RepositoryConfiguration>(); repositoryConfiguration.add(MAVEN_CENTRAL); if (!Boolean.getBoolean("disableSpringSnapshotRepos")) { repositoryConfiguration.add(SPRING_MILESTONE); repositoryConfiguration.add(SPRING_SNAPSHOT); } addDefaultCacheAsRepository(mavenSettings.getLocalRepository(), repositoryConfiguration); addActiveProfileRepositories(mavenSettings.getActiveProfiles(), repositoryConfiguration); return repositoryConfiguration; }
private static void addDefaultCacheAsRepository(String localRepository, List<RepositoryConfiguration> repositoryConfiguration) { RepositoryConfiguration repository = new RepositoryConfiguration("local", getLocalRepositoryDirectory(localRepository).toURI(), true); if (!repositoryConfiguration.contains(repository)) { repositoryConfiguration.add(0, repository); } }
private static void addActiveProfileRepositories(List<Profile> activeProfiles, List<RepositoryConfiguration> configurations) { for (Profile activeProfile : activeProfiles) { Interpolator interpolator = new RegexBasedInterpolator(); interpolator.addValueSource( new PropertiesBasedValueSource(activeProfile.getProperties())); for (Repository repository : activeProfile.getRepositories()) { configurations.add(getRepositoryConfiguration(interpolator, repository)); } } }
private static RepositoryConfiguration getRepositoryConfiguration( Interpolator interpolator, Repository repository) { String name = interpolate(interpolator, repository.getId()); String url = interpolate(interpolator, repository.getUrl()); boolean snapshotsEnabled = false; if (repository.getSnapshots() != null) { snapshotsEnabled = repository.getSnapshots().isEnabled(); } return new RepositoryConfiguration(name, URI.create(url), snapshotsEnabled); }
@Before public void setupResolver() { GroovyCompilerConfiguration configuration = new GroovyCompilerConfiguration() { @Override public boolean isGuessImports() { return true; } @Override public boolean isGuessDependencies() { return true; } @Override public boolean isAutoconfigure() { return false; } @Override public GroovyCompilerScope getScope() { return GroovyCompilerScope.DEFAULT; } @Override public List<RepositoryConfiguration> getRepositoryConfiguration() { return RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); } @Override public String[] getClasspath() { return new String[] { "." }; } }; this.resolver = new GroovyGrabDependencyResolver(configuration); }
@Test public void defaultRepositories() { SystemProperties.doWithSystemProperties(new Runnable() { @Override public void run() { List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); assertRepositoryConfiguration(repositoryConfiguration, "central", "local", "spring-snapshot", "spring-milestone"); } }, "user.home:src/test/resources/maven-settings/basic"); }
@Test public void snapshotRepositoriesDisabled() { SystemProperties.doWithSystemProperties(new Runnable() { @Override public void run() { List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); assertRepositoryConfiguration(repositoryConfiguration, "central", "local"); } }, "user.home:src/test/resources/maven-settings/basic", "disableSpringSnapshotRepos:true"); }
@Test public void activeByDefaultProfileRepositories() { SystemProperties.doWithSystemProperties(new Runnable() { @Override public void run() { List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); assertRepositoryConfiguration(repositoryConfiguration, "central", "local", "spring-snapshot", "spring-milestone", "active-by-default"); } }, "user.home:src/test/resources/maven-settings/active-profile-repositories"); }
@Test public void activeByPropertyProfileRepositories() { SystemProperties.doWithSystemProperties(new Runnable() { @Override public void run() { List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); assertRepositoryConfiguration(repositoryConfiguration, "central", "local", "spring-snapshot", "spring-milestone", "active-by-property"); } }, "user.home:src/test/resources/maven-settings/active-profile-repositories", "foo:bar"); }
@Test public void interpolationProfileRepositories() { SystemProperties.doWithSystemProperties(new Runnable() { @Override public void run() { List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); assertRepositoryConfiguration(repositoryConfiguration, "central", "local", "spring-snapshot", "spring-milestone", "interpolate-releases", "interpolate-snapshots"); } }, "user.home:src/test/resources/maven-settings/active-profile-repositories", "interpolate:true"); }
private void assertRepositoryConfiguration( List<RepositoryConfiguration> configurations, String... expectedNames) { assertThat(configurations).hasSize(expectedNames.length); Set<String> actualNames = new HashSet<String>(); for (RepositoryConfiguration configuration : configurations) { actualNames.add(configuration.getName()); } assertThat(actualNames).containsOnly(expectedNames); }
private static void addActiveProfileRepositories(List<Profile> activeProfiles, List<RepositoryConfiguration> repositoryConfiguration) { for (Profile activeProfile : activeProfiles) { for (Repository repository : activeProfile.getRepositories()) { repositoryConfiguration.add(new RepositoryConfiguration( repository.getId(), URI.create(repository.getUrl()), repository.getSnapshots() != null ? repository.getSnapshots().isEnabled() : false)); } } }