/**
   * @see fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil#getTemplateNameByOverwrite
   */
  public void testTemplateOverwriteNameGeneration() {

    if (true == true) {
      return;
    }

    assertEquals(
        "TwigUtilIntegrationBundle:layout.html.twig",
        TwigUtil.getTemplateNameByOverwrite(
            getProject(),
            VfsUtil.findRelativeFile(
                getProject().getBaseDir(),
                "app/Resources/TwigUtilIntegrationBundle/views/layout.html.twig".split("/"))));

    assertEquals(
        "TwigUtilIntegrationBundle:Foo/layout.html.twig",
        TwigUtil.getTemplateNameByOverwrite(
            getProject(),
            VfsUtil.findRelativeFile(
                getProject().getBaseDir(),
                "app/Resources/TwigUtilIntegrationBundle/views/Foo/layout.html.twig".split("/"))));

    assertEquals(
        "TwigUtilIntegrationBundle:Foo/Bar/layout.html.twig",
        TwigUtil.getTemplateNameByOverwrite(
            getProject(),
            VfsUtil.findRelativeFile(
                getProject().getBaseDir(),
                "app/Resources/TwigUtilIntegrationBundle/views/Foo/Bar/layout.html.twig"
                    .split("/"))));
  }
 private static boolean fileExists(@NotNull VirtualFile bundleDir, @NotNull String className) {
   return VfsUtil.findRelativeFile(
               bundleDir, "DependencyInjection", "Compiler", className + ".php")
           != null
       || VfsUtil.findRelativeFile(
               bundleDir, "DependencyInjection", "CompilerPass", className + ".php")
           != null;
 }
  @Nullable
  private static VirtualFile getAndCreateCompilerDirectory(@NotNull VirtualFile directory) {

    VirtualFile relativeFile =
        VfsUtil.findRelativeFile(directory, "DependencyInjection", "Compiler");
    if (relativeFile != null) {
      return relativeFile;
    }

    relativeFile = VfsUtil.findRelativeFile(directory, "DependencyInjection", "CompilerPass");
    if (relativeFile != null) {
      return relativeFile;
    }

    try {
      return VfsUtil.createDirectoryIfMissing(directory, "DependencyInjection/Compiler");
    } catch (IOException ignored) {
    }

    return null;
  }
  private void addAttachArtifactDependency(
      @NotNull Element buildHelperCfg,
      @NotNull DependencyScope scope,
      @NotNull MavenProject mavenProject,
      @NotNull MavenArtifact artifact) {
    Library.ModifiableModel libraryModel = null;

    for (Element artifactsElement : (List<Element>) buildHelperCfg.getChildren("artifacts")) {
      for (Element artifactElement : (List<Element>) artifactsElement.getChildren("artifact")) {
        String typeString = artifactElement.getChildTextTrim("type");
        if (typeString != null && !typeString.equals("jar")) continue;

        OrderRootType rootType = OrderRootType.CLASSES;

        String classifier = artifactElement.getChildTextTrim("classifier");
        if ("sources".equals(classifier)) {
          rootType = OrderRootType.SOURCES;
        } else if ("javadoc".equals(classifier)) {
          rootType = JavadocOrderRootType.getInstance();
        }

        String filePath = artifactElement.getChildTextTrim("file");
        if (StringUtil.isEmpty(filePath)) continue;

        VirtualFile file = VfsUtil.findRelativeFile(filePath, mavenProject.getDirectoryFile());
        if (file == null) continue;

        file = JarFileSystem.getInstance().getJarRootForLocalFile(file);
        if (file == null) continue;

        if (libraryModel == null) {
          String libraryName = artifact.getLibraryName();
          assert libraryName.startsWith(MavenArtifact.MAVEN_LIB_PREFIX);
          libraryName =
              MavenArtifact.MAVEN_LIB_PREFIX
                  + "ATTACHED-JAR: "
                  + libraryName.substring(MavenArtifact.MAVEN_LIB_PREFIX.length());

          Library library = myModifiableModelsProvider.getLibraryByName(libraryName);
          if (library == null) {
            library = myModifiableModelsProvider.createLibrary(libraryName);
          }
          libraryModel = myModifiableModelsProvider.getLibraryModel(library);

          LibraryOrderEntry entry = myRootModelAdapter.getRootModel().addLibraryEntry(library);
          entry.setScope(scope);
        }

        libraryModel.addRoot(file, rootType);
      }
    }
  }
