use of com.android.tools.idea.gradle.parser.GradleBuildFile in project freeline by alibaba.
the class FreelineUtil method checkInstall.
/**
* 检查是否需要载入Freeline
*
* @param project
* @return
*/
public static boolean checkInstall(@NotNull final Project project) {
final FreelineStatus status = getFreelineStatus(project);
if (GradleUtil.isSyncInProgress(project)) {
NotificationUtils.errorMsgDialog("Waiting for sync project to complete");
return false;
}
if (status.hasInitFreeline()) {
return true;
}
if (status.getGradleBuildFiles().size() < 1) {
NotificationUtils.errorMsgDialog("It's not an Android Gradle project Currently?");
return false;
}
if (status.isExistClasspath() && status.isExistPlugin() && !status.isExistFreelineCore()) {
NotificationUtils.errorNotification("Execute task initFreeline and download freeline dependencies...");
initFreeline(project);
return false;
}
if (DialogUtil.createDialog("Detected that you did not installFreeline Freeline, Whether installFreeline Automatically?", "Install Freeline Automatically", "Cancel")) {
Module[] modules = ModuleManager.getInstance(project).getModules();
List<Pair<Module, PsiFile>> selectModulesList = new ArrayList<Pair<Module, PsiFile>>();
for (Module module : modules) {
GradleBuildFile file = GradleBuildFile.get(module);
if (file != null && !GradleUtil.isLibrary(file)) {
selectModulesList.add(Pair.create(module, file.getPsiFile()));
}
}
// 多个app模块的情况
if (selectModulesList.size() > 1) {
final DialogBuilder builder = new DialogBuilder();
builder.setTitle("Install Freeline");
builder.resizable(false);
builder.setCenterPanel(new JLabel("There are multiple application modules, Please select the module to be installed Freeline.", Messages.getInformationIcon(), SwingConstants.CENTER));
builder.addOkAction().setText("Cancel");
for (final Pair<Module, PsiFile> pair : selectModulesList) {
builder.addAction(new AbstractAction(":" + pair.first.getName()) {
@Override
public void actionPerformed(ActionEvent e) {
builder.getDialogWrapper().close(DialogWrapper.CANCEL_EXIT_CODE);
installFreeline(project, status, pair.getSecond());
}
});
}
if (builder.show() > -1) {
return false;
}
} else if (selectModulesList.size() == 1) {
installFreeline(project, status, selectModulesList.get(0).getSecond());
} else {
NotificationUtils.errorMsgDialog("Can not found Application Module! Please Sync Project.");
return false;
}
}
return false;
}
use of com.android.tools.idea.gradle.parser.GradleBuildFile in project freeline by alibaba.
the class UsingReportAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent event) {
final Project project = event.getProject();
Module[] modules = ModuleManager.getInstance(project).getModules();
List<Pair<Module, PsiFile>> selectModulesList = new ArrayList<Pair<Module, PsiFile>>();
for (Module module : modules) {
GradleBuildFile file = GradleBuildFile.get(module);
if (file != null && !GradleUtil.isLibrary(file)) {
selectModulesList.add(Pair.create(module, file.getPsiFile()));
}
}
if (selectModulesList.size() > 1) {
final DialogBuilder builder = new DialogBuilder();
builder.setTitle("Freeline Reporter");
builder.resizable(false);
builder.setCenterPanel(new JLabel("There are multiple application modules, Please select the exact one.", Messages.getInformationIcon(), SwingConstants.CENTER));
builder.addOkAction().setText("Cancel");
for (final Pair<Module, PsiFile> pair : selectModulesList) {
builder.addAction(new AbstractAction(":" + pair.first.getName()) {
@Override
public void actionPerformed(ActionEvent e) {
builder.getDialogWrapper().close(DialogWrapper.CANCEL_EXIT_CODE);
report(project, pair.getSecond());
}
});
}
if (builder.show() > -1) {
//return false;
}
} else if (selectModulesList.size() == 1) {
report(project, selectModulesList.get(0).getSecond());
}
}
use of com.android.tools.idea.gradle.parser.GradleBuildFile in project android by JetBrains.
the class GradleSyncTest method sdkCreationForAddons.
// https://code.google.com/p/android/issues/detail?id=185313
@Test
public void sdkCreationForAddons() throws IOException {
guiTest.importSimpleApplication();
IdeFrameFixture ideFrame = guiTest.ideFrame();
Project project = ideFrame.getProject();
Module appModule = ideFrame.getModule("app");
GradleBuildFile buildFile = GradleBuildFile.get(appModule);
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
runWriteCommandAction(project, () -> buildFile.setValue(BuildFileKey.COMPILE_SDK_VERSION, "Google Inc.:Google APIs:24"));
}
});
ideFrame.requestProjectSync().waitForGradleProjectSyncToFinish();
Sdk sdk = ModuleRootManager.getInstance(appModule).getSdk();
AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
SdkAdditionalData data = sdk.getSdkAdditionalData();
assertThat(data).isInstanceOf(AndroidSdkAdditionalData.class);
AndroidSdkAdditionalData androidSdkData = (AndroidSdkAdditionalData) data;
IAndroidTarget buildTarget = androidSdkData.getBuildTarget(sdkData);
// By checking that there are no additional libraries in the SDK, we are verifying that an additional SDK was not created for add-ons.
assertThat(buildTarget.getAdditionalLibraries()).hasSize(0);
}
use of com.android.tools.idea.gradle.parser.GradleBuildFile in project android by JetBrains.
the class KeystoreUtils method getGradleDebugKeystore.
/**
* Gets a custom debug keystore defined in the build.gradle file for this module
*
* @return null if there is no custom debug keystore configured, or if the project is not a Gradle project.
*/
@Nullable
private static File getGradleDebugKeystore(@NotNull AndroidFacet facet) {
GradleSettingsFile gradleSettingsFile = GradleSettingsFile.get(facet.getModule().getProject());
if (gradleSettingsFile == null) {
return null;
}
String modulePath = GradleSettingsFile.getModuleGradlePath(facet.getModule());
if (modulePath == null) {
return null;
}
final GradleBuildFile moduleBuildFile = gradleSettingsFile.getModuleBuildFile(modulePath);
if (moduleBuildFile == null) {
return null;
}
Iterable<NamedObject> signingConfigs = ApplicationManager.getApplication().runReadAction(new Computable<Iterable<NamedObject>>() {
@Override
@SuppressWarnings("unchecked")
public Iterable<NamedObject> compute() {
return (Iterable<NamedObject>) moduleBuildFile.getValue(BuildFileKey.SIGNING_CONFIGS);
}
});
if (signingConfigs == null) {
return null;
}
for (NamedObject namedObject : signingConfigs) {
if (!"debug".equals(namedObject.getName())) {
continue;
}
File debugKey = (File) namedObject.getValue(BuildFileKey.STORE_FILE);
if (debugKey == null) {
continue;
}
// NOTE: debugKey.getParent() is the current working directory.
return new File(ModuleUtilCore.getModuleDirPath(facet.getModule()), debugKey.getPath());
}
return null;
}
use of com.android.tools.idea.gradle.parser.GradleBuildFile in project android by JetBrains.
the class ManifestPanel method getErrorRemoveHtml.
@NotNull
private static String getErrorRemoveHtml(@NotNull final AndroidFacet facet, @NotNull String message, @NotNull final SourceFilePosition position, @NotNull HtmlLinkManager htmlLinkManager, @Nullable final VirtualFile currentlyOpenFile) {
/*
Example Input:
ERROR Overlay manifest:package attribute declared at AndroidManifest.xml:3:5-49
value=(com.foo.manifestapplication.debug) has a different value=(com.foo.manifestapplication)
declared in main manifest at AndroidManifest.xml:5:5-43 Suggestion: remove the overlay
declaration at AndroidManifest.xml and place it in the build.gradle: flavorName
{ applicationId = "com.foo.manifestapplication.debug" } AndroidManifest.xml (debug)
*/
HtmlBuilder sb = new HtmlBuilder();
int start = message.indexOf('{');
int end = message.indexOf('}', start + 1);
final String declaration = message.substring(start + 1, end).trim();
if (!declaration.startsWith("applicationId")) {
throw new IllegalArgumentException("unexpected remove suggestion format " + message);
}
final GradleBuildFile buildFile = GradleBuildFile.get(facet.getModule());
Runnable link = null;
if (buildFile != null) {
final String applicationId = declaration.substring(declaration.indexOf('"') + 1, declaration.lastIndexOf('"'));
final File manifestOverlayFile = position.getFile().getSourceFile();
assert manifestOverlayFile != null;
VirtualFile manifestOverlayVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(manifestOverlayFile);
assert manifestOverlayVirtualFile != null;
IdeaSourceProvider sourceProvider = ManifestUtils.findManifestSourceProvider(facet, manifestOverlayVirtualFile);
assert sourceProvider != null;
final String name = sourceProvider.getName();
AndroidModuleModel androidModuleModel = AndroidModuleModel.get(facet.getModule());
assert androidModuleModel != null;
final XmlFile manifestOverlayPsiFile = (XmlFile) PsiManager.getInstance(facet.getModule().getProject()).findFile(manifestOverlayVirtualFile);
assert manifestOverlayPsiFile != null;
if (androidModuleModel.getBuildTypeNames().contains(name)) {
final String packageName = MergedManifest.get(facet).getPackage();
assert packageName != null;
if (applicationId.startsWith(packageName)) {
link = () -> new WriteCommandAction.Simple(facet.getModule().getProject(), "Apply manifest suggestion", buildFile.getPsiFile(), manifestOverlayPsiFile) {
@Override
protected void run() throws Throwable {
if (currentlyOpenFile != null) {
// We mark this action as affecting the currently open file, so the Undo is available in this editor
CommandProcessor.getInstance().addAffectedFiles(facet.getModule().getProject(), currentlyOpenFile);
}
removePackageAttribute(manifestOverlayPsiFile);
final String applicationIdSuffix = applicationId.substring(packageName.length());
@SuppressWarnings("unchecked") List<NamedObject> buildTypes = (List<NamedObject>) buildFile.getValue(BuildFileKey.BUILD_TYPES);
if (buildTypes == null) {
buildTypes = new ArrayList<>();
}
NamedObject buildType = find(buildTypes, name);
if (buildType == null) {
buildType = new NamedObject(name);
buildTypes.add(buildType);
}
buildType.setValue(BuildFileKey.APPLICATION_ID_SUFFIX, applicationIdSuffix);
buildFile.setValue(BuildFileKey.BUILD_TYPES, buildTypes);
GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(facet.getModule().getProject(), null);
}
}.execute();
}
} else if (androidModuleModel.getProductFlavorNames().contains(name)) {
link = () -> new WriteCommandAction.Simple(facet.getModule().getProject(), "Apply manifest suggestion", buildFile.getPsiFile(), manifestOverlayPsiFile) {
@Override
protected void run() throws Throwable {
if (currentlyOpenFile != null) {
// We mark this action as affecting the currently open file, so the Undo is available in this editor
CommandProcessor.getInstance().addAffectedFiles(facet.getModule().getProject(), currentlyOpenFile);
}
removePackageAttribute(manifestOverlayPsiFile);
@SuppressWarnings("unchecked") List<NamedObject> flavors = (List<NamedObject>) buildFile.getValue(BuildFileKey.FLAVORS);
assert flavors != null;
NamedObject flavor = find(flavors, name);
assert flavor != null;
flavor.setValue(BuildFileKey.APPLICATION_ID, applicationId);
buildFile.setValue(BuildFileKey.FLAVORS, flavors);
GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(facet.getModule().getProject(), null);
}
}.execute();
}
}
if (link != null) {
sb.addLink(message.substring(0, end + 1), htmlLinkManager.createRunnableLink(link));
sb.add(message.substring(end + 1));
} else {
sb.add(message);
}
return sb.getHtml();
}
Aggregations