@Override public String getId() { return myModule.getName(); }
private static void collectDependentModules(@NotNull JpsModule module, @NotNull Collection<JpsModule> addedModules, @NotNull Set<String> addedModuleNames) { String moduleName = module.getName(); if (addedModuleNames.contains(moduleName)) return; addedModuleNames.add(moduleName); addedModules.add(module); for (JpsDependencyElement dependency : module.getDependenciesList().getDependencies()) { if (!(dependency instanceof JpsModuleDependency)) continue; JpsModuleDependency moduleDependency = (JpsModuleDependency) dependency; JpsModule depModule = moduleDependency.getModule(); if (depModule != null) { collectDependentModules(depModule, addedModules, addedModuleNames); } } }
public Builder() { super(Arrays.asList(Type.PRODUCTION, Type.TEST)); // disables java resource builder for elixir modules ResourcesBuilder.registerEnabler(module -> !(module.getModuleType() instanceof ModuleType)); }
JpsSdkReferencesTable sdkTable = module.getSdkReferencesTable(); sdkTable.setSdkReference(sdkType, sdk.createReference()); sdkTable.setSdkReference(JpsJavaSdkType.INSTANCE, JpsJavaExtensionService.getInstance().createWrappedJavaSdkReference((JpsJavaSdkTypeWrapper)sdkType, wrapperRef)); module.getDependenciesList().addSdkDependency(sdkType); if(srcPaths.length > 0 || outputPath != null){ for(String srcPath : srcPaths){ module.getContentRootsList().addUrl(JpsPathUtil.pathToUrl(srcPath)); module.addSourceRoot(JpsPathUtil.pathToUrl(srcPath), JavaSourceRootType.SOURCE);
@NotNull @Override public List<SourceRootDescriptor> computeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) { List<SourceRootDescriptor> result = new ArrayList<SourceRootDescriptor>(); JavaSourceRootType type = isTests() ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE; for(JpsTypedModuleSourceRoot<JavaSourceRootProperties> root : myModule.getSourceRoots(type)){ result.add(new SourceRootDescriptor(root.getFile(), this)); } return result; }
private static void addModuleToCodePath(@NotNull GeneralCommandLine commandLine, @NotNull JpsModule module, boolean forTests, @NotNull CompileContext context) throws ProjectBuildException { File outputDirectory = getBuildOutputDirectory(module, forTests, context); commandLine.addParameters(ADD_PATH_TO_FRONT_OF_CODE_PATH, outputDirectory.getPath()); for (String rootUrl : module.getContentRootsList().getUrls()) { try { String path = new URL(rootUrl).getPath(); commandLine.addParameters(ADD_PATH_TO_FRONT_OF_CODE_PATH, path); } catch (MalformedURLException e) { context.processMessage(new CompilerMessage(ElIXIRC_NAME, BuildMessage.Kind.ERROR, "Failed to find content root for module: " + module.getName())); } } }
@NotNull public static JpsSdk<SdkProperties> getSdk(@NotNull CompileContext context, @NotNull JpsModule module) throws ProjectBuildException { JpsSdk<SdkProperties> sdk = module.getSdk(Elixir.INSTANCE); if (sdk == null) { String errorMessage = "No SDK for module " + module.getName(); context.processMessage(new CompilerMessage(Builder.BUILDER_NAME, BuildMessage.Kind.ERROR, errorMessage)); throw new ProjectBuildException(errorMessage); } return sdk; } }
@Override public void build(@NotNull Target target, @NotNull DirtyFilesHolder<SourceRootDescriptor, Target> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull CompileContext context) throws ProjectBuildException, IOException { LOGGER.info(target.getPresentableName()); final Set<File> filesToCompile = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY); holder.processDirtyFiles((target1, file, root) -> { boolean isAcceptFile = target1.isTests() ? ELIXIR_TEST_SOURCE_FILTER.accept(file) : ELIXIR_SOURCE_FILTER.accept(file); if (isAcceptFile && ourCompilableModuleTypes.contains(target1.getModule().getModuleType())) { filesToCompile.add(file); } return true; }); if (filesToCompile.isEmpty() && !holder.hasRemovedFiles()) return; JpsModule module = target.getModule(); JpsProject project = module.getProject(); CompilerOptions compilerOptions = Extension.getOrCreateExtension(project).getOptions(); if (compilerOptions.useMixCompiler) { doBuildWithMix(target, context, module, compilerOptions); } else { // elixirc can not compile tests now. if (!target.isTests()) { doBuildWithElixirc(target, context, module, compilerOptions, filesToCompile); } } }
@NotNull private static List<String> getCompileFilePathsDefault(@NotNull JpsModule module, @NotNull Target target) { CommonProcessors.CollectProcessor<File> exFilesCollector = new CommonProcessors.CollectProcessor<File>() { @Override protected boolean accept(File file) { return !file.isDirectory() && FileUtilRt.extensionEquals(file.getName(), ELIXIR_SOURCE_EXTENSION); } }; List<JpsModuleSourceRoot> sourceRoots = new ArrayList<>(); ContainerUtil.addAll(sourceRoots, module.getSourceRoots(JavaSourceRootType.SOURCE)); if (target.isTests()) { ContainerUtil.addAll(sourceRoots, module.getSourceRoots(JavaSourceRootType.TEST_SOURCE)); } for (JpsModuleSourceRoot root : sourceRoots) { FileUtil.processFilesRecursively(root.getFile(), exFilesCollector); } return ContainerUtil.map(exFilesCollector.getResults(), File::getAbsolutePath); }
private static void doBuildWithMix(Target target, CompileContext context, JpsModule module, CompilerOptions compilerOptions) throws ProjectBuildException, IOException { JpsSdk<SdkProperties> sdk = BuilderUtil.getSdk(context, module); for (String contentRootUrl : module.getContentRootsList().getUrls()) { String contentRootPath = new URL(contentRootUrl).getPath(); File contentRootDir = new File(contentRootPath); File mixConfigFile = new File(contentRootDir, MIX_CONFIG_FILE_NAME); if (!mixConfigFile.exists()) continue; String task = target.isTests() ? "test" : "compile"; runMix(sdk, module, contentRootPath, task, compilerOptions, context); } }
@Nullable @Override public Target createTarget(@NotNull String targetId) { for (JpsTypedModule<JpsDummyElement> module : model.getProject().getModules(ModuleType.INSTANCE)){ if(module.getName().equals(targetId)){ return new Target(Type.this, module); } } return null; } };
@NotNull private static String erlangSdkNameToErlExePath(@NotNull String erlangSdkName, @NotNull JpsModule module) throws LibraryNotFound, FileNotFoundException, AccessDeniedException { JpsLibraryCollection libraryCollection = module.getProject().getModel().getGlobal().getLibraryCollection(); JpsLibrary erlangSdkLibrary = libraryCollection.findLibrary(erlangSdkName); String erlExePath; if (erlangSdkLibrary != null) { erlExePath = erlangSdkLibraryToErlExePath(erlangSdkLibrary); } else { throw new LibraryNotFound(erlangSdkName); } return erlExePath; }
@Nullable public static JpsDLanguageModuleExtension getExtension(@Nullable final JpsModule module) { return module != null ? module.getContainer().getChild(ROLE) : null; }
@NotNull @Override public List<MonkeySourceRootDescriptor> computeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) { List<MonkeySourceRootDescriptor> result = new ArrayList<>(); JavaSourceRootType type = isTests() ? MONKEY_TEST_SOURCE_ROOT_TYPE : MONKEY_SOURCE_ROOT_TYPE; for (JpsTypedModuleSourceRoot<JavaSourceRootProperties> root : myModule.getSourceRoots(type)) { result.add(new MonkeySourceRootDescriptor(root.getFile(), this)); } return result; }
@NotNull @Override public String getPresentableName() { return "Elixir '" + myModule.getName() + "' " + (isTests() ? "test" : "production"); }
public Collection<BuildTarget<?>> computeDependencies(){ List<BuildTarget<?>> dependencies = new ArrayList<BuildTarget<?>>(); Set<JpsModule> modules = JpsJavaExtensionService.dependencies(myModule).includedIn(JpsJavaClasspathKind.compile(isTests())).getModules(); for (JpsModule module : modules){ if(module.getModuleType().equals(ModuleType.INSTANCE)){ dependencies.add(new Target(getElixirTargetType(), module)); } } if(isTests()){ dependencies.add(new Target(Type.PRODUCTION, myModule)); } return dependencies; }
/*** doBuildWithElixirc releated private methods */ @NotNull private static File getBuildOutputDirectory(@NotNull JpsModule module, boolean forTests, @NotNull CompileContext context) throws ProjectBuildException { JpsJavaExtensionService instance = JpsJavaExtensionService.getInstance(); File outputDirectory = instance.getOutputDirectory(module, forTests); if (outputDirectory == null) { String errorMessage = "No output directory for module " + module.getName(); context.processMessage(new CompilerMessage(ElIXIRC_NAME, BuildMessage.Kind.ERROR, errorMessage)); throw new ProjectBuildException(errorMessage); } if (!outputDirectory.exists()) { FileUtil.createDirectory(outputDirectory); } return outputDirectory; }
public MonkeyBuilder() { super(Arrays.asList(MonkeyBuildTargetType.PRODUCTION)); ResourcesBuilder.registerEnabler(module -> module.getModuleType() != JpsMonkeyModuleType.INSTANCE); }
@NotNull @Override public String getId() { return getModule().getName(); }
@NotNull @Override public String getPresentableName() { return "Module '" + getModule().getName() + "' " + (isTests() ? "tests" : "production"); }