Java Code Examples for org.gradle.StartParameter#setGradleUserHomeDir()

The following examples show how to use org.gradle.StartParameter#setGradleUserHomeDir() . 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: ProjectBuilderImpl.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Project createProject(String name, File inputProjectDir) {
    File projectDir = prepareProjectDir(inputProjectDir);

    final File homeDir = new File(projectDir, "gradleHome");

    StartParameter startParameter = new StartParameter();
    startParameter.setGradleUserHomeDir(new File(projectDir, "userHome"));

    ServiceRegistry topLevelRegistry = new TestBuildScopeServices(GLOBAL_SERVICES, startParameter, homeDir);
    GradleInternal gradle = new DefaultGradle(null, startParameter, topLevelRegistry.get(ServiceRegistryFactory.class));

    DefaultProjectDescriptor projectDescriptor = new DefaultProjectDescriptor(null, name, projectDir, new DefaultProjectDescriptorRegistry(),
            topLevelRegistry.get(FileResolver.class));
    ClassLoaderScope baseScope = gradle.getClassLoaderScope();
    ClassLoaderScope rootProjectScope = baseScope.createChild();
    ProjectInternal project = topLevelRegistry.get(IProjectFactory.class).createProject(projectDescriptor, null, gradle, rootProjectScope, baseScope);

    gradle.setRootProject(project);
    gradle.setDefaultProject(project);

    return project;
}
 
Example 2
Source File: ProjectBuilderImpl.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Project createProject(String name, File inputProjectDir) {
    File projectDir = prepareProjectDir(inputProjectDir);

    final File homeDir = new File(projectDir, "gradleHome");

    StartParameter startParameter = new StartParameter();
    startParameter.setGradleUserHomeDir(new File(projectDir, "userHome"));

    ServiceRegistry topLevelRegistry = new TestBuildScopeServices(GLOBAL_SERVICES, startParameter, homeDir);
    GradleInternal gradle = new DefaultGradle(null, startParameter, topLevelRegistry.get(ServiceRegistryFactory.class));

    DefaultProjectDescriptor projectDescriptor = new DefaultProjectDescriptor(null, name, projectDir, new DefaultProjectDescriptorRegistry(),
            topLevelRegistry.get(FileResolver.class));
    ProjectInternal project = topLevelRegistry.get(IProjectFactory.class).createProject(projectDescriptor, null, gradle, gradle.getClassLoaderScope().createSibling());

    gradle.setRootProject(project);
    gradle.setDefaultProject(project);

    return project;
}
 
Example 3
Source File: ProjectBuilderImpl.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Project createProject(String name, File inputProjectDir) {
    File projectDir = prepareProjectDir(inputProjectDir);

    final File homeDir = new File(projectDir, "gradleHome");

    StartParameter startParameter = new StartParameter();
    startParameter.setGradleUserHomeDir(new File(projectDir, "userHome"));

    ServiceRegistry topLevelRegistry = new TestBuildScopeServices(GLOBAL_SERVICES, startParameter, homeDir);
    GradleInternal gradle = new DefaultGradle(null, startParameter, topLevelRegistry.get(ServiceRegistryFactory.class));

    DefaultProjectDescriptor projectDescriptor = new DefaultProjectDescriptor(null, name, projectDir, new DefaultProjectDescriptorRegistry(),
            topLevelRegistry.get(FileResolver.class));
    ClassLoaderScope baseScope = gradle.getClassLoaderScope();
    ClassLoaderScope rootProjectScope = baseScope.createChild();
    ProjectInternal project = topLevelRegistry.get(IProjectFactory.class).createProject(projectDescriptor, null, gradle, rootProjectScope, baseScope);

    gradle.setRootProject(project);
    gradle.setDefaultProject(project);

    return project;
}
 
