Search in sources :

Example 1 with ProjectViewFile

use of com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile in project intellij by bazelbuild.

the class ProjectViewVerifier method verifyIncludedPackagesAreNotExcluded.

private static boolean verifyIncludedPackagesAreNotExcluded(BlazeContext context, ProjectViewSet projectViewSet) {
    boolean ok = true;
    List<WorkspacePath> includedDirectories = projectViewSet.listItems(DirectorySection.KEY).stream().filter(entry -> entry.included).map(entry -> entry.directory).collect(toList());
    for (WorkspacePath includedDirectory : includedDirectories) {
        for (ProjectViewSet.ProjectViewFile projectViewFile : projectViewSet.getProjectViewFiles()) {
            List<DirectoryEntry> directoryEntries = Lists.newArrayList();
            for (ListSection<DirectoryEntry> section : projectViewFile.projectView.getSectionsOfType(DirectorySection.KEY)) {
                directoryEntries.addAll(section.items());
            }
            for (DirectoryEntry entry : directoryEntries) {
                if (entry.included) {
                    continue;
                }
                WorkspacePath excludedDirectory = entry.directory;
                if (FileUtil.isAncestor(excludedDirectory.relativePath(), includedDirectory.relativePath(), false)) {
                    IssueOutput.error(String.format("%s is included, but that contradicts %s which was excluded", includedDirectory.toString(), excludedDirectory.toString())).inFile(projectViewFile.projectViewFile).submit(context);
                    ok = false;
                }
            }
        }
    }
    return ok;
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) SectionParser(com.google.idea.blaze.base.projectview.section.SectionParser) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) LanguageSupport(com.google.idea.blaze.base.sync.projectview.LanguageSupport) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) Sections(com.google.idea.blaze.base.projectview.section.sections.Sections) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Lists(com.google.common.collect.Lists) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) Project(com.intellij.openapi.project.Project) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) FileUtil(com.intellij.openapi.util.io.FileUtil) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) Nullable(javax.annotation.Nullable) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile)

Example 2 with ProjectViewFile

use of com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile in project intellij by bazelbuild.

the class AndroidSdkFromProjectView method getAndroidSdkPlatform.

@Nullable
public static AndroidSdkPlatform getAndroidSdkPlatform(BlazeContext context, ProjectViewSet projectViewSet) {
    List<Sdk> sdks = BlazeSdkProvider.getInstance().getAllAndroidSdks();
    if (sdks.isEmpty()) {
        IssueOutput.error("No Android SDK configured. Please use the SDK manager to configure.").navigatable(new Navigatable() {

            @Override
            public void navigate(boolean b) {
                SdkUtil.openSdkManager();
            }

            @Override
            public boolean canNavigate() {
                return true;
            }

            @Override
            public boolean canNavigateToSource() {
                return false;
            }
        }).submit(context);
        return null;
    }
    if (projectViewSet == null) {
        return null;
    }
    String androidSdk = projectViewSet.getScalarValue(AndroidSdkPlatformSection.KEY).orElse(null);
    Integer androidMinSdk = projectViewSet.getScalarValue(AndroidMinSdkSection.KEY).orElse(null);
    if (androidSdk == null) {
        ProjectViewFile projectViewFile = projectViewSet.getTopLevelProjectViewFile();
        IssueOutput.error(("No android_sdk_platform set. Please set to an android platform. " + "Available android_sdk_platforms are: " + getAvailableTargetHashesAsList(sdks))).inFile(projectViewFile != null ? projectViewFile.projectViewFile : null).submit(context);
        return null;
    }
    Sdk sdk = BlazeSdkProvider.getInstance().findSdk(androidSdk);
    if (sdk == null) {
        ProjectViewFile projectViewFile = projectViewSet.getTopLevelProjectViewFile();
        IssueOutput.error(("No such android_sdk_platform: '" + androidSdk + "'. " + "Available android_sdk_platforms are: " + getAvailableTargetHashesAsList(sdks) + ". " + "Please change android_sdk_platform or run SDK manager " + "to download missing SDK platforms.")).inFile(projectViewFile != null ? projectViewFile.projectViewFile : null).submit(context);
        return null;
    }
    if (androidMinSdk == null) {
        androidMinSdk = getAndroidSdkApiLevel(sdk);
    }
    return new AndroidSdkPlatform(androidSdk, androidMinSdk);
}
Also used : AndroidSdkPlatform(com.google.idea.blaze.android.sync.model.AndroidSdkPlatform) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) Sdk(com.intellij.openapi.projectRoots.Sdk) Navigatable(com.intellij.pom.Navigatable) Nullable(javax.annotation.Nullable)

Example 3 with ProjectViewFile

use of com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile in project intellij by bazelbuild.

the class BlazeEditProjectViewControl method updateBuilder.

