本文整理汇总了Java中org.gradle.tooling.GradleConnector.newConnector方法的典型用法代码示例。如果您正苦于以下问题:Java GradleConnector.newConnector方法的具体用法?Java GradleConnector.newConnector怎么用?Java GradleConnector.newConnector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.gradle.tooling.GradleConnector
的用法示例。
在下文中一共展示了GradleConnector.newConnector方法的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: 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
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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();
}
}
示例9: getGradleConnection
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
/**
* Retrieves the gradle connection to the task folder.
*
* @return a gradle connection to the task folder.
*/
protected ProjectConnection getGradleConnection() {
if (gradleConnector == null) {
gradleConnector = GradleConnector.newConnector();
File gradleHome = new File(GRADLE_PATH);
LOG.log(Level.INFO, "Gradle Home directory");
LOG.log(Level.INFO, gradleHome.getAbsolutePath());
gradleConnector.useInstallation(gradleHome);
gradleConnector.forProjectDirectory(new File(gradleTask.getFolder()));
}
return gradleConnector.connect();
}
示例10: getGradleConnector
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
@NotNull
private static GradleConnector getGradleConnector(@NotNull BuilderExecutionSettings executionSettings) {
GradleConnector connector = GradleConnector.newConnector();
if (connector instanceof DefaultGradleConnector) {
DefaultGradleConnector defaultConnector = (DefaultGradleConnector)connector;
if (executionSettings.isEmbeddedModeEnabled()) {
LOG.info("Using Gradle embedded mode.");
defaultConnector.embedded(true);
}
defaultConnector.setVerboseLogging(executionSettings.isVerboseLoggingEnabled());
}
connector.forProjectDirectory(executionSettings.getProjectDir());
File gradleHomeDir = executionSettings.getGradleHomeDir();
if (gradleHomeDir != null) {
connector.useInstallation(gradleHomeDir);
}
File gradleServiceDir = executionSettings.getGradleServiceDir();
if (gradleServiceDir != null) {
connector.useGradleUserHomeDir(gradleServiceDir);
}
return connector;
}
示例11: 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();
}
}
示例12: getProjectConnection
import org.gradle.tooling.GradleConnector; //导入方法依赖的package包/类
/**
* Returns a Gradle project Connection
*/
@NonNull
private ProjectConnection getProjectConnection() {
GradleConnector connector = GradleConnector.newConnector();
// Limit daemon idle time for tests. 10 seconds is enough for another test
// to start and reuse the daemon.
((DefaultGradleConnector) connector).daemonMaxIdleTime(10, TimeUnit.SECONDS);
return connector
.useGradleVersion(targetGradleVersion)
.forProjectDirectory(testDir)
.connect();
}
示例13: 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();
}
}
示例14: 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();
}
}
}
示例15: 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();
}
}