New utility class
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@615146 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUtils.java b/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUtils.java
new file mode 100644
index 0000000..571fbda
--- /dev/null
+++ b/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUtils.java
@@ -0,0 +1,103 @@
+/*
+ * 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.felix.obr.plugin;
+
+
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.maven.model.Resource;
+
+
+/**
+ * Various OBR utility methods
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ObrUtils
+{
+ private static final String REPO_XML = "repository.xml";
+ private static final String OBR_XML = "obr.xml";
+
+
+ /**
+ * @param baseDir current base directory
+ * @param localRepository path to local maven repository
+ * @param obrRepository path to specific repository.xml
+ * @return URI pointing to correct repository.xml
+ */
+ public static URI findRepositoryXml( File baseDir, String localRepository, String obrRepository )
+ {
+ // Combine location settings into a single repository location
+ if ( null == obrRepository || obrRepository.trim().length() == 0 )
+ {
+ obrRepository = localRepository + '/' + REPO_XML;
+ }
+ else if ( !obrRepository.endsWith( ".xml" ) )
+ {
+ obrRepository = obrRepository + '/' + REPO_XML;
+ }
+
+ URI uri;
+ try
+ {
+ uri = new URI( obrRepository );
+ }
+ catch ( URISyntaxException e )
+ {
+ uri = null;
+ }
+
+ // fall-back to file-system approach
+ if ( null == uri || !uri.isAbsolute() )
+ {
+ File file = new File( obrRepository );
+ if ( !file.isAbsolute() )
+ {
+ file = new File( baseDir, obrRepository );
+ }
+
+ uri = file.toURI();
+ }
+
+ return uri;
+ }
+
+
+ /**
+ * @param resources collection of resource locations
+ * @return URI pointing to correct obr.xml, null if not found
+ */
+ public static URI findObrXml( Collection resources )
+ {
+ for ( Iterator i = resources.iterator(); i.hasNext(); )
+ {
+ Resource resource = ( Resource ) i.next();
+ File obrFile = new File( resource.getDirectory(), OBR_XML );
+ if ( obrFile.exists() )
+ {
+ return obrFile.toURI();
+ }
+ }
+ return null;
+ }
+}