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

The following examples show how to use org.gradle.StartParameter#setCurrentDir() . 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: SettingsHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Finds the settings.gradle for the given startParameter, and loads it if contains the project selected by the
 * startParameter, or if the startParameter explicitly specifies a settings script.  If the settings file is not
 * loaded (executed), then a null is returned.
 */
private SettingsInternal findSettingsAndLoadIfAppropriate(GradleInternal gradle,
                                                          StartParameter startParameter) {
    SettingsLocation settingsLocation = findSettings(startParameter);

    // We found the desired settings file, now build the associated buildSrc before loading settings.  This allows
    // the settings script to reference classes in the buildSrc.
    StartParameter buildSrcStartParameter = startParameter.newBuild();
    buildSrcStartParameter.setCurrentDir(new File(settingsLocation.getSettingsDir(), BaseSettings.DEFAULT_BUILD_SRC_DIR));
    ClassLoaderScope buildSourceClassLoader = buildSourceBuilder.buildAndCreateClassLoader(buildSrcStartParameter);

    return settingsProcessor.process(gradle, settingsLocation, buildSourceClassLoader, startParameter);
}
 
Example 2
Source File: EmbeddedDaemonGradleExecuter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ExecuteBuildAction createBuildAction() {
    DefaultCommandLineConverter commandLineConverter = new DefaultCommandLineConverter();
    StartParameter startParameter = new StartParameter();
    startParameter.setCurrentDir(getWorkingDir());
    commandLineConverter.convert(getAllArgs(), startParameter);
    return new ExecuteBuildAction(startParameter);
}
 
Example 3
Source File: SettingsHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Finds the settings.gradle for the given startParameter, and loads it if contains the project selected by the
 * startParameter, or if the startParameter explicitly specifies a settings script.  If the settings file is not
 * loaded (executed), then a null is returned.
 */
private SettingsInternal findSettingsAndLoadIfAppropriate(GradleInternal gradle,
                                                          StartParameter startParameter) {
    SettingsLocation settingsLocation = findSettings(startParameter);

    // We found the desired settings file, now build the associated buildSrc before loading settings.  This allows
    // the settings script to reference classes in the buildSrc.
    StartParameter buildSrcStartParameter = startParameter.newBuild();
    buildSrcStartParameter.setCurrentDir(new File(settingsLocation.getSettingsDir(),
            BaseSettings.DEFAULT_BUILD_SRC_DIR));
    ClassLoaderScope buildSourceClassLoader = buildSourceBuilder.buildAndCreateClassLoader(buildSrcStartParameter);

    return loadSettings(gradle, settingsLocation, buildSourceClassLoader.createRebasedChild(), startParameter);
}
 
Example 4
Source File: SettingsHandler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Finds the settings.gradle for the given startParameter, and loads it if contains the project selected by the
 * startParameter, or if the startParameter explicitly specifies a settings script.  If the settings file is not
 * loaded (executed), then a null is returned.
 */
private SettingsInternal findSettingsAndLoadIfAppropriate(GradleInternal gradle,
                                                          StartParameter startParameter) {
    SettingsLocation settingsLocation = findSettings(startParameter);

    // We found the desired settings file, now build the associated buildSrc before loading settings.  This allows
    // the settings script to reference classes in the buildSrc.
    StartParameter buildSrcStartParameter = startParameter.newBuild();
    buildSrcStartParameter.setCurrentDir(new File(settingsLocation.getSettingsDir(), BaseSettings.DEFAULT_BUILD_SRC_DIR));
    ClassLoaderScope buildSourceClassLoader = buildSourceBuilder.buildAndCreateClassLoader(buildSrcStartParameter);

    return settingsProcessor.process(gradle, settingsLocation, buildSourceClassLoader, startParameter);
}
 
Example 5
Source File: EmbeddedDaemonGradleExecuter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ExecuteBuildAction createBuildAction() {
    DefaultCommandLineConverter commandLineConverter = new DefaultCommandLineConverter();
    StartParameter startParameter = new StartParameter();
    startParameter.setCurrentDir(getWorkingDir());
    commandLineConverter.convert(getAllArgs(), startParameter);
    return new ExecuteBuildAction(startParameter);
}
 
