Search in sources :

Example 1 with GradleVersion

use of org.gradle.util.GradleVersion in project intellij-community by JetBrains.

the class GradleExecutionHelper method getGradleVersion.

@Nullable
public static GradleVersion getGradleVersion(@NotNull ProjectConnection connection) {
    final BuildEnvironment buildEnvironment = getBuildEnvironment(connection);
    GradleVersion gradleVersion = null;
    if (buildEnvironment != null) {
        gradleVersion = GradleVersion.version(buildEnvironment.getGradle().getGradleVersion());
    }
    return gradleVersion;
}
Also used : BuildEnvironment(org.gradle.tooling.model.build.BuildEnvironment) GradleVersion(org.gradle.util.GradleVersion) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GradleVersion

use of org.gradle.util.GradleVersion in project gradle by gradle.

the class GradleBuildComparison method createProjectConnection.

private ProjectConnection createProjectConnection(ComparableGradleBuildExecuter executer) {
    DefaultGradleConnector connector = (DefaultGradleConnector) GradleConnector.newConnector();
    connector.forProjectDirectory(executer.getSpec().getProjectDir());
    connector.searchUpwards(false);
    File gradleUserHomeDir = gradle.getStartParameter().getGradleUserHomeDir();
    if (gradleUserHomeDir != null) {
        connector.useGradleUserHomeDir(gradleUserHomeDir);
    }
    GradleVersion gradleVersion = executer.getGradleVersion();
    if (gradleVersion.equals(GradleVersion.current())) {
        connector.useInstallation(gradle.getGradleHomeDir());
    } else {
        connector.useGradleVersion(gradleVersion.getVersion());
    }
    return connector.connect();
}
Also used : DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) GradleVersion(org.gradle.util.GradleVersion) File(java.io.File)

Example 3 with GradleVersion

use of org.gradle.util.GradleVersion in project meghanada-server by mopemope.

the class GradleProject method parseProject.

@Override
public Project parseProject() throws ProjectParseException {
    final ProjectConnection connection = getProjectConnection();
    log.info("loading gradle project:{}", new File(this.projectRoot, Project.GRADLE_PROJECT_FILE));
    try {
        BuildEnvironment env = connection.getModel(BuildEnvironment.class);
        String version = env.getGradle().getGradleVersion();
        if (isNull(version)) {
            version = GradleVersion.current().getVersion();
        }
        if (nonNull(version)) {
            this.gradleVersion = new ComparableVersion(version);
        }
        final IdeaProject ideaProject = debugTimeItF("get idea project model elapsed={}", () -> connection.getModel(IdeaProject.class));
        this.setCompileTarget(ideaProject);
        log.trace("load root project path:{}", this.rootProject);
        final DomainObjectSet<? extends IdeaModule> modules = ideaProject.getModules();
        final List<? extends IdeaModule> mainModules = modules.parallelStream().filter(ideaModule -> {
            final org.gradle.tooling.model.GradleProject gradleProject = ideaModule.getGradleProject();
            final File moduleProjectRoot = gradleProject.getProjectDirectory();
            final String name = ideaModule.getName();
            log.trace("find sub-module name {} path {} ", name, moduleProjectRoot);
            this.allModules.putIfAbsent(name, moduleProjectRoot);
            return moduleProjectRoot.equals(this.getProjectRoot());
        }).collect(Collectors.toList());
        mainModules.forEach(wrapIOConsumer(this::parseIdeaModule));
        // set default output
        if (isNull(super.output)) {
            String build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "main");
            if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
                build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "java", "main");
            }
            super.output = this.normalize(build);
        }
        if (isNull(super.testOutput)) {
            String build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "test");
            if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
                build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "java", "test");
            }
            super.testOutput = this.normalize(build);
        }
        return this;
    } catch (Exception e) {
        throw new ProjectParseException(e);
    } finally {
        connection.close();
    }
}
Also used : Config.debugTimeItF(meghanada.config.Config.debugTimeItF) IdeaDependency(org.gradle.tooling.model.idea.IdeaDependency) ProjectParseException(meghanada.project.ProjectParseException) IdeaJavaLanguageSettings(org.gradle.tooling.model.idea.IdeaJavaLanguageSettings) FunctionUtils.wrapIOConsumer(meghanada.utils.FunctionUtils.wrapIOConsumer) StringUtils(org.apache.commons.lang3.StringUtils) PipedInputStream(java.io.PipedInputStream) Map(java.util.Map) GradleConnector(org.gradle.tooling.GradleConnector) Objects.isNull(java.util.Objects.isNull) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) Splitter(com.google.common.base.Splitter) GradleVersion(org.gradle.util.GradleVersion) BuildEnvironment(org.gradle.tooling.model.build.BuildEnvironment) BuildLauncher(org.gradle.tooling.BuildLauncher) CompileResult(meghanada.analyze.CompileResult) AndroidProject(com.android.builder.model.AndroidProject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) ResultHandler(org.gradle.tooling.ResultHandler) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ClassNameUtils(meghanada.utils.ClassNameUtils) IdeaContentRoot(org.gradle.tooling.model.idea.IdeaContentRoot) IdeaSingleEntryLibraryDependency(org.gradle.tooling.model.idea.IdeaSingleEntryLibraryDependency) DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) Project(meghanada.project.Project) Objects.nonNull(java.util.Objects.nonNull) ProjectDependency(meghanada.project.ProjectDependency) Config(meghanada.config.Config) Joiner(com.google.common.base.Joiner) HashMap(java.util.HashMap) GradleConnectionException(org.gradle.tooling.GradleConnectionException) IdeaSourceDirectory(org.gradle.tooling.model.idea.IdeaSourceDirectory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) Files(com.google.common.io.Files) ConfigFactory(com.typesafe.config.ConfigFactory) UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) IdeaModuleDependency(org.gradle.tooling.model.idea.IdeaModuleDependency) DomainObjectSet(org.gradle.tooling.model.DomainObjectSet) IOException(java.io.IOException) PipedOutputStream(java.io.PipedOutputStream) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) IdeaProject(org.gradle.tooling.model.idea.IdeaProject) GradleModuleVersion(org.gradle.tooling.model.GradleModuleVersion) ProjectConnection(org.gradle.tooling.ProjectConnection) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) IdeaProject(org.gradle.tooling.model.idea.IdeaProject) ProjectConnection(org.gradle.tooling.ProjectConnection) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) ProjectParseException(meghanada.project.ProjectParseException) GradleConnectionException(org.gradle.tooling.GradleConnectionException) UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) IOException(java.io.IOException) ProjectParseException(meghanada.project.ProjectParseException) BuildEnvironment(org.gradle.tooling.model.build.BuildEnvironment) File(java.io.File)

