sdedic commented on code in PR #7642:
URL: https://github.com/apache/netbeans/pull/7642#discussion_r1711079878


##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ImageBuilderCommand.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.cloud.oracle.assets;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.logging.Logger;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectManager;
+import org.netbeans.modules.cloud.oracle.developer.ContainerRepositoryItem;
+import org.netbeans.modules.cloud.oracle.developer.ContainerRepositoryNode;
+import org.netbeans.modules.cloud.oracle.steps.ProjectStep;
+import org.netbeans.modules.gradle.api.execute.RunConfig;
+import org.netbeans.modules.gradle.api.execute.RunUtils;
+import org.netbeans.modules.maven.api.NbMavenProject;
+import org.netbeans.spi.lsp.CommandProvider;
+import org.netbeans.spi.project.SubprojectProvider;
+import org.openide.execution.ExecutorTask;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.nodes.Node;
+import org.openide.util.Exceptions;
+import org.openide.util.Lookup;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author Jan Horvath
+ */
+@ServiceProvider(service = CommandProvider.class)
+public class ImageBuilderCommand implements CommandProvider {
+
+    private static final Logger LOG = 
Logger.getLogger(ImageBuilderCommand.class.getName());
+
+    private static final String COMMAND_BUILD_PUSH_IMAGE = 
"nbls.cloud.assets.buildPushImage"; //NOI18N
+
+    private static final RequestProcessor RP = new 
RequestProcessor("PoliciesCommand"); //NOI18N
+
+    private static final Set COMMANDS = new HashSet<>(Arrays.asList(
+            COMMAND_BUILD_PUSH_IMAGE
+    ));
+
+    @Override
+    public Set<String> getCommands() {
+        return Collections.unmodifiableSet(COMMANDS);
+    }
+
+    @Override
+    public CompletableFuture<Object> runCommand(String command, List<Object> 
arguments) {
+        CompletableFuture result = new CompletableFuture();
+        Steps.getDefault()
+                .executeMultistep(new ProjectStep(), Lookup.EMPTY)
+                .thenAccept(values -> {
+                    try {
+                        Project project = 
values.getValueForStep(ProjectStep.class);
+                        ProjectManager.Result r = 
ProjectManager.getDefault().isProject2(project.getProjectDirectory());
+
+                        ContainerRepositoryItem repository = 
CloudAssets.getDefault().getItem(ContainerRepositoryItem.class);
+                        if (repository == null) {
+                            result.cancel(true);
+                            return;
+                        }
+                        Project ociProject = null;
+                        SubprojectProvider subprojectProvider = 
project.getLookup().lookup(SubprojectProvider.class);
+                        if (subprojectProvider != null) {
+                            Set<? extends Project> subprojects = 
subprojectProvider.getSubprojects();
+                            for (Project subproject : subprojects) {
+                                if 
("oci".equals(subproject.getProjectDirectory().getName())) {
+                                    ociProject = subproject;
+                                    break;
+                                }
+                            }
+                        }
+                        if (r != null && 
"org-netbeans-modules-gradle".equals(r.getProjectType())) { //NOI18N
+                            Path tempFile = Files.createTempFile("init", 
".gradle");
+
+                            String init = "allprojects {\n" +
+                                    "    afterEvaluate {\n" +
+                                    "        tasks.matching { it.name == 
'dockerBuild' }.configureEach {\n" +
+                                    "            images = [\"" + 
repository.getUrl() + ":$project.version\"]\n" +
+                                    "        }\n" +
+                                    "    }\n" +
+                                    "}";
+
+                            Files.write(tempFile, 
init.getBytes(StandardCharsets.UTF_8));
+                            RunConfig runConfig = RunUtils.createRunConfig(
+                                    project,
+                                    "",
+                                    "Build container image",
+                                    Collections.emptySet(),
+                                    "--init-script", 
tempFile.toAbsolutePath().toString(), "dockerBuild", "dockerPush"
+                            );
+                            ExecutorTask task = 
RunUtils.executeGradle(runConfig, "");
+                            task.waitFinished();

Review Comment:
   maybe try-finally and delete tempFile at the end ? Consider to put 
refresh+complete into TaskListener instead of blocking on waitFinished().



##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ImageBuilderCommand.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.cloud.oracle.assets;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.logging.Logger;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectManager;
+import org.netbeans.modules.cloud.oracle.developer.ContainerRepositoryItem;
+import org.netbeans.modules.cloud.oracle.developer.ContainerRepositoryNode;
+import org.netbeans.modules.cloud.oracle.steps.ProjectStep;
+import org.netbeans.modules.gradle.api.execute.RunConfig;
+import org.netbeans.modules.gradle.api.execute.RunUtils;
+import org.netbeans.modules.maven.api.NbMavenProject;
+import org.netbeans.spi.lsp.CommandProvider;
+import org.netbeans.spi.project.SubprojectProvider;
+import org.openide.execution.ExecutorTask;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.nodes.Node;
+import org.openide.util.Exceptions;
+import org.openide.util.Lookup;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author Jan Horvath
+ */
+@ServiceProvider(service = CommandProvider.class)
+public class ImageBuilderCommand implements CommandProvider {
+
+    private static final Logger LOG = 
Logger.getLogger(ImageBuilderCommand.class.getName());
+
+    private static final String COMMAND_BUILD_PUSH_IMAGE = 
"nbls.cloud.assets.buildPushImage"; //NOI18N
+
+    private static final RequestProcessor RP = new 
RequestProcessor("PoliciesCommand"); //NOI18N
+
+    private static final Set COMMANDS = new HashSet<>(Arrays.asList(
+            COMMAND_BUILD_PUSH_IMAGE
+    ));
+
+    @Override
+    public Set<String> getCommands() {
+        return Collections.unmodifiableSet(COMMANDS);
+    }
+
+    @Override
+    public CompletableFuture<Object> runCommand(String command, List<Object> 
arguments) {
+        CompletableFuture result = new CompletableFuture();
+        Steps.getDefault()
+                .executeMultistep(new ProjectStep(), Lookup.EMPTY)
+                .thenAccept(values -> {
+                    try {
+                        Project project = 
values.getValueForStep(ProjectStep.class);
+                        ProjectManager.Result r = 
ProjectManager.getDefault().isProject2(project.getProjectDirectory());
+
+                        ContainerRepositoryItem repository = 
CloudAssets.getDefault().getItem(ContainerRepositoryItem.class);
+                        if (repository == null) {
+                            result.cancel(true);
+                            return;
+                        }
+                        Project ociProject = null;
+                        SubprojectProvider subprojectProvider = 
project.getLookup().lookup(SubprojectProvider.class);

Review Comment:
   In other places, `ProjectUtils.getContainedProjects()` is used to enumerate 
modules/contained projects.



##########
java/maven.embedder/nbproject/project.xml:
##########
@@ -326,9 +333,9 @@
             <class-path-extension>
                 
<runtime-relative-path>../maven/lib/javax.annotation-api-1.3.2.jar</runtime-relative-path>
             </class-path-extension>
-            <class-path-extension>
+<!--            <class-path-extension>

Review Comment:
   leftover comment



##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/CloudAssets.java:
##########
@@ -203,6 +203,15 @@ public Collection<OCIItem> getItems() {
     public Collection<OCIItem> getAssignedItems() {
         return Collections.unmodifiableCollection(items);
     }
+    
+    public <T extends OCIItem> T getItem(Class<T> clazz) {
+        for (OCIItem item : items) {
+            if (item.getClass().equals(clazz)) {

Review Comment:
   equals, or instanceof ?



##########
enterprise/websvc.restlib/nbproject/project.xml:
##########
@@ -50,12 +50,21 @@
                         <specification-version>1.3</specification-version>
                     </run-dependency>
                 </dependency>
+                <dependency>
+                    
<code-name-base>org.netbeans.libs.javax.inject</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>2</release-version>
+                        <specification-version>2.61</specification-version>
+                    </run-dependency>
+                </dependency>
             </module-dependencies>
             <public-packages>
                 <package>jakarta.annotation</package>
                 <package>jakarta.annotation.security</package>
                 <package>jakarta.annotation.sql</package>
-                <package>javax.inject</package>
+                <!--<package>javax.inject</package>-->

Review Comment:
   Leftover comment ?



##########
platform/libs.javax.inject/external/jakarta.inject-2.6.1-license.txt:
##########
@@ -0,0 +1,93 @@
+Name: HK2
+Version: 2.6.1
+Description: A light-weight and dynamic dependency injection framework
+License: EPL-v20
+Origin: https://github.com/eclipse-ee4j/glassfish-hk2

Review Comment:
   The name and origin seem incorrect



##########
platform/libs.javax.inject/src/org/netbeans/libs/javax/Dummy.java:
##########
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.libs.jsr223;

Review Comment:
   bad package !



##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ImageBuilderCommand.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.cloud.oracle.assets;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.logging.Logger;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectManager;
+import org.netbeans.modules.cloud.oracle.developer.ContainerRepositoryItem;
+import org.netbeans.modules.cloud.oracle.developer.ContainerRepositoryNode;
+import org.netbeans.modules.cloud.oracle.steps.ProjectStep;
+import org.netbeans.modules.gradle.api.execute.RunConfig;
+import org.netbeans.modules.gradle.api.execute.RunUtils;
+import org.netbeans.modules.maven.api.NbMavenProject;
+import org.netbeans.spi.lsp.CommandProvider;
+import org.netbeans.spi.project.SubprojectProvider;
+import org.openide.execution.ExecutorTask;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.nodes.Node;
+import org.openide.util.Exceptions;
+import org.openide.util.Lookup;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author Jan Horvath
+ */
+@ServiceProvider(service = CommandProvider.class)
+public class ImageBuilderCommand implements CommandProvider {
+
+    private static final Logger LOG = 
Logger.getLogger(ImageBuilderCommand.class.getName());
+
+    private static final String COMMAND_BUILD_PUSH_IMAGE = 
"nbls.cloud.assets.buildPushImage"; //NOI18N
+
+    private static final RequestProcessor RP = new 
RequestProcessor("PoliciesCommand"); //NOI18N
+
+    private static final Set COMMANDS = new HashSet<>(Arrays.asList(
+            COMMAND_BUILD_PUSH_IMAGE
+    ));
+
+    @Override
+    public Set<String> getCommands() {
+        return Collections.unmodifiableSet(COMMANDS);
+    }
+
+    @Override
+    public CompletableFuture<Object> runCommand(String command, List<Object> 
arguments) {
+        CompletableFuture result = new CompletableFuture();
+        Steps.getDefault()
+                .executeMultistep(new ProjectStep(), Lookup.EMPTY)
+                .thenAccept(values -> {
+                    try {
+                        Project project = 
values.getValueForStep(ProjectStep.class);
+                        ProjectManager.Result r = 
ProjectManager.getDefault().isProject2(project.getProjectDirectory());
+
+                        ContainerRepositoryItem repository = 
CloudAssets.getDefault().getItem(ContainerRepositoryItem.class);
+                        if (repository == null) {
+                            result.cancel(true);
+                            return;
+                        }
+                        Project ociProject = null;
+                        SubprojectProvider subprojectProvider = 
project.getLookup().lookup(SubprojectProvider.class);
+                        if (subprojectProvider != null) {
+                            Set<? extends Project> subprojects = 
subprojectProvider.getSubprojects();
+                            for (Project subproject : subprojects) {
+                                if 
("oci".equals(subproject.getProjectDirectory().getName())) {
+                                    ociProject = subproject;
+                                    break;
+                                }
+                            }
+                        }
+                        if (r != null && 
"org-netbeans-modules-gradle".equals(r.getProjectType())) { //NOI18N
+                            Path tempFile = Files.createTempFile("init", 
".gradle");
+
+                            String init = "allprojects {\n" +
+                                    "    afterEvaluate {\n" +
+                                    "        tasks.matching { it.name == 
'dockerBuild' }.configureEach {\n" +
+                                    "            images = [\"" + 
repository.getUrl() + ":$project.version\"]\n" +
+                                    "        }\n" +
+                                    "    }\n" +
+                                    "}";
+
+                            Files.write(tempFile, 
init.getBytes(StandardCharsets.UTF_8));
+                            RunConfig runConfig = RunUtils.createRunConfig(
+                                    project,
+                                    "",
+                                    "Build container image",
+                                    Collections.emptySet(),
+                                    "--init-script", 
tempFile.toAbsolutePath().toString(), "dockerBuild", "dockerPush"
+                            );
+                            ExecutorTask task = 
RunUtils.executeGradle(runConfig, "");
+                            task.waitFinished();
+                            refresh();
+                            result.complete(null);
+                        }
+                        if (r != null && 
"org-netbeans-modules-maven".equals(r.getProjectType())) { //NOI18N
+                            NbMavenProject nbMavenProject;
+                            final boolean isGdk;
+                            if (ociProject != null) {
+                                nbMavenProject = 
ociProject.getLookup().lookup(NbMavenProject.class);
+                                isGdk = true;
+                            } else {
+                                nbMavenProject = 
project.getLookup().lookup(NbMavenProject.class);
+                                isGdk = false;
+                            }
+                            
+                            // Workaround until GCN-4792 is fixed
+                            FileObject projectDirectory = 
FileUtil.toFileObject(nbMavenProject.getMavenProject().getBasedir());
+                            FileObject pomFile = 
projectDirectory.getFileObject("pom.xml");
+                            if (pomFile != null) {
+                                pomFile.refresh();
+                            }
+                            
+                            
nbMavenProject.getFreshProject().thenAccept(mvnProject -> {
+                                List<String> goals;
+                                String version = mvnProject.getVersion();
+                                if (isGdk) {
+                                    goals = List.of("compile", "deploy", 
"-pl", "oci", "-Dpackaging=docker", "-Djib.to.image=" + repository.getUrl()+ 
":" + version);

Review Comment:
   I think this if-else can be replaced by 
`RunConfig.setReactorStyle(ALSO_MAKE)` that generates `--projects <list> 
--also-make` into the commandline.



##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ImageBuilderCommand.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.cloud.oracle.assets;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.logging.Logger;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectManager;
+import org.netbeans.modules.cloud.oracle.developer.ContainerRepositoryItem;
+import org.netbeans.modules.cloud.oracle.developer.ContainerRepositoryNode;
+import org.netbeans.modules.cloud.oracle.steps.ProjectStep;
+import org.netbeans.modules.gradle.api.execute.RunConfig;
+import org.netbeans.modules.gradle.api.execute.RunUtils;
+import org.netbeans.modules.maven.api.NbMavenProject;
+import org.netbeans.spi.lsp.CommandProvider;
+import org.netbeans.spi.project.SubprojectProvider;
+import org.openide.execution.ExecutorTask;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.nodes.Node;
+import org.openide.util.Exceptions;
+import org.openide.util.Lookup;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author Jan Horvath
+ */
+@ServiceProvider(service = CommandProvider.class)
+public class ImageBuilderCommand implements CommandProvider {
+
+    private static final Logger LOG = 
Logger.getLogger(ImageBuilderCommand.class.getName());
+
+    private static final String COMMAND_BUILD_PUSH_IMAGE = 
"nbls.cloud.assets.buildPushImage"; //NOI18N
+
+    private static final RequestProcessor RP = new 
RequestProcessor("PoliciesCommand"); //NOI18N

Review Comment:
   This RP appears unused in the diff ?



##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ImageBuilderCommand.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.cloud.oracle.assets;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.logging.Logger;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectManager;
+import org.netbeans.modules.cloud.oracle.developer.ContainerRepositoryItem;
+import org.netbeans.modules.cloud.oracle.developer.ContainerRepositoryNode;
+import org.netbeans.modules.cloud.oracle.steps.ProjectStep;
+import org.netbeans.modules.gradle.api.execute.RunConfig;
+import org.netbeans.modules.gradle.api.execute.RunUtils;
+import org.netbeans.modules.maven.api.NbMavenProject;
+import org.netbeans.spi.lsp.CommandProvider;
+import org.netbeans.spi.project.SubprojectProvider;
+import org.openide.execution.ExecutorTask;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.nodes.Node;
+import org.openide.util.Exceptions;
+import org.openide.util.Lookup;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author Jan Horvath
+ */
+@ServiceProvider(service = CommandProvider.class)
+public class ImageBuilderCommand implements CommandProvider {
+
+    private static final Logger LOG = 
Logger.getLogger(ImageBuilderCommand.class.getName());
+
+    private static final String COMMAND_BUILD_PUSH_IMAGE = 
"nbls.cloud.assets.buildPushImage"; //NOI18N
+
+    private static final RequestProcessor RP = new 
RequestProcessor("PoliciesCommand"); //NOI18N
+
+    private static final Set COMMANDS = new HashSet<>(Arrays.asList(
+            COMMAND_BUILD_PUSH_IMAGE
+    ));
+
+    @Override
+    public Set<String> getCommands() {
+        return Collections.unmodifiableSet(COMMANDS);
+    }
+
+    @Override
+    public CompletableFuture<Object> runCommand(String command, List<Object> 
arguments) {
+        CompletableFuture result = new CompletableFuture();
+        Steps.getDefault()
+                .executeMultistep(new ProjectStep(), Lookup.EMPTY)
+                .thenAccept(values -> {
+                    try {
+                        Project project = 
values.getValueForStep(ProjectStep.class);
+                        ProjectManager.Result r = 
ProjectManager.getDefault().isProject2(project.getProjectDirectory());
+
+                        ContainerRepositoryItem repository = 
CloudAssets.getDefault().getItem(ContainerRepositoryItem.class);
+                        if (repository == null) {
+                            result.cancel(true);
+                            return;
+                        }
+                        Project ociProject = null;
+                        SubprojectProvider subprojectProvider = 
project.getLookup().lookup(SubprojectProvider.class);
+                        if (subprojectProvider != null) {
+                            Set<? extends Project> subprojects = 
subprojectProvider.getSubprojects();
+                            for (Project subproject : subprojects) {
+                                if 
("oci".equals(subproject.getProjectDirectory().getName())) {
+                                    ociProject = subproject;
+                                    break;
+                                }
+                            }
+                        }
+                        if (r != null && 
"org-netbeans-modules-gradle".equals(r.getProjectType())) { //NOI18N
+                            Path tempFile = Files.createTempFile("init", 
".gradle");
+
+                            String init = "allprojects {\n" +
+                                    "    afterEvaluate {\n" +
+                                    "        tasks.matching { it.name == 
'dockerBuild' }.configureEach {\n" +
+                                    "            images = [\"" + 
repository.getUrl() + ":$project.version\"]\n" +
+                                    "        }\n" +
+                                    "    }\n" +
+                                    "}";
+
+                            Files.write(tempFile, 
init.getBytes(StandardCharsets.UTF_8));
+                            RunConfig runConfig = RunUtils.createRunConfig(
+                                    project,
+                                    "",
+                                    "Build container image",
+                                    Collections.emptySet(),
+                                    "--init-script", 
tempFile.toAbsolutePath().toString(), "dockerBuild", "dockerPush"
+                            );
+                            ExecutorTask task = 
RunUtils.executeGradle(runConfig, "");
+                            task.waitFinished();
+                            refresh();
+                            result.complete(null);
+                        }
+                        if (r != null && 
"org-netbeans-modules-maven".equals(r.getProjectType())) { //NOI18N
+                            NbMavenProject nbMavenProject;
+                            final boolean isGdk;
+                            if (ociProject != null) {
+                                nbMavenProject = 
ociProject.getLookup().lookup(NbMavenProject.class);
+                                isGdk = true;
+                            } else {
+                                nbMavenProject = 
project.getLookup().lookup(NbMavenProject.class);
+                                isGdk = false;
+                            }
+                            
+                            // Workaround until GCN-4792 is fixed
+                            FileObject projectDirectory = 
FileUtil.toFileObject(nbMavenProject.getMavenProject().getBasedir());
+                            FileObject pomFile = 
projectDirectory.getFileObject("pom.xml");
+                            if (pomFile != null) {
+                                pomFile.refresh();
+                            }
+                            
+                            
nbMavenProject.getFreshProject().thenAccept(mvnProject -> {
+                                List<String> goals;
+                                String version = mvnProject.getVersion();
+                                if (isGdk) {
+                                    goals = List.of("compile", "deploy", 
"-pl", "oci", "-Dpackaging=docker", "-Djib.to.image=" + repository.getUrl()+ 
":" + version);
+                                } else {
+                                    goals = List.of("compile", "deploy", 
"-Dpackaging=docker", "-Djib.to.image=" + repository.getUrl()+ ":" + version);
+                                }
+                                
org.netbeans.modules.maven.api.execute.RunConfig runConfig = 
org.netbeans.modules.maven.api.execute.RunUtils.createRunConfig(
+                                        
FileUtil.toFile(project.getProjectDirectory()),
+                                        project,
+                                        "Build container image",
+                                        goals
+                                );
+                                ExecutorTask task = 
org.netbeans.modules.maven.api.execute.RunUtils.executeMaven(runConfig);
+                                task.waitFinished();

Review Comment:
   I'd recommend not to block the maven event delivery  with waiting on 
external process. Use `TaskListener`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
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