You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2007/09/04 16:52:51 UTC
svn commit: r572697 [2/4] - in /felix/sandbox/clement/maven-obr-plugin: ./
src/ src/main/ src/main/java/ src/main/java/bundles/
src/main/java/bundles/obr/ src/main/java/bundles/obr/resource/
src/main/java/org/ src/main/java/org/apache/ src/main/java/or...
Added: felix/sandbox/clement/maven-obr-plugin/src/main/java/bundles/obr/resource/Tag.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/maven-obr-plugin/src/main/java/bundles/obr/resource/Tag.java?rev=572697&view=auto
==============================================================================
--- felix/sandbox/clement/maven-obr-plugin/src/main/java/bundles/obr/resource/Tag.java (added)
+++ felix/sandbox/clement/maven-obr-plugin/src/main/java/bundles/obr/resource/Tag.java Tue Sep 4 07:52:47 2007
@@ -0,0 +1,471 @@
+package bundles.obr.resource;
+
+import java.io.*;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * The Tag class represents a minimal XML tree. It consist of a named element
+ * with a hashtable of named attributes. Methods are provided to walk the tree
+ * and get its constituents. The content of a Tag is a list that contains String
+ * objects or other Tag objects.
+ */
+public class Tag {
+ Tag parent;
+ String name;
+ Map attributes = new TreeMap();
+ Vector content = new Vector();
+
+ static SimpleDateFormat format = new SimpleDateFormat(
+ "yyyyMMddhhmmss.SSS");
+
+ /**
+ * Construct a new Tag with a name.
+ */
+ public Tag(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Construct a new Tag with a name.
+ */
+ public Tag(String name, Map attributes) {
+ this.name = name;
+ this.attributes = attributes;
+ }
+
+ /**
+ * Construct a new Tag with a name and a set of attributes. The attributes
+ * are given as ( name, value ) ...
+ */
+ public Tag(String name, String[] attributes) {
+ this.name = name;
+ for (int i = 0; i < attributes.length; i += 2)
+ addAttribute(attributes[i], attributes[i + 1]);
+ }
+
+ /**
+ * Construct a new Tag with a single string as content.
+ */
+ public Tag(String name, String content) {
+ this.name = name;
+ addContent(content);
+ }
+
+ /**
+ * Add a new attribute.
+ */
+ public void addAttribute(String key, String value) {
+ attributes.put(key, value);
+ }
+
+ /**
+ * Add a new attribute.
+ */
+ public void addAttribute(String key, Object value) {
+ if (value == null)
+ return;
+ attributes.put(key, value.toString());
+ }
+
+ /**
+ * Add a new attribute.
+ */
+ public void addAttribute(String key, int value) {
+ attributes.put(key, Integer.toString(value));
+ }
+
+ /**
+ * Add a new date attribute. The date is formatted as the SimpleDateFormat
+ * describes at the top of this class.
+ */
+ public void addAttribute(String key, Date value) {
+ attributes.put(key, format.format(value));
+ }
+
+ /**
+ * Add a new content string.
+ */
+ public void addContent(String string) {
+ content.addElement(string);
+ }
+
+ /**
+ * Add a new content tag.
+ */
+ public void addContent(Tag tag) {
+ content.addElement(tag);
+ tag.parent = this;
+ }
+
+ /**
+ * Return the name of the tag.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Return the attribute value.
+ */
+ public String getAttribute(String key) {
+ return (String) attributes.get(key);
+ }
+
+ /**
+ * Return the attribute value or a default if not defined.
+ */
+ public String getAttribute(String key, String deflt) {
+ String answer = getAttribute(key);
+ return answer == null ? deflt : answer;
+ }
+
+ /**
+ * Answer the attributes as a Dictionary object.
+ */
+ public Map getAttributes() {
+ return attributes;
+ }
+
+ /**
+ * Return the contents.
+ */
+ public Vector getContents() {
+ return content;
+ }
+
+ /**
+ * Return a string representation of this Tag and all its children
+ * recursively.
+ */
+ public String toString() {
+ StringWriter sw = new StringWriter();
+ print(0, new PrintWriter(sw));
+ return sw.toString();
+ }
+
+ /**
+ * Return only the tags of the first level of descendants that match the
+ * name.
+ */
+ public Vector getContents(String tag) {
+ Vector out = new Vector();
+ for (Enumeration e = content.elements(); e.hasMoreElements();) {
+ Object o = e.nextElement();
+ if (o instanceof Tag && ((Tag) o).getName().equals(tag))
+ out.addElement(o);
+ }
+ return out;
+ }
+
+ /**
+ * Return the whole contents as a String (no tag info and attributes).
+ */
+ public String getContentsAsString() {
+ StringBuffer sb = new StringBuffer();
+ getContentsAsString(sb);
+ return sb.toString();
+ }
+
+ /**
+ * convenient method to get the contents in a StringBuffer.
+ */
+ public void getContentsAsString(StringBuffer sb) {
+ for (Enumeration e = content.elements(); e.hasMoreElements();) {
+ Object o = e.nextElement();
+ if (o instanceof Tag)
+ ((Tag) o).getContentsAsString(sb);
+ else
+ sb.append(o.toString());
+ }
+ }
+
+ /**
+ * Print the tag formatted to a PrintWriter.
+ */
+ public void print(int indent, PrintWriter pw) {
+ pw.print("\n");
+ spaces(pw, indent);
+ pw.print('<');
+ pw.print(name);
+
+ for (Iterator e = attributes.keySet().iterator(); e.hasNext();) {
+ String key = (String) e.next();
+ String value = escape((String) attributes.get(key));
+ pw.print(' ');
+ pw.print(key);
+ pw.print("=");
+ String quote = "'";
+ if (value.indexOf(quote) >= 0)
+ quote = "\"";
+ pw.print(quote);
+ pw.print(value);
+ pw.print(quote);
+ }
+
+ if (content.size() == 0)
+ pw.print('/');
+ else {
+ pw.print('>');
+ for (Enumeration e = content.elements(); e.hasMoreElements();) {
+ Object content = e.nextElement();
+ if (content instanceof String) {
+ formatted(pw, indent + 2, 60, escape((String) content));
+ }
+ else if (content instanceof Tag) {
+ Tag tag = (Tag) content;
+ tag.print(indent + 2, pw);
+ }
+ }
+ pw.print("\n");
+ spaces(pw, indent);
+ pw.print("</");
+ pw.print(name);
+ }
+ pw.print('>');
+ }
+
+ /**
+ * Convenience method to print a string nicely and does character conversion
+ * to entities.
+ */
+ void formatted(PrintWriter pw, int left, int width, String s) {
+ int pos = width + 1;
+ s = s.trim();
+
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+ if (i == 0 || (Character.isWhitespace(c) && pos > width - 3)) {
+ pw.print("\n");
+ spaces(pw, left);
+ pos = 0;
+ }
+ switch (c) {
+ case '<' :
+ pw.print("<");
+ pos += 4;
+ break;
+ case '>' :
+ pw.print(">");
+ pos += 4;
+ break;
+ case '&' :
+ pw.print("&");
+ pos += 5;
+ break;
+ default :
+ pw.print(c);
+ pos++;
+ break;
+ }
+
+ }
+ }
+
+ /**
+ * Escape a string, do entity conversion.
+ */
+ String escape(String s) {
+ if ( s == null )
+ System.out.println("??");
+
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+ switch (c) {
+ case '<' :
+ sb.append("<");
+ break;
+ case '>' :
+ sb.append(">");
+ break;
+ case '&' :
+ sb.append("&");
+ break;
+ default :
+ sb.append(c);
+ break;
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Make spaces.
+ */
+ void spaces(PrintWriter pw, int n) {
+ while (n-- > 0)
+ pw.print(' ');
+ }
+
+ /**
+ * root/preferences/native/os
+ */
+ public Tag[] select(String path) {
+ return select(path, (Tag) null);
+ }
+
+ public Tag[] select(String path, Tag mapping) {
+ Vector v = new Vector();
+ select(path, v, mapping);
+ Tag[] result = new Tag[v.size()];
+ v.copyInto(result);
+ return result;
+ }
+
+ void select(String path, Vector results, Tag mapping) {
+ if (path.startsWith("//")) {
+ int i = path.indexOf('/', 2);
+ String name = path.substring(2, i < 0 ? path.length() : i);
+
+ for (Enumeration e = content.elements(); e.hasMoreElements();) {
+ Object o = e.nextElement();
+ if (o instanceof Tag) {
+ Tag child = (Tag) o;
+ if (match(name, child, mapping))
+ results.add(child);
+ child.select(path, results, mapping);
+ }
+
+ }
+ return;
+ }
+
+ if (path.length() == 0) {
+ results.addElement(this);
+ return;
+ }
+
+ int i = path.indexOf("/");
+ String elementName = path;
+ String remainder = "";
+ if (i > 0) {
+ elementName = path.substring(0, i);
+ remainder = path.substring(i + 1);
+ }
+
+ for (Enumeration e = content.elements(); e.hasMoreElements();) {
+ Object o = e.nextElement();
+ if (o instanceof Tag) {
+ Tag child = (Tag) o;
+ if (child.getName().equals(elementName)
+ || elementName.equals("*"))
+ child.select(remainder, results, mapping);
+ }
+ }
+ }
+
+ public boolean match(String search, Tag child, Tag mapping) {
+ String target = child.getName();
+ String sn = null;
+ String tn = null;
+
+ if (search.equals("*"))
+ return true;
+
+ int s = search.indexOf(':');
+ if (s > 0) {
+ sn = search.substring(0, s);
+ search = search.substring(s + 1);
+ }
+ int t = target.indexOf(':');
+ if (t > 0) {
+ tn = target.substring(0, t);
+ target = target.substring(t + 1);
+ }
+
+ if (!search.equals(target)) // different tag names
+ return false;
+
+ if (mapping == null) {
+ return tn == sn || (sn != null && sn.equals(tn));
+ }
+ else {
+ String suri = sn == null ? mapping.getAttribute("xmlns") : mapping
+ .getAttribute("xmlns:" + sn);
+ String turi = tn == null ? child.findRecursiveAttribute("xmlns")
+ : child.findRecursiveAttribute("xmlns:" + tn);
+ return turi == suri
+ || (turi != null && suri != null && turi.equals(suri));
+ }
+ }
+
+ public String getString(String path) {
+ String attribute = null;
+ int index = path.indexOf("@");
+ if (index >= 0) {
+ // attribute
+ attribute = path.substring(index + 1);
+
+ if (index > 0) {
+ // prefix path
+ path = path.substring(index - 1); // skip -1
+ }
+ else
+ path = "";
+ }
+ Tag tags[] = select(path);
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < tags.length; i++) {
+ if (attribute == null)
+ tags[i].getContentsAsString(sb);
+ else
+ sb.append(tags[i].getAttribute(attribute));
+ }
+ return sb.toString();
+ }
+
+ public String getStringContent() {
+ StringBuffer sb = new StringBuffer();
+ for (Enumeration e = content.elements(); e.hasMoreElements();) {
+ Object c = e.nextElement();
+ if (!(c instanceof Tag))
+ sb.append(c);
+ }
+ return sb.toString();
+ }
+
+ public String getNameSpace() {
+ return getNameSpace(name);
+ }
+
+ public String getNameSpace(String name) {
+ int index = name.indexOf(':');
+ if (index > 0) {
+ String ns = name.substring(0, index);
+ return findRecursiveAttribute("xmlns:" + ns);
+ }
+ else
+ return findRecursiveAttribute("xmlns");
+ }
+
+ public String findRecursiveAttribute(String name) {
+ String value = getAttribute(name);
+ if (value != null)
+ return value;
+ if (parent != null)
+ return parent.findRecursiveAttribute(name);
+ return null;
+ }
+
+ public String getLocalName() {
+ int index = name.indexOf(':');
+ if (index <= 0)
+ return name;
+
+ return name.substring(index + 1);
+ }
+
+ public void rename(String string) {
+ name = string;
+ }
+
+
+ public static void convert( Collection c, String type, Tag parent ) {
+ for ( Iterator i=c.iterator(); i.hasNext(); ) {
+ Map map = (Map) i.next();
+ parent.addContent( new Tag(type, map) );
+ }
+ }
+
+}
Added: felix/sandbox/clement/maven-obr-plugin/src/main/java/bundles/obr/resource/VersionImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/maven-obr-plugin/src/main/java/bundles/obr/resource/VersionImpl.java?rev=572697&view=auto
==============================================================================
--- felix/sandbox/clement/maven-obr-plugin/src/main/java/bundles/obr/resource/VersionImpl.java (added)
+++ felix/sandbox/clement/maven-obr-plugin/src/main/java/bundles/obr/resource/VersionImpl.java Tue Sep 4 07:52:47 2007
@@ -0,0 +1,121 @@
+/*
+ * $Header: /cvshome/bundles/bundles.obr/src/bundles/obr/resource/VersionImpl.java,v 1.3 2006/02/15 16:36:57 pkriens Exp $
+ *
+ * Copyright (c) OSGi Alliance (2004, 2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package bundles.obr.resource;
+
+import org.osgi.framework.Version;
+
+/**
+ * Version identifier for bundles and packages.
+ *
+ * <p>
+ * Version identifiers have four components.
+ * <ol>
+ * <li>Major version. A non-negative integer.</li>
+ * <li>Minor version. A non-negative integer.</li>
+ * <li>Micro version. A non-negative integer.</li>
+ * <li>Qualifier. A text string. See <code>Version(String)</code> for the
+ * format of the qualifier string.</li>
+ * </ol>
+ *
+ * <p>
+ * <code>Version</code> objects are immutable.
+ *
+ * @version $Revision: 1.3 $
+ * @since 1.3
+ */
+
+public class VersionImpl extends Version {
+ VersionRange range;
+
+ /**
+ * Creates a version identifier from the specified numerical components.
+ *
+ * <p>
+ * The qualifier is set to the empty string.
+ *
+ * @param major Major component of the version identifier.
+ * @param minor Minor component of the version identifier.
+ * @param micro Micro component of the version identifier.
+ * @throws IllegalArgumentException If the numerical components are
+ * negative.
+ */
+ public VersionImpl(int major, int minor, int micro) {
+ this(major, minor, micro, null);
+ }
+
+ /**
+ * Creates a version identifier from the specifed components.
+ *
+ * @param major Major component of the version identifier.
+ * @param minor Minor component of the version identifier.
+ * @param micro Micro component of the version identifier.
+ * @param qualifier Qualifier component of the version identifier. If
+ * <code>null</code> is specified, then the qualifier will be set
+ * to the empty string.
+ * @throws IllegalArgumentException If the numerical components are negative
+ * or the qualifier string is invalid.
+ */
+ public VersionImpl(int major, int minor, int micro, String qualifier) {
+ super(major, minor, micro, qualifier);
+ }
+
+ // TODO Ugly!
+ public VersionImpl(String string) {
+ super(
+ string.indexOf("[") >= 0 || string.indexOf("(") >= 0 ? new VersionRange(
+ string).getMinimum().toString()
+ : string);
+ if ( string.indexOf("[") >= 0 || string.indexOf("(") >= 0 )
+ range = new VersionRange(string);
+ }
+
+ VersionRange getRange() {
+ return range;
+ }
+ /**
+ * this other 0 1 -1
+ *
+ * @param o
+ * @return
+ * @see org.osgi.framework.Version#compareTo(java.lang.Object)
+ */
+ public int compareTo(Object o) {
+ if ( o instanceof VersionImpl ) {
+ VersionImpl other = (VersionImpl) o;
+ int cs = 0;
+ if ( range != null )
+ cs++;
+ if ( other.range!=null)
+ cs+=2;
+ switch (cs ) {
+ case 0: // V1 V2
+ return super.compareTo(other);
+
+ case 1: // R1 V2
+ return range.isIncluded(other) ? 0 : 1;
+
+ case 2: // V1 R2
+ return other.range.isIncluded(this) ? 0 : 1;
+
+ // TODO experimental
+ case 3: // R1 R2
+ return range.isIncluded(other.range.getMinimum()) && range.isIncluded(other.range.getMaximum()) ? 0 : 1;
+ }
+ return -1;
+ } else {
+ return super.compareTo(o);
+ }
+ }
+
+ public boolean equals(Object other) {
+ return compareTo(other) == 0;
+ }
+}
\ No newline at end of file
Added: felix/sandbox/clement/maven-obr-plugin/src/main/java/bundles/obr/resource/VersionRange.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/maven-obr-plugin/src/main/java/bundles/obr/resource/VersionRange.java?rev=572697&view=auto
==============================================================================
--- felix/sandbox/clement/maven-obr-plugin/src/main/java/bundles/obr/resource/VersionRange.java (added)
+++ felix/sandbox/clement/maven-obr-plugin/src/main/java/bundles/obr/resource/VersionRange.java Tue Sep 4 07:52:47 2007
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package bundles.obr.resource;
+
+import org.osgi.framework.Version;
+
+/**
+ * This class represents a version range.
+ * @since 3.1
+ */
+public class VersionRange {
+ private static final Version versionMax = new Version(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
+ /**
+ * An empty version
+ */
+ public static final VersionRange emptyRange = new VersionRange(null);
+
+ private Version minVersion;
+ private boolean includeMin;
+ private Version maxVersion;
+ private boolean includeMax;
+
+ /**
+ * Constructs a VersionRange with the specified minVersion and maxVersion.
+ * @param minVersion the minimum version of the range
+ * @param maxVersion the maximum version of the range
+ */
+ public VersionRange(Version minVersion, boolean includeMin, Version maxVersion, boolean includeMax) {
+ this.minVersion = minVersion;
+ this.includeMin = includeMin;
+ this.maxVersion = maxVersion;
+ this.includeMax = includeMax;
+ }
+
+ /**
+ * Constructs a VersionRange from the given versionRange String.
+ * @param versionRange a version range String that specifies a range of
+ * versions.
+ */
+ public VersionRange(String versionRange) {
+ if (versionRange == null || versionRange.length() == 0) {
+ minVersion = Version.emptyVersion;
+ includeMin = true;
+ maxVersion = VersionRange.versionMax;
+ includeMax = true;
+ return;
+ }
+ versionRange = versionRange.trim();
+ if (versionRange.charAt(0) == '[' || versionRange.charAt(0) == '(') {
+ int comma = versionRange.indexOf(',');
+ if (comma < 0)
+ throw new IllegalArgumentException();
+ char last = versionRange.charAt(versionRange.length() - 1);
+ if (last != ']' && last != ')')
+ throw new IllegalArgumentException();
+
+ minVersion = Version.parseVersion(versionRange.substring(1, comma).trim());
+ includeMin = versionRange.charAt(0) == '[';
+ maxVersion = Version.parseVersion(versionRange.substring(comma + 1, versionRange.length() - 1).trim());
+ includeMax = last == ']';
+ } else {
+ minVersion = Version.parseVersion(versionRange.trim());
+ includeMin = true;
+ maxVersion = VersionRange.versionMax;
+ includeMax = true;
+ }
+ }
+
+ /**
+ * Returns the minimum Version of this VersionRange
+ * @return the minimum Version of this VersionRange
+ */
+ public Version getMinimum() {
+ return minVersion;
+ }
+
+ /**
+ * Indicates if the minimum version is included in the version range.
+ * @return true if the minimum version is included in the version range;
+ * otherwise false is returned
+ */
+ public boolean getIncludeMinimum() {
+ return includeMin;
+ }
+
+ /**
+ * Returns the maximum Version of this VersionRange
+ * @return the maximum Version of this VersionRange
+ */
+ public Version getMaximum() {
+ return maxVersion;
+ }
+
+ /**
+ * Indicates if the maximum version is included in the version range.
+ * @return true if the maximum version is included in the version range;
+ * otherwise false is returned
+ */
+ public boolean getIncludeMaximum() {
+ return includeMax;
+ }
+
+ /**
+ * Returns whether the given version is included in this VersionRange.
+ * This will depend on the minimum and maximum versions of this VersionRange
+ * and the given version.
+ *
+ * @param version a version to be tested for inclusion in this VersionRange.
+ * (may be <code>null</code>)
+ * @return <code>true</code> if the version is include,
+ * <code>false</code> otherwise
+ */
+ public boolean isIncluded(Version version) {
+ Version minRequired = getMinimum();
+ if (minRequired == null)
+ return true;
+ if (version == null)
+ return false;
+ Version maxRequired = getMaximum() == null ? VersionRange.versionMax : getMaximum();
+ int minCheck = includeMin ? 0 : 1;
+ int maxCheck = includeMax ? 0 : -1;
+ return version.compareTo(minRequired) >= minCheck && version.compareTo(maxRequired) <= maxCheck;
+
+ }
+
+ public boolean equals(Object object) {
+ if (!(object instanceof VersionRange))
+ return false;
+ VersionRange vr = (VersionRange) object;
+ if (minVersion != null && vr.getMinimum() != null) {
+ if (minVersion.equals(vr.getMinimum()) && includeMin == vr.includeMin)
+ if (maxVersion != null && vr.getMaximum() != null) {
+ if (maxVersion.equals(vr.getMaximum()) && includeMax == vr.includeMax)
+ return true;
+ }
+ else
+ return maxVersion == vr.getMaximum();
+ }
+ else {
+ return minVersion == vr.getMinimum();
+ }
+ return false;
+ }
+
+ public String toString() {
+ if (minVersion == null)
+ return Version.emptyVersion.toString();
+ if (VersionRange.versionMax.equals(maxVersion))
+ return minVersion.toString();
+ StringBuffer result = new StringBuffer();
+ result.append(includeMin ? '[' : '(');
+ result.append(minVersion);
+ result.append(',');
+ result.append(maxVersion);
+ result.append(includeMax ? ']' : ')');
+ return result.toString();
+ }
+}
Added: felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/bundlerepository/metadataparser/kxmlsax/KXml2SAXHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/bundlerepository/metadataparser/kxmlsax/KXml2SAXHandler.java?rev=572697&view=auto
==============================================================================
--- felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/bundlerepository/metadataparser/kxmlsax/KXml2SAXHandler.java (added)
+++ felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/bundlerepository/metadataparser/kxmlsax/KXml2SAXHandler.java Tue Sep 4 07:52:47 2007
@@ -0,0 +1,74 @@
+/*
+ * 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.bundlerepository.metadataparser.kxmlsax;
+
+import java.util.Properties;
+
+/**
+ * Interface for SAX handler with kXML
+ */
+public interface KXml2SAXHandler {
+
+ /**
+ * Method called when parsing text
+ *
+ * @param ch
+ * @param offset
+ * @param length
+ * @exception SAXException
+ */
+ public void characters(char[] ch, int offset, int length) throws Exception;
+
+ /**
+ * Method called when a tag opens
+ *
+ * @param uri
+ * @param localName
+ * @param qName
+ * @param attrib
+ * @exception SAXException
+ **/
+ public void startElement(
+ String uri,
+ String localName,
+ String qName,
+ Properties attrib)
+ throws Exception;
+ /**
+ * Method called when a tag closes
+ *
+ * @param uri
+ * @param localName
+ * @param qName
+ * @exception SAXException
+ */
+ public void endElement(
+ java.lang.String uri,
+ java.lang.String localName,
+ java.lang.String qName)
+ throws Exception;
+
+ public void processingInstruction(String target,
+ String data)
+ throws Exception;
+
+ public void setLineNumber(int lineNumber);
+
+ public void setColumnNumber(int columnNumber);
+}
\ No newline at end of file
Added: felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/bundlerepository/metadataparser/kxmlsax/KXml2SAXParser.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/bundlerepository/metadataparser/kxmlsax/KXml2SAXParser.java?rev=572697&view=auto
==============================================================================
--- felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/bundlerepository/metadataparser/kxmlsax/KXml2SAXParser.java (added)
+++ felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/bundlerepository/metadataparser/kxmlsax/KXml2SAXParser.java Tue Sep 4 07:52:47 2007
@@ -0,0 +1,81 @@
+/*
+ * 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.bundlerepository.metadataparser.kxmlsax;
+
+import java.io.Reader;
+import java.util.Properties;
+
+import org.kxml2.io.KXmlParser;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+/**
+ * The KXml2SAXParser extends the XmlParser from kxml2 (which does not take into account the DTD).
+ */
+public class KXml2SAXParser extends KXmlParser {
+
+ public String uri="uri";
+
+ /**
+ * The constructor for a parser, it receives a java.io.Reader.
+ *
+ * @param reader The reader
+ * @throws XmlPullParserException
+ */
+ public KXml2SAXParser(Reader reader) throws XmlPullParserException {
+ super();
+ setInput(reader);
+ }
+
+ /**
+ * parse from the reader provided in the constructor, and call
+ * the startElement and endElement in the handler
+ *
+ * @param handler The handler
+ * @exception Exception thrown by the superclass
+ */
+ public void parseXML(KXml2SAXHandler handler) throws Exception {
+
+ while (next() != XmlPullParser.END_DOCUMENT) {
+ handler.setLineNumber(getLineNumber());
+ handler.setColumnNumber(getColumnNumber());
+ if (getEventType() == XmlPullParser.START_TAG) {
+ Properties props = new Properties();
+ for (int i = 0; i < getAttributeCount(); i++) {
+ props.put(getAttributeName(i), getAttributeValue(i));
+ }
+ handler.startElement(
+ getNamespace(),
+ getName(),
+ getName(),
+ props);
+ } else if (getEventType() == XmlPullParser.END_TAG) {
+ handler.endElement(getNamespace(), getName(), getName());
+ } else if (getEventType() == XmlPullParser.TEXT) {
+ String text = getText();
+ handler.characters(text.toCharArray(),0,text.length());
+ } else if (getEventType() == XmlPullParser.PROCESSING_INSTRUCTION) {
+ // TODO extract the target from the evt.getText()
+ handler.processingInstruction(null,getText());
+ } else {
+ // do nothing
+ }
+ }
+ }
+}
Added: felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/Capability.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/Capability.java?rev=572697&view=auto
==============================================================================
--- felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/Capability.java (added)
+++ felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/Capability.java Tue Sep 4 07:52:47 2007
@@ -0,0 +1,99 @@
+package org.apache.felix.maven.obr.plugin;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * this class describe and store capability node.
+ *
+ * @author Maxime
+ *
+ */
+public class Capability
+{
+
+ /**
+ * m_name: name of the capability.
+ */
+ private String m_name;
+
+ /**
+ * m_p: List of PElement.
+ */
+ private List m_p = new ArrayList();
+
+ /**
+ * get the name attribute.
+ *
+ * @return name attribute
+ */
+ public String getName()
+ {
+ return m_name;
+ }
+
+ /**
+ * set the name attribute.
+ *
+ * @param m_name new name value
+ *
+ */
+ public void setName(String m_name)
+ {
+ this.m_name = m_name;
+ }
+
+ /**
+ * return the capabilities.
+ *
+ * @return List of PElement
+ */
+ public List getP()
+ {
+ return m_p;
+ }
+
+ /**
+ * set the capabilities.
+ *
+ * @param m_p List of PElement
+ *
+ */
+ public void setP(List m_p)
+ {
+ this.m_p = m_p;
+ }
+
+ /**
+ * add one element in List.
+ *
+ * @param pelement PElement
+ *
+ */
+ public void addP(PElement pelement)
+ {
+ m_p.add(pelement);
+ }
+
+ /**
+ * transform this object to Node.
+ *
+ * @param father father document for create Node
+ * @return node
+ */
+ public Node getNode(Document father)
+ {
+ Element capability = father.createElement("capability");
+ capability.setAttribute("name", this.getName());
+ for (int i = 0; i < this.getP().size(); i++)
+ {
+ capability.appendChild(((PElement) (this.getP().get(i))).getNode(father));
+ }
+ return capability;
+ }
+
+}
Added: felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/Category.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/Category.java?rev=572697&view=auto
==============================================================================
--- felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/Category.java (added)
+++ felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/Category.java Tue Sep 4 07:52:47 2007
@@ -0,0 +1,69 @@
+/*
+ * 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.maven.obr.plugin;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * describe and store category node.
+ *
+ * @author Maxime
+ *
+ */
+
+public class Category
+{
+ /**
+ * id of the category.
+ */
+ private String m_id;
+
+ /**
+ * get the id attribute.
+ *
+ * @return id
+ */
+ public String getId()
+ {
+ return m_id;
+ }
+
+ /**
+ * set the id attribute.
+ * @param id new id value
+ */
+ public void setId(String id)
+ {
+ this.m_id = id;
+ }
+
+ /**
+ * transform this object to node.
+ * @param father father document for create Node
+ * @return node
+ */
+ public Node getNode(Document father)
+ {
+ Element category = father.createElement("category");
+ category.setAttribute("id", this.getId());
+ return category;
+ }
+}
Added: felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/Config.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/Config.java?rev=572697&view=auto
==============================================================================
--- felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/Config.java (added)
+++ felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/Config.java Tue Sep 4 07:52:47 2007
@@ -0,0 +1,84 @@
+/*
+ * 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.maven.obr.plugin;
+/**
+ * this class is used to store some user information about configuration of the plugin.
+ * @author Maxime
+ *
+ */
+public class Config
+{
+
+ /**
+ * use relative path or not.
+ */
+ private boolean m_pathRelative; // use relative or absolute path in repository.xml
+
+ /**
+ * deploy file or not.
+ */
+ private boolean m_fileRemote; // deploy file on remote server
+
+ /**
+ * constructor: set default configuration: use relative path and don't upload file.
+ *
+ */
+ public Config()
+ {
+ // default configuration
+ m_pathRelative = true;
+ m_fileRemote = false;
+ }
+
+ /**
+ * set relativePath attribute.
+ * @param value new value of attribute
+ */
+ public void setPathRelative(boolean value)
+ {
+ m_pathRelative = value;
+ }
+
+ /**
+ * set fileRemote attribute.
+ * @param value new value of attribute
+ */
+ public void setRemotely(boolean value)
+ {
+ m_fileRemote = value;
+ }
+
+ /**
+ * get use path relative.
+ * @return true if plugin use relative path, else false
+ */
+ public boolean isPathRelative()
+ {
+ return m_pathRelative;
+ }
+
+ /**
+ * get if use upload file.
+ * @return true if the file will be uploaded, else false
+ */
+ public boolean isRemotely()
+ {
+ return m_fileRemote;
+ }
+}
Added: felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ExtractBindexInfo.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ExtractBindexInfo.java?rev=572697&view=auto
==============================================================================
--- felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ExtractBindexInfo.java (added)
+++ felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ExtractBindexInfo.java Tue Sep 4 07:52:47 2007
@@ -0,0 +1,268 @@
+/*
+ * 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.maven.obr.plugin;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+import bundles.obr.resource.BundleInfo;
+import bundles.obr.resource.CapabilityImpl;
+import bundles.obr.resource.RepositoryImpl;
+import bundles.obr.resource.RequirementImpl;
+import bundles.obr.resource.ResourceImpl;
+import bundles.obr.resource.VersionImpl;
+
+/**
+ * this class is used to configure bindex and get information built by bindex about targeted bundle.
+ *
+ * @author Maxime
+ *
+ */
+public class ExtractBindexInfo
+{
+
+ /**
+ * attribute get from bindex which describe targeted ressource.
+ */
+ private ResourceImpl m_resource;
+
+ /**
+ * configure bindex and build information.
+ * @param repoFilename URI on OBR descriptor file
+ * @param outFile path on targeted jar-file
+ * @throws MojoExecutionException occurs if bindex configuration failed
+ */
+ public ExtractBindexInfo(URI repoFilename, String outFile) throws MojoExecutionException
+ {
+
+ this.m_resource = null;
+ RepositoryImpl repository = null;
+ try
+ {
+ repository = new RepositoryImpl(new File(repoFilename).getAbsoluteFile().toURL());
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ throw new MojoExecutionException("MalformedURLException");
+ }
+ BundleInfo info = null;
+ try
+ {
+ info = new BundleInfo(repository, new File(outFile));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new MojoExecutionException("Exception");
+ }
+
+ try
+ {
+ m_resource = info.build();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new MojoExecutionException("Exception");
+ }
+ }
+
+ /**
+ * transform logical operator in xml syntax.
+ * @param filter string which contains logical operator
+ * @return string in correct xml syntax
+ */
+ private String parseFilter(String filter)
+ {
+ filter.replaceAll("&", "&");
+ filter.replaceAll(">=", ">");
+
+ return filter;
+ }
+
+ /**
+ * extract capabilities from bindex information.
+ * @return bundle capabilities List
+ */
+ public List getCapabilities()
+ {
+ ArrayList list = new ArrayList();
+ Collection res = m_resource.getCapabilityList();
+ Iterator it = res.iterator();
+ while (it.hasNext())
+ {
+ Capability capability = new Capability();
+ CapabilityImpl ci = ((CapabilityImpl) it.next());
+ capability.setName(ci.getName());
+ // System.out.println(ci.getName()) ;
+ if (!(ci.getName().compareTo("bundle") == 0))
+ {
+ Map properties = ci.getProperties();
+ for (Iterator k = properties.keySet().iterator(); k.hasNext();)
+ {
+ PElement p = new PElement();
+ String key = (String) k.next();
+ List values = (List) properties.get(key);
+ for (Iterator v = values.iterator(); v.hasNext();)
+ {
+ Object value = v.next();
+ p.setN(key);
+ if (value != null)
+ {
+ p.setV(value.toString());
+ }
+ else
+ System.out.println("Missing value " + key);
+ String type = null;
+ if (value instanceof Number)
+ type = "number";
+ else if (value.getClass() == VersionImpl.class)
+ type = "version";
+ if (type != null)
+ {
+ p.setT(type);
+ }
+ }
+ capability.addP(p);
+ }
+
+ list.add(capability);
+ }
+ }
+ return list;
+ }
+ /**
+ * extract requirement from bindex information.
+ * @return bundle requirement List
+ */
+ public List getRequirement()
+ {
+ ArrayList list = new ArrayList();
+ Collection res = m_resource.getRequirementList();
+ Iterator it = res.iterator();
+ while (it.hasNext())
+ {
+ RequirementImpl ci = ((RequirementImpl) it.next());
+ Require require = new Require();
+
+ require.setExtend(String.valueOf(ci.isExtend()));
+ require.setMultiple(String.valueOf(ci.isMultiple()));
+ require.setOptional(String.valueOf(ci.isOptional()));
+ require.setName(ci.getName());
+ require.setFilter(this.parseFilter(ci.getFilter()));
+ require.setValue(ci.getComment());
+ list.add(require);
+ }
+ return list;
+ }
+
+ /**
+ * extract symbolic name from bindex information.
+ * @return bundle symbolic name
+ */
+ public String getSymbolicName()
+ {
+ return m_resource.getSymbolicName();
+ }
+
+ /**
+ * extract version from bindex information.
+ * @return bundle version
+ */
+ public String getVersion()
+ {
+ if (m_resource.getVersion() != null)
+ return m_resource.getVersion().toString();
+ else
+ return null;
+ }
+
+ /**
+ * extract presentation name from bindex information.
+ * @return bundle presentation name
+ */
+ public String getPresentationName()
+ {
+ return m_resource.getPresentationName();
+ }
+
+ /**
+ * extract copyright from bindex information.
+ * @return bundle copyright
+ */
+ public String getCopyright()
+ {
+ return m_resource.getCopyright();
+ }
+
+ /**
+ * extract description from bindex information.
+ * @return bundle description
+ */
+ public String getDescription()
+ {
+ return m_resource.getDescription();
+ }
+
+ /**
+ * extract documentation from bindex information.
+ * @return bundle documentation
+ */
+ public String getDocumentation()
+ {
+ if (m_resource.getDocumentation() != null)
+ return m_resource.getDocumentation().toString();
+ else
+ return null;
+ }
+
+ /**
+ * extract license from bindex information.
+ * @return bundle license
+ */
+ public String getLicense()
+ {
+ if (m_resource.getLicense() != null)
+ return m_resource.getLicense().toString();
+ else
+ return null;
+ }
+
+ /**
+ * extract source from bindex information.
+ * @return bundle source
+ */
+ public String getSource()
+ {
+ if (m_resource.getSource() != null)
+ return m_resource.getSource().toString();
+ else
+ return null;
+ }
+
+}
Added: felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrDeploy.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrDeploy.java?rev=572697&view=auto
==============================================================================
--- felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrDeploy.java (added)
+++ felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrDeploy.java Tue Sep 4 07:52:47 2007
@@ -0,0 +1,349 @@
+/*
+ * 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.maven.obr.plugin;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.List;
+
+import org.apache.maven.artifact.manager.WagonManager;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Resource;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.authorization.AuthorizationException;
+
+/**
+ * deploy the bundle to a remote site.
+ * this goal is used when you compile a project with a pom file
+ * @goal deployment
+ * @phase deploy
+ * @requiresDependencyResolution compile
+ */
+
+public class ObrDeploy extends AbstractMojo
+{
+
+ /**
+ * setting of maven.
+ *
+ * @parameter expression="${settings}"
+ * @require
+ */
+ private Settings m_settings;
+
+ /**
+ * name of the repository xml descriptor file.
+ *
+ * @parameter expression="${repository-name}" default-value="repository.xml"
+ */
+ private String m_repositoryName;
+
+ /**
+ * The local Maven repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ */
+ private ArtifactRepository m_localRepo;
+
+ /**
+ * Project in use.
+ *
+ * @parameter expression="${project}"
+ * @require
+ */
+ private MavenProject m_project;
+
+ /**
+ * @component
+ */
+ private WagonManager m_wagonManager;
+
+ /**
+ * obr file define by the user.
+ *
+ * @parameter expression="${ignore-lock}"
+ *
+ */
+ private boolean m_ignoreLock;
+
+ /**
+ * used to store pathfile in local repo.
+ */
+ private String m_fileInLocalRepo;
+
+
+ /**
+ * main method for this goal.
+ * @implements org.apache.maven.plugin.Mojo.execute
+ * @throws MojoExecutionException if the plugin failed
+ * @throws MojoFailureException if the plugin failed
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException
+ {
+ getLog().info("Obr-deploy start:");
+ System.err.println(m_repositoryName);
+
+ ArtifactRepository ar = m_project.getDistributionManagementArtifactRepository();
+
+ // locate the obr.xml file
+ String obrXmlFile = null;
+ List l = m_project.getResources();
+ for (int i = 0; i < l.size(); i++)
+ {
+ File f = new File(((Resource) l.get(i)).getDirectory() + File.separator + "obr.xml");
+ if (f.exists())
+ {
+ obrXmlFile = ((Resource) l.get(i)).getDirectory() + File.separator + "obr.xml";
+ break;
+ }
+ }
+
+ // the obr.xml file is not present
+ if (obrXmlFile == null)
+ {
+ getLog().warn("obr.xml is not present, use default");
+ }
+
+ File repoDescriptorFile = null;
+
+ // init the wagon connection
+ RemoteFileManager remoteFile = new RemoteFileManager(ar, m_wagonManager, m_settings, getLog());
+ remoteFile.connect();
+
+ // create a non-empty file used to lock the repository descriptor file
+ File lockFile = null;
+ Writer output = null;
+ try
+ {
+ lockFile = File.createTempFile(String.valueOf(System.currentTimeMillis()), null);
+ output = new BufferedWriter(new FileWriter(lockFile));
+ output.write("locked");
+ output.close();
+ }
+ catch (IOException e)
+ {
+ getLog().error("Unable to create temporary file");
+ throw new MojoFailureException("IOException");
+ }
+
+ if (m_ignoreLock)
+ {
+ try
+ {
+ remoteFile.put(lockFile, m_repositoryName + ".lock");
+ }
+ catch (TransferFailedException e)
+ {
+ getLog().error("Transfer failed");
+ e.printStackTrace();
+ throw new MojoFailureException("TransferFailedException");
+
+ }
+ catch (ResourceDoesNotExistException e)
+ {
+ throw new MojoFailureException("ResourceDoesNotExistException");
+ }
+ catch (AuthorizationException e)
+ {
+ getLog().error("Authorization failed");
+ e.printStackTrace();
+ throw new MojoFailureException("AuthorizationException");
+ }
+
+ }
+ else
+ {
+ int countError = 0;
+ while (remoteFile.isLockedFile(remoteFile, m_repositoryName) && countError < 2)
+ {
+ countError++;
+ getLog().warn("File is locked, retry in 10s");
+ try
+ {
+ Thread.sleep(10000);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+
+ if (countError == 2)
+ {
+ getLog().error("File: " + m_repositoryName + " is locked. Try -Dignore-lock=true if you want force uploading");
+ throw new MojoFailureException("fileLocked");
+ }
+ }
+
+ // file is not locked, so we lock it now
+ try
+ {
+ remoteFile.put(lockFile, m_repositoryName + ".lock");
+ }
+ catch (TransferFailedException e)
+ {
+ getLog().error("Transfer failed");
+ e.printStackTrace();
+ throw new MojoFailureException("TransferFailedException");
+
+ }
+ catch (ResourceDoesNotExistException e)
+ {
+ throw new MojoFailureException("ResourceDoesNotExistException");
+ }
+ catch (AuthorizationException e)
+ {
+ getLog().error("Authorization failed");
+ e.printStackTrace();
+ throw new MojoFailureException("AuthorizationException");
+ }
+
+ try
+ {
+ repoDescriptorFile = remoteFile.get(m_repositoryName);
+ }
+ catch (TransferFailedException e)
+ {
+ getLog().error("Transfer failed");
+ e.printStackTrace();
+ throw new MojoFailureException("TransferFailedException");
+
+ }
+ catch (ResourceDoesNotExistException e)
+ {
+ // file doesn't exist! create a new one
+ getLog().warn("file specified does not exist: " + m_repositoryName);
+ getLog().warn("Create a new repository descriptor file " + m_repositoryName);
+ try
+ {
+ File f = File.createTempFile(String.valueOf(System.currentTimeMillis()), null);
+ repoDescriptorFile = new File(f.getParent() + File.separator + String.valueOf(System.currentTimeMillis()) + ".xml");
+ }
+ catch (IOException e1)
+ {
+ getLog().error("canno't create temporary file");
+ e1.printStackTrace();
+ return;
+ }
+ }
+ catch (AuthorizationException e)
+ {
+ getLog().error("Authorization failed");
+ e.printStackTrace();
+ throw new MojoFailureException("AuthorizationException");
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ throw new MojoFailureException("IOException");
+ }
+
+ Config userConfig = new Config();
+ userConfig.setPathRelative(true);
+ userConfig.setRemotely(true);
+
+ PathFile file = null;
+
+ // get the path to local maven repository
+ file = new PathFile(PathFile.uniformSeparator(m_settings.getLocalRepository()) + File.separator + PathFile.uniformSeparator(m_localRepo.pathOf(m_project.getArtifact())));
+ if (file.isExists())
+ m_fileInLocalRepo = file.getOnlyAbsoluteFilename();
+ else
+ {
+ getLog().error("file not found in local repository: " + m_settings.getLocalRepository() + File.separator + m_localRepo.pathOf(m_project.getArtifact()));
+ return;
+ }
+
+ file = new PathFile("file:/" + repoDescriptorFile.getAbsolutePath());
+
+ ObrUpdate obrUpdate = new ObrUpdate(file, obrXmlFile, m_project, m_fileInLocalRepo, PathFile.uniformSeparator(m_settings.getLocalRepository()), userConfig, getLog());
+
+ obrUpdate.updateRepository();
+
+ // the reposiroty descriptor file is modified, we upload it on the remote repository
+ try
+ {
+ remoteFile.put(repoDescriptorFile, m_repositoryName);
+ }
+ catch (TransferFailedException e)
+ {
+ getLog().error("Transfer failed");
+ e.printStackTrace();
+ throw new MojoFailureException("TransferFailedException");
+ }
+ catch (ResourceDoesNotExistException e)
+ {
+ getLog().error("Resource does not exist:" + repoDescriptorFile.getName());
+ e.printStackTrace();
+ throw new MojoFailureException("ResourceDoesNotExistException");
+ }
+ catch (AuthorizationException e)
+ {
+ getLog().error("Authorization failed");
+ e.printStackTrace();
+ throw new MojoFailureException("AuthorizationException");
+ }
+ repoDescriptorFile.delete();
+
+ // we remove lockFile activation
+ lockFile = null;
+ try
+ {
+ lockFile = File.createTempFile(String.valueOf(System.currentTimeMillis()), null);
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ throw new MojoFailureException("IOException");
+ }
+ try
+ {
+ remoteFile.put(lockFile, m_repositoryName + ".lock");
+ }
+ catch (TransferFailedException e)
+ {
+ getLog().error("Transfer failed");
+ e.printStackTrace();
+ throw new MojoFailureException("TransferFailedException");
+ }
+ catch (ResourceDoesNotExistException e)
+ {
+ e.printStackTrace();
+ throw new MojoFailureException("ResourceDoesNotExistException");
+ }
+ catch (AuthorizationException e)
+ {
+ getLog().error("Authorization failed");
+ e.printStackTrace();
+ throw new MojoFailureException("AuthorizationException");
+ }
+
+ remoteFile.disconnect();
+ }
+
+}
Added: felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrDeployFile.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrDeployFile.java?rev=572697&view=auto
==============================================================================
--- felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrDeployFile.java (added)
+++ felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrDeployFile.java Tue Sep 4 07:52:47 2007
@@ -0,0 +1,338 @@
+/*
+ * 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.maven.obr.plugin;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.maven.artifact.manager.WagonManager;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.authorization.AuthorizationException;
+
+/**
+ * deploy the bundle to a ftp site.
+ * this goal is used when you upload a jar file (in command line)
+ * @goal deploy-file
+ * @phase deploy
+ */
+public class ObrDeployFile extends AbstractMojo
+{
+
+ /**
+ * setting of maven.
+ *
+ * @parameter expression="${settings}"
+ * @require
+ */
+
+ private Settings m_settings;
+
+ /**
+ * name of the repository xml descriptor file.
+ *
+ * @parameter expression="${repository-name}" default-value="repository.xml"
+ */
+ private String m_repositoryName;
+
+ /**
+ * The local Maven repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ */
+ private ArtifactRepository m_localRepo;
+
+ /**
+ * Project in use.
+ *
+ * @parameter expression="${project}"
+ * @require
+ */
+ private MavenProject m_project;
+
+ /**
+ * @component
+ */
+ private WagonManager m_wagonManager;
+
+ /**
+ * obr file define by the user.
+ *
+ * @parameter expression="${obr-file}"
+ *
+ */
+ private String m_obrFile;
+
+ /**
+ * obr file define by the user.
+ *
+ * @parameter expression="${ignore-lock}"
+ *
+ */
+ private boolean m_ignoreLock;
+
+ /**
+ * used to store pathfile in local repo.
+ */
+ private String m_fileInLocalRepo;
+
+ /**
+ * main method for this goal.
+ * @implements org.apache.maven.plugin.Mojo.execute
+ * @throws MojoExecutionException if the plugin failed
+ * @throws MojoFailureException if the plugin failed
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException
+ {
+ getLog().info("Obr-deploy-file start:");
+
+ ArtifactRepository ar = m_project.getDistributionManagementArtifactRepository();
+
+ // locate the obr.xml file
+ PathFile fileObrXml = new PathFile(m_obrFile);
+ if (!fileObrXml.isExists())
+ {
+ getLog().warn("obr.xml file not found, use default");
+ }
+
+ File repoDescriptorFile = null;
+
+ RemoteFileManager remoteFile = new RemoteFileManager(ar, m_wagonManager, m_settings, getLog());
+
+ remoteFile.connect();
+
+ // create a non-empty file used to lock the repository descriptor file
+ File lockFile = null;
+ Writer output = null;
+ try
+ {
+ lockFile = File.createTempFile(String.valueOf(System.currentTimeMillis()), null);
+ output = new BufferedWriter(new FileWriter(lockFile));
+ output.write("locked");
+ output.close();
+ }
+ catch (IOException e)
+ {
+ getLog().error("Unable to create temporary file");
+ throw new MojoFailureException("IOException");
+ }
+
+ if (m_ignoreLock)
+ {
+ try
+ {
+ remoteFile.put(lockFile, m_repositoryName + ".lock");
+ }
+ catch (TransferFailedException e)
+ {
+ getLog().error("Transfer failed");
+ e.printStackTrace();
+ throw new MojoFailureException("TransferFailedException");
+
+ }
+ catch (ResourceDoesNotExistException e)
+ {
+ throw new MojoFailureException("ResourceDoesNotExistException");
+ }
+ catch (AuthorizationException e)
+ {
+ getLog().error("Authorization failed");
+ e.printStackTrace();
+ throw new MojoFailureException("AuthorizationException");
+ }
+
+ }
+ else
+ {
+ int countError = 0;
+ while (remoteFile.isLockedFile(remoteFile, m_repositoryName) && countError < 2)
+ {
+ countError++;
+ getLog().warn("File is locked, retry in 10s");
+ try
+ {
+ Thread.sleep(10000);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+
+ if (countError == 2)
+ {
+ getLog().error("File: " + m_repositoryName + " is locked. Try -Dignore-lock=true if you want to force uploading");
+ throw new MojoFailureException("fileLocked");
+ }
+ }
+
+ // file is not locked, so we lock it now
+ try
+ {
+ remoteFile.put(lockFile, m_repositoryName + ".lock");
+ }
+ catch (TransferFailedException e)
+ {
+ getLog().error("Transfer failed");
+ e.printStackTrace();
+ throw new MojoFailureException("TransferFailedException");
+
+ }
+ catch (ResourceDoesNotExistException e)
+ {
+ throw new MojoFailureException("ResourceDoesNotExistException");
+ }
+ catch (AuthorizationException e)
+ {
+ getLog().error("Authorization failed");
+ e.printStackTrace();
+ throw new MojoFailureException("AuthorizationException");
+ }
+
+ try
+ {
+ repoDescriptorFile = remoteFile.get(m_repositoryName);
+ }
+ catch (TransferFailedException e)
+ {
+ getLog().error("Transfer failed");
+ e.printStackTrace();
+ throw new MojoFailureException("TransferFailedException");
+
+ }
+ catch (ResourceDoesNotExistException e)
+ {
+ // file doesn't exist! create a new one
+ getLog().warn("file specified does not exist: " + m_repositoryName);
+ getLog().warn("Create a new repository descriptor file " + m_repositoryName);
+ try
+ {
+ File f = File.createTempFile(String.valueOf(System.currentTimeMillis()), null);
+ repoDescriptorFile = new File(f.getParent() + File.separator + String.valueOf(System.currentTimeMillis()) + ".xml");
+ }
+ catch (IOException e1)
+ {
+ getLog().error("canno't create temporary file");
+ e1.printStackTrace();
+ return;
+ }
+ }
+ catch (AuthorizationException e)
+ {
+ getLog().error("Authorization failed");
+ e.printStackTrace();
+ throw new MojoFailureException("AuthorizationException");
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ throw new MojoFailureException("IOException");
+ }
+
+ Config userConfig = new Config();
+ userConfig.setPathRelative(true);
+ userConfig.setRemotely(true);
+
+ PathFile file = null;
+
+ // get the path to local maven repository
+ file = new PathFile(PathFile.uniformSeparator(m_settings.getLocalRepository()) + File.separator + PathFile.uniformSeparator(m_localRepo.pathOf(m_project.getArtifact())));
+ if (file.isExists())
+ m_fileInLocalRepo = file.getOnlyAbsoluteFilename();
+ else
+ {
+ getLog().error("file not found in local repository: " + m_settings.getLocalRepository() + File.separator + m_localRepo.pathOf(m_project.getArtifact()));
+ return;
+ }
+
+ file = new PathFile("file:/" + repoDescriptorFile.getAbsolutePath());
+
+ ObrUpdate obrUpdate = new ObrUpdate(file, fileObrXml.getOnlyAbsoluteFilename(), m_project, m_fileInLocalRepo, PathFile.uniformSeparator(m_settings.getLocalRepository()), userConfig, getLog());
+
+ obrUpdate.updateRepository();
+
+ // the reposiroty descriptor file is modified, we upload it on the remote repository
+ try
+ {
+ remoteFile.put(repoDescriptorFile, m_repositoryName);
+ }
+ catch (TransferFailedException e)
+ {
+ getLog().error("Transfer failed");
+ e.printStackTrace();
+ throw new MojoFailureException("TransferFailedException");
+ }
+ catch (ResourceDoesNotExistException e)
+ {
+ getLog().error("Resource does not exist:" + repoDescriptorFile.getName());
+ e.printStackTrace();
+ throw new MojoFailureException("ResourceDoesNotExistException");
+ }
+ catch (AuthorizationException e)
+ {
+ getLog().error("Authorization failed");
+ e.printStackTrace();
+ throw new MojoFailureException("AuthorizationException");
+ }
+ repoDescriptorFile.delete();
+
+ // we remove lockFile activation
+ lockFile = null;
+ try
+ {
+ lockFile = File.createTempFile(String.valueOf(System.currentTimeMillis()), null);
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ throw new MojoFailureException("IOException");
+ }
+ try
+ {
+ remoteFile.put(lockFile, m_repositoryName + ".lock");
+ }
+ catch (TransferFailedException e)
+ {
+ getLog().error("Transfer failed");
+ e.printStackTrace();
+ throw new MojoFailureException("TransferFailedException");
+ }
+ catch (ResourceDoesNotExistException e)
+ {
+ e.printStackTrace();
+ throw new MojoFailureException("ResourceDoesNotExistException");
+ }
+ catch (AuthorizationException e)
+ {
+ getLog().error("Authorization failed");
+ e.printStackTrace();
+ throw new MojoFailureException("AuthorizationException");
+ }
+ remoteFile.disconnect();
+ }
+}
Added: felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrInstall.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrInstall.java?rev=572697&view=auto
==============================================================================
--- felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrInstall.java (added)
+++ felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrInstall.java Tue Sep 4 07:52:47 2007
@@ -0,0 +1,154 @@
+/*
+ * 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.maven.obr.plugin;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Resource;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Settings;
+
+/**
+ * deploy the bundle to a ftp site.
+ * this goal is used when you upload a jar file (in command line)
+ * @goal repository
+ * @phase install
+ * @requiresDependencyResolution compile
+ */
+public class ObrInstall extends AbstractMojo
+{
+ /**
+ * The local Maven repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ */
+ private ArtifactRepository m_localRepo;
+
+ /**
+ * path to the repository.xml.
+ *
+ * @parameter expression="${repository-path}"
+ * @require
+ */
+ private String m_repositoryPath;
+
+ /**
+ * Project in use.
+ *
+ * @parameter expression="${project}"
+ * @require
+ */
+
+ private MavenProject m_project;
+
+ /**
+ * setting of maven.
+ *
+ * @parameter expression="${settings}"
+ * @require
+ */
+
+ private Settings m_settings;
+
+ /**
+ * path to file in the maven local repository.
+ */
+ private String m_fileInLocalRepo;
+
+ /**
+ * main method for this goal.
+ * @implements org.apache.maven.plugin.Mojo.execute
+ * @throws MojoExecutionException if the plugin failed
+ */
+ public void execute() throws MojoExecutionException
+ {
+ getLog().info("Obr Plugin starts:");
+
+ if (m_repositoryPath == null)
+ {
+ m_repositoryPath = "file:/" + m_localRepo.getBasedir() + File.separator + "repository.xml";
+ getLog().warn("-DpathRepo is not define, use default repository: " + m_repositoryPath);
+ }
+
+ PathFile file = new PathFile(m_repositoryPath);
+ if (file.isExists())
+ {
+ if (!m_repositoryPath.startsWith("file:/"))
+ m_repositoryPath = "file:/" + m_repositoryPath;
+ }
+
+ // locate the obr.xml file
+ String obrXmlFile = null;
+ List l = m_project.getResources();
+ for (int i = 0; i < l.size(); i++)
+ {
+ File f = new File(((Resource) l.get(i)).getDirectory() + File.separator + "obr.xml");
+ if (f.exists())
+ {
+ obrXmlFile = ((Resource) l.get(i)).getDirectory() + File.separator + "obr.xml";
+ break;
+ }
+ }
+ // the obr.xml file is not present
+ if (obrXmlFile == null)
+ {
+ getLog().warn("obr.xml is not present, use default");
+ }
+
+ // get the path to local maven repository
+ file = new PathFile(PathFile.uniformSeparator(m_settings.getLocalRepository()) + File.separator + PathFile.uniformSeparator(m_localRepo.pathOf(m_project.getArtifact())));
+ if (file.isExists())
+ m_fileInLocalRepo = file.getOnlyAbsoluteFilename();
+ else
+ {
+ getLog().error("file not found in local repository: " + m_settings.getLocalRepository() + File.separator + m_localRepo.pathOf(m_project.getArtifact()));
+ return;
+ }
+
+ // verify the repository.xml
+ PathFile fileRepo = new PathFile(m_repositoryPath);
+ if (fileRepo.isRelative())
+ fileRepo.setBaseDir(m_settings.getLocalRepository());
+
+ // create the folder to the repository
+ PathFile repoExist = new PathFile(fileRepo.getAbsolutePath());
+ if (!repoExist.isExists())
+ fileRepo.createPath();
+
+ // build the user configuration (use default)
+ Config user = new Config();
+
+ ObrUpdate obrUpdate = new ObrUpdate(fileRepo, obrXmlFile, m_project, m_fileInLocalRepo, PathFile.uniformSeparator(m_settings.getLocalRepository()), user, getLog());
+ try
+ {
+ obrUpdate.updateRepository();
+ }
+ catch (MojoExecutionException e)
+ {
+ e.printStackTrace();
+ throw new MojoExecutionException("MojoFailureException");
+ }
+ }
+
+}
Added: felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrInstallFile.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrInstallFile.java?rev=572697&view=auto
==============================================================================
--- felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrInstallFile.java (added)
+++ felix/sandbox/clement/maven-obr-plugin/src/main/java/org/apache/felix/maven/obr/plugin/ObrInstallFile.java Tue Sep 4 07:52:47 2007
@@ -0,0 +1,181 @@
+/*
+ * 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.maven.obr.plugin;
+
+import java.io.File;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Settings;
+
+/**
+ * @description construct the repository.xml from a compiled bundle
+ *
+ * @goal install-file
+ * @requiresProject false
+ * @phase install
+ */
+public class ObrInstallFile extends AbstractMojo
+{
+ /**
+ * The local Maven repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ */
+ private ArtifactRepository m_localRepo;
+
+ /**
+ * path to the repository.xml.
+ *
+ * @parameter expression="${repository-path}"
+ * @require
+ */
+ private String m_repositoryPath;
+
+ /**
+ * setting of maven.
+ *
+ * @parameter expression="${settings}"
+ * @require
+ */
+ private Settings m_settings;
+
+ /**
+ * @descritpion symbolic name define by the user
+ * @parameter expression="${artifactId}"
+ */
+ private String m_artifactId;
+
+ /**
+ * @descritpion groupId define by the user
+ * @parameter expression="${groupId}"
+ */
+ private String m_groupId;
+
+ /**
+ * @descritpion version define by the user
+ * @parameter expression="${version}"
+ */
+ private String m_version;
+
+ /**
+ * @descritpion packaging define by the user
+ * @parameter expression="${packaging}"
+ */
+ private String m_packaging;
+
+ /**
+ * @descritpion obr file define by the user
+ * @parameter expression="${obr-file}"
+ */
+ private String m_obrFile;
+
+ /**
+ * store user information in a project.
+ */
+ private MavenProject m_project;
+
+ /**
+ * main method for this goal.
+ * @implements org.apache.maven.plugin.Mojo.execute
+ * @throws MojoExecutionException if the plugin failed
+ * @throws MojoFailureException if the plugin failed
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException
+ {
+ getLog().info("Install-File Obr starts:");
+
+ m_project = new MavenProject();
+ m_project.setArtifactId(m_artifactId);
+ m_project.setGroupId(m_groupId);
+ m_project.setVersion(m_version);
+ m_project.setPackaging(m_packaging);
+
+ PathFile fileOut;
+
+ if (m_groupId == null)
+ {
+ getLog().error("-DgroupId=VALUE is required");
+ return;
+ }
+ if (m_artifactId == null)
+ {
+ getLog().error("-Dartifactid=VALUE is required");
+ return;
+ }
+ if (m_version == null)
+ {
+ getLog().error("-Dversion=VALUE is required");
+ return;
+ }
+ if (m_packaging == null)
+ {
+ getLog().error("-Dpackaging=VALUE is required");
+ return;
+ }
+
+ // copy the file to the local repository
+ PathFile repoLocal = new PathFile(m_localRepo.getBasedir());
+
+ // get the target file in mvn repo
+ fileOut = new PathFile(PathFile.uniformSeparator(m_settings.getLocalRepository()) + File.separator + m_groupId.replace('.', File.separatorChar) + File.separator + m_artifactId + File.separator + m_version + File.separator + m_artifactId + "-"
+ + m_version + "." + m_packaging);
+
+ if (!fileOut.isExists())
+ {
+ getLog().error("file doesn't exist: " + fileOut.getAbsoluteFilename());
+ return;
+ }
+ else
+ getLog().info("Target file: " + fileOut.getAbsoluteFilename());
+
+ if (m_repositoryPath == null)
+ {
+ m_repositoryPath = "file:" + repoLocal.getOnlyAbsoluteFilename() + "repository.xml";
+ getLog().warn("-DpathRepo is not define, use default repository: " + m_repositoryPath);
+ }
+
+ PathFile fileRepo = new PathFile(m_repositoryPath);
+ if (fileRepo.isRelative())
+ fileRepo.setBaseDir(m_settings.getLocalRepository());
+
+ // create the folder to the repository
+ PathFile repoExist = new PathFile(fileRepo.getAbsolutePath());
+ if (!repoExist.isExists())
+ fileRepo.createPath();
+
+ PathFile fileObrXml = new PathFile(m_obrFile);
+ if (!fileObrXml.isExists())
+ {
+ getLog().warn("obr.xml file not found, use default");
+ }
+
+ // build the user config
+ Config userConfig = new Config();
+
+ ObrUpdate obrUpdate = new ObrUpdate(fileRepo, fileObrXml.getOnlyAbsoluteFilename(), m_project, fileOut.getOnlyAbsoluteFilename(), m_localRepo.getBasedir(), userConfig, getLog());
+ obrUpdate.updateRepository();
+
+ }
+
+}