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;
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations