-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow manual tags to be synced to the project (#5085)
* Adds a allow_manual_tags_sync in the .bazelproject to allow manual tags to be synced in the repo. * Add integration tests * Remove section
- Loading branch information
Showing
8 changed files
with
215 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
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
72 changes: 72 additions & 0 deletions
72
...src/com/google/idea/blaze/base/projectview/section/sections/SyncManualTargetsSection.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,72 @@ | ||
/* | ||
* Copyright 2019 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.projectview.section.sections; | ||
|
||
import com.google.idea.blaze.base.projectview.ProjectView; | ||
import com.google.idea.blaze.base.projectview.ProjectViewSet; | ||
import com.google.idea.blaze.base.projectview.parser.ParseContext; | ||
import com.google.idea.blaze.base.projectview.parser.ProjectViewParser; | ||
import com.google.idea.blaze.base.projectview.section.ProjectViewDefaultValueProvider; | ||
import com.google.idea.blaze.base.projectview.section.ScalarSection; | ||
import com.google.idea.blaze.base.projectview.section.ScalarSectionParser; | ||
import com.google.idea.blaze.base.projectview.section.SectionKey; | ||
import com.google.idea.blaze.base.projectview.section.SectionParser; | ||
import com.google.idea.blaze.base.settings.BuildSystemName; | ||
import javax.annotation.Nullable; | ||
|
||
/** If set to true, automatically derives targets from the project directories. */ | ||
public class SyncManualTargetsSection { | ||
public static final SectionKey<Boolean, ScalarSection<Boolean>> KEY = | ||
SectionKey.of("allow_manual_targets_sync"); | ||
public static final SectionParser PARSER = new SyncManualTargetsParser(); | ||
|
||
private static class SyncManualTargetsParser | ||
extends ScalarSectionParser<Boolean> { | ||
SyncManualTargetsParser() { | ||
super(KEY, ':'); | ||
} | ||
|
||
@Override | ||
@Nullable | ||
protected Boolean parseItem(ProjectViewParser parser, ParseContext parseContext, String text) { | ||
if (text.equals("true")) { | ||
return true; | ||
} | ||
if (text.equals("false")) { | ||
return false; | ||
} | ||
parseContext.addError( | ||
"'allow_manual_tags_sync' must be set to 'true' or 'false' (e.g." | ||
+ " 'allow_manual_tags_sync: true')"); | ||
return null; | ||
} | ||
|
||
@Override | ||
protected void printItem(StringBuilder sb, Boolean item) { | ||
sb.append(item); | ||
} | ||
|
||
@Override | ||
public ItemType getItemType() { | ||
return ItemType.Other; | ||
} | ||
|
||
@Override | ||
public String quickDocs() { | ||
return "If set to true, project targets will be derived from the directories."; | ||
} | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
java/tests/integrationtests/com/google/idea/blaze/java/sync/FakeBlazeQueryProvider.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,45 @@ | ||
package com.google.idea.blaze.java.sync; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.idea.blaze.base.dependencies.BlazeQueryDirectoryToTargetProvider; | ||
import com.google.idea.blaze.base.dependencies.TargetInfo; | ||
import com.google.idea.blaze.base.model.primitives.Label; | ||
import com.google.idea.blaze.base.scope.BlazeContext; | ||
import com.google.idea.blaze.base.sync.projectview.ImportRoots; | ||
import com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver; | ||
import com.intellij.openapi.project.Project; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.List; | ||
|
||
/** | ||
* Need to mock out this target provider since it attempts to execute Bazel outside of the sandbox | ||
* environment. Used primarily within JavaSyncTest to validate the behavior of the | ||
* allow_manual_targets_sync: option. | ||
*/ | ||
class FakeBlazeQueryProvider extends BlazeQueryDirectoryToTargetProvider { | ||
|
||
private static final String MANUAL_EXCLUDE_TAG = "((?!manual)"; | ||
|
||
// Need to override in order to be able to execute getQueryString(). | ||
@Nullable | ||
@Override | ||
public List<TargetInfo> doExpandDirectoryTargets( | ||
Project project, | ||
Boolean shouldManualTargetSync, | ||
ImportRoots directories, | ||
WorkspacePathResolver pathResolver, | ||
BlazeContext context) { | ||
return runQuery(project, getQueryString(directories, shouldManualTargetSync), context); | ||
} | ||
|
||
@Nullable | ||
private static ImmutableList<TargetInfo> runQuery(Project project, String query, BlazeContext context) { | ||
if (!query.contains(MANUAL_EXCLUDE_TAG)) { | ||
TargetInfo targetInfo = TargetInfo.builder(Label.create("//java/com/google:lib"), "java_library").build(); | ||
return ImmutableList.of(targetInfo); | ||
} else { | ||
return ImmutableList.of(); | ||
} | ||
} | ||
} |
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