Search in sources :

Example 1 with GradleDependencyUpdater

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());
}
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 GradleDependencyUpdater

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()))));
}
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 3 with GradleDependencyUpdater

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());
}
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 4 with GradleDependencyUpdater

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()))));
}
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 5 with GradleDependencyUpdater

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

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