@Test public void testGetDockerContainerId() throws Exception { ProjectInfo projectInfo = GradleTooling.loadProjectInfo(_wsPath); Assert.assertEquals("custom-workspace-liferay1", projectInfo.getDockerContainerId()); }
public static ProjectInfo loadProjectInfo(Path projectPath) throws Exception { ProjectInfo projectInfo = null; GradleConnector connector = GradleConnector.newConnector(); connector.forProjectDirectory(projectPath.toFile()); ProjectConnection connection = null; try { connection = connector.connect(); ModelBuilder<ProjectInfo> modelBuilder = connection.model(ProjectInfo.class); Path tempPath = Files.createTempDirectory("tooling"); InputStream in = GradleTooling.class.getResourceAsStream("/tooling.zip"); FileUtil.unzip(in, tempPath.toFile()); try (Stream<Path> toolingFiles = Files.list(tempPath)) { String files = toolingFiles.map( Path::toAbsolutePath ).map( Path::toString ).map( path -> "\"" + path.replaceAll("\\\\", "/") + "\"" ).collect( Collectors.joining(", ") ); String initScriptTemplate = FileUtil.collect(GradleTooling.class.getResourceAsStream("init.gradle")); String initScriptContents = initScriptTemplate.replaceAll("%files%", files); Path initPath = tempPath.resolve("init.gradle"); Files.write(initPath, initScriptContents.getBytes()); modelBuilder.withArguments("--init-script", initPath.toString(), "--stacktrace"); projectInfo = modelBuilder.get(); } } finally { if (connection != null) { connection.close(); } } return projectInfo; }
GradleTooling { public static ProjectInfo loadProjectInfo(Path projectPath) throws Exception { ProjectInfo projectInfo = null; GradleConnector connector = GradleConnector.newConnector(); connector.forProjectDirectory(projectPath.toFile()); ProjectConnection connection = null; try { connection = connector.connect(); ModelBuilder<ProjectInfo> modelBuilder = connection.model(ProjectInfo.class); Path tempPath = Files.createTempDirectory("tooling"); InputStream in = GradleTooling.class.getResourceAsStream("/tooling.zip"); FileUtil.unzip(in, tempPath.toFile()); try (Stream<Path> toolingFiles = Files.list(tempPath)) { String files = toolingFiles.map( Path::toAbsolutePath ).map( Path::toString ).map( path -> "\"" + path.replaceAll("\\\\", "/") + "\"" ).collect( Collectors.joining(", ") ); String initScriptTemplate = FileUtil.collect(GradleTooling.class.getResourceAsStream("init.gradle")); String initScriptContents = initScriptTemplate.replaceAll("%files%", files); Path initPath = tempPath.resolve("init.gradle"); Files.write(initPath, initScriptContents.getBytes()); modelBuilder.withArguments("--init-script", initPath.toString(), "--stacktrace"); projectInfo = modelBuilder.get(); } } finally { if (connection != null) { connection.close(); } } return projectInfo; } }
GradleTooling { public static ProjectInfo loadProjectInfo(Path projectPath) throws Exception { ProjectInfo projectInfo = null; GradleConnector connector = GradleConnector.newConnector(); connector.forProjectDirectory(projectPath.toFile()); ProjectConnection connection = null; try { connection = connector.connect(); ModelBuilder<ProjectInfo> modelBuilder = connection.model(ProjectInfo.class); Path tempPath = Files.createTempDirectory("tooling"); InputStream in = GradleTooling.class.getResourceAsStream("/tooling.zip"); FileUtil.unzip(in, tempPath.toFile()); try (Stream<Path> toolingFiles = Files.list(tempPath)) { String files = toolingFiles.map( Path::toAbsolutePath ).map( Path::toString ).map( path -> "\"" + path.replaceAll("\\\\", "/") + "\"" ).collect( Collectors.joining(", ") ); String initScriptTemplate = FileUtil.collect(GradleTooling.class.getResourceAsStream("init.gradle")); String initScriptContents = initScriptTemplate.replaceAll("%files%", files); Path initPath = tempPath.resolve("init.gradle"); Files.write(initPath, initScriptContents.getBytes()); modelBuilder.withArguments("--init-script", initPath.toString(), "--stacktrace"); projectInfo = modelBuilder.get(); } } finally { if (connection != null) { connection.close(); } } return projectInfo; }  }
GradleTooling { public static ProjectInfo loadProjectInfo(Path projectPath) throws Exception { ProjectInfo projectInfo = null; GradleConnector connector = GradleConnector.newConnector(); connector.forProjectDirectory(projectPath.toFile()); ProjectConnection connection = null; try { connection = connector.connect(); ModelBuilder<ProjectInfo> modelBuilder = connection.model(ProjectInfo.class); Path tempPath = Files.createTempDirectory("tooling"); InputStream in = GradleTooling.class.getResourceAsStream("/tooling.zip"); FileUtil.unzip(in, tempPath.toFile()); try (Stream<Path> toolingFiles = Files.list(tempPath)) { String files = toolingFiles.map( Path::toAbsolutePath ).map( Path::toString ).map( path -> "\"" + path.replaceAll("\\\\", "/") + "\"" ).collect( Collectors.joining(", ") ); String initScriptTemplate = FileUtil.collect(GradleTooling.class.getResourceAsStream("init.gradle")); String initScriptContents = initScriptTemplate.replaceAll("%files%", files); Path initPath = tempPath.resolve("init.gradle"); Files.write(initPath, initScriptContents.getBytes()); modelBuilder.withArguments("--init-script", initPath.toString(), "--stacktrace"); projectInfo = modelBuilder.get(); } } finally { if (connection != null) { connection.close(); } } return projectInfo; }  static ProjectInfo loadProjectInfo(Path projectPath); }
GradleTooling { public static ProjectInfo loadProjectInfo(Path projectPath) throws Exception { ProjectInfo projectInfo = null; GradleConnector connector = GradleConnector.newConnector(); connector.forProjectDirectory(projectPath.toFile()); ProjectConnection connection = null; try { connection = connector.connect(); ModelBuilder<ProjectInfo> modelBuilder = connection.model(ProjectInfo.class); Path tempPath = Files.createTempDirectory("tooling"); InputStream in = GradleTooling.class.getResourceAsStream("/tooling.zip"); FileUtil.unzip(in, tempPath.toFile()); try (Stream<Path> toolingFiles = Files.list(tempPath)) { String files = toolingFiles.map( Path::toAbsolutePath ).map( Path::toString ).map( path -> "\"" + path.replaceAll("\\\\", "/") + "\"" ).collect( Collectors.joining(", ") ); String initScriptTemplate = FileUtil.collect(GradleTooling.class.getResourceAsStream("init.gradle")); String initScriptContents = initScriptTemplate.replaceAll("%files%", files); Path initPath = tempPath.resolve("init.gradle"); Files.write(initPath, initScriptContents.getBytes()); modelBuilder.withArguments("--init-script", initPath.toString(), "--stacktrace"); projectInfo = modelBuilder.get(); } } finally { if (connection != null) { connection.close(); } } return projectInfo; }  static ProjectInfo loadProjectInfo(Path projectPath);  }