Example 4 with GradleVersion

use of org.gradle.util.GradleVersion in project spring-boot by spring-projects.

the class GradleCompatibilityExtension method provideTestTemplateInvocationContexts.

@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
    Stream<String> gradleVersions = GRADLE_VERSIONS.stream();
    GradleCompatibility gradleCompatibility = AnnotationUtils.findAnnotation(context.getRequiredTestClass(), GradleCompatibility.class).get();
    if (StringUtils.hasText(gradleCompatibility.versionsLessThan())) {
        GradleVersion upperExclusive = GradleVersion.version(gradleCompatibility.versionsLessThan());
        gradleVersions = gradleVersions.filter((version) -> GradleVersion.version(version).compareTo(upperExclusive) < 0);
    }
    return gradleVersions.flatMap((version) -> {
        List<TestTemplateInvocationContext> invocationContexts = new ArrayList<>();
        invocationContexts.add(new GradleVersionTestTemplateInvocationContext(version, false));
        boolean configurationCache = gradleCompatibility.configurationCache();
        if (configurationCache) {
            invocationContexts.add(new GradleVersionTestTemplateInvocationContext(version, true));
        }
        return invocationContexts.stream();
    });
}
Also used : GradleBuild(org.springframework.boot.testsupport.gradle.testkit.GradleBuild) Arrays(java.util.Arrays) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) ArrayList(java.util.ArrayList) Extension(org.junit.jupiter.api.extension.Extension) List(java.util.List) TestTemplate(org.junit.jupiter.api.TestTemplate) Stream(java.util.stream.Stream) GradleVersions(org.springframework.boot.testsupport.gradle.testkit.GradleVersions) TestTemplateInvocationContext(org.junit.jupiter.api.extension.TestTemplateInvocationContext) GradleBuildExtension(org.springframework.boot.testsupport.gradle.testkit.GradleBuildExtension) TestTemplateInvocationContextProvider(org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider) AnnotationUtils(org.junit.platform.commons.util.AnnotationUtils) GradleVersion(org.gradle.util.GradleVersion) StringUtils(org.springframework.util.StringUtils) ArrayList(java.util.ArrayList) TestTemplateInvocationContext(org.junit.jupiter.api.extension.TestTemplateInvocationContext) GradleVersion(org.gradle.util.GradleVersion)

Example 5 with GradleVersion

use of org.gradle.util.GradleVersion in project gradle by gradle.

the class GradleReleaseNotesPlugin method generateReleaseNotes.

