[jira] [Work logged] (KNOX-3051) Add a classpath location for patches
[ https://issues.apache.org/jira/browse/KNOX-3051?focusedWorklogId=946899&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-946899 ] ASF GitHub Bot logged work on KNOX-3051: Author: ASF GitHub Bot Created on: 05/Dec/24 15:51 Start Date: 05/Dec/24 15:51 Worklog Time Spent: 10m Work Description: pzampino merged PR #971: URL: https://github.com/apache/knox/pull/971 Issue Time Tracking --- Worklog Id: (was: 946899) Time Spent: 2h 10m (was: 2h) > Add a classpath location for patches > > > Key: KNOX-3051 > URL: https://issues.apache.org/jira/browse/KNOX-3051 > Project: Apache Knox > Issue Type: Improvement > Components: Server >Affects Versions: 2.0.0 >Reporter: Philip Zampino >Priority: Minor > Time Spent: 2h 10m > Remaining Estimate: 0h > > It would be convenient to have the ability to easily pre-pend classes to the > Knox classpath for quickly applying/testing patches. > If this could be configurable, that would be ideal, though I'm not sure it's > possible. > If hard-coded, we should consider whether or not this location should be > within the Knox installation directory or external to it. There are pros and > cons to both, especially when considering upgrades in managed environments. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Work logged] (KNOX-3051) Add a classpath location for patches
[ https://issues.apache.org/jira/browse/KNOX-3051?focusedWorklogId=946697&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-946697 ] ASF GitHub Bot logged work on KNOX-3051: Author: ASF GitHub Bot Created on: 04/Dec/24 13:19 Start Date: 04/Dec/24 13:19 Worklog Time Spent: 10m Work Description: hanicz commented on code in PR #971: URL: https://github.com/apache/knox/pull/971#discussion_r1869480221 ## gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Extender.java: ## @@ -0,0 +1,77 @@ +/* + * 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.apache.knox.gateway.launcher; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Extender { + +private static final String CLASSPATH_EXTENSION_PROPERTY = "gateway.server.classpath.extension"; +private static final String CLASSPATH_PROPERTY_PATTERN = "\\s*" + CLASSPATH_EXTENSION_PROPERTY + "\\s*(.*?)\\s*"; +private static final String CONFIG_FILE = "gateway-site.xml"; +private static final String CONFIG_PATH = "../conf/" + CONFIG_FILE; +private static final String CLASS_PATH_PROPERTY = "class.path"; +private static final String MAIN_CLASS_PROPERTY = "main.class"; +private static final String GATEWAY_SERVER_MAIN_CLASS = "org.apache.knox.gateway.GatewayServer"; +private static final String[] CLASS_PATH_DELIMITERS = new String[]{",", ";"}; + +private final File base; +private final Properties properties; +private final Pattern pattern = Pattern.compile(CLASSPATH_PROPERTY_PATTERN, Pattern.DOTALL); + +public Extender(File base, Properties properties) { +this.base = base; +this.properties = properties; +} + +public void extendClassPathProperty() throws IOException { Review Comment: I removed the reference to the properties and moved it to method parameter. I'd rather not add logic to the constructor. Issue Time Tracking --- Worklog Id: (was: 946697) Time Spent: 2h (was: 1h 50m) > Add a classpath location for patches > > > Key: KNOX-3051 > URL: https://issues.apache.org/jira/browse/KNOX-3051 > Project: Apache Knox > Issue Type: Improvement > Components: Server >Affects Versions: 2.0.0 >Reporter: Philip Zampino >Priority: Minor > Time Spent: 2h > Remaining Estimate: 0h > > It would be convenient to have the ability to easily pre-pend classes to the > Knox classpath for quickly applying/testing patches. > If this could be configurable, that would be ideal, though I'm not sure it's > possible. > If hard-coded, we should consider whether or not this location should be > within the Knox installation directory or external to it. There are pros and > cons to both, especially when considering upgrades in managed environments. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Work logged] (KNOX-3051) Add a classpath location for patches
[ https://issues.apache.org/jira/browse/KNOX-3051?focusedWorklogId=946696&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-946696 ] ASF GitHub Bot logged work on KNOX-3051: Author: ASF GitHub Bot Created on: 04/Dec/24 13:16 Start Date: 04/Dec/24 13:16 Worklog Time Spent: 10m Work Description: hanicz commented on code in PR #971: URL: https://github.com/apache/knox/pull/971#discussion_r1869475861 ## gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Extender.java: ## @@ -0,0 +1,77 @@ +/* + * 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.apache.knox.gateway.launcher; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Extender { Review Comment: Renamed to GatewayServerClasspathExtender Issue Time Tracking --- Worklog Id: (was: 946696) Time Spent: 1h 50m (was: 1h 40m) > Add a classpath location for patches > > > Key: KNOX-3051 > URL: https://issues.apache.org/jira/browse/KNOX-3051 > Project: Apache Knox > Issue Type: Improvement > Components: Server >Affects Versions: 2.0.0 >Reporter: Philip Zampino >Priority: Minor > Time Spent: 1h 50m > Remaining Estimate: 0h > > It would be convenient to have the ability to easily pre-pend classes to the > Knox classpath for quickly applying/testing patches. > If this could be configurable, that would be ideal, though I'm not sure it's > possible. > If hard-coded, we should consider whether or not this location should be > within the Knox installation directory or external to it. There are pros and > cons to both, especially when considering upgrades in managed environments. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Work logged] (KNOX-3051) Add a classpath location for patches
[ https://issues.apache.org/jira/browse/KNOX-3051?focusedWorklogId=946594&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-946594 ] ASF GitHub Bot logged work on KNOX-3051: Author: ASF GitHub Bot Created on: 03/Dec/24 22:42 Start Date: 03/Dec/24 22:42 Worklog Time Spent: 10m Work Description: pzampino commented on code in PR #971: URL: https://github.com/apache/knox/pull/971#discussion_r1868453631 ## gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Extender.java: ## @@ -0,0 +1,77 @@ +/* + * 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.apache.knox.gateway.launcher; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Extender { + +private static final String CLASSPATH_EXTENSION_PROPERTY = "gateway.server.classpath.extension"; +private static final String CLASSPATH_PROPERTY_PATTERN = "\\s*" + CLASSPATH_EXTENSION_PROPERTY + "\\s*(.*?)\\s*"; +private static final String CONFIG_FILE = "gateway-site.xml"; +private static final String CONFIG_PATH = "../conf/" + CONFIG_FILE; +private static final String CLASS_PATH_PROPERTY = "class.path"; +private static final String MAIN_CLASS_PROPERTY = "main.class"; +private static final String GATEWAY_SERVER_MAIN_CLASS = "org.apache.knox.gateway.GatewayServer"; +private static final String[] CLASS_PATH_DELIMITERS = new String[]{",", ";"}; + +private final File base; +private final Properties properties; +private final Pattern pattern = Pattern.compile(CLASSPATH_PROPERTY_PATTERN, Pattern.DOTALL); + +public Extender(File base, Properties properties) { +this.base = base; +this.properties = properties; +} + +public void extendClassPathProperty() throws IOException { Review Comment: Is there any reason why this could not be done automatically when the object is created, rather than requiring another method invocation? There is no case for which this method would not be invoked, and probably not any cases where it would be meaningful to invoke it more than once, correct? Alternatively, you could pass in the properties at the time of the extension method, rather than the constructor, if you feel they should be separate actions. I guess my question ultimately is does this class need to retain a copy of all the properties? Or, could it rather process them once and be done with them? ## gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Extender.java: ## @@ -0,0 +1,77 @@ +/* + * 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.apache.knox.gateway.launcher; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Extender { Review Comment: Since this only applies to GatewayServer, perhaps it should be named more explicitly...s
[jira] [Work logged] (KNOX-3051) Add a classpath location for patches
[ https://issues.apache.org/jira/browse/KNOX-3051?focusedWorklogId=946595&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-946595 ] ASF GitHub Bot logged work on KNOX-3051: Author: ASF GitHub Bot Created on: 03/Dec/24 22:42 Start Date: 03/Dec/24 22:42 Worklog Time Spent: 10m Work Description: pzampino commented on code in PR #971: URL: https://github.com/apache/knox/pull/971#discussion_r1868453631 ## gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Extender.java: ## @@ -0,0 +1,77 @@ +/* + * 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.apache.knox.gateway.launcher; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Extender { + +private static final String CLASSPATH_EXTENSION_PROPERTY = "gateway.server.classpath.extension"; +private static final String CLASSPATH_PROPERTY_PATTERN = "\\s*" + CLASSPATH_EXTENSION_PROPERTY + "\\s*(.*?)\\s*"; +private static final String CONFIG_FILE = "gateway-site.xml"; +private static final String CONFIG_PATH = "../conf/" + CONFIG_FILE; +private static final String CLASS_PATH_PROPERTY = "class.path"; +private static final String MAIN_CLASS_PROPERTY = "main.class"; +private static final String GATEWAY_SERVER_MAIN_CLASS = "org.apache.knox.gateway.GatewayServer"; +private static final String[] CLASS_PATH_DELIMITERS = new String[]{",", ";"}; + +private final File base; +private final Properties properties; +private final Pattern pattern = Pattern.compile(CLASSPATH_PROPERTY_PATTERN, Pattern.DOTALL); + +public Extender(File base, Properties properties) { +this.base = base; +this.properties = properties; +} + +public void extendClassPathProperty() throws IOException { Review Comment: Is there any reason why this could not be done automatically when the object is created, rather than requiring another method invocation? There is no case for which this method would not be invoked, and probably not any cases where it would be meaningful to invoke it more than once, correct? Alternatively, you could pass in the properties at the time of the extension method, rather than the constructor, if you feel they should be separate actions. I guess my question ultimately is does this class need to retain a reference to all the properties? Or, could it rather process them once and be done with them? Issue Time Tracking --- Worklog Id: (was: 946595) Time Spent: 1h 40m (was: 1.5h) > Add a classpath location for patches > > > Key: KNOX-3051 > URL: https://issues.apache.org/jira/browse/KNOX-3051 > Project: Apache Knox > Issue Type: Improvement > Components: Server >Affects Versions: 2.0.0 >Reporter: Philip Zampino >Priority: Minor > Time Spent: 1h 40m > Remaining Estimate: 0h > > It would be convenient to have the ability to easily pre-pend classes to the > Knox classpath for quickly applying/testing patches. > If this could be configurable, that would be ideal, though I'm not sure it's > possible. > If hard-coded, we should consider whether or not this location should be > within the Knox installation directory or external to it. There are pros and > cons to both, especially when considering upgrades in managed environments. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Work logged] (KNOX-3051) Add a classpath location for patches
[ https://issues.apache.org/jira/browse/KNOX-3051?focusedWorklogId=946541&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-946541 ] ASF GitHub Bot logged work on KNOX-3051: Author: ASF GitHub Bot Created on: 03/Dec/24 14:59 Start Date: 03/Dec/24 14:59 Worklog Time Spent: 10m Work Description: smolnar82 commented on PR #971: URL: https://github.com/apache/knox/pull/971#issuecomment-2514809218 Hi @moresandeep , @pzampino - Could you please review this one? Thanks! Issue Time Tracking --- Worklog Id: (was: 946541) Time Spent: 1h 20m (was: 1h 10m) > Add a classpath location for patches > > > Key: KNOX-3051 > URL: https://issues.apache.org/jira/browse/KNOX-3051 > Project: Apache Knox > Issue Type: Improvement > Components: Server >Affects Versions: 2.0.0 >Reporter: Philip Zampino >Priority: Minor > Time Spent: 1h 20m > Remaining Estimate: 0h > > It would be convenient to have the ability to easily pre-pend classes to the > Knox classpath for quickly applying/testing patches. > If this could be configurable, that would be ideal, though I'm not sure it's > possible. > If hard-coded, we should consider whether or not this location should be > within the Knox installation directory or external to it. There are pros and > cons to both, especially when considering upgrades in managed environments. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Work logged] (KNOX-3051) Add a classpath location for patches
[ https://issues.apache.org/jira/browse/KNOX-3051?focusedWorklogId=946358&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-946358 ] ASF GitHub Bot logged work on KNOX-3051: Author: ASF GitHub Bot Created on: 02/Dec/24 15:24 Start Date: 02/Dec/24 15:24 Worklog Time Spent: 10m Work Description: smolnar82 commented on code in PR #971: URL: https://github.com/apache/knox/pull/971#discussion_r1866050706 ## gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Extender.java: ## @@ -0,0 +1,77 @@ +/* + * 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.apache.knox.gateway.launcher; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Extender { + +private static final String CLASSPATH_EXTENSION_PROPERTY = "gateway.server.classpath.extension"; +private static final String CLASSPATH_PROPERTY_PATTERN = "\\s*" + CLASSPATH_EXTENSION_PROPERTY + "\\s*(.*?)\\s*"; +private static final String CONFIG_FILE = "gateway-site.xml"; +private static final String CONFIG_PATH = "../conf/" + CONFIG_FILE; +private static final String CLASS_PATH_PROPERTY = "class.path"; +private static final String MAIN_CLASS_PROPERTY = "main.class"; +private static final String GATEWAY_SERVER_MAIN_CLASS = "org.apache.knox.gateway.GatewayServer"; +private static final String[] CLASS_PATH_DELIMITERS = new String[]{",", ";"}; + +private final File base; +private final Properties properties; + +public Extender(File base, Properties properties) { +this.base = base; +this.properties = properties; +} + +public void extendClassPathProperty() throws IOException { +Path configFilePath = Paths.get(base.getPath(), CONFIG_PATH); +if (GATEWAY_SERVER_MAIN_CLASS.equals(properties.getProperty(MAIN_CLASS_PROPERTY)) && Files.isReadable(configFilePath)) { +String configContent = new String(Files.readAllBytes(configFilePath), StandardCharsets.UTF_8); +extractExtensionPathIntoProperty(configContent); +} +} + +protected void extractExtensionPathIntoProperty(String configContent) { +Pattern pattern = Pattern.compile(CLASSPATH_PROPERTY_PATTERN, Pattern.DOTALL); +Matcher matcher = pattern.matcher(configContent); + +if (matcher.find()) { +StringBuilder newClassPath = new StringBuilder(matcher.group(1).trim()); +if (newClassPath.length() > 0) { +if (!endsWithDelimiter(newClassPath.toString())) { +newClassPath.append(CLASS_PATH_DELIMITERS[1]); +} + newClassPath.append(properties.getProperty(CLASS_PATH_PROPERTY)); +properties.setProperty(CLASS_PATH_PROPERTY, newClassPath.toString()); +} Review Comment: Ack. Issue Time Tracking --- Worklog Id: (was: 946358) Time Spent: 1h 10m (was: 1h) > Add a classpath location for patches > > > Key: KNOX-3051 > URL: https://issues.apache.org/jira/browse/KNOX-3051 > Project: Apache Knox > Issue Type: Improvement > Components: Server >Affects Versions: 2.0.0 >Reporter: Philip Zampino >Priority: Minor > Time Spent: 1h 10m > Remaining Estimate: 0h > > It would be convenient to have the ability to easily pre-pend classes to the > Knox classpath for quickly applying/testing patches. > If this could be configurable, that would be ideal, though I'm not sure it's > possible. > If hard-coded, we should consider whether or not this location should be > within the Knox installation directory or external to it. There are pros and > cons to both, especially when considering upgrades in managed environments. -- This mes
[jira] [Work logged] (KNOX-3051) Add a classpath location for patches
[ https://issues.apache.org/jira/browse/KNOX-3051?focusedWorklogId=946330&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-946330 ] ASF GitHub Bot logged work on KNOX-3051: Author: ASF GitHub Bot Created on: 02/Dec/24 12:42 Start Date: 02/Dec/24 12:42 Worklog Time Spent: 10m Work Description: hanicz commented on code in PR #971: URL: https://github.com/apache/knox/pull/971#discussion_r1865782321 ## gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Extender.java: ## @@ -0,0 +1,77 @@ +/* + * 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.apache.knox.gateway.launcher; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Extender { + +private static final String CLASSPATH_EXTENSION_PROPERTY = "gateway.server.classpath.extension"; +private static final String CLASSPATH_PROPERTY_PATTERN = "\\s*" + CLASSPATH_EXTENSION_PROPERTY + "\\s*(.*?)\\s*"; +private static final String CONFIG_FILE = "gateway-site.xml"; +private static final String CONFIG_PATH = "../conf/" + CONFIG_FILE; +private static final String CLASS_PATH_PROPERTY = "class.path"; +private static final String MAIN_CLASS_PROPERTY = "main.class"; +private static final String GATEWAY_SERVER_MAIN_CLASS = "org.apache.knox.gateway.GatewayServer"; +private static final String[] CLASS_PATH_DELIMITERS = new String[]{",", ";"}; + +private final File base; +private final Properties properties; + +public Extender(File base, Properties properties) { +this.base = base; +this.properties = properties; +} + +public void extendClassPathProperty() throws IOException { +Path configFilePath = Paths.get(base.getPath(), CONFIG_PATH); +if (GATEWAY_SERVER_MAIN_CLASS.equals(properties.getProperty(MAIN_CLASS_PROPERTY)) && Files.isReadable(configFilePath)) { +String configContent = new String(Files.readAllBytes(configFilePath), StandardCharsets.UTF_8); +extractExtensionPathIntoProperty(configContent); +} +} + +protected void extractExtensionPathIntoProperty(String configContent) { +Pattern pattern = Pattern.compile(CLASSPATH_PROPERTY_PATTERN, Pattern.DOTALL); +Matcher matcher = pattern.matcher(configContent); + +if (matcher.find()) { +StringBuilder newClassPath = new StringBuilder(matcher.group(1).trim()); +if (newClassPath.length() > 0) { +if (!endsWithDelimiter(newClassPath.toString())) { +newClassPath.append(CLASS_PATH_DELIMITERS[1]); +} + newClassPath.append(properties.getProperty(CLASS_PATH_PROPERTY)); +properties.setProperty(CLASS_PATH_PROPERTY, newClassPath.toString()); +} Review Comment: I agree it would be nice to have some kind of feedback for the user. However there is no any kind of logging setup in the launcher, there is no log dependencies added either to keep it lightweight. At this point the log4j properties are not loaded. Only the standard output is available. Issue Time Tracking --- Worklog Id: (was: 946330) Time Spent: 1h (was: 50m) > Add a classpath location for patches > > > Key: KNOX-3051 > URL: https://issues.apache.org/jira/browse/KNOX-3051 > Project: Apache Knox > Issue Type: Improvement > Components: Server >Affects Versions: 2.0.0 >Reporter: Philip Zampino >Priority: Minor > Time Spent: 1h > Remaining Estimate: 0h > > It would be convenient to have the ability to easily pre-pend classes to the > Knox classpath for quickly applying/testing patches. > If this could be configurable, that would be ideal, though I'm
[jira] [Work logged] (KNOX-3051) Add a classpath location for patches
[ https://issues.apache.org/jira/browse/KNOX-3051?focusedWorklogId=946329&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-946329 ] ASF GitHub Bot logged work on KNOX-3051: Author: ASF GitHub Bot Created on: 02/Dec/24 12:40 Start Date: 02/Dec/24 12:40 Worklog Time Spent: 10m Work Description: hanicz commented on code in PR #971: URL: https://github.com/apache/knox/pull/971#discussion_r1865779170 ## gateway-util-launcher/src/test/java/org/apache/knox/gateway/launcher/ExtenderTest.java: ## @@ -0,0 +1,195 @@ +/* + * 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.apache.knox.gateway.launcher; + + +import org.junit.Test; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; + +public class ExtenderTest { + +private Path tempDir; +private Path confDir; +private Path configFilePath; + +@Test +public void extendClassPathPropertyTest() throws IOException { +this.setupDirs(); +Properties properties = new Properties(); +properties.setProperty("class.path", "classpath"); +properties.setProperty("main.class", "org.apache.knox.gateway.GatewayServer"); +Extender extender = new Extender(confDir.toFile(), properties); + +String configContent = this.getConfigContent("/new/classp/*"); +Files.write(configFilePath, configContent.getBytes(StandardCharsets.UTF_8)); +extender.extendClassPathProperty(); + +assertEquals("/new/classp/*;classpath", properties.getProperty("class.path")); +this.cleanUpDirs(); +} + +@Test +public void extendClassPathPropertyDifferentMainClassTest() throws IOException { +this.setupDirs(); +Properties properties = new Properties(); +properties.setProperty("class.path", "classpath"); +properties.setProperty("main.class", "org.apache.knox.gateway.KnoxCLI"); +Extender extender = new Extender(confDir.toFile(), properties); + +String configContent = this.getConfigContent("/new/classp/*"); +Files.write(configFilePath, configContent.getBytes(StandardCharsets.UTF_8)); +extender.extendClassPathProperty(); + +assertEquals("classpath", properties.getProperty("class.path")); +this.cleanUpDirs(); +} + +@Test +public void extractExtensionPathIntoPropertyNoDelimTest() { +Properties properties = new Properties(); +properties.setProperty("class.path", "classpath"); +Extender extender = new Extender(null, properties); + +String configContent = this.getConfigContent("/new/classp/*"); +extender.extractExtensionPathIntoProperty(configContent); + +assertEquals("/new/classp/*;classpath", properties.getProperty("class.path")); +} + +@Test +public void extractExtensionPathIntoPropertyXMLFormatTest() { +Properties properties = new Properties(); +properties.setProperty("class.path", "classpath"); +Extender extender = new Extender(null, properties); + +String configContent = this.getConfigContent("/new/classp/*;"); +extender.extractExtensionPathIntoProperty(configContent); + +assertEquals("/new/classp/*;classpath", properties.getProperty("class.path")); +} + +@Test +public void extractExtensionPathIntoPropertyWhitespaceTest() { +Properties properties = new Properties(); +properties.setProperty("class.path", "classpath"); +Extender extender = new Extender(null, properties); + +String configContent = this.getConfigContent(" /new/classp/*; "); +extender.extractExtensionPathIntoProperty(configContent); + +assertEquals("/new/classp/*;classpath", properties.getProperty("class.path")); +} + +@Test +public void extractExtensionPathIntoPropertyMultipleTest() { +Properties properties = new Properties(); +properties.setProperty("class.path", "classpath"); +Extender exte
[jira] [Work logged] (KNOX-3051) Add a classpath location for patches
[ https://issues.apache.org/jira/browse/KNOX-3051?focusedWorklogId=946328&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-946328 ] ASF GitHub Bot logged work on KNOX-3051: Author: ASF GitHub Bot Created on: 02/Dec/24 12:39 Start Date: 02/Dec/24 12:39 Worklog Time Spent: 10m Work Description: hanicz commented on code in PR #971: URL: https://github.com/apache/knox/pull/971#discussion_r1865778308 ## gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Extender.java: ## @@ -0,0 +1,77 @@ +/* + * 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.apache.knox.gateway.launcher; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Extender { + +private static final String CLASSPATH_EXTENSION_PROPERTY = "gateway.server.classpath.extension"; +private static final String CLASSPATH_PROPERTY_PATTERN = "\\s*" + CLASSPATH_EXTENSION_PROPERTY + "\\s*(.*?)\\s*"; +private static final String CONFIG_FILE = "gateway-site.xml"; +private static final String CONFIG_PATH = "../conf/" + CONFIG_FILE; +private static final String CLASS_PATH_PROPERTY = "class.path"; +private static final String MAIN_CLASS_PROPERTY = "main.class"; +private static final String GATEWAY_SERVER_MAIN_CLASS = "org.apache.knox.gateway.GatewayServer"; +private static final String[] CLASS_PATH_DELIMITERS = new String[]{",", ";"}; + +private final File base; +private final Properties properties; + +public Extender(File base, Properties properties) { +this.base = base; +this.properties = properties; +} + +public void extendClassPathProperty() throws IOException { +Path configFilePath = Paths.get(base.getPath(), CONFIG_PATH); +if (GATEWAY_SERVER_MAIN_CLASS.equals(properties.getProperty(MAIN_CLASS_PROPERTY)) && Files.isReadable(configFilePath)) { +String configContent = new String(Files.readAllBytes(configFilePath), StandardCharsets.UTF_8); +extractExtensionPathIntoProperty(configContent); +} +} + +protected void extractExtensionPathIntoProperty(String configContent) { +Pattern pattern = Pattern.compile(CLASSPATH_PROPERTY_PATTERN, Pattern.DOTALL); +Matcher matcher = pattern.matcher(configContent); Review Comment: Changed them to final Issue Time Tracking --- Worklog Id: (was: 946328) Time Spent: 40m (was: 0.5h) > Add a classpath location for patches > > > Key: KNOX-3051 > URL: https://issues.apache.org/jira/browse/KNOX-3051 > Project: Apache Knox > Issue Type: Improvement > Components: Server >Affects Versions: 2.0.0 >Reporter: Philip Zampino >Priority: Minor > Time Spent: 40m > Remaining Estimate: 0h > > It would be convenient to have the ability to easily pre-pend classes to the > Knox classpath for quickly applying/testing patches. > If this could be configurable, that would be ideal, though I'm not sure it's > possible. > If hard-coded, we should consider whether or not this location should be > within the Knox installation directory or external to it. There are pros and > cons to both, especially when considering upgrades in managed environments. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Work logged] (KNOX-3051) Add a classpath location for patches
[ https://issues.apache.org/jira/browse/KNOX-3051?focusedWorklogId=946327&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-946327 ] ASF GitHub Bot logged work on KNOX-3051: Author: ASF GitHub Bot Created on: 02/Dec/24 12:39 Start Date: 02/Dec/24 12:39 Worklog Time Spent: 10m Work Description: hanicz commented on code in PR #971: URL: https://github.com/apache/knox/pull/971#discussion_r1865777992 ## gateway-util-launcher/src/test/java/org/apache/knox/gateway/launcher/ExtenderTest.java: ## @@ -0,0 +1,195 @@ +/* + * 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.apache.knox.gateway.launcher; + + +import org.junit.Test; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; + +public class ExtenderTest { + +private Path tempDir; +private Path confDir; +private Path configFilePath; + +@Test +public void extendClassPathPropertyTest() throws IOException { +this.setupDirs(); +Properties properties = new Properties(); +properties.setProperty("class.path", "classpath"); +properties.setProperty("main.class", "org.apache.knox.gateway.GatewayServer"); +Extender extender = new Extender(confDir.toFile(), properties); + +String configContent = this.getConfigContent("/new/classp/*"); +Files.write(configFilePath, configContent.getBytes(StandardCharsets.UTF_8)); +extender.extendClassPathProperty(); + +assertEquals("/new/classp/*;classpath", properties.getProperty("class.path")); +this.cleanUpDirs(); Review Comment: Yes, that was my thinking. They are not needed for every case, however I didn't think of error handling. I changed them to `After/Before`. Issue Time Tracking --- Worklog Id: (was: 946327) Time Spent: 0.5h (was: 20m) > Add a classpath location for patches > > > Key: KNOX-3051 > URL: https://issues.apache.org/jira/browse/KNOX-3051 > Project: Apache Knox > Issue Type: Improvement > Components: Server >Affects Versions: 2.0.0 >Reporter: Philip Zampino >Priority: Minor > Time Spent: 0.5h > Remaining Estimate: 0h > > It would be convenient to have the ability to easily pre-pend classes to the > Knox classpath for quickly applying/testing patches. > If this could be configurable, that would be ideal, though I'm not sure it's > possible. > If hard-coded, we should consider whether or not this location should be > within the Knox installation directory or external to it. There are pros and > cons to both, especially when considering upgrades in managed environments. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Work logged] (KNOX-3051) Add a classpath location for patches
[ https://issues.apache.org/jira/browse/KNOX-3051?focusedWorklogId=946321&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-946321 ] ASF GitHub Bot logged work on KNOX-3051: Author: ASF GitHub Bot Created on: 02/Dec/24 10:09 Start Date: 02/Dec/24 10:09 Worklog Time Spent: 10m Work Description: smolnar82 commented on code in PR #971: URL: https://github.com/apache/knox/pull/971#discussion_r1865570612 ## gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Extender.java: ## @@ -0,0 +1,77 @@ +/* + * 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.apache.knox.gateway.launcher; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Extender { + +private static final String CLASSPATH_EXTENSION_PROPERTY = "gateway.server.classpath.extension"; +private static final String CLASSPATH_PROPERTY_PATTERN = "\\s*" + CLASSPATH_EXTENSION_PROPERTY + "\\s*(.*?)\\s*"; +private static final String CONFIG_FILE = "gateway-site.xml"; +private static final String CONFIG_PATH = "../conf/" + CONFIG_FILE; +private static final String CLASS_PATH_PROPERTY = "class.path"; +private static final String MAIN_CLASS_PROPERTY = "main.class"; +private static final String GATEWAY_SERVER_MAIN_CLASS = "org.apache.knox.gateway.GatewayServer"; +private static final String[] CLASS_PATH_DELIMITERS = new String[]{",", ";"}; + +private final File base; +private final Properties properties; + +public Extender(File base, Properties properties) { +this.base = base; +this.properties = properties; +} + +public void extendClassPathProperty() throws IOException { +Path configFilePath = Paths.get(base.getPath(), CONFIG_PATH); +if (GATEWAY_SERVER_MAIN_CLASS.equals(properties.getProperty(MAIN_CLASS_PROPERTY)) && Files.isReadable(configFilePath)) { +String configContent = new String(Files.readAllBytes(configFilePath), StandardCharsets.UTF_8); +extractExtensionPathIntoProperty(configContent); +} +} + +protected void extractExtensionPathIntoProperty(String configContent) { +Pattern pattern = Pattern.compile(CLASSPATH_PROPERTY_PATTERN, Pattern.DOTALL); +Matcher matcher = pattern.matcher(configContent); Review Comment: nit: they can be `final`. ## gateway-util-launcher/src/test/java/org/apache/knox/gateway/launcher/ExtenderTest.java: ## @@ -0,0 +1,195 @@ +/* + * 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.apache.knox.gateway.launcher; + + +import org.junit.Test; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; + +public class ExtenderTest { + +private Path tempDir; +private Path confDir; +private Path configFilePath; + +@Test +public void extendClassPathPropertyTest() throws IOException { +this.setupDirs(); +Properties properties = new Properties(); +
[jira] [Work logged] (KNOX-3051) Add a classpath location for patches
[ https://issues.apache.org/jira/browse/KNOX-3051?focusedWorklogId=946244&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-946244 ] ASF GitHub Bot logged work on KNOX-3051: Author: ASF GitHub Bot Created on: 01/Dec/24 11:12 Start Date: 01/Dec/24 11:12 Worklog Time Spent: 10m Work Description: hanicz opened a new pull request, #971: URL: https://github.com/apache/knox/pull/971 ## What changes were proposed in this pull request? **Classpath extension for patches** It would be convenient to have the ability to easily pre-pend classes/JARs to the Knox classpath for quickly applying/testing patches. This approach is completely configurable and multiple locations can be configured although their order has to be kept in mind to avoid overrides. Placing any class or JAR in these locations will take precedence on the classpath as it will come first. These locations can be within the Knox installation, external to it or even a mix of them. The logic is checking the gateway-site.xml file for 'gateway.server.classpath.extension' property, if it is there it will extend the classpath with its value. The launcher only modifies the classpath for the GatewayServer. There is a check for the main class that's in the properties and if it is 'org.apache.knox.gateway.GatewayServer' only then the classpath is extended. Example extension: `/new/classpath/jars/*.jar;../patch/*;/new/classpath/classes;` - The different locations should be separated by ',' or ';'. - '*.jar': picks up all jar files in the folder. - '*': picks up all files in the folder. - '/folder': class files are picked up from various folder hierarchies (eq. put GatewayServer.class in org/apache/knox/gateway folder) ## How was this patch tested? - Unit tests - Tested locally with class and JAR files Issue Time Tracking --- Worklog Id: (was: 946244) Remaining Estimate: 0h Time Spent: 10m > Add a classpath location for patches > > > Key: KNOX-3051 > URL: https://issues.apache.org/jira/browse/KNOX-3051 > Project: Apache Knox > Issue Type: Improvement > Components: Server >Affects Versions: 2.0.0 >Reporter: Philip Zampino >Priority: Minor > Time Spent: 10m > Remaining Estimate: 0h > > It would be convenient to have the ability to easily pre-pend classes to the > Knox classpath for quickly applying/testing patches. > If this could be configurable, that would be ideal, though I'm not sure it's > possible. > If hard-coded, we should consider whether or not this location should be > within the Knox installation directory or external to it. There are pros and > cons to both, especially when considering upgrades in managed environments. -- This message was sent by Atlassian Jira (v8.20.10#820010)