microsoft / vscode-maven

VSCode extension "Maven for Java"
https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven
Other
183 stars 89 forks source link

maven explorer Profiles #964

Closed kukuxiahuni closed 1 year ago

kukuxiahuni commented 1 year ago

Describe the bug first i can not sure this is a bug. but in my vscode I get different show. I hava two maven project, the one can show the profiles and the other not. sometimes Background process terminated with code 127. image image

How to fix them??

Expected behavior can list the maybe problems or the notices.

Environments (please complete the following information as much as possible):

Eskibear commented 1 year ago

When the error occurred, go to Output Maven for Java, see what was printed there.

kukuxiahuni commented 1 year ago
  1. there are no errors in output;
  2. only a warning "message": "Build path specifies execution environment JavaSE-1.8. There are no JREs installed in the workspace that are strictly compatible with this environment. ",

image

Eskibear commented 1 year ago

so the content of xxxx.profiles.txt in your screenshot? this extension directly parse output from there. BTW if you can stably reproduce it, a sample project can be shared, that would be more helpful.

kukuxiahuni commented 1 year ago

I think the code have a little problem。

        const profiles: MavenProfile[] = [];
        const regexp = /Profile Id: (.*) \(Active: (true|false) , Source: (.*)\)/g;
        let match: RegExpExecArray | null;
        do {
            match = regexp.exec(output);
            if (match != null && match.length === 4) {
                const id = match[1];
                const active = match[2] === "true";
                const source = match[3];
                if (!profiles.find(p => p.id === id)) {
                    const profile = new MavenProfile(project, id, active, source);
                    profiles.push(profile);
                }
            }
        } while (match !== null);
        return profiles;
    }

image maybe there is an extra space。

/Profile Id: (.*) \(Active: (true|false) , Source: (.*)\)/g Profile Id: dev (Active: true, Source: pom)

image

this is my test code

var pattern = /Profile Id: (.*) \(Active: (true|false) , Source: (.*)\)/,
    str = 'Profile Id: dev (Active: true, Source: pom)';
   console.log(pattern.test(str));

may can

var pattern = /Profile Id: (.*) \(Active: (true|false)(.*), Source: (.*)\)/,
    str = 'Profile Id: dev (Active: true, Source: pom)';
console.log(pattern.test(str));
Eskibear commented 1 year ago

Good catch. Probably it's due to some changes in maven-help-plugin 3.4.0, released last month. see https://github.com/apache/maven-help-plugin/releases/tag/maven-help-plugin-3.4.0

Yes, we should update the regexp to make it more robust and you provided a good example.

Talking about the implementation, instead of adding (.*) , I would prefer to \s? indicating there can be an optional whitespace char.

Let us know if you are interested in creating a PR, otherwise we'll fix it on our own. /cc @testforstephen

kukuxiahuni commented 1 year ago

Wating for your fix. i am newer in javascript, study hard.

in my new project is ok. Maybe the old project created by idea, the new one created by vscode. but the cit/crm come from setting.xml.

[INFO] --- help:3.3.0:all-profiles (default-cli) @ chaos ---
[INFO] Listing Profiles for Project: com.sankun.chatgpt:chaos:jar:0.0.1-SNAPSHOT
  Profile Id: cit (Active: true , Source: settings.xml)
  Profile Id: crm (Active: true , Source: settings.xml)
  Profile Id: native (Active: false , Source: pom)
  Profile Id: nativeTest (Active: false , Source: pom)
Eskibear commented 1 year ago

[INFO] --- help:3.3.0:all-profiles (default-cli) @ chaos ---

That's because your new project is using maven-help-plugin 3.3.0.

Wating for your fix.

No problem. I'll invite @testforstephen to provide a quick fix.

synckey commented 1 year ago

Any plan to fix this?

Eskibear commented 1 year ago

@synckey I created PR #980 for this.

@testforstephen please take a look.

synckey commented 1 year ago

@synckey I created PR #980 for this.

@testforstephen please take a look.

Really sweet for this

kukuxiahuni commented 1 year ago

How about this bug?