Example 4
Source File: ProjectBuilderImpl.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Project createProject(String name, File inputProjectDir) {
    File projectDir = prepareProjectDir(inputProjectDir);

    final File homeDir = new File(projectDir, "gradleHome");

    StartParameter startParameter = new StartParameter();
    startParameter.setGradleUserHomeDir(new File(projectDir, "userHome"));

    ServiceRegistry topLevelRegistry = new TestBuildScopeServices(GLOBAL_SERVICES, startParameter, homeDir);
    GradleInternal gradle = new DefaultGradle(null, startParameter, topLevelRegistry.get(ServiceRegistryFactory.class));

    DefaultProjectDescriptor projectDescriptor = new DefaultProjectDescriptor(null, name, projectDir, new DefaultProjectDescriptorRegistry(),
            topLevelRegistry.get(FileResolver.class));
    ProjectInternal project = topLevelRegistry.get(IProjectFactory.class).createProject(projectDescriptor, null, gradle, gradle.getClassLoaderScope().createSibling());

    gradle.setRootProject(project);
    gradle.setDefaultProject(project);

    return project;
}
 
Example 5
Source File: ConfiguringBuildAction.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private StartParameter configureStartParameter(ProviderOperationParameters parameters, Map<String, String> properties) {
    // Important that this is constructed on the client so that it has the right gradleHomeDir and other state internally
    StartParameter startParameter = new StartParameter();

    startParameter.setProjectDir(parameters.getProjectDir());
    if (parameters.getGradleUserHomeDir() != null) {
        startParameter.setGradleUserHomeDir(parameters.getGradleUserHomeDir());
    }

    List<InternalLaunchable> launchables = parameters.getLaunchables(null);
    if (launchables != null) {
        startParameter.setTaskRequests(unpack(launchables));
    } else if (parameters.getTasks() != null) {
        startParameter.setTaskNames(parameters.getTasks());
    }

    new PropertiesToStartParameterConverter().convert(properties, startParameter);

    List<String> arguments = parameters.getArguments(Collections.<String>emptyList());
    if (arguments != null) {
        DefaultCommandLineConverter converter = new DefaultCommandLineConverter();
        try {
            converter.convert(arguments, startParameter);
        } catch (CommandLineArgumentException e) {
            throw new InternalUnsupportedBuildArgumentException(
                "Problem with provided build arguments: " + arguments + ". "
                + "\n" + e.getMessage()
                + "\nEither it is not a valid build option or it is not supported in the target Gradle version."
                + "\nNot all of the Gradle command line options are supported build arguments."
                + "\nExamples of supported build arguments: '--info', '-u', '-p'."
                + "\nExamples of unsupported build options: '--daemon', '-?', '-v'."
                + "\nPlease find more information in the javadoc for the BuildLauncher class.", e);
        }
    }

    if (parameters.isSearchUpwards() != null) {
        startParameter.setSearchUpwards(parameters.isSearchUpwards());
    }

    if (parameters.getBuildLogLevel() != null) {
        startParameter.setLogLevel(parameters.getBuildLogLevel());
    }

    return startParameter;
}
 
