Search in sources :

Example 86 with InvalidPathException

use of java.nio.file.InvalidPathException in project yii2support by nvlad.

the class ViewUtil method resolveViewFromWidget.

@NotNull
private static ViewResolve resolveViewFromWidget(PhpClass clazz, String value) {
    ViewResolve result = new ViewResolve(ViewResolveFrom.Widget);
    final String classFQN = clazz.getFQN().replace('\\', '/');
    StringBuilder key = new StringBuilder("@app");
    String path = deletePathPart(classFQN);
    final int widgetsPathPartPosition = path.indexOf("/widgets/");
    if (widgetsPathPartPosition == -1) {
        throw new InvalidPathException(path, "Not found \"widgets\" directory.");
    }
    result.application = getFirstPathPart(classFQN);
    if (widgetsPathPartPosition > 0) {
        final String modulePath = path.substring(0, widgetsPathPartPosition);
        key.append(modulePath);
        result.module = modulePath.substring(modulePath.lastIndexOf('/') + 1);
        path = path.substring(modulePath.length());
    }
    if (value.startsWith("/")) {
        key.append("/views");
    } else {
        key.append("/widgets");
        path = deletePathPart(path);
        key.append(path, 0, path.length() - clazz.getName().length());
        key.append("views/");
    }
    key.append(value);
    result.key = normalizePath(key.toString());
    return result;
}
Also used : ViewResolve(com.nvlad.yii2support.views.entities.ViewResolve) InvalidPathException(java.nio.file.InvalidPathException) NotNull(org.jetbrains.annotations.NotNull)

Example 87 with InvalidPathException

use of java.nio.file.InvalidPathException in project yii2support by nvlad.

the class ViewUtil method resolveViewFromView.

