Java Code Examples for org.springframework.core.io.FileUrlResource

The following examples show how to use org.springframework.core.io.FileUrlResource. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void setupUpgradeDueToResourceChange() throws IOException{
	TaskExecution myTask = this.taskRepository.createTaskExecution(TASK_NAME_ORIG);
	TaskManifest manifest = new TaskManifest();
	manifest.setPlatformName("default");
	AppDeploymentRequest request = new AppDeploymentRequest(new AppDefinition("some-name", null),
			new FileUrlResource("src/test/resources/apps"));
	manifest.setTaskDeploymentRequest(request);

	this.dataflowTaskExecutionMetadataDao.save(myTask, manifest);
	this.taskRepository.startTaskExecution(myTask.getExecutionId(), TASK_NAME_ORIG, new Date(), new ArrayList<>(), null);
	this.taskRepository.completeTaskExecution(myTask.getExecutionId(), 0, new Date(), null);

	initializeSuccessfulRegistry(appRegistry);

	when(taskLauncher.launch(any())).thenReturn("0");

	this.taskExecutionService.executeTask(TASK_NAME_ORIG, new HashMap<>(), new LinkedList<>());

	TaskManifest lastManifest = this.dataflowTaskExecutionMetadataDao.getLatestManifest(TASK_NAME_ORIG);
	assertEquals("file:src/test/resources/apps/foo-task", lastManifest.getTaskDeploymentRequest().getResource().getURL().toString());
	assertEquals("default", lastManifest.getPlatformName());
}
 
Example 2
@Test
@DirtiesContext
public void testUpgradeDueToDeploymentPropsChangeForCloudFoundryFailsWhenAlreadyRunning() throws IOException {
	this.launcherRepository.delete(this.launcher);
	this.launcherRepository.save(new Launcher("default", "Cloud Foundry", taskLauncher));
	initializeSuccessfulRegistry(appRegistry);
	TaskExecution myTask = this.taskRepository.createTaskExecution(TASK_NAME_ORIG);
	TaskManifest manifest = new TaskManifest();
	manifest.setPlatformName("default");
	AppDeploymentRequest request = new AppDeploymentRequest(new AppDefinition("some-name", null),
			new FileUrlResource("src/test/resources/apps/foo-task"));
	manifest.setTaskDeploymentRequest(request);
	this.dataflowTaskExecutionMetadataDao.save(myTask, manifest);
	this.taskRepository.startTaskExecution(myTask.getExecutionId(), TASK_NAME_ORIG, new Date(), new ArrayList<>(), null);
	this.taskRepository.updateExternalExecutionId(myTask.getExecutionId(), "abc");
	when(this.taskLauncher.launch(any())).thenReturn("abc");
	when(this.taskLauncher.status("abc")).thenReturn(new TaskStatus("abc", LaunchState.running,new HashMap<>()));
	thrown.expect(IllegalStateException.class);
	thrown.expectMessage("Unable to update application due to currently running applications");
	this.taskExecutionService.executeTask(TASK_NAME_ORIG, new HashMap<>(), new LinkedList<>());
}
 
Example 3
@Test
@DirtiesContext
public void testUpgradeDueToDeploymentPropsChangeForCloudFoundrySucceedsIfNotReallyRunning() throws IOException {
	this.launcherRepository.delete(this.launcher);
	this.launcherRepository.save(new Launcher("default", "Cloud Foundry", taskLauncher));
	initializeSuccessfulRegistry(appRegistry);
	TaskExecution myTask = this.taskRepository.createTaskExecution(TASK_NAME_ORIG);
	TaskManifest manifest = new TaskManifest();
	manifest.setPlatformName("default");
	AppDeploymentRequest request = new AppDeploymentRequest(new AppDefinition("some-name", null),
			new FileUrlResource("src/test/resources/apps/foo-task"));
	manifest.setTaskDeploymentRequest(request);
	this.dataflowTaskExecutionMetadataDao.save(myTask, manifest);
	this.taskRepository.startTaskExecution(myTask.getExecutionId(), TASK_NAME_ORIG, new Date(), new ArrayList<>(), null);
	this.taskRepository.updateExternalExecutionId(myTask.getExecutionId(), "abc");
	when(this.taskLauncher.launch(any())).thenReturn("abc");
	when(this.taskLauncher.status("abc")).thenReturn(new TaskStatus("abc", LaunchState.failed, new HashMap<>()));
	this.taskExecutionService.executeTask(TASK_NAME_ORIG, new HashMap<>(), new LinkedList<>());
	verify(this.taskLauncher).destroy(TASK_NAME_ORIG);
}
 
