Search in sources :

Example 76 with GradleException

use of org.gradle.api.GradleException in project gradle by gradle.

the class DefaultHttpBuildCacheServiceFactory method createBuildCacheService.

@Override
public BuildCacheService createBuildCacheService(HttpBuildCache configuration) {
    URI url = configuration.getUrl();
    if (url == null) {
        throw new IllegalStateException("HTTP build cache has no URL configured");
    }
    Collection<Authentication> authentications = Collections.emptyList();
    if (configuration.getCredentials().getUsername() != null && configuration.getCredentials().getPassword() != null) {
        try {
            url = new URI(url.getScheme(), null, url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getFragment());
        } catch (URISyntaxException e) {
            throw new GradleException("Error constructing URL for http build cache", e);
        }
        DefaultBasicAuthentication basicAuthentication = new DefaultBasicAuthentication("basic");
        basicAuthentication.setCredentials(configuration.getCredentials());
        authentications = Collections.<Authentication>singleton(basicAuthentication);
    }
    HttpClientHelper httpClientHelper = new HttpClientHelper(new DefaultHttpSettings(authentications, sslContextFactory));
    return new HttpBuildCacheService(httpClientHelper, url);
}
Also used : HttpClientHelper(org.gradle.internal.resource.transport.http.HttpClientHelper) Authentication(org.gradle.authentication.Authentication) DefaultBasicAuthentication(org.gradle.internal.authentication.DefaultBasicAuthentication) GradleException(org.gradle.api.GradleException) DefaultBasicAuthentication(org.gradle.internal.authentication.DefaultBasicAuthentication) URISyntaxException(java.net.URISyntaxException) DefaultHttpSettings(org.gradle.internal.resource.transport.http.DefaultHttpSettings) URI(java.net.URI)

Example 77 with GradleException

use of org.gradle.api.GradleException in project gradle by gradle.

the class CompareGradleBuilds method communicateResult.

private void communicateResult(BuildComparisonResult result) {
    File reportFile = new File(getReportDir(), GradleBuildComparison.HTML_REPORT_FILE_NAME);
    String reportUrl = new ConsoleRenderer().asClickableFileUrl(reportFile);
    if (result.isBuildsAreIdentical()) {
        getLogger().info("The build outcomes were found to be identical. See the report at: {}", reportUrl);
    } else {
        String message = String.format("The build outcomes were not found to be identical. See the report at: %s", reportUrl);
        if (getIgnoreFailures()) {
            getLogger().warn(message);
        } else {
            throw new GradleException(message);
        }
    }
}
Also used : GradleException(org.gradle.api.GradleException) ConsoleRenderer(org.gradle.internal.logging.ConsoleRenderer) File(java.io.File)

Example 78 with GradleException

use of org.gradle.api.GradleException in project gradle by gradle.

the class FindBugs method evaluateResult.

@VisibleForTesting
void evaluateResult(FindBugsResult result) {
    if (result.getException() != null) {
        throw new GradleException("FindBugs encountered an error. Run with --debug to get more information.", result.getException());
    }
    if (result.getErrorCount() > 0) {
        throw new GradleException("FindBugs encountered an error. Run with --debug to get more information.");
    }
    if (result.getBugCount() > 0) {
        String message = "FindBugs rule violations were found.";
        SingleFileReport report = reports.getFirstEnabled();
        if (report != null) {
            String reportUrl = new ConsoleRenderer().asClickableFileUrl(report.getDestination());
            message += " See the report at: " + reportUrl;
        }
        if (getIgnoreFailures()) {
            getLogger().warn(message);
        } else {
            throw new GradleException(message);
        }
    }
}
Also used : GradleException(org.gradle.api.GradleException) ConsoleRenderer(org.gradle.internal.logging.ConsoleRenderer) SingleFileReport(org.gradle.api.reporting.SingleFileReport) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 79 with GradleException

use of org.gradle.api.GradleException in project atlas by alibaba.

the class AtlasLibTaskManager method runTask.

