Search in sources :

Example 1 with Logger

use of org.gradle.api.logging.Logger in project gradle-eta by typelead.

the class DefaultEtaConfiguration method doResolve.

public void doResolve(final Project project, final DependencyHandler handler, final ImmutableDAG<String, PackageInfo> dependencyGraph, Set<String> resolvedDependencies) {
    final Logger logger = project.getLogger();
    final String configurationName = parentConfiguration.getName();
    Set<String> resolvedDeps = new HashSet<String>();
    for (Configuration configuration : parentConfiguration.getExtendsFrom()) {
        DefaultEtaConfiguration etaConfiguration = ExtensionHelper.getExtension(configuration, DefaultEtaConfiguration.class);
        etaConfiguration.doResolve(project, handler, dependencyGraph, resolvedDeps);
    }
    List<String> keys = new ArrayList<String>();
    for (EtaDependency dep : dependencies) {
        if (dep instanceof HasPackageName) {
            keys.add(((HasPackageName) dep).getPackageName());
        }
    }
    if (!resolved.get() && resolved.compareAndSet(false, true)) {
        logger.info("Resolving Eta Configuration '" + configurationName + "'");
        List<PackageInfo> packageInfos = dependencyGraph.differenceClosure(keys, resolvedDeps);
        if (packageInfos.size() > 0) {
            mavenRepository.installPackages(packageInfos, dependencyGraph);
            resolvedMavenDependencies = packageInfos.stream().filter(packageInfo -> keys.contains(packageInfo.getName())).map(mavenRepository::getMavenDependency).collect(Collectors.toList());
            for (String mavenDep : resolvedMavenDependencies) {
                handler.add(configurationName, mavenDep);
                logger.info("Injecting maven dependency '" + mavenDep + "'");
            }
        } else {
            resolvedMavenDependencies = Collections.emptyList();
        }
    }
    resolvedDependencies.addAll(resolvedDeps);
    resolvedDependencies.addAll(keys);
}
Also used : DomainObjectCollection(org.gradle.api.DomainObjectCollection) DefaultDomainObjectCollection(org.gradle.api.internal.DefaultDomainObjectCollection) ExtensionHelper(com.typelead.gradle.utils.ExtensionHelper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) FileCollection(org.gradle.api.file.FileCollection) Logger(org.gradle.api.logging.Logger) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Configuration(org.gradle.api.artifacts.Configuration) Provider(org.gradle.api.provider.Provider) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) ConfigurationUtils(com.typelead.gradle.eta.internal.ConfigurationUtils) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) Map(java.util.Map) EtaBasePlugin(com.typelead.gradle.eta.plugins.EtaBasePlugin) LinkedHashSet(java.util.LinkedHashSet) ImmutableDAG(com.typelead.gradle.utils.ImmutableDAG) Project(org.gradle.api.Project) EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) HasPackageName(com.typelead.gradle.eta.api.HasPackageName) PackageInfo(com.typelead.gradle.utils.PackageInfo) GradleException(org.gradle.api.GradleException) EtlasMavenRepository(com.typelead.gradle.eta.internal.EtlasMavenRepository) Collections(java.util.Collections) Dependency(org.gradle.api.artifacts.Dependency) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) Configuration(org.gradle.api.artifacts.Configuration) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) PackageInfo(com.typelead.gradle.utils.PackageInfo) ArrayList(java.util.ArrayList) Logger(org.gradle.api.logging.Logger) HasPackageName(com.typelead.gradle.eta.api.HasPackageName) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with Logger

use of org.gradle.api.logging.Logger in project gradle by gradle.

the class JsHint method doJsHint.

