GradleProject extends Project { @Override @SuppressWarnings("try") public Project parseProject(File projectRoot, File current) throws ProjectParseException { try (TelemetryUtils.ScopedSpan scope = TelemetryUtils.startScopedSpan("GradleProject.parseProject"); final ProjectConnection connection = getProjectConnection()) { TelemetryUtils.ScopedSpan.addAnnotation( TelemetryUtils.annotationBuilder() .put("projectRoot", projectRoot.getPath()) .put("current", current.getPath()) .build("args")); log.info( "loading gradle project:{}", new File(this.projectRoot, isGradleProject(this.projectRoot).get())); BuildEnvironment env = connection.getModel(BuildEnvironment.class); String version = env.getGradle().getGradleVersion(); if (isNull(version)) { version = GradleVersion.current().getVersion(); } this.gradleVersion = new ComparableVersion(version); IdeaProject ideaProject = debugTimeItF( "get idea project model elapsed={}", () -> connection.getModel(IdeaProject.class)); this.setCompileTarget(ideaProject); log.trace("load root project path:{}", this.rootProject); DomainObjectSet<? extends IdeaModule> modules = ideaProject.getModules(); List<? extends IdeaModule> mainModules = modules .parallelStream() .filter( ideaModule -> { org.gradle.tooling.model.GradleProject gradleProject = ideaModule.getGradleProject(); File moduleProjectRoot = gradleProject.getProjectDirectory(); String name = ideaModule.getName(); log.trace("find sub-module name {} path {} ", name, moduleProjectRoot); this.allModules.putIfAbsent(name, moduleProjectRoot); return moduleProjectRoot.equals(this.getProjectRoot()); }) .collect(Collectors.toList()); mainModules.forEach( wrapIOConsumer( p -> { this.parseIdeaModule(connection, p); })); if (isNull(super.output)) { String build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "main"); if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) { build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "java", "main"); } super.output = this.normalize(build); } if (isNull(super.testOutput)) { String build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "test"); if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) { build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "java", "test"); } super.testOutput = this.normalize(build); } return this; } catch (Exception e) { Throwable cause = findLocationException(e); throw new ProjectParseException(cause); } } GradleProject(File projectRoot);  GradleProject(File projectRoot, boolean kts); static String getTempPath(); static long getSerialVersionUID(); @Override @SuppressWarnings("try") Project parseProject(File projectRoot, File current); @Override InputStream runTask(List<String> args); @Override CompileResult compileJava(); @Override CompileResult compileJava(boolean force); @Override CompileResult compileTestJava(); @Override CompileResult compileTestJava(boolean force); @Override Project mergeFromProjectConfig(); @Override String getProjectType(); boolean isKTS(); static Optional<String> isGradleProject(File dir); static final String[] STRINGS; }
@Ignore @Test public void testParse01() throws Exception { File file = project.getProjectRoot(); Project parsed = this.project.parseProject(file, file); final File outputDirectory = parsed.getOutput(); assertNotNull(outputDirectory); System.out.println(outputDirectory); }
@Ignore @Test public void testParse02() throws Exception { File file = project.getProjectRoot(); final Project project = timeIt(() -> this.project.parseProject(file, file)); final String classpath = project.classpath(); assertNotNull(classpath); final String all = project.classpath(); assertNotNull(all); }
@Ignore @Test public void testLoadProject01() throws Exception { File file = project.getProjectRoot(); Project parsed = project.parseProject(file, file); String classpath1 = parsed.classpath(); timeIt(parsed::saveProject); Thread.sleep(1000); Project load = timeIt(() -> Project.loadProject(this.projectRootPath)); String classpath2 = load.classpath(); assertEquals(classpath1, classpath2); timeIt(load::saveProject); }