Example 6
Source File: DefaultCommandLineConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public StartParameter convert(final ParsedCommandLine options, final StartParameter startParameter) throws CommandLineArgumentException {
    loggingConfigurationCommandLineConverter.convert(options, startParameter);
    Transformer<File, String> resolver = new BasicFileResolver(startParameter.getCurrentDir());

    Map<String, String> systemProperties = systemPropertiesCommandLineConverter.convert(options, new HashMap<String, String>());
    convertCommandLineSystemProperties(systemProperties, startParameter, resolver);

    Map<String, String> projectProperties = projectPropertiesCommandLineConverter.convert(options, new HashMap<String, String>());
    startParameter.getProjectProperties().putAll(projectProperties);

    BuildLayoutParameters layout = new BuildLayoutParameters()
            .setGradleUserHomeDir(startParameter.getGradleUserHomeDir())
            .setProjectDir(startParameter.getProjectDir())
            .setCurrentDir(startParameter.getCurrentDir());
    layoutCommandLineConverter.convert(options, layout);
    startParameter.setGradleUserHomeDir(layout.getGradleUserHomeDir());
    if (layout.getProjectDir() != null) {
        startParameter.setProjectDir(layout.getProjectDir());
    }
    startParameter.setSearchUpwards(layout.getSearchUpwards());

    if (options.hasOption(BUILD_FILE)) {
        startParameter.setBuildFile(resolver.transform(options.option(BUILD_FILE).getValue()));
    }
    if (options.hasOption(SETTINGS_FILE)) {
        startParameter.setSettingsFile(resolver.transform(options.option(SETTINGS_FILE).getValue()));
    }

    for (String script : options.option(INIT_SCRIPT).getValues()) {
        startParameter.addInitScript(resolver.transform(script));
    }

    if (options.hasOption(PROJECT_CACHE_DIR)) {
        startParameter.setProjectCacheDir(resolver.transform(options.option(PROJECT_CACHE_DIR).getValue()));
    }

    if (options.hasOption(NO_PROJECT_DEPENDENCY_REBUILD)) {
        startParameter.setBuildProjectDependencies(false);
    }

    if (!options.getExtraArguments().isEmpty()) {
        startParameter.setTaskNames(options.getExtraArguments());
    }

    if (options.hasOption(DRY_RUN)) {
        startParameter.setDryRun(true);
    }

    if (options.hasOption(RERUN_TASKS)) {
        startParameter.setRerunTasks(true);
    }

    if (options.hasOption(RECOMPILE_SCRIPTS)) {
        startParameter.setRecompileScripts(true);
    }

    if (options.hasOption(EXCLUDE_TASK)) {
        startParameter.setExcludedTaskNames(options.option(EXCLUDE_TASK).getValues());
    }

    if (options.hasOption(PROFILE)) {
        startParameter.setProfile(true);
    }

    if (options.hasOption(CONTINUE)) {
        startParameter.setContinueOnFailure(true);
    }

    if (options.hasOption(OFFLINE)) {
        startParameter.setOffline(true);
    }

    if (options.hasOption(REFRESH_DEPENDENCIES)) {
        startParameter.setRefreshDependencies(true);
    }

    if (options.hasOption(PARALLEL)) {
        startParameter.setParallelThreadCount(-1);
    }

    if (options.hasOption(PARALLEL_THREADS)) {
        try {
            int parallelThreads = Integer.parseInt(options.option(PARALLEL_THREADS).getValue());
            startParameter.setParallelThreadCount(parallelThreads);
        } catch (NumberFormatException e) {
            throw new CommandLineArgumentException(String.format("Not a numeric argument for %s", PARALLEL_THREADS));
        }
    }

    if (options.hasOption(CONFIGURE_ON_DEMAND)) {
        startParameter.setConfigureOnDemand(true);
    }

    return startParameter;
}
 
Example 7
Source File: DefaultCommandLineConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
void convertCommandLineSystemProperties(Map<String, String> systemProperties, StartParameter startParameter, Transformer<File, String> resolver) {
    startParameter.getSystemPropertiesArgs().putAll(systemProperties);
    if (systemProperties.containsKey(GRADLE_USER_HOME_PROPERTY_KEY)) {
        startParameter.setGradleUserHomeDir(resolver.transform(systemProperties.get(GRADLE_USER_HOME_PROPERTY_KEY)));
    }
}
 
