-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Linked resource for .project works more reliably
- Loading branch information
1 parent
c7f6ac0
commit 711168f
Showing
23 changed files
with
141 additions
and
484 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
...e.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/FixDotProjectPathResourceListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.ls.core.internal; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.attribute.BasicFileAttributeView; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.time.Instant; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.eclipse.core.internal.events.ILifecycleListener; | ||
import org.eclipse.core.internal.events.LifecycleEvent; | ||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.resources.IProjectDescription; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.resources.IResourceChangeEvent; | ||
import org.eclipse.core.resources.IResourceChangeListener; | ||
import org.eclipse.core.resources.WorkspaceJob; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.ICoreRunnable; | ||
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager; | ||
|
||
public class FixDotProjectPathResourceListener implements IResourceChangeListener, ILifecycleListener { | ||
|
||
private Map<IProject, Instant> createdProjects = new HashMap<>(); | ||
|
||
@Override | ||
public void resourceChanged(IResourceChangeEvent event) { | ||
if (ProjectsManager.generatesMetadataFilesAtProjectRoot() || event.getDelta() == null) { | ||
return; | ||
} | ||
try { | ||
event.getDelta().accept(delta -> { | ||
if (delta.getResource() instanceof IProject project && // | ||
project.isOpen() && // | ||
createdProjects.containsKey(project)) { | ||
Instant projectCreation = createdProjects.remove(project); | ||
Path dotProjectOnDisk = project.getLocation().append(IProjectDescription.DESCRIPTION_FILE_NAME).toPath(); | ||
try { | ||
BasicFileAttributes attributes = Files.getFileAttributeView(dotProjectOnDisk, BasicFileAttributeView.class).readAttributes(); | ||
if (attributes.creationTime().toInstant().isAfter(projectCreation)) { | ||
// cannot link to resource in current workspace task, plan it next | ||
WorkspaceJob.createSystem("Use linked .project for " + project, (ICoreRunnable) (monitor -> { | ||
ProjectsManager.linkDotProject(project); | ||
ProjectsManager.linkResources(project); | ||
})).schedule(); | ||
} | ||
} catch (IOException ex) { | ||
JavaLanguageServerPlugin.logException(ex); | ||
} | ||
} | ||
return delta.getResource().getType() == IResource.ROOT; | ||
}); | ||
} catch (CoreException e) { | ||
JavaLanguageServerPlugin.logException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void handleEvent(LifecycleEvent event) throws CoreException { | ||
if (event.kind == LifecycleEvent.PRE_PROJECT_CREATE) { | ||
if (event.resource instanceof IProject project) { | ||
createdProjects.put(project, Instant.now()); | ||
} | ||
} else if (event.kind == LifecycleEvent.PRE_REFRESH) { | ||
unlinkIfLocal(event.resource); | ||
} | ||
} | ||
|
||
private void unlinkIfLocal(IResource resource) { | ||
if (resource instanceof IProject project && project.isOpen()) { | ||
try { | ||
Arrays.stream(project.members()) | ||
.filter(IFile.class::isInstance) | ||
.map(IFile.class::cast) | ||
.filter(IFile::isLinked) | ||
.filter(file -> file.getProject().getLocation().append(file.getProjectRelativePath()).toFile().isFile()) | ||
.forEach(file -> { | ||
try { | ||
file.delete(false, false, null); | ||
} catch (CoreException e) { | ||
JavaLanguageServerPlugin.logException(e); | ||
} | ||
}); | ||
} catch (CoreException e) { | ||
JavaLanguageServerPlugin.logException(e); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
org.eclipse.jdt.ls.filesystem/.settings/org.eclipse.core.resources.prefs
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
org.eclipse.jdt.ls.filesystem/.settings/org.eclipse.jdt.core.prefs
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
org.eclipse.jdt.ls.filesystem/.settings/org.eclipse.m2e.core.prefs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
....filesystem/src/org/eclipse/jdt/ls/core/internal/filesystem/JDTLSFilesystemActivator.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.