本文整理汇总了Java中org.gradle.tooling.ProjectConnection类的典型用法代码示例。如果您正苦于以下问题:Java ProjectConnection类的具体用法?Java ProjectConnection怎么用?Java ProjectConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProjectConnection类属于org.gradle.tooling包,在下文中一共展示了ProjectConnection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: fetch
import org.gradle.tooling.ProjectConnection; //导入依赖的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());
}
开发者ID:lxxlxx888,项目名称:Reer,代码行数:26,代码来源:Main.java
示例2: createProjectConnection
import org.gradle.tooling.ProjectConnection; //导入依赖的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();
}
开发者ID:lxxlxx888,项目名称:Reer,代码行数:18,代码来源:GradleBuildComparison.java
示例3: generate
import org.gradle.tooling.ProjectConnection; //导入依赖的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();
}
}
开发者ID:bmuschko,项目名称:gradle-initializr,代码行数:17,代码来源:ToolingApiProjectGenerator.java
示例4: prepareCompileAndroidJava
import org.gradle.tooling.ProjectConnection; //导入依赖的package包/类
void prepareCompileAndroidJava() {
ProjectConnection connection = this.project.getProjectConnection();
try {
BuildLauncher buildLauncher = connection.newBuild();
String genTask = this.project.getName() + this.genSourceTaskName;
buildLauncher.forTasks(genTask).run();
int size = this.project.getDependencies().size();
String aar =
Joiner.on(File.separator)
.join(this.project.getProjectRoot(), BUILD_DIR, INTERMEDIATE_DIR, EXPLODED_DIR);
List<File> jars = FileUtils.collectFiles(new File(aar), EXT_JAR);
for (File jar : jars) {
addAAR(jar);
}
int after = this.project.getDependencies().size();
if (size != after) {
CachedASMReflector.getInstance().createClassIndexes(jars);
this.project.resetCachedClasspath();
}
} finally {
connection.close();
}
}
开发者ID:mopemope,项目名称:meghanada-server,代码行数:27,代码来源:AndroidSupport.java
示例5: getProjectConnection
import org.gradle.tooling.ProjectConnection; //导入依赖的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();
}
开发者ID:mopemope,项目名称:meghanada-server,代码行数:20,代码来源:GradleProject.java
示例6: createProject
import org.gradle.tooling.ProjectConnection; //导入依赖的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
示例7: defaultJvmArgsArePreservedWhenLoadedAgentIsConfigured
import org.gradle.tooling.ProjectConnection; //导入依赖的package包/类
@Test
public void defaultJvmArgsArePreservedWhenLoadedAgentIsConfigured()
throws IOException {
ProjectConnection project = new ProjectCreator()
.createProject("spring-loaded-jvm-args");
project.newBuild().forTasks("bootRun")
.withArguments("-PbootVersion=" + BOOT_VERSION,
"-PspringLoadedVersion=" + SPRING_LOADED_VERSION, "--stacktrace")
.run();
List<String> output = getOutput();
assertOutputContains("-DSOME_ARG=someValue", output);
assertOutputContains("-Xverify:none", output);
assertOutputMatches("-javaagent:.*springloaded-" + SPRING_LOADED_VERSION + ".jar",
output);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:SpringLoadedTests.java
示例8: gradleBuild
import org.gradle.tooling.ProjectConnection; //导入依赖的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));
}
}
开发者ID:dschaefer,项目名称:andmore2,代码行数:18,代码来源:AndroidBuilder.java
示例9: runTasks
import org.gradle.tooling.ProjectConnection; //导入依赖的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();
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:18,代码来源:GradleAutomaticBuilder.java
示例10: getSingleModel
import org.gradle.tooling.ProjectConnection; //导入依赖的package包/类
/**
* Returns the project model without building.
*
* This will fail if the project is a multi-project setup.
*
* @param emulateStudio_1_0 whether to emulate an older IDE (studio 1.0) querying the model.
* @param assertNoSyncIssues true if the presence of sync issues during the model evaluation
* should raise a {@link AssertionError}s
*/
@NonNull
private AndroidProject getSingleModel(boolean emulateStudio_1_0, boolean assertNoSyncIssues) {
ProjectConnection connection = getProjectConnection();
try {
Map<String, AndroidProject> modelMap = buildModel(
connection,
new GetAndroidModelAction(),
emulateStudio_1_0);
// ensure there was only one project
assertEquals("Quering GradleTestProject.getModel() with multi-project settings",
1, modelMap.size());
AndroidProject androidProject = modelMap.get(":");
if (assertNoSyncIssues) {
assertNoSyncIssues(androidProject);
}
return androidProject;
} finally {
connection.close();
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:GradleTestProject.java
示例11: executeBuild
import org.gradle.tooling.ProjectConnection; //导入依赖的package包/类
private void executeBuild(List<String> arguments, ProjectConnection connection,
String[] tasks) {
List<String> args = Lists.newArrayListWithCapacity(3 + arguments.size());
args.add("-i");
args.add("-u");
args.addAll(arguments);
BuildLauncher launcher = connection.newBuild()
.forTasks(tasks)
.withArguments(Iterables.toArray(args, String.class));
setJvmArguments(launcher);
if (stdout != null) {
launcher.setStandardOutput(stdout);
} else {
launcher.setStandardOutput(System.out);
}
if (stderr != null) {
launcher.setStandardError(stderr);
} else {
launcher.setStandardError(System.err);
}
launcher.run();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:GradleTestProject.java
示例12: buildModel
import org.gradle.tooling.ProjectConnection; //导入依赖的package包/类
/**
* Returns a project model for each sub-project without building.
*
* @param connection the opened ProjectConnection
* @param action the build action to gather the model
* @param emulateStudio_1_0 whether to emulate an older IDE (studio 1.0) querying the model.
*/
@NonNull
private <K,V> Map<K, V> buildModel(
@NonNull ProjectConnection connection,
@NonNull BuildAction<Map<K, V>> action,
boolean emulateStudio_1_0) {
BuildActionExecuter<Map<K, V>> executor = connection.action(action);
List<String> arguments = Lists.newArrayListWithCapacity(emulateStudio_1_0 ? 2 : 3);
arguments.add("-P" + AndroidProject.PROPERTY_BUILD_MODEL_ONLY + "=true");
arguments.add("-P" + AndroidProject.PROPERTY_INVOKED_FROM_IDE + "=true");
if (!emulateStudio_1_0) {
arguments.add("-P" + AndroidProject.PROPERTY_BUILD_MODEL_ONLY_ADVANCED + "=true");
}
setJvmArguments(executor);
executor.withArguments(Iterables.toArray(arguments, String.class));
executor.setStandardOutput(System.out);
executor.setStandardError(System.err);
return executor.run();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:GradleTestProject.java
示例13: setUp
import org.gradle.tooling.ProjectConnection; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
myIdeaProject = new IdeaProjectStub("multiProject");
myAndroidProject = TestProjects.createBasicProject(myIdeaProject.getRootDir());
myAndroidModule = myIdeaProject.addModule(myAndroidProject.getName(), "androidTask");
myUtilModule = myIdeaProject.addModule("util", "compileJava", "jar", "classes");
myIdeaProject.addModule("notReallyAGradleProject");
ProjectImportAction.AllModels allModels = new ProjectImportAction.AllModels(myIdeaProject);
allModels.addExtraProject(myAndroidProject, AndroidProject.class, myAndroidModule);
ExternalSystemTaskId id = ExternalSystemTaskId.create(SYSTEM_ID, RESOLVE_PROJECT, myIdeaProject.getName());
String projectPath = FileUtil.toSystemDependentName(myIdeaProject.getBuildFile().getParent());
ExternalSystemTaskNotificationListener notificationListener = new ExternalSystemTaskNotificationListenerAdapter() {};
myResolverCtx = new ProjectResolverContext(id, projectPath, null, createMock(ProjectConnection.class), notificationListener, true);
myResolverCtx.setModels(allModels);
myProjectResolver = new AndroidGradleProjectResolver(createMock(ProjectImportErrorHandler.class));
myProjectResolver.setProjectResolverContext(myResolverCtx);
GradleProjectResolverExtension next = new BaseGradleProjectResolverExtension();
next.setProjectResolverContext(myResolverCtx);
myProjectResolver.setNext(next);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:AndroidGradleProjectResolverIdeaTest.java
示例14: getAndroidProject
import org.gradle.tooling.ProjectConnection; //导入依赖的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;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ExportSignedPackageTest.java
示例15: addGradleClassPath
import org.gradle.tooling.ProjectConnection; //导入依赖的package包/类
private static void addGradleClassPath(@NotNull final List<String> classpath) {
String gradleLibDirPath = null;
String gradleToolingApiJarPath = PathUtil.getJarPathForClass(ProjectConnection.class);
if (!StringUtil.isEmpty(gradleToolingApiJarPath)) {
gradleLibDirPath = PathUtil.getParentPath(gradleToolingApiJarPath);
}
if (gradleLibDirPath == null || gradleLibDirPath.isEmpty()) return;
File gradleLibDir = new File(gradleLibDirPath);
if (!gradleLibDir.isDirectory()) return;
File[] children = FileUtil.notNullize(gradleLibDir.listFiles());
for (File child : children) {
final String fileName = child.getName();
if (fileName.endsWith(".jar") && child.isFile()) {
classpath.add(child.getAbsolutePath());
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:GradleBuildProcessParametersProvider.java
示例16: executeWith
import org.gradle.tooling.ProjectConnection; //导入依赖的package包/类
public ProjectOutcomes executeWith(ProjectConnection connection) {
List<String> tasksList = getSpec().getTasks();
String[] tasks = tasksList.toArray(new String[tasksList.size()]);
List<String> argumentsList = getImpliedArguments();
String[] arguments = argumentsList.toArray(new String[argumentsList.size()]);
if (isCanObtainProjectOutcomesModel()) {
// Run the build and get the build outcomes model
ModelBuilder<ProjectOutcomes> modelBuilder = connection.model(ProjectOutcomes.class);
return modelBuilder.
withArguments(arguments).
forTasks(tasks).
get();
} else {
BuildLauncher buildLauncher = connection.newBuild();
buildLauncher.
withArguments(arguments).
forTasks(tasks).
run();
return null;
}
}
开发者ID:Pushjet,项目名称:Pushjet-Android,代码行数:24,代码来源:ComparableGradleBuildExecuter.java
示例17: getGradleModel
import org.gradle.tooling.ProjectConnection; //导入依赖的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;
}
开发者ID:spideruci,项目名称:tacoco,代码行数:21,代码来源:GradleBuildProbe.java
示例18: compile
import org.gradle.tooling.ProjectConnection; //导入依赖的package包/类
public void compile() throws Exception {
ProjectConnection connection = getConnector().connect();
try {
// Configure the build
BuildLauncher launcher = connection.newBuild();
if (flavor != null) {
launcher.forTasks(task + StringUtils.capitalize(flavor));
} else {
launcher.forTasks(task);
}
if (buildFile != null) {
launcher.withArguments("-b", buildFile.getAbsolutePath());
}
launcher.setStandardOutput(System.out);
launcher.setStandardError(System.err);
// Run the build
launcher.run();
} finally {
// Clean up
connection.close();
}
}
开发者ID:walkmod,项目名称:walkmod-gradle-plugin,代码行数:25,代码来源:ClassLoaderConfigurationProvider.java
示例19: doResolveProjectInfo
import org.gradle.tooling.ProjectConnection; //导入依赖的package包/类
@NotNull
private DataNode<ProjectData> doResolveProjectInfo(@NotNull final ExternalSystemTaskId id,
@NotNull String projectPath,
@Nullable GradleExecutionSettings settings,
@NotNull ProjectConnection connection,
@NotNull ExternalSystemTaskNotificationListener listener,
boolean downloadLibraries)
throws IllegalArgumentException, IllegalStateException
{
ModelBuilder<? extends IdeaProject> modelBuilder = myHelper.getModelBuilder(id, settings, connection, listener, downloadLibraries);
IdeaProject project = modelBuilder.get();
DataNode<ProjectData> result = populateProject(project, projectPath);
// We need two different steps ('create' and 'populate') in order to handle module dependencies, i.e. when one module is
// configured to be dependency for another one, corresponding dependency module object should be available during
// populating dependent module object.
Map<String, Pair<DataNode<ModuleData>, IdeaModule>> modules = createModules(project, result);
populateModules(modules.values(), result);
Collection<DataNode<LibraryData>> libraries = ExternalSystemApiUtil.getChildren(result, ProjectKeys.LIBRARY);
myLibraryNamesMixer.mixNames(libraries);
parseTasks(result, project);
return result;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:24,代码来源:GradleProjectResolver.java
示例20: run
import org.gradle.tooling.ProjectConnection; //导入依赖的package包/类
/**
* Performs this task.
* @throws GradleException if and only if the build was failed
*/
@Override
public void run(IProgressMonitor monitor) throws GradleException, CoreException {
SubMonitor sub = SubMonitor.convert(monitor, Messages.GradleBuildTask_monitorRun, 100);
try {
try {
GradleUtil.enhance(sub.newChild(10, SubMonitor.SUPPRESS_NONE), configuration);
ProjectConnection connection = createProjectConnection(sub.newChild(10, SubMonitor.SUPPRESS_NONE));
try {
buildProject(sub.newChild(60, SubMonitor.SUPPRESS_NONE), connection);
} finally {
disconnectProject(sub.newChild(10, SubMonitor.SUPPRESS_NONE), connection);
}
} finally {
GradleUtil.dispose(sub.newChild(10, SubMonitor.SUPPRESS_NONE), configuration);
}
} finally {
monitor.done();
}
}
开发者ID:asakusafw,项目名称:asakusafw-shafu,代码行数:24,代码来源:GradleBuildTask.java
注:本文中的org.gradle.tooling.ProjectConnection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论