本文整理汇总了Java中org.gradle.tooling.GradleConnector.connect方法的典型用法代码示例。如果您正苦于以下问题:Java GradleConnector.connect方法的具体用法?Java GradleConnector.connect怎么用?Java GradleConnector.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.gradle.tooling.GradleConnector
的用法示例。
在下文中一共展示了GradleConnector.connect方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetch
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
private static void fetch(File buildDir, File gradleInstallDir, boolean embedded) {
System.out.println("* Fetching model for " + buildDir);
System.out.println("* Using tooling API " + GradleVersion.current().getVersion());
Timer timer = new Timer();
GradleConnector gradleConnector = GradleConnector.newConnector();
gradleConnector.forProjectDirectory(buildDir);
((DefaultGradleConnector) gradleConnector).embedded(embedded);
if (gradleInstallDir != null) {
gradleConnector.useInstallation(gradleInstallDir);
}
ProjectConnection connect = gradleConnector.connect();
try {
for (int i = 0; i < 5; i++) {
SyncAction.withProjectConnection(connect, null);
}
} finally {
connect.close();
}
timer.stop();
System.out.println("total time: " + timer.duration());
}
示例2: createProjectConnection
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
private ProjectConnection createProjectConnection(ComparableGradleBuildExecuter executer) {
GradleConnector connector = GradleConnector.newConnector();
connector.forProjectDirectory(executer.getSpec().getProjectDir());
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();
}
示例3: generate
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
@Override
public void generate(File targetDir, ProjectRequest projectRequest) {
GradleConnector gradleConnector = GradleConnector.newConnector().forProjectDirectory(targetDir);
if (projectRequest.getGradleVersion() != null) {
gradleConnector.useGradleVersion(projectRequest.getGradleVersion());
}
ProjectConnection connection = gradleConnector.connect();
try {
connection.newBuild().forTasks(buildTasks(projectRequest)).run();
} finally {
connection.close();
}
}
示例4: getProjectConnection
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
ProjectConnection getProjectConnection() {
final String gradleVersion = Config.load().getGradleVersion();
GradleConnector connector;
if (gradleVersion.isEmpty()) {
connector = GradleConnector.newConnector().forProjectDirectory(this.rootProject);
} else {
log.debug("use gradle version:'{}'", gradleVersion);
connector =
GradleConnector.newConnector()
.useGradleVersion(gradleVersion)
.forProjectDirectory(this.rootProject);
}
if (connector instanceof DefaultGradleConnector) {
final DefaultGradleConnector defaultGradleConnector = (DefaultGradleConnector) connector;
defaultGradleConnector.daemonMaxIdleTime(1, TimeUnit.HOURS);
}
return connector.connect();
}
示例5: getAndroidProject
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
/**
* Returns the {@link com.android.builder.model.AndroidProject} given the gradle project root.
* Note that this works only single module projects (only one build.gradle)
*/
@Nullable
private static AndroidProject getAndroidProject(String projectPath) {
File androidPlugin = new File(AndroidTestBase.getAndroidPluginHome());
File projectDir = new File(androidPlugin, BASE_PATH + projectPath);
GradleConnector connector = GradleConnector.newConnector();
connector.forProjectDirectory(projectDir);
connector.useDistribution(new DistributionLocator().getDistributionFor(GradleVersion.version("2.2.1")));
AndroidProject model = null;
ProjectConnection connection = connector.connect();
try {
model = connection.getModel(AndroidProject.class);
} finally {
connection.close();
}
return model;
}
示例6: getGradleModel
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
private EclipseProject getGradleModel(final String absoluteTargetPath) {
GradleConnector connector = GradleConnector.newConnector();
File target = new File(absoluteTargetPath);
connector.forProjectDirectory(target);
ProjectConnection connection = null;
EclipseProject eclipseProject = null;
try {
connection = connector.connect();
eclipseProject = connection.getModel(EclipseProject.class);
} finally {
if (connection != null) {
connection.close();
}
}
return eclipseProject;
}
示例7: main
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
public static void main(String[] args) {
// Configure the connector and create the connection
GradleConnector connector = GradleConnector.newConnector();
if (args.length > 0) {
connector.useInstallation(new File(args[0]));
if (args.length > 1) {
connector.useGradleUserHomeDir(new File(args[1]));
}
}
connector.forProjectDirectory(new File("."));
ProjectConnection connection = connector.connect();
try {
// Configure the build
BuildLauncher launcher = connection.newBuild();
launcher.forTasks("help");
launcher.setStandardOutput(System.out);
launcher.setStandardError(System.err);
// Run the build
launcher.run();
} finally {
// Clean up
connection.close();
}
}
示例8: getAndroidProject
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
static AndroidProject getAndroidProject(
final File root, final org.gradle.tooling.model.GradleProject gradleProject) {
String path = gradleProject.getPath();
String name = path.substring(1);
File childDir = new File(root, name);
GradleConnector childConnector = GradleConnector.newConnector().forProjectDirectory(childDir);
ProjectConnection childConnection = childConnector.connect();
try {
return childConnection.getModel(AndroidProject.class);
} catch (Exception e) {
return null;
} finally {
childConnection.close();
}
}
示例9: getModel
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
public AndroidProject getModel(@NonNull File project) {
// Configure the connector and create the connection
GradleConnector connector = GradleConnector.newConnector();
connector.forProjectDirectory(project);
ProjectConnection connection = connector.connect();
try {
// Load the custom model for the project
return connection.getModel(AndroidProject.class);
} finally {
connection.close();
}
}
示例10: main
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
public static void main(String[] args) {
// Configure the connector and create the connection
GradleConnector connector = GradleConnector.newConnector();
if (args.length > 0) {
connector.useInstallation(new File(args[0]));
if (args.length > 1) {
connector.useGradleUserHomeDir(new File(args[1]));
}
}
connector.forProjectDirectory(new File("."));
ProjectConnection connection = connector.connect();
try {
// Configure the build
BuildLauncher launcher = connection.newBuild();
launcher.forTasks("help");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
launcher.setStandardOutput(outputStream);
launcher.setStandardError(outputStream);
// Run the build
launcher.run();
} finally {
// Clean up
connection.close();
}
}
示例11: generateGradleClasspath
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
private void generateGradleClasspath() {
GradleConnector connector = GradleConnector.newConnector();
File target = new File(targetDir);
connector.forProjectDirectory(target);
ProjectConnection connection = null;
try {
connection = connector.connect();
EclipseProject eclipseProject = connection.getModel(EclipseProject.class);
StringBuilder gradleClasspath = new StringBuilder();
for (ExternalDependency externalDependency : eclipseProject.getClasspath()) {
if(gradleClasspath.toString().isEmpty()) {
gradleClasspath.append(externalDependency.getFile().getAbsolutePath());
} else {
gradleClasspath.append(File.pathSeparator + externalDependency.getFile().getAbsolutePath());
}
}
PrintWriter pw = null;
try {
pw = new PrintWriter(new File(targetDir + File.separator + "tacoco.cp"));
pw.write(gradleClasspath.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
pw.close();
} finally {
if (connection != null) {
connection.close();
}
}
}
示例12: execute
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
public void execute(ProjectConfigurationProvider provider, BasicGradleProject parent) throws Exception {
DomainObjectSet<? extends BasicGradleProject> subprojects = null;
File parentDir = provider.getConfigurationFile().getCanonicalFile().getParentFile();
if (parent == null) {
GradleConnector connector = GradleConnector.newConnector();
connector.forProjectDirectory(parentDir);
ProjectConnection connection = connector.connect();
GradleBuild settings = connection.getModel(GradleBuild.class);
subprojects = settings.getProjects();
} else {
subprojects = parent.getChildren();
}
Iterator<? extends BasicGradleProject> it = subprojects.iterator();
String currentDir = parentDir.getCanonicalPath();
List<String> modules = new LinkedList<String>();
while (it.hasNext()) {
BasicGradleProject current = it.next();
File projectDir = current.getProjectDirectory().getCanonicalFile();
if (!projectDir.getPath().equals(currentDir)) {
modules.add(current.getName());
ProjectConfigurationProvider moduleCfgProvider = provider
.clone(new File(projectDir, "walkmod." + provider.getFileExtension()));
execute(moduleCfgProvider, current);
}
}
if (!modules.isEmpty()) {
provider.addModules(modules);
} else {
provider.createConfig();
}
}
示例13: start
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
public GradleHandle start(File directory, List<String> arguments) {
GradleConnector connector = GradleConnector.newConnector();
connector.forProjectDirectory(directory);
ProjectConnection connection = connector.connect();
BuildLauncher launcher = connection.newBuild();
String[] argumentArray = new String[arguments.size()];
arguments.toArray(argumentArray);
launcher.withArguments(argumentArray);
return new BuildLauncherBackedGradleHandle(launcher);
}
示例14: setUp
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
assumeThat(gradleVersion, versionMatcherRule.getMatcher());
ensureTempDirCreated();
String methodName = name.getMethodName();
Matcher m = TEST_METHOD_NAME_PATTERN.matcher(methodName);
if (m.matches()) {
methodName = m.group(1);
}
testDir = new File(ourTempDir, methodName);
FileUtil.ensureExists(testDir);
FileUtil.writeToFile(
new File(testDir, GradleConstants.DEFAULT_SCRIPT_NAME),
FileUtil.loadTextAndClose(getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.DEFAULT_SCRIPT_NAME))
);
FileUtil.writeToFile(
new File(testDir, GradleConstants.SETTINGS_FILE_NAME),
FileUtil.loadTextAndClose(getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.SETTINGS_FILE_NAME))
);
GradleConnector connector = GradleConnector.newConnector();
final URI distributionUri = new DistributionLocator().getDistributionFor(GradleVersion.version(gradleVersion));
connector.useDistribution(distributionUri);
connector.forProjectDirectory(testDir);
int daemonMaxIdleTime = 10;
try {
daemonMaxIdleTime = Integer.parseInt(System.getProperty("gradleDaemonMaxIdleTime", "10"));
}
catch (NumberFormatException ignore) {}
((DefaultGradleConnector)connector).daemonMaxIdleTime(daemonMaxIdleTime, TimeUnit.SECONDS);
ProjectConnection connection = connector.connect();
try {
final ProjectImportAction projectImportAction = new ProjectImportAction(false);
projectImportAction.addExtraProjectModelClasses(getModels());
BuildActionExecuter<ProjectImportAction.AllModels> buildActionExecutor = connection.action(projectImportAction);
File initScript = GradleExecutionHelper.generateInitScript(false, getToolingExtensionClasses());
assertNotNull(initScript);
String jdkHome = IdeaTestUtil.requireRealJdkHome();
buildActionExecutor.setJavaHome(new File(jdkHome));
buildActionExecutor.setJvmArguments("-Xmx64m", "-XX:MaxPermSize=64m");
buildActionExecutor.withArguments("--info", "--recompile-scripts", GradleConstants.INIT_SCRIPT_CMD_OPTION, initScript.getAbsolutePath());
allModels = buildActionExecutor.run();
assertNotNull(allModels);
} finally {
connection.close();
}
}