35
35
import com .intellij .concurrency .AsyncUtil ;
36
36
import com .intellij .execution .ExecutionException ;
37
37
import com .intellij .openapi .util .Key ;
38
- import com .intellij .openapi .util .text .StringUtil ;
39
38
import java .io .BufferedInputStream ;
40
39
import java .io .File ;
41
40
import java .io .IOException ;
42
41
import java .io .InputStream ;
43
42
import java .io .InputStreamReader ;
43
+ import java .nio .file .Path ;
44
44
import java .util .ArrayList ;
45
45
import java .util .Collection ;
46
46
import java .util .HashMap ;
47
47
import java .util .List ;
48
- import java .util .Locale ;
49
48
import java .util .Map ;
50
49
import java .util .concurrent .Future ;
51
50
@@ -59,7 +58,7 @@ class BlazeIntellijPluginDeployer {
59
58
Key .create (BlazeIntellijPluginDeployer .class .getName ());
60
59
61
60
private final String sandboxHome ;
62
- private final Map <String , OutputArtifact > buildArtifactsMap = new HashMap <>();
61
+ private final Map <Path , OutputArtifact > buildArtifactsMap = new HashMap <>();
63
62
private final List <OutputArtifact > deployInfoArtifacts = new ArrayList <>();
64
63
private final Map <OutputArtifact , File > filesToDeploy = Maps .newHashMap ();
65
64
@@ -81,7 +80,7 @@ void buildStarted() {
81
80
void reportBuildComplete (BlazeBuildOutputs .Legacy blazeBuildOutputs ) throws GetArtifactsException {
82
81
ImmutableSet <OutputArtifact > buildArtifacts = blazeBuildOutputs .getAllOutputArtifacts ();
83
82
buildArtifactsMap .clear ();
84
- buildArtifacts .forEach (a -> buildArtifactsMap .put (a .getBazelOutRelativePath (), a ));
83
+ buildArtifacts .forEach (a -> buildArtifactsMap .put (a .getArtifactPath (), a ));
85
84
86
85
deployInfoArtifacts .clear ();
87
86
deployInfoArtifacts .addAll (
@@ -158,36 +157,34 @@ private ImmutableMap<OutputArtifact, File> getFilesToDeploy(
158
157
for (IntellijPluginDeployInfo deployInfo : deployInfos ) {
159
158
for (IntellijPluginDeployFile deployFile : deployInfo .getDeployFilesList ()) {
160
159
result .put (
161
- getArtifactFromDeployFile (deployFile , buildSystem ),
160
+ getArtifactFromDeployFile (deployFile ),
162
161
new File (sandboxPluginDirectory (sandboxHome ), deployFile .getDeployLocation ()));
163
162
}
164
163
for (IntellijPluginDeployFile deployFile : deployInfo .getJavaAgentDeployFilesList ()) {
165
164
result .put (
166
- getArtifactFromDeployFile (deployFile , buildSystem ),
165
+ getArtifactFromDeployFile (deployFile ),
167
166
new File (sandboxPluginDirectory (sandboxHome ), deployFile .getDeployLocation ()));
168
167
}
169
168
}
170
169
return result .build ();
171
170
}
172
171
173
- private OutputArtifact getArtifactFromDeployFile (
174
- IntellijPluginDeployFile deployFile , String buildSystem ) throws ExecutionException {
175
- String relativePath =
176
- buildArtifactsMap .keySet ().stream ()
177
- .filter (
178
- key ->
179
- key .endsWith (
180
- StringUtil .trimStart (
181
- deployFile .getExecutionPath (),
182
- String .format ("%s-out/" , buildSystem .toLowerCase (Locale .ROOT )))))
183
- .findAny ()
184
- .orElseThrow (
185
- () ->
186
- new ExecutionException (
187
- String .format (
188
- "Plugin file '%s' not found. Did the build fail?" ,
189
- deployFile .getExecutionPath ())));
190
- return buildArtifactsMap .get (relativePath );
172
+ private OutputArtifact getArtifactFromDeployFile (IntellijPluginDeployFile deployFile ) throws ExecutionException {
173
+ final var fileExecutionPath = Path .of (deployFile .getExecutionPath ());
174
+
175
+ // trim the first element from the execution path i.e. bazel-out
176
+ final var fileRelativePath = fileExecutionPath .subpath (1 , fileExecutionPath .getNameCount ());
177
+
178
+ // Find the matching artifact by comparing the end of the path
179
+ Path matchingPath = buildArtifactsMap .keySet ().stream ()
180
+ .filter (key -> key .endsWith (fileRelativePath ))
181
+ .findAny ()
182
+ .orElseThrow (
183
+ () ->
184
+ new ExecutionException (
185
+ String .format ("Plugin file '%s' not found. Did the build fail?" , fileExecutionPath )));
186
+
187
+ return buildArtifactsMap .get (matchingPath );
191
188
}
192
189
193
190
private ImmutableSet <File > listJavaAgentFiles (Collection <IntellijPluginDeployInfo > deployInfos ) {
0 commit comments