use of org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder in project intellij-community by JetBrains.
the class GradleModuleBuilder method setupModule.
@Override
protected void setupModule(Module module) throws ConfigurationException {
super.setupModule(module);
assert rootProjectPath != null;
VirtualFile buildScriptFile = null;
final BuildScriptDataBuilder buildScriptDataBuilder = getBuildScriptData(module);
try {
if (buildScriptDataBuilder != null) {
buildScriptFile = buildScriptDataBuilder.getBuildScriptFile();
final String text = buildScriptDataBuilder.build();
appendToFile(buildScriptFile, "\n" + text);
}
} catch (IOException e) {
LOG.warn("Unexpected exception on applying frameworks templates", e);
}
final Project project = module.getProject();
if (myWizardContext.isCreatingNewProject()) {
getExternalProjectSettings().setExternalProjectPath(rootProjectPath);
AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID);
project.putUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT, Boolean.TRUE);
//noinspection unchecked
settings.linkProject(getExternalProjectSettings());
} else {
FileDocumentManager.getInstance().saveAllDocuments();
final GradleProjectSettings gradleProjectSettings = getExternalProjectSettings();
final VirtualFile finalBuildScriptFile = buildScriptFile;
Runnable runnable = () -> {
if (myParentProject == null) {
gradleProjectSettings.setExternalProjectPath(rootProjectPath);
AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID);
//noinspection unchecked
settings.linkProject(gradleProjectSettings);
}
ImportSpec importSpec = new ImportSpecBuilder(project, GradleConstants.SYSTEM_ID).use(ProgressExecutionMode.IN_BACKGROUND_ASYNC).createDirectoriesForEmptyContentRoots().useDefaultCallback().build();
ExternalSystemUtil.refreshProject(rootProjectPath, importSpec);
final PsiFile psiFile;
if (finalBuildScriptFile != null) {
psiFile = PsiManager.getInstance(project).findFile(finalBuildScriptFile);
if (psiFile != null) {
EditorHelper.openInEditor(psiFile);
}
}
};
// execute when current dialog is closed
ExternalSystemUtil.invokeLater(project, ModalityState.NON_MODAL, runnable);
}
}
use of org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder in project intellij-community by JetBrains.
the class GradleModuleBuilder method setupRootModel.
@Override
public void setupRootModel(final ModifiableRootModel modifiableRootModel) throws ConfigurationException {
String contentEntryPath = getContentEntryPath();
if (StringUtil.isEmpty(contentEntryPath)) {
return;
}
File contentRootDir = new File(contentEntryPath);
FileUtilRt.createDirectory(contentRootDir);
LocalFileSystem fileSystem = LocalFileSystem.getInstance();
VirtualFile modelContentRootDir = fileSystem.refreshAndFindFileByIoFile(contentRootDir);
if (modelContentRootDir == null) {
return;
}
modifiableRootModel.addContentEntry(modelContentRootDir);
// todo this should be moved to generic ModuleBuilder
if (myJdk != null) {
modifiableRootModel.setSdk(myJdk);
} else {
modifiableRootModel.inheritSdk();
}
final Project project = modifiableRootModel.getProject();
if (myParentProject != null) {
rootProjectPath = myParentProject.getLinkedExternalProjectPath();
} else {
rootProjectPath = FileUtil.toCanonicalPath(myWizardContext.isCreatingNewProject() ? project.getBasePath() : modelContentRootDir.getPath());
}
assert rootProjectPath != null;
final VirtualFile gradleBuildFile = setupGradleBuildFile(modelContentRootDir);
setupGradleSettingsFile(rootProjectPath, modelContentRootDir, modifiableRootModel.getProject().getName(), myProjectId == null ? modifiableRootModel.getModule().getName() : myProjectId.getArtifactId(), myWizardContext.isCreatingNewProject() || myParentProject == null);
if (gradleBuildFile != null) {
modifiableRootModel.getModule().putUserData(BUILD_SCRIPT_DATA, new BuildScriptDataBuilder(gradleBuildFile));
}
}
Aggregations