public void updateBuilder(BlazeNewProjectBuilder builder) {
    String projectName = projectNameField.getText().trim();
    File projectDataDirectoryFile = new File(projectDataDirField.getText().trim());
    if (workspaceOption.allowProjectDataInVcs()) {
        projectDataDirectoryFile = new File(projectDataDirectoryFile, BlazeDataStorage.PROJECT_DATA_SUBDIRECTORY);
    }
    String projectDataDirectory = projectDataDirectoryFile.getPath();
    File localProjectViewFile = ProjectViewStorageManager.getLocalProjectViewFileName(builder.getBuildSystem(), new File(projectDataDirectory));
    BlazeSelectProjectViewOption selectProjectViewOption = builder.getProjectViewOption();
    boolean useSharedProjectView = projectViewUi.getUseSharedProjectView();
    // If we're using a shared project view, synthesize a local one that imports the shared one
    ProjectViewSet parseResult = projectViewUi.parseProjectView(Lists.newArrayList());
    final ProjectView projectView;
    final ProjectViewSet projectViewSet;
    if (useSharedProjectView && selectProjectViewOption.getSharedProjectView() != null) {
        projectView = ProjectView.builder().add(ScalarSection.builder(ImportSection.KEY).set(selectProjectViewOption.getSharedProjectView())).build();
        projectViewSet = ProjectViewSet.builder().addAll(parseResult.getProjectViewFiles()).add(localProjectViewFile, projectView).build();
    } else {
        ProjectViewSet.ProjectViewFile projectViewFile = parseResult.getTopLevelProjectViewFile();
        assert projectViewFile != null;
        projectView = projectViewFile.projectView;
        projectViewSet = parseResult;
    }
    builder.setProjectView(projectView).setProjectViewFile(localProjectViewFile).setProjectViewSet(projectViewSet).setProjectName(projectName).setProjectDataDirectory(projectDataDirectory);
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) BlazeSelectProjectViewOption(com.google.idea.blaze.base.wizard2.BlazeSelectProjectViewOption) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) File(java.io.File) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile)

Example 4 with ProjectViewFile

use of com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile in project intellij by bazelbuild.

the class BlazeEditProjectViewControl method modifyInitialProjectView.

private static String modifyInitialProjectView(BuildSystem buildSystem, String initialProjectViewText, WorkspacePathResolver workspacePathResolver) {
    BlazeContext context = new BlazeContext();
    ProjectViewParser projectViewParser = new ProjectViewParser(context, workspacePathResolver);
    projectViewParser.parseProjectView(initialProjectViewText);
    ProjectViewSet projectViewSet = projectViewParser.getResult();
    ProjectViewFile projectViewFile = projectViewSet.getTopLevelProjectViewFile();
    if (projectViewFile == null) {
        return initialProjectViewText;
    }
    ProjectView projectView = projectViewFile.projectView;
    // Sort default value providers to match the section order
    List<SectionKey> sectionKeys = Sections.getParsers().stream().map(SectionParser::getSectionKey).collect(toList());
    List<ProjectViewDefaultValueProvider> defaultValueProviders = Lists.newArrayList(ProjectViewDefaultValueProvider.EP_NAME.getExtensions());
    defaultValueProviders.sort(Comparator.comparingInt(val -> sectionKeys.indexOf(val.getSectionKey())));
    for (ProjectViewDefaultValueProvider defaultValueProvider : defaultValueProviders) {
        projectView = defaultValueProvider.addProjectViewDefaultValue(buildSystem, projectViewSet, projectView);
    }
    return ProjectViewParser.projectViewToString(projectView);
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ScalarSection(com.google.idea.blaze.base.projectview.section.ScalarSection) LanguageSupport(com.google.idea.blaze.base.sync.projectview.LanguageSupport) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) Sections(com.google.idea.blaze.base.projectview.section.sections.Sections) JBLabel(com.intellij.ui.components.JBLabel) JPanelProvidingProject(com.google.idea.blaze.base.settings.ui.JPanelProvidingProject) UiUtil(com.google.idea.blaze.base.ui.UiUtil) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) BorderLayout(java.awt.BorderLayout) ProgressManager(com.intellij.openapi.progress.ProgressManager) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) BlazeValidationResult(com.google.idea.blaze.base.ui.BlazeValidationResult) RecentProjectsManager(com.intellij.ide.RecentProjectsManager) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) BorderFactory(javax.swing.BorderFactory) ProjectViewDefaultValueProvider(com.google.idea.blaze.base.projectview.section.ProjectViewDefaultValueProvider) TextComponentAccessor(com.intellij.openapi.ui.TextComponentAccessor) Component(java.awt.Component) JRadioButton(javax.swing.JRadioButton) TargetSection(com.google.idea.blaze.base.projectview.section.sections.TargetSection) Propagation(com.google.idea.blaze.base.scope.OutputSink.Propagation) List(java.util.List) SystemProperties(com.intellij.util.SystemProperties) ImportSection(com.google.idea.blaze.base.projectview.section.sections.ImportSection) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) GridBagLayout(java.awt.GridBagLayout) NotNull(org.jetbrains.annotations.NotNull) JPanel(javax.swing.JPanel) SectionParser(com.google.idea.blaze.base.projectview.section.SectionParser) SectionKey(com.google.idea.blaze.base.projectview.section.SectionKey) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeSelectWorkspaceOption(com.google.idea.blaze.base.wizard2.BlazeSelectWorkspaceOption) JTextField(javax.swing.JTextField) Paths(com.intellij.history.core.Paths) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) Hashing(com.google.common.hash.Hashing) Lists(com.google.common.collect.Lists) BuildSystem(com.google.idea.blaze.base.settings.Blaze.BuildSystem) Scope(com.google.idea.blaze.base.scope.Scope) BlazeDataStorage(com.google.idea.blaze.base.sync.data.BlazeDataStorage) BoolExperiment(com.google.idea.common.experiments.BoolExperiment) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) Nullable(javax.annotation.Nullable) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) ProjectDataDirectoryValidator(com.google.idea.blaze.base.wizard2.ProjectDataDirectoryValidator) ButtonGroup(javax.swing.ButtonGroup) HashCode(com.google.common.hash.HashCode) ProjectViewParser(com.google.idea.blaze.base.projectview.parser.ProjectViewParser) StringUtil(com.intellij.openapi.util.text.StringUtil) BlazeSelectProjectViewOption(com.google.idea.blaze.base.wizard2.BlazeSelectProjectViewOption) IOException(java.io.IOException) BlazeNewProjectBuilder(com.google.idea.blaze.base.wizard2.BlazeNewProjectBuilder) ProjectViewStorageManager(com.google.idea.blaze.base.projectview.ProjectViewStorageManager) Disposable(com.intellij.openapi.Disposable) File(java.io.File) Category(com.google.idea.blaze.base.scope.output.IssueOutput.Category) JScrollPane(javax.swing.JScrollPane) Collectors.toList(java.util.stream.Collectors.toList) BlazeValidationError(com.google.idea.blaze.base.ui.BlazeValidationError) ProjectViewVerifier(com.google.idea.blaze.base.projectview.ProjectViewVerifier) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) ProjectViewUi(com.google.idea.blaze.base.settings.ui.ProjectViewUi) JLabel(javax.swing.JLabel) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Comparator(java.util.Comparator) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) SectionKey(com.google.idea.blaze.base.projectview.section.SectionKey) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) ProjectViewDefaultValueProvider(com.google.idea.blaze.base.projectview.section.ProjectViewDefaultValueProvider) ProjectViewParser(com.google.idea.blaze.base.projectview.parser.ProjectViewParser)