@TaskAction
public void doJsHint() {
    RhinoWorkerHandleFactory handleFactory = new DefaultRhinoWorkerHandleFactory(getWorkerProcessBuilderFactory());
    LogLevel logLevel = getProject().getGradle().getStartParameter().getLogLevel();
    JsHintProtocol worker = handleFactory.create(getRhinoClasspath(), JsHintProtocol.class, JsHintWorker.class, logLevel, getProject().getProjectDir());
    JsHintSpec spec = new JsHintSpec();
    // flatten because we need to serialize
    spec.setSource(getSource().getFiles());
    spec.setEncoding(getEncoding());
    spec.setJsHint(getJsHint().getSingleFile());
    JsHintResult result = worker.process(spec);
    setDidWork(true);
    // TODO - this is all terribly lame. We need some proper reporting here (which means implementing Reporting).
    Logger logger = getLogger();
    boolean anyErrors = false;
    Map<String, Map<?, ?>> reportData = new LinkedHashMap<String, Map<?, ?>>(result.getResults().size());
    for (Map.Entry<File, Map<String, Object>> fileEntry : result.getResults().entrySet()) {
        File file = fileEntry.getKey();
        Map<String, Object> data = fileEntry.getValue();
        reportData.put(file.getAbsolutePath(), data);
        if (data.containsKey("errors")) {
            anyErrors = true;
            URI projectDirUri = getProject().getProjectDir().toURI();
            @SuppressWarnings("unchecked") Map<String, Object> errors = (Map<String, Object>) data.get("errors");
            if (!errors.isEmpty()) {
                URI relativePath = projectDirUri.relativize(file.toURI());
                logger.warn("JsHint errors for file: {}", relativePath.getPath());
                for (Map.Entry<String, Object> errorEntry : errors.entrySet()) {
                    @SuppressWarnings("unchecked") Map<String, Object> error = (Map<String, Object>) errorEntry.getValue();
                    int line = Float.valueOf(error.get("line").toString()).intValue();
                    int character = Float.valueOf(error.get("character").toString()).intValue();
                    String reason = error.get("reason").toString();
                    logger.warn("  {}:{} > {}", new Object[] { line, character, reason });
                }
            }
        }
    }
    File jsonReportFile = getJsonReport();
    if (jsonReportFile != null) {
        try {
            FileWriter reportWriter = new FileWriter(jsonReportFile);
            new GsonBuilder().setPrettyPrinting().create().toJson(reportData, reportWriter);
            reportWriter.close();
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
    if (anyErrors) {
        throw new TaskExecutionException(this, new GradleException("JsHint detected errors"));
    }
}
Also used : DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) RhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.RhinoWorkerHandleFactory) FileWriter(java.io.FileWriter) UncheckedIOException(org.gradle.api.UncheckedIOException) Logger(org.gradle.api.logging.Logger) URI(java.net.URI) LogLevel(org.gradle.api.logging.LogLevel) LinkedHashMap(java.util.LinkedHashMap) JsHintSpec(org.gradle.plugins.javascript.jshint.internal.JsHintSpec) JsHintResult(org.gradle.plugins.javascript.jshint.internal.JsHintResult) GsonBuilder(com.google.gson.GsonBuilder) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) GradleException(org.gradle.api.GradleException) JsHintProtocol(org.gradle.plugins.javascript.jshint.internal.JsHintProtocol) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with Logger

use of org.gradle.api.logging.Logger in project gradle by gradle.

the class CompareGradleBuilds method compare.

