Search in sources :

Example 1 with FeatureStatus

use of org.eclipse.jdt.ls.core.internal.preferences.Preferences.FeatureStatus in project eclipse.jdt.ls by eclipse.

the class StandardProjectsManager method fileChanged.

@Override
public void fileChanged(String uriString, CHANGE_TYPE changeType) {
    if (uriString == null) {
        return;
    }
    boolean configureNeeded = false;
    String formatterUrl = preferenceManager.getPreferences().getFormatterUrl();
    if (formatterUrl != null && JavaLanguageServerPlugin.getInstance().getProtocol() != null) {
        URI uri = JDTUtils.toURI(uriString);
        List<URI> uris = getURIs(formatterUrl);
        boolean changed = false;
        for (URI formatterUri : uris) {
            if (URIUtil.sameURI(formatterUri, uri)) {
                changed = true;
                break;
            }
        }
        if (changed) {
            if (changeType == CHANGE_TYPE.DELETED || changeType == CHANGE_TYPE.CREATED) {
                registerWatchers();
            }
            configureNeeded = true;
        }
    }
    String settingsUrl = preferenceManager.getPreferences().getSettingsUrl();
    if (settingsUrl != null && JavaLanguageServerPlugin.getInstance().getProtocol() != null) {
        URI uri = JDTUtils.toURI(uriString);
        List<URI> uris = getURIs(settingsUrl);
        boolean changed = false;
        for (URI settingsURI : uris) {
            if (URIUtil.sameURI(settingsURI, uri)) {
                changed = true;
                break;
            }
        }
        if (changed) {
            if (changeType == CHANGE_TYPE.DELETED || changeType == CHANGE_TYPE.CREATED) {
                registerWatchers();
            }
            configureNeeded = true;
        }
    }
    if (configureNeeded) {
        configureSettings(preferenceManager.getPreferences());
    }
    IResource resource = JDTUtils.getFileOrFolder(uriString);
    if (resource == null) {
        return;
    }
    try {
        Optional<IBuildSupport> bs = getBuildSupport(resource.getProject());
        if (bs.isPresent()) {
            IBuildSupport buildSupport = bs.get();
            if (JDTUtils.isExcludedFile(buildSupport.getExcludedFilePatterns(), uriString)) {
                return;
            }
            boolean requireConfigurationUpdate = buildSupport.fileChanged(resource, changeType, new NullProgressMonitor());
            if (requireConfigurationUpdate) {
                FeatureStatus status = preferenceManager.getPreferences().getUpdateBuildConfigurationStatus();
                switch(status) {
                    case automatic:
                        // do not force the build, because it's not started by user and should be done only if build file has changed
                        updateProject(resource.getProject(), false);
                        break;
                    case disabled:
                        break;
                    default:
                        if (client != null) {
                            String cmd = "java.projectConfiguration.status";
                            TextDocumentIdentifier uri = new TextDocumentIdentifier(uriString);
                            ActionableNotification updateProjectConfigurationNotification = new ActionableNotification().withSeverity(MessageType.Info).withMessage("A build file was modified. Do you want to synchronize the Java classpath/configuration?").withCommands(asList(new Command("Never", cmd, asList(uri, FeatureStatus.disabled)), new Command("Now", cmd, asList(uri, FeatureStatus.interactive)), new Command("Always", cmd, asList(uri, FeatureStatus.automatic))));
                            client.sendActionableNotification(updateProjectConfigurationNotification);
                        }
                }
            }
        }
    } catch (CoreException e) {
        JavaLanguageServerPlugin.logException("Problem refreshing workspace", e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) FeatureStatus(org.eclipse.jdt.ls.core.internal.preferences.Preferences.FeatureStatus) ActionableNotification(org.eclipse.jdt.ls.core.internal.ActionableNotification) URI(java.net.URI) CoreException(org.eclipse.core.runtime.CoreException) Command(org.eclipse.lsp4j.Command) IResource(org.eclipse.core.resources.IResource)

Example 2 with FeatureStatus

use of org.eclipse.jdt.ls.core.internal.preferences.Preferences.FeatureStatus in project eclipse.jdt.ls by eclipse.

the class ProjectsManager method fileChanged.

public void fileChanged(String uriString, CHANGE_TYPE changeType) {
    if (uriString == null) {
        return;
    }
    IResource resource = JDTUtils.findFile(uriString);
    if (resource == null) {
        return;
    }
    try {
        if (changeType == CHANGE_TYPE.DELETED) {
            resource = resource.getParent();
        }
        if (resource != null) {
            resource.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
        }
        if (isBuildFile(resource)) {
            FeatureStatus status = preferenceManager.getPreferences().getUpdateBuildConfigurationStatus();
            switch(status) {
                case automatic:
                    updateProject(resource.getProject());
                    break;
                case disabled:
                    break;
                default:
                    if (client != null) {
                        String cmd = "java.projectConfiguration.status";
                        TextDocumentIdentifier uri = new TextDocumentIdentifier(uriString);
                        ActionableNotification updateProjectConfigurationNotification = new ActionableNotification().withSeverity(MessageType.Info).withMessage("A build file was modified. Do you want to synchronize the Java classpath/configuration?").withCommands(asList(new Command("Never", cmd, asList(uri, FeatureStatus.disabled)), new Command("Now", cmd, asList(uri, FeatureStatus.interactive)), new Command("Always", cmd, asList(uri, FeatureStatus.automatic))));
                        client.sendActionableNotification(updateProjectConfigurationNotification);
                    }
            }
        }
    } catch (CoreException e) {
        JavaLanguageServerPlugin.logException("Problem refreshing workspace", e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CoreException(org.eclipse.core.runtime.CoreException) FeatureStatus(org.eclipse.jdt.ls.core.internal.preferences.Preferences.FeatureStatus) Command(org.eclipse.lsp4j.Command) ActionableNotification(org.eclipse.jdt.ls.core.internal.ActionableNotification) IResource(org.eclipse.core.resources.IResource)

Example 3 with FeatureStatus

use of org.eclipse.jdt.ls.core.internal.preferences.Preferences.FeatureStatus in project eclipse.jdt.ls by eclipse.

the class GradleProjectMetadataFileTest method testDeleteClasspath.

@Test
public void testDeleteClasspath() throws Exception {
    FeatureStatus status = preferenceManager.getPreferences().getUpdateBuildConfigurationStatus();
    try {
        preferenceManager.getPreferences().setUpdateBuildConfigurationStatus(FeatureStatus.automatic);
        IProject project = importSimpleJavaProject();
        assertIsJavaProject(project);
        assertIsGradleProject(project);
        IFile dotClasspath = project.getFile(IJavaProject.CLASSPATH_FILE_NAME);
        // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
        File file = FileUtil.toPath(dotClasspath.getLocationURI()).toFile();
        assertTrue(file.exists());
        file.delete();
        projectsManager.fileChanged(file.toPath().toUri().toString(), CHANGE_TYPE.DELETED);
        waitForBackgroundJobs();
        Job.getJobManager().join(CorePlugin.GRADLE_JOB_FAMILY, new NullProgressMonitor());
        project = WorkspaceHelper.getProject("simple-gradle");
        assertIsGradleProject(project);
        assertIsJavaProject(project);
        IFile bin = project.getFile("bin");
        assertFalse(bin.getRawLocation().toFile().exists());
        assertTrue(dotClasspath.exists());
    } finally {
        preferenceManager.getPreferences().setUpdateBuildConfigurationStatus(status);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) FeatureStatus(org.eclipse.jdt.ls.core.internal.preferences.Preferences.FeatureStatus) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test) AbstractGradleBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractGradleBasedTest)

Example 4 with FeatureStatus

use of org.eclipse.jdt.ls.core.internal.preferences.Preferences.FeatureStatus in project eclipse.jdt.ls by eclipse.

the class MavenBuildSupportTest method testUpdateSnapshots.

@Test
public void testUpdateSnapshots() throws Exception {
    boolean updateSnapshots = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().isMavenUpdateSnapshots();
    FeatureStatus status = preferenceManager.getPreferences().getUpdateBuildConfigurationStatus();
    try {
        IProject project = importMavenProject("salut3");
        waitForBackgroundJobs();
        IJavaProject javaProject = JavaCore.create(project);
        IType type = javaProject.findType("org.apache.commons.lang3.StringUtils");
        assertNull(type);
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setMavenUpdateSnapshots(false);
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setUpdateBuildConfigurationStatus(FeatureStatus.automatic);
        IFile pom = project.getFile("pom.xml");
        String content = ResourceUtils.getContent(pom);
        // @formatter:off
        content = content.replace("<dependencies></dependencies>", "<dependencies>\n" + "<dependency>\n" + "   <groupId>org.apache.commons</groupId>\n" + "   <artifactId>commons-lang3</artifactId>\n" + "   <version>3.9</version>\n" + "</dependency>" + "</dependencies>");
        // @formatter:on
        ResourceUtils.setContent(pom, content);
        URI uri = pom.getRawLocationURI();
        projectsManager.fileChanged(uri.toString(), CHANGE_TYPE.CHANGED);
        waitForBackgroundJobs();
        type = javaProject.findType("org.apache.commons.lang3.StringUtils");
        assertNotNull(type);
    } finally {
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setMavenUpdateSnapshots(updateSnapshots);
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setUpdateBuildConfigurationStatus(status);
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) FeatureStatus(org.eclipse.jdt.ls.core.internal.preferences.Preferences.FeatureStatus) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Aggregations

FeatureStatus (org.eclipse.jdt.ls.core.internal.preferences.Preferences.FeatureStatus)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 URI (java.net.URI)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 ActionableNotification (org.eclipse.jdt.ls.core.internal.ActionableNotification)2 Command (org.eclipse.lsp4j.Command)2 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)2 Test (org.junit.Test)2 File (java.io.File)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IType (org.eclipse.jdt.core.IType)1 AbstractGradleBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractGradleBasedTest)1