use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class ConvertToConstraintLayoutAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
ScreenView screenView = mySurface.getCurrentScreenView();
if (screenView == null) {
return;
}
NlComponent target = findTarget(screenView);
if (target == null) {
// Shouldn't happen, enforced by update(AnActionEvent)
return;
}
// Step #1: UI
Project project = mySurface.getProject();
ConvertToConstraintLayoutForm dialog = new ConvertToConstraintLayoutForm(project);
if (!dialog.showAndGet()) {
return;
}
boolean flatten = dialog.getFlattenHierarchy();
boolean includeIds = dialog.getFlattenReferenced();
// Step #2: Ensure ConstraintLayout is available in the project
GradleDependencyManager manager = GradleDependencyManager.getInstance(project);
GradleCoordinate coordinate = GradleCoordinate.parseCoordinateString(SdkConstants.CONSTRAINT_LAYOUT_LIB_ARTIFACT + ":+");
if (!manager.ensureLibraryIsIncluded(screenView.getModel().getModule(), Collections.singletonList(coordinate), null)) {
return;
}
// Step #3: Migrate
NlModel model = screenView.getModel();
@SuppressWarnings("ConstantConditions") ConstraintLayoutConverter converter = new ConstraintLayoutConverter(screenView, target, flatten, includeIds);
converter.execute();
// Finally we need to apply the infer constraints action; we can't do that from the above action
// since we're holding the write lock
inferConstraints(model);
}
use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class NlOldPalettePanel method toGradleCoordinates.
@NotNull
private static List<GradleCoordinate> toGradleCoordinates(@NotNull Collection<String> dependencies) {
if (dependencies.isEmpty()) {
return Collections.emptyList();
}
List<GradleCoordinate> coordinates = Lists.newArrayList();
for (String dependency : dependencies) {
GradleCoordinate coordinate = GradleCoordinate.parseCoordinateString(dependency + ":+");
if (coordinate == null) {
continue;
}
coordinates.add(coordinate);
}
return coordinates;
}
use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class GradleEditorModelParserFacade method buildEntities.
@NotNull
private static List<GradleEditorEntityGroup> buildEntities(@NotNull GradleEditorModelParseContext context) {
VersionGradleEditorEntity entity = GradleEditorModelParserV1.buildGradlePluginVersion(context);
GradleCoordinate androidGradlePluginVersion = null;
if (entity != null) {
String currentVersion = entity.getCurrentValue();
if (!currentVersion.isEmpty()) {
androidGradlePluginVersion = GradleCoordinate.parseVersionOnly(currentVersion);
}
}
if (androidGradlePluginVersion == null) {
androidGradlePluginVersion = GradleCoordinate.parseVersionOnly("0");
}
Comparator<GradleCoordinate> c = GradleCoordinate.COMPARE_PLUS_HIGHER;
for (GradleEditorModelParser parser : ourParsers) {
if (c.compare(androidGradlePluginVersion, parser.getMinSupportedAndroidGradlePluginVersion()) >= 0 && c.compare(androidGradlePluginVersion, parser.getMaxSupportedAndroidGradlePluginVersion()) < 0) {
return parser.buildEntities(context);
}
}
return Collections.emptyList();
}
use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class UnresolvedDependenciesReporter method report.
private void report(@NotNull String dependency, @NotNull Module module, @Nullable VirtualFile buildFile) {
String group = "Unresolved Android dependencies";
GradleCoordinate coordinate = GradleCoordinate.parseCoordinateString(dependency);
RepoPackage constraintPackage = null;
if (coordinate != null) {
ProgressIndicator indicator = new StudioLoggerProgressIndicator(getClass());
reloadRemoteSdkWithModalProgress();
Collection<RemotePackage> remotePackages = getRemotePackages(indicator);
constraintPackage = findBestPackageMatching(coordinate, remotePackages);
}
List<NotificationHyperlink> quickFixes = new ArrayList<>();
if (dependency.startsWith("com.android.support.constraint:constraint-layout:") && !canGetConstraintLayoutFromSdkManager(module)) {
quickFixes.add(new FixAndroidGradlePluginVersionHyperlink());
} else if (constraintPackage != null) {
quickFixes.add(new InstallArtifactHyperlink(constraintPackage.getPath()));
} else if (dependency.startsWith("com.android.support")) {
quickFixes.add(new InstallRepositoryHyperlink(ANDROID));
} else if (dependency.startsWith("com.google.android")) {
quickFixes.add(new InstallRepositoryHyperlink(GOOGLE));
} else {
group = "Unresolved dependencies";
Project project = module.getProject();
if (isOfflineBuildModeEnabled(project)) {
quickFixes.add(new DisableOfflineModeHyperlink());
}
}
String text = "Failed to resolve: " + dependency;
SyncMessage message;
if (buildFile != null) {
PositionInFile position = findDependencyPosition(dependency, buildFile);
message = new SyncMessage(module.getProject(), group, ERROR, position, text);
String hyperlinkText = position.line > -1 ? "Show in File" : "Open File";
quickFixes.add(new OpenFileHyperlink(buildFile.getPath(), hyperlinkText, position.line, position.column));
} else {
message = new SyncMessage(group, ERROR, NonNavigatable.INSTANCE, text);
}
if (IdeInfo.getInstance().isAndroidStudio()) {
if (coordinate != null) {
quickFixes.add(new ShowDependencyInProjectStructureHyperlink(module, coordinate));
}
}
message.add(quickFixes);
getSyncMessages(module).report(message);
}
use of com.android.ide.common.repository.GradleCoordinate in project android by JetBrains.
the class GradleDependencyManagerTest method ignore_testDependencyAarIsExplodedForLayoutLib.
@SuppressWarnings("unused")
public void ignore_testDependencyAarIsExplodedForLayoutLib() throws Exception {
loadSimpleApplication();
List<GradleCoordinate> dependencies = Collections.singletonList(RECYCLER_VIEW_DEPENDENCY);
GradleDependencyManager dependencyManager = GradleDependencyManager.getInstance(getProject());
assertThat(dependencyManager.findMissingDependencies(myModules.getAppModule(), dependencies)).isNotEmpty();
Messages.setTestDialog(new TestMessagesDialog(Messages.OK));
boolean found = dependencyManager.ensureLibraryIsIncluded(myModules.getAppModule(), dependencies, null);
assertThat(found).isTrue();
List<ResourceItem> items = AppResourceRepository.getAppResources(myAndroidFacet, true).getResourceItem(ResourceType.DECLARE_STYLEABLE, "RecyclerView");
assertThat(items).isNotEmpty();
assertThat(dependencyManager.findMissingDependencies(myModules.getAppModule(), dependencies)).isEmpty();
}
Aggregations