use of com.android.tools.idea.gradle.dependencies.GradleDependencyManager in project android by JetBrains.
the class GradleBuildSystemService method addDependency.
/**
* @param artifact The dependency artifact without version.
* This method will add the ":+" to the given artifact.
* For Guava, for example: the artifact coordinate will not include the version:
* com.google.guava:guava
* and this method will add "+" as the version of the dependency to add.
*/
@Override
public void addDependency(@NotNull Module module, @NotNull String artifact) {
GradleDependencyManager manager = GradleDependencyManager.getInstance(module.getProject());
GradleCoordinate coordinate = GradleCoordinate.parseCoordinateString(artifact + ":+");
manager.ensureLibraryIsIncluded(module, Collections.singletonList(coordinate), null);
}
use of com.android.tools.idea.gradle.dependencies.GradleDependencyManager 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.tools.idea.gradle.dependencies.GradleDependencyManager in project android by JetBrains.
the class NlProperties method getProperties.
@NotNull
public Table<String, String, NlPropertyItem> getProperties(@NotNull List<NlComponent> components) {
AndroidFacet facet = getFacet(components);
if (facet == null) {
return ImmutableTable.of();
}
GradleDependencyManager dependencyManager = GradleDependencyManager.getInstance(facet.getModule().getProject());
return getProperties(facet, components, dependencyManager);
}
use of com.android.tools.idea.gradle.dependencies.GradleDependencyManager in project android by JetBrains.
the class NlOldPalettePanel method enableClickToLoadMissingDependency.
private void enableClickToLoadMissingDependency() {
myPaletteTree.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent event) {
Palette.BaseItem object = getItemForPath(myPaletteTree.getPathForLocation(event.getX(), event.getY()));
if (needsLibraryLoad(object)) {
Palette.Item item = (Palette.Item) object;
String coordinate = item.getGradleCoordinateId();
assert coordinate != null;
Module module = getModule();
assert module != null;
GradleDependencyManager manager = GradleDependencyManager.getInstance(myProject);
manager.ensureLibraryIsIncluded(module, toGradleCoordinates(Collections.singletonList(coordinate)), null);
}
}
});
GradleSyncState.subscribe(myProject, new GradleSyncListener.Adapter() {
@Override
public void syncSucceeded(@NotNull Project project) {
if (checkForNewMissingDependencies()) {
repaint();
}
}
}, this);
}
use of com.android.tools.idea.gradle.dependencies.GradleDependencyManager in project android by JetBrains.
the class UpgradeConstraintLayoutFix method apply.
public static void apply(@Nullable Module module) {
if (module != null) {
StudioSdkUtil.reloadRemoteSdkWithModalProgress();
AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(AndroidLintMissingConstraintsInspection.class);
RepoPackage p = SdkMavenRepository.findLatestVersion(LATEST_KNOWN_VERSION, sdkHandler, progress);
if (p != null) {
GradleCoordinate gc = SdkMavenRepository.getCoordinateFromSdkPath(p.getPath());
if (gc != null) {
// should always be the case unless the version suffix is somehow wrong
// Update version dependency in the module. Note that this will trigger a sync too.
GradleDependencyManager manager = GradleDependencyManager.getInstance(module.getProject());
manager.updateLibrariesToVersion(module, Collections.singletonList(gc), null);
}
}
}
}
Aggregations