Skip to content

Commit

Permalink
Implement GetComposeLayoutInspectorJarToken in blaze
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 577022472
  • Loading branch information
Googler authored and copybara-github committed Nov 1, 2023
1 parent fe0df78 commit ff99171
Show file tree
Hide file tree
Showing 20 changed files with 614 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public BlazeProjectSystem(Project project) {
new AndroidResourceClassPsiElementFinder(getLightResourceClassService()));
}

public Project getProject() {
return project;
}

@Override
public boolean allowsFileCreation() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public BlazeProjectSystem(Project project) {
new AndroidResourceClassPsiElementFinder(getLightResourceClassService()));
}

@Override
public Project getProject() {
return project;
}
Expand Down
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public BlazeProjectSystem(Project project) {
new AndroidResourceClassPsiElementFinder(getLightResourceClassService()));
}

public Project getProject() {
return project;
}

@Override
public boolean allowsFileCreation() {
return true;
Expand Down
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;
}
}
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 base/src/com/google/idea/blaze/base/qsync/AppInspectorBuilder.java
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 base/src/com/google/idea/blaze/base/qsync/AppInspectorInfo.java
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 base/src/com/google/idea/blaze/base/qsync/AppInspectorTracker.java
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;
}
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(", "));
}
}
Loading

0 comments on commit ff99171

Please sign in to comment.