@Nullable
 @Override
 public RefEntity getReference(final String type, final String fqName) {
   for (RefManagerExtension extension : myExtensions.values()) {
     final RefEntity refEntity = extension.getReference(type, fqName);
     if (refEntity != null) return refEntity;
   }
   if (SmartRefElementPointer.FILE.equals(type)) {
     return RefFileImpl.fileFromExternalName(this, fqName);
   }
   if (SmartRefElementPointer.MODULE.equals(type)) {
     return RefModuleImpl.moduleFromName(this, fqName);
   }
   if (SmartRefElementPointer.PROJECT.equals(type)) {
     return getRefProject();
   }
   if (SmartRefElementPointer.DIR.equals(type)) {
     String url =
         VfsUtilCore.pathToUrl(PathMacroManager.getInstance(getProject()).expandPath(fqName));
     VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(url);
     if (vFile != null) {
       final PsiDirectory dir = PsiManager.getInstance(getProject()).findDirectory(vFile);
       return getReference(dir);
     }
   }
   return null;
 }
 public void setXmlInputFile(@NotNull String xmlInputFile) {
   if (StringUtils.isEmpty(xmlInputFile)) {
     myXmlInputFile = null;
   } else {
     myXmlInputFile =
         VirtualFilePointerManager.getInstance()
             .create(
                 VfsUtilCore.pathToUrl(xmlInputFile).replace(File.separatorChar, '/'),
                 getProject(),
                 null);
   }
 }
Ejemplo n.º 3
0
    private void addPackage(@NotNull final String packageName, @NotNull final String packagePath) {
      myLibRootUrls.add(VfsUtilCore.pathToUrl(packagePath));

      List<String> paths = myPackagesMap.get((packageName));
      if (paths == null) {
        paths = new SmartList<String>();
        myPackagesMap.put(packageName, paths);
      }

      if (!paths.contains(packagePath)) {
        paths.add(packagePath);
      }
    }
  @NotNull
  private Map<String, GradleModuleResourceConfiguration> generateAffectedGradleModulesConfiguration(
      @NotNull CompileContext context) {
    final Map<String, GradleModuleResourceConfiguration> affectedGradleModuleConfigurations =
        ContainerUtil.newTroveMap();

    //noinspection MismatchedQueryAndUpdateOfCollection
    final Map<String, ExternalProject> lazyExternalProjectMap =
        new FactoryMap<String, ExternalProject>() {
          @Nullable
          @Override
          protected ExternalProject create(String gradleProjectPath) {
            return myExternalProjectDataService.getRootExternalProject(
                GradleConstants.SYSTEM_ID, new File(gradleProjectPath));
          }
        };

    for (Module module : context.getCompileScope().getAffectedModules()) {
      if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
        continue;

      if (shouldBeBuiltByExternalSystem(module)) continue;

      final String gradleProjectPath =
          module.getOptionValue(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY);
      assert gradleProjectPath != null;
      final ExternalProject externalRootProject = lazyExternalProjectMap.get(gradleProjectPath);
      if (externalRootProject == null) {
        context.addMessage(
            CompilerMessageCategory.ERROR,
            String.format(
                "Unable to make the module: %s, related gradle configuration was not found. "
                    + "Please, re-import the Gradle project and try again.",
                module.getName()),
            VfsUtilCore.pathToUrl(gradleProjectPath),
            -1,
            -1);
        continue;
      }

      ExternalProject externalProject =
          myExternalProjectDataService.findExternalProject(externalRootProject, module);
      if (externalProject == null) {
        LOG.warn("Unable to find config for module: " + module.getName());
        continue;
      }

      GradleModuleResourceConfiguration resourceConfig = new GradleModuleResourceConfiguration();
      resourceConfig.id =
          new ModuleVersion(
              externalProject.getGroup(), externalProject.getName(), externalProject.getVersion());
      resourceConfig.directory =
          FileUtil.toSystemIndependentName(externalProject.getProjectDir().getPath());

      final ExternalSourceSet mainSourcesSet = externalProject.getSourceSets().get("main");
      addResources(resourceConfig.resources, mainSourcesSet, ExternalSystemSourceType.RESOURCE);

      final ExternalSourceSet testSourcesSet = externalProject.getSourceSets().get("test");
      addResources(
          resourceConfig.testResources, testSourcesSet, ExternalSystemSourceType.TEST_RESOURCE);

      final CompilerModuleExtension compilerModuleExtension =
          CompilerModuleExtension.getInstance(module);
      if (compilerModuleExtension != null
          && compilerModuleExtension.isCompilerOutputPathInherited()) {
        String outputPath = VfsUtilCore.urlToPath(compilerModuleExtension.getCompilerOutputUrl());
        for (ResourceRootConfiguration resource : resourceConfig.resources) {
          resource.targetPath = outputPath;
        }

        String testOutputPath =
            VfsUtilCore.urlToPath(compilerModuleExtension.getCompilerOutputUrlForTests());
        for (ResourceRootConfiguration resource : resourceConfig.testResources) {
          resource.targetPath = testOutputPath;
        }
      }

      affectedGradleModuleConfigurations.put(module.getName(), resourceConfig);
    }

    return affectedGradleModuleConfigurations;
  }
Ejemplo n.º 5
0
 public void addRoots(final Collection<String> dirPaths) {
   for (String path : dirPaths) {
     myLibRootUrls.add(VfsUtilCore.pathToUrl(path));
   }
 }