Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into che6
Browse files Browse the repository at this point in the history
  • Loading branch information
skabashnyuk committed Oct 12, 2017
2 parents f1e0592 + 14061f5 commit 70ac13c
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 1,221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,19 @@ export class ImportGithubProjectController {
* The list of selected repositories.
*/
private selectedRepositories: Array<IGithubRepository>;
/**
* Keycloak auth service.
*/
private keycloakAuth: any;

/**
* Default constructor that is using resource
* @ngInject for Dependency injection
*/
constructor ($q: ng.IQService, $mdDialog: ng.material.IDialogService, $location: ng.ILocationService, $browser: ng.IBrowserService, $scope: ng.IScope, githubPopup: any, cheBranding: CheBranding, githubOrganizationNameResolver: any, importGithubProjectService: ImportGithubProjectService, cheListHelperFactory: che.widget.ICheListHelperFactory, addImportProjectService: AddImportProjectService) {
constructor ($q: ng.IQService, $mdDialog: ng.material.IDialogService, $location: ng.ILocationService,
$browser: ng.IBrowserService, $scope: ng.IScope, githubPopup: any, cheBranding: CheBranding,
githubOrganizationNameResolver: any, importGithubProjectService: ImportGithubProjectService,
cheListHelperFactory: che.widget.ICheListHelperFactory, addImportProjectService: AddImportProjectService, keycloakAuth: any) {
this.$q = $q;
this.$mdDialog = $mdDialog;
this.$location = $location;
Expand All @@ -123,6 +130,7 @@ export class ImportGithubProjectController {
this.githubOrganizationNameResolver = githubOrganizationNameResolver;
this.resolveOrganizationName = this.githubOrganizationNameResolver.resolve;
this.addImportProjectService = addImportProjectService;
this.keycloakAuth = keycloakAuth;

this.importGithubProjectService = importGithubProjectService;
this.productName = cheBranding.getName();
Expand Down Expand Up @@ -209,6 +217,24 @@ export class ImportGithubProjectController {
return;
}

if (this.keycloakAuth.isPresent) {
this.keycloakAuth.keycloak.updateToken(5).success(() => {
let token = '&token=' + this.keycloakAuth.keycloak.token;
this.openGithubPopup(token);
}).error(() => {
this.keycloakAuth.keycloak.login();
});
} else {
this.openGithubPopup('');
}
}

/**
* Opens Github popup.
*
* @param {string} token
*/
openGithubPopup(token: string): void {
const redirectUrl = this.$location.protocol() + '://'
+ this.$location.host() + ':'
+ this.$location.port()
Expand All @@ -218,6 +244,7 @@ export class ImportGithubProjectController {
+ '?oauth_provider=github'
+ '&scope=' + ['user', 'repo', 'write:public_key'].join(',')
+ '&userId=' + this.importGithubProjectService.getCurrentUserId()
+ token
+ '&redirect_after_login='
+ redirectUrl,
{
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/components/github/github-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class GitHubService {
} catch (error) {
}

if (popupWindow.closed) {
if (popupWindow && popupWindow.closed) {
$interval.cancel(polling);
deferred.reject({data: 'Authorization Failed'});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.jsonwebtoken.Jwt;
import java.io.IOException;
import java.security.Principal;
import java.util.Optional;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.FilterChain;
Expand Down Expand Up @@ -107,19 +108,30 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha

private User getOrCreateUser(String id, String email, String username)
throws ServerException, ConflictException {
try {
return userManager.getById(id);
} catch (NotFoundException e) {
Optional<User> user = getUser(id);
if (!user.isPresent()) {
synchronized (this) {
final UserImpl cheUser = new UserImpl(id, email, username, generate("", 12), emptyList());
try {
return userManager.create(cheUser, false);
} catch (ConflictException ex) {
cheUser.setName(generate(cheUser.getName(), 4));
return userManager.create(cheUser, false);
user = getUser(id);
if (!user.isPresent()) {
final UserImpl cheUser = new UserImpl(id, email, username, generate("", 12), emptyList());
try {
return userManager.create(cheUser, false);
} catch (ConflictException ex) {
cheUser.setName(generate(cheUser.getName(), 4));
return userManager.create(cheUser, false);
}
}
}
}
return user.get();
}

private Optional<User> getUser(String id) throws ServerException {
try {
return Optional.of(userManager.getById(id));
} catch (NotFoundException e) {
return Optional.empty();
}
}

private HttpServletRequest addUserInRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.eclipse.che.api.project.server.importer.ProjectImporterRegistry;
import org.eclipse.che.api.project.server.type.ProjectTypeRegistry;
import org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler;
import org.eclipse.che.api.vfs.impl.file.FileTreeWatcher;
import org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler;
import org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider;
import org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider;
Expand Down Expand Up @@ -91,8 +90,6 @@ private static void init() throws Exception {
ProjectImporterRegistry importerRegistry = new ProjectImporterRegistry(new HashSet<>());
FileWatcherNotificationHandler fileWatcherNotificationHandler =
new DefaultFileWatcherNotificationHandler(vfsProvider);
FileTreeWatcher fileTreeWatcher =
new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler);
ProjectManager projectManager =
new ProjectManager(
vfsProvider,
Expand All @@ -102,7 +99,6 @@ private static void init() throws Exception {
projectHandlerRegistry,
importerRegistry,
fileWatcherNotificationHandler,
fileTreeWatcher,
workspaceHolder,
mock(FileWatcherManager.class));

Expand All @@ -121,6 +117,7 @@ private static void init() throws Exception {
}

private static class TestWorkspaceHolder extends WorkspaceProjectsSyncer {

private List<ProjectConfigDto> projects;

TestWorkspaceHolder(List<ProjectConfigDto> projects) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.eclipse.che.api.project.server.importer.ProjectImporterRegistry;
import org.eclipse.che.api.project.server.type.ProjectTypeRegistry;
import org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler;
import org.eclipse.che.api.vfs.impl.file.FileTreeWatcher;
import org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler;
import org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider;
import org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider;
Expand All @@ -60,6 +59,7 @@
/** Test for the java formatter service. */
@Listeners(value = {MockitoTestNGListener.class})
public class JavaFormatterServiceTest {

private static final String FORMATTER_CONTENT =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
+ "<profiles version=\"13\">\n"
Expand Down Expand Up @@ -109,8 +109,6 @@ protected void initProjectApi() throws Exception {
ProjectImporterRegistry importerRegistry = new ProjectImporterRegistry(new HashSet<>());
FileWatcherNotificationHandler fileWatcherNotificationHandler =
new DefaultFileWatcherNotificationHandler(vfsProvider);
FileTreeWatcher fileTreeWatcher =
new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler);
projectManager =
new ProjectManager(
vfsProvider,
Expand All @@ -120,7 +118,6 @@ protected void initProjectApi() throws Exception {
projectHandlerRegistry,
importerRegistry,
fileWatcherNotificationHandler,
fileTreeWatcher,
workspaceHolder,
mock(FileWatcherManager.class));

Expand Down Expand Up @@ -243,6 +240,7 @@ private void checkProjectFormatterFile() throws IOException {
}

private static class TestWorkspaceHolder extends WorkspaceProjectsSyncer {

private List<ProjectConfigDto> projects;

TestWorkspaceHolder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.eclipse.che.api.project.server.importer.ProjectImporterRegistry;
import org.eclipse.che.api.project.server.type.ProjectTypeRegistry;
import org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler;
import org.eclipse.che.api.vfs.impl.file.FileTreeWatcher;
import org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler;
import org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider;
import org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider;
Expand All @@ -55,6 +54,7 @@

/** @author Valeriy Svydenko */
public abstract class BaseTest {

private static final String wsPath = BaseTest.class.getResource("/projects").getFile();
private static final String INDEX_PATH = "target/fs_index";

Expand All @@ -70,7 +70,9 @@ protected void initProjectApi() throws Exception {

TestWorkspaceHolder workspaceHolder = new TestWorkspaceHolder();

if (root == null) root = new File(wsPath);
if (root == null) {
root = new File(wsPath);
}

if (root.exists()) {
IoUtil.deleteRecursive(root);
Expand Down Expand Up @@ -109,9 +111,6 @@ protected void initProjectApi() throws Exception {
ProjectImporterRegistry importerRegistry = new ProjectImporterRegistry(new HashSet<>());
FileWatcherNotificationHandler fileWatcherNotificationHandler =
new DefaultFileWatcherNotificationHandler(vfsProvider);
FileTreeWatcher fileTreeWatcher =
new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler);

projectManager =
new ProjectManager(
vfsProvider,
Expand All @@ -121,7 +120,6 @@ protected void initProjectApi() throws Exception {
projectHandlerRegistry,
importerRegistry,
fileWatcherNotificationHandler,
fileTreeWatcher,
new TestWorkspaceHolder(new ArrayList<>()),
mock(FileWatcherManager.class));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.eclipse.che.api.project.server.type.ProjectTypeDef;
import org.eclipse.che.api.project.server.type.ProjectTypeRegistry;
import org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler;
import org.eclipse.che.api.vfs.impl.file.FileTreeWatcher;
import org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler;
import org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider;
import org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider;
Expand Down Expand Up @@ -83,7 +82,6 @@ public abstract class BaseTest {
protected LocalVirtualFileSystemProvider vfsProvider;
protected ProjectRegistry projectRegistry;
protected FileWatcherNotificationHandler fileWatcherNotificationHandler;
protected FileTreeWatcher fileTreeWatcher;
protected ProjectTypeRegistry projectTypeRegistry;
protected ProjectHandlerRegistry projectHandlerRegistry;
protected ProjectImporterRegistry importerRegistry;
Expand Down Expand Up @@ -111,7 +109,9 @@ protected void initProjectApi() throws Exception {
mavenServerManager = new MavenServerManager(mavenServerPath);
workspaceHolder = new TestWorkspaceHolder();

if (root == null) root = new File(wsPath);
if (root == null) {
root = new File(wsPath);
}

if (root.exists()) {
IoUtil.deleteRecursive(root);
Expand Down Expand Up @@ -149,7 +149,6 @@ protected void initProjectApi() throws Exception {
importerRegistry = new ProjectImporterRegistry(new HashSet<>());

fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(vfsProvider);
fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler);

pm =
new ProjectManager(
Expand All @@ -160,7 +159,6 @@ protected void initProjectApi() throws Exception {
projectHandlerRegistry,
importerRegistry,
fileWatcherNotificationHandler,
fileTreeWatcher,
new TestWorkspaceHolder(new ArrayList<>()),
mock(FileWatcherManager.class));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.eclipse.che.api.project.server.type.ProjectTypeDef;
import org.eclipse.che.api.project.server.type.ProjectTypeRegistry;
import org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler;
import org.eclipse.che.api.vfs.impl.file.FileTreeWatcher;
import org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler;
import org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider;
import org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider;
Expand Down Expand Up @@ -69,7 +68,6 @@ public abstract class BaseTest {
protected LocalVirtualFileSystemProvider vfsProvider;
protected ProjectRegistry projectRegistry;
protected FileWatcherNotificationHandler fileWatcherNotificationHandler;
protected FileTreeWatcher fileTreeWatcher;
protected ProjectTypeRegistry projectTypeRegistry;
protected ProjectHandlerRegistry projectHandlerRegistry;
protected ProjectImporterRegistry importerRegistry;
Expand Down Expand Up @@ -131,7 +129,6 @@ protected void initProjectApi() throws Exception {
importerRegistry = new ProjectImporterRegistry(new HashSet<>());

fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(vfsProvider);
fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler);

pm =
new ProjectManager(
Expand All @@ -142,7 +139,6 @@ protected void initProjectApi() throws Exception {
projectHandlerRegistry,
importerRegistry,
fileWatcherNotificationHandler,
fileTreeWatcher,
new TestWorkspaceHolder(new ArrayList<>()),
Mockito.mock(FileWatcherManager.class));

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@
<dependency>
<groupId>org.eclipse.che.multiuser</groupId>
<artifactId>che-multiuser-personal-account</artifactId>
<version>${project.version}</version>
<version>${che.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.che.multiuser</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import org.eclipse.che.api.vfs.VirtualFile;
import org.eclipse.che.api.vfs.VirtualFileSystem;
import org.eclipse.che.api.vfs.VirtualFileSystemProvider;
import org.eclipse.che.api.vfs.impl.file.FileTreeWatcher;
import org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler;
import org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationListener;
import org.eclipse.che.api.vfs.search.Searcher;
Expand All @@ -81,7 +80,6 @@ public class ProjectManager {
private final ProjectRegistry projectRegistry;
private final ProjectHandlerRegistry handlers;
private final ProjectImporterRegistry importers;
private final FileTreeWatcher fileWatcher;
private final FileWatcherNotificationHandler fileWatchNotifier;
private final ExecutorService executor;
private final WorkspaceProjectsSyncer workspaceProjectsHolder;
Expand All @@ -98,7 +96,6 @@ public ProjectManager(
ProjectHandlerRegistry handlers,
ProjectImporterRegistry importers,
FileWatcherNotificationHandler fileWatcherNotificationHandler,
FileTreeWatcher fileTreeWatcher,
WorkspaceProjectsSyncer workspaceProjectsHolder,
FileWatcherManager fileWatcherManager)
throws ServerException {
Expand All @@ -109,7 +106,6 @@ public ProjectManager(
this.handlers = handlers;
this.importers = importers;
this.fileWatchNotifier = fileWatcherNotificationHandler;
this.fileWatcher = fileTreeWatcher;
this.workspaceProjectsHolder = workspaceProjectsHolder;
this.fileWatcherManager = fileWatcherManager;

Expand Down Expand Up @@ -164,12 +160,6 @@ public void onFileWatcherEvent(VirtualFile virtualFile, FileWatcherEventType eve
}
};
fileWatchNotifier.addNotificationListener(defaultListener);
try {
fileWatcher.startup();
} catch (IOException e) {
LOG.error(e.getMessage(), e);
fileWatchNotifier.removeNotificationListener(defaultListener);
}
}

@PreDestroy
Expand Down Expand Up @@ -198,13 +188,9 @@ public void removeWatchListener(FileWatcherNotificationListener listener) {
fileWatchNotifier.removeNotificationListener(listener);
}

public void addWatchExcludeMatcher(PathMatcher matcher) {
fileWatcher.addExcludeMatcher(matcher);
}
public void addWatchExcludeMatcher(PathMatcher matcher) {}

public void removeWatchExcludeMatcher(PathMatcher matcher) {
fileWatcher.removeExcludeMatcher(matcher);
}
public void removeWatchExcludeMatcher(PathMatcher matcher) {}

/**
* @return all the projects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

@Singleton
public class DefaultFileWatcherNotificationHandler implements FileWatcherNotificationHandler {

private static final Logger LOG =
LoggerFactory.getLogger(DefaultFileWatcherNotificationHandler.class);

Expand Down Expand Up @@ -93,6 +94,7 @@ private VirtualFile convertToVirtualFile(File root, String subPath, boolean isDi
}

private static class DeletedLocalVirtualFile extends LocalVirtualFile {

private final boolean isDir;

DeletedLocalVirtualFile(
Expand Down
Loading

0 comments on commit 70ac13c

Please sign in to comment.