Search in sources :

Example 1 with GradleDependency

use of com.liferay.ide.gradle.core.parser.GradleDependency 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());
}
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 2 with GradleDependency

use of com.liferay.ide.gradle.core.parser.GradleDependency 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());
}
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 3 with GradleDependency

use of com.liferay.ide.gradle.core.parser.GradleDependency 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;
}
Also used : GradleDependencyUpdater(com.liferay.ide.gradle.core.parser.GradleDependencyUpdater) IOException(java.io.IOException) GradleDependency(com.liferay.ide.gradle.core.parser.GradleDependency)

Example 4 with GradleDependency

use of com.liferay.ide.gradle.core.parser.GradleDependency 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 5 with GradleDependency

use of com.liferay.ide.gradle.core.parser.GradleDependency 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)

Aggregations

GradleDependency (com.liferay.ide.gradle.core.parser.GradleDependency)6 GradleDependencyUpdater (com.liferay.ide.gradle.core.parser.GradleDependencyUpdater)6 File (java.io.File)4 Test (org.junit.Test)4 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