@SuppressWarnings("UnusedDeclaration")
@TaskAction
void compare() {
    GradleBuildInvocationSpec sourceBuild = getSourceBuild();
    GradleBuildInvocationSpec targetBuild = getTargetBuild();
    if (sourceBuild.equals(targetBuild)) {
        getLogger().warn("The source build and target build are identical. Set '{}.targetBuild.gradleVersion' if you want to compare with a different Gradle version.", getName());
    }
    ComparableGradleBuildExecuter sourceBuildExecuter = new ComparableGradleBuildExecuter(sourceBuild);
    ComparableGradleBuildExecuter targetBuildExecuter = new ComparableGradleBuildExecuter(targetBuild);
    Logger logger = getLogger();
    ProgressLogger progressLogger = getProgressLoggerFactory().newOperation(getClass());
    progressLogger.setDescription("Gradle Build Comparison");
    progressLogger.setShortDescription(getName());
    GradleBuildComparison comparison = new GradleBuildComparison(sourceBuildExecuter, targetBuildExecuter, logger, progressLogger, getProject().getGradle());
    comparison.registerType(GeneratedArchiveBuildOutcome.class, new GeneratedArchiveBuildOutcomeComparator(), new GeneratedArchiveBuildOutcomeComparisonResultHtmlRenderer(), new GeneratedArchiveBuildOutcomeHtmlRenderer());
    comparison.registerType(UnknownBuildOutcome.class, new UnknownBuildOutcomeComparator(), new UnknownBuildOutcomeComparisonResultHtmlRenderer(), new UnknownBuildOutcomeHtmlRenderer());
    File fileStoreTmpBase = getFileResolver().resolve(String.format(TMP_FILESTORAGE_PREFIX + "-%s-%s", getName(), System.currentTimeMillis()));
    MovableFileStore<String> fileStore = new Files(fileStoreTmpBase);
    Map<String, String> hostAttributes = new LinkedHashMap<String, String>(4);
    hostAttributes.put("Project", getProject().getRootDir().getAbsolutePath());
    hostAttributes.put("Task", getPath());
    hostAttributes.put("Gradle version", GradleVersion.current().getVersion());
    hostAttributes.put("Executed at", new SimpleDateFormat().format(new Date()));
    BuildComparisonResult result = comparison.compare(fileStore, getReportDir(), hostAttributes);
    communicateResult(result);
}
Also used : UnknownBuildOutcomeComparator(org.gradle.api.plugins.buildcomparison.outcome.internal.unknown.UnknownBuildOutcomeComparator) ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger) Logger(org.gradle.api.logging.Logger) ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger) GeneratedArchiveBuildOutcomeComparator(org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcomeComparator) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) BuildComparisonResult(org.gradle.api.plugins.buildcomparison.compare.internal.BuildComparisonResult) DefaultGradleBuildInvocationSpec(org.gradle.api.plugins.buildcomparison.gradle.internal.DefaultGradleBuildInvocationSpec) GeneratedArchiveBuildOutcomeComparisonResultHtmlRenderer(org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcomeComparisonResultHtmlRenderer) ComparableGradleBuildExecuter(org.gradle.api.plugins.buildcomparison.gradle.internal.ComparableGradleBuildExecuter) UnknownBuildOutcomeHtmlRenderer(org.gradle.api.plugins.buildcomparison.outcome.internal.unknown.UnknownBuildOutcomeHtmlRenderer) GeneratedArchiveBuildOutcomeHtmlRenderer(org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcomeHtmlRenderer) UnknownBuildOutcomeComparisonResultHtmlRenderer(org.gradle.api.plugins.buildcomparison.outcome.internal.unknown.UnknownBuildOutcomeComparisonResultHtmlRenderer) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) GradleBuildComparison(org.gradle.api.plugins.buildcomparison.gradle.internal.GradleBuildComparison) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

File (java.io.File)3 Logger (org.gradle.api.logging.Logger)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 GradleException (org.gradle.api.GradleException)2 TaskAction (org.gradle.api.tasks.TaskAction)2 GsonBuilder (com.google.gson.GsonBuilder)1 EtaConfiguration (com.typelead.gradle.eta.api.EtaConfiguration)1 EtaDependency (com.typelead.gradle.eta.api.EtaDependency)1 EtaProjectDependency (com.typelead.gradle.eta.api.EtaProjectDependency)1 HasPackageName (com.typelead.gradle.eta.api.HasPackageName)1 ConfigurationUtils (com.typelead.gradle.eta.internal.ConfigurationUtils)1 EtlasMavenRepository (com.typelead.gradle.eta.internal.EtlasMavenRepository)1 EtaBasePlugin (com.typelead.gradle.eta.plugins.EtaBasePlugin)1 ExtensionHelper (com.typelead.gradle.utils.ExtensionHelper)1 ImmutableDAG (com.typelead.gradle.utils.ImmutableDAG)1 PackageInfo (com.typelead.gradle.utils.PackageInfo)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 URI (java.net.URI)1