Search in sources :

Example 6 with GradleDependencyUpdater

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);
        }
    });
}
Also used : GradleDependencyUpdater(com.liferay.ide.gradle.core.parser.GradleDependencyUpdater) Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) IProject(org.eclipse.core.resources.IProject) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CUCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal) ArrayList(java.util.ArrayList) List(java.util.List) GradleDependency(com.liferay.ide.gradle.core.parser.GradleDependency) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IDocument(org.eclipse.jface.text.IDocument) IResource(org.eclipse.core.resources.IResource) Display(org.eclipse.swt.widgets.Display)

Example 7 with GradleDependencyUpdater

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());
}
Also used : GradleDependencyUpdater(com.liferay.ide.gradle.core.parser.GradleDependencyUpdater) GradleDependency(com.liferay.ide.gradle.core.parser.GradleDependency) File(java.io.File) Test(org.junit.Test)

Example 8 with GradleDependencyUpdater

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()))));
}
Also used : GradleDependencyUpdater(com.liferay.ide.gradle.core.parser.GradleDependencyUpdater) FindDependenciesVisitor(com.liferay.ide.gradle.core.parser.FindDependenciesVisitor) File(java.io.File) Test(org.junit.Test)

Example 9 with GradleDependencyUpdater

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()))));
}
Also used : GradleDependencyUpdater(com.liferay.ide.gradle.core.parser.GradleDependencyUpdater) FindDependenciesVisitor(com.liferay.ide.gradle.core.parser.FindDependenciesVisitor) File(java.io.File) Test(org.junit.Test)

Example 10 with GradleDependencyUpdater

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()))));
}
Also used : GradleDependencyUpdater(com.liferay.ide.gradle.core.parser.GradleDependencyUpdater) FindDependenciesVisitor(com.liferay.ide.gradle.core.parser.FindDependenciesVisitor) File(java.io.File) Test(org.junit.Test)

Aggregations

GradleDependencyUpdater (com.liferay.ide.gradle.core.parser.GradleDependencyUpdater)11 File (java.io.File)9 Test (org.junit.Test)9 GradleDependency (com.liferay.ide.gradle.core.parser.GradleDependency)6 FindDependenciesVisitor (com.liferay.ide.gradle.core.parser.FindDependenciesVisitor)5 IOException (java.io.IOException)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 LiferayGradleProject (com.liferay.ide.gradle.core.LiferayGradleProject)1 IProjectBuilder (com.liferay.ide.project.core.IProjectBuilder)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IResource (org.eclipse.core.resources.IResource)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)1 IDocument (org.eclipse.jface.text.IDocument)1 Image (org.eclipse.swt.graphics.Image)1 Display (org.eclipse.swt.widgets.Display)1 Bundle (org.osgi.framework.Bundle)1