@Nullable
 protected VirtualFile findClassFile(String className) {
   final CompilerModuleExtension extension =
       ModuleRootManager.getInstance(myModule).getModuleExtension(CompilerModuleExtension.class);
   //noinspection ConstantConditions
   return extension.getCompilerOutputPath().findChild(className + ".class");
 }
Example #2
0
  protected void assertModuleOutput(String moduleName, String output, String testOutput) {
    CompilerModuleExtension e = getCompilerExtension(moduleName);

    assertFalse(e.isCompilerOutputPathInherited());
    assertEquals(output, getAbsolutePath(e.getCompilerOutputUrl()));
    assertEquals(testOutput, getAbsolutePath(e.getCompilerOutputUrlForTests()));
  }
 /**
  * The same as {@link #getModuleOutputDirectory} but returns String. The method still returns a
  * non-null value if the output path is specified in Settings but does not exist on disk.
  */
 @Nullable
 public static String getModuleOutputPath(final Module module, boolean forTestClasses) {
   final String outPathUrl;
   final Application application = ApplicationManager.getApplication();
   final CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module);
   if (forTestClasses) {
     if (application.isDispatchThread()) {
       final String url = extension.getCompilerOutputUrlForTests();
       outPathUrl = url != null ? url : extension.getCompilerOutputUrl();
     } else {
       outPathUrl =
           application.runReadAction(
               new Computable<String>() {
                 public String compute() {
                   final String url = extension.getCompilerOutputUrlForTests();
                   return url != null ? url : extension.getCompilerOutputUrl();
                 }
               });
     }
   } else { // for ordinary classes
     if (application.isDispatchThread()) {
       outPathUrl = extension.getCompilerOutputUrl();
     } else {
       outPathUrl =
           application.runReadAction(
               new Computable<String>() {
                 public String compute() {
                   return extension.getCompilerOutputUrl();
                 }
               });
     }
   }
   return outPathUrl != null ? VirtualFileManager.extractPath(outPathUrl) : null;
 }
 protected static File getOutputDir(Module module) {
   CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module);
   Assert.assertNotNull(extension);
   String outputUrl = extension.getCompilerOutputUrl();
   Assert.assertNotNull(
       "Output directory for module '" + module.getName() + "' isn't specified", outputUrl);
   return JpsPathUtil.urlToFile(outputUrl);
 }
 private static String getOutput(Module module1, boolean test) {
   CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module1);
   assertNotNull(compilerModuleExtension);
   VirtualFile output =
       test
           ? compilerModuleExtension.getCompilerOutputPathForTests()
           : compilerModuleExtension.getCompilerOutputPath();
   return getFSPath(output);
 }
 private void createOutputDirectories() {
   for (Module module : ModuleManager.getInstance(myProject).getModules()) {
     CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module);
     if (extension != null) {
       createDirectoryIfDoesntExist(extension.getCompilerOutputUrl());
       createDirectoryIfDoesntExist(extension.getCompilerOutputUrlForTests());
     }
   }
 }
 public static void setCompilerOutputPath(Module module, String url, boolean forTests) {
   ModuleRootModificationUtil.updateModel(
       module,
       model -> {
         CompilerModuleExtension extension =
             model.getModuleExtension(CompilerModuleExtension.class);
         extension.inheritCompilerOutputPath(false);
         if (forTests) {
           extension.setCompilerOutputPathForTests(url);
         } else {
           extension.setCompilerOutputPath(url);
         }
       });
 }
 private static Iterable<String> getOutputPaths(Project project) {
   final Collection<String> paths = new LinkedHashSet<>();
   final CompilerProjectExtension cpe = CompilerProjectExtension.getInstance(project);
   if (cpe != null && cpe.getCompilerOutput() != null) {
     paths.add(cpe.getCompilerOutput().getCanonicalPath());
   }
   final Module[] modules = ModuleManager.getInstance(project).getModules();
   for (Module module : modules) {
     final CompilerModuleExtension cme = CompilerModuleExtension.getInstance(module);
     if (cme != null && cme.getCompilerOutputPath() != null) {
       paths.add(cme.getCompilerOutputPath().getCanonicalPath());
     }
   }
   return paths;
 }
  private static void addRootsFromModule(Module module, Collection<String> pythonPathList) {

    // for Jython
    final CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module);
    if (extension != null) {
      final VirtualFile path = extension.getCompilerOutputPath();
      if (path != null) {
        pythonPathList.add(path.getPath());
      }
      final VirtualFile pathForTests = extension.getCompilerOutputPathForTests();
      if (pathForTests != null) {
        pythonPathList.add(pathForTests.getPath());
      }
    }

    // additional paths from facets (f.e. buildout)
    final Facet[] facets = FacetManager.getInstance(module).getAllFacets();
    for (Facet facet : facets) {
      if (facet instanceof PythonPathContributingFacet) {
        List<String> more_paths = ((PythonPathContributingFacet) facet).getAdditionalPythonPath();
        if (more_paths != null) pythonPathList.addAll(more_paths);
      }
    }
  }