Example 8
Source File: ConfiguringBuildAction.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
StartParameter configureStartParameter(PropertiesToStartParameterConverter propertiesToStartParameterConverter) {
    StartParameter startParameter = startParameterTemplate.newInstance();

    startParameter.setProjectDir(projectDirectory);
    if (gradleUserHomeDir != null) {
        startParameter.setGradleUserHomeDir(gradleUserHomeDir);
    }

    if (launchables != null) {
        List<String> allTasks = new ArrayList<String>();
        String projectPath = null;
        for (InternalLaunchable launchable : launchables) {
            if (launchable instanceof LaunchableImplementation) {
                LaunchableImplementation launchableImpl = (LaunchableImplementation) launchable;
                allTasks.add(launchableImpl.getTaskName());
                if (launchableImpl.getProjectPath() != null) {
                    if (projectPath != null && !projectPath.equals(launchableImpl.getProjectPath())) {
                        throw new InternalUnsupportedBuildArgumentException(
                                "Problem with provided launchable arguments: " + launchables + ". "
                                        + "\nOnly selector from the same Gradle project can be built."
                        );
                    }
                    projectPath = launchableImpl.getProjectPath();
                }
            } else {
                throw new InternalUnsupportedBuildArgumentException(
                        "Problem with provided launchable arguments: " + launchables + ". "
                                + "\nOnly objects from this provider can be built."
                );
            }
        }
        if (projectPath != null) {
            startParameter.setProjectPath(projectPath);
        }
        startParameter.setTaskNames(allTasks);
    } else if (tasks != null) {
        startParameter.setTaskNames(tasks);
    }

    propertiesToStartParameterConverter.convert(properties, startParameter);

    if (arguments != null) {
        DefaultCommandLineConverter converter = new DefaultCommandLineConverter();
        try {
            converter.convert(arguments, startParameter);
        } catch (CommandLineArgumentException e) {
            throw new InternalUnsupportedBuildArgumentException(
                "Problem with provided build arguments: " + arguments + ". "
                + "\n" + e.getMessage()
                + "\nEither it is not a valid build option or it is not supported in the target Gradle version."
                + "\nNot all of the Gradle command line options are supported build arguments."
                + "\nExamples of supported build arguments: '--info', '-u', '-p'."
                + "\nExamples of unsupported build options: '--daemon', '-?', '-v'."
                + "\nPlease find more information in the javadoc for the BuildLauncher class.", e);
        }
    }

    if (searchUpwards != null) {
        startParameter.setSearchUpwards(searchUpwards);
    }

    if (buildLogLevel != null) {
        startParameter.setLogLevel(buildLogLevel);
    }

    return startParameter;
}
 
Example 9
Source File: DefaultCommandLineConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
void convertCommandLineSystemProperties(Map<String, String> systemProperties, StartParameter startParameter, FileResolver resolver) {
    startParameter.getSystemPropertiesArgs().putAll(systemProperties);
    if (systemProperties.containsKey(GRADLE_USER_HOME_PROPERTY_KEY)) {
        startParameter.setGradleUserHomeDir(resolver.resolve(systemProperties.get(GRADLE_USER_HOME_PROPERTY_KEY)));
    }
}
 
Example 10
Source File: ConfiguringBuildAction.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private StartParameter configureStartParameter(ProviderOperationParameters parameters, Map<String, String> properties) {
    // Important that this is constructed on the client so that it has the right gradleHomeDir and other state internally
    StartParameter startParameter = new StartParameter();

    startParameter.setProjectDir(parameters.getProjectDir());
    if (parameters.getGradleUserHomeDir() != null) {
        startParameter.setGradleUserHomeDir(parameters.getGradleUserHomeDir());
    }

    List<InternalLaunchable> launchables = parameters.getLaunchables(null);
    if (launchables != null) {
        startParameter.setTaskRequests(unpack(launchables));
    } else if (parameters.getTasks() != null) {
        startParameter.setTaskNames(parameters.getTasks());
    }

    new PropertiesToStartParameterConverter().convert(properties, startParameter);

    List<String> arguments = parameters.getArguments(Collections.<String>emptyList());
    if (arguments != null) {
        DefaultCommandLineConverter converter = new DefaultCommandLineConverter();
        try {
            converter.convert(arguments, startParameter);
        } catch (CommandLineArgumentException e) {
            throw new InternalUnsupportedBuildArgumentException(
                "Problem with provided build arguments: " + arguments + ". "
                + "\n" + e.getMessage()
                + "\nEither it is not a valid build option or it is not supported in the target Gradle version."
                + "\nNot all of the Gradle command line options are supported build arguments."
                + "\nExamples of supported build arguments: '--info', '-u', '-p'."
                + "\nExamples of unsupported build options: '--daemon', '-?', '-v'."
                + "\nPlease find more information in the javadoc for the BuildLauncher class.", e);
        }
    }

    if (parameters.isSearchUpwards() != null) {
        startParameter.setSearchUpwards(parameters.isSearchUpwards());
    }

    if (parameters.getBuildLogLevel() != null) {
        startParameter.setLogLevel(parameters.getBuildLogLevel());
    }

    return startParameter;
}
 