private void generateReleaseNotes(Project project, ProjectLayout layout, TaskContainer tasks, GradleDocumentationExtension extension) {
    TaskProvider<RenderMarkdown> releaseNotesMarkdown = tasks.register("releaseNotesMarkdown", RenderMarkdown.class, task -> {
        task.setGroup("release notes");
        task.setDescription("Generate release notes HTML page from Markdown.");
        task.getInputEncoding().convention(Charset.defaultCharset().name());
        task.getOutputEncoding().convention(Charset.defaultCharset().name());
        task.getMarkdownFile().convention(extension.getReleaseNotes().getMarkdownFile());
        task.getDestinationFile().convention(extension.getStagingRoot().file("release-notes/raw.html"));
    });
    TaskProvider<DecorateReleaseNotes> releaseNotesPostProcess = tasks.register("releaseNotes", DecorateReleaseNotes.class, task -> {
        task.setGroup("release notes");
        task.setDescription("Transforms generated release notes.");
        task.getHtmlFile().convention(releaseNotesMarkdown.flatMap(RenderMarkdown::getDestinationFile));
        task.getBaseCssFile().convention(extension.getReleaseNotes().getBaseCssFile());
        task.getReleaseNotesCssFile().convention(extension.getReleaseNotes().getReleaseNotesCssFile());
        task.getReleaseNotesJavascriptFile().convention(extension.getReleaseNotes().getReleaseNotesJsFile());
        task.getJquery().from(extension.getReleaseNotes().getJquery());
        ModuleIdentityExtension moduleIdentity = project.getExtensions().getByType(ModuleIdentityExtension.class);
        MapProperty<String, String> replacementTokens = task.getReplacementTokens();
        replacementTokens.put("version", moduleIdentity.getVersion().map(GradleVersion::getVersion));
        replacementTokens.put("baseVersion", moduleIdentity.getVersion().map(v -> v.getBaseVersion().getVersion()));
        task.getDestinationFile().convention(extension.getStagingRoot().file("release-notes/release-notes.html"));
    });
    Configuration jquery = project.getConfigurations().create("jquery", conf -> {
        conf.setDescription("JQuery dependencies embedded by release notes.");
    });
    extension.releaseNotes(releaseNotes -> {
        releaseNotes.getMarkdownFile().convention(extension.getSourceRoot().file("release/notes.md"));
        releaseNotes.getRenderedDocumentation().convention(releaseNotesPostProcess.flatMap(DecorateReleaseNotes::getDestinationFile));
        releaseNotes.getBaseCssFile().convention(extension.getSourceRoot().file("css/base.css"));
        releaseNotes.getReleaseNotesCssFile().convention(extension.getSourceRoot().file("css/release-notes.css"));
        releaseNotes.getReleaseNotesJsFile().convention(extension.getSourceRoot().file("release/content/script.js"));
        releaseNotes.getJquery().from(jquery);
    });
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) ProjectLayout(org.gradle.api.file.ProjectLayout) TaskContainer(org.gradle.api.tasks.TaskContainer) Charset(java.nio.charset.Charset) Project(org.gradle.api.Project) MapProperty(org.gradle.api.provider.MapProperty) TaskProvider(org.gradle.api.tasks.TaskProvider) ModuleIdentityExtension(gradlebuild.identity.extension.ModuleIdentityExtension) Plugin(org.gradle.api.Plugin) GradleVersion(org.gradle.util.GradleVersion) Configuration(org.gradle.api.artifacts.Configuration) ModuleIdentityExtension(gradlebuild.identity.extension.ModuleIdentityExtension)

Aggregations

GradleVersion (org.gradle.util.GradleVersion)19 File (java.io.File)10 ArrayList (java.util.ArrayList)6 DefaultGradleConnector (org.gradle.tooling.internal.consumer.DefaultGradleConnector)4 IOException (java.io.IOException)3 List (java.util.List)3 Map (java.util.Map)3 ZipFile (java.util.zip.ZipFile)3 GradleConnector (org.gradle.tooling.GradleConnector)3 ProjectConnection (org.gradle.tooling.ProjectConnection)3 InputStream (java.io.InputStream)2 BuildEnvironment (org.gradle.tooling.model.build.BuildEnvironment)2 DefaultGradleVersion (org.gradle.util.internal.DefaultGradleVersion)2 NotNull (org.jetbrains.annotations.NotNull)2 UnsupportedCancellationToken (org.jetbrains.plugins.gradle.service.execution.UnsupportedCancellationToken)2 GradleBuildParticipant (org.jetbrains.plugins.gradle.settings.GradleBuildParticipant)2 GradleExecutionSettings (org.jetbrains.plugins.gradle.settings.GradleExecutionSettings)2 AndroidProject (com.android.builder.model.AndroidProject)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Joiner (com.google.common.base.Joiner)1