本文整理汇总了Java中org.gradle.tooling.GradleConnector类的典型用法代码示例。如果您正苦于以下问题:Java GradleConnector类的具体用法?Java GradleConnector怎么用?Java GradleConnector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GradleConnector类属于org.gradle.tooling包,在下文中一共展示了GradleConnector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: createProject
import org.gradle.tooling.GradleConnector; //导入依赖的package包/类
public ProjectConnection createProject(String name) throws IOException {
File projectDirectory = new File("target/" + name);
projectDirectory.mkdirs();
File gradleScript = new File(projectDirectory, "build.gradle");
if (new File("src/test/resources", name).isDirectory()) {
FileSystemUtils.copyRecursively(new File("src/test/resources", name),
projectDirectory);
}
else {
FileCopyUtils.copy(new File("src/test/resources/" + name + ".gradle"),
gradleScript);
}
GradleConnector gradleConnector = GradleConnector.newConnector();
gradleConnector.useGradleVersion(this.gradleVersion);
((DefaultGradleConnector) gradleConnector).embedded(true);
return gradleConnector.forProjectDirectory(projectDirectory).connect();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:22,代码来源:ProjectCreator.java
示例6: gradleBuild
import org.gradle.tooling.GradleConnector; //导入依赖的package包/类
public static void gradleBuild(IProject project, String task, IProgressMonitor monitor) throws CoreException {
String taskName = String.format("Executing %s on project %s", task, project.getName());
try {
IConsoleService console = Activator.getService(IConsoleService.class);
console.activate();
console.writeOutput(String.format("\n%s\n\n", taskName)); //$NON-NLS-1$
File projectDir = new File(project.getLocationURI());
ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(projectDir).connect();
connection.newBuild().forTasks(task).setStandardOutput(console.getOutputStream())
.setStandardError(console.getErrorStream()).run();
connection.close();
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
} catch (BuildException | IOException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), taskName, e));
}
}
示例7: startSynchronization
import org.gradle.tooling.GradleConnector; //导入依赖的package包/类
protected void startSynchronization(Path rootFolder, IProgressMonitor monitor) {
File location = rootFolder.toFile();
boolean shouldSynchronize = shouldSynchronize(location);
List<IProject> projects = ProjectUtils.getGradleProjects();
for (IProject project : projects) {
File projectDir = project.getLocation() == null ? null : project.getLocation().toFile();
if (location.equals(projectDir)) {
//
shouldSynchronize = checkGradlePersistence(shouldSynchronize, project, projectDir);
break;
}
}
if (shouldSynchronize) {
boolean overrideWorkspaceSettings = getGradleHomeFile() != null;
GradleDistribution distribution = getGradleDistribution(rootFolder);
BuildConfiguration configuration = CorePlugin.configurationManager().createBuildConfiguration(location, overrideWorkspaceSettings, distribution, null, false, false, false);
GradleBuild build = CorePlugin.gradleWorkspaceManager().getGradleBuild(configuration);
build.getModelProvider().fetchEclipseGradleProjects(FetchStrategy.LOAD_IF_NOT_CACHED, GradleConnector.newCancellationTokenSource().token(), monitor);
build.synchronize(NewProjectHandler.IMPORT_AND_MERGE);
}
}
示例8: runTasks
import org.gradle.tooling.GradleConnector; //导入依赖的package包/类
protected byte[] runTasks(String pathToRootOfProject, String... tasks) {
ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(new File(pathToRootOfProject)).connect();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
BuildLauncher build = connection.newBuild();
build.forTasks(tasks);
build.setStandardOutput(outputStream);
build.setStandardError(outputStream);
build.run();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
connection.close();
}
return outputStream.toByteArray();
}
示例9: 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;
}
示例10: open
import org.gradle.tooling.GradleConnector; //导入依赖的package包/类
/**
* Connects to the NVList project at the specified location.
*
* @throws CheckedGradleException If connecting the the project's Gradle build fails.
*/
public void open(ProjectFolderConfig folderConfig) throws CheckedGradleException {
if (connection != null) {
connection.close();
}
try {
connection = GradleConnector.newConnector()
.useBuildDistribution()
.forProjectDirectory(folderConfig.getBuildToolsFolder())
.connect();
} catch (GradleConnectionException e) {
throw new CheckedGradleException("Error connecting to Gradle: folderConfig=" + folderConfig, e);
}
this.folderConfig = folderConfig;
}
示例11: 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;
}
示例12: createConnector
import org.gradle.tooling.GradleConnector; //导入依赖的package包/类
/**
* Creates a new Gradle connector for the context.
* @param context the target context
* @return a connector
*/
public static GradleConnector createConnector(GradleContext context) {
GradleConnector connector = GradleConnector.newConnector();
connector.forProjectDirectory(context.getProjectDirectory().getAbsoluteFile());
String versionLabel;
if (context.getGradleDistribution() != null) {
versionLabel = context.getGradleDistribution().toString();
connector.useDistribution(context.getGradleDistribution());
} else {
String version = context.getGradleVersion();
version = version == null ? GradleVersion.current().getVersion() : version;
versionLabel = version;
URI distribution = toDistributionUri(version, context.isUseHttps());
if (distribution != null) {
connector.useDistribution(distribution);
} else {
connector.useGradleVersion(version);
}
}
context.information(MessageFormat.format(
Messages.GradleUtil_infoPrepareDaemon,
versionLabel));
if (context.getGradleUserHomeDir() != null) {
connector.useGradleUserHomeDir(context.getGradleUserHomeDir().getAbsoluteFile());
}
return connector;
}
示例13: OperationHandler
import org.gradle.tooling.GradleConnector; //导入依赖的package包/类
/**
* Creates a new instance.
* @param operation the target operation
* @param systemProperties the original system properties
* @param cancelFile cancel marker file
*/
public OperationHandler(
LongRunningOperation operation,
Properties systemProperties,
File cancelFile) {
this.cancellator = GradleConnector.newCancellationTokenSource();
operation.addProgressListener(new ProgressListener() {
@Override
public void statusChanged(ProgressEvent event) {
eventRef.set(event);
}
});
operation.withCancellationToken(cancellator.token());
this.systemProperties = systemProperties;
this.cancelFile = cancelFile;
}
示例14: configureGradleRuntime
import org.gradle.tooling.GradleConnector; //导入依赖的package包/类
/**
* Configure the gradle runtime, version or home depending on the settings.
* @param connector
*/
public static void configureGradleRuntime(GradleConnector connector, IPreferenceStore prefs) {
String gradleVersion = prefs.getString(WorkbenchPreferencePage.GRADLE_VERSION_ID);
if (GradlePluginConstants.USE_GRADLE_HOME_VERSION_VALUE.equals(gradleVersion)) {
String gradleHome = prefs.getString(WorkbenchPreferencePage.GRADLE_HOME_ID);
File gradleHomeDir = new File(gradleHome);
if (isFileValidGradleInstallation(gradleHomeDir)) {
connector.useInstallation(gradleHomeDir);
return;
} else {
throw new IllegalStateException("Configured gradle home is not valid");
}
}
connector.useGradleVersion(gradleVersion);
}
示例15: buildConnector
import org.gradle.tooling.GradleConnector; //导入依赖的package包/类
private GradleConnector buildConnector(File gradleUserHome, File projectDir, boolean embedded, GradleProvider gradleProvider) {
DefaultGradleConnector gradleConnector = (DefaultGradleConnector) GradleConnector.newConnector();
gradleConnector.useDistributionBaseDir(GradleUserHomeLookup.gradleUserHome());
gradleProvider.applyTo(gradleConnector);
gradleConnector.useGradleUserHomeDir(gradleUserHome);
gradleConnector.daemonBaseDir(new File(gradleUserHome, TEST_KIT_DAEMON_DIR_NAME));
gradleConnector.forProjectDirectory(projectDir);
gradleConnector.searchUpwards(false);
gradleConnector.daemonMaxIdleTime(120, TimeUnit.SECONDS);
gradleConnector.embedded(embedded);
return gradleConnector;
}