Skip to content
This repository has been archived by the owner on Oct 25, 2019. It is now read-only.

Commit

Permalink
Fix #39: Feature request: add DataGrip support
Browse files Browse the repository at this point in the history
  • Loading branch information
bchatard committed Feb 7, 2018
1 parent 2a96b60 commit 5f48a2a
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### v2.0.0-beta7 - 2018-02-07
* Fix [#39](https://github.com/bchatard/jetbrains-alfred-workflow/issues/39): Feature request: add DataGrip support
* update license year

### v2.0.0-beta6 - 2017-11-17
* Fix [#36](https://github.com/bchatard/jetbrains-alfred-workflow/issues/36): Please update package alfredworkflow file

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2017 Brice CHATARD
Copyright (c) 2015-2018 Brice CHATARD

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ Alfred2 user, please use [v1.0](https://github.com/bchatard/jetbrains-alfred-wor


### Default Keywords
* AppCode: `appcode`;
* CLion: `clion`;
* IntelliJ Idea: `idea`;
* PhpStorm: `pstorm` (before 2016.3) or `phpstorm` (2016.3+);
* PyCharm: `charm`;
* RubyMine: `mine`;
* WebStorm: `wstorm` (before 2016.3) or `webstorm` (2016.3+);
* Android Studio: `studio`;
* AppCode: `appcode` ;
* CLion: `clion` ;
* IntelliJ Idea: `idea` ;
* PhpStorm: `pstorm` (before 2016.3) or `phpstorm` (2016.3+) ;
* PyCharm: `charm` ;
* RubyMine: `mine` ;
* WebStorm: `wstorm` (before 2016.3) or `webstorm` (2016.3+) ;
* Android Studio: `studio` ;
* Gogland: `gogland` ;
* Rider: `rider` ;
* DataGrip: `datagrip` (since v2.0.0-beta7) ;


### Supported versions
Expand All @@ -61,6 +62,7 @@ I test with this products/versions:
* Android Studio: v2.x ;
* Gogland: 2017.x ;
* Rider: 2017.x ;
* DataGrip: 2017.3+

NB: about PhpStorm, if you need compatibility with older version please use my old workflow: [PhpStorm Alfred Workflow](https://github.com/bchatard/phpstorm-alfred-workflow)

Expand Down
Binary file modified package/JetBrains - Open project.alfredworkflow
Binary file not shown.
85 changes: 63 additions & 22 deletions src/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class Project
private $cacheDir;


/**
* @param string $jetbrainsApp
* @throws \RuntimeException
*/
public function __construct($jetbrainsApp)
{
date_default_timezone_set('UTC');
Expand All @@ -76,8 +80,8 @@ public function __construct($jetbrainsApp)
$this->debug = isset($_SERVER['jb_debug']) ? (bool)$_SERVER['jb_debug'] : false;

$this->cacheDir = $_SERVER['alfred_workflow_cache'];
if (!is_dir($this->cacheDir)) {
mkdir($this->cacheDir, 0750);
if (!mkdir($this->cacheDir) && !is_dir($this->cacheDir)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $this->cacheDir));
}

if ($this->debug) {
Expand All @@ -90,6 +94,10 @@ public function __construct($jetbrainsApp)
}
}

/**
* @param string $query
* @return Result
*/
public function search($query)
{
$this->log("\n" . __FUNCTION__ . "({$query})");
Expand Down Expand Up @@ -132,13 +140,21 @@ public function search($query)
return $this->result;
}

/**
* @param string $query
* @return string
*/
private function parseQuery($query)
{
$query = str_replace('\ ', ' ', $query);

return trim($query);
}

/**
* @return array
* @throws \RuntimeException
*/
private function getProjectsData()
{
$this->log("\n" . __FUNCTION__);
Expand Down Expand Up @@ -177,7 +193,11 @@ private function getProjectsData()
/** @var SimpleXMLElement $optionElement */
foreach ($optionElements as $optionElement) {
if ($optionElement->value) {
$path = str_replace('$USER_HOME$', $_SERVER['HOME'], $optionElement->value->__toString());
$path = str_replace(
['$USER_HOME$', '$APPLICATION_CONFIG_DIR$'],
[$_SERVER['HOME'], $this->jetbrainsAppConfigPath],
$optionElement->value->__toString()
);

$this->log("\nProcess {$path}");

Expand Down Expand Up @@ -205,6 +225,10 @@ private function getProjectsData()
return $projectsData;
}

/**
* @param string $path
* @return bool|string
*/
private function getProjectName($path)
{
$this->log(__FUNCTION__);
Expand Down Expand Up @@ -232,31 +256,38 @@ private function getProjectName($path)
return false;
}

/**
*
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
private function checkJetbrainsApp()
{
$this->log("\n" . __FUNCTION__);

$paths = [
'RUN_PATH' => 'jetbrainsAppPath',
'CONFIG_PATH' => 'jetbrainsAppConfigPath',
];

$handle = @fopen($this->jetbrainsApp, 'rb');
if ($handle) {
while (($row = fgets($handle)) !== false) {
if (strpos($row, 'RUN_PATH =') === 0) {
$jetbrainsAppPath = str_replace('RUN_PATH = u', '', $row);
$jetbrainsAppPath = trim($jetbrainsAppPath);
$jetbrainsAppPath = trim($jetbrainsAppPath, "'");
if (is_dir($jetbrainsAppPath) && is_readable($jetbrainsAppPath)) {
$this->jetbrainsAppPath = $jetbrainsAppPath;

$this->log("App path: {$this->jetbrainsAppPath}");
}
}
if (strpos($row, 'CONFIG_PATH =') === 0) {
$jetbrainsAppConfigPath = str_replace('CONFIG_PATH = u', '', $row);
$jetbrainsAppConfigPath = trim($jetbrainsAppConfigPath);
$jetbrainsAppConfigPath = trim($jetbrainsAppConfigPath, "'");
if (is_dir($jetbrainsAppConfigPath) && is_readable($jetbrainsAppConfigPath)) {
$this->jetbrainsAppConfigPath = $jetbrainsAppConfigPath;

$this->log("App config path: {$this->jetbrainsAppConfigPath}");

foreach ($paths as $var => $field) {
if (strpos($row, "{$var} =") === 0) {
$path = str_replace("{$var} = u", '', $row);
$path = trim($path);
$path = trim($path, "'");
if (is_dir($path) && is_readable($path)) {
$this->$field = $path;

$this->log("{$field}: {$this->$field}");

break;
}
}

}

if ($this->jetbrainsAppPath && $this->jetbrainsAppConfigPath) {
Expand Down Expand Up @@ -285,6 +316,10 @@ private function checkJetbrainsApp()
$this->cache = new Cache($cacheFile);
}

/**
* @param string $name
* @param string $path
*/
private function addProjectItem($name, $path)
{
$item = new Item();
Expand All @@ -301,6 +336,9 @@ private function addProjectItem($name, $path)
$this->result->addItem($item);
}

/**
* @param string $query
*/
private function addNoProjectMatchItem($query)
{
$item = new Item();
Expand Down Expand Up @@ -353,7 +391,7 @@ private function addErrorItem($e)
$this->log($e);
}

public function addDebugItem()
private function addDebugItem()
{
if ($this->debug) {
$item = new Item();
Expand All @@ -370,6 +408,9 @@ public function addDebugItem()
}
}

/**
* @param string|array|\stdClass $message
*/
private function log($message)
{
if ($this->debug) {
Expand Down

0 comments on commit 5f48a2a

Please sign in to comment.