You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mt...@apache.org on 2019/10/05 16:20:32 UTC
svn commit: r1868028 - in /ofbiz/ofbiz-framework/trunk/framework:
base/src/main/java/org/apache/ofbiz/base/component/
base/src/main/java/org/apache/ofbiz/base/container/
base/src/main/java/org/apache/ofbiz/base/util/
catalina/src/main/java/org/apache/o...
Author: mthl
Date: Sat Oct 5 16:20:32 2019
New Revision: 1868028
URL: http://svn.apache.org/viewvc?rev=1868028&view=rev
Log:
Improved: Use ‘Path’ for component config ‘rootLocation’ attribute
(OFBIZ-11192)
The method ‘ComponentConfig#getRootLocation’ has been removed
and replaced by ‘ComponentConfig#rootLocation’.
The callers have been adapted.
Modified:
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilJavaParse.java
ofbiz/ofbiz-framework/trunk/framework/catalina/src/main/java/org/apache/ofbiz/catalina/container/CatalinaContainer.java
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataLoadContainer.java
ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/artifactinfo/ComponentList.groovy
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelManagerFactory.java
ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java
Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java?rev=1868028&r1=1868027&r2=1868028&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java Sat Oct 5 16:20:32 2019
@@ -18,9 +18,11 @@
*******************************************************************************/
package org.apache.ofbiz.base.component;
-import java.io.File;
import java.io.InputStream;
import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.security.KeyStore;
import java.util.ArrayList;
import java.util.Collection;
@@ -226,7 +228,7 @@ public final class ComponentConfig {
public static String getRootLocation(String componentName) throws ComponentException {
ComponentConfig cc = getComponentConfig(componentName);
- return cc.getRootLocation();
+ return cc.rootLocation().toString();
}
public static InputStream getStream(String componentName, String resourceLoaderName, String location) throws ComponentException {
@@ -257,7 +259,7 @@ public final class ComponentConfig {
// ========== ComponentConfig instance ==========
private final String globalName;
- private final String rootLocation;
+ private final Path rootLocation;
private final String componentName;
private final boolean enabled;
private final Map<String, ResourceLoaderInfo> resourceLoaderInfos;
@@ -280,7 +282,8 @@ public final class ComponentConfig {
*/
private ComponentConfig(Builder b) {
this.globalName = b.globalName;
- this.rootLocation = b.rootLocation;
+ String rootLocation = (b.rootLocation == null) ? "" : b.rootLocation;
+ this.rootLocation = Paths.get(rootLocation.replace('\\', '/')).normalize().toAbsolutePath();
this.componentName = b.componentName;
this.enabled = b.enabled;
this.resourceLoaderInfos = b.resourceLoaderInfos;
@@ -392,17 +395,13 @@ public final class ComponentConfig {
* @throws NullPointerException when {@code rootLocation} is {@code null}
*/
private ComponentConfig(String globalName, String rootLocation) throws ComponentException {
- if (!rootLocation.endsWith("/")) {
- rootLocation = rootLocation + "/";
- }
- this.rootLocation = rootLocation.replace('\\', '/');
- File rootLocationDir = new File(rootLocation);
- if (!rootLocationDir.exists()) {
+ this.rootLocation = Paths.get(rootLocation.replace('\\', '/')).normalize().toAbsolutePath();
+ if (Files.notExists(this.rootLocation)) {
throw new ComponentException("The component root location does not exist: " + rootLocation);
- } else if (!rootLocationDir.isDirectory()) {
+ } else if (!Files.isDirectory(this.rootLocation)) {
throw new ComponentException("The component root location is not a directory: " + rootLocation);
}
- String xmlFilename = this.rootLocation + "/" + OFBIZ_COMPONENT_XML_FILENAME;
+ String xmlFilename = this.rootLocation.resolve(OFBIZ_COMPONENT_XML_FILENAME).toString();
URL xmlUrl = UtilURL.fromFilename(xmlFilename);
if (xmlUrl == null) {
throw new ComponentException("Could not find the " + OFBIZ_COMPONENT_XML_FILENAME
@@ -486,6 +485,7 @@ public final class ComponentConfig {
// pre-pend component root location if this is a type component resource-loader
if ("component".equals(resourceLoaderInfo.type)) {
buf.append(rootLocation);
+ buf.append('/');
}
if (UtilValidate.isNotEmpty(resourceLoaderInfo.prependEnv)) {
@@ -520,8 +520,13 @@ public final class ComponentConfig {
return this.resourceLoaderInfos;
}
- public String getRootLocation() {
- return this.rootLocation;
+ /**
+ * Provides the root location of the component definition.
+ *
+ * @return a normalized absolute path
+ */
+ public Path rootLocation() {
+ return rootLocation;
}
public List<ServiceResourceInfo> getServiceResourceInfos() {
@@ -633,7 +638,7 @@ public final class ComponentConfig {
private synchronized ComponentConfig put(ComponentConfig config) {
String globalName = config.getGlobalName();
- String fileLocation = config.getRootLocation();
+ String fileLocation = config.rootLocation().toString();
componentLocations.put(fileLocation, globalName);
return componentConfigs.put(globalName, config);
}
@@ -1070,7 +1075,7 @@ public final class ComponentConfig {
}
public String getLocation() {
- return componentConfig.getRootLocation() + location;
+ return componentConfig.rootLocation().resolve(location).toString();
}
public String getName() {
Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java?rev=1868028&r1=1868027&r2=1868028&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java Sat Oct 5 16:20:32 2019
@@ -25,7 +25,6 @@ import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -335,8 +334,7 @@ public class ComponentContainer implemen
*/
private static Classpath buildClasspathFromComponentConfig(ComponentConfig config) throws IOException {
Classpath classPath = new Classpath();
- String configRoot = config.getRootLocation().replace('\\', '/');
- configRoot = configRoot.endsWith("/") ? configRoot : configRoot + "/";
+ Path configRoot = config.rootLocation();
List<ComponentConfig.ClasspathInfo> classpathInfos = config.getClasspathInfos();
for (ComponentConfig.ClasspathInfo cp: classpathInfos) {
@@ -348,7 +346,7 @@ public class ComponentContainer implemen
location = location.startsWith("/") ? location.substring(1) : location;
String dirLoc = location.endsWith("/*") ? location.substring(0, location.length() - 2) : location;
- Path path = Paths.get(configRoot + dirLoc).toAbsolutePath().normalize();
+ Path path = configRoot.resolve(dirLoc).normalize();
if (Files.exists(path)) {
classPath.add(path, cp.type);
} else {
Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilJavaParse.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilJavaParse.java?rev=1868028&r1=1868027&r2=1868028&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilJavaParse.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilJavaParse.java Sat Oct 5 16:20:32 2019
@@ -19,6 +19,8 @@
package org.apache.ofbiz.base.util;
import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -100,32 +102,24 @@ public final class UtilJavaParse {
Collection<ComponentConfig> allComponentConfigs = ComponentConfig.getAllComponents();
for (ComponentConfig cc: allComponentConfigs) {
- String rootDirectory = cc.getRootLocation();
- if (!rootDirectory.endsWith(File.separatorChar + "")) {
- rootDirectory += File.separatorChar;
- }
- rootDirectory += "src" + File.separatorChar;
-
- File rootDirFile = new File(rootDirectory);
- if (!rootDirFile.exists()) {
+ Path rootDirectory = cc.rootLocation().resolve("src");
+ if (Files.notExists(rootDirectory)) {
// no src directory, move along
continue;
}
- String classDir = rootDirectory + sourceSubPath;
- File classDirFile = new File(classDir);
- if (!classDirFile.exists()) {
+ Path classDir = rootDirectory.resolve(sourceSubPath);
+ if (Files.notExists(classDir)) {
// no src class sub-directory, move along
continue;
}
- String fullPathAndFile = classDir + File.separatorChar + classFileName;
- File classFile = new File(fullPathAndFile);
- if (classFile.exists()) {
+ Path fullPathAndFile = classDir.resolve(classFileName);
+ if (Files.notExists(fullPathAndFile)) {
if (Debug.verboseOn()) {
Debug.logVerbose("In findRealPathAndFileForClass for [" + fullyQualifiedClassName + "]: [" + fullPathAndFile + "]", module);
}
- return fullPathAndFile;
+ return fullPathAndFile.toString();
}
}
Modified: ofbiz/ofbiz-framework/trunk/framework/catalina/src/main/java/org/apache/ofbiz/catalina/container/CatalinaContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/catalina/src/main/java/org/apache/ofbiz/catalina/container/CatalinaContainer.java?rev=1868028&r1=1868027&r2=1868028&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/catalina/src/main/java/org/apache/ofbiz/catalina/container/CatalinaContainer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/catalina/src/main/java/org/apache/ofbiz/catalina/container/CatalinaContainer.java Sat Oct 5 16:20:32 2019
@@ -561,12 +561,10 @@ public class CatalinaContainer implement
}
private static String getWebappRootLocation(ComponentConfig.WebappInfo appInfo) {
- String location = appInfo.componentConfig.getRootLocation() + appInfo.location;
- location = location.replace('\\', '/');
- if (location.endsWith("/")) {
- location = location.substring(0, location.length() - 1);
- }
- return location;
+ return appInfo.componentConfig.rootLocation()
+ .resolve(appInfo.location.replace('\\', '/'))
+ .normalize()
+ .toString();
}
private static String getWebappMountPoint(ComponentConfig.WebappInfo appInfo) {
Modified: ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataLoadContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataLoadContainer.java?rev=1868028&r1=1868027&r2=1868028&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataLoadContainer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataLoadContainer.java Sat Oct 5 16:20:32 2019
@@ -279,7 +279,7 @@ public class EntityDataLoadContainer imp
for (ComponentConfig config : allComponents) {
GenericValue componentEntry = baseDelegator.makeValue("Component");
componentEntry.set("componentName", config.getComponentName());
- componentEntry.set("rootLocation", config.getRootLocation());
+ componentEntry.set("rootLocation", config.rootLocation().toString());
try {
GenericValue componentCheck = EntityQuery.use(baseDelegator)
.from("Component")
Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/artifactinfo/ComponentList.groovy
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/artifactinfo/ComponentList.groovy?rev=1868028&r1=1868027&r2=1868028&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/artifactinfo/ComponentList.groovy (original)
+++ ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/artifactinfo/ComponentList.groovy Sat Oct 5 16:20:32 2019
@@ -33,7 +33,7 @@ components.each { component ->
webApps.each { webApp ->
componentMap = [:]
componentMap.compName = component.getComponentName()
- componentMap.rootLocation = component.getRootLocation()
+ componentMap.rootLocation = component.rootLocation().toString()
componentMap.enabled = (component.enabled() == true? "Y" : "N")
componentMap.webAppName = webApp.getName()
componentMap.contextRoot = webApp.getContextRoot()
@@ -46,7 +46,7 @@ components.each { component ->
if (!webApps) {
componentMap = [:]
componentMap.compName = component.getComponentName()
- componentMap.rootLocation = component.getRootLocation()
+ componentMap.rootLocation = component.rootLocation().toString()
componentMap.enabled = (component.enabled() == true? "Y" : "N")
componentList.add(componentMap)
componentMap.webAppName = ""
Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java?rev=1868028&r1=1868027&r2=1868028&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java Sat Oct 5 16:20:32 2019
@@ -395,7 +395,7 @@ public class ArtifactInfoFactory {
private Callable<Void> prepareTaskForComponentAnalysis(final ComponentConfig componentConfig) {
return () -> {
String componentName = componentConfig.getGlobalName();
- String rootComponentPath = componentConfig.getRootLocation();
+ String rootComponentPath = componentConfig.rootLocation().toString();
List<File> screenFiles = new ArrayList<>();
List<File> formFiles = new ArrayList<>();
List<File> controllerFiles = new ArrayList<>();
Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelManagerFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelManagerFactory.java?rev=1868028&r1=1868027&r2=1868028&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelManagerFactory.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelManagerFactory.java Sat Oct 5 16:20:32 2019
@@ -21,6 +21,7 @@ package org.apache.ofbiz.webtools.labelm
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.nio.file.Path;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
@@ -84,16 +85,13 @@ public class LabelManagerFactory {
List<ClasspathInfo> cpInfos = ComponentConfig.getAllClasspathInfos();
for (ClasspathInfo cpi : cpInfos) {
if ("dir".equals(cpi.type)) {
- String configRoot = cpi.componentConfig.getRootLocation();
- configRoot = configRoot.replace('\\', '/');
- if (!configRoot.endsWith("/")) {
- configRoot = configRoot + "/";
- }
+ Path configRoot = cpi.componentConfig.rootLocation();
String location = cpi.location.replace('\\', '/');
if (location.startsWith("/")) {
location = location.substring(1);
}
- List<File> resourceFiles = FileUtil.findXmlFiles(configRoot + location, null, "resource", null);
+ Path fullLocation = configRoot.resolve(location);
+ List<File> resourceFiles = FileUtil.findXmlFiles(fullLocation.toString(), null, "resource", null);
for (File resourceFile : resourceFiles) {
filesFound.put(resourceFile.getName(), new LabelFile(resourceFile, cpi.componentConfig.getComponentName()));
}
Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java?rev=1868028&r1=1868027&r2=1868028&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java Sat Oct 5 16:20:32 2019
@@ -21,6 +21,7 @@ package org.apache.ofbiz.webtools.labelm
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.nio.file.Path;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
@@ -67,7 +68,7 @@ public class LabelReferences {
protected DispatchContext dispatchContext;
protected Map<String, LabelInfo> labels;
protected Set<String> labelSet = new HashSet<>();
- protected Set<String> rootFolders = new HashSet<>();
+ protected Set<Path> rootFolders = new HashSet<>();
public LabelReferences(Delegator delegator, LabelManagerFactory factory) {
this.delegator = delegator;
@@ -93,11 +94,7 @@ public class LabelReferences {
}
Collection<ComponentConfig> componentConfigs = ComponentConfig.getAllComponents();
for (ComponentConfig config : componentConfigs) {
- String rootFolder = config.getRootLocation();
- rootFolder = rootFolder.replace('\\', '/');
- if (!rootFolder.endsWith("/")) {
- rootFolder = rootFolder + "/";
- }
+ Path rootFolder = config.rootLocation();
this.rootFolders.add(rootFolder);
}
}
@@ -117,9 +114,9 @@ public class LabelReferences {
getLabelsFromSimpleMethodFiles();
// get labels from widgets files
List<File> fileList = new LinkedList<>();
- for (String rootFolder : this.rootFolders) {
- fileList.addAll(FileUtil.findXmlFiles(rootFolder + "webapp", null, null, null));
- fileList.addAll(FileUtil.findXmlFiles(rootFolder + "widget", null, null, null));
+ for (Path rootFolder : this.rootFolders) {
+ fileList.addAll(FileUtil.findXmlFiles(rootFolder.resolve("webapp").toString(), null, null, null));
+ fileList.addAll(FileUtil.findXmlFiles(rootFolder.resolve("widget").toString(), null, null, null));
}
for (File file : fileList) {
String inFile = FileUtil.readString("UTF-8", file);
@@ -159,8 +156,8 @@ public class LabelReferences {
}
private void getLabelsFromFtlFiles() throws IOException {
- for (String rootFolder : this.rootFolders) {
- List<File> ftlFiles = FileUtil.findFiles("ftl", rootFolder, null, null);
+ for (Path rootFolder : this.rootFolders) {
+ List<File> ftlFiles = FileUtil.findFiles("ftl", rootFolder.toString(), null, null);
for (File file : ftlFiles) {
String inFile = FileUtil.readString("UTF-8", file);
inFile = inFile.replaceAll(getResourceRegex, getResource);
@@ -182,8 +179,8 @@ public class LabelReferences {
}
}
private void getLabelsFromJavaFiles() throws IOException {
- for (String rootFolder : this.rootFolders) {
- List<File> javaFiles = FileUtil.findFiles("java", rootFolder + "src", null, null);
+ for (Path rootFolder : this.rootFolders) {
+ List<File> javaFiles = FileUtil.findFiles("java", rootFolder.resolve("src").toString(), null, null);
for (File javaFile : javaFiles) {
// do not parse this file, else issue with getResourceRegex
if ("LabelReferences.java".equals(javaFile.getName())) continue;
@@ -195,8 +192,9 @@ public class LabelReferences {
}
}
private void getLabelsFromGroovyFiles() throws IOException {
- for (String rootFolder : this.rootFolders) {
- List<File> groovyFiles = FileUtil.findFiles("groovy", rootFolder + "groovyScripts", null, null);
+ for (Path rootFolder : this.rootFolders) {
+ List<File> groovyFiles =
+ FileUtil.findFiles("groovy", rootFolder.resolve("groovyScripts").toString(), null, null);
for (File file : groovyFiles) {
String inFile = FileUtil.readString("UTF-8", file);
findUiLabelMapInPattern(inFile, uiLabelMap, file.getPath());
@@ -285,8 +283,9 @@ public class LabelReferences {
}
private void getLabelsFromSimpleMethodFiles() throws IOException {
- for (String rootFolder : this.rootFolders) {
- List<File> simpleMethodsFiles = FileUtil.findFiles("xml", rootFolder + "minilang", null, null);
+ for (Path rootFolder : this.rootFolders) {
+ List<File> simpleMethodsFiles =
+ FileUtil.findFiles("xml", rootFolder.resolve("minilang").toString(), null, null);
for (File file : simpleMethodsFiles) {
String inFile = FileUtil.readString("UTF-8", file);
findUiLabelMapInFile(inFile, file.getPath());