org.apache.felix.obrplugin.ResourcesBundle Maven / Gradle / Ivy
/*
* 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.obrplugin;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* this class describe all information by bundle.
* @author Felix Project Team
*/
public class ResourcesBundle
{
/**
* store the bundle symbolic name.
*/
private String m_symbolicName;
/**
* store the bundle presentation name.
*/
private String m_presentationName;
/**
* store the bundle version.
*/
private String m_version;
/**
* store the bundle URI.
*/
private String m_uri;
/**
* store the bundle description.
*/
private String m_description;
/**
* store the bundle size.
*/
private String m_size;
/**
* store the bundle documentation.
*/
private String m_documentation;
/**
* store the bundle source.
*/
private String m_source;
/**
* store the bundle javadoc.
*/
private String m_javadoc;
/**
* store the bundle license.
*/
private String m_license;
/**
* store the bundle id.
*/
private String m_id;
/**
* store the bundle categories.
*/
private List m_category = new ArrayList();
/**
* store the bundle capabilities.
*/
private List m_capability = new ArrayList();
/**
* store the bundle requirement.
*/
private List m_require = new ArrayList();
/**
* get the plugin logger.
*/
private Log m_logger;
/**
* initialize logger.
* @param log log use by plugin
*/
public ResourcesBundle( Log log )
{
m_logger = log;
}
public List getCapability()
{
return m_capability;
}
public void setCapability( List capability )
{
m_capability = capability;
}
public List getCategory()
{
return m_category;
}
public void setCategory( List category )
{
m_category = category;
}
public String getLicense()
{
return m_license;
}
public void setLicense( String license )
{
m_license = license;
}
public String getDescription()
{
return m_description;
}
public void setDescription( String description )
{
m_description = description;
}
public String getDocumentation()
{
return m_documentation;
}
public void setDocumentation( String documentation )
{
m_documentation = documentation;
}
public String getPresentationName()
{
return m_presentationName;
}
public void setPresentationName( String name )
{
m_presentationName = name;
}
public String getSize()
{
return m_size;
}
public void setSize( String size )
{
m_size = size;
}
public String getSymbolicName()
{
return m_symbolicName;
}
public void setSymbolicName( String name )
{
m_symbolicName = name;
}
public String getUri()
{
return m_uri;
}
public void setUri( String url )
{
m_uri = url;
}
public String getVersion()
{
return m_version;
}
public void setVersion( String version )
{
m_version = version;
}
public List getRequire()
{
return m_require;
}
public void setRequire( List require )
{
m_require = require;
}
public String getSource()
{
return m_source;
}
public void setSource( String source )
{
m_source = source;
}
public String getJavadoc()
{
return m_javadoc;
}
public void setJavadoc( String javadoc )
{
m_javadoc = javadoc;
}
public String getId()
{
return m_id;
}
public void setId( String id )
{
m_id = id;
}
/**
* add a new capability for this bundle description.
* @param capability the Capability to add
*/
public void addCapability( Capability capability )
{
m_capability.add( capability );
}
/**
* add a new requirement for this bundle description.
* @param require th Require to add
*/
public void addRequire( Require require )
{
m_require.add( require );
}
/**
* add a new category for this bundle decription.
* @param category the Category to add
*/
public void addCategory( Category category )
{
m_category.add( category );
}
/**
* transform this object to Node.
* tranform all sub-object to node also
* @param father father document for create Node
* @return node
*/
public Node getNode( Document father )
{
// return the complete resource tree
if ( !isValid() || getId() == null )
{
m_logger.error( "those properties was not defined:" + getInvalidProperties() );
return null;
}
Element resource = father.createElement( "resource" );
Element description = father.createElement( "description" );
Element size = father.createElement( "size" );
Element documentation = father.createElement( "documentation" );
Element source = father.createElement( "source" );
Element javadoc = father.createElement( "javadoc" );
Element license = father.createElement( "license" );
resource.setAttribute( "id", getId() );
resource.setAttribute( "symbolicname", getSymbolicName() );
resource.setAttribute( "presentationname", getPresentationName() );
resource.setAttribute( "uri", getUri() );
resource.setAttribute( "version", getVersion() );
XmlHelper.setTextContent( description, getDescription() );
resource.appendChild( description );
XmlHelper.setTextContent( size, getSize() );
resource.appendChild( size );
if ( getDocumentation() != null )
{
XmlHelper.setTextContent( documentation, getDocumentation() );
resource.appendChild( documentation );
}
if ( getSource() != null )
{
XmlHelper.setTextContent( source, getSource() );
resource.appendChild( source );
}
if ( getJavadoc() != null )
{
XmlHelper.setTextContent( javadoc, getJavadoc() );
resource.appendChild( javadoc );
}
if ( getLicense() != null )
{
XmlHelper.setTextContent( license, getLicense() );
resource.appendChild( license );
}
List list = getNodeCategories( father );
for ( int i = 0; i < list.size(); i++ )
{
resource.appendChild( ( Node ) list.get( i ) );
}
list = getNodeCapabilities( father );
for ( int i = 0; i < list.size(); i++ )
{
resource.appendChild( ( Node ) list.get( i ) );
}
list = getNodeRequirement( father );
for ( int i = 0; i < list.size(); i++ )
{
resource.appendChild( ( Node ) list.get( i ) );
}
return resource;
}
/**
* this method gets information form pom.xml to complete missing data from those given by user.
* @param project project information given by maven
* @param ebi bundle information extracted from bindex
* @param sourcePath path to local sources
* @param javadocPath path to local javadocs
* @return true
*/
public boolean construct( MavenProject project, ExtractBindexInfo ebi, String sourcePath, String javadocPath )
{
if ( ebi.getPresentationName() != null )
{
setPresentationName( ebi.getPresentationName() );
if ( project.getName() != null )
{
m_logger.debug( "pom property override: " + project.getName() );
}
}
else
{
setPresentationName( project.getName() );
}
if ( ebi.getSymbolicName() != null )
{
setSymbolicName( ebi.getSymbolicName() );
if ( project.getArtifactId() != null )
{
m_logger.debug( "pom property override: " + project.getArtifactId() );
}
}
else
{
setSymbolicName( project.getArtifactId() );
}
if ( ebi.getVersion() != null )
{
setVersion( ebi.getVersion() );
if ( project.getVersion() != null )
{
m_logger.debug( "pom property override: " + project.getVersion() );
}
}
else
{
setVersion( project.getVersion() );
}
if ( ebi.getId() != null )
{
setId( ebi.getId() );
}
if ( ebi.getDescription() != null )
{
setDescription( ebi.getDescription() );
if ( project.getDescription() != null )
{
m_logger.debug( "pom property override: " + project.getDescription() );
}
}
else
{
setDescription( project.getDescription() );
}
// fallback to javadoc if no project URL
String documentation = project.getUrl();
if ( null == documentation )
{
documentation = javadocPath;
}
if ( ebi.getDocumentation() != null )
{
setDocumentation( ebi.getDocumentation() );
if ( documentation != null )
{
m_logger.debug( "pom property override: " + documentation );
}
}
else
{
setDocumentation( documentation );
}
if ( ebi.getSource() != null )
{
setSource( ebi.getSource() );
if ( sourcePath != null )
{
m_logger.debug( "pom property override:
© 2015 - 2025 Weber Informatics LLC | Privacy Policy