Example 4
Source Project: spring-init   Source File: SimpleProcessorTests.java    License: Apache License 2.0 5 votes vote down vote up
private List<File> getSpringDependencies() {
	try {
		File f = new File("pom.xml");
		DependencyResolver engine = DependencyResolver.instance();
		List<Dependency> dependencies = engine.dependencies(new FileUrlResource(f.toURI().toURL()));
		List<File> resolvedDependencies = dependencies.stream().map(d -> engine.resolve(d))
				.collect(Collectors.toList());
		return resolvedDependencies;
	}
	catch (Exception e) {
		return null;
	}
}
 
Example 5
private static void initializeSuccessfulRegistry(AppRegistryService appRegistry) {
	when(appRegistry.find(anyString(), any(ApplicationType.class))).thenReturn(
			new AppRegistration("some-name", ApplicationType.task, URI.create("https://helloworld")));
	try {
		when(appRegistry.getAppResource(any())).thenReturn(new FileUrlResource("src/test/resources/apps/foo-task"));
	}
	catch (MalformedURLException e) {
		throw new IllegalStateException("Invalid File Resource Specified", e);
	}
	when(appRegistry.getAppMetadataResource(any())).thenReturn(null);
}
 
Example 6
private void setupUpgradeDueToDeploymentPropsChangeForCloudFoundry() throws IOException {
	TaskExecution myTask = this.taskRepository.createTaskExecution(TASK_NAME_ORIG);
	TaskManifest manifest = new TaskManifest();
	manifest.setPlatformName("default");
	AppDeploymentRequest request = new AppDeploymentRequest(new AppDefinition("some-name", null),
			new FileUrlResource("src/test/resources/apps/foo-task"));
	manifest.setTaskDeploymentRequest(request);

	this.dataflowTaskExecutionMetadataDao.save(myTask, manifest);
	this.taskRepository.startTaskExecution(myTask.getExecutionId(), TASK_NAME_ORIG, new Date(), new ArrayList<>(), null);
	this.taskRepository.completeTaskExecution(myTask.getExecutionId(), 0, new Date(), null);
	this.taskRepository.updateExternalExecutionId(myTask.getExecutionId(), "0");

	initializeSuccessfulRegistry(appRegistry);

	when(taskLauncher.launch(any())).thenReturn("0");

	Map<String,String> deploymentProperties = new HashMap<>(1);
	deploymentProperties.put("deployer.demo.memory", "10000GB");

	this.taskExecutionService.executeTask(TASK_NAME_ORIG, deploymentProperties, new LinkedList<>());

	TaskManifest lastManifest = this.dataflowTaskExecutionMetadataDao.getLatestManifest(TASK_NAME_ORIG);

	assertEquals("file:src/test/resources/apps/foo-task", lastManifest.getTaskDeploymentRequest().getResource().getURL().toString());
	assertEquals("default", lastManifest.getPlatformName());
	assertEquals(1, lastManifest.getTaskDeploymentRequest().getDeploymentProperties().size());
	assertEquals("10000GB", lastManifest.getTaskDeploymentRequest().getDeploymentProperties().get("spring.cloud.deployer.memory"));

}
 