Example 6
Source File: SettingsHandler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Finds the settings.gradle for the given startParameter, and loads it if contains the project selected by the
 * startParameter, or if the startParameter explicitly specifies a settings script.  If the settings file is not
 * loaded (executed), then a null is returned.
 */
private SettingsInternal findSettingsAndLoadIfAppropriate(GradleInternal gradle,
                                                          StartParameter startParameter) {
    SettingsLocation settingsLocation = findSettings(startParameter);

    // We found the desired settings file, now build the associated buildSrc before loading settings.  This allows
    // the settings script to reference classes in the buildSrc.
    StartParameter buildSrcStartParameter = startParameter.newBuild();
    buildSrcStartParameter.setCurrentDir(new File(settingsLocation.getSettingsDir(),
            BaseSettings.DEFAULT_BUILD_SRC_DIR));
    ClassLoaderScope buildSourceClassLoader = buildSourceBuilder.buildAndCreateClassLoader(buildSrcStartParameter);

    return loadSettings(gradle, settingsLocation, buildSourceClassLoader.createRebasedChild(), startParameter);
}
 
Example 7
Source File: InProcessGradleExecuter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private BuildResult doRun(final OutputListenerImpl outputListener, OutputListenerImpl errorListener, BuildListenerImpl listener) {
    // Capture the current state of things that we will change during execution
    InputStream originalStdIn = System.in;
    Properties originalSysProperties = new Properties();
    originalSysProperties.putAll(System.getProperties());
    File originalUserDir = new File(originalSysProperties.getProperty("user.dir"));
    Map<String, String> originalEnv = new HashMap<String, String>(System.getenv());

    // Augment the environment for the execution
    System.setIn(getStdin());
    processEnvironment.maybeSetProcessDir(getWorkingDir());
    for (Map.Entry<String, String> entry : getEnvironmentVars().entrySet()) {
        processEnvironment.maybeSetEnvironmentVariable(entry.getKey(), entry.getValue());
    }
    Map<String, String> implicitJvmSystemProperties = getImplicitJvmSystemProperties();
    System.getProperties().putAll(implicitJvmSystemProperties);

    StartParameter parameter = new StartParameter();
    parameter.setCurrentDir(getWorkingDir());
    parameter.setShowStacktrace(ShowStacktrace.ALWAYS);

    CommandLineParser parser = new CommandLineParser();
    DefaultCommandLineConverter converter = new DefaultCommandLineConverter();
    converter.configure(parser);
    ParsedCommandLine parsedCommandLine = parser.parse(getAllArgs());

    BuildLayoutParameters layout = converter.getLayoutConverter().convert(parsedCommandLine, new BuildLayoutParameters());

    Map<String, String> properties = new HashMap<String, String>();
    new LayoutToPropertiesConverter().convert(layout, properties);
    converter.getSystemPropertiesConverter().convert(parsedCommandLine, properties);

    new PropertiesToStartParameterConverter().convert(properties, parameter);
    converter.convert(parsedCommandLine, parameter);

    DefaultGradleLauncherFactory factory = GLOBAL_SERVICES.get(DefaultGradleLauncherFactory.class);
    factory.addListener(listener);
    try {
        GradleLauncher gradleLauncher = factory.newInstance(parameter, new DefaultBuildCancellationToken());
        try {
            gradleLauncher.addStandardOutputListener(outputListener);
            gradleLauncher.addStandardErrorListener(errorListener);
            return gradleLauncher.run();
        } finally {
            gradleLauncher.stop();
        }
    } finally {
        // Restore the environment
        System.setProperties(originalSysProperties);
        processEnvironment.maybeSetProcessDir(originalUserDir);
        for (String envVar : getEnvironmentVars().keySet()) {
            String oldValue = originalEnv.get(envVar);
            if (oldValue != null) {
                processEnvironment.maybeSetEnvironmentVariable(envVar, oldValue);
            } else {
                processEnvironment.maybeRemoveEnvironmentVariable(envVar);
            }
        }
        factory.removeListener(listener);
        System.setIn(originalStdIn);
    }
}
 
