logic: added Gradle project setup (issue #379)
* added implementation for Gradle project setup (icon is still missing) * refactored project loading/saving and SourceGroupSettings * removed long deprecated Cxx UseSourcePathsForHeaderSearch option fortune cookie message = There is true and sincere friendship between you and your friends.
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -24,11 +24,37 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>mvnrepository</id>
|
||||
<name>mvnrepository</name>
|
||||
<url>http://www.mvnrepository.com</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>repo_gradle</id>
|
||||
<name>repo_gradle</name>
|
||||
<url>http://repo.gradle.org/gradle/libs-releases-local</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jdt</groupId>
|
||||
<artifactId>org.eclipse.jdt.core</artifactId>
|
||||
<version>3.12.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-tooling-api</artifactId>
|
||||
<version>4.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.7.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.sourcetrail.gradle;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintStream;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.gradle.tooling.BuildLauncher;
|
||||
import org.gradle.tooling.GradleConnector;
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
|
||||
public class InfoRetriever
|
||||
{
|
||||
public static String getMainSrcDirs(String projectRootPath, String initScriptPath)
|
||||
{
|
||||
String ret = "";
|
||||
|
||||
List<String> srcDirs = getSrcDirs("printMainSrcDirs", projectRootPath, initScriptPath);
|
||||
for (int i = 0; i < srcDirs.size(); i++)
|
||||
{
|
||||
if (i != 0)
|
||||
{
|
||||
ret += ";";
|
||||
}
|
||||
ret += srcDirs.get(i);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String getTestSrcDirs(String projectRootPath, String initScriptPath)
|
||||
{
|
||||
String ret = "";
|
||||
|
||||
List<String> srcDirs = getSrcDirs("printTestSrcDirs", projectRootPath, initScriptPath);
|
||||
for (int i = 0; i < srcDirs.size(); i++)
|
||||
{
|
||||
if (i != 0)
|
||||
{
|
||||
ret += ";";
|
||||
}
|
||||
ret += srcDirs.get(i);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void copyCompileLibs(String projectRootPath, String initScriptPath, String targetPath)
|
||||
{
|
||||
executeTask("copyCompileLibs", projectRootPath, initScriptPath, Arrays.asList("-Psourcetrail_lib_path=" + targetPath));
|
||||
}
|
||||
|
||||
public static void copyTestCompileLibs(String projectRootPath, String initScriptPath, String targetPath)
|
||||
{
|
||||
executeTask("copyTestCompileLibs", projectRootPath, initScriptPath, Arrays.asList("-Psourcetrail_lib_path=" + targetPath));
|
||||
}
|
||||
|
||||
private static List<String> getSrcDirs(String taskName, String projectRootPath, String initScriptPath)
|
||||
{
|
||||
String output = executeTask(taskName, projectRootPath, initScriptPath, null);
|
||||
|
||||
List<String> paths = new ArrayList<>();
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new StringReader(output)))
|
||||
{
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null)
|
||||
{
|
||||
paths.add(line);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// TODO: LOGERROR
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
private static String executeTask(String taskName, String projectRootPath, String initScriptPath, List<String> additionalArguments)
|
||||
{
|
||||
ProjectConnection connection = GradleConnector
|
||||
.newConnector()
|
||||
.forProjectDirectory(new File(projectRootPath))
|
||||
.connect();
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
|
||||
|
||||
try
|
||||
{
|
||||
List<String> arguments = new ArrayList<>();
|
||||
arguments.add("--init-script");
|
||||
arguments.add(initScriptPath);
|
||||
// arguments.add("-q");
|
||||
|
||||
if (additionalArguments != null)
|
||||
{
|
||||
arguments.addAll(additionalArguments);
|
||||
}
|
||||
|
||||
BuildLauncher Launcher = connection.newBuild().forTasks(taskName)
|
||||
.withArguments(arguments)
|
||||
.setStandardOutput(new PrintStream(outputStream))
|
||||
.setStandardError(new PrintStream(errorStream));
|
||||
|
||||
Launcher.run();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// TODO: LOGERROR
|
||||
}
|
||||
finally
|
||||
{
|
||||
connection.close();
|
||||
}
|
||||
|
||||
if (!errorStream.toString().isEmpty())
|
||||
{
|
||||
// TODO: handle this by sending the error to cpp
|
||||
System.out.println("Error: " + errorStream.toString()); // TODO: remove this later
|
||||
}
|
||||
|
||||
return outputStream.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user