How to hide unnecessary files from intellij project view? - java

Given a sample gradle project with project structure as shown:
As you can see there are bunch of stuff you actually dont ever need to see in idea but you need them to exist...
I know about ignored file/folder types under Editor/File Types but those are affecting the libs and projects, idea will ignore them everywhere while i only need to hide few unnecessary entries in project view.
Primary question : how do we hide them from project view?
Also for very big projects somethimes it is easy if some related modules are shown one after another... but do not do like that alphabeticaly.
Secondary question : is it possible to have customized order in project view?
I'm using Intellij 15 EAP IU-142.5047.6

Usually I use the Scopes support for filtering out/in elements.
I like this support and it can be use as the scope for other tool windows such as Hierarchy Call, and Find in path dialog. Moreover you can have many scopes and easily switch between them. The support for scratch files and version control - change sets - benefits from scopes support.
In order to create a new Scope:
open Settings > Appearance & Behavior > Scopes
Create a new scope by clicking on + icon
and then use include/exclude (recursively)
Kind regards

In IntelliJ, version 2022.1.3 Ultimate Edition:
Settings -> Editor-> File types
select "Ignored Files and Folders" tab
Click on the "+" sign to add the file extension to be ignored (files with this extension will not be displayed in the "Project" view).

Related

How to hide .class files in VS Code? [duplicate]