Example 11
Source File: DefaultCommandLineConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public StartParameter convert(final ParsedCommandLine options, final StartParameter startParameter) throws CommandLineArgumentException {
    loggingConfigurationCommandLineConverter.convert(options, startParameter);
    Transformer<File, String> resolver = new BasicFileResolver(startParameter.getCurrentDir());

    Map<String, String> systemProperties = systemPropertiesCommandLineConverter.convert(options, new HashMap<String, String>());
    convertCommandLineSystemProperties(systemProperties, startParameter, resolver);

    Map<String, String> projectProperties = projectPropertiesCommandLineConverter.convert(options, new HashMap<String, String>());
    startParameter.getProjectProperties().putAll(projectProperties);

    BuildLayoutParameters layout = new BuildLayoutParameters()
            .setGradleUserHomeDir(startParameter.getGradleUserHomeDir())
            .setProjectDir(startParameter.getProjectDir())
            .setCurrentDir(startParameter.getCurrentDir());
    layoutCommandLineConverter.convert(options, layout);
    startParameter.setGradleUserHomeDir(layout.getGradleUserHomeDir());
    if (layout.getProjectDir() != null) {
        startParameter.setProjectDir(layout.getProjectDir());
    }
    startParameter.setSearchUpwards(layout.getSearchUpwards());

    if (options.hasOption(BUILD_FILE)) {
        startParameter.setBuildFile(resolver.transform(options.option(BUILD_FILE).getValue()));
    }
    if (options.hasOption(SETTINGS_FILE)) {
        startParameter.setSettingsFile(resolver.transform(options.option(SETTINGS_FILE).getValue()));
    }

    for (String script : options.option(INIT_SCRIPT).getValues()) {
        startParameter.addInitScript(resolver.transform(script));
    }

    if (options.hasOption(PROJECT_CACHE_DIR)) {
        startParameter.setProjectCacheDir(resolver.transform(options.option(PROJECT_CACHE_DIR).getValue()));
    }

    if (options.hasOption(NO_PROJECT_DEPENDENCY_REBUILD)) {
        startParameter.setBuildProjectDependencies(false);
    }

    if (!options.getExtraArguments().isEmpty()) {
        startParameter.setTaskNames(options.getExtraArguments());
    }

    if (options.hasOption(DRY_RUN)) {
        startParameter.setDryRun(true);
    }

    if (options.hasOption(RERUN_TASKS)) {
        startParameter.setRerunTasks(true);
    }

    if (options.hasOption(RECOMPILE_SCRIPTS)) {
        startParameter.setRecompileScripts(true);
    }

    if (options.hasOption(EXCLUDE_TASK)) {
        startParameter.setExcludedTaskNames(options.option(EXCLUDE_TASK).getValues());
    }

    if (options.hasOption(PROFILE)) {
        startParameter.setProfile(true);
    }

    if (options.hasOption(CONTINUE)) {
        startParameter.setContinueOnFailure(true);
    }

    if (options.hasOption(OFFLINE)) {
        startParameter.setOffline(true);
    }

    if (options.hasOption(REFRESH_DEPENDENCIES)) {
        startParameter.setRefreshDependencies(true);
    }

    if (options.hasOption(PARALLEL)) {
        startParameter.setParallelThreadCount(-1);
    }

    if (options.hasOption(PARALLEL_THREADS)) {
        try {
            int parallelThreads = Integer.parseInt(options.option(PARALLEL_THREADS).getValue());
            startParameter.setParallelThreadCount(parallelThreads);
        } catch (NumberFormatException e) {
            throw new CommandLineArgumentException(String.format("Not a numeric argument for %s", PARALLEL_THREADS));
        }
    }

    if (options.hasOption(CONFIGURE_ON_DEMAND)) {
        startParameter.setConfigureOnDemand(true);
    }

    return startParameter;
}
 