Example 7
private void setupUpgradeForCommandLineArgsChange() throws IOException {
 TaskExecution myTask = this.taskRepository.createTaskExecution(TASK_NAME_ORIG);
 TaskManifest manifest = new TaskManifest();
 manifest.setPlatformName("default");
 AppDeploymentRequest request = new AppDeploymentRequest(new AppDefinition("some-name", null),
		 new FileUrlResource("src/test/resources/apps/foo-task"));
 manifest.setTaskDeploymentRequest(request);

 this.dataflowTaskExecutionMetadataDao.save(myTask, manifest);
 this.taskRepository.startTaskExecution(myTask.getExecutionId(), TASK_NAME_ORIG, new Date(), new ArrayList<>(), null);
 this.taskRepository.completeTaskExecution(myTask.getExecutionId(), 0, new Date(), null);

 initializeSuccessfulRegistry(appRegistry);

 when(taskLauncher.launch(any())).thenReturn("0");

 Map<String,String> deploymentProperties = new HashMap<>(1);

 this.taskExecutionService.executeTask(TASK_NAME_ORIG, deploymentProperties, Collections.singletonList("--foo=bar"));
 TaskManifest lastManifest = this.dataflowTaskExecutionMetadataDao.getLatestManifest(TASK_NAME_ORIG);
 assertEquals(3, lastManifest.getTaskDeploymentRequest().getCommandlineArguments().size());
 assertEquals("--foo=bar", lastManifest.getTaskDeploymentRequest().getCommandlineArguments().get(0));

 this.taskExecutionService.executeTask(TASK_NAME_ORIG, deploymentProperties, Collections.emptyList());
 lastManifest = this.dataflowTaskExecutionMetadataDao.getLatestManifest(TASK_NAME_ORIG);
 assertEquals(2, lastManifest.getTaskDeploymentRequest().getCommandlineArguments().size());
}
 
Example 8
private void setupUpgradeForAppPropsChange() throws IOException {
	TaskExecution myTask = this.taskRepository.createTaskExecution(TASK_NAME_ORIG);
	TaskManifest manifest = new TaskManifest();
	manifest.setPlatformName("default");
	AppDeploymentRequest request = new AppDeploymentRequest(new AppDefinition("some-name", null),
			new FileUrlResource("src/test/resources/apps/foo-task"));
	manifest.setTaskDeploymentRequest(request);

	this.dataflowTaskExecutionMetadataDao.save(myTask, manifest);
	this.taskRepository.startTaskExecution(myTask.getExecutionId(), TASK_NAME_ORIG, new Date(), new ArrayList<>(), null);
	this.taskRepository.completeTaskExecution(myTask.getExecutionId(), 0, new Date(), null);

	initializeSuccessfulRegistry(appRegistry);

	when(taskLauncher.launch(any())).thenReturn("0");

	Map<String,String> deploymentProperties = new HashMap<>(1);
	deploymentProperties.put("app.demo.foo", "bar");

	this.taskExecutionService.executeTask(TASK_NAME_ORIG, deploymentProperties, new LinkedList<>());

	TaskManifest lastManifest = this.dataflowTaskExecutionMetadataDao.getLatestManifest(TASK_NAME_ORIG);

	assertEquals("file:src/test/resources/apps/foo-task", lastManifest.getTaskDeploymentRequest().getResource().getURL().toString());
	assertEquals("default", lastManifest.getPlatformName());
	assertEquals(5, lastManifest.getTaskDeploymentRequest().getDefinition().getProperties().size());
	assertEquals("bar", lastManifest.getTaskDeploymentRequest().getDefinition().getProperties().get("foo"));
}
 
Example 9
@Test(expected = IllegalStateException.class)
@DirtiesContext
public void testUpgradeFailureTaskCurrentlyRunning() throws MalformedURLException {
	TaskExecution myTask = this.taskRepository.createTaskExecution(TASK_NAME_ORIG);
	TaskManifest manifest = new TaskManifest();
	manifest.setPlatformName("default");
	AppDeploymentRequest request = new AppDeploymentRequest(new AppDefinition("some-name", null),
			new FileUrlResource("src/test/resources/apps/foo-task"));
	manifest.setTaskDeploymentRequest(request);

	this.dataflowTaskExecutionMetadataDao.save(myTask, manifest);

	initializeSuccessfulRegistry(appRegistry);
	this.taskExecutionService.executeTask(TASK_NAME_ORIG, new HashMap<>(), new LinkedList<>());
}
 