In Visual Studio Code, what setting can be configured, using file patterns, to hide files from view in the sidebar's file-explorer?
I would like to hide certain groups of files, like .meta and .git files.
You can configure patterns to hide files and folders from the explorer and searches.
Open VS User Settings (Main menu: File > Preferences > Settings). This will open the setting screen.
Search for files:exclude in the search at the top.
Configure the User Setting with new glob patterns as needed. In this case add this pattern node_modules/ then click OK. The pattern syntax is powerful. You can find pattern matching details under the Search Across Files topic.
When you are done it should look something like this:
If you want to directly edit the settings file:
For example to hide a top level node_modules folder in your workspace:
"files.exclude": {
"node_modules/": true
}
To hide all files that start with ._ such as ._.DS_Store files found on OSX:
"files.exclude": {
"**/._*": true
}
You also have the ability to change Workspace Settings (Main menu: File > Preferences > Workspace Settings). Workspace settings will create a .vscode/settings.json file in your current workspace and will only be applied to that workspace. User Settings will be applied globally to any instance of VS Code you open, but they won't override Workspace Settings if present. Read more on customizing User and Workspace Settings.
Sometimes you just want to hide certain file types for a specific project. In that case, you can create a folder in your project folder called .vscode and create the settings.json file in there, (i.e. .vscode/settings.json). All settings within that file will affect your current workspace only.
For example, in a TypeScript project, this is what I have used:
// Workspace settings
{
// The following will hide the js and map files in the editor
"files.exclude": {
"**/*.js": true,
"**/*.map": true
}
}
The "Make Hidden" extension works great!
Make Hidden provides more control over your project's directory by enabling context menus that allow you to perform hide/show actions effortlessly, a view pane explorer to see hidden items and the ability to save workspaces to quickly toggle between bulk hidden items.
The __pycache__ folder and *.pyc files are totally unnecessary to the developer. To hide these files from the explorer view, we need to edit the settings.json for VSCode. Add the folder and the files as shown below:
"files.exclude": {
...
...
"**/*.pyc": {"when": "$(basename).py"},
"**/__pycache__": true,
...
...
}
I would also like to recommend vscode extension Peep, which allows you to toggle hide on the excluded files in your projects settings.json.
Hit F1 for vscode command line (command palette), then
ext install [enter] peep [enter]
You can bind "extension.peepToggle" to a key like Ctrl+Shift+P (same as F1 by default) for easy toggling. Hit Ctrl+K Ctrl+S for key bindings, enter peep, select Peep Toggle and add your binding.
For .meta files while using Unity3D, I found the best pattern for hiding is:
"files.exclude": {
"*/**/**.meta": true
}
This captures all folders and subfolders, and will pick up foo.cs.meta in addition to foo.meta
If you're using VSCode:
File > Preferences > Settings
Search for:
files:exclude
Then add
**/node_modules
Click OK.
You shouldn't need to restart or reload VSCode to take effect
2022 New File-explorer Features
There are a couple very cool new features that let devs configure the files that show in the sidebar, as well as offering new ways of hiding files, while keeping them accessible.
This answer covers
"explorer.fileNesting" (NEW as of April-2022)
"files.exclude"
explorer.excludeGitIgnore (new as of June-2022)
File Excludes
So the best answer included in this post, originally, was the "files.exclude"
VS Code's File Nesting Feature
Because "File Nesting" is IMO one of the coolest features added to VS Code in recent releases, I thought I'd take the time to create a animated GIF-image that shows how it works in real-time.
Below is a .gif image that shows the explorer.fileNesting feature being used in Real-time
File nesting is very cool, it is important to note, like most VS Code features, it does need to be custom configured for your personal development environment.
Personally I find this is a good addition for the workspace scoped settings.json configuration file. Unless you only ever use VS Code for developing the same type of projects, using the same project template, over & over again (which I understand some people do) I suggest using it to configure each individual project.
An alternative is per-language configuration. I don't use it this way, but it is very helpful with TypeScript's tsc emissions. For Example .d.ts files & *map files, they can configured to always be nested into *.js files, with the same name. Or the *.js files can be configured to nest under the *.ts files.
The above two notes point out that this is a feature aimed at improving the environment for compiled languages that have a compiler that emits project-build files; and specifically "transpilers" like TypeScript in other words,
Below shows a "File Nesting" configuration that you'll likely find written to "./.vscode/settings.json" file that belongs to a TypeScript project.
"explorer.fileNesting.patterns": {
"*.ts": "${capture}.js",
"*.js": "${capture}.js.map, ${capture}.min.js, ${capture}.d.ts",
"*.mts": "${capture}.mjs, ${capture}.d.mts",
"*.mjs": "${capture}.mjs.map, ${capture}.min.mjs, ${capture}.d.mts",
"*.cts": "${capture}.js",
"*.cjs": "${capture}.js.map, ${capture}.min.js, ${capture}.d.ts",
"*.jsx": "${capture}.js",
"*.tsx": "${capture}.ts",
}
The above configuration is actually from one of my projects, and it results in the following behavior:
I have included below, a complete list of All available configurations, as well as the link to the official release-notes (early form of documentation) that covers the "VS Code File-nesting Feature".
As of 2022-06-17 the following list contains all configurations available for "VS Code's File Nesting Feature".
explorer.fileNesting.enabled
Controls whether file nesting is enabled at-large. It can be set either globally or for a specific workspace.
explorer.fileNesting.expand
Controls whether nested files are expanded by default.
explorer.fileNesting.patterns
Controls how files are nested. The default configuration provides nesting intelligence for TypeScript and JavaScript projects, but you're encouraged to modify this to fit your own project's structure. Some examples:
VS CODE'S OFFICIAL RELEASE NOTES ON THE NEW FILE NESTING FEATURE
File Excludes
NOTE: "File excludes, has been covered by other answers so I will be brief."
"It's important we cover files.exclude though, as the next feature builds on it."
File-nesting is awesome, but don't exclude files.exclude Just yet. Comparing features like explorer.fileNesting, and files.exclude against each-other is not very helpful. It is actually best to look at the new "File Nesting" feature as either an alternative to files.exclude, or as a complementing feature to files.exclude. There's no need to go indepth about using explorer.fileNesting as an alternative, so lets talk a bit about it complimenting files.exclude.
There are several ways you can use the two settings to configure your projects "file-explorer" (the file-tree in the side-bar). I use both explorer.fileNesting & "files.exclude". I nest certain groups of files that obviously share somthing in common. A common example given in the official docs for the file nesting feature is using file nesting to hide your package-lock.json file under your package.json file, which is obviously a great way to make use of file nesting.
However I take it a step further: I also hide my .npmrc file, and if I am writing an NPM-Package, I hide my .npmignore file with the package files too.
Here are two groups I create
package.json
package-lock.json
.npmignore
.npmrc
eslintrc.json
.eslintignore
.prettierrc
.markdownlintrc
The problem is with file nesting, you get a bunch of 1-offs, like .editorconfig (ya I can place it with my .eslintrc.json group, but it doesn't really fit their. And what about .gitignore. I suppose I could just leave .gitignore in the view.
Or I could use files.exclude, and configure my "files.exclude": {} object in my project's .vscode/settings.json file to hide files like .gitignore, LICENSE, .editorconfig, etc...
I can also use it to hide directorys this is somthing File Nesting cannot do. I use it to hide my "build" dir & "node_modules" dir.
By default, files.exclude hides project's .git/ directory, which is why you never see it.
Below is the default configuration I use for ESM NodeJS TypeScript projects, which is what most of my projects are. The configuration is generic, and changes from project to project.
"files.exclude": {
// -------- PROJECT DIRECTORIES --------
"**/.git/": true,
"node_modules/": true,
"out/": true,
"typings/": true,
// ------- PROJECT FILES -------
"LICENSE": true,
"README.md": true
},
"explorer.fileNesting.patterns": {
"*.ts": "${capture}.js",
"*.js": "${capture}.js.map, ${capture}.min.js, ${capture}.d.ts",
"*.jsx": "${capture}.js",
"*.tsx": "${capture}.ts",
".eslintrc.*": ".eslintignore, .editorconfig, .prettierrc",
"tsconfig.json": "tsconfig.*.json, package.json, .gitignore",
},
The Latest Feature of the Bunch, Which I Edited in a bit after editing in File Nesting's new settings, is the new...
GitIgnore Exclude Feature
This feature allows you to configure VS Code to treat entries in your .gitignore file, as if they were included in your files.exclude object. The means that the File Explorer actually parses your .gitignore file, and reads its contents, then hides the files you configure it too.
To configure the setting to on use explorer.excludeGitIgnore.
Remember, this setting, like the other two features, should not be thought of from a perspective of,
"Is "GitIgnore Exclude" better than "Files Exclude"?
Its unhelpful, and counter productive to think in this way. Git Excludes (as the release notes say)...
...works alongside files.exclude to hide unwanted files from the Explorer.
       ~ VS Code Release Notes v1.68
You can read more about GitIgnore Excludes Here
If your working on a Angular 2+ application, and like me you like a clean working environment, follow #omt66 answer and paste the below in your settings.json file.
I recommend you do this once all the initial setup has been completed.
Note: This will actually hide the .vscode folder (with settings.json) in as well. (Open in your native file explorer / text editor if you need to make changes afterwards)
https://pastebin.com/X2NL6Vxb
{
"files.exclude": {
".vscode":true,
"node_modules/":true,
"dist/":true,
"e2e/":true,
"*.json": true,
"**/*.md": true,
".gitignore": true,
"**/.gitkeep":true,
".editorconfig": true,
"**/polyfills.ts": true,
"**/main.ts": true,
"**/tsconfig.app.json": true,
"**/tsconfig.spec.json": true,
"**/tslint.json": true,
"**/karma.conf.js": true,
"**/favicon.ico": true,
"**/browserslist": true,
"**/test.ts": true
}
}
The accepted answer is perfect if you're looking to hide something like node_modules.
In the case you're working with a static meta-framework like Astro.js, you'll end up with index.astro files but also get a lot of noise because of dist/test/index.html or /dist/about-page/index.html etc... pages.
To exclude them from the command palette search but still be able to inspect the dist folder in your files tree, I recommend using the following in a .vscode/settings.json file
{
"search.exclude": {
"dist/**": true
}
}
That way, you still keep it visible while not having it polluting your ctrl + p search.
PS: more info can be found here (submit the URL again after opening it to go to the highlight directly).
I had the same problem in the past as I was looking to remove the .class files generated after we suceessfully run .java files so .class files are created automatically after compilation and .exe files are created after compiling C or C++ code.
The most simple method to do this is to change your workspace settings by pressing F1 and selecting Preferences: Open Workspace Settings from the popup. After that scroll to the Files: Exclude row and add a tag - **/*.class in the list and now the .class files will not be shown in the Vscode Project File Explorer.
You can do the same method to remove .exe files by using the tag **/*.exe
for C & C++ files.
Thanks
Manpreet Singh
Open Settings and search for Files.Exclude then click on add pattern then it will give a notification
Unable to write into user settings. Please open the user settings to correct errors/warnings in it and try again.
Now open that settings.json file and search for files.exclude{ } block and include
"**/*.exe": true Here I use .exe as example, Instead of that use the extension whatever you want to block.
I hope this helps.

How can SonarQube be used to view results for specific directories (packages) of a project?

I want to investigate how certain rules and issues have been violated in a certain package, however, from what I have seen in the Components-interface in SonarQube, it is only possible to view leaf node-directories and I am interested in viewing the entire folder, including sub-folders and files in that folder.
E.g.
Project
src
package1
subdirectoryone
done
code-a.java
dtwo
code-x.java
dthree
code-i.java
code-1.java
code-2.java
subdirectorytwo
package2
subdirone
subdirtwo
In this example I would like to investigate the issues and rule violations in subdirectoryone including the code files at all levels in the directory.
Is there a way I can do this?
I use something like this:
<sonar.projectName>Some project name (com/your-directory only)</sonar.projectName>
<sonar.exclusions>org/**/*, com/acme/**/*</sonar.exclusions>
<sonar.test.exclusions>org/**/*, com/acme/**/*</sonar.test.exclusions>
<sonar.sources>${project.build.sourceDirectory}/com/your-directory</sonar.sources>
This excludes everything but the code I want to be analyzed (exclusions properties) and define my source dir as ${project.build.sourceDirectory}/com/your-directory (this is where the code I want to be analyzed is)
Then the analysis is run using maven:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package -Dtest=com/your-directory/**/*Test.java
(note the -Dtest= restriction for the tests)
Some reading: http://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus
In SonarQube 4.5 if you start from the dashboard and click the Issues link you will see all the issues for every module. In the left box below the lists of Severities and Rules is a list of all the modules and sub-modules in your project. If you select from that list it will narrow down the centre and right boxes to just the packages and files within that module. Unfortunately it doesn't filter the rules or severities in the top boxes.
In SonarQube 5.3 if you go to the issues tab you can select the module checkbox on the left side and select from your high runners. Near the top of the page is a hierarchy for the module you selected which you can click on to see the dashboard for that module or sub-module and then click issues for just that part. Then if you want a sub-module that isn't in high runners note that the URL is editable if you are careful and know your target hierarchy.
I haven't found a better way than that yet in 5.3, but after only a few days playing with a recent 5.3 upgrade I am generally liking the UI changes.

How do I treat warnings as errors in specific Java files?

I am working on a Java project that has a lot of compiler warnings. I can't fix all of them at once, but I would like to ensure that each file that becomes warning-free remains warning-free. Is there a way to turn warnings into errors in specific files or packages? I'm interested in generating the errors with either Eclipse or javac.
In your Eclipse, go to Window > Preferences > Java > Compiler > Errors/Warnings:
Here you could switch any Warning entry to Error. Beware some entries may be hidden by expandable panels, so make sure you expand them all.
At the top right corner you can also select "Configure Project Specific Settings.." if you want to apply this configuration to only a project and not to all projects by default. Alternatively, you can achieve the same by right click on the concerned project > Properties > Java Compiler > Errors/Warnings entry.
Hence, this will be applied to either the whole workspace or just a project, but not to specific files or packages, you don't have this granularity in Eclipse.
This should help you to achieve it, although it might become time and effort consuming to keep it clean, but that's another story.
Moreover, from the Problems view you can create a new Problem View, then from its menu (right top corner of the view, as shown by the picture below), you can configure it.
Once created a new Problems View, you can again use the same menu and select the Configure Contents.. entry. From there, you can create a New configuration (see picture below) and define it only for the select element (if you previously selected the concerned class or package), and define whether you want to see any of Errors, Warnings, Info and from which category.
This configuration could help you out to narrow down and filtering errors and warnings on a specific package or class as a complement or as a different solution/approach than the description above.
Final note: I used Eclipse Mars to try it out, but the functionality should be there since many past versions.

Eclipse-PMD Configure ruleset globally

So i am using the Plugin Eclipse-PMD (http://sourceforge.net/projects/pmd/files/pmd-eclipse/update-site/) in a shared version control enviroment.
We have multiple smaller projects in the entire project.
Out of the box it seems that this plugin requires individual configuration for every single project.
The way it works it that it searched for a .pmd file in the project and read information from that.
But it's really inconvenient to do that for 10-20 subprojects.
There is a general setting under Preferences -> PMD. But this doesn't seem to apply globally, even if that global checkbox is checked.
What i basically want: I want to configure the plugin to respect a single ruleSet-file in one place.
There is another problem with configuring it subproject-specific: I cannot configure a relative path for the ruleSetFile in the .pmd-file.
The problem with absolute path is that the file is checked into version control ... so with every commit everyone else would have to readjust.
I found this commit: https://github.com/pmd/pmd/pull/36 but i cannot seem to make it work the way it's roughly described.
So, did anyone achieve what i am looking for?
Edit: Actually i cannot even specify any other file that is not ".ruleset" in the .pmd-file as <ruleSetFile> without specifying an absolute path??
The default value for ruleSetFile is ".ruleset". So i thought, analogous to that, i could create a file in the exact same dir, call it fooRules.xml, and specify it via <ruleSetFile>fooRules.xml</ruleSetFile> but it can only find it if put the entire path to fooRules.xml in there?!
Try eclipse-pmd (available in the Eclipse marketplace or via the update site http://www.acanda.ch/eclipse-pmd/release/latest). With eclipse-pmd you can configure your projects to use a single rule set file for several projects. It also stores its path relative to the workspace. You still have to configure each project individually though (for now, this will change in a future release).
To set up eclipse-pmd in the way you described you have to open the project properties of your first project, select the "PMD" property page and add the rule set. Select the rule set type "Workspace" and pick your rule set file.
For every other project you have to open the project's PMD property page where you'll find the previously selected rule set file which simply needs to be checked to activate.
If you set it up this way there will be a .eclipse-pmd file in each project containing the settings. If you check this into your version control system then no one else in your team has to set up anything (apart from installing eclipse-pmd).
Disclaimer: I wrote eclipse-pmd. Mostly because I had the exact same problems as you with the other plugin.
I've been struggling a long time to get this working with PMD for Eclipse. While Eclipse-PMD has this feature built-in, I had some other issues with it (e.g. I think it is not meant to create reports).
The trick was adding the rules to the project as a link.
Create the rule file, e.g. pmd.xml, in the parent folder of the project. Add the file to the projects to be checked, but add it as a reference. Therefore, drag the file from the explorer to the bundle and select:
In the project properties, in the PMD section, check Enable PMD and Apply and Close the settings.
Now close Eclipse. Edit the file with the name .pmd in the project folder by replacing the content with the following:
<?xml version="1.0" encoding="UTF-8"?>
<pmd>
<useProjectRuleSet>true</useProjectRuleSet>
<ruleSetFile>pmd.xml</ruleSetFile>
<includeDerivedFiles>false</includeDerivedFiles>
<violationsAsErrors>true</violationsAsErrors>
<fullBuildEnabled>true</fullBuildEnabled>
</pmd>
Restart Eclipse and right click the project. Select PMD/Check Code. Now, only the violations defined in pmd.xml should be reported.
Configuring PMD only using the GUI does not seem to work for me.

How do I conditionally include or exclude a file from an archetype when project is generated?

I'm creating Maven 2 archetypes for our project (Weld). I would like to be able to control which files are placed into the generated project based on the value of a property that is defined during archetype:generate. For instance, I foresee the following prompt:
Define value for groupId: : com.example
Define value for artifactId: : myproject
Define value for package: com.example: :
Define value for includeGradleSupport: : y
Based on the value of includeGradleSupport, I want to include (or not include) the build.gradle file in the generated project. If the user does not want Gradle support, I don't want to clutter up the generated project with unnecessary files.
Another example is that I might need to provide a Jetty web fragment (to activate a listener perhaps) if the user wants Jetty support.
It's all about customization of the project based on what the developer intends to use. While I could create a whole other archetype, sometimes the changes are so slight that it would be easier to include/exclude a file.
Is there a way to control this behavior using the archetype-metadata.xml descriptor?
I personally would move the parts that can be removed/added on user request and put the into different maven profiles so u can build different part using different profiles
I can have a look into what coding it would take to enable this in the archetype plugin.
I think the primary vehicle to do this today would be to conditionally produce two different archetype artifacts during the original build. The archetype user would then explicitly use yourarchetype-withthing or yourarchetype-withoutthing.
I know this isn't perfectly what you are after and I agree that what you are asking for is a sensible use case.
While I could create a whole other archetype, sometimes the changes are so slight that it would be easier to include/exclude a file.
This sentence made me think...
It seems like you have a default project structure.
Let's suppose it is big, has many files. Of course, you don't want to duplicate the logic and the files in a different archetype.
Now sometimes, a project has an additional behavior (related to Gradle).
This sound a typical use-case for another archetype that does not start from nothing, but that comes after the first one. I've seen several examples of such archetypes on the web. The developper triggers this archetype only if the project needs Graddle. :-)
So I suggest : create your Graddle archetype, that adds only the files relevant to Graddle.
Thanks for the info Dan !
I just looked at looked at archetype plugin source code, and http://jira.codehaus.org/browse/ARCHETYPE-58 doesn't appear to have resolved this issue.
Just created http://jira.codehaus.org/browse/ARCHETYPE-424 to track it.

Categories