use of org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles.SourceFolder in project spring-boot by spring-projects.
the class ClassPathChangeUploaderTests method verifyUploadRequest.
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();
}
use of org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles.SourceFolder in project spring-boot by spring-projects.
the class ClassLoaderFilesTests method getSourceFolders.
@Test
public void getSourceFolders() throws Exception {
ClassLoaderFile file1 = new ClassLoaderFile(Kind.ADDED, new byte[10]);
ClassLoaderFile file2 = new ClassLoaderFile(Kind.MODIFIED, new byte[10]);
ClassLoaderFile file3 = new ClassLoaderFile(Kind.MODIFIED, new byte[10]);
ClassLoaderFile file4 = new ClassLoaderFile(Kind.MODIFIED, new byte[10]);
this.files.addFile("a", "myfile1", file1);
this.files.addFile("a", "myfile2", file2);
this.files.addFile("b", "myfile3", file3);
this.files.addFile("b", "myfile4", file4);
Iterator<SourceFolder> sourceFolders = this.files.getSourceFolders().iterator();
SourceFolder sourceFolder1 = sourceFolders.next();
SourceFolder sourceFolder2 = sourceFolders.next();
assertThat(sourceFolders.hasNext()).isFalse();
assertThat(sourceFolder1.getName()).isEqualTo("a");
assertThat(sourceFolder2.getName()).isEqualTo("b");
assertThat(sourceFolder1.getFiles()).containsOnly(file1, file2);
assertThat(sourceFolder2.getFiles()).containsOnly(file3, file4);
}
use of org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles.SourceFolder in project spring-boot by spring-projects.
the class ClassLoaderFilesResourcePatternResolver method getAdditionalResources.
private List<Resource> getAdditionalResources(String locationPattern) throws MalformedURLException {
List<Resource> additionalResources = new ArrayList<>();
String trimmedLocationPattern = trimLocationPattern(locationPattern);
for (SourceFolder sourceFolder : this.classLoaderFiles.getSourceFolders()) {
for (Entry<String, ClassLoaderFile> entry : sourceFolder.getFilesEntrySet()) {
String name = entry.getKey();
ClassLoaderFile file = entry.getValue();
if (file.getKind() == Kind.ADDED && this.antPathMatcher.match(trimmedLocationPattern, name)) {
URL url = new URL("reloaded", null, -1, "/" + name, new ClassLoaderFileURLStreamHandler(file));
UrlResource resource = new UrlResource(url);
additionalResources.add(resource);
}
}
}
return additionalResources;
}
use of org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles.SourceFolder in project spring-boot by spring-projects.
the class RestartServer method updateAndRestart.
/**
* 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<>();
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);
}
use of org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles.SourceFolder in project spring-boot by spring-projects.
the class ClassLoaderFilesResourcePatternResolver method isDeleted.
private boolean isDeleted(Resource resource) {
for (SourceFolder sourceFolder : this.classLoaderFiles.getSourceFolders()) {
for (Entry<String, ClassLoaderFile> entry : sourceFolder.getFilesEntrySet()) {
try {
String name = entry.getKey();
ClassLoaderFile file = entry.getValue();
if (file.getKind() == Kind.DELETED && resource.exists() && resource.getURI().toString().endsWith(name)) {
return true;
}
} catch (IOException ex) {
throw new IllegalStateException("Failed to retrieve URI from '" + resource + "'", ex);
}
}
}
return false;
}
Aggregations