-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement GetComposeLayoutInspectorJarToken in blaze
PiperOrigin-RevId: 577022472
- Loading branch information
1 parent
fe0df78
commit ff99171
Showing
20 changed files
with
614 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
aswb/sdkcompat/as232/com/google/idea/blaze/android/projectsystem/BlazeToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2023 The Bazel Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.idea.blaze.android.projectsystem; | ||
|
||
import com.android.tools.idea.projectsystem.AndroidProjectSystem; | ||
import com.android.tools.idea.projectsystem.Token; | ||
|
||
/** A mix-in implementation of the {@link Token} interface for the Blaze project system. */ | ||
public interface BlazeToken extends Token { | ||
@Override | ||
default boolean isApplicable(AndroidProjectSystem projectSystem) { | ||
return projectSystem instanceof BlazeProjectSystem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
aswb/sdkcompat/asdev/com/google/idea/blaze/android/projectsystem/BlazeToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2023 The Bazel Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.idea.blaze.android.projectsystem; | ||
|
||
import com.android.tools.idea.projectsystem.AndroidProjectSystem; | ||
import com.android.tools.idea.projectsystem.Token; | ||
|
||
/** A mix-in implementation of the {@link Token} interface for the Blaze project system. */ | ||
public interface BlazeToken extends Token { | ||
@Override | ||
default boolean isApplicable(AndroidProjectSystem projectSystem) { | ||
return projectSystem instanceof BlazeProjectSystem; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
base/src/com/google/idea/blaze/base/qsync/AppInspectorArtifactTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2023 The Bazel Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.idea.blaze.base.qsync; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.google.idea.blaze.base.scope.BlazeContext; | ||
import com.google.idea.blaze.common.Label; | ||
import com.google.idea.blaze.exception.BuildException; | ||
import java.nio.file.Path; | ||
import java.util.Set; | ||
|
||
/** A local cache of built render jarss. */ | ||
public interface AppInspectorArtifactTracker { | ||
|
||
/** Fetches, caches and sets up new render jar artifacts. */ | ||
ImmutableSet<Path> update( | ||
Set<Label> targets, AppInspectorInfo appInspectorInfo, BlazeContext context) | ||
throws BuildException; | ||
} |
29 changes: 29 additions & 0 deletions
29
base/src/com/google/idea/blaze/base/qsync/AppInspectorBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2023 The Bazel Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.idea.blaze.base.qsync; | ||
|
||
import com.google.idea.blaze.base.scope.BlazeContext; | ||
import com.google.idea.blaze.common.Label; | ||
import com.google.idea.blaze.exception.BuildException; | ||
import java.io.IOException; | ||
import java.util.Set; | ||
|
||
/** A query sync service that builds render jars for given targets */ | ||
public interface AppInspectorBuilder { | ||
|
||
AppInspectorInfo buildAppInspector(BlazeContext context, Set<Label> buildTargets) | ||
throws IOException, BuildException; | ||
} |
40 changes: 40 additions & 0 deletions
40
base/src/com/google/idea/blaze/base/qsync/AppInspectorInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2023 The Bazel Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.idea.blaze.base.qsync; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.idea.blaze.base.command.buildresult.OutputArtifact; | ||
|
||
/** A data class that collecting and converting render jar artifacts. */ | ||
@AutoValue | ||
public abstract class AppInspectorInfo { | ||
|
||
@VisibleForTesting public static final AppInspectorInfo EMPTY = create(ImmutableList.of(), 0); | ||
|
||
public abstract ImmutableList<OutputArtifact> getJars(); | ||
|
||
public abstract int getExitCode(); | ||
|
||
public boolean isEmpty() { | ||
return getJars().isEmpty(); | ||
} | ||
|
||
public static AppInspectorInfo create(ImmutableList<OutputArtifact> jars, int exitCode) { | ||
return new AutoValue_AppInspectorInfo(jars, exitCode); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
base/src/com/google/idea/blaze/base/qsync/AppInspectorTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2023 The Bazel Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.idea.blaze.base.qsync; | ||
|
||
import com.google.common.collect.ImmutableCollection; | ||
import com.google.idea.blaze.base.scope.BlazeContext; | ||
import com.google.idea.blaze.common.Label; | ||
import com.google.idea.blaze.exception.BuildException; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
/** A service responsible for management of artifacts used by app inspectors.. */ | ||
public interface AppInspectorTracker { | ||
|
||
/** Builds the app inspector jars from the given labels */ | ||
ImmutableCollection<Path> buildAppInspector(BlazeContext context, List<Label> appInspectors) | ||
throws IOException, BuildException; | ||
} |
74 changes: 74 additions & 0 deletions
74
base/src/com/google/idea/blaze/base/qsync/AppInspectorTrackerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2023 The Bazel Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.idea.blaze.base.qsync; | ||
|
||
import com.google.common.collect.ImmutableCollection; | ||
import com.google.common.collect.Sets; | ||
import com.google.idea.blaze.base.bazel.BazelExitCode; | ||
import com.google.idea.blaze.base.scope.BlazeContext; | ||
import com.google.idea.blaze.common.Label; | ||
import com.google.idea.blaze.common.PrintOutput; | ||
import com.google.idea.blaze.exception.BuildException; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* An implementation of {@link AppInspectorTracker} service responsible for management of artifacts | ||
* used by app inspectors. | ||
*/ | ||
public class AppInspectorTrackerImpl implements AppInspectorTracker { | ||
|
||
private final AppInspectorBuilder appInspectorBuilder; | ||
private final AppInspectorArtifactTracker appInspectorArtifactTracker; | ||
|
||
public AppInspectorTrackerImpl( | ||
AppInspectorBuilder appInspectorBuilder, | ||
AppInspectorArtifactTracker appInspectorArtifactTracker) { | ||
this.appInspectorBuilder = appInspectorBuilder; | ||
this.appInspectorArtifactTracker = appInspectorArtifactTracker; | ||
} | ||
|
||
@Override | ||
public ImmutableCollection<Path> buildAppInspector( | ||
BlazeContext context, List<Label> appInspectors) throws IOException, BuildException { | ||
HashSet<Label> targets = Sets.newHashSet(appInspectors); | ||
AppInspectorInfo appInspectorInfo = appInspectorBuilder.buildAppInspector(context, targets); | ||
if (appInspectorInfo.isEmpty()) { | ||
throw new NoAppInspectorBuiltException( | ||
String.format("Building %s produced no jars.", labelsToDisplayText(appInspectors))); | ||
} | ||
|
||
if (appInspectorInfo.getExitCode() != BazelExitCode.SUCCESS) { | ||
// This will happen if there is an error in a build file, as no build actions are attempted | ||
// in that case. | ||
context.setHasWarnings(); | ||
context.output( | ||
PrintOutput.error( | ||
String.format( | ||
"There were build errors when building %s app inspector jar.", | ||
labelsToDisplayText(appInspectors)))); | ||
} | ||
|
||
return appInspectorArtifactTracker.update(targets, appInspectorInfo, context); | ||
} | ||
|
||
private static String labelsToDisplayText(List<Label> labels) { | ||
return labels.stream().map(Label::toString).collect(Collectors.joining(", ")); | ||
} | ||
} |
Oops, something went wrong.