Example #10
0
 /**
  * @param module
  * @param forTestClasses true if directory for test sources, false - for sources.
  * @return a directory to which the sources (or test sources depending on the second partameter)
  *     should be compiled. Null is returned if output directory is not specified or is not valid
  */
 @Nullable
 public static VirtualFile getModuleOutputDirectory(final Module module, boolean forTestClasses) {
   final CompilerModuleExtension compilerModuleExtension =
       CompilerModuleExtension.getInstance(module);
   VirtualFile outPath;
   if (forTestClasses) {
     final VirtualFile path = compilerModuleExtension.getCompilerOutputPathForTests();
     if (path != null) {
       outPath = path;
     } else {
       outPath = compilerModuleExtension.getCompilerOutputPath();
     }
   } else {
     outPath = compilerModuleExtension.getCompilerOutputPath();
   }
   if (outPath == null) {
     return null;
   }
   if (!outPath.isValid()) {
     LOG.info("Requested output path for module " + module.getName() + " is not valid");
     return null;
   }
   return outPath;
 }
 private static File jarModulesOutput(
     @NotNull Set<Module> modules,
     @Nullable Manifest manifest,
     final @Nullable String pluginXmlPath)
     throws IOException {
   File jarFile = FileUtil.createTempFile(TEMP_PREFIX, JAR_EXTENSION);
   jarFile.deleteOnExit();
   ZipOutputStream jarPlugin = null;
   try {
     BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(jarFile));
     jarPlugin = manifest != null ? new JarOutputStream(out, manifest) : new JarOutputStream(out);
     final ProgressIndicator progressIndicator =
         ProgressManager.getInstance().getProgressIndicator();
     final Set<String> writtenItemRelativePaths = new HashSet<String>();
     for (Module module : modules) {
       final VirtualFile compilerOutputPath =
           CompilerModuleExtension.getInstance(module).getCompilerOutputPath();
       if (compilerOutputPath == null)
         continue; // pre-condition: output dirs for all modules are up-to-date
       ZipUtil.addDirToZipRecursively(
           jarPlugin,
           jarFile,
           new File(compilerOutputPath.getPath()),
           "",
           createFilter(progressIndicator, FileTypeManager.getInstance()),
           writtenItemRelativePaths);
     }
     if (pluginXmlPath != null) {
       ZipUtil.addFileToZip(
           jarPlugin,
           new File(pluginXmlPath),
           "/META-INF/plugin.xml",
           writtenItemRelativePaths,
           createFilter(progressIndicator, null));
     }
   } finally {
     if (jarPlugin != null) jarPlugin.close();
   }
   return jarFile;
 }
