Skip to content

Commit 4a6906a

Browse files
Maven plugin for dumping dependencies (cross-repo navigation) (#735)
Additionally: * Add `build` command which packages CLI in a reasonable location * update SBT * move benchmark tests to check job * Add a new maven workflow * Read classpath entries from possibly any number of *dependencies.txt
1 parent 4e5dfd3 commit 4a6906a

File tree

10 files changed

+442
-25
lines changed

10 files changed

+442
-25
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,15 @@ jobs:
1717
java: [8, 11, 17, 21]
1818
steps:
1919
- uses: actions/checkout@v4
20+
2021
- uses: actions/setup-java@v4
2122
with:
2223
distribution: "temurin"
2324
cache: "sbt"
2425
java-version: ${{ matrix.java }}
25-
- name: Main project tests
26-
run: sbt test
2726

28-
benchmarks-test:
29-
runs-on: ubuntu-latest
30-
name: Benchmark tests
31-
steps:
32-
- uses: actions/checkout@v4
33-
- uses: actions/setup-java@v4
34-
with:
35-
distribution: "temurin"
36-
cache: "sbt"
37-
java-version: 17
38-
- name: Run sample benchmarks
39-
run: sbt 'bench/Jmh/run -i 1 -f1 -t1 -foe true'
27+
- name: Main project tests
28+
run: sbt test
4029

4130
docker_test:
4231
runs-on: ${{ matrix.os }}
@@ -94,8 +83,8 @@ jobs:
9483
steps:
9584
- uses: actions/checkout@v2
9685
- run: yarn global add @bazel/bazelisk
97-
- run: sbt cli/pack
98-
- run: echo "$PWD/scip-java/target/pack/bin" >> $GITHUB_PATH
86+
- run: sbt build
87+
- run: echo "$PWD/out/bin" >> $GITHUB_PATH
9988
- name: Auto-index scip-java codebase
10089
run: |
10190
scip-java index --build-tool=bazel --bazel-scip-java-binary=$(which scip-java)
@@ -116,4 +105,48 @@ jobs:
116105
distribution: "temurin"
117106
java-version: 17
118107
cache: "sbt"
108+
119109
- run: sbt checkAll
110+
111+
- name: Run sample benchmarks
112+
run: sbt 'bench/Jmh/run -i 1 -f1 -t1 -foe true'
113+
114+
115+
maven:
116+
runs-on: ubuntu-latest
117+
name: Maven tests
118+
strategy:
119+
fail-fast: false
120+
matrix:
121+
java: [8, 11, 17, 21]
122+
steps:
123+
- uses: actions/checkout@v4
124+
125+
- uses: actions/setup-java@v4
126+
with:
127+
distribution: "temurin"
128+
cache: "sbt"
129+
java-version: ${{ matrix.java }}
130+
131+
132+
- run: |
133+
sbt build publishM2 publishLocal dumpScipJavaVersion
134+
echo "SCIP_JAVA_VERSION=$(cat VERSION)" >> $GITHUB_ENV
135+
echo "SCIP_JAVA_CLI=$PWD/out/bin/scip-java" >> $GITHUB_ENV
136+
137+
- run: |
138+
mvn clean verify -DskipTests -Dscip-java.version=$SCIP_JAVA_VERSION sourcegraph:sourcegraphDependencies
139+
working-directory: examples/maven-example
140+
141+
- run: $SCIP_JAVA_CLI index-semanticdb target/semanticdb-targetroot
142+
working-directory: examples/maven-example
143+
144+
- run: |
145+
set -e
146+
grep org.hamcrest target/semanticdb-targetroot/*dependencies.txt
147+
grep $PWD/src/main/java target/semanticdb-targetroot/*dependencies.txt
148+
working-directory: examples/maven-example
149+
150+
- run: du -h index.scip
151+
working-directory: examples/maven-example
152+

build.sbt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ lazy val scipProto = project
205205
lazy val scip = project
206206
.in(file("scip-semanticdb"))
207207
.settings(
208+
publishMavenStyle := true,
208209
moduleName := "scip-semanticdb",
209210
javaToolchainVersion := "8",
210211
javaOnlySettings,
@@ -214,6 +215,36 @@ lazy val scip = project
214215
)
215216
.dependsOn(semanticdb, scipProto)
216217

218+
lazy val mavenPlugin = project
219+
.in(file("maven-plugin"))
220+
.settings(
221+
moduleName := "maven-plugin",
222+
javaToolchainVersion := "8",
223+
javaOnlySettings,
224+
libraryDependencies ++=
225+
Seq(
226+
"org.apache.maven" % "maven-plugin-api" % "3.6.3",
227+
"org.apache.maven.plugin-tools" % "maven-plugin-annotations" % "3.6.4" %
228+
Provided,
229+
"org.apache.maven" % "maven-project" % "2.2.1"
230+
),
231+
Compile / resourceGenerators +=
232+
Def.task {
233+
val dir = (Compile / managedResourceDirectories).value.head /
234+
"META-INF" / "maven"
235+
IO.createDirectory(dir)
236+
val file = dir / "plugin.xml"
237+
val template = IO.read(
238+
(Compile / resourceDirectory).value / "META-INF" / "maven" /
239+
"plugin.template.xml"
240+
)
241+
242+
IO.write(file, template.replace("@VERSION@", version.value))
243+
244+
Seq(file)
245+
}
246+
)
247+
217248
lazy val cli = project
218249
.in(file("scip-java"))
219250
.settings(
@@ -602,3 +633,13 @@ dumpScipJavaVersion := {
602633

603634
IO.write((ThisBuild / baseDirectory).value / "VERSION", versionValue)
604635
}
636+
637+
lazy val build = taskKey[Unit](
638+
"Build `scip-java` CLI and place it in the out/bin/scip-java. "
639+
)
640+
641+
build := {
642+
val source = (cli / pack).value
643+
val destination = (ThisBuild / baseDirectory).value / "out"
644+
IO.copyDirectory(source, destination)
645+
}

docs/manual-configuration.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ index.scip: JSON data
156156

157157
## Step 5 (optional): Enable cross-repository navigation
158158

159+
Cross-repository navigation is a feature that allows "goto definition" and "find
160+
references" to show results from multiple repositories.
161+
159162
By default, the `index.scip` file only enables navigation within the local
160163
repository. You can optionally enable cross-repository navigation by creating
161164
one of the following files in the SemanticDB _targetroot_ directory (the path in
@@ -193,5 +196,35 @@ one of the following files in the SemanticDB _targetroot_ directory (the path in
193196
your Sourcegraph instance has another repository that defines that symbol, the
194197
cross-repository navigation should succeed.
195198

199+
### Maven plugin
200+
201+
To simplify setting up cross-repo navigation for Maven projects, we provide a
202+
plugin that can dump the project's dependencies in a format that scip-java understands.
203+
204+
You can either use it directly from commandline:
205+
206+
```
207+
$ mvn com.sourcegraph:maven-plugin:@STABLE_VERSION@:sourcegraphDependencies
208+
```
209+
210+
Or add it to your build like any other maven plugin:
211+
212+
```xml
213+
<plugin>
214+
<groupId>com.sourcegraph</groupId>
215+
<artifactId>maven-plugin</artifactId>
216+
<version>@STABLE_VERSION@</version>
217+
<executions>
218+
<execution>
219+
<goals>
220+
<goal>sourcegraphDependencies</goal>
221+
</goals>
222+
</execution>
223+
</executions>
224+
</plugin>
225+
```
226+
227+
Which allows you to invoke it by simply running `mvn sourcegraph:sourcegraphDependencies`.
228+
196229
Cross-repository navigation is a feature that allows "goto definition" and "find
197230
references" to show results from multiple repositories.

examples/maven-example/pom.xml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.sourcegraph</groupId>
8+
<artifactId>example</artifactId>
9+
<version>${revision}</version>
10+
11+
<name>example</name>
12+
<!-- FIXME change it to the project's website -->
13+
<url>http://www.example.com</url>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<maven.compiler.source>1.8</maven.compiler.source>
18+
<maven.compiler.target>1.8</maven.compiler.target>
19+
<revision>1.0.0-SNAPSHOT</revision>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>junit</groupId>
25+
<artifactId>junit</artifactId>
26+
<version>4.11</version>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>com.sourcegraph</groupId>
31+
<artifactId>semanticdb-javac</artifactId>
32+
<version>${scip-java.version}</version>
33+
</dependency>
34+
</dependencies>
35+
36+
<build>
37+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
38+
<plugins>
39+
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
40+
<plugin>
41+
<artifactId>maven-clean-plugin</artifactId>
42+
<version>3.1.0</version>
43+
</plugin>
44+
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
45+
<plugin>
46+
<artifactId>maven-resources-plugin</artifactId>
47+
<version>3.0.2</version>
48+
</plugin>
49+
<plugin>
50+
<artifactId>maven-compiler-plugin</artifactId>
51+
<version>3.8.0</version>
52+
<configuration>
53+
<compilerArgs>
54+
<arg>-Xplugin:semanticdb -sourceroot:${session.executionRootDirectory} -targetroot:${session.executionRootDirectory}/target/semanticdb-targetroot</arg>
55+
</compilerArgs>
56+
</configuration>
57+
</plugin>
58+
<plugin>
59+
<artifactId>maven-surefire-plugin</artifactId>
60+
<version>2.22.1</version>
61+
</plugin>
62+
<plugin>
63+
<artifactId>maven-jar-plugin</artifactId>
64+
<version>3.0.2</version>
65+
</plugin>
66+
<plugin>
67+
<artifactId>maven-install-plugin</artifactId>
68+
<version>2.5.2</version>
69+
</plugin>
70+
<plugin>
71+
<artifactId>maven-deploy-plugin</artifactId>
72+
<version>2.8.2</version>
73+
</plugin>
74+
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
75+
<plugin>
76+
<artifactId>maven-site-plugin</artifactId>
77+
<version>3.7.1</version>
78+
</plugin>
79+
<plugin>
80+
<artifactId>maven-project-info-reports-plugin</artifactId>
81+
<version>3.0.0</version>
82+
</plugin>
83+
<plugin>
84+
<groupId>com.sourcegraph</groupId>
85+
<artifactId>maven-plugin</artifactId>
86+
<version>${scip-java.version}</version>
87+
<executions>
88+
<execution>
89+
<goals>
90+
<goal>sourcegraphDependencies</goal>
91+
</goals>
92+
</execution>
93+
</executions>
94+
<!-- <configuration> -->
95+
<!-- <scope>test</scope> -->
96+
<!-- </configuration> -->
97+
</plugin>
98+
</plugins>
99+
</pluginManagement>
100+
</build>
101+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package test;
2+
3+
/**
4+
* Hello world!
5+
*
6+
*/
7+
public class App
8+
{
9+
public static void main( String[] args )
10+
{
11+
System.out.println( "Hello World!" );
12+
}
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package test;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import org.junit.Test;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
{
12+
/**
13+
* Rigorous Test :-)
14+
*/
15+
@Test
16+
public void shouldAnswerWithTrue()
17+
{
18+
assertTrue( true );
19+
}
20+
}

0 commit comments

Comments
 (0)