Search in sources :

Example 6 with StartParameter

use of org.gradle.StartParameter in project gradle by gradle.

the class SetupLoggingActionExecuter method execute.

@Override
public Object execute(BuildAction action, BuildRequestContext requestContext, BuildActionParameters actionParameters, ServiceRegistry contextServices) {
    StartParameter startParameter = action.getStartParameter();
    loggingManager.setLevelInternal(startParameter.getLogLevel());
    loggingManager.start();
    try {
        return delegate.execute(action, requestContext, actionParameters, contextServices);
    } finally {
        loggingManager.stop();
    }
}
Also used : StartParameter(org.gradle.StartParameter)

Example 7 with StartParameter

use of org.gradle.StartParameter in project build-info by JFrogDev.

the class GradleArtifactoryClientConfigUpdater method update.

/**
 * Returns a configuration handler object out of a Gradle project. This method will aggregate the properties in our
 * defined hierarchy. First search for the property as a system property, if found return it.
 * Second search for the property in the Gradle {@link org.gradle.StartParameter#getProjectProperties} container
 * and if found there, then return it. Third search for the property in {@link
 * org.gradle.api.Project#property(String)}
 * if not found, search upwards in the project hierarchy until
 * reach the root project. if not found at all in this hierarchy return null
 *
 * @param project the gradle project with properties for build info client configuration (Usually in start parameter
 *                from CI Server)
 */
public static void update(ArtifactoryClientConfiguration config, Project project) {
    Properties props = new Properties();
    // First aggregate properties from parent to child
    fillProperties(project, props);
    // Then start parameters
    StartParameter startParameter = project.getGradle().getStartParameter();
    Map<String, String> startProps = startParameter.getProjectProperties();
    props.putAll(BuildInfoExtractorUtils.filterStringEntries(startProps));
    // Then System properties
    Properties mergedProps = BuildInfoExtractorUtils.mergePropertiesWithSystemAndPropertyFile(props, config.info.getLog());
    // Then special buildInfo properties
    Properties buildInfoProperties = BuildInfoExtractorUtils.filterDynamicProperties(mergedProps, BUILD_INFO_PROP_PREDICATE);
    buildInfoProperties = BuildInfoExtractorUtils.stripPrefixFromProperties(buildInfoProperties, BUILD_INFO_PROP_PREFIX);
    mergedProps.putAll(buildInfoProperties);
    // Add the collected properties to the Artifactory client configuration.
    // In case the build name and build number have already been added to the configuration
    // from inside the gradle script, we do not want to override them by the values sent from
    // the CI server plugin.
    String prefix = BuildInfoProperties.BUILD_INFO_PREFIX;
    Set<String> excludeIfExist = Sets.newHashSet(prefix + BuildInfoFields.BUILD_NUMBER, prefix + BuildInfoFields.BUILD_NAME, prefix + BuildInfoFields.BUILD_STARTED);
    config.fillFromProperties(mergedProps, excludeIfExist);
    // After props are set, apply missing project props (not set by CI-plugin generated props)
    setMissingBuildAttributes(config, project);
}
Also used : StartParameter(org.gradle.StartParameter) Properties(java.util.Properties) BuildInfoProperties(org.jfrog.build.api.BuildInfoProperties)

Example 8 with StartParameter

use of org.gradle.StartParameter in project gradle by gradle.

the class DefaultTasksBuildExecutionAction method configure.

@Override
public void configure(BuildExecutionContext context) {
    StartParameter startParameter = context.getGradle().getStartParameter();
    for (TaskExecutionRequest request : startParameter.getTaskRequests()) {
        if (!request.getArgs().isEmpty()) {
            context.proceed();
            return;
        }
    }
    // Gather the default tasks from this first group project
    ProjectInternal project = context.getGradle().getDefaultProject();
    // so that we don't miss out default tasks
    projectConfigurer.configure(project);
    List<String> defaultTasks = project.getDefaultTasks();
    if (defaultTasks.size() == 0) {
        defaultTasks = new ArrayList<>();
        for (BuiltInCommand command : builtInCommands) {
            defaultTasks.addAll(command.asDefaultTask());
        }
        LOGGER.info("No tasks specified. Using default task {}", GUtil.toString(defaultTasks));
    } else {
        LOGGER.info("No tasks specified. Using project default tasks {}", GUtil.toString(defaultTasks));
    }
    startParameter.setTaskNames(defaultTasks);
    context.proceed();
}
Also used : StartParameter(org.gradle.StartParameter) TaskExecutionRequest(org.gradle.TaskExecutionRequest) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) BuiltInCommand(org.gradle.configuration.project.BuiltInCommand)

Example 9 with StartParameter

use of org.gradle.StartParameter in project gradle by gradle.

