On 19. 07. 22 18:32, Peter Cheung wrote:
Hi

     I am creating a new project type for RISC-V. The below code only work when 
my netbeans loaded maven plugin. Is it possible to let netbeans load my plugin 
and auto load maven plugin together?


Well, that's bad. Maven module's API is just 'friend API'; so it is only available to a certain set of modules. Mainly because the API is too broad and the original author perhaps did not feel (?) it's rock solid to be published and maintained for good.

If it was a regular API, you could just add a module dependency.

You may consider to make an "implementation dependency" on Maven Projects module -- https://netbeans.apache.org/wiki/DevFaqImplementationDependency.asciidoc

------%<-------- from project.xml of the dependent module -----%<------
            <module-dependencies>
                <dependency>

<code-name-base>org.netbeans.modules.maven</code-name-base>
                    <build-prerequisite/>
                    <compile-dependency/>
                    <run-dependency>
                        <release-version>2</release-version>
                        <implementation-version/>
                    </run-dependency>
                </dependency>
            </module-dependencies>
------%<----------------------------%<-------------------------%<------
But please read carefully to understand the consequences. But the reflection is really ugly....

-S.



     How can my netbeans modules got the mvn path? i found "mavenHome = 
EmbedderFactory.getEffectiveMavenHome();" in netbeans source code but I don't have 
class EmbedderFactory

ClassLoader syscl = Lookup.getDefault().lookup(ClassLoader.class);
System.out.println(syscl);

List<String> goals = new ArrayList<>();
goals.add("compile");
ProjectInformation projectInformation = ProjectUtils.getInformation(this);

Class runUtils = 
syscl.loadClass("org.netbeans.modules.maven.api.execute.RunUtils");
Method createRunConfig = runUtils.getMethod("createRunConfig", new 
Class[]{File.class, Project.class, String.class, List.class});
Object rc = createRunConfig.invoke(null, FileUtil.toFile(this.projectDir), 
this, projectInformation.getDisplayName(), goals);

Class runConfig = 
syscl.loadClass("org.netbeans.modules.maven.api.execute.RunConfig");

// maven properties
Method setProperty = runConfig.getMethod("addProperties", new 
Class[]{Map.class});
Map<String, String> properties = new HashMap<>();
setProperty.invoke(rc, properties);

// maven profile
Method setActivatedProfiles = runConfig.getMethod("setActivatedProfiles", new 
Class[]{java.util.List.class});
List<String> profiles = new ArrayList<>();
profiles.add("dev");
profiles.add("prod");
setActivatedProfiles.invoke(rc, profiles);

Method executeMaven = runUtils.getMethod("executeMaven", new 
Class[]{runConfig});
executeMaven.invoke(null, rc);



Thanks

From Peter (System Architect, Quantr Limited https://www.quantr.hk , Mobile : 
96554595)



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



Reply via email to