View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.creadur.tentacles;
20  
21  import java.io.File;
22  import java.net.URI;
23  import java.net.URISyntaxException;
24  
25  public class Configuration {
26  
27      private static final String DEFAULT_FILE_REPOSITORY_PATH_NAME_FILTER =
28              "org/apache/openejb";
29      private static final String SYSTEM_PROPERTY_NAME_FOR_FILE_REPOSITORY_PATH_NAME_FILTER =
30              "filter";
31      private static final int ARGUMENT_INDEX_FOR_LOCAL_ROOT_DIRECTORY = 1;
32      private static final int ARGUMENT_INDEX_FOR_URI_CONFIGURATION = 0;
33      private static final int ARGUMENT_LENGTH_FOR_URI_CONFIGURATION_ONLY =
34              ARGUMENT_INDEX_FOR_URI_CONFIGURATION + 1;
35  
36      private static URI toURI(final String arg) throws URISyntaxException {
37          final URI uri = new URI(arg);
38          if (arg.startsWith("file:")) {
39              return new File(uri).getAbsoluteFile().toURI();
40          }
41          return uri;
42      }
43  
44      private final URI stagingRepositoryURI;
45      private final String rootDirectoryForLocalOutput;
46      private final String fileRepositoryPathNameFilter;
47  
48      public Configuration(final String... args) throws URISyntaxException {
49          this.stagingRepositoryURI = toURI(args[ARGUMENT_INDEX_FOR_URI_CONFIGURATION]);
50          this.rootDirectoryForLocalOutput = rootDirectoryForLocalOutput(args);
51          this.fileRepositoryPathNameFilter =
52                  System.getProperty(
53                          SYSTEM_PROPERTY_NAME_FOR_FILE_REPOSITORY_PATH_NAME_FILTER,
54                          DEFAULT_FILE_REPOSITORY_PATH_NAME_FILTER);
55      }
56  
57      public String getFileRepositoryPathNameFilter() {
58          return this.fileRepositoryPathNameFilter;
59      }
60  
61      public URI getStagingRepositoryURI() {
62          return this.stagingRepositoryURI;
63      }
64  
65      public String getRootDirectoryForLocalOutput() {
66          return this.rootDirectoryForLocalOutput;
67      }
68  
69      private String rootDirectoryForLocalOutput(final String... args) {
70          final String rootDirectoryForLocal;
71          if (args.length > ARGUMENT_LENGTH_FOR_URI_CONFIGURATION_ONLY) {
72              rootDirectoryForLocal =
73                      args[ARGUMENT_INDEX_FOR_LOCAL_ROOT_DIRECTORY];
74          } else {
75              rootDirectoryForLocal = new File(this.stagingRepositoryURI.getPath()).getName();
76          }
77          return rootDirectoryForLocal;
78      }
79  }