当前位置: 首页>>代码示例>>Java>>正文


Java ClassLoaderFile类代码示例

本文整理汇总了Java中org.springframework.boot.devtools.restart.classloader.ClassLoaderFile的典型用法代码示例。如果您正苦于以下问题:Java ClassLoaderFile类的具体用法?Java ClassLoaderFile怎么用?Java ClassLoaderFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClassLoaderFile类属于org.springframework.boot.devtools.restart.classloader包,在下文中一共展示了ClassLoaderFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateAndRestart

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
/**
 * Update the current running application with the specified {@link ClassLoaderFiles}
 * and trigger a reload.
 * @param files updated class loader files
 */
public void updateAndRestart(ClassLoaderFiles files) {
	Set<URL> urls = new LinkedHashSet<URL>();
	Set<URL> classLoaderUrls = getClassLoaderUrls();
	for (SourceFolder folder : files.getSourceFolders()) {
		for (Entry<String, ClassLoaderFile> entry : folder.getFilesEntrySet()) {
			for (URL url : classLoaderUrls) {
				if (updateFileSystem(url, entry.getKey(), entry.getValue())) {
					urls.add(url);
				}
			}
		}
		urls.addAll(getMatchingUrls(classLoaderUrls, folder.getName()));
	}
	updateTimeStamp(urls);
	restart(urls, files);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:22,代码来源:RestartServer.java

示例2: updateFileSystem

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
private boolean updateFileSystem(URL url, String name,
		ClassLoaderFile classLoaderFile) {
	if (!isFolderUrl(url.toString())) {
		return false;
	}
	try {
		File folder = ResourceUtils.getFile(url);
		File file = new File(folder, name);
		if (file.exists() && file.canWrite()) {
			if (classLoaderFile.getKind() == Kind.DELETED) {
				return file.delete();
			}
			FileCopyUtils.copy(classLoaderFile.getContents(), file);
			return true;
		}
	}
	catch (IOException ex) {
		// Ignore
	}
	return false;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:22,代码来源:RestartServer.java

示例3: updateAndRestart

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
@Test
public void updateAndRestart() throws Exception {
	URL url1 = new URL("file:/proj/module-a.jar!/");
	URL url2 = new URL("file:/proj/module-b.jar!/");
	URL url3 = new URL("file:/proj/module-c.jar!/");
	URL url4 = new URL("file:/proj/module-d.jar!/");
	URLClassLoader classLoaderA = new URLClassLoader(new URL[] { url1, url2 });
	URLClassLoader classLoaderB = new URLClassLoader(new URL[] { url3, url4 },
			classLoaderA);
	SourceFolderUrlFilter filter = new DefaultSourceFolderUrlFilter();
	MockRestartServer server = new MockRestartServer(filter, classLoaderB);
	ClassLoaderFiles files = new ClassLoaderFiles();
	ClassLoaderFile fileA = new ClassLoaderFile(Kind.ADDED, new byte[0]);
	ClassLoaderFile fileB = new ClassLoaderFile(Kind.ADDED, new byte[0]);
	files.addFile("my/module-a", "ClassA.class", fileA);
	files.addFile("my/module-c", "ClassB.class", fileB);
	server.updateAndRestart(files);
	Set<URL> expectedUrls = new LinkedHashSet<URL>(Arrays.asList(url1, url3));
	assertThat(server.restartUrls).isEqualTo(expectedUrls);
	assertThat(server.restartFiles).isEqualTo(files);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:22,代码来源:RestartServerTests.java

示例4: updateSetsJarLastModified

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
@Test
public void updateSetsJarLastModified() throws Exception {
	long startTime = System.currentTimeMillis();
	File folder = this.temp.newFolder();
	File jarFile = new File(folder, "module-a.jar");
	new FileOutputStream(jarFile).close();
	jarFile.setLastModified(0);
	URL url = jarFile.toURI().toURL();
	URLClassLoader classLoader = new URLClassLoader(new URL[] { url });
	SourceFolderUrlFilter filter = new DefaultSourceFolderUrlFilter();
	MockRestartServer server = new MockRestartServer(filter, classLoader);
	ClassLoaderFiles files = new ClassLoaderFiles();
	ClassLoaderFile fileA = new ClassLoaderFile(Kind.ADDED, new byte[0]);
	files.addFile("my/module-a", "ClassA.class", fileA);
	server.updateAndRestart(files);
	assertThat(jarFile.lastModified()).isGreaterThan(startTime - 1000);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:RestartServerTests.java

示例5: updateReplacesLocalFilesWhenPossible

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
@Test
public void updateReplacesLocalFilesWhenPossible() throws Exception {
	// This is critical for Cloud Foundry support where the application is
	// run exploded and resources can be found from the servlet root (outside of the
	// classloader)
	File folder = this.temp.newFolder();
	File classFile = new File(folder, "ClassA.class");
	FileCopyUtils.copy("abc".getBytes(), classFile);
	URL url = folder.toURI().toURL();
	URLClassLoader classLoader = new URLClassLoader(new URL[] { url });
	SourceFolderUrlFilter filter = new DefaultSourceFolderUrlFilter();
	MockRestartServer server = new MockRestartServer(filter, classLoader);
	ClassLoaderFiles files = new ClassLoaderFiles();
	ClassLoaderFile fileA = new ClassLoaderFile(Kind.ADDED, "def".getBytes());
	files.addFile("my/module-a", "ClassA.class", fileA);
	server.updateAndRestart(files);
	assertThat(FileCopyUtils.copyToByteArray(classFile)).isEqualTo("def".getBytes());
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:RestartServerTests.java

示例6: updateAndRestart

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
@Test
public void updateAndRestart() throws Exception {
	URL url1 = new URL("file:/proj/module-a.jar!/");
	URL url2 = new URL("file:/proj/module-b.jar!/");
	URL url3 = new URL("file:/proj/module-c.jar!/");
	URL url4 = new URL("file:/proj/module-d.jar!/");
	URLClassLoader classLoaderA = new URLClassLoader(new URL[] { url1, url2 });
	URLClassLoader classLoaderB = new URLClassLoader(new URL[] { url3, url4 },
			classLoaderA);
	SourceFolderUrlFilter filter = new DefaultSourceFolderUrlFilter();
	MockRestartServer server = new MockRestartServer(filter, classLoaderB);
	ClassLoaderFiles files = new ClassLoaderFiles();
	ClassLoaderFile fileA = new ClassLoaderFile(Kind.ADDED, new byte[0]);
	ClassLoaderFile fileB = new ClassLoaderFile(Kind.ADDED, new byte[0]);
	files.addFile("my/module-a", "ClassA.class", fileA);
	files.addFile("my/module-c", "ClassB.class", fileB);
	server.updateAndRestart(files);
	Set<URL> expectedUrls = new LinkedHashSet<URL>(Arrays.asList(url1, url3));
	assertThat(server.restartUrls, equalTo(expectedUrls));
	assertThat(server.restartFiles, equalTo(files));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:22,代码来源:RestartServerTests.java

示例7: updateSetsJarLastModified

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
@Test
public void updateSetsJarLastModified() throws Exception {
	long startTime = System.currentTimeMillis();
	File folder = this.temp.newFolder();
	File jarFile = new File(folder, "module-a.jar");
	new FileOutputStream(jarFile).close();
	jarFile.setLastModified(0);
	URL url = jarFile.toURI().toURL();
	URLClassLoader classLoader = new URLClassLoader(new URL[] { url });
	SourceFolderUrlFilter filter = new DefaultSourceFolderUrlFilter();
	MockRestartServer server = new MockRestartServer(filter, classLoader);
	ClassLoaderFiles files = new ClassLoaderFiles();
	ClassLoaderFile fileA = new ClassLoaderFile(Kind.ADDED, new byte[0]);
	files.addFile("my/module-a", "ClassA.class", fileA);
	server.updateAndRestart(files);
	assertThat(jarFile.lastModified(), greaterThan(startTime - 1000));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:18,代码来源:RestartServerTests.java

示例8: updateReplacesLocalFilesWhenPossible

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
@Test
public void updateReplacesLocalFilesWhenPossible() throws Exception {
	// This is critical for Cloud Foundry support where the application is
	// run exploded and resources can be found from the servlet root (outside of the
	// classloader)
	File folder = this.temp.newFolder();
	File classFile = new File(folder, "ClassA.class");
	FileCopyUtils.copy("abc".getBytes(), classFile);
	URL url = folder.toURI().toURL();
	URLClassLoader classLoader = new URLClassLoader(new URL[] { url });
	SourceFolderUrlFilter filter = new DefaultSourceFolderUrlFilter();
	MockRestartServer server = new MockRestartServer(filter, classLoader);
	ClassLoaderFiles files = new ClassLoaderFiles();
	ClassLoaderFile fileA = new ClassLoaderFile(Kind.ADDED, "def".getBytes());
	files.addFile("my/module-a", "ClassA.class", fileA);
	server.updateAndRestart(files);
	assertThat(FileCopyUtils.copyToByteArray(classFile), equalTo("def".getBytes()));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:19,代码来源:RestartServerTests.java

示例9: asClassLoaderFile

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
private ClassLoaderFile asClassLoaderFile(ChangedFile changedFile)
		throws IOException {
	ClassLoaderFile.Kind kind = TYPE_MAPPINGS.get(changedFile.getType());
	byte[] bytes = (kind == Kind.DELETED ? null
			: FileCopyUtils.copyToByteArray(changedFile.getFile()));
	long lastModified = (kind == Kind.DELETED ? System.currentTimeMillis()
			: changedFile.getFile().lastModified());
	return new ClassLoaderFile(kind, lastModified, bytes);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:ClassPathChangeUploader.java

示例10: addClassLoaderFiles

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
@Test
public void addClassLoaderFiles() throws Exception {
	ClassLoaderFiles classLoaderFiles = new ClassLoaderFiles();
	classLoaderFiles.addFile("f", new ClassLoaderFile(Kind.ADDED, "abc".getBytes()));
	Restarter restarter = Restarter.getInstance();
	restarter.addClassLoaderFiles(classLoaderFiles);
	restarter.restart();
	ClassLoader classLoader = ((TestableRestarter) restarter)
			.getRelaunchClassLoader();
	assertThat(FileCopyUtils.copyToByteArray(classLoader.getResourceAsStream("f")))
			.isEqualTo("abc".getBytes());
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:RestarterTests.java

示例11: sendClassLoaderFiles

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
@Test
public void sendClassLoaderFiles() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockHttpServletResponse response = new MockHttpServletResponse();
	ClassLoaderFiles files = new ClassLoaderFiles();
	files.addFile("name", new ClassLoaderFile(Kind.ADDED, new byte[0]));
	byte[] bytes = serialize(files);
	request.setContent(bytes);
	this.server.handle(new ServletServerHttpRequest(request),
			new ServletServerHttpResponse(response));
	verify(this.delegate).updateAndRestart(this.filesCaptor.capture());
	assertThat(this.filesCaptor.getValue().getFile("name")).isNotNull();
	assertThat(response.getStatus()).isEqualTo(200);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:HttpRestartServerTests.java

示例12: verifyUploadRequest

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
private void verifyUploadRequest(File sourceFolder, MockClientHttpRequest request)
		throws IOException, ClassNotFoundException {
	ClassLoaderFiles classLoaderFiles = deserialize(request.getBodyAsBytes());
	Collection<SourceFolder> sourceFolders = classLoaderFiles.getSourceFolders();
	assertThat(sourceFolders.size()).isEqualTo(1);
	SourceFolder classSourceFolder = sourceFolders.iterator().next();
	assertThat(classSourceFolder.getName()).isEqualTo(sourceFolder.getAbsolutePath());
	Iterator<ClassLoaderFile> classFiles = classSourceFolder.getFiles().iterator();
	assertClassFile(classFiles.next(), "File1", ClassLoaderFile.Kind.ADDED);
	assertClassFile(classFiles.next(), "File2", ClassLoaderFile.Kind.MODIFIED);
	assertClassFile(classFiles.next(), null, ClassLoaderFile.Kind.DELETED);
	assertThat(classFiles.hasNext()).isFalse();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:ClassPathChangeUploaderTests.java

示例13: sendsClassLoaderFiles

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
@Test
public void sendsClassLoaderFiles() throws Exception {
	File sourceFolder = this.temp.newFolder();
	Set<ChangedFile> files = new LinkedHashSet<ChangedFile>();
	File file1 = createFile(sourceFolder, "File1");
	File file2 = createFile(sourceFolder, "File2");
	File file3 = createFile(sourceFolder, "File3");
	files.add(new ChangedFile(sourceFolder, file1, Type.ADD));
	files.add(new ChangedFile(sourceFolder, file2, Type.MODIFY));
	files.add(new ChangedFile(sourceFolder, file3, Type.DELETE));
	Set<ChangedFiles> changeSet = new LinkedHashSet<ChangedFiles>();
	changeSet.add(new ChangedFiles(sourceFolder, files));
	ClassPathChangedEvent event = new ClassPathChangedEvent(this, changeSet, false);
	this.requestFactory.willRespond(HttpStatus.OK);
	this.uploader.onApplicationEvent(event);
	MockClientHttpRequest request = this.requestFactory.getExecutedRequests().get(0);
	ClassLoaderFiles classLoaderFiles = deserialize(request.getBodyAsBytes());
	Collection<SourceFolder> sourceFolders = classLoaderFiles.getSourceFolders();
	assertThat(sourceFolders.size()).isEqualTo(1);
	SourceFolder classSourceFolder = sourceFolders.iterator().next();
	assertThat(classSourceFolder.getName()).isEqualTo(sourceFolder.getAbsolutePath());
	Iterator<ClassLoaderFile> classFiles = classSourceFolder.getFiles().iterator();
	assertClassFile(classFiles.next(), "File1", ClassLoaderFile.Kind.ADDED);
	assertClassFile(classFiles.next(), "File2", ClassLoaderFile.Kind.MODIFIED);
	assertClassFile(classFiles.next(), null, ClassLoaderFile.Kind.DELETED);
	assertThat(classFiles.hasNext()).isFalse();
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:28,代码来源:ClassPathChangeUploaderTests.java

示例14: addClassLoaderFiles

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
@Test
public void addClassLoaderFiles() throws Exception {
	ClassLoaderFiles classLoaderFiles = new ClassLoaderFiles();
	classLoaderFiles.addFile("f", new ClassLoaderFile(Kind.ADDED, "abc".getBytes()));
	Restarter restarter = Restarter.getInstance();
	restarter.addClassLoaderFiles(classLoaderFiles);
	restarter.restart();
	ClassLoader classLoader = ((TestableRestarter) restarter)
			.getRelaunchClassLoader();
	assertThat(FileCopyUtils.copyToByteArray(classLoader.getResourceAsStream("f")),
			equalTo("abc".getBytes()));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:13,代码来源:RestarterTests.java

示例15: sendClassLoaderFiles

import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; //导入依赖的package包/类
@Test
public void sendClassLoaderFiles() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockHttpServletResponse response = new MockHttpServletResponse();
	ClassLoaderFiles files = new ClassLoaderFiles();
	files.addFile("name", new ClassLoaderFile(Kind.ADDED, new byte[0]));
	byte[] bytes = serialize(files);
	request.setContent(bytes);
	this.server.handle(new ServletServerHttpRequest(request),
			new ServletServerHttpResponse(response));
	verify(this.delegate).updateAndRestart(this.filesCaptor.capture());
	assertThat(this.filesCaptor.getValue().getFile("name"), notNullValue());
	assertThat(response.getStatus(), equalTo(200));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:15,代码来源:HttpRestartServerTests.java


注:本文中的org.springframework.boot.devtools.restart.classloader.ClassLoaderFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。