You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "petrovic-d (via GitHub)" <gi...@apache.org> on 2024/08/26 15:05:25 UTC
[PR] Copy application config file before docker run [netbeans]
petrovic-d opened a new pull request, #7698:
URL: https://github.com/apache/netbeans/pull/7698
When run docker image in compute instance command is invoked, before actually running the image, configuration file will be uploaded to the compute instance and later it would be mounted as a volume so that application is provided with the properties. Properties are generated with PropertiesGenerator
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Copy application config file before docker run [netbeans]
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #7698:
URL: https://github.com/apache/netbeans/pull/7698#discussion_r1740456913
##########
java/java.lsp.server/vscode/src/extension.ts:
##########
@@ -972,8 +972,25 @@ function openSSHSession(username: string, host: string, name?: string) {
terminal.show();
}
-function runDockerSSH(username: string, host: string, dockerImage: string) {
- const sshCommand = `ssh ${username}@${host} "docker pull ${dockerImage} && docker run -p 8080:8080 -it ${dockerImage}"`;
+async function runDockerSSH(username: string, host: string, dockerImage: string) {
+ const configFilePath: string = await vscode.commands.executeCommand('nbls.config.file.path') as string;
+ const paths: string[] = configFilePath.split(",");
+
+ const applicationPropertiesRemotePath = `/home/${username}/application.properties`;
+ const bootstrapPropertiesRemotePath = `/home/${username}/bootstrap.properties`;
+ const applicationPropertiesContainerPath = "/home/app/application.properties";
+ const bootstrapPropertiesContainerPath = "/home/app/bootstrap.properties";
+
+ let sshCommand = `scp "${paths[0]}" ${username}@${host}:${bootstrapPropertiesRemotePath} `;
+ let mountVolume = `-v ${bootstrapPropertiesRemotePath}:${bootstrapPropertiesContainerPath}:Z`;
+ let micronautConfigFilesEnv = `${bootstrapPropertiesContainerPath}`;
+
+ if (paths.length > 1) {
Review Comment:
Note that if bootstrap props is empty, the server part [does not include](https://github.com/apache/netbeans/pull/7698/files#diff-454320ed6ea71f3969632101b3de1a06c5cd2cb05eb16b169570f30754cc8597R66) that entry in the path list at 1st position.
Suggest to either return a pair/list of paths, possibly empty where each of the slots is reserved for a certain properties flavour, or a Map that would map from {bootstrap|application}.properties filename to the absolute path of the generated temp file.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Copy application config file before docker run [netbeans]
Posted by "jhorvath (via GitHub)" <gi...@apache.org>.
jhorvath merged PR #7698:
URL: https://github.com/apache/netbeans/pull/7698
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Copy application config file before docker run [netbeans]
Posted by "petrovic-d (via GitHub)" <gi...@apache.org>.
petrovic-d commented on code in PR #7698:
URL: https://github.com/apache/netbeans/pull/7698#discussion_r1734789448
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ConfigFileGenerator.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.file.DirectoryStream;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.nio.file.attribute.AclEntry;
+import java.nio.file.attribute.AclEntryPermission;
+import static java.nio.file.attribute.AclEntryPermission.APPEND_DATA;
+import static java.nio.file.attribute.AclEntryPermission.DELETE;
+import static java.nio.file.attribute.AclEntryPermission.READ_ACL;
+import static java.nio.file.attribute.AclEntryPermission.READ_ATTRIBUTES;
+import static java.nio.file.attribute.AclEntryPermission.READ_DATA;
+import static java.nio.file.attribute.AclEntryPermission.READ_NAMED_ATTRS;
+import static java.nio.file.attribute.AclEntryPermission.SYNCHRONIZE;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_ACL;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_ATTRIBUTES;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_DATA;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_NAMED_ATTRS;
+import java.nio.file.attribute.AclFileAttributeView;
+import java.nio.file.attribute.DosFileAttributeView;
+import java.nio.file.attribute.FileAttribute;
+import java.nio.file.attribute.PosixFileAttributeView;
+import java.nio.file.attribute.PosixFilePermission;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_READ;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author Dusan Petrovic
+ */
+public class ConfigFileGenerator {
+
+ private static final Logger LOG = Logger.getLogger(ConfigFileGenerator.class.getName());
+
+ private static final boolean POSIX = FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); // NOI18N
+ private static final EnumSet<PosixFilePermission> readWritePosix = EnumSet.of(OWNER_READ, OWNER_WRITE);
+ private static final EnumSet<PosixFilePermission> readPosix = EnumSet.of(OWNER_READ);
+
+ private static final EnumSet<AclEntryPermission> readOnlyAcl = EnumSet.of(
+ READ_ACL,
+ READ_ATTRIBUTES,
+ WRITE_ATTRIBUTES,
+ READ_DATA,
+ READ_NAMED_ATTRS,
+ DELETE,
+ SYNCHRONIZE
+ );
+
+ private static final EnumSet<AclEntryPermission> readWriteAcl = EnumSet.of(
+ READ_DATA,
+ WRITE_DATA,
+ APPEND_DATA,
+ READ_NAMED_ATTRS,
+ WRITE_NAMED_ATTRS,
+ READ_ATTRIBUTES,
+ WRITE_ATTRIBUTES,
+ READ_ACL,
+ WRITE_ACL
+ );
+
+ private static final Path tmpdir = Path.of(System.getProperty("java.io.tmpdir")); // NOI18N
+
+ private final Boolean readOnly;
+ private final String filePrefix;
+ private final String fileSufix;
+ private final String configPath;
+
+ public ConfigFileGenerator(String filePrefix, String fileSufix, String configPath, boolean readOnly) {
+ this.readOnly = readOnly;
+ this.configPath = configPath;
+ this.filePrefix = filePrefix;
+ this.fileSufix = fileSufix;
+ }
+
+ public Path generateConfigFile() throws IOException {
+ Path dir = generateDirPath();
+
+ if (!Files.isDirectory(dir, LinkOption.NOFOLLOW_LINKS)) {
+ Files.createDirectory(dir);
+ }
+ if (POSIX) {
+ return createFilePosix(dir);
+ }
+
+ Path temp = Files.createTempFile(dir, this.filePrefix, this.fileSufix);
+ try {
+ setFileOwnerAcl(temp, readWriteAcl);
+ } catch (IOException ex) {
+ deleteTempFile(temp);
+ throw ex;
+ }
+ return temp;
+ }
+
+ public void writePropertiesToFile(Properties props, Path filePath) throws IOException {
+ try (Writer writer = new FileWriter(filePath.toFile(), Charset.defaultCharset());) {
+ props.store(writer, "");
+ if (POSIX) {
+ setFilePermissionPosix(filePath);
+ } else {
+ if (readOnly) {
+ DosFileAttributeView attribs = Files.getFileAttributeView(filePath, DosFileAttributeView.class);
+ attribs.setReadOnly(true);
+ setFileOwnerAcl(filePath, readOnlyAcl);
+ } else {
+ setFileOwnerAcl(filePath, readWriteAcl);
+ }
+ }
+ filePath.toFile().deleteOnExit();
+ }
+ }
+
+ private void setFileOwnerAcl(Path filePath, Set<AclEntryPermission> permissions) throws IOException {
+ AclFileAttributeView acl = Files.getFileAttributeView(filePath, AclFileAttributeView.class);
+ AclEntry ownerEntry = findFileOwner(acl);
+
+ if (ownerEntry == null) {
+ throw new IOException("Owner missing, file:" + filePath.toString()); // NOI18N
+ }
+
+ AclEntry ownerAcl = AclEntry.newBuilder(ownerEntry).setPermissions(permissions).build();
+ acl.setAcl(Collections.singletonList(ownerAcl));
+ }
+
+ private AclEntry findFileOwner(AclFileAttributeView acl) throws IOException {
+ for(AclEntry e : acl.getAcl()) {
+ if (e.principal().equals(acl.getOwner())) {
+ return e;
+ }
+ }
+ return null;
+ }
+
+ private void setFilePermissionPosix(Path temp) throws IOException {
+ PosixFileAttributeView attributes = Files.getFileAttributeView(temp, PosixFileAttributeView.class);
+ if (this.readOnly) {
+ attributes.setPermissions(readPosix);
+ } else {
+ attributes.setPermissions(readWritePosix);
+ }
+ }
+
+
+ private Path createFilePosix(Path dir) throws IOException {
+ FileAttribute<?> readWriteAttribs = PosixFilePermissions.asFileAttribute(readWritePosix);
+ return Files.createTempFile(dir,this.filePrefix, this.fileSufix, readWriteAttribs);
+ }
+
+ Path generateDirPath() {
+ String s = this.configPath + "_" + System.getProperty("user.name"); // NOI18N
+ Path name = tmpdir.getFileSystem().getPath(s);
+ return tmpdir.resolve(name);
+ }
+
+ void deleteTempFile(Path temp) {
+ if (temp != null && Files.isRegularFile(temp, LinkOption.NOFOLLOW_LINKS)) {
+ try {
+ if (POSIX) {
+ PosixFileAttributeView attribs = Files.getFileAttributeView(temp, PosixFileAttributeView.class);
+ attribs.setPermissions(readWritePosix);
+ } else {
+ DosFileAttributeView attribs = Files.getFileAttributeView(temp, DosFileAttributeView.class);
+ attribs.setReadOnly(false);
+ }
+ Files.delete(temp);
+ } catch (IOException ex) {
+ LOG.log(Level.WARNING, "deleteTempFile", ex);
+ }
+ }
+ }
+
+ void deleteOldFiles() throws IOException {
+ Path dir = generateDirPath();
+ if (Files.isDirectory(dir, LinkOption.NOFOLLOW_LINKS)) {
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
+ for (Path f : stream) {
Review Comment:
I doubt that any folder will happen, but even in that case the `deleteTempFile` method has a check if it is a file
So files are expected
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Copy application config file before docker run [netbeans]
Posted by "jhorvath (via GitHub)" <gi...@apache.org>.
jhorvath commented on code in PR #7698:
URL: https://github.com/apache/netbeans/pull/7698#discussion_r1738620222
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ConfigFileProvider.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.file.Path;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.netbeans.spi.lsp.CommandProvider;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author Dusan Petrovic
+ */
+@ServiceProvider(service = CommandProvider.class)
+public class ConfigFileProvider implements CommandProvider {
+ private static final String GET_CONFIG_FILE_PATH = "nbls.config.file.path"; //NOI18N
+
+ private final ConfigFileGenerator configFileGenerator;
+
+ public ConfigFileProvider() {
+ this.configFileGenerator = new ConfigFileGenerator("app-config-", ".properties", GET_CONFIG_FILE_PATH, false); // NOI18N
+ }
+
+ @Override
+ public Set<String> getCommands() {
+ return Collections.singleton(GET_CONFIG_FILE_PATH);
+ }
+
+ @Override
+ public CompletableFuture<Object> runCommand(String command, List<Object> arguments) {
+ CompletableFuture ret = new CompletableFuture();
+
+ Properties props = new Properties();
+ PropertiesGenerator propGen = new PropertiesGenerator(false);
+ props.putAll(propGen.getApplication());
+ props.putAll(propGen.getBootstrap());
Review Comment:
Bootstrap properties should be stored in a separate file `bootstrap.properties`
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Copy application config file before docker run [netbeans]
Posted by "petrovic-d (via GitHub)" <gi...@apache.org>.
petrovic-d commented on code in PR #7698:
URL: https://github.com/apache/netbeans/pull/7698#discussion_r1734838555
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/OCIPropertiesProvider.java:
##########
@@ -62,16 +44,12 @@ public class OCIPropertiesProvider implements CommandProvider {
private static final Logger LOG = Logger.getLogger(OCIPropertiesProvider.class.getName());
private static final String GET_DB_CONNECTION = "nbls.db.connection"; //NOI18N
- private static final boolean POSIX = FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); // NOI18N
- private static final EnumSet<PosixFilePermission> readWritePosix = EnumSet.of(OWNER_READ, OWNER_WRITE);
- private static final EnumSet<AclEntryPermission> readOnlyAcl = EnumSet.of(READ_ACL, READ_ATTRIBUTES, WRITE_ATTRIBUTES, READ_DATA, READ_NAMED_ATTRS, DELETE, SYNCHRONIZE);
-
- // temporary directory location
- private static final Path tmpdir = Path.of(System.getProperty("java.io.tmpdir")); // NOI18N
+ private final ConfigFileGenerator configFileGenerator;
public OCIPropertiesProvider() {
+ this.configFileGenerator = new ConfigFileGenerator("db-", ".properties", GET_DB_CONNECTION, true); // NOI18N
try {
- deleteOldFiles(generateDirPath());
+ configFileGenerator.deleteOldFiles();
Review Comment:
I guess you are right, one vscode instance will consume the path to the file, and the other will delete it.
I think that this deletion can be omitted since later we are deleting it anyways -> `filePath.toFile().deleteOnExit();` ?
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Copy application config file before docker run [netbeans]
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #7698:
URL: https://github.com/apache/netbeans/pull/7698#discussion_r1734853857
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/OCIPropertiesProvider.java:
##########
@@ -62,16 +44,12 @@ public class OCIPropertiesProvider implements CommandProvider {
private static final Logger LOG = Logger.getLogger(OCIPropertiesProvider.class.getName());
private static final String GET_DB_CONNECTION = "nbls.db.connection"; //NOI18N
- private static final boolean POSIX = FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); // NOI18N
- private static final EnumSet<PosixFilePermission> readWritePosix = EnumSet.of(OWNER_READ, OWNER_WRITE);
- private static final EnumSet<AclEntryPermission> readOnlyAcl = EnumSet.of(READ_ACL, READ_ATTRIBUTES, WRITE_ATTRIBUTES, READ_DATA, READ_NAMED_ATTRS, DELETE, SYNCHRONIZE);
-
- // temporary directory location
- private static final Path tmpdir = Path.of(System.getProperty("java.io.tmpdir")); // NOI18N
+ private final ConfigFileGenerator configFileGenerator;
public OCIPropertiesProvider() {
+ this.configFileGenerator = new ConfigFileGenerator("db-", ".properties", GET_DB_CONNECTION, true); // NOI18N
try {
- deleteOldFiles(generateDirPath());
+ configFileGenerator.deleteOldFiles();
Review Comment:
I'd give each NBLS process its own (random) temporary dir under java.io.tmpdir to play within. `deleteOnExit` is nice fallback, should also work on directories.
Hm! We can possibly use `org.openide.modules.Places.getCacheSubdirectory()` -- this is inside NBLS/NB userdir, unique for each process, can even use a fixed name there.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Copy application config file before docker run [netbeans]
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #7698:
URL: https://github.com/apache/netbeans/pull/7698#discussion_r1734565147
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ConfigFileGenerator.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.file.DirectoryStream;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.nio.file.attribute.AclEntry;
+import java.nio.file.attribute.AclEntryPermission;
+import static java.nio.file.attribute.AclEntryPermission.APPEND_DATA;
+import static java.nio.file.attribute.AclEntryPermission.DELETE;
+import static java.nio.file.attribute.AclEntryPermission.READ_ACL;
+import static java.nio.file.attribute.AclEntryPermission.READ_ATTRIBUTES;
+import static java.nio.file.attribute.AclEntryPermission.READ_DATA;
+import static java.nio.file.attribute.AclEntryPermission.READ_NAMED_ATTRS;
+import static java.nio.file.attribute.AclEntryPermission.SYNCHRONIZE;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_ACL;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_ATTRIBUTES;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_DATA;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_NAMED_ATTRS;
+import java.nio.file.attribute.AclFileAttributeView;
+import java.nio.file.attribute.DosFileAttributeView;
+import java.nio.file.attribute.FileAttribute;
+import java.nio.file.attribute.PosixFileAttributeView;
+import java.nio.file.attribute.PosixFilePermission;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_READ;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author Dusan Petrovic
+ */
+public class ConfigFileGenerator {
+
+ private static final Logger LOG = Logger.getLogger(ConfigFileGenerator.class.getName());
+
+ private static final boolean POSIX = FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); // NOI18N
+ private static final EnumSet<PosixFilePermission> readWritePosix = EnumSet.of(OWNER_READ, OWNER_WRITE);
+ private static final EnumSet<PosixFilePermission> readPosix = EnumSet.of(OWNER_READ);
+
+ private static final EnumSet<AclEntryPermission> readOnlyAcl = EnumSet.of(
+ READ_ACL,
+ READ_ATTRIBUTES,
+ WRITE_ATTRIBUTES,
+ READ_DATA,
+ READ_NAMED_ATTRS,
+ DELETE,
Review Comment:
`DELETE` and `WRITE_ATTRIBUTES` among read-only attrs ?
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ConfigFileGenerator.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.file.DirectoryStream;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.nio.file.attribute.AclEntry;
+import java.nio.file.attribute.AclEntryPermission;
+import static java.nio.file.attribute.AclEntryPermission.APPEND_DATA;
+import static java.nio.file.attribute.AclEntryPermission.DELETE;
+import static java.nio.file.attribute.AclEntryPermission.READ_ACL;
+import static java.nio.file.attribute.AclEntryPermission.READ_ATTRIBUTES;
+import static java.nio.file.attribute.AclEntryPermission.READ_DATA;
+import static java.nio.file.attribute.AclEntryPermission.READ_NAMED_ATTRS;
+import static java.nio.file.attribute.AclEntryPermission.SYNCHRONIZE;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_ACL;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_ATTRIBUTES;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_DATA;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_NAMED_ATTRS;
+import java.nio.file.attribute.AclFileAttributeView;
+import java.nio.file.attribute.DosFileAttributeView;
+import java.nio.file.attribute.FileAttribute;
+import java.nio.file.attribute.PosixFileAttributeView;
+import java.nio.file.attribute.PosixFilePermission;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_READ;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author Dusan Petrovic
+ */
+public class ConfigFileGenerator {
+
+ private static final Logger LOG = Logger.getLogger(ConfigFileGenerator.class.getName());
+
+ private static final boolean POSIX = FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); // NOI18N
+ private static final EnumSet<PosixFilePermission> readWritePosix = EnumSet.of(OWNER_READ, OWNER_WRITE);
+ private static final EnumSet<PosixFilePermission> readPosix = EnumSet.of(OWNER_READ);
+
+ private static final EnumSet<AclEntryPermission> readOnlyAcl = EnumSet.of(
+ READ_ACL,
+ READ_ATTRIBUTES,
+ WRITE_ATTRIBUTES,
+ READ_DATA,
+ READ_NAMED_ATTRS,
+ DELETE,
+ SYNCHRONIZE
+ );
+
+ private static final EnumSet<AclEntryPermission> readWriteAcl = EnumSet.of(
+ READ_DATA,
+ WRITE_DATA,
+ APPEND_DATA,
+ READ_NAMED_ATTRS,
+ WRITE_NAMED_ATTRS,
+ READ_ATTRIBUTES,
+ WRITE_ATTRIBUTES,
+ READ_ACL,
+ WRITE_ACL
+ );
+
+ private static final Path tmpdir = Path.of(System.getProperty("java.io.tmpdir")); // NOI18N
+
+ private final Boolean readOnly;
+ private final String filePrefix;
+ private final String fileSufix;
+ private final String configPath;
+
+ public ConfigFileGenerator(String filePrefix, String fileSufix, String configPath, boolean readOnly) {
+ this.readOnly = readOnly;
+ this.configPath = configPath;
+ this.filePrefix = filePrefix;
+ this.fileSufix = fileSufix;
+ }
+
+ public Path generateConfigFile() throws IOException {
+ Path dir = generateDirPath();
+
+ if (!Files.isDirectory(dir, LinkOption.NOFOLLOW_LINKS)) {
Review Comment:
Q: what will be the result if there's a symbolic link named `${dir}` ?
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ConfigFileGenerator.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.file.DirectoryStream;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.nio.file.attribute.AclEntry;
+import java.nio.file.attribute.AclEntryPermission;
+import static java.nio.file.attribute.AclEntryPermission.APPEND_DATA;
+import static java.nio.file.attribute.AclEntryPermission.DELETE;
+import static java.nio.file.attribute.AclEntryPermission.READ_ACL;
+import static java.nio.file.attribute.AclEntryPermission.READ_ATTRIBUTES;
+import static java.nio.file.attribute.AclEntryPermission.READ_DATA;
+import static java.nio.file.attribute.AclEntryPermission.READ_NAMED_ATTRS;
+import static java.nio.file.attribute.AclEntryPermission.SYNCHRONIZE;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_ACL;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_ATTRIBUTES;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_DATA;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_NAMED_ATTRS;
+import java.nio.file.attribute.AclFileAttributeView;
+import java.nio.file.attribute.DosFileAttributeView;
+import java.nio.file.attribute.FileAttribute;
+import java.nio.file.attribute.PosixFileAttributeView;
+import java.nio.file.attribute.PosixFilePermission;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_READ;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author Dusan Petrovic
+ */
+public class ConfigFileGenerator {
+
+ private static final Logger LOG = Logger.getLogger(ConfigFileGenerator.class.getName());
+
+ private static final boolean POSIX = FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); // NOI18N
+ private static final EnumSet<PosixFilePermission> readWritePosix = EnumSet.of(OWNER_READ, OWNER_WRITE);
+ private static final EnumSet<PosixFilePermission> readPosix = EnumSet.of(OWNER_READ);
+
+ private static final EnumSet<AclEntryPermission> readOnlyAcl = EnumSet.of(
+ READ_ACL,
+ READ_ATTRIBUTES,
+ WRITE_ATTRIBUTES,
+ READ_DATA,
+ READ_NAMED_ATTRS,
+ DELETE,
+ SYNCHRONIZE
+ );
+
+ private static final EnumSet<AclEntryPermission> readWriteAcl = EnumSet.of(
+ READ_DATA,
+ WRITE_DATA,
+ APPEND_DATA,
+ READ_NAMED_ATTRS,
+ WRITE_NAMED_ATTRS,
+ READ_ATTRIBUTES,
+ WRITE_ATTRIBUTES,
+ READ_ACL,
+ WRITE_ACL
+ );
+
+ private static final Path tmpdir = Path.of(System.getProperty("java.io.tmpdir")); // NOI18N
+
+ private final Boolean readOnly;
+ private final String filePrefix;
+ private final String fileSufix;
+ private final String configPath;
+
+ public ConfigFileGenerator(String filePrefix, String fileSufix, String configPath, boolean readOnly) {
+ this.readOnly = readOnly;
+ this.configPath = configPath;
+ this.filePrefix = filePrefix;
+ this.fileSufix = fileSufix;
+ }
+
+ public Path generateConfigFile() throws IOException {
+ Path dir = generateDirPath();
+
+ if (!Files.isDirectory(dir, LinkOption.NOFOLLOW_LINKS)) {
+ Files.createDirectory(dir);
+ }
+ if (POSIX) {
+ return createFilePosix(dir);
+ }
+
+ Path temp = Files.createTempFile(dir, this.filePrefix, this.fileSufix);
+ try {
+ setFileOwnerAcl(temp, readWriteAcl);
+ } catch (IOException ex) {
+ deleteTempFile(temp);
+ throw ex;
+ }
+ return temp;
+ }
+
+ public void writePropertiesToFile(Properties props, Path filePath) throws IOException {
+ try (Writer writer = new FileWriter(filePath.toFile(), Charset.defaultCharset());) {
+ props.store(writer, "");
+ if (POSIX) {
+ setFilePermissionPosix(filePath);
+ } else {
+ if (readOnly) {
+ DosFileAttributeView attribs = Files.getFileAttributeView(filePath, DosFileAttributeView.class);
+ attribs.setReadOnly(true);
+ setFileOwnerAcl(filePath, readOnlyAcl);
+ } else {
+ setFileOwnerAcl(filePath, readWriteAcl);
+ }
+ }
+ filePath.toFile().deleteOnExit();
+ }
+ }
+
+ private void setFileOwnerAcl(Path filePath, Set<AclEntryPermission> permissions) throws IOException {
+ AclFileAttributeView acl = Files.getFileAttributeView(filePath, AclFileAttributeView.class);
+ AclEntry ownerEntry = findFileOwner(acl);
+
+ if (ownerEntry == null) {
+ throw new IOException("Owner missing, file:" + filePath.toString()); // NOI18N
+ }
+
+ AclEntry ownerAcl = AclEntry.newBuilder(ownerEntry).setPermissions(permissions).build();
+ acl.setAcl(Collections.singletonList(ownerAcl));
+ }
+
+ private AclEntry findFileOwner(AclFileAttributeView acl) throws IOException {
+ for(AclEntry e : acl.getAcl()) {
+ if (e.principal().equals(acl.getOwner())) {
+ return e;
+ }
+ }
+ return null;
+ }
+
+ private void setFilePermissionPosix(Path temp) throws IOException {
+ PosixFileAttributeView attributes = Files.getFileAttributeView(temp, PosixFileAttributeView.class);
+ if (this.readOnly) {
+ attributes.setPermissions(readPosix);
+ } else {
+ attributes.setPermissions(readWritePosix);
+ }
+ }
+
+
+ private Path createFilePosix(Path dir) throws IOException {
+ FileAttribute<?> readWriteAttribs = PosixFilePermissions.asFileAttribute(readWritePosix);
+ return Files.createTempFile(dir,this.filePrefix, this.fileSufix, readWriteAttribs);
+ }
+
+ Path generateDirPath() {
+ String s = this.configPath + "_" + System.getProperty("user.name"); // NOI18N
+ Path name = tmpdir.getFileSystem().getPath(s);
+ return tmpdir.resolve(name);
Review Comment:
Nitpick: can use `tmpDir.resolve(String)`, does the same through tmpdir's filesystem.
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/OCIPropertiesProvider.java:
##########
@@ -62,16 +44,12 @@ public class OCIPropertiesProvider implements CommandProvider {
private static final Logger LOG = Logger.getLogger(OCIPropertiesProvider.class.getName());
private static final String GET_DB_CONNECTION = "nbls.db.connection"; //NOI18N
- private static final boolean POSIX = FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); // NOI18N
- private static final EnumSet<PosixFilePermission> readWritePosix = EnumSet.of(OWNER_READ, OWNER_WRITE);
- private static final EnumSet<AclEntryPermission> readOnlyAcl = EnumSet.of(READ_ACL, READ_ATTRIBUTES, WRITE_ATTRIBUTES, READ_DATA, READ_NAMED_ATTRS, DELETE, SYNCHRONIZE);
-
- // temporary directory location
- private static final Path tmpdir = Path.of(System.getProperty("java.io.tmpdir")); // NOI18N
+ private final ConfigFileGenerator configFileGenerator;
public OCIPropertiesProvider() {
+ this.configFileGenerator = new ConfigFileGenerator("db-", ".properties", GET_DB_CONNECTION, true); // NOI18N
try {
- deleteOldFiles(generateDirPath());
+ configFileGenerator.deleteOldFiles();
Review Comment:
Suppose 2 NBLS servers run at the same time, e.g. two vscode windows, per-workspace NBLS (= 2 instances). `deleteOldFiles` removes files underneath `generateDirPath` which does not use random seed ... so it seems that `deleteOldFiles` in `NBLS #1` constructs the same path as `NBLS #2` is using and deletes the contents ?
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ConfigFileGenerator.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.file.DirectoryStream;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.nio.file.attribute.AclEntry;
+import java.nio.file.attribute.AclEntryPermission;
+import static java.nio.file.attribute.AclEntryPermission.APPEND_DATA;
+import static java.nio.file.attribute.AclEntryPermission.DELETE;
+import static java.nio.file.attribute.AclEntryPermission.READ_ACL;
+import static java.nio.file.attribute.AclEntryPermission.READ_ATTRIBUTES;
+import static java.nio.file.attribute.AclEntryPermission.READ_DATA;
+import static java.nio.file.attribute.AclEntryPermission.READ_NAMED_ATTRS;
+import static java.nio.file.attribute.AclEntryPermission.SYNCHRONIZE;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_ACL;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_ATTRIBUTES;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_DATA;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_NAMED_ATTRS;
+import java.nio.file.attribute.AclFileAttributeView;
+import java.nio.file.attribute.DosFileAttributeView;
+import java.nio.file.attribute.FileAttribute;
+import java.nio.file.attribute.PosixFileAttributeView;
+import java.nio.file.attribute.PosixFilePermission;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_READ;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author Dusan Petrovic
+ */
+public class ConfigFileGenerator {
+
+ private static final Logger LOG = Logger.getLogger(ConfigFileGenerator.class.getName());
+
+ private static final boolean POSIX = FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); // NOI18N
+ private static final EnumSet<PosixFilePermission> readWritePosix = EnumSet.of(OWNER_READ, OWNER_WRITE);
+ private static final EnumSet<PosixFilePermission> readPosix = EnumSet.of(OWNER_READ);
+
+ private static final EnumSet<AclEntryPermission> readOnlyAcl = EnumSet.of(
+ READ_ACL,
+ READ_ATTRIBUTES,
+ WRITE_ATTRIBUTES,
+ READ_DATA,
+ READ_NAMED_ATTRS,
+ DELETE,
+ SYNCHRONIZE
+ );
+
+ private static final EnumSet<AclEntryPermission> readWriteAcl = EnumSet.of(
+ READ_DATA,
+ WRITE_DATA,
+ APPEND_DATA,
+ READ_NAMED_ATTRS,
+ WRITE_NAMED_ATTRS,
+ READ_ATTRIBUTES,
+ WRITE_ATTRIBUTES,
+ READ_ACL,
+ WRITE_ACL
+ );
+
+ private static final Path tmpdir = Path.of(System.getProperty("java.io.tmpdir")); // NOI18N
+
+ private final Boolean readOnly;
+ private final String filePrefix;
+ private final String fileSufix;
+ private final String configPath;
+
+ public ConfigFileGenerator(String filePrefix, String fileSufix, String configPath, boolean readOnly) {
+ this.readOnly = readOnly;
+ this.configPath = configPath;
+ this.filePrefix = filePrefix;
+ this.fileSufix = fileSufix;
+ }
+
+ public Path generateConfigFile() throws IOException {
+ Path dir = generateDirPath();
+
+ if (!Files.isDirectory(dir, LinkOption.NOFOLLOW_LINKS)) {
+ Files.createDirectory(dir);
+ }
+ if (POSIX) {
+ return createFilePosix(dir);
+ }
+
+ Path temp = Files.createTempFile(dir, this.filePrefix, this.fileSufix);
+ try {
+ setFileOwnerAcl(temp, readWriteAcl);
+ } catch (IOException ex) {
+ deleteTempFile(temp);
+ throw ex;
+ }
+ return temp;
+ }
+
+ public void writePropertiesToFile(Properties props, Path filePath) throws IOException {
+ try (Writer writer = new FileWriter(filePath.toFile(), Charset.defaultCharset());) {
+ props.store(writer, "");
+ if (POSIX) {
+ setFilePermissionPosix(filePath);
+ } else {
+ if (readOnly) {
+ DosFileAttributeView attribs = Files.getFileAttributeView(filePath, DosFileAttributeView.class);
+ attribs.setReadOnly(true);
+ setFileOwnerAcl(filePath, readOnlyAcl);
+ } else {
+ setFileOwnerAcl(filePath, readWriteAcl);
+ }
+ }
+ filePath.toFile().deleteOnExit();
+ }
+ }
+
+ private void setFileOwnerAcl(Path filePath, Set<AclEntryPermission> permissions) throws IOException {
+ AclFileAttributeView acl = Files.getFileAttributeView(filePath, AclFileAttributeView.class);
+ AclEntry ownerEntry = findFileOwner(acl);
+
+ if (ownerEntry == null) {
+ throw new IOException("Owner missing, file:" + filePath.toString()); // NOI18N
+ }
+
+ AclEntry ownerAcl = AclEntry.newBuilder(ownerEntry).setPermissions(permissions).build();
+ acl.setAcl(Collections.singletonList(ownerAcl));
+ }
+
+ private AclEntry findFileOwner(AclFileAttributeView acl) throws IOException {
+ for(AclEntry e : acl.getAcl()) {
+ if (e.principal().equals(acl.getOwner())) {
+ return e;
+ }
+ }
+ return null;
+ }
+
+ private void setFilePermissionPosix(Path temp) throws IOException {
+ PosixFileAttributeView attributes = Files.getFileAttributeView(temp, PosixFileAttributeView.class);
+ if (this.readOnly) {
+ attributes.setPermissions(readPosix);
+ } else {
+ attributes.setPermissions(readWritePosix);
+ }
+ }
+
+
+ private Path createFilePosix(Path dir) throws IOException {
+ FileAttribute<?> readWriteAttribs = PosixFilePermissions.asFileAttribute(readWritePosix);
+ return Files.createTempFile(dir,this.filePrefix, this.fileSufix, readWriteAttribs);
+ }
+
+ Path generateDirPath() {
+ String s = this.configPath + "_" + System.getProperty("user.name"); // NOI18N
+ Path name = tmpdir.getFileSystem().getPath(s);
+ return tmpdir.resolve(name);
+ }
+
+ void deleteTempFile(Path temp) {
+ if (temp != null && Files.isRegularFile(temp, LinkOption.NOFOLLOW_LINKS)) {
+ try {
+ if (POSIX) {
+ PosixFileAttributeView attribs = Files.getFileAttributeView(temp, PosixFileAttributeView.class);
+ attribs.setPermissions(readWritePosix);
+ } else {
+ DosFileAttributeView attribs = Files.getFileAttributeView(temp, DosFileAttributeView.class);
+ attribs.setReadOnly(false);
+ }
+ Files.delete(temp);
+ } catch (IOException ex) {
+ LOG.log(Level.WARNING, "deleteTempFile", ex);
+ }
+ }
+ }
+
+ void deleteOldFiles() throws IOException {
+ Path dir = generateDirPath();
+ if (Files.isDirectory(dir, LinkOption.NOFOLLOW_LINKS)) {
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
+ for (Path f : stream) {
Review Comment:
Q: just leaf folders are expected, no subfolders ?
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ConfigFileProvider.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.file.Path;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.netbeans.spi.lsp.CommandProvider;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author Dusan Petrovic
+ */
+@ServiceProvider(service = CommandProvider.class)
+public class ConfigFileProvider implements CommandProvider {
+
+ private static final String GET_CONFIG_FILE_PATH = "nbls.config.file.path"; //NOI18N
+
+ private final ConfigFileGenerator configFileGenerator;
+
+ public ConfigFileProvider() {
+ this.configFileGenerator = new ConfigFileGenerator("app-config-", ".properties", GET_CONFIG_FILE_PATH, false); // NOI18N
+ }
+
+ @Override
+ public Set<String> getCommands() {
+ return Collections.singleton(GET_CONFIG_FILE_PATH);
+ }
+
+ @Override
+ public CompletableFuture<Object> runCommand(String command, List<Object> arguments) {
+ CompletableFuture ret = new CompletableFuture();
+
+ Properties props = new Properties();
+ PropertiesGenerator propGen = new PropertiesGenerator(false);
+ props.putAll(propGen.getApplication());
+ props.putAll(propGen.getBootstrap());
+
+ if (!props.isEmpty()) {
+ Path temp;
+
+ try {
+ temp = configFileGenerator.generateConfigFile();
Review Comment:
Instead of two calls (`generateConfigFile`, `writePropertiesToFile`) that happen in the sequence with double error handling, could there be just a `writePropertiesFile` that makes the directory, creates temp file and populates it in one call - centralizing IOException handling (delete the file being created) inside ConfigFileGenerator ?
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ConfigFileGenerator.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.file.DirectoryStream;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.nio.file.attribute.AclEntry;
+import java.nio.file.attribute.AclEntryPermission;
+import static java.nio.file.attribute.AclEntryPermission.APPEND_DATA;
+import static java.nio.file.attribute.AclEntryPermission.DELETE;
+import static java.nio.file.attribute.AclEntryPermission.READ_ACL;
+import static java.nio.file.attribute.AclEntryPermission.READ_ATTRIBUTES;
+import static java.nio.file.attribute.AclEntryPermission.READ_DATA;
+import static java.nio.file.attribute.AclEntryPermission.READ_NAMED_ATTRS;
+import static java.nio.file.attribute.AclEntryPermission.SYNCHRONIZE;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_ACL;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_ATTRIBUTES;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_DATA;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_NAMED_ATTRS;
+import java.nio.file.attribute.AclFileAttributeView;
+import java.nio.file.attribute.DosFileAttributeView;
+import java.nio.file.attribute.FileAttribute;
+import java.nio.file.attribute.PosixFileAttributeView;
+import java.nio.file.attribute.PosixFilePermission;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_READ;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author Dusan Petrovic
+ */
+public class ConfigFileGenerator {
+
+ private static final Logger LOG = Logger.getLogger(ConfigFileGenerator.class.getName());
+
+ private static final boolean POSIX = FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); // NOI18N
+ private static final EnumSet<PosixFilePermission> readWritePosix = EnumSet.of(OWNER_READ, OWNER_WRITE);
+ private static final EnumSet<PosixFilePermission> readPosix = EnumSet.of(OWNER_READ);
+
+ private static final EnumSet<AclEntryPermission> readOnlyAcl = EnumSet.of(
+ READ_ACL,
+ READ_ATTRIBUTES,
+ WRITE_ATTRIBUTES,
+ READ_DATA,
+ READ_NAMED_ATTRS,
+ DELETE,
+ SYNCHRONIZE
+ );
+
+ private static final EnumSet<AclEntryPermission> readWriteAcl = EnumSet.of(
+ READ_DATA,
+ WRITE_DATA,
+ APPEND_DATA,
+ READ_NAMED_ATTRS,
+ WRITE_NAMED_ATTRS,
+ READ_ATTRIBUTES,
+ WRITE_ATTRIBUTES,
+ READ_ACL,
+ WRITE_ACL
+ );
+
+ private static final Path tmpdir = Path.of(System.getProperty("java.io.tmpdir")); // NOI18N
+
+ private final Boolean readOnly;
Review Comment:
should be primitive `boolean`, no use for `null` value in the code.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Copy application config file before docker run [netbeans]
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #7698:
URL: https://github.com/apache/netbeans/pull/7698#discussion_r1740449631
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ConfigFileProvider.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.file.Path;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.netbeans.spi.lsp.CommandProvider;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author Dusan Petrovic
+ */
+@ServiceProvider(service = CommandProvider.class)
+public class ConfigFileProvider implements CommandProvider {
+ private static final String GET_CONFIG_FILE_PATH = "nbls.config.file.path"; //NOI18N
+ private static final String FILE_DELIMITER = ","; //NOI18N
+
+ private final ConfigFileGenerator applicationPropertiesFileGenerator;
+ private final ConfigFileGenerator bootstrapPropertiesFileGenerator;
+
+ public ConfigFileProvider() {
+ this.applicationPropertiesFileGenerator = new ConfigFileGenerator("application-", ".properties", GET_CONFIG_FILE_PATH, false); // NOI18N
+ this.bootstrapPropertiesFileGenerator = new ConfigFileGenerator("bootstrap-", ".properties", GET_CONFIG_FILE_PATH, false); // NOI18N
+ }
+
+ @Override
+ public Set<String> getCommands() {
+ return Collections.singleton(GET_CONFIG_FILE_PATH);
+ }
+
+ @Override
+ public CompletableFuture<Object> runCommand(String command, List<Object> arguments) {
+ CompletableFuture ret = new CompletableFuture();
+
+ Properties applicationProps = new Properties();
+ Properties bootstrapProps = new Properties();
+ PropertiesGenerator propGen = new PropertiesGenerator(false);
+
+ applicationProps.putAll(propGen.getApplication());
+ bootstrapProps.putAll(propGen.getBootstrap());
+
+ StringBuilder sb = new StringBuilder();
+ try {
+ if (!bootstrapProps.isEmpty()) {
+ Path bootstrapProperties = bootstrapPropertiesFileGenerator.writePropertiesFile(bootstrapProps);
+ sb.append(bootstrapProperties.toAbsolutePath().toString());
+ }
+
+ if (!applicationProps.isEmpty()) {
+ Path applicationPropertiesPath = applicationPropertiesFileGenerator.writePropertiesFile(applicationProps);
+ if (sb.length() > 0) {
+ sb.append(FILE_DELIMITER);
+ }
+ sb.append(applicationPropertiesPath.toAbsolutePath().toString());
+ }
+ ret.complete(sb.toString());
Review Comment:
Why return a delimited string, instead of String[] ?
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Copy application config file before docker run [netbeans]
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #7698:
URL: https://github.com/apache/netbeans/pull/7698#discussion_r1734853857
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/OCIPropertiesProvider.java:
##########
@@ -62,16 +44,12 @@ public class OCIPropertiesProvider implements CommandProvider {
private static final Logger LOG = Logger.getLogger(OCIPropertiesProvider.class.getName());
private static final String GET_DB_CONNECTION = "nbls.db.connection"; //NOI18N
- private static final boolean POSIX = FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); // NOI18N
- private static final EnumSet<PosixFilePermission> readWritePosix = EnumSet.of(OWNER_READ, OWNER_WRITE);
- private static final EnumSet<AclEntryPermission> readOnlyAcl = EnumSet.of(READ_ACL, READ_ATTRIBUTES, WRITE_ATTRIBUTES, READ_DATA, READ_NAMED_ATTRS, DELETE, SYNCHRONIZE);
-
- // temporary directory location
- private static final Path tmpdir = Path.of(System.getProperty("java.io.tmpdir")); // NOI18N
+ private final ConfigFileGenerator configFileGenerator;
public OCIPropertiesProvider() {
+ this.configFileGenerator = new ConfigFileGenerator("db-", ".properties", GET_DB_CONNECTION, true); // NOI18N
try {
- deleteOldFiles(generateDirPath());
+ configFileGenerator.deleteOldFiles();
Review Comment:
I'd give each NBLS process its own (random) temporary dir under java.io.tmpdir to play within. `deleteOnExit` is nice fallback, should also work on directories.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Copy application config file before docker run [netbeans]
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #7698:
URL: https://github.com/apache/netbeans/pull/7698#discussion_r1740456913
##########
java/java.lsp.server/vscode/src/extension.ts:
##########
@@ -972,8 +972,25 @@ function openSSHSession(username: string, host: string, name?: string) {
terminal.show();
}
-function runDockerSSH(username: string, host: string, dockerImage: string) {
- const sshCommand = `ssh ${username}@${host} "docker pull ${dockerImage} && docker run -p 8080:8080 -it ${dockerImage}"`;
+async function runDockerSSH(username: string, host: string, dockerImage: string) {
+ const configFilePath: string = await vscode.commands.executeCommand('nbls.config.file.path') as string;
+ const paths: string[] = configFilePath.split(",");
+
+ const applicationPropertiesRemotePath = `/home/${username}/application.properties`;
+ const bootstrapPropertiesRemotePath = `/home/${username}/bootstrap.properties`;
+ const applicationPropertiesContainerPath = "/home/app/application.properties";
+ const bootstrapPropertiesContainerPath = "/home/app/bootstrap.properties";
+
+ let sshCommand = `scp "${paths[0]}" ${username}@${host}:${bootstrapPropertiesRemotePath} `;
+ let mountVolume = `-v ${bootstrapPropertiesRemotePath}:${bootstrapPropertiesContainerPath}:Z`;
+ let micronautConfigFilesEnv = `${bootstrapPropertiesContainerPath}`;
+
+ if (paths.length > 1) {
Review Comment:
Note that if bootstrap props is empty, the server part [does not include](https://github.com/apache/netbeans/pull/7698/files#diff-454320ed6ea71f3969632101b3de1a06c5cd2cb05eb16b169570f30754cc8597R66) that entry in the path list at 1st position.
Suggest to either return a pair/list of paths, with possibly empty items, where each of the slots is reserved for a certain properties flavour, or a Map that would map from {bootstrap|application}.properties filename to the absolute path of the generated temp file.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Copy application config file before docker run [netbeans]
Posted by "petrovic-d (via GitHub)" <gi...@apache.org>.
petrovic-d commented on code in PR #7698:
URL: https://github.com/apache/netbeans/pull/7698#discussion_r1734753252
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ConfigFileGenerator.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.file.DirectoryStream;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.nio.file.attribute.AclEntry;
+import java.nio.file.attribute.AclEntryPermission;
+import static java.nio.file.attribute.AclEntryPermission.APPEND_DATA;
+import static java.nio.file.attribute.AclEntryPermission.DELETE;
+import static java.nio.file.attribute.AclEntryPermission.READ_ACL;
+import static java.nio.file.attribute.AclEntryPermission.READ_ATTRIBUTES;
+import static java.nio.file.attribute.AclEntryPermission.READ_DATA;
+import static java.nio.file.attribute.AclEntryPermission.READ_NAMED_ATTRS;
+import static java.nio.file.attribute.AclEntryPermission.SYNCHRONIZE;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_ACL;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_ATTRIBUTES;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_DATA;
+import static java.nio.file.attribute.AclEntryPermission.WRITE_NAMED_ATTRS;
+import java.nio.file.attribute.AclFileAttributeView;
+import java.nio.file.attribute.DosFileAttributeView;
+import java.nio.file.attribute.FileAttribute;
+import java.nio.file.attribute.PosixFileAttributeView;
+import java.nio.file.attribute.PosixFilePermission;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_READ;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author Dusan Petrovic
+ */
+public class ConfigFileGenerator {
+
+ private static final Logger LOG = Logger.getLogger(ConfigFileGenerator.class.getName());
+
+ private static final boolean POSIX = FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); // NOI18N
+ private static final EnumSet<PosixFilePermission> readWritePosix = EnumSet.of(OWNER_READ, OWNER_WRITE);
+ private static final EnumSet<PosixFilePermission> readPosix = EnumSet.of(OWNER_READ);
+
+ private static final EnumSet<AclEntryPermission> readOnlyAcl = EnumSet.of(
+ READ_ACL,
+ READ_ATTRIBUTES,
+ WRITE_ATTRIBUTES,
+ READ_DATA,
+ READ_NAMED_ATTRS,
+ DELETE,
+ SYNCHRONIZE
+ );
+
+ private static final EnumSet<AclEntryPermission> readWriteAcl = EnumSet.of(
+ READ_DATA,
+ WRITE_DATA,
+ APPEND_DATA,
+ READ_NAMED_ATTRS,
+ WRITE_NAMED_ATTRS,
+ READ_ATTRIBUTES,
+ WRITE_ATTRIBUTES,
+ READ_ACL,
+ WRITE_ACL
+ );
+
+ private static final Path tmpdir = Path.of(System.getProperty("java.io.tmpdir")); // NOI18N
+
+ private final Boolean readOnly;
+ private final String filePrefix;
+ private final String fileSufix;
+ private final String configPath;
+
+ public ConfigFileGenerator(String filePrefix, String fileSufix, String configPath, boolean readOnly) {
+ this.readOnly = readOnly;
+ this.configPath = configPath;
+ this.filePrefix = filePrefix;
+ this.fileSufix = fileSufix;
+ }
+
+ public Path generateConfigFile() throws IOException {
+ Path dir = generateDirPath();
+
+ if (!Files.isDirectory(dir, LinkOption.NOFOLLOW_LINKS)) {
Review Comment:
The if statement will return `true` and then line below will throw exception...
Maybe I could add a check before this if it is symlink, and delete it in that case?
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists