You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by og...@apache.org on 2009/04/23 00:57:04 UTC
svn commit: r767705 [10/31] - in /maven/mercury/trunk/mercury-core: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/maven/ src/main/java/org/apache/maven/mercury/
src/main/java/org/apache/maven/mer...
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/m2/Messages.properties
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/m2/Messages.properties?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/m2/Messages.properties (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/m2/Messages.properties Wed Apr 22 22:56:48 2009
@@ -0,0 +1,36 @@
+#
+# 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.
+#
+bad.repository.type=repository should implement LocalRepository, instead got {0}
+empty.query=received empty query - {0}
+binary.not.found=Artifact {0} binary at not found {1}
+ga.not.found=Artifact {0} version group not found at {1}
+gav.not.found=No artifact version for {0} found in {1}
+snapshot.not.found=No snapshot version for {0} found in {1}
+gavdir.not.found=No directory {1} for artifact {0}
+pom.not.found=Artifact {0} - binary exists, but POM not found in the repository
+artifact.no.stream=Cannot find either input stream or file, associated with artifact {0}
+pom.artifact.no.stream=Cannot find either pom blob, input stream or file, associated with artifact {0}
+no.signature.file=Verifier for {0} is mandatory, but file {1} does not exist
+signature.failed=Signature "{0}": verification failed for file {1}
+cannot.read.signature.file=Cannot read signature file {0}, error: {1}
+cannot.lock.gav=Cannot lock GAV folder {0} in {1} millis
+file.is.empty=File {0} exists, but is empty. Data corruption somewhere - please repair metadata.
+
+null.directory=supplied local repo root is null
+file.directory=supplied local repo root is not a folder: {0}
\ No newline at end of file
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/m2/Messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/m2/Messages.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/DefaultStorage.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/DefaultStorage.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/DefaultStorage.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/DefaultStorage.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,142 @@
+package org.apache.maven.mercury.repository.local.map;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.maven.mercury.artifact.Artifact;
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+import org.apache.maven.mercury.util.FileUtil;
+import org.apache.maven.mercury.util.Util;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class DefaultStorage
+implements Storage
+{
+ private static final Language _lang = new DefaultLanguage( DefaultStorage.class );
+
+ Map< String, Artifact > _artifacts;
+
+ Map< String, File > _files;
+
+ File _dir;
+
+ public DefaultStorage( File dir )
+ throws StorageException
+ {
+ if( dir == null )
+ {
+ try
+ {
+ _dir = File.createTempFile( "temp-", "-mercury-default-storage" );
+ _dir.deleteOnExit();
+ }
+ catch ( IOException e )
+ {
+ throw new StorageException(e);
+ }
+
+ _dir.delete();
+
+ _dir.mkdirs();
+ }
+ else
+ {
+ if( !dir.exists() )
+ dir.mkdirs();
+ else
+ if( dir.isDirectory() )
+ throw new StorageException( _lang.getMessage( "default.storage.bad.dir", dir.getAbsolutePath() ) );
+
+ _dir = dir;
+ }
+ }
+
+ public DefaultStorage()
+ throws StorageException
+ {
+ this( null );
+ }
+
+ public void add( ArtifactMetadata bmd, Artifact artifact )
+ {
+ if( _artifacts == null )
+ _artifacts = new HashMap<String, Artifact>(32);
+
+ _artifacts.put( bmd.toString(), artifact );
+ }
+
+ public Artifact findArtifact( ArtifactMetadata bmd )
+ {
+ if( _artifacts == null )
+ return null;
+
+ return _artifacts.get( bmd.getGAV() );
+ }
+
+ public byte[] findRaw( String key )
+ throws StorageException
+ {
+ if( Util.isEmpty( _files ) )
+ return null;
+
+ File f = _files.get( key );
+
+ if( f == null )
+ return null;
+
+ try
+ {
+ return FileUtil.readRawData( f );
+ }
+ catch ( IOException e )
+ {
+ throw new StorageException(e);
+ }
+ }
+
+ public void add( String key, byte[] bytes )
+ throws StorageException
+ {
+ try
+ {
+ add( key, FileUtil.writeTempData( bytes ) );
+ }
+ catch ( IOException e )
+ {
+ throw new StorageException(e);
+ }
+ }
+
+ public void add( String key, File file )
+ throws StorageException
+ {
+ if( file == null || !file.exists() )
+ throw new StorageException( _lang.getMessage( "defaultStorage.add.file.no.file", key ) );
+
+ if( _files == null )
+ _files = new HashMap<String, File>(32);
+
+ _files.put( key, file );
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.maven.mercury.repository.local.map.Storage#removeRaw(java.lang.String)
+ */
+ public void removeRaw( String key )
+ throws StorageException
+ {
+ if( Util.isEmpty( _files ) )
+ throw new StorageException( _lang.getMessage( "dep.cannot.remove", key ) );
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/DefaultStorage.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/DefaultStorage.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryMap.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryMap.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryMap.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryMap.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,123 @@
+/**
+ * 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.local.map;
+
+import java.io.File;
+
+import org.apache.maven.mercury.builder.api.DependencyProcessor;
+import org.apache.maven.mercury.builder.api.MetadataReader;
+import org.apache.maven.mercury.repository.api.AbstractRepository;
+import org.apache.maven.mercury.repository.api.LocalRepository;
+import org.apache.maven.mercury.repository.api.NonExistentProtocolException;
+import org.apache.maven.mercury.repository.api.RepositoryReader;
+import org.apache.maven.mercury.repository.api.RepositoryWriter;
+
+/**
+ * in-memory only repository for processing POMs on-the-fly
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class LocalRepositoryMap
+extends AbstractRepository
+implements LocalRepository
+{
+ public static final String FLAT_REPOSITORY_TYPE = "map";
+
+ protected Storage _storage;
+
+ protected MetadataReader _mdReader;
+
+ // ----------------------------------------------------------------------------------
+ public Storage getStorage()
+ {
+ return _storage;
+ }
+ // ----------------------------------------------------------------------------------
+ public LocalRepositoryMap( String id, DependencyProcessor dp, Storage storage )
+ {
+ super( id, FLAT_REPOSITORY_TYPE );
+ setDependencyProcessor( dp );
+
+ _storage = storage;
+ }
+ // ----------------------------------------------------------------------------------
+ public LocalRepositoryMap( DependencyProcessor dp, Storage storage )
+ {
+ this( "" + System.currentTimeMillis() + (int)(Math.random()*10000), dp, storage );
+ }
+
+ public void setMetadataReader( MetadataReader reader )
+ {
+ _mdReader = reader;
+ }
+ // ----------------------------------------------------------------------------------
+ public File getDirectory()
+ {
+ return null;
+ }
+ // ----------------------------------------------------------------------------------
+ public RepositoryReader getReader()
+ {
+ return new LocalRepositoryReaderMap( this, getDependencyProcessor() );
+ }
+ // ----------------------------------------------------------------------------------
+ public RepositoryReader getReader( String protocol )
+ {
+ return getReader();
+ }
+ // ----------------------------------------------------------------------------------
+ public RepositoryWriter getWriter()
+ {
+ return RepositoryWriter.NULL_WRITER;
+ }
+ // ----------------------------------------------------------------------------------
+ public RepositoryWriter getWriter( String protocol )
+ throws NonExistentProtocolException
+ {
+ return getWriter();
+ }
+ // ----------------------------------------------------------------------------------
+ public boolean isLocal()
+ {
+ return true;
+ }
+ // ----------------------------------------------------------------------------------
+ public boolean isReadable()
+ {
+ return true;
+ }
+ // ----------------------------------------------------------------------------------
+ public boolean isWriteable()
+ {
+ return false;
+ }
+ // ----------------------------------------------------------------------------------
+ public String getType()
+ {
+ return FLAT_REPOSITORY_TYPE;
+ }
+ // ----------------------------------------------------------------------------------
+ public String getMetadataName()
+ {
+ return null;
+ }
+ // ----------------------------------------------------------------------------------
+ // ----------------------------------------------------------------------------------
+}
\ No newline at end of file
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryMap.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryReaderMap.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryReaderMap.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryReaderMap.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryReaderMap.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,196 @@
+/**
+ * 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.local.map;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.maven.mercury.artifact.Artifact;
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+import org.apache.maven.mercury.builder.api.DependencyProcessor;
+import org.apache.maven.mercury.builder.api.MetadataReader;
+import org.apache.maven.mercury.builder.api.MetadataReaderException;
+import org.apache.maven.mercury.logging.IMercuryLogger;
+import org.apache.maven.mercury.logging.MercuryLoggerManager;
+import org.apache.maven.mercury.repository.api.AbstracRepositoryReader;
+import org.apache.maven.mercury.repository.api.AbstractRepository;
+import org.apache.maven.mercury.repository.api.MetadataResults;
+import org.apache.maven.mercury.repository.api.ArtifactResults;
+import org.apache.maven.mercury.repository.api.Repository;
+import org.apache.maven.mercury.repository.api.RepositoryException;
+import org.apache.maven.mercury.repository.api.RepositoryReader;
+import org.apache.maven.mercury.util.Util;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+public class LocalRepositoryReaderMap
+ extends AbstracRepositoryReader
+ implements RepositoryReader
+{
+ private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( LocalRepositoryReaderMap.class );
+
+ private static final Language LANG = new DefaultLanguage( LocalRepositoryReaderMap.class );
+
+ // ---------------------------------------------------------------------------------------------------------------
+ private static final String[] _protocols = new String[] { "map" };
+
+ private final LocalRepositoryMap _repo;
+
+ // ---------------------------------------------------------------------------------------------------------------
+ public LocalRepositoryReaderMap( Repository repo, DependencyProcessor dp )
+ {
+ if ( repo == null )
+ throw new IllegalArgumentException( "localRepo cannot be null" );
+
+ if ( dp == null )
+ throw new IllegalArgumentException( "localRepo cannot be null" );
+
+ _mdProcessor = dp;
+
+ _repo = (LocalRepositoryMap) repo;
+
+ }
+ // ---------------------------------------------------------------------------------------------------------------
+ public Repository getRepository()
+ {
+ return _repo;
+ }
+ // ---------------------------------------------------------------------------------------------------------------
+ public boolean canHandle( String protocol )
+ {
+ return AbstractRepository.DEFAULT_LOCAL_READ_PROTOCOL.equals( protocol );
+ }
+ // ---------------------------------------------------------------------------------------------------------------
+ public String[] getProtocols()
+ {
+ return _protocols;
+ }
+ // ---------------------------------------------------------------------------------------------------------------
+ public ArtifactResults readArtifacts( Collection<ArtifactMetadata> query )
+ throws RepositoryException
+ {
+ if( Util.isEmpty( query ) )
+ return null;
+
+ if( Util.isEmpty( _repo._storage ) )
+ return null;
+
+ ArtifactResults res = new ArtifactResults();
+
+ for( ArtifactMetadata md : query )
+ {
+ Artifact a;
+ try
+ {
+ a = _repo._storage.findArtifact( md );
+ }
+ catch ( Exception e )
+ {
+ throw new RepositoryException(e);
+ }
+
+ if( a != null )
+ res.add( md, a );
+ }
+
+ return res;
+ }
+ // ---------------------------------------------------------------------------------------------------------------
+ public byte[] readRawData( String path )
+ throws MetadataReaderException
+ {
+ return readRawData( path, false );
+ }
+ // ---------------------------------------------------------------------------------------------------------------
+ public byte[] readRawData( String path, boolean exempt )
+ throws MetadataReaderException
+ {
+ try
+ {
+ return _repo._storage.findRaw( path );
+ }
+ catch ( StorageException e )
+ {
+ throw new MetadataReaderException(e);
+ }
+ }
+ // ---------------------------------------------------------------------------------------------------------------
+ public byte[] readRawData( ArtifactMetadata bmd, String classifier, String type )
+ throws MetadataReaderException
+ {
+ return readRawData( bmd, classifier, type, false );
+ }
+ // ---------------------------------------------------------------------------------------------------------------
+ public byte[] readRawData( ArtifactMetadata bmd, String classifier, String type, boolean exempt )
+ throws MetadataReaderException
+ {
+
+ String key = bmd.getGroupId()
+ + ":"+bmd.getArtifactId()
+ + ":"+bmd.getVersion()
+ + ":"+ (classifier == null ? "" : classifier)
+ + ":"+ (type == null ? bmd.getType() : type)
+ ;
+
+ return readRawData( key, exempt );
+ }
+ // ---------------------------------------------------------------------------------------------------------------
+ public MetadataResults readDependencies( Collection<ArtifactMetadata> query )
+ throws RepositoryException
+ {
+ if( Util.isEmpty( query ) )
+ return null;
+
+ DependencyProcessor dp = _repo.getDependencyProcessor();
+
+ MetadataResults res = new MetadataResults( query.size() );
+
+ for( ArtifactMetadata bmd : query )
+ {
+ try
+ {
+ MetadataReader mdr = _repo._mdReader == null ? this : _repo._mdReader;
+
+ List<ArtifactMetadata> deps = dp.getDependencies( bmd, mdr, System.getenv(), System.getProperties() );
+
+ res.add( bmd, deps );
+ }
+ catch ( Exception e )
+ {
+ LOG.error( e.getMessage() );
+
+ res.addError( bmd, e );
+ }
+ }
+
+ return res;
+ }
+ // ---------------------------------------------------------------------------------------------------------------
+ public MetadataResults readVersions( Collection<ArtifactMetadata> query )
+ throws RepositoryException
+ {
+ return null;
+ }
+ // ---------------------------------------------------------------------------------------------------------------
+ public void close()
+ {
+ }
+ // ---------------------------------------------------------------------------------------------------------------
+ // ---------------------------------------------------------------------------------------------------------------
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryReaderMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryReaderMap.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryReaderMapFactory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryReaderMapFactory.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryReaderMapFactory.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryReaderMapFactory.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,48 @@
+/**
+ * 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.local.map;
+
+import org.apache.maven.mercury.builder.api.DependencyProcessor;
+import org.apache.maven.mercury.repository.api.AbstractRepository;
+import org.apache.maven.mercury.repository.api.Repository;
+import org.apache.maven.mercury.repository.api.RepositoryException;
+import org.apache.maven.mercury.repository.api.RepositoryReader;
+import org.apache.maven.mercury.repository.api.RepositoryReaderFactory;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+public class LocalRepositoryReaderMapFactory
+ implements RepositoryReaderFactory
+{
+ private static final Language _lang = new DefaultLanguage( LocalRepositoryReaderMapFactory.class );
+
+ private static final LocalRepositoryReaderMapFactory FACTORY = new LocalRepositoryReaderMapFactory();
+
+ static
+ {
+ AbstractRepository.register( LocalRepositoryMap.FLAT_REPOSITORY_TYPE, FACTORY );
+ }
+
+ public RepositoryReader getReader( Repository repo, DependencyProcessor mdProcessor )
+ throws RepositoryException
+ {
+ return new LocalRepositoryReaderMap( repo, mdProcessor );
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryReaderMapFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryReaderMapFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/Messages.properties
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/Messages.properties?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/Messages.properties (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/Messages.properties Wed Apr 22 22:56:48 2009
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+bad.repository.type=repository should implement LocalRepository, instead got {0}
+empty.query=received empty query - {0}
+binary.not.found=Artifact {0} binary at not found {1}
+ga.not.found=Artifact {0} version group not found at {1}
+gav.not.found=No artifact version for {0} found in {1}
+snapshot.not.found=No snapshot version for {0} found in {1}
+gavdir.not.found=No directory {1} for artifact {0}
+pom.not.found=Artifact {0} - binary exists, but POM not found in the repository
+artifact.no.stream=Cannot find either input stream or file, associated with artifact {0}
+pom.artifact.no.stream=Cannot find either pom blob, input stream or file, associated with artifact {0}
+no.signature.file=Verifier for {0} is mandatory, but file {1} does not exist
+signature.failed=Signature "{0}": verification failed for file {1}
+cannot.read.signature.file=Cannot read signature file {0}, error: {1}
+cannot.lock.gav=Cannot lock GAV folder {0} in {1} millis
+file.is.empty=File {0} exists, but is empty. Data corruption somewhere - please repair metadata.
+
+default.storage.bad.dir=supplied directory {0} is actually a file.
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/Messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/Messages.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/Storage.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/Storage.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/Storage.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/Storage.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,68 @@
+package org.apache.maven.mercury.repository.local.map;
+
+import java.io.File;
+
+import org.apache.maven.mercury.artifact.Artifact;
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+
+/**
+ * storage for the repository
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public interface Storage
+{
+ /**
+ * store an artifact
+ *
+ * @param bmd metadata
+ * @param artifact artifact behind it
+ */
+ public abstract void add( ArtifactMetadata bmd, Artifact artifact );
+
+ /**
+ * find an artifact by it's metadata
+ *
+ * @param bmd
+ * @return
+ */
+ public abstract Artifact findArtifact( ArtifactMetadata bmd );
+
+ /**
+ * find raw data in this stotage
+ *
+ * @param key
+ * @return
+ * @throws StorageException
+ */
+ public abstract byte[] findRaw( String key ) throws StorageException;
+
+ /**
+ *
+ * @param key
+ * @param bytes
+ * @throws StorageException
+ */
+ public abstract void add( String key, byte [] bytes )
+ throws StorageException;
+
+ /**
+ *
+ * @param key
+ * @param file
+ * @throws StorageException
+ */
+ public abstract void add( String key, File file )
+ throws StorageException;
+
+ /**
+ * delete this datum
+ *
+ * @param key
+ */
+ public abstract void removeRaw( String key )
+ throws StorageException;
+
+}
\ No newline at end of file
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/Storage.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/Storage.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/StorageException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/StorageException.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/StorageException.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/StorageException.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,46 @@
+package org.apache.maven.mercury.repository.local.map;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class StorageException
+ extends Exception
+{
+
+ /**
+ *
+ */
+ public StorageException()
+ {
+ }
+
+ /**
+ * @param message
+ */
+ public StorageException( String message )
+ {
+ super( message );
+ }
+
+ /**
+ * @param cause
+ */
+ public StorageException( Throwable cause )
+ {
+ super( cause );
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public StorageException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/StorageException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/local/map/StorageException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AbstractOperand.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AbstractOperand.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AbstractOperand.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AbstractOperand.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,31 @@
+/**
+ * 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;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public abstract class AbstractOperand
+{
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AbstractOperand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AbstractOperand.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AddPluginOperation.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AddPluginOperation.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AddPluginOperation.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AddPluginOperation.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,123 @@
+/**
+ * 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 java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ * adds new plugin to metadata
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class AddPluginOperation
+ implements MetadataOperation
+{
+ private static final Language LANG = new DefaultLanguage( AddPluginOperation.class );
+
+ private Plugin plugin;
+
+ private static PluginComparator pluginComparator;
+
+ {
+ pluginComparator = new PluginComparator();
+ }
+
+ /**
+ * @throws MetadataException
+ */
+ public AddPluginOperation( PluginOperand data )
+ throws MetadataException
+ {
+ setOperand( data );
+ }
+
+ public void setOperand( Object data )
+ throws MetadataException
+ {
+ if ( data == null || !( data instanceof PluginOperand ) )
+ {
+ throw new MetadataException( LANG.getMessage( "bad.operand", "PluginOperand", data == null ? "null"
+ : data.getClass().getName() ) );
+ }
+
+ plugin = ( (PluginOperand) data ).getOperand();
+ }
+
+ /**
+ * add plugin to the in-memory metadata instance
+ *
+ * @param metadata
+ * @param version
+ * @return
+ * @throws MetadataException
+ */
+ public boolean perform( Metadata metadata )
+ throws MetadataException
+ {
+ if ( metadata == null )
+ {
+ return false;
+ }
+
+ List<Plugin> plugins = metadata.getPlugins();
+
+ for ( Plugin p : plugins )
+ {
+ if ( p.getArtifactId().equals( plugin.getArtifactId() ) )
+ {
+ // plugin already enlisted
+ return false;
+ }
+ }
+
+ // not found, add it
+ plugins.add( plugin );
+
+ Collections.sort( plugins, pluginComparator );
+
+ return true;
+ }
+
+ class PluginComparator
+ implements Comparator<Plugin>
+ {
+ public int compare( Plugin p1, Plugin p2 )
+ {
+ if ( p1 == null || p2 == null )
+ {
+ throw new IllegalArgumentException( LANG.getMessage( "null.plugin.to.compare" ) );
+ }
+
+ if ( p1.getArtifactId() == null || p2.getArtifactId() == null )
+ {
+ throw new IllegalArgumentException( LANG.getMessage( "null.plugin.artifactId.to.compare", p1
+ .getArtifactId(), p2.getArtifactId() ) );
+ }
+
+ return p1.getArtifactId().compareTo( p2.getArtifactId() );
+ }
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AddPluginOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AddPluginOperation.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AddVersionOperation.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AddVersionOperation.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AddVersionOperation.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AddVersionOperation.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,130 @@
+/**
+ * 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 java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.mercury.artifact.version.VersionComparator;
+import org.apache.maven.mercury.util.TimeUtil;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ * adds new version to metadata
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class AddVersionOperation
+ implements MetadataOperation
+{
+ private static final Language LANG = new DefaultLanguage( AddVersionOperation.class );
+
+ private String version;
+
+ /**
+ * @throws MetadataException
+ */
+ public AddVersionOperation( StringOperand data )
+ throws MetadataException
+ {
+ setOperand( data );
+ }
+
+ public void setOperand( Object data )
+ throws MetadataException
+ {
+ if ( data == null || !( data instanceof StringOperand ) )
+ {
+ throw new MetadataException( LANG.getMessage( "bad.operand", "StringOperand", data == null ? "null"
+ : data.getClass().getName() ) );
+ }
+
+ version = ( (StringOperand) data ).getOperand();
+ }
+
+ /**
+ * add version to the in-memory metadata instance
+ *
+ * @param metadata
+ * @param version
+ * @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 );
+ }
+
+ if ( vs.getVersions() != null && vs.getVersions().size() > 0 )
+ {
+ List<String> vl = vs.getVersions();
+
+ if ( vl.contains( version ) )
+ {
+ return false;
+ }
+ }
+
+ vs.addVersion( version );
+
+ List<String> versions = vs.getVersions();
+
+ Collections.sort( versions, new VersionComparator() );
+
+ vs.setLatest( getLatestVersion(versions) );
+
+ vs.setRelease( getReleaseVersion(versions) );
+
+ vs.setLastUpdated( TimeUtil.getUTCTimestamp() );
+
+ return true;
+ }
+
+ private String getLatestVersion( List<String> orderedVersions )
+ {
+ return orderedVersions.get( orderedVersions.size() - 1 );
+ }
+
+ private String getReleaseVersion( List<String> orderedVersions )
+ {
+ for (int i = orderedVersions.size() - 1; i >= 0; i--)
+ {
+ if (!orderedVersions.get(i).endsWith("SNAPSHOT"))
+ {
+ return orderedVersions.get(i);
+ }
+ }
+
+ return "";
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AddVersionOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/AddVersionOperation.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MergeOperation.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MergeOperation.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MergeOperation.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MergeOperation.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,189 @@
+/**
+ * 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 java.util.List;
+
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ * merge Metadata.
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class MergeOperation
+ implements MetadataOperation
+{
+ private static final Language LANG = new DefaultLanguage( MergeOperation.class );
+
+ private Metadata sourceMetadata;
+
+ /**
+ * @throws MetadataException
+ */
+ public MergeOperation( MetadataOperand data )
+ throws MetadataException
+ {
+ setOperand( data );
+ }
+
+ /**
+ * merge the supplied operand Metadata into this metadata
+ */
+ public boolean perform( Metadata targetMetadata )
+ throws MetadataException
+ {
+ boolean changed = false;
+
+ if ( sourceMetadata == null || targetMetadata == null )
+ {
+ return false;
+ }
+
+ List<Plugin> plugins = sourceMetadata.getPlugins();
+ for ( Plugin plugin : plugins )
+ {
+ boolean found = false;
+
+ List<Plugin> targetPlugins = targetMetadata.getPlugins();
+ for ( Plugin preExisting : targetPlugins )
+ {
+ if ( preExisting.getPrefix().equals( plugin.getPrefix() ) )
+ {
+ found = true;
+ }
+ }
+
+ if ( !found )
+ {
+ Plugin mappedPlugin = new Plugin();
+
+ mappedPlugin.setArtifactId( plugin.getArtifactId() );
+ mappedPlugin.setPrefix( plugin.getPrefix() );
+ mappedPlugin.setName( plugin.getName() );
+
+ targetMetadata.addPlugin( mappedPlugin );
+
+ changed = true;
+ }
+ }
+
+ Versioning sourceVersioning = sourceMetadata.getVersioning();
+ if ( sourceVersioning != null )
+ {
+ Versioning targetVersioning = targetMetadata.getVersioning();
+ if ( targetVersioning == null )
+ {
+ targetVersioning = new Versioning();
+ targetMetadata.setVersioning( targetVersioning );
+ changed = true;
+ }
+
+ List<String> versions = sourceVersioning.getVersions();
+ for ( String version : versions )
+ {
+ if ( !targetVersioning.getVersions().contains( version ) )
+ {
+ changed = true;
+ targetVersioning.getVersions().add( version );
+ }
+ }
+
+ if ( "null".equals( sourceVersioning.getLastUpdated() ) )
+ {
+ sourceVersioning.setLastUpdated( null );
+ }
+
+ if ( "null".equals( targetVersioning.getLastUpdated() ) )
+ {
+ targetVersioning.setLastUpdated( null );
+ }
+
+ if ( sourceVersioning.getLastUpdated() == null || sourceVersioning.getLastUpdated().length() == 0 )
+ {
+ // this should only be for historical reasons - we assume local is newer
+ sourceVersioning.setLastUpdated( targetVersioning.getLastUpdated() );
+ }
+
+ if ( targetVersioning.getLastUpdated() == null || targetVersioning.getLastUpdated().length() == 0
+ || sourceVersioning.getLastUpdated().compareTo( targetVersioning.getLastUpdated() ) >= 0 )
+ {
+ changed = true;
+ targetVersioning.setLastUpdated( sourceVersioning.getLastUpdated() );
+
+ if ( sourceVersioning.getRelease() != null )
+ {
+ changed = true;
+ targetVersioning.setRelease( sourceVersioning.getRelease() );
+ }
+ if ( sourceVersioning.getLatest() != null )
+ {
+ changed = true;
+ targetVersioning.setLatest( sourceVersioning.getLatest() );
+ }
+
+ Snapshot s = targetVersioning.getSnapshot();
+ Snapshot snapshot = sourceVersioning.getSnapshot();
+ if ( snapshot != null )
+ {
+ if ( s == null )
+ {
+ s = new Snapshot();
+ targetVersioning.setSnapshot( s );
+ changed = true;
+ }
+
+ // overwrite
+ if ( s.getTimestamp() == null ? snapshot.getTimestamp() != null
+ : !s.getTimestamp().equals( snapshot.getTimestamp() ) )
+ {
+ s.setTimestamp( snapshot.getTimestamp() );
+ changed = true;
+ }
+ if ( s.getBuildNumber() != snapshot.getBuildNumber() )
+ {
+ s.setBuildNumber( snapshot.getBuildNumber() );
+ changed = true;
+ }
+ if ( s.isLocalCopy() != snapshot.isLocalCopy() )
+ {
+ s.setLocalCopy( snapshot.isLocalCopy() );
+ changed = true;
+ }
+ }
+ }
+ }
+ return changed;
+ }
+
+ public void setOperand( Object data )
+ throws MetadataException
+ {
+ if ( data == null || !( data instanceof MetadataOperand ) )
+ {
+ throw new MetadataException( LANG.getMessage( "bad.operand", "MetadataOperand", data == null ? "null"
+ : data.getClass().getName() ) );
+ }
+
+ sourceMetadata = ( (MetadataOperand) data ).getOperand();
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MergeOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MergeOperation.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/Messages.properties
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/Messages.properties?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/Messages.properties (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/Messages.properties Wed Apr 22 22:56:48 2009
@@ -0,0 +1,24 @@
+#
+# 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.
+#
+bad.operand=Operand is not correct: expected {0}, but got {1}
+empty.operand=Operand cannot be null or empty: {0}
+bad.string.data=cannot initialize from an empty string: {0}
+bad.snapshot.data=null snapshot passed as parameter
+
+bad.snapshot.version=the supplied version {0} cannot be parsed as a timestamped snapshot, expected: xxx-timeStamp-buildNo
\ No newline at end of file
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/Messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/Messages.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataBuilder.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataBuilder.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataBuilder.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataBuilder.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,288 @@
+/**
+ * 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 java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.mercury.artifact.Artifact;
+import org.apache.maven.mercury.repository.metadata.io.xpp3.MetadataXpp3Reader;
+import org.apache.maven.mercury.repository.metadata.io.xpp3.MetadataXpp3Writer;
+import org.apache.maven.mercury.util.TimeUtil;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+import org.codehaus.plexus.util.WriterFactory;
+
+/**
+ * utility class to help with de/serializing metadata from/to XML
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class MetadataBuilder
+{
+ private static final Language LANG = new DefaultLanguage( MetadataBuilder.class );
+ /**
+ * instantiate Metadata from a stream
+ *
+ * @param in
+ * @return
+ * @throws MetadataException
+ */
+ public static Metadata read( InputStream in )
+ throws MetadataException
+ {
+ try
+ {
+ return new MetadataXpp3Reader().read( in );
+ }
+ catch ( Exception e )
+ {
+ throw new MetadataException( e );
+ }
+ }
+
+ /**
+ * instantiate Metadata from a byte array
+ *
+ * @param in
+ * @return
+ * @throws MetadataException
+ */
+ public static Metadata getMetadata( byte[] in )
+ throws MetadataException
+ {
+ if ( in == null || in.length < 10 )
+ {
+ return null;
+ }
+
+ try
+ {
+ return new MetadataXpp3Reader().read( new ByteArrayInputStream( in ) );
+ }
+ catch ( Exception e )
+ {
+ throw new MetadataException( e );
+ }
+ }
+
+ /**
+ * serialize metadata into xml
+ *
+ * @param metadata to serialize
+ * @param out output to this stream
+ * @return same metadata as was passed in
+ * @throws MetadataException if any problems occurred
+ */
+ public static Metadata write( Metadata metadata, OutputStream out )
+ throws MetadataException
+ {
+ if ( metadata == null )
+ {
+ return metadata;
+ }
+
+ try
+ {
+ new MetadataXpp3Writer().write( WriterFactory.newXmlWriter( out ), metadata );
+
+ return metadata;
+ }
+ catch ( Exception e )
+ {
+ throw new MetadataException( e );
+ }
+ }
+
+ /**
+ * apply a list of operators to the specified serialized Metadata object
+ *
+ * @param metadataBytes - serialized Metadata object
+ * @param mutators - operators
+ * @return changed serialized object
+ * @throws MetadataException
+ */
+ public static byte[] changeMetadata( byte[] metadataBytes, List<MetadataOperation> mutators )
+ throws MetadataException
+ {
+ if ( mutators == null || mutators.size() < 1 )
+ {
+ return metadataBytes;
+ }
+
+ Metadata metadata;
+ boolean changed = false;
+
+ if ( metadataBytes == null || metadataBytes.length < 10 )
+ {
+ metadata = new Metadata();
+ }
+ else
+ {
+ ByteArrayInputStream in = new ByteArrayInputStream( metadataBytes );
+ metadata = read( in );
+ }
+
+ for ( MetadataOperation op : mutators )
+ {
+ changed = op.perform( metadata ) || changed;
+ }
+
+ // TODO og: does not work - check
+ // if( !changed )
+ // return metadataBytes;
+
+ return getBytes( metadata );
+ }
+
+ /**
+ * marshall metadata into a byte array
+ *
+ * @param metadata
+ * @return
+ * @throws MetadataException
+ */
+ public static byte[] getBytes( Metadata metadata )
+ throws MetadataException
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ write( metadata, out );
+
+ byte[] res = out.toByteArray();
+
+ return res;
+ }
+
+ /**
+ * apply a list of operators to the specified serialized Metadata object
+ *
+ * @param metadataBytes - serialized Metadata object
+ * @param mutators - operators
+ * @return changed serialized object
+ * @throws MetadataException
+ */
+ public static byte[] changeMetadata( Metadata metadata, List<MetadataOperation> mutators )
+ throws MetadataException
+ {
+
+ boolean changed = false;
+
+ if ( metadata == null )
+ {
+ metadata = new Metadata();
+ }
+
+ if ( mutators != null && mutators.size() > 0 )
+ {
+ for ( MetadataOperation op : mutators )
+ {
+ changed = op.perform( metadata ) || changed;
+ }
+ }
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ write( metadata, out );
+
+ byte[] res = out.toByteArray();
+
+ return res;
+ }
+
+ public static byte[] changeMetadata( byte[] metadataBytes, MetadataOperation op )
+ throws MetadataException
+ {
+ ArrayList<MetadataOperation> ops = new ArrayList<MetadataOperation>( 1 );
+ ops.add( op );
+
+ return changeMetadata( metadataBytes, ops );
+ }
+
+ public static byte[] changeMetadata( Metadata metadata, MetadataOperation op )
+ throws MetadataException
+ {
+ ArrayList<MetadataOperation> ops = new ArrayList<MetadataOperation>( 1 );
+ ops.add( op );
+
+ return changeMetadata( metadata, ops );
+ }
+
+ /**
+ * update snapshot timestamp to now
+ *
+ * @param target
+ */
+ public static void updateTimestamp( Snapshot target )
+ {
+ target.setTimestamp( TimeUtil.getUTCTimestamp() );
+ }
+
+ /**
+ * update versioning's lastUpdated timestamp to now
+ *
+ * @param target
+ */
+ public static void updateTimestamp( Versioning target )
+ {
+ target.setLastUpdated( TimeUtil.getUTCTimestamp() );
+ }
+
+ public static Snapshot createSnapshot( String version )
+ {
+ Snapshot sn = new Snapshot();
+
+ if ( version == null || version.length() < 3 )
+ {
+ return sn;
+ }
+
+ String utc = TimeUtil.getUTCTimestamp();
+ sn.setTimestamp( utc );
+
+ if ( version.endsWith( Artifact.SNAPSHOT_VERSION ) )
+ {
+ return sn;
+ }
+
+ int pos = version.lastIndexOf( '-' );
+
+ if( pos == -1 )
+ throw new IllegalArgumentException( LANG.getMessage( "bad.snapshot.version", version ) );
+
+ String sbn = version.substring( pos + 1 );
+
+ int bn = Integer.parseInt( sbn );
+ sn.setBuildNumber( bn );
+
+ String sts = version.substring( 0, pos);
+ pos = sts.lastIndexOf( '-' );
+
+ if( pos == -1 )
+ throw new IllegalArgumentException( LANG.getMessage( "bad.snapshot.version", version ) );
+
+ sn.setTimestamp( sts.substring( pos+1 ) );
+
+ return sn;
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataBuilder.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataException.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataException.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataException.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,61 @@
+/**
+ * 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;
+
+/**
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class MetadataException
+ extends Exception
+{
+
+ /**
+ *
+ */
+ public MetadataException()
+ {
+ }
+
+ /**
+ * @param message
+ */
+ public MetadataException( String message )
+ {
+ super( message );
+ }
+
+ /**
+ * @param cause
+ */
+ public MetadataException( Throwable cause )
+ {
+ super( cause );
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public MetadataException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataOperand.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataOperand.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataOperand.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataOperand.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,51 @@
+/**
+ * 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.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class MetadataOperand
+ extends AbstractOperand
+{
+ private static final Language LANG = new DefaultLanguage( MetadataOperand.class );
+
+ Metadata metadata;
+
+ public MetadataOperand( Metadata data )
+ {
+ if ( data == null )
+ {
+ this.metadata = new Metadata();
+ }
+ else
+ {
+ this.metadata = data;
+ }
+ }
+
+ public Metadata getOperand()
+ {
+ return metadata;
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataOperand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataOperand.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataOperation.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataOperation.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataOperation.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataOperation.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,44 @@
+/**
+ * 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;
+
+/**
+ * change of a Metadata object
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public interface MetadataOperation
+{
+ /**
+ * sets the operation's data
+ */
+ public void setOperand( Object data )
+ throws MetadataException;
+
+ /**
+ * performs the operation
+ *
+ * @param metadata to perform on
+ * @return true if operation changed the data
+ */
+ public boolean perform( Metadata metadata )
+ throws MetadataException;
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/MetadataOperation.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/PluginOperand.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/PluginOperand.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/PluginOperand.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/PluginOperand.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,46 @@
+/**
+ * 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.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ * Plugin storage
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class PluginOperand
+ extends AbstractOperand
+{
+ private static final Language LANG = new DefaultLanguage( PluginOperand.class );
+
+ Plugin plugin;
+
+ public PluginOperand( Plugin data )
+ {
+ this.plugin = data;
+ }
+
+ public Plugin getOperand()
+ {
+ return plugin;
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/PluginOperand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/PluginOperand.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/RemovePluginOperation.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/RemovePluginOperation.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/RemovePluginOperation.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/RemovePluginOperation.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,93 @@
+/**
+ * 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 java.util.Iterator;
+import java.util.List;
+
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ * removes a Plugin from Metadata
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class RemovePluginOperation
+ implements MetadataOperation
+{
+ private static final Language lang = new DefaultLanguage( RemovePluginOperation.class );
+
+ private Plugin plugin;
+
+ /**
+ * @throws MetadataException
+ */
+ public RemovePluginOperation( PluginOperand data )
+ throws MetadataException
+ {
+ setOperand( data );
+ }
+
+ public void setOperand( Object data )
+ throws MetadataException
+ {
+ if ( data == null || !( data instanceof PluginOperand ) )
+ {
+ throw new MetadataException( lang.getMessage( "bad.operand", "PluginOperand", data == null ? "null"
+ : data.getClass().getName() ) );
+ }
+
+ plugin = ( (PluginOperand) data ).getOperand();
+ }
+
+ /**
+ * remove version to the in-memory metadata instance
+ *
+ * @param metadata
+ * @param version
+ * @return
+ */
+ public boolean perform( Metadata metadata )
+ throws MetadataException
+ {
+ if ( metadata == null )
+ return false;
+
+ List<Plugin> plugins = metadata.getPlugins();
+
+ if ( plugins != null && plugins.size() > 0 )
+ {
+ for ( Iterator<Plugin> pi = plugins.iterator(); pi.hasNext(); )
+ {
+ Plugin p = pi.next();
+
+ if ( p.getArtifactId().equals( plugin.getArtifactId() ) )
+ {
+ pi.remove();
+
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/RemovePluginOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/RemovePluginOperation.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/RemoveVersionOperation.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/RemoveVersionOperation.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/RemoveVersionOperation.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/RemoveVersionOperation.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,98 @@
+/**
+ * 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 java.util.List;
+
+import org.apache.maven.mercury.util.TimeUtil;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ * removes a version from Metadata
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class RemoveVersionOperation
+ implements MetadataOperation
+{
+ private static final Language LANG = new DefaultLanguage( RemoveVersionOperation.class );
+
+ private String version;
+
+ /**
+ * @throws MetadataException
+ */
+ public RemoveVersionOperation( StringOperand data )
+ throws MetadataException
+ {
+ setOperand( data );
+ }
+
+ public void setOperand( Object data )
+ throws MetadataException
+ {
+ if ( data == null || !( data instanceof StringOperand ) )
+ {
+ throw new MetadataException( LANG.getMessage( "bad.operand", "StringOperand", data == null ? "null"
+ : data.getClass().getName() ) );
+ }
+
+ version = ( (StringOperand) data ).getOperand();
+ }
+
+ /**
+ * remove version to the in-memory metadata instance
+ *
+ * @param metadata
+ * @param version
+ * @return
+ */
+ public boolean perform( Metadata metadata )
+ throws MetadataException
+ {
+ if ( metadata == null )
+ {
+ return false;
+ }
+
+ Versioning vs = metadata.getVersioning();
+
+ if ( vs == null )
+ {
+ return false;
+ }
+
+ if ( vs.getVersions() != null && vs.getVersions().size() > 0 )
+ {
+ List<String> vl = vs.getVersions();
+ if ( !vl.contains( version ) )
+ {
+ return false;
+ }
+ }
+
+ vs.removeVersion( version );
+ vs.setLastUpdated( TimeUtil.getUTCTimestamp() );
+
+ return true;
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/RemoveVersionOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/RemoveVersionOperation.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/SetSnapshotOperation.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/SetSnapshotOperation.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/SetSnapshotOperation.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/SetSnapshotOperation.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,192 @@
+/**
+ * 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;
+
+ private String snapshotPomName;
+
+ /**
+ * @throws MetadataException
+ */
+ public SetSnapshotOperation( SnapshotOperand data )
+ throws MetadataException
+ {
+ setOperand( data );
+ }
+
+ public SetSnapshotOperation( StringOperand data )
+ throws MetadataException
+ {
+ setOperand( data );
+ }
+
+ public void setOperand( Object data )
+ throws MetadataException
+ {
+ if ( data != null && data instanceof SnapshotOperand )
+ {
+ snapshot = ( (SnapshotOperand) data ).getOperand();
+ }
+ else if ( data != null && data instanceof StringOperand )
+ {
+ snapshotPomName = ( (StringOperand) data ).getOperand();
+ }
+ else
+ {
+ throw new MetadataException( LANG.getMessage( "bad.operand", "SnapshotOperand", data == null ? "null"
+ : data.getClass().getName() ) );
+ }
+
+ }
+
+ /**
+ * 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 );
+ }
+
+ if ( snapshotPomName != null )
+ {
+ return updateSnapshot( snapshotPomName, metadata );
+ }
+ else
+ {
+ return updateSnapshot( snapshot, vs );
+ }
+
+ }
+
+ private boolean updateSnapshot( String snapshotVersion, Metadata metadata )
+ {
+ Snapshot snapshot = buildSnapshot( snapshotVersion, metadata );
+
+ Snapshot oldSnapshot = metadata.getVersioning().getSnapshot();
+
+ if ( needUpdateSnapshot( oldSnapshot, snapshot) )
+ {
+ return updateSnapshot( snapshot, metadata.getVersioning() );
+ }
+
+ return false;
+
+
+ }
+
+ private boolean updateSnapshot( Snapshot snapshot, Versioning vs )
+ {
+ vs.setSnapshot( snapshot );
+
+ vs.setLastUpdated( TimeUtil.getUTCTimestamp() );
+
+ return true;
+ }
+
+ private boolean needUpdateSnapshot( Snapshot oldSnapshot, Snapshot newSnapshot )
+ {
+ if ( newSnapshot == null )
+ {
+ return false;
+ }
+
+ if ( oldSnapshot == null )
+ {
+ return true;
+ }
+
+ if ( oldSnapshot.getBuildNumber() < newSnapshot.getBuildNumber() )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ private Snapshot buildSnapshot( String pomName, Metadata md )
+ {
+ // skip files like groupId-artifactId-versionSNAPSHOT.pom
+ if ( pomName.endsWith( "SNAPSHOT.pom" ) )
+ {
+ return null;
+ }
+
+ Snapshot result = new Snapshot();
+
+ int lastHyphenPos = pomName.lastIndexOf( '-' );
+
+ try
+ {
+ int buildNumber = Integer.parseInt( pomName.substring(
+ lastHyphenPos + 1,
+ pomName.length() - 4 ) );
+
+ String timestamp = pomName.substring( ( md.getArtifactId() + '-' + md.getVersion() + '-' )
+ .length()
+ - "-SNAPSHOT".length(), lastHyphenPos );
+
+ result.setLocalCopy( false );
+
+ result.setBuildNumber( buildNumber );
+
+ result.setTimestamp( timestamp );
+
+ return result;
+ }
+ catch ( Exception e )
+ {
+ // skip any exception because of illegal version numbers
+ return null;
+ }
+
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/SetSnapshotOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/metadata/SetSnapshotOperation.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision