From 54d3a4bc493546c641b96f2f0b63d0f8f739abb8 Mon Sep 17 00:00:00 2001 From: Stephan Janssen Date: Fri, 8 Nov 2024 10:47:06 +0100 Subject: [PATCH] Feature #325: Exclude specific files by name --- build.gradle.kts | 2 +- .../service/DevoxxGenieSettingsService.java | 2 + .../projectscanner/ProjectScannerService.java | 20 +++++- .../ui/settings/DevoxxGenieStateService.java | 4 ++ .../CopyProjectSettingsComponent.java | 66 ++++++++++++++++++- .../CopyProjectSettingsConfigurable.java | 23 +++---- src/main/resources/META-INF/plugin.xml | 2 +- src/main/resources/application.properties | 4 +- 8 files changed, 102 insertions(+), 21 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 9b0ebc8a..1f377e22 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "com.devoxx.genie" -version = "0.2.26" +version = "0.2.27" repositories { mavenCentral() diff --git a/core/src/main/java/com/devoxx/genie/service/DevoxxGenieSettingsService.java b/core/src/main/java/com/devoxx/genie/service/DevoxxGenieSettingsService.java index a1ec3a0f..b773b9a2 100644 --- a/core/src/main/java/com/devoxx/genie/service/DevoxxGenieSettingsService.java +++ b/core/src/main/java/com/devoxx/genie/service/DevoxxGenieSettingsService.java @@ -90,6 +90,8 @@ public interface DevoxxGenieSettingsService { Integer getDefaultWindowContext(); + List getExcludedFiles(); + void setCustomPrompts(List customPrompts); void setLanguageModels(List languageModels); diff --git a/src/main/java/com/devoxx/genie/service/projectscanner/ProjectScannerService.java b/src/main/java/com/devoxx/genie/service/projectscanner/ProjectScannerService.java index e2798084..9a5de124 100644 --- a/src/main/java/com/devoxx/genie/service/projectscanner/ProjectScannerService.java +++ b/src/main/java/com/devoxx/genie/service/projectscanner/ProjectScannerService.java @@ -312,7 +312,15 @@ private boolean shouldExcludeDirectory(@NotNull VirtualFile file) { * @return true if the file should be excluded, false otherwise */ private boolean shouldExcludeFile(@NotNull VirtualFile file) { - if (DevoxxGenieStateService.getInstance().getUseGitIgnore()) { + DevoxxGenieSettingsService settings = DevoxxGenieStateService.getInstance(); + + // Check if file is in excluded files list + if (settings.getExcludedFiles().contains(file.getName())) { + return true; + } + + // Check gitignore if enabled + if (settings.getUseGitIgnore()) { if (gitignoreParser != null) { Path path = Paths.get(file.getPath()); return gitignoreParser.matches(path); @@ -329,9 +337,15 @@ private boolean shouldExcludeFile(@NotNull VirtualFile file) { */ private boolean shouldIncludeFile(@NotNull VirtualFile file) { DevoxxGenieSettingsService settings = DevoxxGenieStateService.getInstance(); + + // First check if file should be excluded + if (shouldExcludeFile(file)) { + return false; + } + + // Then check if extension is included String extension = file.getExtension(); - boolean includedByExtension = extension != null && settings.getIncludedFileExtensions().contains(extension.toLowerCase()); - return includedByExtension && !shouldExcludeFile(file); + return extension != null && settings.getIncludedFileExtensions().contains(extension.toLowerCase()); } /** diff --git a/src/main/java/com/devoxx/genie/ui/settings/DevoxxGenieStateService.java b/src/main/java/com/devoxx/genie/ui/settings/DevoxxGenieStateService.java index 97398160..c7edd048 100644 --- a/src/main/java/com/devoxx/genie/ui/settings/DevoxxGenieStateService.java +++ b/src/main/java/com/devoxx/genie/ui/settings/DevoxxGenieStateService.java @@ -32,6 +32,10 @@ public static DevoxxGenieStateService getInstance() { return ApplicationManager.getApplication().getService(DevoxxGenieStateService.class); } + private List excludedFiles = new ArrayList<>(Arrays.asList( + "package-lock.json", "yarn.lock", "pom.xml", "build.gradle", "settings.gradle" + )); + private List customPrompts = new ArrayList<>(); private List languageModels = new ArrayList<>(); diff --git a/src/main/java/com/devoxx/genie/ui/settings/copyproject/CopyProjectSettingsComponent.java b/src/main/java/com/devoxx/genie/ui/settings/copyproject/CopyProjectSettingsComponent.java index 08b51fd4..9252ba0b 100644 --- a/src/main/java/com/devoxx/genie/ui/settings/copyproject/CopyProjectSettingsComponent.java +++ b/src/main/java/com/devoxx/genie/ui/settings/copyproject/CopyProjectSettingsComponent.java @@ -1,6 +1,5 @@ package com.devoxx.genie.ui.settings.copyproject; -import com.devoxx.genie.service.DevoxxGenieSettingsService; import com.devoxx.genie.ui.settings.AbstractSettingsComponent; import com.devoxx.genie.ui.settings.DevoxxGenieStateService; import com.intellij.ui.AddEditRemovePanel; @@ -19,6 +18,7 @@ public class CopyProjectSettingsComponent extends AbstractSettingsComponent { private final ExcludedDirectoriesPanel excludedDirectoriesPanel; + private final ExcludedFilesPanel excludedFilesPanel; // New panel for excluded files private final IncludedFileExtensionsPanel includedFileExtensionsPanel; private final JCheckBox excludeJavadocCheckBox; private final JCheckBox useGitIgnoreCheckBox; @@ -27,6 +27,7 @@ public CopyProjectSettingsComponent() { DevoxxGenieStateService settings = DevoxxGenieStateService.getInstance(); useGitIgnoreCheckBox = new JCheckBox("Use .gitignore", settings.getUseGitIgnore()); excludedDirectoriesPanel = new ExcludedDirectoriesPanel(settings.getExcludedDirectories()); + excludedFilesPanel = new ExcludedFilesPanel(settings.getExcludedFiles()); // Initialize the new panel includedFileExtensionsPanel = new IncludedFileExtensionsPanel(settings.getIncludedFileExtensions()); excludeJavadocCheckBox = new JCheckBox("Exclude Javadoc", settings.getExcludeJavaDoc()); } @@ -46,6 +47,7 @@ public JPanel createPanel() { JPanel contentPanel = new JPanel(); contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS)); contentPanel.add(excludedDirectoriesPanel); + contentPanel.add(excludedFilesPanel); contentPanel.add(createUseGitIgnorePanel()); @@ -103,7 +105,7 @@ public List getIncludedFileExtensions() { private static class ExcludedDirectoriesPanel extends AddEditRemovePanel { public ExcludedDirectoriesPanel(List initialData) { - super(new ExcludedDirectoriesModel(), initialData, "Excluded Directories"); + super(new ExcludedDirectoriesModel(), initialData, "Excluded directories"); setPreferredSize(new Dimension(400, 200)); } @@ -139,7 +141,7 @@ protected String editItem(String item) { private static class IncludedFileExtensionsPanel extends AddEditRemovePanel { public IncludedFileExtensionsPanel(List initialData) { - super(new IncludedFileExtensionsModel(), initialData, "Included File Extensions"); + super(new IncludedFileExtensionsModel(), initialData, "Included file extensions"); setPreferredSize(new Dimension(400, 200)); } @@ -177,6 +179,10 @@ public boolean getExcludeJavadoc() { return excludeJavadocCheckBox.isSelected(); } + public List getExcludedFiles() { + return excludedFilesPanel.getData(); + } + public boolean getUseGitIgnore() { return useGitIgnoreCheckBox.isSelected(); } @@ -216,4 +222,58 @@ public Object getField(String o, int columnIndex) { return o; } } + + private static class ExcludedFilesPanel extends AddEditRemovePanel { + public ExcludedFilesPanel(List initialData) { + super(new ExcludedFilesModel(), initialData, "Excluded files"); + setPreferredSize(new Dimension(400, 200)); + } + + @Override + protected String addItem() { + return showEditDialog(""); + } + + @Override + protected boolean removeItem(String item) { + return true; + } + + @Override + protected String editItem(String item) { + return showEditDialog(item); + } + + private @Nullable String showEditDialog(String initialValue) { + JBTextField field = new JBTextField(initialValue); + JPanel panel = new JPanel(new BorderLayout()); + panel.add(new JLabel("File name:"), BorderLayout.NORTH); + panel.add(field, BorderLayout.CENTER); + panel.setBorder(JBUI.Borders.empty(10)); + + int result = JOptionPane.showConfirmDialog(this, panel, "Enter File Name", JOptionPane.OK_CANCEL_OPTION); + if (result == JOptionPane.OK_OPTION) { + return field.getText().trim(); + } + return null; + } + } + + private static class ExcludedFilesModel extends AddEditRemovePanel.TableModel { + @Override + public int getColumnCount() { + return 1; + } + + @Contract(pure = true) + @Override + public @NotNull String getColumnName(int columnIndex) { + return "File Name"; + } + + @Override + public Object getField(String o, int columnIndex) { + return o; + } + } } diff --git a/src/main/java/com/devoxx/genie/ui/settings/copyproject/CopyProjectSettingsConfigurable.java b/src/main/java/com/devoxx/genie/ui/settings/copyproject/CopyProjectSettingsConfigurable.java index 97e4963a..37e42273 100644 --- a/src/main/java/com/devoxx/genie/ui/settings/copyproject/CopyProjectSettingsConfigurable.java +++ b/src/main/java/com/devoxx/genie/ui/settings/copyproject/CopyProjectSettingsConfigurable.java @@ -1,16 +1,17 @@ package com.devoxx.genie.ui.settings.copyproject; -import com.devoxx.genie.service.DevoxxGenieSettingsService; import com.devoxx.genie.ui.settings.DevoxxGenieStateService; import com.intellij.openapi.options.Configurable; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.util.List; public class CopyProjectSettingsConfigurable implements Configurable { private CopyProjectSettingsComponent copyProjectSettingsComponent; + private final DevoxxGenieStateService stateService = DevoxxGenieStateService.getInstance(); @Nls(capitalization = Nls.Capitalization.Title) @Override @@ -27,20 +28,20 @@ public JComponent createComponent() { @Override public boolean isModified() { - DevoxxGenieStateService settings = DevoxxGenieStateService.getInstance(); - return !copyProjectSettingsComponent.getExcludedDirectories().equals(settings.getExcludedDirectories()) || - !copyProjectSettingsComponent.getIncludedFileExtensions().equals(settings.getIncludedFileExtensions()) || - copyProjectSettingsComponent.getExcludeJavadoc() != settings.getExcludeJavaDoc() || - copyProjectSettingsComponent.getUseGitIgnore() != settings.getUseGitIgnore(); + return !copyProjectSettingsComponent.getExcludedDirectories().equals(stateService.getExcludedDirectories()) || + !copyProjectSettingsComponent.getExcludedFiles().equals(stateService.getExcludedFiles()) || // Add check for excluded files + !copyProjectSettingsComponent.getIncludedFileExtensions().equals(stateService.getIncludedFileExtensions()) || + copyProjectSettingsComponent.getExcludeJavadoc() != stateService.getExcludeJavaDoc() || + copyProjectSettingsComponent.getUseGitIgnore() != stateService.getUseGitIgnore(); } @Override public void apply() { - DevoxxGenieStateService settings = DevoxxGenieStateService.getInstance(); - settings.setExcludedDirectories(copyProjectSettingsComponent.getExcludedDirectories()); - settings.setIncludedFileExtensions(copyProjectSettingsComponent.getIncludedFileExtensions()); - settings.setExcludeJavaDoc(copyProjectSettingsComponent.getExcludeJavadoc()); - settings.setUseGitIgnore(copyProjectSettingsComponent.getUseGitIgnore()); + stateService.setExcludedDirectories(copyProjectSettingsComponent.getExcludedDirectories()); + stateService.setExcludedFiles(copyProjectSettingsComponent.getExcludedFiles()); // Save excluded files + stateService.setIncludedFileExtensions(copyProjectSettingsComponent.getIncludedFileExtensions()); + stateService.setExcludeJavaDoc(copyProjectSettingsComponent.getExcludeJavadoc()); + stateService.setUseGitIgnore(copyProjectSettingsComponent.getUseGitIgnore()); } @Override diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 08656f58..f8668dc0 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -37,7 +37,7 @@ v0.2.26
    -
  • +
  • Feature #325: Exclude a single file for 'Scan & Copy Project'

v0.2.25

    diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 6fe07bc6..3c0bb4de 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,2 @@ -#Wed Oct 23 11:16:36 EEST 2024 -version=0.2.24 +#Fri Nov 08 10:42:04 CET 2024 +version=0.2.27