Skip to content

Commit

Permalink
Migrate to Buildship 3.0
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza committed Dec 4, 2018
1 parent 6c3e029 commit 55af926
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 39 deletions.
4 changes: 0 additions & 4 deletions org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0",
org.eclipse.core.filebuffers;bundle-version="3.6.0",
org.eclipse.m2e.maven.runtime,
org.eclipse.buildship.core;bundle-version="1.0.18",
com.gradleware.tooling.client;bundle-version="0.14.0",
com.gradleware.tooling.model;bundle-version="0.14.0",
com.gradleware.tooling.utils;bundle-version="0.14.0",
org.gradle.toolingapi,
org.eclipse.jdt.launching,
org.eclipse.jdt.core.manipulation;bundle-version="1.8.0",
org.apache.log4j;bundle-version="1.2.15",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.buildship.core.configuration.GradleProjectNature;
import org.eclipse.buildship.core.internal.configuration.GradleProjectNature;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
package org.eclipse.jdt.ls.core.internal.managers;

import java.io.File;
import java.util.Optional;

import org.eclipse.buildship.core.CorePlugin;
import org.eclipse.buildship.core.util.file.FileUtils;
import org.eclipse.buildship.core.workspace.GradleBuild;
import org.eclipse.buildship.core.workspace.NewProjectHandler;
import org.eclipse.buildship.core.workspace.WorkbenchShutdownEvent;
import org.eclipse.buildship.core.GradleBuild;
import org.eclipse.buildship.core.internal.CorePlugin;
import org.eclipse.buildship.core.internal.util.file.FileUtils;
import org.eclipse.buildship.core.internal.workspace.DefaultGradleWorkspace;
import org.eclipse.buildship.core.internal.workspace.WorkbenchShutdownEvent;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
Expand All @@ -29,8 +30,6 @@
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;

import com.google.common.base.Optional;

