Search in sources :

Example 1 with GradleDependencyManager

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);
}
Also used : GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) GradleDependencyManager(com.android.tools.idea.gradle.dependencies.GradleDependencyManager)

Example 2 with GradleDependencyManager

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);
}
Also used : Project(com.intellij.openapi.project.Project) ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) NlModel(com.android.tools.idea.uibuilder.model.NlModel) GradleDependencyManager(com.android.tools.idea.gradle.dependencies.GradleDependencyManager)

Example 3 with GradleDependencyManager

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);
}
Also used : GradleDependencyManager(com.android.tools.idea.gradle.dependencies.GradleDependencyManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GradleDependencyManager

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);
}
Also used : DnDTransferItem(com.android.tools.idea.uibuilder.model.DnDTransferItem) Project(com.intellij.openapi.project.Project) MouseEvent(java.awt.event.MouseEvent) GradleSyncListener(com.android.tools.idea.gradle.project.sync.GradleSyncListener) MouseAdapter(java.awt.event.MouseAdapter) Module(com.intellij.openapi.module.Module) GradleDependencyManager(com.android.tools.idea.gradle.dependencies.GradleDependencyManager)

Example 5 with GradleDependencyManager

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);
            }
        }
    }
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) GradleDependencyManager(com.android.tools.idea.gradle.dependencies.GradleDependencyManager) RepoPackage(com.android.repository.api.RepoPackage)

Aggregations

GradleDependencyManager (com.android.tools.idea.gradle.dependencies.GradleDependencyManager)8 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)5 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 RepoPackage (com.android.repository.api.RepoPackage)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 GradleSyncListener (com.android.tools.idea.gradle.project.sync.GradleSyncListener)1 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)1 DnDTransferItem (com.android.tools.idea.uibuilder.model.DnDTransferItem)1 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)1 NlModel (com.android.tools.idea.uibuilder.model.NlModel)1 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1 NotNull (org.jetbrains.annotations.NotNull)1