Example 12
Source File: DefaultCommandLineConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
void convertCommandLineSystemProperties(Map<String, String> systemProperties, StartParameter startParameter, Transformer<File, String> resolver) {
    startParameter.getSystemPropertiesArgs().putAll(systemProperties);
    if (systemProperties.containsKey(GRADLE_USER_HOME_PROPERTY_KEY)) {
        startParameter.setGradleUserHomeDir(resolver.transform(systemProperties.get(GRADLE_USER_HOME_PROPERTY_KEY)));
    }
}
 
Example 13
Source File: ConfiguringBuildAction.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
StartParameter configureStartParameter(PropertiesToStartParameterConverter propertiesToStartParameterConverter) {
    StartParameter startParameter = startParameterTemplate.newInstance();

    startParameter.setProjectDir(projectDirectory);
    if (gradleUserHomeDir != null) {
        startParameter.setGradleUserHomeDir(gradleUserHomeDir);
    }

    if (launchables != null) {
        List<String> allTasks = new ArrayList<String>();
        String projectPath = null;
        for (InternalLaunchable launchable : launchables) {
            if (launchable instanceof LaunchableImplementation) {
                LaunchableImplementation launchableImpl = (LaunchableImplementation) launchable;
                allTasks.add(launchableImpl.getTaskName());
                if (launchableImpl.getProjectPath() != null) {
                    if (projectPath != null && !projectPath.equals(launchableImpl.getProjectPath())) {
                        throw new InternalUnsupportedBuildArgumentException(
                                "Problem with provided launchable arguments: " + launchables + ". "
                                        + "\nOnly selector from the same Gradle project can be built."
                        );
                    }
                    projectPath = launchableImpl.getProjectPath();
                }
            } else {
                throw new InternalUnsupportedBuildArgumentException(
                        "Problem with provided launchable arguments: " + launchables + ". "
                                + "\nOnly objects from this provider can be built."
                );
            }
        }
        if (projectPath != null) {
            startParameter.setProjectPath(projectPath);
        }
        startParameter.setTaskNames(allTasks);
    } else if (tasks != null) {
        startParameter.setTaskNames(tasks);
    }

    propertiesToStartParameterConverter.convert(properties, startParameter);

    if (arguments != null) {
        DefaultCommandLineConverter converter = new DefaultCommandLineConverter();
        try {
            converter.convert(arguments, startParameter);
        } catch (CommandLineArgumentException e) {
            throw new InternalUnsupportedBuildArgumentException(
                "Problem with provided build arguments: " + arguments + ". "
                + "\n" + e.getMessage()
                + "\nEither it is not a valid build option or it is not supported in the target Gradle version."
                + "\nNot all of the Gradle command line options are supported build arguments."
                + "\nExamples of supported build arguments: '--info', '-u', '-p'."
                + "\nExamples of unsupported build options: '--daemon', '-?', '-v'."
                + "\nPlease find more information in the javadoc for the BuildLauncher class.", e);
        }
    }

    if (searchUpwards != null) {
        startParameter.setSearchUpwards(searchUpwards);
    }

    if (buildLogLevel != null) {
        startParameter.setLogLevel(buildLogLevel);
    }

    return startParameter;
}
 
Example 14
Source File: DefaultCommandLineConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
void convertCommandLineSystemProperties(Map<String, String> systemProperties, StartParameter startParameter, FileResolver resolver) {
    startParameter.getSystemPropertiesArgs().putAll(systemProperties);
    if (systemProperties.containsKey(GRADLE_USER_HOME_PROPERTY_KEY)) {
        startParameter.setGradleUserHomeDir(resolver.resolve(systemProperties.get(GRADLE_USER_HOME_PROPERTY_KEY)));
    }
}