Search in sources :

Example 1 with BuildConfiguration

use of org.eclipse.buildship.core.BuildConfiguration in project eclipse.jdt.ls by eclipse.

the class GradleProjectImporterTest method testGradleJvmArguments.

@Test
public void testGradleJvmArguments() {
    List<String> jvmArguments = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getGradleJvmArguments();
    try {
        Path rootPath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().toPath();
        BuildConfiguration build = GradleProjectImporter.getBuildConfiguration(rootPath);
        assertTrue(build.getJvmArguments().isEmpty());
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleJvmArguments(ImmutableList.of("-Djavax.net.ssl.trustStore=truststore.jks"));
        build = GradleProjectImporter.getBuildConfiguration(rootPath);
        assertEquals(1, build.getJvmArguments().size());
        assertTrue(build.getJvmArguments().contains("-Djavax.net.ssl.trustStore=truststore.jks"));
    } finally {
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleJvmArguments(jvmArguments);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(java.nio.file.Path) BuildConfiguration(org.eclipse.buildship.core.BuildConfiguration) Test(org.junit.Test)

Example 2 with BuildConfiguration

use of org.eclipse.buildship.core.BuildConfiguration in project eclipse.jdt.ls by eclipse.

the class GradleProjectImporterTest method testGradleOfflineMode.

@Test
public void testGradleOfflineMode() {
    boolean offlineMode = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().isImportGradleOfflineEnabled();
    try {
        Path rootPath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().toPath();
        BuildConfiguration build = GradleProjectImporter.getBuildConfiguration(rootPath);
        assertFalse(build.isOfflineMode());
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setImportGradleOfflineEnabled(true);
        build = GradleProjectImporter.getBuildConfiguration(rootPath);
        assertTrue(build.isOfflineMode());
    } finally {
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setImportGradleOfflineEnabled(offlineMode);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(java.nio.file.Path) BuildConfiguration(org.eclipse.buildship.core.BuildConfiguration) Test(org.junit.Test)

Example 3 with BuildConfiguration

use of org.eclipse.buildship.core.BuildConfiguration in project eclipse.jdt.ls by eclipse.

the class GradleProjectImporterTest method testGradleArguments.

@Test
public void testGradleArguments() {
    List<String> arguments = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getGradleArguments();
    try {
        Path rootPath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().toPath();
        BuildConfiguration build = GradleProjectImporter.getBuildConfiguration(rootPath);
        assertTrue(build.getArguments().isEmpty());
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleArguments(ImmutableList.of("-Pproperty=value", "--stacktrace"));
        build = GradleProjectImporter.getBuildConfiguration(rootPath);
        assertEquals(2, build.getArguments().size());
        assertTrue(build.getArguments().contains("-Pproperty=value"));
        assertTrue(build.getArguments().contains("--stacktrace"));
    } finally {
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleArguments(arguments);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(java.nio.file.Path) BuildConfiguration(org.eclipse.buildship.core.BuildConfiguration) Test(org.junit.Test)

Example 4 with BuildConfiguration

use of org.eclipse.buildship.core.BuildConfiguration in project eclipse.jdt.ls by eclipse.

the class GradleProjectImporter method getBuildConfiguration.

public static BuildConfiguration getBuildConfiguration(Path rootFolder) {
    GradleDistribution distribution = getGradleDistribution(rootFolder);
    Preferences preferences = getPreferences();
    File javaHome = getJavaHome(preferences);
    File gradleUserHome = getGradleUserHomeFile();
    List<String> gradleArguments = preferences.getGradleArguments();
    List<String> gradleJvmArguments = preferences.getGradleJvmArguments();
    boolean offlineMode = preferences.isImportGradleOfflineEnabled();
    boolean overrideWorkspaceConfiguration = !(distribution instanceof WrapperGradleDistribution) || offlineMode || (gradleArguments != null && !gradleArguments.isEmpty()) || (gradleJvmArguments != null && !gradleJvmArguments.isEmpty()) || gradleUserHome != null || javaHome != null;
    // @formatter:off
    BuildConfiguration build = BuildConfiguration.forRootProjectDirectory(rootFolder.toFile()).overrideWorkspaceConfiguration(overrideWorkspaceConfiguration).gradleDistribution(distribution).javaHome(javaHome).arguments(gradleArguments).gradleUserHome(gradleUserHome).jvmArguments(gradleJvmArguments).offlineMode(offlineMode).build();
    // @formatter:on
    return build;
}
Also used : GradleDistribution(org.eclipse.buildship.core.GradleDistribution) WrapperGradleDistribution(org.eclipse.buildship.core.WrapperGradleDistribution) BuildConfiguration(org.eclipse.buildship.core.BuildConfiguration) WrapperGradleDistribution(org.eclipse.buildship.core.WrapperGradleDistribution) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) File(java.io.File)

Example 5 with BuildConfiguration

use of org.eclipse.buildship.core.BuildConfiguration in project eclipse.jdt.ls by eclipse.

the class GradleBuildSupport method update.

@Override
public void update(IProject project, boolean force, IProgressMonitor monitor) throws CoreException {
    if (!applies(project)) {
        return;
    }
    JavaLanguageServerPlugin.logInfo("Starting Gradle update for " + project.getName());
    Optional<GradleBuild> build = GradleCore.getWorkspace().getBuild(project);
    if (build.isPresent()) {
        GradleBuild gradleBuild = build.get();
        boolean isRoot = isRoot(project, gradleBuild, monitor);
        if (force && isRoot) {
            String projectPath = project.getLocation().toFile().getAbsolutePath();
            BuildConfiguration buildConfiguration = GradleProjectImporter.getBuildConfiguration(Paths.get(projectPath));
            gradleBuild = GradleCore.getWorkspace().createBuild(buildConfiguration);
        }
        File buildFile = project.getFile(GradleProjectImporter.BUILD_GRADLE_DESCRIPTOR).getLocation().toFile();
        File settingsFile = project.getFile(GradleProjectImporter.SETTINGS_GRADLE_DESCRIPTOR).getLocation().toFile();
        File buildKtsFile = project.getFile(GradleProjectImporter.BUILD_GRADLE_KTS_DESCRIPTOR).getLocation().toFile();
        File settingsKtsFile = project.getFile(GradleProjectImporter.SETTINGS_GRADLE_KTS_DESCRIPTOR).getLocation().toFile();
        boolean shouldUpdate = (buildFile.exists() && JavaLanguageServerPlugin.getDigestStore().updateDigest(buildFile.toPath())) || (settingsFile.exists() && JavaLanguageServerPlugin.getDigestStore().updateDigest(settingsFile.toPath())) || (buildKtsFile.exists() && JavaLanguageServerPlugin.getDigestStore().updateDigest(buildKtsFile.toPath())) || (settingsKtsFile.exists() && JavaLanguageServerPlugin.getDigestStore().updateDigest(settingsKtsFile.toPath()));
        if (isRoot || shouldUpdate) {
            gradleBuild.synchronize(monitor);
        }
    }
}
Also used : BuildConfiguration(org.eclipse.buildship.core.BuildConfiguration) File(java.io.File) InternalGradleBuild(org.eclipse.buildship.core.internal.workspace.InternalGradleBuild) GradleBuild(org.eclipse.buildship.core.GradleBuild)

Aggregations

BuildConfiguration (org.eclipse.buildship.core.BuildConfiguration)10 File (java.io.File)7 IPath (org.eclipse.core.runtime.IPath)7 Test (org.junit.Test)6 Path (java.nio.file.Path)5 GradleBuild (org.eclipse.buildship.core.GradleBuild)3 IFile (org.eclipse.core.resources.IFile)3 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)3 Preferences (org.eclipse.jdt.ls.core.internal.preferences.Preferences)3 IOException (java.io.IOException)2 Properties (java.util.Properties)2 CoreException (org.eclipse.core.runtime.CoreException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 IVMInstall (org.eclipse.jdt.launching.IVMInstall)2 IVMInstallType (org.eclipse.jdt.launching.IVMInstallType)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1 GradleDistribution (org.eclipse.buildship.core.GradleDistribution)1 SynchronizationResult (org.eclipse.buildship.core.SynchronizationResult)1