use of com.liferay.ide.gradle.core.parser.GradleDependencyUpdater in project liferay-ide by liferay.
the class GradleParseTests method getAllDependenciesShortFormatAndLongFormat.
@Test
public void getAllDependenciesShortFormatAndLongFormat() throws IOException {
final File inputFile = new File("projects/testParseInput/testDependenciesShortFormatAndLongFormat.gradle");
GradleDependencyUpdater updater = new GradleDependencyUpdater(inputFile);
List<GradleDependency> allDependencies = updater.getAllDependencies();
assertEquals(3, allDependencies.size());
}
use of com.liferay.ide.gradle.core.parser.GradleDependencyUpdater in project liferay-ide by liferay.
the class GradleParseTests method addDependenceInClosureLine.
@Test
public void addDependenceInClosureLine() throws IOException {
final File inputFile = new File("projects/testParseInput/testParse5.gradle");
GradleDependencyUpdater updater = new GradleDependencyUpdater(inputFile);
FindDependenciesVisitor visitor = updater.insertDependency("\tcompile group: \"com.liferay\", name:\"com.liferay.bookmarks.api\", version:\"1.0.0\"");
int dependenceLineNum = visitor.getDependenceLineNum();
assertEquals(24, dependenceLineNum);
Files.write(outputfile.toPath(), updater.getGradleFileContents(), StandardCharsets.UTF_8);
final File expectedOutputFile = new File("projects/testParseOutput/testParse5.gradle");
assertEquals(encoding(CoreUtil.readStreamToString(Files.newInputStream(expectedOutputFile.toPath()))), encoding(CoreUtil.readStreamToString(Files.newInputStream(outputfile.toPath()))));
}
use of com.liferay.ide.gradle.core.parser.GradleDependencyUpdater in project liferay-ide by liferay.
the class GradleParseTests method getAllDependenciesShortFormat.
@Test
public void getAllDependenciesShortFormat() throws IOException {
final File inputFile = new File("projects/testParseInput/testDependenciesShortFormat.gradle");
GradleDependencyUpdater updater = new GradleDependencyUpdater(inputFile);
List<GradleDependency> allDependencies = updater.getAllDependencies();
assertEquals(3, allDependencies.size());
}
use of com.liferay.ide.gradle.core.parser.GradleDependencyUpdater in project liferay-ide by liferay.
the class GradleParseTests method addDependenceInSameLine.
@Test
public void addDependenceInSameLine() throws IOException {
final File inputFile = new File("projects/testParseInput/testParse4.gradle");
GradleDependencyUpdater updater = new GradleDependencyUpdater(inputFile);
FindDependenciesVisitor visitor = updater.insertDependency("\tcompile group: \"com.liferay\", name:\"com.liferay.bookmarks.api\", version:\"1.0.0\"");
int dependenceLineNum = visitor.getDependenceLineNum();
assertEquals(23, dependenceLineNum);
Files.write(outputfile.toPath(), updater.getGradleFileContents(), StandardCharsets.UTF_8);
final File expectedOutputFile = new File("projects/testParseOutput/testParse4.gradle");
assertEquals(encoding(CoreUtil.readStreamToString(Files.newInputStream(expectedOutputFile.toPath()))), encoding(CoreUtil.readStreamToString(Files.newInputStream(outputfile.toPath()))));
}
use of com.liferay.ide.gradle.core.parser.GradleDependencyUpdater in project liferay-ide by liferay.
the class GradleProjectBuilder method updateProjectDependency.
@Override
public IStatus updateProjectDependency(IProject project, List<String[]> dependencies) throws CoreException {
if (FileUtil.notExists(_gradleBuildFile)) {
return Status.OK_STATUS;
}
try {
GradleDependencyUpdater updater = new GradleDependencyUpdater(FileUtil.getFile(_gradleBuildFile));
List<GradleDependency> existDependencies = updater.getAllDependencies();
for (String[] dependency : dependencies) {
GradleDependency gd = new GradleDependency(dependency[0], dependency[1], dependency[2]);
if (!existDependencies.contains(gd)) {
updater.insertDependency(gd);
FileUtils.writeLines(_gradleBuildFile.getLocation().toFile(), updater.getGradleFileContents());
GradleUtil.refreshGradleProject(project);
}
}
} catch (IOException ioe) {
return GradleCore.createErrorStatus("Error updating gradle project dependency", ioe);
}
return Status.OK_STATUS;
}
Aggregations