Example 10
private static void initializeSuccessfulRegistry(AppRegistryService appRegistry) {
	when(appRegistry.find(anyString(), any(ApplicationType.class))).thenReturn(
			new AppRegistration("some-name", ApplicationType.task, URI.create("https://helloworld")));
	try {
		when(appRegistry.getAppResource(any())).thenReturn(new FileUrlResource("src/test/resources/apps/foo-task"));
	}
	catch (MalformedURLException e) {
		throw new IllegalStateException("Invalid File Resource Specified", e);
	}
	when(appRegistry.getAppMetadataResource(any())).thenReturn(null);
}
 
Example 11
Source Project: tutorials   Source File: ReloadablePropertySourceFactory.java    License: MIT License 5 votes vote down vote up
@Override
public PropertySource<?> createPropertySource(String s, EncodedResource encodedResource) throws IOException {
    Resource internal = encodedResource.getResource();
    if (internal instanceof FileSystemResource) {
        return new ReloadablePropertySource(s, ((FileSystemResource) internal).getPath());
    }
    if (internal instanceof FileUrlResource) {
        return new ReloadablePropertySource(s, ((FileUrlResource) internal)
          .getURL()
          .getPath());
    }
    return super.createPropertySource(s, encodedResource);
}
 
Example 12
Source Project: spring-analysis-note   Source File: PathResourceResolverTests.java    License: MIT License 4 votes vote down vote up
@Test // gh-22272
public void resolveWithEncodedPath() throws IOException {
	Resource classpathLocation = new ClassPathResource("test/", PathResourceResolver.class);
	testWithEncodedPath(classpathLocation);
	testWithEncodedPath(new FileUrlResource(classpathLocation.getURL()));
}
 
Example 13
Source Project: spring-init   Source File: Utils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Use maven to resolve the dependencies of the specified folder (expected to contain
 * a pom), and then resolve them to either entries in the maven cache or as
 * target/classes folders in other modules in this project build.
 * 
 * @param projectRootFolder the project to be resolved (should contain the pom.xml)
 * @return a list of jars/folders - folders used for local
 */
public static List<File> resolveProjectDependencies(File projectRootFolder) {
	List<File> resolvedDependencies = resolvedDependenciesCache
			.get(projectRootFolder);
	if (resolvedDependencies == null) {
		long stime = System.currentTimeMillis();
		DependencyResolver engine = DependencyResolver.instance();
		try {
			File f = new File(projectRootFolder, "pom.xml");
			List<Dependency> dependencies = engine
					.dependencies(new FileUrlResource(f.toURI().toURL()));
			resolvedDependencies = new ArrayList<>();
			for (Dependency dependency : dependencies) {
				File resolvedDependency = null;
				// Example:
				// org.springframework.experimental:tests-lib:jar:1.0-SNAPSHOT
				if (dependency.toString().startsWith(PROJECT + ":")) {
					// Resolve locally
					StringTokenizer st = new StringTokenizer(dependency.toString(),
							":");
					st.nextToken();
					String submodule = st.nextToken();
					if (submodule.startsWith("spring-init-")) {
						submodule = submodule.substring("spring-init-".length());
					}
					resolvedDependency = new File(projectRootFolder,
							"../" + submodule + "/target/classes").getCanonicalFile();
					if (!resolvedDependency.exists()) {
						// try another place
						resolvedDependency = new File(projectRootFolder,
								"../../modules/" + submodule + "/target/classes")
										.getCanonicalFile();
					}
					if (!resolvedDependency.exists()) {
						// try another place
						resolvedDependency = new File(projectRootFolder,
								"../../generated/" + generated(submodule)
										+ "/target/classes").getCanonicalFile();
					}
					if (!resolvedDependency.exists()) {
						System.out.println("Bad miss? "
								+ resolvedDependency.getAbsolutePath().toString());
						resolvedDependency = null;
					}
				}
				if (resolvedDependency == null) {
					resolvedDependency = engine.resolve(dependency);
				}
				resolvedDependencies.add(resolvedDependency);
			}
			logger.debug("Resolved #{} dependencies in {}ms",
					resolvedDependencies.size(),
					(System.currentTimeMillis() - stime));
			resolvedDependenciesCache.put(projectRootFolder,
					Collections.unmodifiableList(resolvedDependencies));
		}
		catch (Throwable e) {
			throw new IllegalStateException(
					"Unexpected problem resolving dependencies", e);
		}
	}
	return resolvedDependencies;
}