org.gradle.tooling.BuildException Java Examples

The following examples show how to use org.gradle.tooling.BuildException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResultHandlerAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void onFailure(Throwable failure) {
    if (failure instanceof InternalUnsupportedBuildArgumentException) {
        handler.onFailure(new UnsupportedBuildArgumentException(connectionFailureMessage(failure)
                + "\n" + failure.getMessage(), failure));
    } else if (failure instanceof UnsupportedOperationConfigurationException) {
        handler.onFailure(new UnsupportedOperationConfigurationException(connectionFailureMessage(failure)
                + "\n" + failure.getMessage(), failure.getCause()));
    } else if (failure instanceof GradleConnectionException) {
        handler.onFailure((GradleConnectionException) failure);
    } else if (failure instanceof InternalBuildCancelledException) {
        handler.onFailure(new BuildCancelledException(connectionFailureMessage(failure), failure.getCause()));
    } else if (failure instanceof BuildExceptionVersion1) {
        handler.onFailure(new BuildException(connectionFailureMessage(failure), failure.getCause()));
    } else {
        handler.onFailure(new GradleConnectionException(connectionFailureMessage(failure), failure));
    }
}
 
Example #2
Source File: GradleBuildFileFromConnector.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public List<Dependency> getDependencies() throws IOException {
    if (dependencies == null) {
        EclipseProject eclipseProject = null;
        if (getBuildContent() != null) {
            try {
                ProjectConnection connection = GradleConnector.newConnector()
                        .forProjectDirectory(getProjectDirPath().toFile())
                        .connect();
                eclipseProject = connection.getModel(EclipseProject.class);
            } catch (BuildException e) {
                // ignore this error.
                e.printStackTrace();
            }
        }
        if (eclipseProject != null) {
            dependencies = eclipseProject.getClasspath().stream().map(this::gradleModuleVersionToDependency)
                    .filter(Objects::nonNull)
                    .collect(Collectors.toList());
        } else {
            dependencies = Collections.emptyList();
        }
        dependencies = Collections.unmodifiableList(dependencies);
    }
    return dependencies;
}
 
Example #3
Source File: AndroidComponentModelPlugin.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private static void checkGradleVersion(Project project) {
    String gradleVersion = project.getGradle().getGradleVersion();
    if (!gradleVersion.startsWith(GRADLE_ACCEPTABLE_VERSION)) {
        boolean allowNonMatching = Boolean.getBoolean(GRADLE_VERSION_CHECK_OVERRIDE_PROPERTY);
        File file = new File("gradle" + File.separator + "wrapper" + File.separator +
                "gradle-wrapper.properties");
        String errorMessage = String.format(
                "Gradle version %s is required. Current version is %s. " +
                        "If using the gradle wrapper, try editing the distributionUrl in %s " +
                        "to gradle-%s-all.zip",
                GRADLE_ACCEPTABLE_VERSION, gradleVersion, file.getAbsolutePath(),
                GRADLE_ACCEPTABLE_VERSION);
        if (allowNonMatching) {
            project.getLogger().warn(errorMessage);
            project.getLogger().warn("As %s is set, continuing anyways.",
                    GRADLE_VERSION_CHECK_OVERRIDE_PROPERTY);
        } else {
            throw new BuildException(errorMessage, null);
        }
    }
}
 
Example #4
Source File: ResultHandlerAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void onFailure(Throwable failure) {
    if (failure instanceof InternalUnsupportedBuildArgumentException) {
        handler.onFailure(new UnsupportedBuildArgumentException(connectionFailureMessage(failure)
                + "\n" + failure.getMessage(), failure));
    } else if (failure instanceof UnsupportedOperationConfigurationException) {
        handler.onFailure(new UnsupportedOperationConfigurationException(connectionFailureMessage(failure)
                + "\n" + failure.getMessage(), failure.getCause()));
    } else if (failure instanceof GradleConnectionException) {
        handler.onFailure((GradleConnectionException) failure);
    } else if (failure instanceof InternalBuildCancelledException) {
        handler.onFailure(new BuildCancelledException(connectionFailureMessage(failure), failure.getCause()));
    } else if (failure instanceof BuildExceptionVersion1) {
        handler.onFailure(new BuildException(connectionFailureMessage(failure), failure.getCause()));
    } else {
        handler.onFailure(new GradleConnectionException(connectionFailureMessage(failure), failure));
    }
}
 
Example #5
Source File: ResultHandlerAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onFailure(Throwable failure) {
    if (failure instanceof InternalUnsupportedBuildArgumentException) {
        handler.onFailure(new UnsupportedBuildArgumentException(connectionFailureMessage(failure)
                + "\n" + failure.getMessage(), failure));
    } else if (failure instanceof UnsupportedOperationConfigurationException) {
        handler.onFailure(new UnsupportedOperationConfigurationException(connectionFailureMessage(failure)
                + "\n" + failure.getMessage(), failure.getCause()));
    } else if (failure instanceof GradleConnectionException) {
        handler.onFailure((GradleConnectionException) failure);
    } else if (failure instanceof BuildExceptionVersion1) {
        handler.onFailure(new BuildException(connectionFailureMessage(failure), failure.getCause()));
    } else {
        handler.onFailure(new GradleConnectionException(connectionFailureMessage(failure), failure));
    }
}
 
