import com.opensymphony.xwork2.Validateable;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.Dependency;
+import org.apache.archiva.metadata.model.License;
import org.apache.archiva.metadata.model.MailingList;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference;
private boolean dependencyTree = false;
private ProjectVersionMetadata projectMetadata;
+
+ private String deleteItem;
+
+ private String itemValue;
/**
* Show the versioned project information tab.
return SUCCESS;
}
-
+
+ public String deleteMetadataEntry()
+ {
+ projectMetadata = getProjectVersionMetadata();
+
+ if ( !StringUtils.isEmpty( deleteItem ) && !StringUtils.isEmpty( itemValue ) )
+ {
+ if ( "dependency".equals( deleteItem ) )
+ {
+ removeDependency();
+ }
+ else if ( "mailingList".equals( deleteItem ) )
+ {
+ removeMailingList();
+ }
+ else if ( "license".equals( deleteItem ) )
+ {
+ removeLicense();
+ }
+
+ deleteItem = "";
+ itemValue = "";
+ }
+
+ return updateProjectMetadata();
+ }
+
+ private void removeDependency()
+ {
+ List<Dependency> dependencies = projectMetadata.getDependencies();
+ List<Dependency> newDependencies = new ArrayList<Dependency>();
+
+ if ( dependencies != null )
+ {
+ for ( Dependency dependency : dependencies )
+ {
+ if ( !StringUtils.equals( itemValue, dependency.getArtifactId() ) )
+ {
+ newDependencies.add( dependency );
+ }
+ }
+ }
+
+ projectMetadata.setDependencies( newDependencies );
+ }
+
+ private void removeMailingList()
+ {
+ List<MailingList> mailingLists = projectMetadata.getMailingLists();
+ List<MailingList> newMailingLists = new ArrayList<MailingList>();
+
+ if ( mailingLists != null )
+ {
+ for ( MailingList mailingList : mailingLists )
+ {
+ if ( !StringUtils.equals( itemValue, mailingList.getName() ) )
+ {
+ newMailingLists.add( mailingList );
+ }
+ }
+ }
+
+ projectMetadata.setMailingLists( newMailingLists );
+ }
+
+ private void removeLicense()
+ {
+ List<License> licenses = projectMetadata.getLicenses();
+ List<License> newLicenses = new ArrayList<License>();
+
+ if ( licenses != null )
+ {
+ for ( License license : licenses )
+ {
+ if ( !StringUtils.equals( itemValue, license.getName() ) )
+ {
+ newLicenses.add( license );
+ }
+ }
+ }
+
+ projectMetadata.setLicenses( newLicenses );
+ }
+
@Override
public void validate()
{
this.projectMetadata = projectMetadata;
}
+ public void setDeleteItem( String deleteItem )
+ {
+ this.deleteItem = deleteItem;
+ }
+
+ public void setItemValue( String itemValue )
+ {
+ this.itemValue = itemValue;
+ }
+
// TODO: move this into the artifact metadata itself via facets where necessary
public class ArtifactDownloadInfo
private Logger log = LoggerFactory.getLogger( ProjectMetadataTag.class );
private Object object;
+
+ private String groupId;
+
+ private String artifactId;
+
+ private String version;
@Override
public void release()
startList( metadataEntries );
for ( License license : licenses )
{
+ createDeleteLink( "license", license.getName(), metadataEntries );
+ startList( metadataEntries );
addListItem( "licenses." + ctr + ".name=", license.getName(), metadataEntries );
addListItem( "licenses." + ctr + ".url=", license.getUrl(), metadataEntries );
+ endList( metadataEntries );
+ endListItem( metadataEntries );
ctr++;
}
endList( metadataEntries );
startList( metadataEntries );
for ( MailingList list : lists )
{
+ createDeleteLink( "mailingList", list.getName(), metadataEntries );
+ startList( metadataEntries );
addListItem( "mailingLists." + ctr + ".name=", list.getName(), metadataEntries );
addListItem( "mailingLists." + ctr + ".archive.url=", list.getMainArchiveUrl(), metadataEntries );
addListItem( "mailingLists." + ctr + ".post=", list.getPostAddress(), metadataEntries );
endList( metadataEntries );
}
endListItem( metadataEntries );
+ endList( metadataEntries );
+ endListItem( metadataEntries );
ctr++;
}
endList( metadataEntries );
int ctr = 0;
startList( metadataEntries );
+
for ( Dependency dependency : dependencies )
{
+ createDeleteLink( "dependency", dependency.getArtifactId(), metadataEntries );
+ startList( metadataEntries );
addListItem( "dependency." + ctr + ".group.id=", dependency.getGroupId(), metadataEntries );
addListItem( "dependency." + ctr + ".artifact.id=", dependency.getArtifactId(), metadataEntries );
addListItem( "dependency." + ctr + ".version=", dependency.getVersion(), metadataEntries );
addListItem( "dependency." + ctr + ".type=", dependency.getType(), metadataEntries );
addListItem( "dependency." + ctr + ".scope=", dependency.getScope(), metadataEntries );
addListItem( "dependency." + ctr + ".system.path=", dependency.getSystemPath(), metadataEntries );
+ endList( metadataEntries );
+ endListItem( metadataEntries );
ctr++;
}
endList( metadataEntries );
+
endListItem( metadataEntries );
}
{
metadataEntries.append( "\n</li>" );
}
+
+ private void createDeleteLink( String name, String value, StringBuffer metadataEntries )
+ {
+ metadataEntries.append( "\n<li>" ).append( value )
+ .append( "\n<a href=\"showProjectMetadata!deleteMetadataEntry.action?" )
+ .append( "groupId=" ).append( groupId )
+ .append( "&artifactId=" ).append( artifactId )
+ .append( "&version=" ).append( version )
+ .append( "&deleteItem=" ).append( name )
+ .append( "&itemValue=").append( value ).append( "\" >" )
+ .append( "<img src=\"images/icons/delete.gif\"/>" ).append( "</a>" );
+ }
public void setObject( Object object )
{
this.object = object;
}
+
+ public void setGroupId( String groupId )
+ {
+ this.groupId = groupId;
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ this.artifactId = artifactId;
+ }
+
+ public void setVersion( String version )
+ {
+ this.version = version;
+ }
}