Exemplo n.º 5
0
  @Nullable
  public static PsiFile resolveFile(String name, PsiFile baseFile) {
    if (baseFile == null) return null;

    final VirtualFile virtualFile = VfsUtil.findRelativeFile(name, baseFile.getVirtualFile());
    if (virtualFile != null) {
      final PsiFile file = baseFile.getManager().findFile(virtualFile);
      if (file != baseFile && file instanceof XmlFile) {
        return file;
      }
    }
    return null;
  }
 private void doRebarIncludePathsTest() throws Exception {
   String projectPath = getProject().getBaseDir().getPath();
   String importFromPath = projectPath + "/test/";
   Module module =
       importProjectFrom(
           importFromPath, null, new RebarProjectImportProvider(new RebarProjectImportBuilder()));
   ErlangFacet facet = ErlangFacet.getFacet(module);
   assertNotNull(facet);
   List<String> actualIncludePaths = facet.getConfiguration().getIncludePaths();
   List<String> expectedIncludePaths = new ArrayList<String>();
   for (VirtualFile contentRoot : ModuleRootManager.getInstance(module).getContentRoots()) {
     VirtualFile includeDirectory = VfsUtil.findRelativeFile(contentRoot, "include1");
     if (includeDirectory != null) {
       expectedIncludePaths.add(includeDirectory.getPath());
     }
     includeDirectory = VfsUtil.findRelativeFile(contentRoot, "include2");
     if (includeDirectory != null) {
       expectedIncludePaths.add(includeDirectory.getPath());
     }
   }
   assertSameElements(actualIncludePaths, expectedIncludePaths);
 }
  private static boolean fileExists(
      @NotNull VirtualFile bundleDir, @NotNull String... fqnClassName) {

    for (String s : fqnClassName) {
      String[] split = s.split("/");
      split[split.length - 1] += ".php";

      if (VfsUtil.findRelativeFile(bundleDir, split) != null) {
        return true;
      }
    }

    return false;
  }
 private static void validateFacet(@NotNull Module module) throws Exception {
   FacetManager facetManager = FacetManager.getInstance(module);
   ErlangFacet facet = facetManager.getFacetByType(ErlangFacetType.TYPE_ID);
   assertNotNull("Erlang facet was not added.", facet);
   List<String> actualIncludePaths = facet.getConfiguration().getIncludePaths();
   List<String> expectedIncludePaths = new ArrayList<String>();
   for (VirtualFile contentRoot : ModuleRootManager.getInstance(module).getContentRoots()) {
     VirtualFile includeDirectory = VfsUtil.findRelativeFile(contentRoot, "include");
     if (includeDirectory != null) {
       expectedIncludePaths.add(includeDirectory.getPath());
     }
   }
   assertSameElements(actualIncludePaths, expectedIncludePaths);
 }
  private void excludeFromCompilationArchetypeResources() {
    VirtualFile directoryFile = myMavenProject.getDirectoryFile();

    VirtualFile archetypeResourcesDir =
        VfsUtil.findRelativeFile(directoryFile, "src", "main", "resources", "archetype-resources");

    if (archetypeResourcesDir != null) {
      Project project = myModule.getProject();

      CompilerConfigurationImpl compilerConfiguration =
          (CompilerConfigurationImpl) CompilerConfiguration.getInstance(project);

      if (!compilerConfiguration.isExcludedFromCompilation(archetypeResourcesDir)) {
        ExcludedEntriesConfiguration cfg = compilerConfiguration.getExcludedEntriesConfiguration();

        cfg.addExcludeEntryDescription(
            new ExcludeEntryDescription(archetypeResourcesDir, true, false, project));
      }
    }
  }