Example 8
Source File: InProcessGradleExecuter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private BuildResult doRun(final OutputListenerImpl outputListener, OutputListenerImpl errorListener, BuildListenerImpl listener) {
    // Capture the current state of things that we will change during execution
    InputStream originalStdIn = System.in;
    Properties originalSysProperties = new Properties();
    originalSysProperties.putAll(System.getProperties());
    File originalUserDir = new File(originalSysProperties.getProperty("user.dir"));
    Map<String, String> originalEnv = new HashMap<String, String>(System.getenv());

    // Augment the environment for the execution
    System.setIn(getStdin());
    processEnvironment.maybeSetProcessDir(getWorkingDir());
    for (Map.Entry<String, String> entry : getEnvironmentVars().entrySet()) {
        processEnvironment.maybeSetEnvironmentVariable(entry.getKey(), entry.getValue());
    }
    Map<String, String> implicitJvmSystemProperties = getImplicitJvmSystemProperties();
    System.getProperties().putAll(implicitJvmSystemProperties);

    StartParameter parameter = new StartParameter();
    parameter.setCurrentDir(getWorkingDir());
    parameter.setShowStacktrace(ShowStacktrace.ALWAYS);

    CommandLineParser parser = new CommandLineParser();
    DefaultCommandLineConverter converter = new DefaultCommandLineConverter();
    converter.configure(parser);
    ParsedCommandLine parsedCommandLine = parser.parse(getAllArgs());

    BuildLayoutParameters layout = converter.getLayoutConverter().convert(parsedCommandLine);

    Map<String, String> properties = new HashMap<String, String>();
    new LayoutToPropertiesConverter().convert(layout, properties);
    converter.getSystemPropertiesConverter().convert(parsedCommandLine, properties);

    new PropertiesToStartParameterConverter().convert(properties, parameter);
    converter.convert(parsedCommandLine, parameter);

    DefaultGradleLauncherFactory factory = DeprecationLogger.whileDisabled(new Factory<DefaultGradleLauncherFactory>() {
        public DefaultGradleLauncherFactory create() {
            return (DefaultGradleLauncherFactory) GradleLauncher.getFactory();
        }
    });
    factory.addListener(listener);
    GradleLauncher gradleLauncher = factory.newInstance(parameter);
    gradleLauncher.addStandardOutputListener(outputListener);
    gradleLauncher.addStandardErrorListener(errorListener);
    try {
        return gradleLauncher.run();
    } finally {
        // Restore the environment
        System.setProperties(originalSysProperties);
        processEnvironment.maybeSetProcessDir(originalUserDir);
        for (String envVar: getEnvironmentVars().keySet()) {
            String oldValue = originalEnv.get(envVar);
            if (oldValue != null) {
                processEnvironment.maybeSetEnvironmentVariable(envVar, oldValue);
            } else {
                processEnvironment.maybeRemoveEnvironmentVariable(envVar);
            }
        }
        factory.removeListener(listener);
        System.setIn(originalStdIn);
    }
}
 
Example 9
Source File: InProcessGradleExecuter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private BuildResult doRun(final OutputListenerImpl outputListener, OutputListenerImpl errorListener, BuildListenerImpl listener) {
    // Capture the current state of things that we will change during execution
    InputStream originalStdIn = System.in;
    Properties originalSysProperties = new Properties();
    originalSysProperties.putAll(System.getProperties());
    File originalUserDir = new File(originalSysProperties.getProperty("user.dir"));
    Map<String, String> originalEnv = new HashMap<String, String>(System.getenv());

    // Augment the environment for the execution
    System.setIn(getStdin());
    processEnvironment.maybeSetProcessDir(getWorkingDir());
    for (Map.Entry<String, String> entry : getEnvironmentVars().entrySet()) {
        processEnvironment.maybeSetEnvironmentVariable(entry.getKey(), entry.getValue());
    }
    Map<String, String> implicitJvmSystemProperties = getImplicitJvmSystemProperties();
    System.getProperties().putAll(implicitJvmSystemProperties);

    StartParameter parameter = new StartParameter();
    parameter.setCurrentDir(getWorkingDir());
    parameter.setShowStacktrace(ShowStacktrace.ALWAYS);

    CommandLineParser parser = new CommandLineParser();
    DefaultCommandLineConverter converter = new DefaultCommandLineConverter();
    converter.configure(parser);
    ParsedCommandLine parsedCommandLine = parser.parse(getAllArgs());

    BuildLayoutParameters layout = converter.getLayoutConverter().convert(parsedCommandLine, new BuildLayoutParameters());

    Map<String, String> properties = new HashMap<String, String>();
    new LayoutToPropertiesConverter().convert(layout, properties);
    converter.getSystemPropertiesConverter().convert(parsedCommandLine, properties);

    new PropertiesToStartParameterConverter().convert(properties, parameter);
    converter.convert(parsedCommandLine, parameter);

    DefaultGradleLauncherFactory factory = GLOBAL_SERVICES.get(DefaultGradleLauncherFactory.class);
    factory.addListener(listener);
    try {
        GradleLauncher gradleLauncher = factory.newInstance(parameter, new DefaultBuildCancellationToken());
        try {
            gradleLauncher.addStandardOutputListener(outputListener);
            gradleLauncher.addStandardErrorListener(errorListener);
            return gradleLauncher.run();
        } finally {
            gradleLauncher.stop();
        }
    } finally {
        // Restore the environment
        System.setProperties(originalSysProperties);
        processEnvironment.maybeSetProcessDir(originalUserDir);
        for (String envVar : getEnvironmentVars().keySet()) {
            String oldValue = originalEnv.get(envVar);
            if (oldValue != null) {
                processEnvironment.maybeSetEnvironmentVariable(envVar, oldValue);
            } else {
                processEnvironment.maybeRemoveEnvironmentVariable(envVar);
            }
        }
        factory.removeListener(listener);
        System.setIn(originalStdIn);
    }
}
 
