blob: 785ddad9b7632b77c441db26ee8d09e57491d3e3 [file] [log] [blame]
/**
* 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.maven.mercury.repository.metadata;
import org.apache.maven.mercury.util.TimeUtil;
import org.codehaus.plexus.lang.DefaultLanguage;
import org.codehaus.plexus.lang.Language;
/**
* adds new snapshot to metadata
*
* @author Oleg Gusakov
* @version $Id$
*
*/
public class SetSnapshotOperation
implements MetadataOperation
{
private static final Language lang = new DefaultLanguage( SetSnapshotOperation.class );
private Snapshot snapshot;
/**
* @throws MetadataException
*
*/
public SetSnapshotOperation( SnapshotOperand data )
throws MetadataException
{
setOperand( data );
}
public void setOperand( Object data )
throws MetadataException
{
if( data == null || !(data instanceof SnapshotOperand) )
throw new MetadataException( lang.getMessage( "bad.operand", "SnapshotOperand", data == null ? "null" : data.getClass().getName() ) );
snapshot = ((SnapshotOperand)data).getOperand();
}
/**
* add/replace snapshot to the in-memory metadata instance
*
* @param metadata
* @return
* @throws MetadataException
*/
public boolean perform( Metadata metadata )
throws MetadataException
{
if( metadata == null )
return false;
Versioning vs = metadata.getVersioning();
if( vs == null )
{
vs = new Versioning();
metadata.setVersioning( vs );
}
vs.setSnapshot( snapshot );
vs.setLastUpdated( TimeUtil.getUTCTimestamp() );
return true;
}
}