Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for RunPlainJavaProjectTest test #11133

Merged
merged 4 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
*/
@Singleton
public class ClasspathMacro implements Macro {

private static final String KEY = "${project.java.classpath}";

private final ClasspathContainer classpathContainer;
Expand Down Expand Up @@ -99,7 +98,7 @@ public Promise<String> expand() {
Set<String> libs = classpathResolver.getLibs();
StringBuilder classpath = new StringBuilder();
for (String lib : libs) {
classpath.append(lib).append(':');
classpath.append(appContext.getProjectsRoot()).append(lib).append(':');
}

for (ClasspathEntry container : classpathResolver.getContainers()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import static org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject;
import static org.eclipse.che.ide.ext.java.shared.Constants.OUTPUT_FOLDER;

import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.api.promises.client.Promise;
Expand Down Expand Up @@ -66,28 +65,22 @@ public Promise<String> expand() {
if (resources != null && resources.length == 1) {

final Resource resource = resources[0];
final Optional<Project> project = resource.getRelatedProject();
Project project = resource.getProject();

if (!project.isPresent()) {
if (!project.exists() || !isJavaProject(project)) {
return promises.resolve("");
}

Project relatedProject = project.get();

if (!isJavaProject(relatedProject)) {
return promises.resolve("");
}

if (relatedProject.getAttributes().containsKey(OUTPUT_FOLDER)) {
if (project.getAttributes().containsKey(OUTPUT_FOLDER)) {
return promises.resolve(
appContext
.getProjectsRoot()
.append(relatedProject.getLocation())
.append(relatedProject.getAttributes().get(OUTPUT_FOLDER).get(0))
.append(project.getLocation())
.append(project.getAttributes().get(OUTPUT_FOLDER).get(0))
.toString());
} else {
return promises.resolve(
appContext.getProjectsRoot().append(relatedProject.getLocation()).toString());
appContext.getProjectsRoot().append(project.getLocation()).toString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public final class Constants {
public static final String CONTAINS_JAVA_FILES = "containsJavaFiles";
public static final String SOURCE_FOLDER = "java.source.folder";
public static final String OUTPUT_FOLDER = "java.output.folder";
public static final String DEFAULT_OUTPUT_FOLDER_VALUE = "bin";

public static final String JAVAC = "javac";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@
*/
package org.eclipse.che.plugin.java.plain.server.projecttype;

import static com.google.common.base.Strings.isNullOrEmpty;
import static org.eclipse.che.api.fs.server.WsPathUtils.absolutize;
import static org.eclipse.che.ide.ext.java.shared.Constants.JAVAC;
import static org.eclipse.che.plugin.java.plain.shared.PlainJavaProjectConstants.LIBRARY_FOLDER;

import com.google.inject.Inject;
import com.google.inject.Provider;
import java.util.List;
import org.eclipse.che.api.core.ConflictException;
import org.eclipse.che.api.core.ForbiddenException;
import org.eclipse.che.api.core.NotFoundException;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.core.model.workspace.config.ProjectConfig;
import org.eclipse.che.api.project.server.ProjectManager;
import org.eclipse.che.api.project.server.handlers.ProjectInitHandler;
import org.eclipse.che.plugin.java.languageserver.JavaLanguageServerExtensionService;
import org.eclipse.che.plugin.java.languageserver.JavaLanguageServerLauncher;

/**
* Init handler for simple java project.
Expand All @@ -26,12 +36,44 @@
* @author Valeriy Svydenko
*/
public class PlainJavaInitHandler implements ProjectInitHandler {
private final Provider<JavaLanguageServerExtensionService> extensionService;
private final Provider<JavaLanguageServerLauncher> languageServerLauncher;
private final Provider<ProjectManager> projectRegistryProvider;

@Inject
public PlainJavaInitHandler(
Provider<JavaLanguageServerExtensionService> extensionService,
Provider<JavaLanguageServerLauncher> languageServerLauncher,
Provider<ProjectManager> projectRegistryProvider) {
this.extensionService = extensionService;
this.languageServerLauncher = languageServerLauncher;
this.projectRegistryProvider = projectRegistryProvider;
}

@Override
public String getProjectType() {
return JAVAC;
}

@Override
public void onProjectInitialized(String projectFolder)
throws ServerException, ForbiddenException, ConflictException, NotFoundException {}
throws ServerException, ForbiddenException, ConflictException, NotFoundException {
if (!languageServerLauncher.get().isStarted()) {
return;
}
String wsPath = absolutize(projectFolder);
ProjectConfig project =
projectRegistryProvider
.get()
.get(wsPath)
.orElseThrow(() -> new ServerException("Can't find a project: " + wsPath));

List<String> library = project.getAttributes().get(LIBRARY_FOLDER);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this property is set, shouldn't the classpath have been updated before? I'm not sure why we need this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code executes when the property was set and if this property exists we need to update classpath to add jars from this folder.

if (library != null && !library.isEmpty()) {
String libraryFolder = library.get(0);
if (!isNullOrEmpty(libraryFolder)) {
extensionService.get().addJars(project.getPath(), libraryFolder);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static CompletableFuture<Object> updateProjectConfig(
NewProjectConfig projectConfig =
new NewProjectConfigImpl(
projectWsPath, project.getName(), project.getType(), project.getSource());
projectConfig.setAttributes(project.getAttributes());
RegisteredProject result = projectManager.update(projectConfig);
return CompletableFuture.completedFuture(result.getPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
package org.eclipse.che.plugin.java.plain.server.projecttype;

import static com.google.common.base.Strings.isNullOrEmpty;
import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -38,6 +39,7 @@
import org.eclipse.che.api.project.server.type.ValueProvider;
import org.eclipse.che.api.project.server.type.ValueProviderFactory;
import org.eclipse.che.api.project.server.type.ValueStorageException;
import org.eclipse.che.ide.ext.java.shared.Constants;
import org.eclipse.che.plugin.java.languageserver.JavaLanguageServerExtensionService;
import org.eclipse.che.plugin.java.languageserver.NotifyJsonRpcTransmitter;
import org.slf4j.Logger;
Expand Down Expand Up @@ -119,9 +121,12 @@ private List<String> getOutputFolder() throws ValueStorageException {
String outputDir;
try {
outputDir = extensionService.getOutputDir(wsPath);
if (isNullOrEmpty(outputDir)) {
outputDir = Constants.DEFAULT_OUTPUT_FOLDER_VALUE;
}
} catch (Exception e) {
throw new ValueStorageException(
format("Failed to get '%s'. ", OUTPUT_FOLDER), e.getCause());
// can't read output dir
outputDir = Constants.DEFAULT_OUTPUT_FOLDER_VALUE;
}

String fsPath = transformer.transform(wsPath).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,24 @@ public void configureMethods() {
public String getOutputDir(String projectPath) {
checkLanguageServerInitialized();

String projectUri = LanguageServiceUtils.prefixURI(projectPath);
String projectUri = prefixURI(projectPath);
Type type = new TypeToken<String>() {}.getType();
return doGetOne(GET_OUTPUT_DIR_COMMAND, singletonList(projectUri), type);
}

/**
* Adds all jars from the folder into the classpath.
*
* @param projectPath project's path
* @param library path to the folder with libraries
*/
public void addJars(String projectPath, String library) {
checkLanguageServerInitialized();

String projectUri = prefixURI(projectPath);
executeCommand(Commands.ADD_JARS_COMMAND, Arrays.asList(projectUri, library));
}

/**
* Compute output directory of the project.
*
Expand Down Expand Up @@ -447,7 +460,7 @@ private ClasspathEntry fixEntry(ClasspathEntry e) {
public List<String> getSourceFolders(String projectPath) {
checkLanguageServerInitialized();

String projectUri = LanguageServiceUtils.prefixURI(projectPath);
String projectUri = prefixURI(projectPath);
Type type = new TypeToken<ArrayList<String>>() {}.getType();
List<String> result = doGetList(GET_SOURCE_FOLDERS, projectUri, type);
return result.stream().map(LanguageServiceUtils::removePrefixUri).collect(Collectors.toList());
Expand Down Expand Up @@ -578,9 +591,7 @@ private List<ExtendedSymbolInformationDto> executeFileStructure(
}

public ImplementersResponseDto findImplementers(TextDocumentPositionParams params) {
params
.getTextDocument()
.setUri(LanguageServiceUtils.prefixURI(params.getTextDocument().getUri()));
params.getTextDocument().setUri(prefixURI(params.getTextDocument().getUri()));
CompletableFuture<Object> result =
executeCommand(FIND_IMPLEMENTERS_COMMAND, singletonList(params));

Expand Down Expand Up @@ -1036,7 +1047,7 @@ private void fixLocation(ExtendedSymbolInformation symbol) {
}

private UsagesResponse usages(TextDocumentPositionParams parameters) {
String uri = LanguageServiceUtils.prefixURI(parameters.getUri());
String uri = prefixURI(parameters.getUri());
parameters.setUri(uri);
parameters.getTextDocument().setUri(uri);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.che.api.core.BadRequestException;
import org.eclipse.che.api.core.ConflictException;
import org.eclipse.che.api.core.ForbiddenException;
Expand Down Expand Up @@ -72,6 +73,8 @@ public class JavaLanguageServerLauncher implements LanguageServerConfig {
private final EventService eventService;
private final ProjectManager projectManager;

private AtomicBoolean isStarted;

@Inject
public JavaLanguageServerLauncher(
ProcessorJsonRpcCommunication processorJsonRpcCommunication,
Expand All @@ -84,16 +87,24 @@ public JavaLanguageServerLauncher(
this.notifyTransmitter = notifyTransmitter;
this.eventService = eventService;
this.projectManager = projectManager;

isStarted = new AtomicBoolean(false);
launchScript = Paths.get(System.getenv("HOME"), "che/ls-java/launch.sh");
}

public void sendStatusReport(StatusReport report) {
LOG.info("{}: {}", report.getType(), report.getMessage());
if ("Started".equals(report.getType())) {
isStarted.set(true);
updateWorkspaceOnLSStarted();
}
}

/** @return {@code true} if jd.ls has started, otherwise {@code false}. */
public boolean isStarted() {
return isStarted.get();
}

private void updateWorkspaceOnLSStarted() {
projectManager
.getAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void prepare() throws Exception {
PROJECT_NAME,
ProjectTemplates.PLAIN_JAVA);
ide.open(testWorkspace);
consoles.waitJDTLSProjectResolveFinishedMessage(PROJECT_NAME);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void prepare() throws Exception {
testProjectServiceClient.importProject(
ws.getId(), Paths.get(resource.toURI()), PROJECT_NAME, ProjectTemplates.PLAIN_JAVA);
ide.open(ws);
consoles.waitJDTLSProjectResolveFinishedMessage(PROJECT_NAME);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.google.inject.name.Named;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.che.commons.lang.NameGenerator;
import org.eclipse.che.selenium.core.client.TestGitHubRepository;
import org.eclipse.che.selenium.core.client.TestUserPreferencesServiceClient;
import org.eclipse.che.selenium.core.constant.TestProjectExplorerContextMenuConstants.ContextMenuFirstLevelItems;
Expand All @@ -53,7 +52,7 @@

/** @author Aleksandr Shmaraev */
public class RunPlainJavaProjectTest {
private static final String PROJECT_NAME = NameGenerator.generate("RunningPlainJavaProject", 4);
private static final String PROJECT_NAME = "run-plain-java-project";
tsmaeder marked this conversation as resolved.
Show resolved Hide resolved
private static final String NEW_PACKAGE = "base.test";
private static final String NAME_COMMAND = "startApp";
private static final String COMMAND =
Expand Down Expand Up @@ -94,6 +93,7 @@ public void prepare() throws Exception {
testRepo.addContent(entryPath);

ide.open(ws);
consoles.waitJDTLSStartedMessage();
}

@Test
Expand All @@ -110,7 +110,7 @@ public void checkRunPlainJavaProject() {
menu.runCommand(PROJECT, CONFIGURE_CLASSPATH);
configureClasspath.waitConfigureClasspathFormIsOpen();
configureClasspath.waitExpectedTextJarsAndFolderArea(
"testLibrary.jar - /projects/" + PROJECT_NAME + "/store");
"testLibrary.jar - /" + PROJECT_NAME + "/store");
configureClasspath.closeConfigureClasspathFormByIcon();

// create the instance of the library
Expand Down