Search in sources :

Example 1 with ValidationError

use of com.android.tools.idea.run.ValidationError in project intellij by bazelbuild.

the class BlazeAndroidBinaryRunConfigurationHandler method validate.

/**
 * We collect errors rather than throwing to avoid missing fatal errors by exiting early for a
 * warning. We use a separate method for the collection so the compiler prevents us from
 * accidentally throwing.
 */
private List<ValidationError> validate() {
    List<ValidationError> errors = Lists.newArrayList();
    Module module = getModule();
    errors.addAll(BlazeAndroidRunConfigurationValidationUtil.validateModule(module));
    AndroidFacet facet = null;
    if (module != null) {
        facet = AndroidFacet.getInstance(module);
        errors.addAll(BlazeAndroidRunConfigurationValidationUtil.validateFacet(facet, module));
    }
    errors.addAll(configState.validate(facet));
    errors.addAll(BlazeAndroidRunConfigurationValidationUtil.validateLabel(getLabel(), configuration.getProject(), ImmutableList.of(Kind.ANDROID_BINARY)));
    return errors;
}
Also used : ValidationError(com.android.tools.idea.run.ValidationError) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 2 with ValidationError

use of com.android.tools.idea.run.ValidationError in project intellij by bazelbuild.

the class BlazeAndroidRunConfigurationValidationUtil method validateModule.

public static List<ValidationError> validateModule(@Nullable Module module) {
    List<ValidationError> errors = Lists.newArrayList();
    if (module == null) {
        errors.add(ValidationError.fatal("No run configuration module found. Have you successfully synced your project?"));
        return errors;
    }
    final Project project = module.getProject();
    if (AndroidProjectInfo.getInstance(project).requiredAndroidModelMissing()) {
        errors.add(ValidationError.fatal(SYNC_FAILED_ERR_MSG));
    }
    return errors;
}
Also used : Project(com.intellij.openapi.project.Project) ValidationError(com.android.tools.idea.run.ValidationError)

Example 3 with ValidationError

use of com.android.tools.idea.run.ValidationError in project intellij by bazelbuild.

the class BlazeAndroidRunConfigurationValidationUtil method validateExecution.

public static void validateExecution(@Nullable Module module, @Nullable AndroidFacet facet, @Nullable ProjectViewSet projectViewSet) throws ExecutionException {
    List<ValidationError> errors = Lists.newArrayList();
    errors.addAll(validateModule(module));
    if (module != null) {
        errors.addAll(validateFacet(facet, module));
    }
    if (projectViewSet == null) {
        errors.add(ValidationError.fatal("Could not load project view. Please resync project"));
    }
    if (errors.isEmpty()) {
        return;
    }
    ValidationError topError = Ordering.natural().max(errors);
    if (topError.isFatal()) {
        throw new ExecutionException(topError.getMessage());
    }
}
Also used : ValidationError(com.android.tools.idea.run.ValidationError) ExecutionException(com.intellij.execution.ExecutionException)

Example 4 with ValidationError

use of com.android.tools.idea.run.ValidationError in project intellij by bazelbuild.

the class BlazeAndroidTestRunConfigurationHandler method validate.

/**
 * We collect errors rather than throwing to avoid missing fatal errors by exiting early for a
 * warning. We use a separate method for the collection so the compiler prevents us from
 * accidentally throwing.
 */
private List<ValidationError> validate() {
    List<ValidationError> errors = Lists.newArrayList();
    Module module = getModule();
    errors.addAll(BlazeAndroidRunConfigurationValidationUtil.validateModule(module));
    AndroidFacet facet = null;
    if (module != null) {
        facet = AndroidFacet.getInstance(module);
        errors.addAll(BlazeAndroidRunConfigurationValidationUtil.validateFacet(facet, module));
    }
    errors.addAll(configState.validate(facet));
    errors.addAll(BlazeAndroidRunConfigurationValidationUtil.validateLabel(getLabel(), configuration.getProject(), ImmutableList.of(Kind.ANDROID_TEST, Kind.ANDROID_INSTRUMENTATION_TEST)));
    return errors;
}
Also used : ValidationError(com.android.tools.idea.run.ValidationError) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 5 with ValidationError

use of com.android.tools.idea.run.ValidationError in project intellij by bazelbuild.

the class BlazeAndroidRunConfigurationValidationUtil method validateLabel.

public static List<ValidationError> validateLabel(@Nullable Label label, Project project, ImmutableList<Kind> kinds) {
    List<ValidationError> errors = Lists.newArrayList();
    if (label == null) {
        errors.add(ValidationError.fatal("No target selected."));
        return errors;
    }
    TargetInfo target = TargetFinder.findTargetInfo(project, label);
    if (target == null) {
        errors.add(ValidationError.fatal(String.format("No existing %s rule selected.", Blaze.buildSystemName(project))));
    } else if (target.getKind() == null || !target.getKind().isOneOf(kinds)) {
        errors.add(ValidationError.fatal(String.format("Selected %s rule is not one of: %s", Blaze.buildSystemName(project), kinds.stream().map(Kind::toString).collect(Collectors.joining(", ")))));
    }
    return errors;
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ValidationError(com.android.tools.idea.run.ValidationError)

Aggregations

ValidationError (com.android.tools.idea.run.ValidationError)5 Module (com.intellij.openapi.module.Module)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)1 ExecutionException (com.intellij.execution.ExecutionException)1 Project (com.intellij.openapi.project.Project)1