use of com.liferay.ide.gradle.core.parser.GradleDependencyUpdater in project liferay-ide by liferay.
the class QuickFixGradleDep method _createDepProposal.
private void _createDepProposal(IInvocationContext context, Collection<IJavaCompletionProposal> proposals, ServiceContainer bundle) {
String bundleGroup = bundle.getBundleGroup();
String bundleName = bundle.getBundleName();
String bundleVersion = bundle.getBundleVersion();
proposals.add(new CUCorrectionProposal("Add Gradle Dependence " + bundleName, context.getCompilationUnit(), null, -0) {
@Override
public void apply(IDocument document) {
try {
GradleDependencyUpdater updater = new GradleDependencyUpdater(_gradleFile.getLocation().toFile());
List<GradleDependency> existDependencies = updater.getAllDependencies();
GradleDependency gd = new GradleDependency(bundleGroup, bundleName, bundleVersion);
if (!existDependencies.contains(gd)) {
updater.insertDependency(gd);
File gradleFile = _gradleFile.getLocation().toFile();
Files.write(gradleFile.toPath(), updater.getGradleFileContents(), StandardCharsets.UTF_8);
IResource resource = context.getCompilationUnit().getResource();
IProject project = resource.getProject();
GradleUtil.refreshGradleProject(project);
}
} catch (Exception e) {
GradleCore.logError("Gradle dependence got error", e);
}
}
@Override
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
return "Add dependenece";
}
@Override
public Image getImage() {
Display display = UIUtil.getActiveShell().getDisplay();
String file = null;
try {
Bundle bundle = GradleUI.getDefault().getBundle();
file = FileLocator.toFileURL(bundle.getEntry("icons/e16/liferay_logo_16.png")).getFile();
} catch (IOException ioe) {
GradleUI.logError(ioe);
}
return new Image(display, file);
}
});
}
use of com.liferay.ide.gradle.core.parser.GradleDependencyUpdater in project liferay-ide by liferay.
the class GradleParseTests method getAllDependencies.
@Test
public void getAllDependencies() throws IOException {
final File inputFile = new File("projects/testParseInput/testDependencies.gradle");
GradleDependencyUpdater updater = new GradleDependencyUpdater(inputFile);
List<GradleDependency> allDependence = updater.getAllDependencies();
assertEquals(3, allDependence.size());
}
use of com.liferay.ide.gradle.core.parser.GradleDependencyUpdater in project liferay-ide by liferay.
the class GradleParseTests method addDependenceIntoEmptyBlock.
@Test
public void addDependenceIntoEmptyBlock() throws IOException {
final File inputFile = new File("projects/testParseInput/testParse2.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/testParse2.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 addDependenceWithoutDendendenceBlock.
@Test
public void addDependenceWithoutDendendenceBlock() throws IOException {
final File inputFile = new File("projects/testParseInput/testParse3.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(-1, dependenceLineNum);
Files.write(outputfile.toPath(), updater.getGradleFileContents(), StandardCharsets.UTF_8);
final File expectedOutputFile = new File("projects/testParseOutput/testParse3.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 addDependenceSkipComment.
@Test
public void addDependenceSkipComment() throws IOException {
final File inputFile = new File("projects/testParseInput/testParse.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(27, dependenceLineNum);
Files.write(outputfile.toPath(), updater.getGradleFileContents(), StandardCharsets.UTF_8);
final File expectedOutputFile = new File("projects/testParseOutput/testParse.gradle");
assertEquals(encoding(CoreUtil.readStreamToString(Files.newInputStream(expectedOutputFile.toPath()))), encoding(CoreUtil.readStreamToString(Files.newInputStream(outputfile.toPath()))));
}
Aggregations