Example 10
Source File: InProcessGradleExecuter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private BuildResult doRun(final OutputListenerImpl outputListener, OutputListenerImpl errorListener, BuildListenerImpl listener) {
    // Capture the current state of things that we will change during execution
    InputStream originalStdIn = System.in;
    Properties originalSysProperties = new Properties();
    originalSysProperties.putAll(System.getProperties());
    File originalUserDir = new File(originalSysProperties.getProperty("user.dir"));
    Map<String, String> originalEnv = new HashMap<String, String>(System.getenv());

    // Augment the environment for the execution
    System.setIn(getStdin());
    processEnvironment.maybeSetProcessDir(getWorkingDir());
    for (Map.Entry<String, String> entry : getEnvironmentVars().entrySet()) {
        processEnvironment.maybeSetEnvironmentVariable(entry.getKey(), entry.getValue());
    }
    Map<String, String> implicitJvmSystemProperties = getImplicitJvmSystemProperties();
    System.getProperties().putAll(implicitJvmSystemProperties);

    StartParameter parameter = new StartParameter();
    parameter.setCurrentDir(getWorkingDir());
    parameter.setShowStacktrace(ShowStacktrace.ALWAYS);

    CommandLineParser parser = new CommandLineParser();
    DefaultCommandLineConverter converter = new DefaultCommandLineConverter();
    converter.configure(parser);
    ParsedCommandLine parsedCommandLine = parser.parse(getAllArgs());

    BuildLayoutParameters layout = converter.getLayoutConverter().convert(parsedCommandLine);

    Map<String, String> properties = new HashMap<String, String>();
    new LayoutToPropertiesConverter().convert(layout, properties);
    converter.getSystemPropertiesConverter().convert(parsedCommandLine, properties);

    new PropertiesToStartParameterConverter().convert(properties, parameter);
    converter.convert(parsedCommandLine, parameter);

    DefaultGradleLauncherFactory factory = DeprecationLogger.whileDisabled(new Factory<DefaultGradleLauncherFactory>() {
        public DefaultGradleLauncherFactory create() {
            return (DefaultGradleLauncherFactory) GradleLauncher.getFactory();
        }
    });
    factory.addListener(listener);
    GradleLauncher gradleLauncher = factory.newInstance(parameter);
    gradleLauncher.addStandardOutputListener(outputListener);
    gradleLauncher.addStandardErrorListener(errorListener);
    try {
        return gradleLauncher.run();
    } finally {
        // Restore the environment
        System.setProperties(originalSysProperties);
        processEnvironment.maybeSetProcessDir(originalUserDir);
        for (String envVar: getEnvironmentVars().keySet()) {
            String oldValue = originalEnv.get(envVar);
            if (oldValue != null) {
                processEnvironment.maybeSetEnvironmentVariable(envVar, oldValue);
            } else {
                processEnvironment.maybeRemoveEnvironmentVariable(envVar);
            }
        }
        factory.removeListener(listener);
        System.setIn(originalStdIn);
    }
}