use of com.intellij.openapi.module.ModuleType in project intellij-community by JetBrains.
the class MavenImporter method getSuitableImporters.
public static List<MavenImporter> getSuitableImporters(MavenProject p) {
List<MavenImporter> result = null;
Set<ModuleType> moduleTypes = null;
for (MavenImporter importer : EXTENSION_POINT_NAME.getExtensions()) {
if (importer.isApplicable(p)) {
if (result == null) {
result = new ArrayList<>();
moduleTypes = new THashSet<>();
}
result.add(importer);
moduleTypes.add(importer.getModuleType());
}
}
if (result == null) {
return Collections.emptyList();
}
if (moduleTypes.size() <= 1) {
return result;
}
// This code is reached when several importers say that they are applicable but they want to have different module types.
// Now we select one module type and return only those importers that are ok with it.
// If possible - return at least one importer that explicitly supports packaging of the given maven project.
ModuleType moduleType = result.get(0).getModuleType();
List<String> supportedPackagings = new ArrayList<>();
for (MavenImporter importer : result) {
supportedPackagings.clear();
importer.getSupportedPackagings(supportedPackagings);
if (supportedPackagings.contains(p.getPackaging())) {
moduleType = importer.getModuleType();
break;
}
}
final ModuleType finalModuleType = moduleType;
return ContainerUtil.filter(result, importer -> importer.getModuleType() == finalModuleType);
}
use of com.intellij.openapi.module.ModuleType in project intellij-community by JetBrains.
the class PythonLanguageLevelPusher method isPythonModule.
private static boolean isPythonModule(@NotNull final Module module) {
final ModuleType moduleType = ModuleType.get(module);
if (moduleType instanceof PythonModuleTypeBase)
return true;
final Facet[] allFacets = FacetManager.getInstance(module).getAllFacets();
for (Facet facet : allFacets) {
if (facet.getConfiguration() instanceof PythonFacetSettings) {
return true;
}
}
return false;
}
use of com.intellij.openapi.module.ModuleType in project intellij-community by JetBrains.
the class FacetManagerImpl method addFacets.
private void addFacets(final List<FacetState> facetStates, final Facet underlyingFacet, ModifiableFacetModel model) {
FacetTypeRegistry registry = FacetTypeRegistry.getInstance();
for (FacetState child : facetStates) {
final String typeId = child.getFacetType();
if (typeId == null) {
addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.facet.type.isn.t.specified"));
continue;
}
final FacetType<?, ?> type = registry.findFacetType(typeId);
if (type == null) {
addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.unknown.facet.type.0", typeId), typeId);
continue;
}
ModuleType moduleType = ModuleType.get(myModule);
if (!type.isSuitableModuleType(moduleType)) {
addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.facets.are.not.allowed.in.1", type.getPresentableName(), moduleType.getName()));
continue;
}
FacetType<?, ?> expectedUnderlyingType = null;
FacetTypeId<?> underlyingTypeId = type.getUnderlyingFacetType();
if (underlyingTypeId != null) {
expectedUnderlyingType = registry.findFacetType(underlyingTypeId);
}
FacetType actualUnderlyingType = underlyingFacet != null ? underlyingFacet.getType() : null;
if (expectedUnderlyingType != null) {
if (!expectedUnderlyingType.equals(actualUnderlyingType)) {
addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.facet.must.be.placed.under.1.facet", type.getPresentableName(), expectedUnderlyingType.getPresentableName()));
continue;
}
} else if (actualUnderlyingType != null) {
addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.cannot.be.placed.under.1", type.getPresentableName(), actualUnderlyingType.getPresentableName()));
continue;
}
try {
addFacet(type, child, underlyingFacet, model);
} catch (InvalidDataException e) {
LOG.info(e);
addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.cannot.load.facet.configuration.0", e.getMessage()));
}
}
}
use of com.intellij.openapi.module.ModuleType in project android by JetBrains.
the class AndroidGradleProjectComponent method checkForSupportedModules.
/**
* Verifies that the project, if it is an Android Gradle project, does not have any modules that are not known by Gradle. For example,
* when adding a plain IDEA Java module.
* Do not call this method from {@link ModuleListener#moduleAdded(Project, Module)} because the settings that this method look for are
* not present when importing a valid Gradle-aware module, resulting in false positives.
*/
public void checkForSupportedModules() {
Module[] modules = ModuleManager.getInstance(myProject).getModules();
if (modules.length == 0 || !isBuildWithGradle(myProject)) {
return;
}
List<Module> unsupportedModules = new ArrayList<>();
for (Module module : modules) {
ModuleType moduleType = ModuleType.get(module);
if (moduleType instanceof JavaModuleType) {
if (!GRADLE_SYSTEM_ID.getId().equals(ExternalSystemModulePropertyManager.getInstance(module).getExternalSystemId())) {
unsupportedModules.add(module);
}
}
}
if (unsupportedModules.size() == 0) {
return;
}
String s = join(unsupportedModules, Module::getName, ", ");
AndroidGradleNotification.getInstance(myProject).showBalloon("Unsupported Modules Detected", "Compilation is not supported for following modules: " + s + ". Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project.", NotificationType.ERROR);
}
use of com.intellij.openapi.module.ModuleType in project intellij-community by JetBrains.
the class RootDetectionProcessor method mergeContentRoots.
private List<DetectedRootData> mergeContentRoots(Map<File, DetectedRootData> rootData) {
LOG.debug(rootData.size() + " roots found, merging content roots");
boolean hasSourceRoots = false;
Set<ModuleType> typesToReplace = new HashSet<>();
Set<ModuleType> moduleTypes = new HashSet<>();
for (DetectedRootData data : rootData.values()) {
for (DetectedProjectRoot root : data.getAllRoots()) {
if (root instanceof DetectedContentRoot) {
Collections.addAll(typesToReplace, ((DetectedContentRoot) root).getTypesToReplace());
moduleTypes.add(((DetectedContentRoot) root).getModuleType());
} else if (root instanceof DetectedSourceRoot) {
LOG.debug("Source root found: " + root.getDirectory() + ", content roots will be ignored");
hasSourceRoots = true;
break;
}
}
}
moduleTypes.removeAll(typesToReplace);
if (hasSourceRoots || moduleTypes.size() <= 1) {
Iterator<DetectedRootData> iterator = rootData.values().iterator();
DetectedContentRoot firstRoot = null;
ProjectStructureDetector firstDetector = null;
while (iterator.hasNext()) {
DetectedRootData data = iterator.next();
for (DetectedProjectRoot root : data.getAllRoots()) {
if (root instanceof DetectedContentRoot) {
LOG.debug("Removed detected " + root.getRootTypeName() + " content root: " + root.getDirectory());
Collection<ProjectStructureDetector> detectors = data.removeRoot(root);
if ((firstRoot == null || firstDetector == null) && moduleTypes.contains(((DetectedContentRoot) root).getModuleType())) {
firstRoot = (DetectedContentRoot) root;
firstDetector = ContainerUtil.getFirstItem(detectors);
}
}
}
if (data.isEmpty()) {
iterator.remove();
}
}
if (!hasSourceRoots && firstRoot != null && firstDetector != null) {
DetectedContentRoot baseRoot = new DetectedContentRoot(myBaseDir, firstRoot.getRootTypeName(), firstRoot.getModuleType());
DetectedRootData data = rootData.get(myBaseDir);
if (data == null) {
rootData.put(myBaseDir, new DetectedRootData(firstDetector, baseRoot));
} else {
data.addRoot(firstDetector, baseRoot);
}
LOG.debug("Added " + firstRoot.getRootTypeName() + " content root for " + myBaseDir);
}
}
return new ArrayList<>(rootData.values());
}
Aggregations