Example usage for org.springframework.boot.devtools.restart.classloader ClassLoaderFile getKind

List of usage examples for org.springframework.boot.devtools.restart.classloader ClassLoaderFile getKind

Introduction

In this page you can find the example usage for org.springframework.boot.devtools.restart.classloader ClassLoaderFile getKind.

Prototype

public Kind getKind() 

Source Link

Document

Return the file Kind (added, modified, deleted).

Usage

From source file:org.springframework.boot.devtools.restart.classloader.RestartClassLoader.java

@Override
public Enumeration<URL> getResources(String name) throws IOException {
    // Use the parent since we're shadowing resource and we don't want duplicates
    Enumeration<URL> resources = getParent().getResources(name);
    ClassLoaderFile file = this.updatedFiles.getFile(name);
    if (file != null) {
        // Assume that we're replacing just the first item
        if (resources.hasMoreElements()) {
            resources.nextElement();/*w  w  w  . ja v  a 2s.  c  om*/
        }
        if (file.getKind() != Kind.DELETED) {
            return new CompoundEnumeration<URL>(createFileUrl(name, file), resources);
        }
    }
    return resources;
}

From source file:org.springframework.boot.devtools.restart.classloader.RestartClassLoader.java

@Override
public URL getResource(String name) {
    ClassLoaderFile file = this.updatedFiles.getFile(name);
    if (file != null && file.getKind() == Kind.DELETED) {
        return null;
    }//www. ja  va  2 s .c o m
    URL resource = findResource(name);
    if (resource != null) {
        return resource;
    }
    return getParent().getResource(name);
}

From source file:org.springframework.boot.devtools.restart.classloader.RestartClassLoader.java

@Override
public URL findResource(final String name) {
    final ClassLoaderFile file = this.updatedFiles.getFile(name);
    if (file == null) {
        return super.findResource(name);
    }//from  www.j  a v a 2  s . c  om
    if (file.getKind() == Kind.DELETED) {
        return null;
    }
    return AccessController.doPrivileged(new PrivilegedAction<URL>() {
        @Override
        public URL run() {
            return createFileUrl(name, file);
        }
    });
}

From source file:org.springframework.boot.devtools.restart.classloader.RestartClassLoader.java

@Override
public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
    String path = name.replace('.', '/').concat(".class");
    ClassLoaderFile file = this.updatedFiles.getFile(path);
    if (file != null && file.getKind() == Kind.DELETED) {
        throw new ClassNotFoundException(name);
    }//from  w w w  .  j a  v a 2  s  .c  o m
    Class<?> loadedClass = findLoadedClass(name);
    if (loadedClass == null) {
        try {
            loadedClass = findClass(name);
        } catch (ClassNotFoundException ex) {
            loadedClass = getParent().loadClass(name);
        }
    }
    if (resolve) {
        resolveClass(loadedClass);
    }
    return loadedClass;
}

From source file:org.springframework.boot.devtools.restart.classloader.RestartClassLoader.java

@Override
protected Class<?> findClass(final String name) throws ClassNotFoundException {
    String path = name.replace('.', '/').concat(".class");
    final ClassLoaderFile file = this.updatedFiles.getFile(path);
    if (file == null) {
        return super.findClass(name);
    }// w  ww.  j  a  v a 2  s . co m
    if (file.getKind() == Kind.DELETED) {
        throw new ClassNotFoundException(name);
    }
    return AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {
        @Override
        public Class<?> run() {
            byte[] bytes = file.getContents();
            return defineClass(name, bytes, 0, bytes.length);
        }
    });
}

From source file:org.springframework.boot.devtools.restart.server.RestartServer.java

private boolean updateFileSystem(URL url, String name, ClassLoaderFile classLoaderFile) {
    if (!isFolderUrl(url.toString())) {
        return false;
    }/*from  w  w  w  .ja v  a 2 s.  c  om*/
    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;
}