@Override
public void runTask() {
    //不做资源的合并
    if (!atlasExtension.getBundleConfig().isMergeRes()) {
        new ResMerger(project).mergeRes();
    }
    //对maven发布失败做异常翻译, 一目了然
    new PublishHooker(project).hookPublish();
    libraryExtension.getLibraryVariants().forEach(new Consumer<LibraryVariant>() {

        @Override
        public void accept(LibraryVariant libraryVariant) {
            //if ("debug".equals(libraryVariant.getBaseName())) {
            //    new ModuleInfoWriter(project,libraryVariant).write();
            //}
            LibVariantContext libVariantContext = new LibVariantContext((LibraryVariantImpl) libraryVariant, project, atlasExtension, libraryExtension);
            List<Zip> zipTasks = libVariantContext.getZipTasks();
            if (zipTasks.isEmpty()) {
                return;
            }
            for (Zip zipTask : zipTasks) {
                new AndroidComponetCreator(atlasExtension, project).createAndroidComponent(zipTask);
                //生成 awb 和 jar
                new AwbGenerator(atlasExtension).generate(zipTask);
            }
        }
    });
    libraryExtension.getLibraryVariants().forEach(new Consumer<LibraryVariant>() {

        @Override
        public void accept(LibraryVariant libraryVariant) {
            LibVariantContext libVariantContext = new LibVariantContext((LibraryVariantImpl) libraryVariant, project, atlasExtension, libraryExtension);
            List<Zip> zipTasks = libVariantContext.getZipTasks();
            if (zipTasks.isEmpty()) {
                return;
            }
            for (Zip zipTask : zipTasks) {
                TBuildType tBuildType = libVariantContext.getBuildType();
                if (null != tBuildType) {
                    try {
                        new AwoPropHandler().process(tBuildType, atlasExtension.getBundleConfig());
                    } catch (Exception e) {
                        throw new GradleException("process awo exception", e);
                    }
                }
                //TODO DEBUG it
                if (atlasExtension.getBundleConfig().isAwoBuildEnabled() && libraryVariant.getName().equals("debug")) {
                    libVariantContext.setBundleTask(zipTask);
                    try {
                        libVariantContext.setAwbBundle(createAwbBundle(libVariantContext, libraryVariant.getName()));
                    } catch (IOException e) {
                        throw new GradleException("set awb bundle error");
                    }
                    if (atlasExtension.getBundleConfig().isAwbBundle()) {
                        createAwoTask(libVariantContext, zipTask);
                    } else {
                        createDexTask(libVariantContext, zipTask);
                    }
                }
            }
        }
    });
}
Also used : Zip(org.gradle.api.tasks.bundling.Zip) ResMerger(com.taobao.android.builder.tasks.library.ResMerger) PublishHooker(com.taobao.android.builder.tasks.library.PublishHooker) LibVariantContext(com.android.build.gradle.internal.api.LibVariantContext) IOException(java.io.IOException) AndroidComponetCreator(com.taobao.android.builder.tasks.library.AndroidComponetCreator) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) AwoPropHandler(com.taobao.android.builder.tools.ideaplugin.AwoPropHandler) AwbGenerator(com.taobao.android.builder.tasks.library.AwbGenerator) LibraryVariant(com.android.build.gradle.api.LibraryVariant) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) List(java.util.List) LibraryVariantImpl(com.android.build.gradle.internal.api.LibraryVariantImpl) TBuildType(com.taobao.android.builder.extension.TBuildType)

Example 80 with GradleException

use of org.gradle.api.GradleException in project atlas by alibaba.

the class PrepareMainDexJarsTask method doFullTaskAction.

@TaskAction
public void doFullTaskAction() {
    AndroidDependencyTree libDependencyTree = AtlasBuildContext.libDependencyTrees.get(this.getVariantName());
    if (null == libDependencyTree) {
        throw new GradleException("The libDependencyTree is null!");
    }
    List<File> jarList = new AwoDependency(libVariantContext).getDependencyJar(libDependencyTree);
    libVariantContext.setJarDexList(jarList);
}
Also used : AwoDependency(com.taobao.android.builder.tasks.awo.utils.AwoDependency) GradleException(org.gradle.api.GradleException) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

GradleException (org.gradle.api.GradleException)114 File (java.io.File)40 IOException (java.io.IOException)32 TaskAction (org.gradle.api.tasks.TaskAction)16 ArrayList (java.util.ArrayList)10 UncheckedIOException (org.gradle.api.UncheckedIOException)10 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)9 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)8 HashSet (java.util.HashSet)8 FileOutputStream (java.io.FileOutputStream)6 Method (java.lang.reflect.Method)6 UncheckedException (org.gradle.internal.UncheckedException)6 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)5 URL (java.net.URL)5 List (java.util.List)5 ConsoleRenderer (org.gradle.internal.logging.ConsoleRenderer)5 ProcessOutputHandler (com.android.ide.common.process.ProcessOutputHandler)4 FileInputStream (java.io.FileInputStream)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 MalformedURLException (java.net.MalformedURLException)4