tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [2/6] incubator-tamaya git commit: TAMAYA-43: Bugfix and minor improvements.
Date Sun, 11 Jan 2015 00:43:49 GMT
TAMAYA-43: Bugfix and minor improvements.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/842b33e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/842b33e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/842b33e8

Branch: refs/heads/master
Commit: 842b33e8b3410ce213762cde1883dc2111b9bf3c
Parents: e8cc566
Author: anatole <anatole@apache.org>
Authored: Thu Jan 8 04:14:49 2015 +0100
Committer: anatole <anatole@apache.org>
Committed: Sun Jan 11 01:40:58 2015 +0100

----------------------------------------------------------------------
 modules/resources/pom.xml                       |   5 -
 ...AbstractPathBasedPropertySourceProvider.java |  92 -----------------
 .../AbstractResourcePropertySourceProvider.java | 102 -------------------
 .../tamaya/resource/ResourceResolver.java       |  20 +++-
 .../tamaya/resource/internal/Locator.java       |  41 +++-----
 5 files changed, 34 insertions(+), 226 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/842b33e8/modules/resources/pom.xml
----------------------------------------------------------------------
diff --git a/modules/resources/pom.xml b/modules/resources/pom.xml
index fa1f34e..a932887 100644
--- a/modules/resources/pom.xml
+++ b/modules/resources/pom.xml
@@ -36,10 +36,5 @@ under the License.
             <artifactId>tamaya-api</artifactId>
             <version>${project.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.apache.tamaya.ext</groupId>
-            <artifactId>tamaya-formats</artifactId>
-            <version>${project.version}</version>
-        </dependency>
     </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/842b33e8/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractPathBasedPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractPathBasedPropertySourceProvider.java
b/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractPathBasedPropertySourceProvider.java
deleted file mode 100644
index 58acba3..0000000
--- a/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractPathBasedPropertySourceProvider.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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.tamaya.resource;
-
-import org.apache.tamaya.format.ConfigurationFormat;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.apache.tamaya.spi.ServiceContext;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Implementation of a {@link PropertySourceProvider} that reads configuration from some
given resource paths
- * and using the given formats. The resource path are resolved using the current
- * {@link org.apache.tamaya.resource.ResourceResolver} active.
- */
-public abstract class AbstractPathBasedPropertySourceProvider implements PropertySourceProvider
{
-    /** The logger used. */
-    private static final Logger LOG = Logger.getLogger(AbstractPathBasedPropertySourceProvider.class.getName());
-    /** The property source base name, will be used for creating a useful name of the
-     * {@link org.apache.tamaya.spi.PropertySource} created. */
-    private String sourceName;
-    /** The config formats supported for the given location/resource paths. */
-    private List<ConfigurationFormat> configFormats = new ArrayList<>();
-    /** The paths to be evaluated. */
-    private List<String> paths = new ArrayList<>();
-
-    /**
-     * Creates a new instance.
-     * @param sourceName the base name of the configuration, used for creating PropertySource
child names.
-     * @param formats the formats to be used, not null, not empty.
-     * @param paths the paths to be resolved, not null, not empty.
-     */
-    public AbstractPathBasedPropertySourceProvider(String sourceName, List<ConfigurationFormat>
formats, String... paths) {
-        this.sourceName = Objects.requireNonNull(sourceName);
-        this.configFormats.addAll(Objects.requireNonNull(formats));
-        this.paths.addAll(Arrays.asList(Objects.requireNonNull(paths)));
-    }
-
-    /**
-     * Creates a new instance.
-     * @param sourceName the base name of the configuration, used for creating PropertySource
child names.
-     * @param format the format to be used.
-     * @param paths the paths to be resolved, not null, not empty.
-     */
-    public AbstractPathBasedPropertySourceProvider(String sourceName, ConfigurationFormat
format, String... paths) {
-        this.sourceName = Objects.requireNonNull(sourceName);
-        this.configFormats.add(Objects.requireNonNull(format));
-        this.paths.addAll(Arrays.asList(Objects.requireNonNull(paths)));
-    }
-
-    @Override
-    public Collection<PropertySource> getPropertySources() {
-        List<PropertySource> propertySources = new ArrayList<>();
-        paths.forEach((path) -> {
-            for (URL res : ServiceContext.getInstance().getService(ResourceResolver.class).get().getResources(path))
{
-                try {
-                    for (ConfigurationFormat format : configFormats) {
-                        propertySources.addAll(format.readConfiguration(res));
-                    }
-                } catch (Exception e) {
-                    LOG.log(Level.WARNING, "Failed to add resource based config: " + res,
e);
-                }
-            }
-        });
-        return propertySources;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/842b33e8/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractResourcePropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractResourcePropertySourceProvider.java
b/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractResourcePropertySourceProvider.java
deleted file mode 100644
index f1ec885..0000000
--- a/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractResourcePropertySourceProvider.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.tamaya.resource;
-
-import org.apache.tamaya.format.ConfigurationFormat;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Implementation of a {@link org.apache.tamaya.spi.PropertySourceProvider} that is based
on a single resource
- * and a number of formats.
- */
-public abstract class AbstractResourcePropertySourceProvider implements PropertySourceProvider
{
-    /** The logger used. */
-    private static final Logger LOG = Logger.getLogger(AbstractResourcePropertySourceProvider.class.getName());
-    /** The supported formats. */
-    private List<ConfigurationFormat> formats = new ArrayList<>();
-    /** The resource. */
-    private URL resource;
-    /** The source name used for creating the PropertySource names. */
-    private String sourceName;
-
-    /**
-     * Creates a new instance.
-     * @param resource the {@link URL}, not null.
-     * @param formats the supported formats, not empty.
-     */
-    public AbstractResourcePropertySourceProvider(String sourceName, URL resource, ConfigurationFormat...
formats) {
-        this(sourceName, resource, Arrays.asList(formats));
-    }
-
-    /**
-     * Creates a new instance.
-     * @param resource the {@link URL}, not null.
-     * @param formats the supported formats, not empty.
-     */
-    public AbstractResourcePropertySourceProvider(String sourceName, URL resource, List<ConfigurationFormat>
formats) {
-        this.resource = Objects.requireNonNull(resource);
-        this.sourceName = Objects.requireNonNull(sourceName);
-        if(formats.size()==0){
-            throw new IllegalArgumentException("Format required.");
-        }
-        this.formats.addAll(formats);
-    }
-
-
-    /**
-     * Get the underlying resource.
-     *
-     * @return the underlying resource, never null.
-     */
-    public URL getResource() {
-        return this.resource;
-    }
-
-
-    @Override
-    public String toString() {
-        return "ResourcePropertySourceProvider{" +
-                "resource=" + resource +
-                ", formats=+" + formats +
-                '}';
-    }
-
-    @Override
-    public Collection<PropertySource> getPropertySources() {
-        List<PropertySource> propertySources = new ArrayList<>();
-        for (ConfigurationFormat format : formats) {
-            try {
-                propertySources.addAll(format.readConfiguration(resource));
-            } catch (Exception e) {
-                LOG.info(() -> "Format was not matching: " + format + " for resource:
" + resource);
-            }
-        }
-        return propertySources;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/842b33e8/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java
b/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java
index 31856cf..3dcf6fa 100644
--- a/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java
+++ b/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java
@@ -23,8 +23,24 @@ import java.util.Arrays;
 import java.util.Collection;
 
 /**
- * Interface to be implemented by modules. By default only direct file/resource resolution
is supported, whereas
- * extension modules may add functionality to perform ant styled pattern resolution of format.
+ * Interface to be implemented by modules. It supports loading of files or classpath resources
either directly or by
+ * defining a Ant-styled resource pattern:
+ * <ul>
+ *     <li>'*' is a placeholder for any character (0..n)</li>
+ *     <li>'**' is a placeholder for any number of subdirectories going down a directory
structure recursively.</li>
+ *     <li>'?' is a placeholder for exact one character</li>
+ * </ul>
+ * Given that the following expressions are valid expressions:
+ * <pre>
+ *     classpath:javax/annotations/*
+ *     javax?/annotations&#47;**&#47;*.class
+ *     org/apache/tamaya&#47;**&#47;tamayaconfig.properties
+ *     file:C:/temp/*.txt
+ *     file:C:\**\*.ini
+ *     C:\Programs\**&#47;*.ini
+ *     /user/home/A*b101_?.pid
+ *     /var/logs&#47;**&#47;*.log
+ * </pre>
  */
 public interface ResourceResolver {
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/842b33e8/modules/resources/src/main/java/org/apache/tamaya/resource/internal/Locator.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/Locator.java
b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/Locator.java
index 8d9e08a..8b61f03 100644
--- a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/Locator.java
+++ b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/Locator.java
@@ -21,6 +21,7 @@ package org.apache.tamaya.resource.internal;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.StringJoiner;
 import java.util.stream.Collectors;
 
 /**
@@ -59,19 +60,15 @@ final class Locator {
      * @return the root path, never null.
      */
     public String getRootPath() {
-        StringBuilder builder = new StringBuilder();
-        for (String token : tokens) {
+        StringJoiner sj = new StringJoiner("/");
+        for (String token : getSubPathTokens()) {
             if (containsPlaceholder(token)) {
                 break;
             } else {
-                builder.append(token);
-                builder.append('/');
+                sj.add(token);
             }
         }
-        if (builder.length() > 0) {
-            builder.setLength(builder.length() - 1);
-        }
-        return builder.toString();
+        return sj.toString();
     }
 
     /**
@@ -81,15 +78,11 @@ final class Locator {
      * @return the sub expression part, never null.
      */
     public String getSubPath() {
-        StringBuilder builder = new StringBuilder();
+        StringJoiner sj = new StringJoiner("/");
         for (String token : getSubPathTokens()) {
-            builder.append(token);
-            builder.append('/');
-        }
-        if (builder.length() > 0) {
-            builder.setLength(builder.length() - 1);
+            sj.add(token);
         }
-        return builder.toString();
+        return sj.toString();
     }
 
     /**
@@ -100,10 +93,12 @@ final class Locator {
      */
     public List<String> getSubPathTokens() {
         List<String> subTokens = new ArrayList<>();
+        boolean subTokensStarted = false;
         for (String token : tokens) {
-            if (!containsPlaceholder(token)) {
-                continue;
-            } else {
+            if(subTokensStarted){
+                subTokens.add(token);
+            } else if (containsPlaceholder(token)) {
+                subTokensStarted = true;
                 subTokens.add(token);
             }
         }
@@ -116,15 +111,11 @@ final class Locator {
      * @return the full expression path, never null.
      */
     public String getPath() {
-        StringBuilder builder = new StringBuilder();
+        StringJoiner sj = new StringJoiner("/");
         for (String token : tokens) {
-            builder.append(token);
-            builder.append('/');
-        }
-        if (builder.length() > 0) {
-            builder.setLength(builder.length() - 1);
+            sj.add(token);
         }
-        return builder.toString();
+        return sj.toString();
     }
 
     /**


Mime
View raw message