/**
* @author Fred Bricon
*
Expand All @@ -50,9 +49,10 @@ public void update(IProject project, boolean force, IProgressMonitor monitor) th
return;
}
JavaLanguageServerPlugin.logInfo("Starting Gradle update for "+project.getName());
Optional<GradleBuild> build = CorePlugin.gradleWorkspaceManager().getGradleBuild(project);
if (build.isPresent()){
build.get().synchronize(NewProjectHandler.IMPORT_AND_MERGE);
DefaultGradleWorkspace gradleWorkspace = (DefaultGradleWorkspace) CorePlugin.internalGradleWorkspace();
Optional<GradleBuild> build = gradleWorkspace.getBuild(project);
if (build.isPresent()) {
build.get().synchronize(monitor);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
import java.util.Map;
import java.util.Properties;

import org.eclipse.buildship.core.CorePlugin;
import org.eclipse.buildship.core.configuration.BuildConfiguration;
import org.eclipse.buildship.core.preferences.PersistentModel;
import org.eclipse.buildship.core.util.gradle.GradleDistributionWrapper;
import org.eclipse.buildship.core.util.gradle.GradleDistributionWrapper.DistributionType;
import org.eclipse.buildship.core.workspace.GradleBuild;
import org.eclipse.buildship.core.workspace.NewProjectHandler;
import org.eclipse.buildship.core.BuildConfiguration;
import org.eclipse.buildship.core.GradleCore;
import org.eclipse.buildship.core.GradleDistribution;
import org.eclipse.buildship.core.SynchronizationResult;
import org.eclipse.buildship.core.internal.CorePlugin;
import org.eclipse.buildship.core.internal.preferences.PersistentModel;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
Expand All @@ -34,10 +33,6 @@
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager;
import org.gradle.tooling.GradleConnector;

import com.gradleware.tooling.toolingclient.GradleDistribution;
import com.gradleware.tooling.toolingmodel.repository.FetchStrategy;

/**
* @author Fred Bricon
Expand Down Expand Up @@ -85,9 +80,10 @@ public void importToWorkspace(IProgressMonitor monitor) throws CoreException {
return;
}
int projectSize = directories.size();
SubMonitor subMonitor = SubMonitor.convert(monitor, projectSize);
SubMonitor subMonitor = SubMonitor.convert(monitor, projectSize + 1);
subMonitor.setTaskName(IMPORTING_GRADLE_PROJECTS);
JavaLanguageServerPlugin.logInfo(IMPORTING_GRADLE_PROJECTS);
subMonitor.worked(1);
directories.forEach(d -> importDir(d, subMonitor.newChild(1)));
subMonitor.done();
}
Expand All @@ -102,7 +98,7 @@ private void importDir(Path rootFolder, IProgressMonitor monitor) {
public static GradleDistribution getGradleDistribution(Path rootFolder) {
GradleDistribution distribution = DEFAULT_DISTRIBUTION;
if (Files.exists(rootFolder.resolve("gradlew"))) {
distribution = GradleDistributionWrapper.from(DistributionType.WRAPPER, null).toGradleDistribution();
distribution = GradleDistribution.fromBuild();
} else {
File gradleHomeFile = getGradleHomeFile();
if (gradleHomeFile != null) {
Expand Down Expand Up @@ -145,12 +141,23 @@ protected void startSynchronization(Path rootFolder, IProgressMonitor monitor) {
}
}
if (shouldSynchronize) {
boolean overrideWorkspaceSettings = getGradleHomeFile() != null;
File gradleUserHome = getGradleHomeFile();
boolean overrideWorkspaceConfiguration = gradleUserHome != null;
GradleDistribution distribution = getGradleDistribution(rootFolder);
BuildConfiguration configuration = CorePlugin.configurationManager().createBuildConfiguration(location, overrideWorkspaceSettings, distribution, null, false, false, false);
GradleBuild build = CorePlugin.gradleWorkspaceManager().getGradleBuild(configuration);
build.getModelProvider().fetchEclipseGradleProjects(FetchStrategy.LOAD_IF_NOT_CACHED, GradleConnector.newCancellationTokenSource().token(), monitor);
build.synchronize(NewProjectHandler.IMPORT_AND_MERGE);
String javaHomeStr = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getJavaHome();
File javaHome = javaHomeStr == null ? null : new File(javaHomeStr);
// @formatter:off
BuildConfiguration build = BuildConfiguration.forRootProjectDirectory(location)
.overrideWorkspaceConfiguration(overrideWorkspaceConfiguration)
.gradleDistribution(distribution)
.javaHome(javaHome)
.gradleUserHome(gradleUserHome)
.build();
// @formatter:on
SynchronizationResult result = GradleCore.getWorkspace().createBuild(build).synchronize(monitor);
if (!result.getStatus().isOK()) {
JavaLanguageServerPlugin.log(result.getStatus());
}
}
}

Expand Down
9 changes: 4 additions & 5 deletions org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?><target name="Java Language Server Target Definition" sequenceNumber="113">
<?xml version="1.0" encoding="UTF-8" standalone="no"?><?pde version="3.8"?><target name="Java Language Server Target Definition" sequenceNumber="113">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.mockito.mockito-all" version="1.9.5"/>
Expand All @@ -15,8 +14,8 @@
<repository location="http://download.eclipse.org/tools/orbit/R-builds/R20170516192513/repository"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.buildship.feature.group" version="2.2.2.v20181003-1021"/>
<repository location="https://download.eclipse.org/buildship/updates/e47/releases/2.x/2.2.2.v20181003-1021/"/>
<unit id="org.eclipse.buildship.feature.group" version="0.0.0"/>
<repository location="https://download.eclipse.org/buildship/updates/e49/snapshots/3.x/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.m2e.feature.feature.group" version="1.10.0.20181127-2120"/>
Expand Down Expand Up @@ -47,4 +46,4 @@
</location>
</locations>
<targetJRE path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
</target>
</target>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Map;
import java.util.Properties;

import org.eclipse.buildship.core.CorePlugin;
import org.eclipse.buildship.core.internal.CorePlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
Expand Down

0 comments on commit 55af926

Please sign in to comment.