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);  }
@Test public void testGetDockerContainerId() throws Exception { ProjectInfo projectInfo = GradleTooling.loadProjectInfo(_wsPath); Assert.assertEquals("custom-workspace-liferay1", projectInfo.getDockerContainerId()); }
@Test public void testGetDockerImageId() throws Exception { ProjectInfo projectInfo = GradleTooling.loadProjectInfo(_wsPath); Assert.assertEquals("custom-workspace-image:1.0.0", projectInfo.getDockerImageId()); }
@Test public void testGetDockerImageLiferay() throws Exception { ProjectInfo projectInfo = GradleTooling.loadProjectInfo(_wsPath); Assert.assertNotNull("liferay/portal:7.2.0-ga1", projectInfo.getDockerImageLiferay()); }
@Test public void testGetOutputFiles() throws Exception { ProjectInfo projectInfo = GradleTooling.loadProjectInfo(_wsPath); Map<String, Set<File>> projectOutputFiles = projectInfo.getProjectOutputFiles(); Assert.assertNotNull(projectOutputFiles); Assert.assertEquals( projectOutputFiles.toString(), true, projectOutputFiles.containsKey(":modules:testportlet")); Set<File> files = projectOutputFiles.get(":modules:testportlet"); Assert.assertEquals(files.toString(), 1, files.size()); }
@Test public void testGetPluginClassNames() throws Exception { Path projectPath = _wsPath.resolve("modules/testportlet"); ProjectInfo projectInfo = GradleTooling.loadProjectInfo(projectPath); Set<String> pluginClassNames = projectInfo.getPluginClassNames(); Assert.assertNotNull(pluginClassNames); Assert.assertTrue(pluginClassNames.contains("com.liferay.gradle.plugins.LiferayOSGiPlugin")); }
@Test public void testIsLiferayModule() throws Exception { Path projectPath = _wsPath.resolve("modules/testportlet"); ProjectInfo projectInfo = GradleTooling.loadProjectInfo(projectPath); Assert.assertTrue(projectInfo.isLiferayProject()); }
@Test public void testIsNotLiferayModule() throws Exception { Path projectPath = _wsPath.resolve("modules"); ProjectInfo projectInfo = GradleTooling.loadProjectInfo(projectPath); Assert.assertFalse(projectInfo.isLiferayProject()); }