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

Remove jgit dependency #798

Merged
merged 3 commits into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion gradle-baseline-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dependencies {
compile 'net.ltgt.gradle:gradle-errorprone-plugin'
compile 'org.apache.maven.shared:maven-dependency-analyzer'
compile 'org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.11'
implementation 'org.eclipse.jgit:org.eclipse.jgit'

testCompile gradleTestKit()
testCompile 'com.github.stefanbirkner:system-rules'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

package com.palantir.baseline.plugins

import com.palantir.baseline.util.GitUtils
import groovy.transform.CompileStatic
import groovy.xml.XmlUtil
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.transport.URIish
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.Task
Expand Down Expand Up @@ -241,7 +240,7 @@ class BaselineIdea extends AbstractBaselinePlugin {
}

private void addGitHubIssueNavigation(node) {
maybeGitHubUri().ifPresent { githubUri ->
GitUtils.maybeGitHubUri().ifPresent { githubUri ->
node.append(new XmlParser().parseText("""
<component name="IssueNavigationConfiguration">
<option name="links">
Expand All @@ -257,29 +256,6 @@ class BaselineIdea extends AbstractBaselinePlugin {
}
}

private Optional<String> maybeGitHubUri() {
try {
Git git = Git.open(project.projectDir);
return git.remoteList().call().stream()
.flatMap { remoteConfig -> remoteConfig.getURIs().stream() }
.map { uri -> gitHubProjectFromRemote(uri) }
.filter { uri -> uri.contains("github") }
.findFirst()
} catch (Exception e) {
project.logger.info("Failed to detect Git remotes", e)
return Optional.empty()
}
}

/**
* Naiive conversion from ssh git remote to a Github project uri
*/
static String gitHubProjectFromRemote(URIish uri) {
def path = uri.path.endsWith('.git') ? uri.path.substring(0, uri.path.length() - 4) : uri.path
path = path.startsWith('/') ? path.substring(1) : path
return "https://${uri.host}/${path}"
}

/**
* Configure the default working directory of RunManager configurations to be the module directory.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.palantir.baseline.util;

import java.io.File;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.gradle.util.GFileUtils;

public final class GitUtils {
private static final Pattern GIT_ORIGIN = Pattern.compile("url = git@([^:]+):([^.]+).git");


public static Optional<String> maybeGitHubUri() {
try {
String gitConfigContents = GFileUtils.readFile(new File(".git/config'"));
Matcher matcher = GIT_ORIGIN.matcher(gitConfigContents);
if (!matcher.find()) {
return Optional.of(String.format("https://%s/%s", matcher.group(1), matcher.group(2)));
}
return Optional.empty();
} catch (Exception e) {
return Optional.empty();
}
}

private GitUtils() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.palantir.baseline

import com.palantir.baseline.plugins.BaselineIdea
import org.eclipse.jgit.transport.URIish
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Specification
Expand All @@ -37,17 +36,4 @@ class BaselineIdeaTest extends Specification {
expect:
project.plugins.hasPlugin(BaselineIdea.class)
}

def testGitHubUriExtraction(String remoteUri, String projectUri) {
expect:
assert BaselineIdea.gitHubProjectFromRemote(new URIish(remoteUri)) == projectUri

where:
remoteUri | projectUri
"[email protected]:palantir/gradle-baseline.git" | "https://github.com/palantir/gradle-baseline"
"[email protected]:palantir/gradle-baseline.git" | "https://github.my.company/palantir/gradle-baseline"
"https://github.com/palantir/gradle-baseline.git" | "https://github.com/palantir/gradle-baseline"
"https://github.my.company/palantir/gradle-baseline.git" | "https://github.my.company/palantir/gradle-baseline"
}

}
1 change: 0 additions & 1 deletion versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ org.apache.maven.shared:maven-dependency-analyzer = 1.11.1
org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.11 = 1.0.1
org.inferred:freebuilder = 1.14.6
org.slf4j:slf4j-api = 1.7.25
org.eclipse.jgit:org.eclipse.jgit = 5.3.2.201906051522-r

# test deps
com.netflix.nebula:nebula-test = 7.3.0
Expand Down