Example #6
Source File: SigningConfig.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a SigningConfig with a given name.
 *
 * @param name the name of the signingConfig.
 */
public SigningConfig(@NonNull String name) {
    super(name);

    if (BuilderConstants.DEBUG.equals(name)) {
        try {
            initDebug();
        } catch (AndroidLocation.AndroidLocationException e) {
            throw new BuildException("Failed to get default debug keystore location", e);
        }
    }
}
 
Example #7
Source File: ValidateSigningTask.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@TaskAction
public void validate() throws AndroidLocation.AndroidLocationException, KeytoolException {
    File storeFile = signingConfig.getStoreFile();
    if (storeFile == null) {
        throw new IllegalArgumentException(
                "Keystore file not set for signing config " + signingConfig.getName());
    }
    if (!storeFile.exists()) {
        if (KeystoreHelper.defaultDebugKeystoreLocation().equals(storeFile.getAbsolutePath())) {
            checkState(signingConfig.isSigningReady(), "Debug signing config not ready.");

            getLogger().info(
                    "Creating default debug keystore at {}",
                    storeFile.getAbsolutePath());

            //noinspection ConstantConditions - isSigningReady() called above
            if (!KeystoreHelper.createDebugStore(
                    signingConfig.getStoreType(), signingConfig.getStoreFile(),
                    signingConfig.getStorePassword(), signingConfig.getKeyPassword(),
                    signingConfig.getKeyAlias(), getILogger())) {
                throw new BuildException("Unable to recreate missing debug keystore.", null);
            }
        } else {
            throw new IllegalArgumentException(
                    String.format(
                            "Keystore file %s not found for signing config '%s'.",
                            storeFile.getAbsolutePath(),
                            signingConfig.getName()));
        }
    }
}
 
Example #8
Source File: ResultHandlerAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onFailure(Throwable failure) {
    if (failure instanceof InternalUnsupportedBuildArgumentException) {
        handler.onFailure(new UnsupportedBuildArgumentException(connectionFailureMessage(failure)
                + "\n" + failure.getMessage(), failure));
    } else if (failure instanceof UnsupportedOperationConfigurationException) {
        handler.onFailure(new UnsupportedOperationConfigurationException(connectionFailureMessage(failure)
                + "\n" + failure.getMessage(), failure.getCause()));
    } else if (failure instanceof GradleConnectionException) {
        handler.onFailure((GradleConnectionException) failure);
    } else if (failure instanceof BuildExceptionVersion1) {
        handler.onFailure(new BuildException(connectionFailureMessage(failure), failure.getCause()));
    } else {
        handler.onFailure(new GradleConnectionException(connectionFailureMessage(failure), failure));
    }
}
 
Example #9
Source File: ExtractAnnotations.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
@TaskAction
protected void compile() {
    if (!hasAndroidAnnotations()) {
        return;

    }


    if (encoding == null) {
        encoding = "UTF_8";
    }


    Pair<Collection<CompilationUnitDeclaration>, INameEnvironment> result = parseSources();
    Collection<CompilationUnitDeclaration> parsedUnits = result.getFirst();
    INameEnvironment environment = result.getSecond();

    try {
        if (!allowErrors) {
            for (CompilationUnitDeclaration unit : parsedUnits) {
                // so maybe I don't need my map!!
                CategorizedProblem[] problems = unit.compilationResult().getAllProblems();
                for (IProblem problem : problems) {
                    if (problem.isError()) {
                        System.out.println("Not extracting annotations (compilation problems encountered)");
                        System.out.println("Error: " + problem.getOriginatingFileName() + ":" + problem.getSourceLineNumber() + ": " + problem.getMessage());
                        // TODO: Consider whether we abort the build at this point!
                        return;

                    }

                }

            }

        }


        // API definition file
        ApiDatabase database = null;
        if (apiFilter != null && apiFilter.exists()) {
            try {
                database = new ApiDatabase(apiFilter);
            } catch (IOException e) {
                throw new BuildException("Could not open API database " + apiFilter, e);
            }

        }


        boolean displayInfo = getProject().getLogger().isEnabled(LogLevel.INFO);
        Boolean includeClassRetentionAnnotations = false;
        Boolean sortAnnotations = false;

        Extractor extractor = new Extractor(database, classDir, displayInfo, includeClassRetentionAnnotations, sortAnnotations);
        extractor.extractFromProjectSource(parsedUnits);
        if (mergeJars != null) {
            for (File jar : mergeJars) {
                extractor.mergeExisting(jar);
            }

        }

        extractor.export(output, proguard);
        extractor.removeTypedefClasses();
    } finally {
        if (environment != null) {
            environment.cleanup();
        }

    }

}