@NotNull
private static ViewResolve resolveViewFromView(PsiElement element, String value) {
    VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
    if (virtualFile == null) {
        virtualFile = element.getContainingFile().getOriginalFile().getVirtualFile();
    }
    ViewResolve result = resolveView(virtualFile, element.getProject());
    if (result == null) {
        throw new InvalidPathException(virtualFile.getPath(), "Not resolved");
    }
    result.from = ViewResolveFrom.View;
    if (value.startsWith("/")) {
        int viewsPathPartPosition = result.key.lastIndexOf("/views/");
        if (viewsPathPartPosition == -1) {
            throw new InvalidPathException(result.key, "Not found \"views\" directory");
        }
        result.key = result.key.substring(0, viewsPathPartPosition + 6) + value;
        return result;
    }
    int lastSlashPosition = result.key.lastIndexOf('/');
    result.key = normalizePath(result.key.substring(0, lastSlashPosition + 1) + value);
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ViewResolve(com.nvlad.yii2support.views.entities.ViewResolve) InvalidPathException(java.nio.file.InvalidPathException) NotNull(org.jetbrains.annotations.NotNull)

Example 88 with InvalidPathException

use of java.nio.file.InvalidPathException in project yii2support by nvlad.

the class ViewUtil method resolveView.

@Nullable
public static ViewResolve resolveView(PsiElement element) {
    String value = PhpUtil.getValue(element);
    if (value.startsWith("@")) {
        ViewResolve resolve = new ViewResolve(value);
        resolve.application = YiiApplicationUtils.getApplicationName(element.getContainingFile());
        return resolve;
    }
    if (value.startsWith("//")) {
        ViewResolve resolve = new ViewResolve("@app/views" + value.substring(1));
        resolve.application = YiiApplicationUtils.getApplicationName(element.getContainingFile());
        return resolve;
    }
    final MethodReference method = PsiTreeUtil.getParentOfType(element, MethodReference.class);
    if (method == null || method.getClassReference() == null) {
        return null;
    }
    PhpClass callerClass = ClassUtils.getPhpClassByCallChain(method);
    if (callerClass == null) {
        return null;
    }
    final PhpIndex phpIndex = PhpIndex.getInstance(element.getProject());
    final ViewResolve viewResolve;
    try {
        if (callerClass.getName().endsWith("Controller") && ClassUtils.isClassInheritsOrEqual(callerClass, "\\yii\\base\\Controller", phpIndex)) {
            viewResolve = resolveViewFromController(callerClass, value);
        } else if (ClassUtils.isClassInheritsOrEqual(callerClass, "\\yii\\base\\View", phpIndex)) {
            viewResolve = resolveViewFromView(element, value);
        } else if (ClassUtils.isClassInheritsOrEqual(callerClass, "\\yii\\base\\Widget", phpIndex)) {
            viewResolve = resolveViewFromWidget(callerClass, value);
        } else {
            return null;
        }
    } catch (InvalidPathException e) {
        return null;
    }
    viewResolve.application = YiiApplicationUtils.getApplicationName(element.getContainingFile());
    return viewResolve;
}
Also used : ViewResolve(com.nvlad.yii2support.views.entities.ViewResolve) PhpIndex(com.jetbrains.php.PhpIndex) InvalidPathException(java.nio.file.InvalidPathException) Nullable(org.jetbrains.annotations.Nullable)

Example 89 with InvalidPathException

use of java.nio.file.InvalidPathException in project wildfly-swarm by wildfly-swarm.

the class Swarm method initializeConfigView.

private void initializeConfigView(Properties props) throws IOException, ModuleLoadException {
    try (AutoCloseable handle = Performance.time("Loading YAML")) {
        if (System.getProperty(SwarmProperties.PROJECT_STAGE_FILE) != null) {
            String file = System.getProperty(SwarmProperties.PROJECT_STAGE_FILE);
            boolean loaded = false;
            try {
                Path path = Paths.get(file);
                if (Files.exists(path)) {
                    this.configView.load("stages", path.toUri().toURL());
                    loaded = true;
                }
            } catch (InvalidPathException e) {
            // ignore
            }
            if (!loaded) {
                // try it as a URL
                try {
                    URL url = new URL(file);
                    this.configView.load("stages", url);
                } catch (MalformedURLException e) {
                // oh well
                }
            }
        }
        // List<String> activatedNames = new ArrayList<>();
        String projectStageProp = System.getProperty(SwarmProperties.PROJECT_STAGE);
        if (projectStageProp == null && props != null) {
            projectStageProp = props.getProperty(SwarmProperties.PROJECT_STAGE);
        }
        if (projectStageProp == null) {
            projectStageProp = this.configView.get().resolve(SwarmProperties.PROJECT_STAGE).withDefault("NOT_FOUND").getValue();
            if (projectStageProp != null && projectStageProp.equals("NOT_FOUND")) {
                projectStageProp = null;
            }
        }
        if (projectStageProp != null) {
            String[] activated = projectStageProp.split(",");
            for (String each : activated) {
                this.configView.load(each);
                this.configView.withProfile(each);
            }
        }
        int counter = 0;
        for (URL config : this.configs) {
            String syntheticName = "cli-" + (++counter);
            this.configView.load(syntheticName, config);
            this.configView.withProfile(syntheticName);
        }
        this.configView.load("stages");
        for (String profile : this.profiles) {
            this.configView.load(profile);
            this.configView.withProfile(profile);
        }
        this.configView.load("defaults");
        initializeConfigFilters();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) MalformedURLException(java.net.MalformedURLException) InvalidPathException(java.nio.file.InvalidPathException) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) DeploymentException(org.wildfly.swarm.container.DeploymentException) InvalidPathException(java.nio.file.InvalidPathException) ModuleLoadException(org.jboss.modules.ModuleLoadException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 90 with InvalidPathException

use of java.nio.file.InvalidPathException in project apache-kafka-on-k8s by banzaicloud.

the class DelegatingClassLoader method initPluginLoader.

private void initPluginLoader(String path) {
    try {
        if (CLASSPATH_NAME.equals(path)) {
            scanUrlsAndAddPlugins(getParent(), ClasspathHelper.forJavaClassPath().toArray(new URL[0]), null);
        } else {
            Path pluginPath = Paths.get(path).toAbsolutePath();
            // Update for exception handling
            path = pluginPath.toString();
            // containing plugins
            if (Files.isDirectory(pluginPath)) {
                for (Path pluginLocation : PluginUtils.pluginLocations(pluginPath)) {
                    registerPlugin(pluginLocation);
                }
            } else if (PluginUtils.isArchive(pluginPath)) {
                registerPlugin(pluginPath);
            }
        }
    } catch (InvalidPathException | MalformedURLException e) {
        log.error("Invalid path in plugin path: {}. Ignoring.", path, e);
    } catch (IOException e) {
        log.error("Could not get listing for plugin path: {}. Ignoring.", path, e);
    } catch (InstantiationException | IllegalAccessException e) {
        log.error("Could not instantiate plugins in: {}. Ignoring: {}", path, e);
    }
}
Also used : Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) URL(java.net.URL) InvalidPathException(java.nio.file.InvalidPathException)

Aggregations

InvalidPathException (java.nio.file.InvalidPathException)111 Path (java.nio.file.Path)58 IOException (java.io.IOException)30 File (java.io.File)17 URL (java.net.URL)15 MalformedURLException (java.net.MalformedURLException)12 Test (org.junit.Test)11 AlluxioURI (alluxio.AlluxioURI)7 ArrayList (java.util.ArrayList)7 Resource (org.springframework.core.io.Resource)7 Nullable (org.springframework.lang.Nullable)7 URI (java.net.URI)6 URISyntaxException (java.net.URISyntaxException)6 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5 BufferedReader (java.io.BufferedReader)5 URIStatus (alluxio.client.file.URIStatus)4 ViewResolve (com.nvlad.yii2support.views.entities.ViewResolve)4 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4