the class RunBuildDependenciesTaskBuilder method buildAll.

@Override
public RunClosedProjectBuildDependencies buildAll(String modelName, EclipseRuntime eclipseRuntime, Project project) {
    this.projectOpenStatus = eclipseRuntime.getWorkspace().getProjects().stream().collect(Collectors.toMap(EclipseWorkspaceProject::getName, EclipseModelBuilder::isProjectOpen, (a, b) -> a | b));
    List<TaskDependency> buildDependencies = populate(project.getRootProject());
    if (!buildDependencies.isEmpty()) {
        Gradle rootGradle = getRootGradle(project.getGradle());
        Project rootProject = rootGradle.getRootProject();
        StartParameter startParameter = rootGradle.getStartParameter();
        List<String> taskPaths = new ArrayList<>(startParameter.getTaskNames());
        String parentTaskName = parentTaskName(rootProject, "eclipseClosedDependencies");
        Task task = rootProject.task(parentTaskName);
        task.dependsOn(buildDependencies.toArray(new Object[0]));
        taskPaths.add(parentTaskName);
        startParameter.setTaskNames(taskPaths);
    }
    return DefaultRunClosedProjectBuildDependencies.INSTANCE;
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) Project(org.gradle.api.Project) EclipseWorkspaceProject(org.gradle.tooling.model.eclipse.EclipseWorkspaceProject) StartParameter(org.gradle.StartParameter) Task(org.gradle.api.Task) EclipseWorkspaceProject(org.gradle.tooling.model.eclipse.EclipseWorkspaceProject) ArrayList(java.util.ArrayList) Gradle(org.gradle.api.invocation.Gradle)

Example 10 with StartParameter

use of org.gradle.StartParameter in project gradle by gradle.

the class RunEclipseTasksBuilder method buildAll.

@Override
public Object buildAll(String modelName, Project project) {
    StartParameter startParameter = project.getGradle().getStartParameter();
    List<String> taskPaths = new ArrayList<String>();
    taskPaths.addAll(startParameter.getTaskNames());
    boolean isSyncModel = isSyncModel(modelName);
    boolean isAutoBuildModel = isAutoBuildModel(modelName);
    for (Project p : project.getAllprojects()) {
        EclipseModel model = p.getExtensions().findByType(EclipseModel.class);
        if (model != null) {
            if (isSyncModel) {
                for (Task t : model.getSynchronizationTasks().getDependencies(null)) {
                    taskPaths.add(t.getPath());
                }
            }
            if (isAutoBuildModel) {
                for (Task t : model.getAutoBuildTasks().getDependencies(null)) {
                    taskPaths.add(t.getPath());
                }
            }
        }
    }
    if (taskPaths.isEmpty()) {
        // If no tasks is specified then the default tasks will be executed.
        // To work around this, we assign a new empty task for execution.
        String placeHolderTaskName = placeHolderTaskName(project, "nothing");
        project.task(placeHolderTaskName);
        taskPaths.add(placeHolderTaskName);
    }
    project.getGradle().getStartParameter().setTaskNames(taskPaths);
    return null;
}
Also used : StartParameter(org.gradle.StartParameter) Project(org.gradle.api.Project) Task(org.gradle.api.Task) ArrayList(java.util.ArrayList) EclipseModel(org.gradle.plugins.ide.eclipse.model.EclipseModel)

Aggregations

StartParameter (org.gradle.StartParameter)25 GradleInternal (org.gradle.api.internal.GradleInternal)4 File (java.io.File)3 ClassPath (org.gradle.internal.classpath.ClassPath)3 ListenerManager (org.gradle.internal.event.ListenerManager)3 Path (org.gradle.util.Path)3 ArrayList (java.util.ArrayList)2 Project (org.gradle.api.Project)2 Task (org.gradle.api.Task)2 TaskExecutionStatisticsEventAdapter (org.gradle.api.internal.tasks.execution.statistics.TaskExecutionStatisticsEventAdapter)2 Gradle (org.gradle.api.invocation.Gradle)2 ShowStacktrace (org.gradle.api.logging.configuration.ShowStacktrace)2 GradleLauncher (org.gradle.initialization.GradleLauncher)2 BuildLogger (org.gradle.internal.buildevents.BuildLogger)2 TaskExecutionStatisticsReporter (org.gradle.internal.buildevents.TaskExecutionStatisticsReporter)2 ScriptUsageLocationReporter (org.gradle.internal.featurelifecycle.ScriptUsageLocationReporter)2 Properties (java.util.Properties)1 TaskExecutionRequest (org.gradle.TaskExecutionRequest)1 Settings (org.gradle.api.initialization.Settings)1 BuildDefinition (org.gradle.api.internal.BuildDefinition)1