use of com.intellij.facet.FacetManager in project intellij by bazelbuild.
the class BlazePythonSyncPlugin method getOrCreatePythonFacet.
@Nullable
private static LibraryContributingFacet<?> getOrCreatePythonFacet(BlazeContext context, Module module) {
LibraryContributingFacet<?> facet = findPythonFacet(module);
if (facet != null && facetHasSdk(facet)) {
return facet;
}
FacetManager manager = FacetManager.getInstance(module);
ModifiableFacetModel facetModel = manager.createModifiableModel();
if (facet != null) {
// we can't modify in place, IntelliJ has no hook to trigger change events. Instead we create
// a new facet.
facetModel.removeFacet(facet);
}
Sdk sdk = getOrCreatePythonSdk();
if (sdk == null) {
String msg = "Unable to find a Python SDK installed.\n" + "After configuring a suitable SDK in the \"Project Structure\" dialog, " + "sync the project again.";
IssueOutput.error(msg).submit(context);
return null;
}
facet = manager.createFacet(PythonFacetUtil.getFacetType(), "Python", null);
facetModel.addFacet(facet);
facetModel.commit();
return facet;
}
use of com.intellij.facet.FacetManager in project intellij by bazelbuild.
the class AndroidFacetModuleCustomizer method createAndroidFacet.
public static void createAndroidFacet(Module module) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null) {
configureFacet(facet);
} else {
// Module does not have Android facet. Create one and add it.
FacetManager facetManager = FacetManager.getInstance(module);
ModifiableFacetModel model = facetManager.createModifiableModel();
try {
facet = facetManager.createFacet(AndroidFacet.getFacetType(), AndroidFacet.NAME, null);
model.addFacet(facet);
configureFacet(facet);
} finally {
model.commit();
}
}
}
use of com.intellij.facet.FacetManager in project google-cloud-intellij by GoogleCloudPlatform.
the class AppEngineUtil method createArtifactDeploymentSources.
/**
* Creates a list of artifact deployment sources available for deployment to App Engine.
*
* <p>Artifacts either target the standard or the flexible environment. All standard artifacts are
* added. Flexible artifacts are only added if there are no other standard artifacts associated
* with the same module.
*
* @return a list of {@link AppEngineArtifactDeploymentSource}
*/
public static List<AppEngineArtifactDeploymentSource> createArtifactDeploymentSources(@NotNull final Project project) {
List<AppEngineArtifactDeploymentSource> sources = Lists.newArrayList();
AppEngineProjectService projectService = AppEngineProjectService.getInstance();
for (Module module : ModuleManager.getInstance(project).getModules()) {
FacetManager facetManager = FacetManager.getInstance(module);
if (facetManager.getFacetByType(AppEngineStandardFacetType.ID) != null || facetManager.getFacetByType(AppEngineFlexibleFacetType.ID) != null) {
final AppEngineEnvironment environment = projectService.getModuleAppEngineEnvironment(module).orElseThrow(() -> new RuntimeException("No environment."));
Collection<Artifact> artifacts = ArtifactUtil.getArtifactsContainingModuleOutput(module);
sources.addAll(artifacts.stream().filter(artifact -> doesArtifactMatchEnvironment(artifact, environment)).map(artifact -> AppEngineUtil.createArtifactDeploymentSource(project, artifact, environment)).collect(toList()));
}
}
return sources;
}
use of com.intellij.facet.FacetManager in project android by JetBrains.
the class AndroidTestCase method addAndroidFacet.
private static AndroidFacet addAndroidFacet(Module module, boolean attachSdk) {
FacetManager facetManager = FacetManager.getInstance(module);
AndroidFacet facet = facetManager.createFacet(AndroidFacet.getFacetType(), "Android", null);
if (attachSdk) {
addLatestAndroidSdk(module);
}
ModifiableFacetModel facetModel = facetManager.createModifiableModel();
facetModel.addFacet(facet);
ApplicationManager.getApplication().runWriteAction(facetModel::commit);
return facet;
}
use of com.intellij.facet.FacetManager in project android by JetBrains.
the class NewProjectImportGradleSyncListener method createTopLevelModule.
@VisibleForTesting
public static void createTopLevelModule(@NotNull Project project) {
ModuleManager moduleManager = ModuleManager.getInstance(project);
File projectRootDir = getBaseDirPath(project);
VirtualFile contentRoot = findFileByIoFile(projectRootDir, true);
if (contentRoot != null) {
File moduleFile = new File(projectRootDir, projectRootDir.getName() + ".iml");
Module module = moduleManager.newModule(moduleFile.getPath(), JAVA.getId());
// This prevents the balloon "Unsupported Modules detected".
ExternalSystemModulePropertyManager.getInstance(module).setExternalId(GRADLE_SYSTEM_ID);
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
model.addContentEntry(contentRoot);
if (IdeInfo.getInstance().isAndroidStudio()) {
// If sync fails, make sure that the project has a JDK, otherwise Groovy indices won't work (a common scenario where
// users will update build.gradle files to fix Gradle sync.)
// See: https://code.google.com/p/android/issues/detail?id=194621
Sdk jdk = IdeSdks.getInstance().getJdk();
if (jdk != null) {
model.setSdk(jdk);
}
}
model.commit();
FacetManager facetManager = FacetManager.getInstance(module);
ModifiableFacetModel facetModel = facetManager.createModifiableModel();
try {
GradleFacet gradleFacet = GradleFacet.getInstance(module);
if (gradleFacet == null) {
// Add "gradle" facet, to avoid balloons about unsupported compilation of modules.
gradleFacet = facetManager.createFacet(GradleFacet.getFacetType(), GradleFacet.getFacetName(), null);
facetModel.addFacet(gradleFacet);
}
gradleFacet.getConfiguration().GRADLE_PROJECT_PATH = GRADLE_PATH_SEPARATOR;
// Add "android" facet to avoid the balloon "Android Framework detected".
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
if (androidFacet == null) {
androidFacet = facetManager.createFacet(AndroidFacet.getFacetType(), AndroidFacet.NAME, null);
facetModel.addFacet(androidFacet);
}
// This is what actually stops Studio from showing the balloon.
androidFacet.getProperties().ALLOW_USER_CONFIGURATION = false;
} finally {
facetModel.commit();
}
}
}
Aggregations