Example #12
0
 private CompilerModuleExtension getCompilerExtension(String module) {
   ModuleRootManager m = getRootManager(module);
   return CompilerModuleExtension.getInstance(m.getModule());
 }
  @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;
  }
 private static void removeModuleOutput(Module module, List<VirtualFile> from) {
   final CompilerModuleExtension extension =
       ModuleRootManager.getInstance(module).getModuleExtension(CompilerModuleExtension.class);
   from.remove(extension.getCompilerOutputPath());
   from.remove(extension.getCompilerOutputPathForTests());
 }
 public static void setOutputUrl(ModifiableRootModel rootModel, String path) {
   final CompilerModuleExtension compilerModuleExtension =
       rootModel.getModuleExtension(CompilerModuleExtension.class);
   compilerModuleExtension.setCompilerOutputPath(pathToUrl(path));
   compilerModuleExtension.inheritCompilerOutputPath(false);
 }
  @Override
  public List<Module> commit(
      @NotNull Project project,
      @Nullable ModifiableModuleModel moduleModel,
      @NotNull ModulesProvider modulesProvider,
      @Nullable ModifiableArtifactModel modifiableArtifactModel) {
    Set<String> selectedAppNames = ContainerUtil.newHashSet();
    for (ImportedOtpApp importedOtpApp : mySelectedOtpApps) {
      selectedAppNames.add(importedOtpApp.getName());
    }
    Sdk projectSdk = fixProjectSdk(project);
    List<Module> createdModules = new ArrayList<Module>();
    final List<ModifiableRootModel> createdRootModels = new ArrayList<ModifiableRootModel>();
    final ModifiableModuleModel obtainedModuleModel =
        moduleModel != null ? moduleModel : ModuleManager.getInstance(project).getModifiableModel();
    for (ImportedOtpApp importedOtpApp : mySelectedOtpApps) {
      VirtualFile ideaModuleDir = importedOtpApp.getRoot();
      String ideaModuleFile =
          ideaModuleDir.getCanonicalPath() + File.separator + importedOtpApp.getName() + ".iml";
      Module module =
          obtainedModuleModel.newModule(ideaModuleFile, ErlangModuleType.getInstance().getId());
      createdModules.add(module);
      importedOtpApp.setModule(module);
      if (importedOtpApp.getIdeaModuleFile() == null) {
        ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
        // Make it inherit SDK from the project.
        rootModel.inheritSdk();
        // Initialize source and test paths.
        ContentEntry content = rootModel.addContentEntry(importedOtpApp.getRoot());
        addSourceDirToContent(content, ideaModuleDir, "src", false);
        addSourceDirToContent(content, ideaModuleDir, "test", true);
        addIncludeDirectories(content, importedOtpApp);
        // Exclude standard folders
        excludeDirFromContent(content, ideaModuleDir, "doc");
        // Initialize output paths according to Rebar conventions.
        CompilerModuleExtension compilerModuleExt =
            rootModel.getModuleExtension(CompilerModuleExtension.class);
        compilerModuleExt.inheritCompilerOutputPath(false);
        compilerModuleExt.setCompilerOutputPath(ideaModuleDir + File.separator + "ebin");
        compilerModuleExt.setCompilerOutputPathForTests(ideaModuleDir + File.separator + ".eunit");
        createdRootModels.add(rootModel);
        // Set inter-module dependencies
        resolveModuleDeps(rootModel, importedOtpApp, projectSdk, selectedAppNames);
      }
    }
    // Commit project structure.
    LOG.info("Commit project structure");
    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              public void run() {
                for (ModifiableRootModel rootModel : createdRootModels) {
                  rootModel.commit();
                }
                obtainedModuleModel.commit();
              }
            });

    addErlangFacets(mySelectedOtpApps);
    RebarSettings.getInstance(project).setRebarPath(myRebarPath);
    if (myIsImportingProject) {
      ErlangCompilerSettings.getInstance(project).setUseRebarCompilerEnabled(true);
    }
    CompilerWorkspaceConfiguration.getInstance(project).CLEAR_OUTPUT_DIRECTORY = false;

    return createdModules;
  }