Skip to content

Commit

Permalink
Reopening a gradle project resets its gradle version
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza committed Jul 17, 2019
1 parent febf189 commit 65c4cd8
Show file tree
Hide file tree
Showing 18 changed files with 775 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Deque;
import java.util.List;

import org.eclipse.buildship.core.internal.CorePlugin;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
Expand Down Expand Up @@ -195,7 +196,7 @@ static class BuildJobMatcher implements IJobMatcher {
@Override
public boolean matches(Job job) {
return (job instanceof WorkspaceJob) || job.getClass().getName().matches("(.*\\.AutoBuild.*)")
|| job.getClass().getName().endsWith("JREUpdateJob");
|| job.getClass().getName().endsWith("JREUpdateJob") || job.belongsTo(CorePlugin.GRADLE_JOB_FAMILY);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
Expand Down Expand Up @@ -368,5 +369,13 @@ private static IPath detectSources(Path file) {
return Files.isRegularFile(sourcePath) ? new org.eclipse.core.runtime.Path(sourcePath.toString()) : null;
}


public static IProject findUniqueProject(IWorkspace workspace, String basename) {
IProject project = null;
String name;
for (int i = 1; project == null || project.exists(); i++) {
name = (i < 2) ? basename : basename + " (" + i + ")";
project = workspace.getRoot().getProject(name);
}
return project;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ public static String getContent(URI fileURI) throws CoreException {
return content;
}

/**
* Reads file content directly from the filesystem.
*/
public static String getContent(File file) throws CoreException {
if (file == null) {
return null;
}
String content;
try {
content = Files.toString(file, Charsets.UTF_8);
} catch (IOException e) {
throw new CoreException(StatusFactory.newErrorStatus("Can not get " + file + " content", e));
}
return content;
}

/**
* Writes content to file, outside the workspace. No change event is
* emitted.
Expand Down Expand Up @@ -263,4 +279,16 @@ public static String toGlobPattern(IPath path) {
return globPattern;
}

public static IPath fixDevice(IPath path) {
if (path != null && path.getDevice() != null) {
return path.setDevice(path.getDevice().toUpperCase());
}
if (Platform.OS_WIN32.equals(Platform.getOS()) && path != null && path.toString().startsWith("//")) {
String server = path.segment(0);
String pathStr = path.toString().replace(server, server.toUpperCase());
return new Path(pathStr);
}
return path;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ls.core.internal.AbstractProjectImporter;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.jdt.ls.core.internal.ResourceUtils;

public class EclipseProjectImporter extends AbstractProjectImporter {

Expand Down Expand Up @@ -78,14 +79,14 @@ private void importDir(java.nio.file.Path dir, IProgressMonitor m) {
IProject project = workspace.getRoot().getProject(name);
if (project.exists()) {
IPath existingProjectPath = project.getLocation();
existingProjectPath = fixDevice(existingProjectPath);
dotProjectPath = fixDevice(dotProjectPath);
existingProjectPath = ResourceUtils.fixDevice(existingProjectPath);
dotProjectPath = ResourceUtils.fixDevice(dotProjectPath);
if (existingProjectPath.equals(dotProjectPath.removeLastSegments(1))) {
project.open(IResource.NONE, monitor.newChild(1));
project.refreshLocal(IResource.DEPTH_INFINITE, monitor.newChild(1));
return;
} else {
project = findUniqueProject(workspace, name);
project = ProjectUtils.findUniqueProject(workspace, name);
descriptor.setName(project.getName());
}
}
Expand All @@ -99,27 +100,4 @@ private void importDir(java.nio.file.Path dir, IProgressMonitor m) {
}
}

private IPath fixDevice(IPath path) {
if (path != null && path.getDevice() != null) {
return path.setDevice(path.getDevice().toUpperCase());
}
if (Platform.OS_WIN32.equals(Platform.getOS()) && path != null && path.toString().startsWith("//")) {
String server = path.segment(0);
String pathStr = path.toString().replace(server, server.toUpperCase());
return new Path(pathStr);
}
return path;
}

//XXX should be package protected. Temporary fix (ahaha!) until test fragment can work in tycho builds
public IProject findUniqueProject(IWorkspace workspace, String basename) {
IProject project = null;
String name;
for (int i = 1; project == null || project.exists(); i++) {
name = (i < 2)? basename:basename + " ("+ i +")";
project = workspace.getRoot().getProject(name);
}
return project;
}

}
Loading

0 comments on commit 65c4cd8

Please sign in to comment.