Example 5 with ProjectViewFile

use of com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile in project intellij by bazelbuild.

the class AlwaysPresentGoSyncPlugin method validateProjectView.

@Override
public boolean validateProjectView(@Nullable Project project, BlazeContext context, ProjectViewSet projectViewSet, WorkspaceLanguageSettings workspaceLanguageSettings) {
    if (workspaceLanguageSettings.isLanguageActive(LanguageClass.GO) && !isGoPluginSupported()) {
        IssueOutput.error(String.format("Go is no longer supported by the %s plugin with IntelliJ Community Edition.\n" + "Please install Ultimate Edition and upgrade to the JetBrains Go plugin", Blaze.defaultBuildSystemName())).submit(context);
        return false;
    }
    if (goWorkspaceTypeSupported() || !workspaceLanguageSettings.isWorkspaceType(WorkspaceType.GO)) {
        return true;
    }
    ProjectViewFile topLevelProjectViewFile = projectViewSet.getTopLevelProjectViewFile();
    String msg = "Go workspace_type is no longer supported. Please add 'go' to " + "additional_languages instead";
    boolean fixable = project != null && topLevelProjectViewFile != null && topLevelProjectViewFile.projectView.getScalarValue(WorkspaceTypeSection.KEY) == WorkspaceType.GO;
    msg += fixable ? ". Click here to fix your .blazeproject and resync." : ", then resync.";
    IssueOutput.error(msg).navigatable(!fixable ? null : new NavigatableAdapter() {

        @Override
        public void navigate(boolean requestFocus) {
            fixLanguageSupport(project);
        }
    }).submit(context);
    return false;
}
Also used : ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) NavigatableAdapter(com.intellij.pom.NavigatableAdapter)

Aggregations

ProjectViewFile (com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile)10 File (java.io.File)6 Nullable (javax.annotation.Nullable)4 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)3 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)3 SectionParser (com.google.idea.blaze.base.projectview.section.SectionParser)3 DirectoryEntry (com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry)3 Lists (com.google.common.collect.Lists)2 FileOperationProvider (com.google.idea.blaze.base.io.FileOperationProvider)2 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)2 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)2 DirectorySection (com.google.idea.blaze.base.projectview.section.sections.DirectorySection)2 Sections (com.google.idea.blaze.base.projectview.section.sections.Sections)2 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)2 IssueOutput (com.google.idea.blaze.base.scope.output.IssueOutput)2 BlazeSyncPlugin (com.google.idea.blaze.base.sync.BlazeSyncPlugin)2 LanguageSupport (com.google.idea.blaze.base.sync.projectview.LanguageSupport)2 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)2 WorkspacePathResolver (com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver)2 BlazeSelectProjectViewOption (com.google.idea.blaze.base.wizard2.BlazeSelectProjectViewOption)2