+++ /dev/null
-package org.apache.maven.archiva.common.consumers;
-
-/*
- * 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.
- */
-
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * AbstractDiscovererConsumer
- *
- * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
- * @version $Id$
- */
-public abstract class AbstractConsumer
- extends AbstractLogEnabled
- implements Consumer
-{
- /**
- * @plexus.requirement
- */
- protected ArtifactFactory artifactFactory;
-
- protected ArtifactRepository repository;
-
- protected AbstractConsumer()
- {
- /* do nothing */
- }
-
- public List getExcludePatterns()
- {
- return Collections.EMPTY_LIST;
- }
-
- public boolean init( ArtifactRepository repository )
- {
- this.repository = repository;
- return isEnabled();
- }
-
- protected boolean isEnabled()
- {
- return true;
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.consumers;
-
-/*
- * 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.
- */
-
-import org.apache.maven.archiva.common.utils.BaseFile;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-
-import java.util.List;
-
-/**
- * DiscovererConsumer
- *
- * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
- * @version $Id$
- */
-public interface Consumer
-{
- public static final String ROLE = Consumer.class.getName();
-
- /**
- * This is the human readable name for the discoverer.
- *
- * @return the human readable discoverer name.
- */
- public String getName();
-
- /**
- * This is used to initialize any internals in the consumer before it is used.
- *
- * This method is called by the internals of archiva and is not meant to be used by other developers.
- * This method is called once per repository.
- *
- * @param repository the repository to initialize the consumer against.
- * @return true if the repository is valid for this consumer. false will result in consumer being disabled
- * for the provided repository.
- */
- public boolean init( ArtifactRepository repository );
-
- /**
- * Get the List of excluded file patterns for this consumer.
- *
- * @return the list of excluded file patterns for this consumer.
- */
- public List getExcludePatterns();
-
- /**
- * Get the List of included file patterns for this consumer.
- *
- * @return the list of included file patterns for this consumer.
- */
- public List getIncludePatterns();
-
- /**
- * Called by archiva framework to indicate that there is a file suitable for consuming,
- * This method will only be called if the {@link #init(ArtifactRepository)} and {@link #getExcludePatterns()}
- * and {@link #getIncludePatterns()} all pass for this consumer.
- *
- * @param file the file to process.
- * @throws ConsumerException if there was a problem processing this file.
- */
- public void processFile( BaseFile file ) throws ConsumerException;
-
- /**
- * Called by archiva framework to indicate that there has been a problem detected
- * on a specific file.
- *
- * NOTE: It is very possible for 1 file to have more than 1 problem associated with it.
- *
- * @param file the file to process.
- * @param message the message describing the problem.
- */
- public void processFileProblem( BaseFile file, String message );
-}
+++ /dev/null
-package org.apache.maven.archiva.common.consumers;
-
-/*
- * 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.
- */
-
-import org.apache.maven.archiva.common.ArchivaException;
-import org.apache.maven.archiva.common.utils.BaseFile;
-
-/**
- * ConsumerException - details about the failure of a consumer.
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class ConsumerException
- extends ArchivaException
-{
- private BaseFile file;
-
- public ConsumerException( BaseFile file, String message, Throwable cause )
- {
- super( message, cause );
- this.file = file;
- }
-
- public ConsumerException( BaseFile file, String message )
- {
- super( message );
- this.file = file;
- }
-
- public BaseFile getFile()
- {
- return file;
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.consumers;
-
-/*
- * 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.
- */
-
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.context.Context;
-import org.codehaus.plexus.context.ContextException;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
-
-/**
- * DiscovererConsumerFactory - factory for consumers.
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- * @plexus.component role="org.apache.maven.archiva.common.consumers.ConsumerFactory"
- */
-public class ConsumerFactory
- extends AbstractLogEnabled
- implements Contextualizable
-{
- public static final String ROLE = ConsumerFactory.class.getName();
-
- private PlexusContainer container;
-
- public Consumer createConsumer( String name )
- throws ConsumerException
- {
- getLogger().info( "Attempting to create consumer [" + name + "]" );
-
- Consumer consumer;
- try
- {
- consumer = (Consumer) container.lookup( Consumer.ROLE, name, container.getLookupRealm() );
- }
- catch ( Throwable t )
- {
- String emsg = "Unable to create consumer [" + name + "]: " + t.getMessage();
- getLogger().warn( t.getMessage(), t );
- throw new ConsumerException( null, emsg, t );
- }
-
- getLogger().info( "Created consumer [" + name + "|" + consumer.getName() + "]" );
- return consumer;
- }
-
- public void contextualize( Context context )
- throws ContextException
- {
- container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.consumers;
-
-/*
- * 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.
- */
-
-import org.apache.maven.archiva.common.artifact.builder.BuilderException;
-import org.apache.maven.archiva.common.artifact.builder.DefaultLayoutArtifactBuilder;
-import org.apache.maven.archiva.common.artifact.builder.LayoutArtifactBuilder;
-import org.apache.maven.archiva.common.artifact.builder.LegacyLayoutArtifactBuilder;
-import org.apache.maven.archiva.common.utils.BaseFile;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
-import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
-import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * DefaultArtifactConsumer
- *
- * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
- * @version $Id$
- */
-public abstract class GenericArtifactConsumer
- extends AbstractConsumer
- implements Consumer
-{
- public abstract void processArtifact( Artifact artifact, BaseFile file );
-
- private Map artifactBuilders = new HashMap();
-
- private static final List includePatterns;
-
- static
- {
- includePatterns = new ArrayList();
- includePatterns.add( "**/*.pom" );
- includePatterns.add( "**/*.jar" );
- includePatterns.add( "**/*.war" );
- includePatterns.add( "**/*.ear" );
- includePatterns.add( "**/*.sar" );
- includePatterns.add( "**/*.zip" );
- includePatterns.add( "**/*.gz" );
- includePatterns.add( "**/*.bz2" );
- }
-
- private String layoutId = "default";
-
- public boolean init( ArtifactRepository repository )
- {
- this.artifactBuilders.clear();
- this.artifactBuilders.put( "default", new DefaultLayoutArtifactBuilder( artifactFactory ) );
- this.artifactBuilders.put( "legacy", new LegacyLayoutArtifactBuilder( artifactFactory ) );
-
- if ( repository.getLayout() instanceof LegacyRepositoryLayout )
- {
- this.layoutId = "legacy";
- }
-
- return super.init( repository );
- }
-
- public List getIncludePatterns()
- {
- return includePatterns;
- }
-
- public boolean isEnabled()
- {
- ArtifactRepositoryLayout layout = repository.getLayout();
- return ( layout instanceof DefaultRepositoryLayout ) || ( layout instanceof LegacyRepositoryLayout );
- }
-
- public void processFile( BaseFile file )
- throws ConsumerException
- {
- if ( file.length() <= 0 )
- {
- processFileProblem( file, "File is empty." );
- }
-
- if ( !file.canRead() )
- {
- processFileProblem( file, "Not allowed to read file due to permission settings on file." );
- }
-
- try
- {
- Artifact artifact = buildArtifact( file );
-
- processArtifact( artifact, file );
- }
- catch ( BuilderException e )
- {
- throw new ConsumerException( file, e.getMessage(), e );
- }
- }
-
- private Artifact buildArtifact( BaseFile file )
- throws BuilderException
- {
- LayoutArtifactBuilder builder = (LayoutArtifactBuilder) artifactBuilders.get( layoutId );
-
- Artifact artifact = builder.build( file.getRelativePath() );
- artifact.setRepository( repository );
- artifact.setFile( file );
-
- return artifact;
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.consumers;
-
-/*
- * 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.
- */
-
-import org.apache.maven.archiva.common.utils.BaseFile;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * GenericModelConsumer - consumer for pom files.
- *
- * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
- * @version $Id$
- */
-public abstract class GenericModelConsumer
- extends AbstractConsumer
- implements Consumer
-{
- public abstract void processModel( Model model, BaseFile file );
-
- private static final List includePatterns;
-
- static
- {
- includePatterns = new ArrayList();
- includePatterns.add( "**/*.pom" );
- }
-
- public List getIncludePatterns()
- {
- return includePatterns;
- }
-
- public boolean isEnabled()
- {
- return true;
- }
-
- public void processFile( BaseFile file )
- throws ConsumerException
- {
- Model model = buildModel( file );
- processModel( model, file );
- }
-
- private Model buildModel( BaseFile file )
- throws ConsumerException
- {
- Model model;
- Reader reader = null;
- try
- {
- reader = new FileReader( file );
- MavenXpp3Reader modelReader = new MavenXpp3Reader();
-
- model = modelReader.read( reader );
- }
- catch ( XmlPullParserException e )
- {
- throw new ConsumerException( file, "Error parsing metadata file: " + e.getMessage(), e );
- }
- catch ( IOException e )
- {
- throw new ConsumerException( file, "Error reading metadata file: " + e.getMessage(), e );
- }
- finally
- {
- IOUtil.close( reader );
- }
-
- return model;
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.consumers;
-
-/*
- * 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.
- */
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.BaseFile;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
-import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
-import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
-import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
-import org.apache.maven.artifact.repository.metadata.Metadata;
-import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
-import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
-import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
-
-/**
- * GenericRepositoryMetadataConsumer - Consume any maven-metadata.xml files as {@link RepositoryMetadata} objects.
- *
- * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
- * @version $Id$
- */
-public abstract class GenericRepositoryMetadataConsumer
- extends AbstractConsumer
- implements Consumer
-{
- public abstract void processRepositoryMetadata( RepositoryMetadata metadata, BaseFile file );
-
- private static final List includePatterns;
-
- static
- {
- includePatterns = new ArrayList();
- includePatterns.add( "**/maven-metadata.xml" );
- }
-
- public List getIncludePatterns()
- {
- return includePatterns;
- }
-
- public boolean isEnabled()
- {
- // the RepositoryMetadata objects only exist in 'default' layout repositories.
- ArtifactRepositoryLayout layout = repository.getLayout();
- return ( layout instanceof DefaultRepositoryLayout );
- }
-
- public void processFile( BaseFile file )
- throws ConsumerException
- {
- if ( file.length() <= 0 )
- {
- throw new ConsumerException( file, "File is empty." );
- }
-
- if ( !file.canRead() )
- {
- throw new ConsumerException( file, "Not allowed to read file due to permission settings on file." );
- }
-
- RepositoryMetadata metadata = buildMetadata( file );
- processRepositoryMetadata( metadata, file );
- }
-
- private RepositoryMetadata buildMetadata( BaseFile metadataFile )
- throws ConsumerException
- {
- Metadata m;
- Reader reader = null;
- try
- {
- reader = new FileReader( metadataFile );
- MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();
-
- m = metadataReader.read( reader );
- }
- catch ( XmlPullParserException e )
- {
- throw new ConsumerException( metadataFile, "Error parsing metadata file: " + e.getMessage(), e );
- }
- catch ( IOException e )
- {
- throw new ConsumerException( metadataFile, "Error reading metadata file: " + e.getMessage(), e );
- }
- finally
- {
- IOUtil.close( reader );
- }
-
- RepositoryMetadata repositoryMetadata = buildMetadata( m, metadataFile );
-
- if ( repositoryMetadata == null )
- {
- throw new ConsumerException( metadataFile, "Unable to build a repository metadata from path." );
- }
-
- return repositoryMetadata;
- }
-
- /**
- * Builds a RepositoryMetadata object from a Metadata object and its path.
- *
- * @param m Metadata
- * @param metadataFile file information
- * @return RepositoryMetadata if the parameters represent one; null if not
- * @throws ConsumerException
- */
- private RepositoryMetadata buildMetadata( Metadata m, BaseFile metadataFile )
- throws ConsumerException
- {
- if ( artifactFactory == null )
- {
- throw new IllegalStateException( "Unable to build metadata with a null artifactFactory." );
- }
-
- String metaGroupId = m.getGroupId();
- String metaArtifactId = m.getArtifactId();
- String metaVersion = m.getVersion();
-
- // check if the groupId, artifactId and version is in the
- // metadataPath
- // parse the path, in reverse order
- List pathParts = new ArrayList();
- StringTokenizer st = new StringTokenizer( metadataFile.getRelativePath(), "/\\" );
- while ( st.hasMoreTokens() )
- {
- pathParts.add( st.nextToken() );
- }
-
- Collections.reverse( pathParts );
- // remove the metadata file
- pathParts.remove( 0 );
- Iterator it = pathParts.iterator();
- String tmpDir = (String) it.next();
-
- Artifact artifact = null;
- if ( StringUtils.isNotEmpty( metaVersion ) )
- {
- artifact = artifactFactory.createProjectArtifact( metaGroupId, metaArtifactId, metaVersion );
- }
-
- // snapshotMetadata
- RepositoryMetadata metadata = null;
- if ( tmpDir != null && tmpDir.equals( metaVersion ) )
- {
- if ( artifact != null )
- {
- metadata = new SnapshotArtifactRepositoryMetadata( artifact );
- }
- }
- else if ( tmpDir != null && tmpDir.equals( metaArtifactId ) )
- {
- // artifactMetadata
- if ( artifact != null )
- {
- metadata = new ArtifactRepositoryMetadata( artifact );
- }
- else
- {
- artifact = artifactFactory.createProjectArtifact( metaGroupId, metaArtifactId, "1.0" );
- metadata = new ArtifactRepositoryMetadata( artifact );
- }
- }
- else
- {
- String groupDir = "";
- int ctr = 0;
- for ( it = pathParts.iterator(); it.hasNext(); )
- {
- String path = (String) it.next();
- if ( ctr == 0 )
- {
- groupDir = path;
- }
- else
- {
- groupDir = path + "." + groupDir;
- }
- ctr++;
- }
-
- // groupMetadata
- if ( metaGroupId != null && metaGroupId.equals( groupDir ) )
- {
- metadata = new GroupRepositoryMetadata( metaGroupId );
- }
- else
- {
- /* If we reached this point, we have some bad metadata.
- * We have a metadata file, with values for groupId / artifactId / version.
- * But the information it is providing does not exist relative to the file location.
- *
- * See ${basedir}/src/test/repository/javax/maven-metadata.xml for example
- */
- throw new ConsumerException( metadataFile,
- "Contents of metadata are not appropriate for its location on disk." );
- }
- }
-
- return metadata;
- }
-}
--- /dev/null
+package org.apache.maven.archiva.common.utils;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * RepositoryURL - Mutable (and protocol forgiving) URL object.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RepositoryURL
+{
+ private String url;
+
+ private String protocol;
+
+ private String host;
+
+ private String port;
+
+ private String username;
+
+ private String password;
+
+ private String path;
+
+ public RepositoryURL( String url )
+ {
+ this.url = url;
+
+ // .\ Parse the URL \.____________________________________________
+
+ int pos;
+
+ pos = url.indexOf( "://" );
+ if ( pos == ( -1 ) )
+ {
+ throw new IllegalArgumentException( "Invalid URL, unable to parse protocol:// from " + url );
+ }
+
+ protocol = url.substring( 0, pos );
+
+ // attempt to find the start of the 'path'
+ pos = url.indexOf( "/", protocol.length() + 3 );
+
+ // no path specified - ex "http://localhost"
+ if ( pos == ( -1 ) )
+ {
+ // set pos to end of string. (needed for 'middle section')
+ pos = url.length();
+ // default path
+ path = "/";
+ }
+ else
+ {
+ // get actual path.
+ path = url.substring( pos );
+ }
+
+ // get the middle section ( username : password @ hostname : port )
+ String middle = url.substring( protocol.length() + 3, pos );
+
+ pos = middle.indexOf( '@' );
+
+ // we have an authentication section.
+ if ( pos > 0 )
+ {
+ String authentication = middle.substring( 0, pos );
+ middle = middle.substring( pos + 1 ); // lop off authentication for host:port search
+
+ pos = authentication.indexOf( ':' );
+
+ // we have a password.
+ if ( pos > 0 )
+ {
+ username = authentication.substring( 0, pos );
+ password = authentication.substring( pos + 1 );
+ }
+ else
+ {
+ username = authentication;
+ }
+ }
+
+ pos = middle.indexOf( ':' );
+
+ // we have a defined port
+ if ( pos > 0 )
+ {
+ host = middle.substring( 0, pos );
+ port = middle.substring( pos + 1 );
+ }
+ else
+ {
+ host = middle;
+ }
+ }
+
+ public String toString()
+ {
+ return url;
+ }
+
+ public String getUsername()
+ {
+ return username;
+ }
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public String getHost()
+ {
+ return host;
+ }
+
+ public String getPath()
+ {
+ return path;
+ }
+
+ public String getPort()
+ {
+ return port;
+ }
+
+ public String getProtocol()
+ {
+ return protocol;
+ }
+
+ public String getUrl()
+ {
+ return url;
+ }
+}
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.util.FileUtils;
import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
/**
public abstract class AbstractArchivaCommonTestCase
extends PlexusTestCase
{
- protected ArtifactRepository getLegacyRepository()
- throws Exception
- {
- File repoBaseDir = new File( getBasedir(), "src/test/legacy-repository" );
- ArtifactRepository repository = createRepository( repoBaseDir, "legacy" );
- resetRepositoryState( repository );
- return repository;
- }
-
- protected ArtifactRepository getDefaultRepository()
- throws Exception
- {
- File repoBaseDir = new File( getBasedir(), "src/test/repository" );
- ArtifactRepository repository = createRepository( repoBaseDir, "default" );
- resetRepositoryState( repository );
- return repository;
- }
-
- private void resetRepositoryState( ArtifactRepository repository )
- throws IOException
- {
- File repoBaseDir = new File( repository.getBasedir() );
-
- List tmpfiles = FileUtils.getFiles( repoBaseDir, ".*", "" );
- for ( Iterator it = tmpfiles.iterator(); it.hasNext(); )
- {
- File hit = (File) it.next();
- if ( hit.exists() )
- {
- if ( hit.isFile() )
- {
- hit.delete();
- }
-
- if ( hit.isDirectory() )
- {
- FileUtils.deleteDirectory( hit );
- }
- }
- }
- }
-
protected ArtifactRepository createRepository( File basedir, String layout )
throws Exception
{
TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva.common" );
//$JUnit-BEGIN$
suite.addTest( org.apache.maven.archiva.common.artifact.builder.AllTests.suite() );
- suite.addTest( org.apache.maven.archiva.common.consumers.AllTests.suite() );
suite.addTest( org.apache.maven.archiva.common.utils.AllTests.suite() );
//$JUnit-END$
return suite;
+++ /dev/null
-package org.apache.maven.archiva.common.consumers;
-
-/*
- * 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.
- */
-
-import org.apache.maven.archiva.common.AbstractArchivaCommonTestCase;
-
-/**
- * AbstractGenericConsumerTestCase
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public abstract class AbstractGenericConsumerTestCase
- extends AbstractArchivaCommonTestCase
-{
- protected ConsumerFactory consumerFactory;
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
-
- consumerFactory = (ConsumerFactory) lookup( ConsumerFactory.ROLE );
- }
-
- protected void tearDown()
- throws Exception
- {
- if ( consumerFactory != null )
- {
- release( consumerFactory );
- }
- super.tearDown();
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.consumers;
-
-/*
- * 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.
- */
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * AllTests
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class AllTests
-{
-
- public static Test suite()
- {
- TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva.common.consumers" );
- //$JUnit-BEGIN$
- suite.addTestSuite( GenericArtifactConsumerTest.class );
- //$JUnit-END$
- return suite;
- }
-
-}
+++ /dev/null
-package org.apache.maven.archiva.common.consumers;
-
-/*
- * 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.
- */
-
-import org.apache.maven.archiva.common.utils.BaseFile;
-import org.codehaus.plexus.util.StringUtils;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * FileProblemsTracker
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class FileProblemsTracker
-{
- private Map problemMap = new HashMap();
-
- public void addProblem( BaseFile file, String message )
- {
- String path = file.getRelativePath();
- addProblem( path, message );
- }
-
- private void addProblem( String path, String message )
- {
- path = StringUtils.replace( path, "\\", "/" );
- List problems = getProblems( path );
- problems.add( message );
- problemMap.put( path, problems );
- }
-
- public void addProblem( ConsumerException e )
- {
- if ( e.getFile() != null )
- {
- this.addProblem( e.getFile(), e.getMessage() );
- }
- else
- {
- this.addProblem( "|fatal|", e.getMessage() );
- }
- }
-
- public boolean hasProblems( String path )
- {
- if ( !problemMap.containsKey( path ) )
- {
- // No tracking of path at all.
- return false;
- }
-
- List problems = (List) problemMap.get( path );
- if ( problems == null )
- {
- // found path, but no list.
- return false;
- }
-
- return !problems.isEmpty();
- }
-
- public Set getPaths()
- {
- return problemMap.keySet();
- }
-
- public List getProblems( String path )
- {
- List problems = (List) problemMap.get( path );
- if ( problems == null )
- {
- problems = new ArrayList();
- }
-
- return problems;
- }
-
- public int getProblemCount()
- {
- int count = 0;
- for ( Iterator it = problemMap.values().iterator(); it.hasNext(); )
- {
- List problems = (List) it.next();
- count += problems.size();
- }
-
- return count;
- }
-
-}
+++ /dev/null
-package org.apache.maven.archiva.common.consumers;
-
-/*
- * 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.
- */
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.BaseFile;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * GenericArtifactConsumerTest
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class GenericArtifactConsumerTest
- extends AbstractGenericConsumerTestCase
-{
- private MockArtifactConsumer getMockArtifactConsumer()
- throws Exception
- {
- return (MockArtifactConsumer) consumerFactory.createConsumer( "mock-artifact" );
- }
-
- public void testScanLegacy()
- throws Exception
- {
- ArtifactRepository repository = getLegacyRepository();
- List consumers = new ArrayList();
-
- MockArtifactConsumer mockConsumer = getMockArtifactConsumer();
- mockConsumer.init( repository );
-
- consumers.add( mockConsumer );
-
- List files = getLegacyLayoutArtifactPaths();
- for ( Iterator it = files.iterator(); it.hasNext(); )
- {
- String path = (String) it.next();
- try
- {
- mockConsumer.processFile( new BaseFile( repository.getBasedir(), path ) );
- }
- catch ( ConsumerException e )
- {
- mockConsumer.getProblemsTracker().addProblem( e );
- }
- }
-
- assertNotNull( consumers );
-
- FileProblemsTracker tracker = mockConsumer.getProblemsTracker();
-
- assertTracker( tracker, 16 );
-
- assertHasFailureMessage( "Path does not match a legacy repository path for an artifact",
- "invalid/invalid-1.0.jar", tracker );
- assertHasFailureMessage( "Path filename version is empty", "invalid/jars/invalid.jar", tracker );
- assertHasFailureMessage( "Path does not match a legacy repository path for an artifact",
- "invalid/jars/1.0/invalid-1.0.jar", tracker );
-
- assertEquals( 10, mockConsumer.getArtifactMap().size() );
- }
-
- public void testScanDefault()
- throws Exception
- {
- ArtifactRepository repository = getDefaultRepository();
- List consumers = new ArrayList();
-
- MockArtifactConsumer mockConsumer = getMockArtifactConsumer();
- mockConsumer.init( repository );
-
- consumers.add( mockConsumer );
-
- List files = getDefaultLayoutArtifactPaths();
- for ( Iterator it = files.iterator(); it.hasNext(); )
- {
- String path = (String) it.next();
- try
- {
- mockConsumer.processFile( new BaseFile( repository.getBasedir(), path ) );
- }
- catch ( ConsumerException e )
- {
- mockConsumer.getProblemsTracker().addProblem( e );
- }
- }
-
- // Test gathered information from Mock consumer.
-
- assertNotNull( consumers );
-
- FileProblemsTracker tracker = mockConsumer.getProblemsTracker();
-
- assertTracker( tracker, 21 );
-
- assertHasFailureMessage( "Failed to create a snapshot artifact: invalid:invalid:jar:1.0:runtime",
- "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", tracker );
- assertHasFailureMessage( "Path is too short to build an artifact from.", "invalid/invalid-1.0.jar", tracker );
- assertHasFailureMessage( "Built artifact version does not match path version",
- "invalid/invalid/1.0/invalid-2.0.jar", tracker );
-
- assertEquals( 25, mockConsumer.getArtifactMap().size() );
-
- // Test for known include artifacts
-
- Collection artifacts = mockConsumer.getArtifactMap().values();
- assertHasArtifact( "org.apache.maven", "testing", "1.0", "jar", null, artifacts );
- assertHasArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client", artifacts );
- assertHasArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources", artifacts );
- assertHasArtifact( "org.apache.maven", "testing", "1.0", "java-source", "test-sources", artifacts );
- assertHasArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip", null, artifacts );
- assertHasArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz", null, artifacts );
- assertHasArtifact( "javax.sql", "jdbc", "2.0", "jar", null, artifacts );
- assertHasArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1", "jar", null, artifacts );
- assertHasArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1", "jar", "javadoc", artifacts );
-
- // Test for known excluded files and dirs to validate exclusions.
-
- Iterator it = mockConsumer.getArtifactMap().values().iterator();
- while ( it.hasNext() )
- {
- Artifact a = (Artifact) it.next();
- assertTrue( "Artifact " + a + " should have it's .getFile() set.", a.getFile() != null );
- assertTrue( "Artifact " + a + " should have it's .getRepository() set.", a.getRepository() != null );
- assertTrue( "Artifact " + a + " should have non-null repository url.", a.getRepository().getUrl() != null );
- assertFalse( "Check not CVS", a.getFile().getPath().indexOf( "CVS" ) >= 0 );
- assertFalse( "Check not .svn", a.getFile().getPath().indexOf( ".svn" ) >= 0 );
- }
- }
-
- private void dumpProblems( FileProblemsTracker tracker )
- {
- int problemNum = 0;
- System.out.println( "-- ProblemTracker dump -------------------------" );
- for ( Iterator itPaths = tracker.getPaths().iterator(); itPaths.hasNext(); )
- {
- String path = (String) itPaths.next();
- System.out.println( " [" + problemNum + "]: " + path );
-
- int messageNum = 0;
- for ( Iterator itProblems = tracker.getProblems( path ).iterator(); itProblems.hasNext(); )
- {
- String message = (String) itProblems.next();
- System.out.println( " [" + messageNum + "]: " + message );
- messageNum++;
- }
-
- problemNum++;
- }
- }
-
- private void assertTracker( FileProblemsTracker tracker, int expectedProblemCount )
- {
- assertNotNull( "ProblemsTracker should not be null.", tracker );
-
- int actualProblemCount = tracker.getProblemCount();
- if ( expectedProblemCount != actualProblemCount )
- {
- dumpProblems( tracker );
- fail( "Problem count (across all paths) expected:<" + expectedProblemCount + ">, actual:<"
- + actualProblemCount + ">" );
- }
- }
-
- private void assertHasFailureMessage( String message, String path, FileProblemsTracker tracker )
- {
- if ( !tracker.hasProblems( path ) )
- {
- fail( "There are no messages for expected path [" + path + "]" );
- }
-
- assertTrue( "Unable to find message [" + message + "] in path [" + path + "]", tracker.getProblems( path )
- .contains( message ) );
- }
-
- private void assertHasArtifact( String groupId, String artifactId, String version, String type, String classifier,
- Collection collection )
- {
- for ( Iterator it = collection.iterator(); it.hasNext(); )
- {
- Artifact artifact = (Artifact) it.next();
- if ( StringUtils.equals( groupId, artifact.getGroupId() )
- && StringUtils.equals( artifactId, artifact.getArtifactId() )
- && StringUtils.equals( version, artifact.getVersion() )
- && StringUtils.equals( type, artifact.getType() )
- && StringUtils.equals( classifier, artifact.getClassifier() ) )
- {
- // Found it!
- return;
- }
- }
-
- fail( "Was unable to find artifact " + groupId + ":" + artifactId + ":" + version + ":" + type + ":"
- + classifier );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.consumers;
-
-/*
- * 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.
- */
-
-import org.apache.maven.archiva.common.utils.BaseFile;
-import org.apache.maven.archiva.common.utils.PathUtil;
-import org.apache.maven.artifact.Artifact;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * MockArtifactConsumer
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- *
- * @plexus.component role="org.apache.maven.archiva.common.consumers.Consumers"
- * role-hint="mock-artifact"
- * instantiation-strategy="per-lookup"
- */
-public class MockArtifactConsumer
- extends GenericArtifactConsumer
-{
- private Map artifactMap = new HashMap();
-
- private FileProblemsTracker problemsTracker = new FileProblemsTracker();
-
- public void processArtifact( Artifact artifact, BaseFile file )
- {
- String relpath = PathUtil.getRelative( repository.getBasedir(), file );
- artifactMap.put( relpath, artifact );
- }
-
- public void processFileProblem( BaseFile file, String message )
- {
- problemsTracker.addProblem( file, message );
- }
-
- public Map getArtifactMap()
- {
- return artifactMap;
- }
-
- public String getName()
- {
- return "Mock Artifact Consumer (Testing Only)";
- }
-
- public FileProblemsTracker getProblemsTracker()
- {
- return problemsTracker;
- }
-}
\ No newline at end of file
+++ /dev/null
-package org.apache.maven.archiva.common.consumers;
-
-/*
- * 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.
- */
-
-import org.apache.maven.archiva.common.utils.BaseFile;
-import org.apache.maven.model.Model;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * MockModelConsumer
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- *
- * @plexus.component role="org.apache.maven.archiva.common.consumers.Consumers"
- * role-hint="mock-model"
- * instantiation-strategy="per-lookup"
- */
-public class MockModelConsumer
- extends GenericModelConsumer
-{
- private Map modelMap = new HashMap();
-
- private FileProblemsTracker problemsTracker = new FileProblemsTracker();
-
- public void processModel( Model model, BaseFile file )
- {
- modelMap.put( file.getRelativePath(), model );
- }
-
- public void processFileProblem( BaseFile file, String message )
- {
- problemsTracker.addProblem( file, message );
- }
-
- public Map getModelMap()
- {
- return modelMap;
- }
-
- public String getName()
- {
- return "Mock Model Consumer (Testing Only)";
- }
-
- public FileProblemsTracker getProblemsTracker()
- {
- return problemsTracker;
- }
-
-}
\ No newline at end of file
+++ /dev/null
-package org.apache.maven.archiva.common.consumers;
-
-/*
- * 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.
- */
-
-import org.apache.maven.archiva.common.utils.BaseFile;
-import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * MockRepositoryMetadataConsumer
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- *
- * @plexus.component role="org.apache.maven.archiva.common.consumers.Consumers"
- * role-hint="mock-metadata"
- * instantiation-strategy="per-lookup"
- */
-public class MockRepositoryMetadataConsumer
- extends GenericRepositoryMetadataConsumer
-{
- private Map repositoryMetadataMap = new HashMap();
-
- private FileProblemsTracker problemsTracker = new FileProblemsTracker();
-
- public void processRepositoryMetadata( RepositoryMetadata metadata, BaseFile file )
- {
- repositoryMetadataMap.put( file.getRelativePath(), metadata );
- }
-
- public void processFileProblem( BaseFile file, String message )
- {
- problemsTracker.addProblem( file, message );
- }
-
- public Map getRepositoryMetadataMap()
- {
- return repositoryMetadataMap;
- }
-
- public String getName()
- {
- return "Mock RepositoryMetadata Consumer (Testing Only)";
- }
-
- public FileProblemsTracker getProblemsTracker()
- {
- return problemsTracker;
- }
-}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>archiva-consumer-api</artifactId>
+ <name>Archiva Consumer API</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-model</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.model.ArchivaRepository;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * AbstractDiscovererConsumer
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class AbstractConsumer
+ extends AbstractLogEnabled
+ implements Consumer
+{
+ /**
+ * @plexus.requirement
+ */
+ protected ArtifactFactory artifactFactory;
+
+ protected ArchivaRepository repository;
+
+ protected AbstractConsumer()
+ {
+ /* do nothing */
+ }
+
+ public List getExcludePatterns()
+ {
+ return Collections.EMPTY_LIST;
+ }
+
+ public boolean init( ArchivaRepository repository )
+ {
+ this.repository = repository;
+ return isEnabled();
+ }
+
+ protected boolean isEnabled()
+ {
+ return true;
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.maven.archiva.model.ArchivaRepository;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+
+import java.util.List;
+
+/**
+ * DiscovererConsumer
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface Consumer
+{
+ public static final String ROLE = Consumer.class.getName();
+
+ /**
+ * This is the human readable name for the discoverer.
+ *
+ * @return the human readable discoverer name.
+ */
+ public String getName();
+
+ /**
+ * This is used to initialize any internals in the consumer before it is used.
+ *
+ * This method is called by the internals of archiva and is not meant to be used by other developers.
+ * This method is called once per repository.
+ *
+ * @param repository the repository to initialize the consumer against.
+ * @return true if the repository is valid for this consumer. false will result in consumer being disabled
+ * for the provided repository.
+ */
+ public boolean init( ArchivaRepository repository );
+
+ /**
+ * Get the List of excluded file patterns for this consumer.
+ *
+ * @return the list of excluded file patterns for this consumer.
+ */
+ public List getExcludePatterns();
+
+ /**
+ * Get the List of included file patterns for this consumer.
+ *
+ * @return the list of included file patterns for this consumer.
+ */
+ public List getIncludePatterns();
+
+ /**
+ * Called by archiva framework to indicate that there is a file suitable for consuming,
+ * This method will only be called if the {@link #init(ArtifactRepository)} and {@link #getExcludePatterns()}
+ * and {@link #getIncludePatterns()} all pass for this consumer.
+ *
+ * @param file the file to process.
+ * @throws ConsumerException if there was a problem processing this file.
+ */
+ public void processFile( BaseFile file ) throws ConsumerException;
+
+ /**
+ * Called by archiva framework to indicate that there has been a problem detected
+ * on a specific file.
+ *
+ * NOTE: It is very possible for 1 file to have more than 1 problem associated with it.
+ *
+ * @param file the file to process.
+ * @param message the message describing the problem.
+ */
+ public void processFileProblem( BaseFile file, String message );
+}
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.maven.archiva.common.utils.BaseFile;
+
+/**
+ * ConsumerException - details about the failure of a consumer.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ConsumerException
+ extends ArchivaException
+{
+ private BaseFile file;
+
+ public ConsumerException( BaseFile file, String message, Throwable cause )
+ {
+ super( message, cause );
+ this.file = file;
+ }
+
+ public ConsumerException( BaseFile file, String message )
+ {
+ super( message );
+ this.file = file;
+ }
+
+ public BaseFile getFile()
+ {
+ return file;
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+
+/**
+ * DiscovererConsumerFactory - factory for consumers.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ * @plexus.component role="org.apache.maven.archiva.common.consumers.ConsumerFactory"
+ */
+public class ConsumerFactory
+ extends AbstractLogEnabled
+ implements Contextualizable
+{
+ public static final String ROLE = ConsumerFactory.class.getName();
+
+ private PlexusContainer container;
+
+ public Consumer createConsumer( String name )
+ throws ConsumerException
+ {
+ getLogger().info( "Attempting to create consumer [" + name + "]" );
+
+ Consumer consumer;
+ try
+ {
+ consumer = (Consumer) container.lookup( Consumer.ROLE, name, container.getLookupRealm() );
+ }
+ catch ( Throwable t )
+ {
+ String emsg = "Unable to create consumer [" + name + "]: " + t.getMessage();
+ getLogger().warn( t.getMessage(), t );
+ throw new ConsumerException( null, emsg, t );
+ }
+
+ getLogger().info( "Created consumer [" + name + "|" + consumer.getName() + "]" );
+ return consumer;
+ }
+
+ public void contextualize( Context context )
+ throws ContextException
+ {
+ container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.common.artifact.builder.BuilderException;
+import org.apache.maven.archiva.common.artifact.builder.DefaultLayoutArtifactBuilder;
+import org.apache.maven.archiva.common.artifact.builder.LayoutArtifactBuilder;
+import org.apache.maven.archiva.common.artifact.builder.LegacyLayoutArtifactBuilder;
+import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.maven.archiva.model.ArchivaRepository;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * DefaultArtifactConsumer
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class GenericArtifactConsumer
+ extends AbstractConsumer
+ implements Consumer
+{
+ public abstract void processArtifact( Artifact artifact, BaseFile file );
+
+ private Map artifactBuilders = new HashMap();
+
+ private static final List includePatterns;
+
+ static
+ {
+ includePatterns = new ArrayList();
+ includePatterns.add( "**/*.pom" );
+ includePatterns.add( "**/*.jar" );
+ includePatterns.add( "**/*.war" );
+ includePatterns.add( "**/*.ear" );
+ includePatterns.add( "**/*.sar" );
+ includePatterns.add( "**/*.zip" );
+ includePatterns.add( "**/*.gz" );
+ includePatterns.add( "**/*.bz2" );
+ }
+
+ private String layoutId = "default";
+
+ public boolean init( ArchivaRepository repository )
+ {
+ this.artifactBuilders.clear();
+ this.artifactBuilders.put( "default", new DefaultLayoutArtifactBuilder( artifactFactory ) );
+ this.artifactBuilders.put( "legacy", new LegacyLayoutArtifactBuilder( artifactFactory ) );
+
+ if ( repository.getLayout() instanceof LegacyRepositoryLayout )
+ {
+ this.layoutId = "legacy";
+ }
+
+ return super.init( repository );
+ }
+
+ public List getIncludePatterns()
+ {
+ return includePatterns;
+ }
+
+ public boolean isEnabled()
+ {
+ ArtifactRepositoryLayout layout = repository.getLayout();
+ return ( layout instanceof DefaultRepositoryLayout ) || ( layout instanceof LegacyRepositoryLayout );
+ }
+
+ public void processFile( BaseFile file )
+ throws ConsumerException
+ {
+ if ( file.length() <= 0 )
+ {
+ processFileProblem( file, "File is empty." );
+ }
+
+ if ( !file.canRead() )
+ {
+ processFileProblem( file, "Not allowed to read file due to permission settings on file." );
+ }
+
+ try
+ {
+ Artifact artifact = buildArtifact( file );
+
+ processArtifact( artifact, file );
+ }
+ catch ( BuilderException e )
+ {
+ throw new ConsumerException( file, e.getMessage(), e );
+ }
+ }
+
+ private Artifact buildArtifact( BaseFile file )
+ throws BuilderException
+ {
+ LayoutArtifactBuilder builder = (LayoutArtifactBuilder) artifactBuilders.get( layoutId );
+
+ Artifact artifact = builder.build( file.getRelativePath() );
+// artifact.setRepository( repository );
+ artifact.setFile( file );
+
+ return artifact;
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * GenericModelConsumer - consumer for pom files.
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class GenericModelConsumer
+ extends AbstractConsumer
+ implements Consumer
+{
+ public abstract void processModel( Model model, BaseFile file );
+
+ private static final List includePatterns;
+
+ static
+ {
+ includePatterns = new ArrayList();
+ includePatterns.add( "**/*.pom" );
+ }
+
+ public List getIncludePatterns()
+ {
+ return includePatterns;
+ }
+
+ public boolean isEnabled()
+ {
+ return true;
+ }
+
+ public void processFile( BaseFile file )
+ throws ConsumerException
+ {
+ Model model = buildModel( file );
+ processModel( model, file );
+ }
+
+ private Model buildModel( BaseFile file )
+ throws ConsumerException
+ {
+ Model model;
+ Reader reader = null;
+ try
+ {
+ reader = new FileReader( file );
+ MavenXpp3Reader modelReader = new MavenXpp3Reader();
+
+ model = modelReader.read( reader );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new ConsumerException( file, "Error parsing metadata file: " + e.getMessage(), e );
+ }
+ catch ( IOException e )
+ {
+ throw new ConsumerException( file, "Error reading metadata file: " + e.getMessage(), e );
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
+
+ return model;
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Metadata;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+/**
+ * GenericRepositoryMetadataConsumer - Consume any maven-metadata.xml files as {@link RepositoryMetadata} objects.
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class GenericRepositoryMetadataConsumer
+ extends AbstractConsumer
+ implements Consumer
+{
+ public abstract void processRepositoryMetadata( RepositoryMetadata metadata, BaseFile file );
+
+ private static final List includePatterns;
+
+ static
+ {
+ includePatterns = new ArrayList();
+ includePatterns.add( "**/maven-metadata.xml" );
+ }
+
+ public List getIncludePatterns()
+ {
+ return includePatterns;
+ }
+
+ public boolean isEnabled()
+ {
+ // the RepositoryMetadata objects only exist in 'default' layout repositories.
+ ArtifactRepositoryLayout layout = repository.getLayout();
+ return ( layout instanceof DefaultRepositoryLayout );
+ }
+
+ public void processFile( BaseFile file )
+ throws ConsumerException
+ {
+ if ( file.length() <= 0 )
+ {
+ throw new ConsumerException( file, "File is empty." );
+ }
+
+ if ( !file.canRead() )
+ {
+ throw new ConsumerException( file, "Not allowed to read file due to permission settings on file." );
+ }
+
+ RepositoryMetadata metadata = buildMetadata( file );
+ processRepositoryMetadata( metadata, file );
+ }
+
+ private RepositoryMetadata buildMetadata( BaseFile metadataFile )
+ throws ConsumerException
+ {
+ Metadata m;
+ Reader reader = null;
+ try
+ {
+ reader = new FileReader( metadataFile );
+ MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();
+
+ m = metadataReader.read( reader );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new ConsumerException( metadataFile, "Error parsing metadata file: " + e.getMessage(), e );
+ }
+ catch ( IOException e )
+ {
+ throw new ConsumerException( metadataFile, "Error reading metadata file: " + e.getMessage(), e );
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
+
+ RepositoryMetadata repositoryMetadata = buildMetadata( m, metadataFile );
+
+ if ( repositoryMetadata == null )
+ {
+ throw new ConsumerException( metadataFile, "Unable to build a repository metadata from path." );
+ }
+
+ return repositoryMetadata;
+ }
+
+ /**
+ * Builds a RepositoryMetadata object from a Metadata object and its path.
+ *
+ * @param m Metadata
+ * @param metadataFile file information
+ * @return RepositoryMetadata if the parameters represent one; null if not
+ * @throws ConsumerException
+ */
+ private RepositoryMetadata buildMetadata( Metadata m, BaseFile metadataFile )
+ throws ConsumerException
+ {
+ if ( artifactFactory == null )
+ {
+ throw new IllegalStateException( "Unable to build metadata with a null artifactFactory." );
+ }
+
+ String metaGroupId = m.getGroupId();
+ String metaArtifactId = m.getArtifactId();
+ String metaVersion = m.getVersion();
+
+ // check if the groupId, artifactId and version is in the
+ // metadataPath
+ // parse the path, in reverse order
+ List pathParts = new ArrayList();
+ StringTokenizer st = new StringTokenizer( metadataFile.getRelativePath(), "/\\" );
+ while ( st.hasMoreTokens() )
+ {
+ pathParts.add( st.nextToken() );
+ }
+
+ Collections.reverse( pathParts );
+ // remove the metadata file
+ pathParts.remove( 0 );
+ Iterator it = pathParts.iterator();
+ String tmpDir = (String) it.next();
+
+ Artifact artifact = null;
+ if ( StringUtils.isNotEmpty( metaVersion ) )
+ {
+ artifact = artifactFactory.createProjectArtifact( metaGroupId, metaArtifactId, metaVersion );
+ }
+
+ // snapshotMetadata
+ RepositoryMetadata metadata = null;
+ if ( tmpDir != null && tmpDir.equals( metaVersion ) )
+ {
+ if ( artifact != null )
+ {
+ metadata = new SnapshotArtifactRepositoryMetadata( artifact );
+ }
+ }
+ else if ( tmpDir != null && tmpDir.equals( metaArtifactId ) )
+ {
+ // artifactMetadata
+ if ( artifact != null )
+ {
+ metadata = new ArtifactRepositoryMetadata( artifact );
+ }
+ else
+ {
+ artifact = artifactFactory.createProjectArtifact( metaGroupId, metaArtifactId, "1.0" );
+ metadata = new ArtifactRepositoryMetadata( artifact );
+ }
+ }
+ else
+ {
+ String groupDir = "";
+ int ctr = 0;
+ for ( it = pathParts.iterator(); it.hasNext(); )
+ {
+ String path = (String) it.next();
+ if ( ctr == 0 )
+ {
+ groupDir = path;
+ }
+ else
+ {
+ groupDir = path + "." + groupDir;
+ }
+ ctr++;
+ }
+
+ // groupMetadata
+ if ( metaGroupId != null && metaGroupId.equals( groupDir ) )
+ {
+ metadata = new GroupRepositoryMetadata( metaGroupId );
+ }
+ else
+ {
+ /* If we reached this point, we have some bad metadata.
+ * We have a metadata file, with values for groupId / artifactId / version.
+ * But the information it is providing does not exist relative to the file location.
+ *
+ * See ${basedir}/src/test/repository/javax/maven-metadata.xml for example
+ */
+ throw new ConsumerException( metadataFile,
+ "Contents of metadata are not appropriate for its location on disk." );
+ }
+ }
+
+ return metadata;
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.model.ArchivaRepository;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * AbstractConsumerTestCase
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class AbstractConsumerTestCase extends PlexusTestCase
+{
+ protected ArchivaRepository getLegacyRepository() throws Exception
+ {
+ File repoBaseDir = new File( getBasedir(), "src/test/legacy-repository" );
+ ArchivaRepository repository = createRepository( repoBaseDir, "legacy" );
+ resetRepositoryState( repository );
+ return repository;
+ }
+
+ protected ArchivaRepository getDefaultRepository() throws Exception
+ {
+ File repoBaseDir = new File( getBasedir(), "src/test/repository" );
+ ArchivaRepository repository = createRepository( repoBaseDir, "default" );
+ resetRepositoryState( repository );
+ return repository;
+ }
+
+ private void resetRepositoryState( ArchivaRepository repository ) throws IOException
+ {
+ File repoBaseDir = new File( repository.getRepositoryURL().getPath() );
+
+ List tmpfiles = FileUtils.getFiles( repoBaseDir, ".*", "" );
+ for ( Iterator it = tmpfiles.iterator(); it.hasNext(); )
+ {
+ File hit = (File) it.next();
+ if ( hit.exists() )
+ {
+ if ( hit.isFile() )
+ {
+ hit.delete();
+ }
+
+ if ( hit.isDirectory() )
+ {
+ FileUtils.deleteDirectory( hit );
+ }
+ }
+ }
+ }
+
+ protected ArchivaRepository createRepository( File basedir, String layout ) throws Exception
+ {
+ ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, layout );
+
+ ArchivaRepository repo = new ArchivaRepository();
+ repo.setId( "discoveryRepo" );
+ repo.setUrl( "file://" + basedir );
+ repo.setLayout( repoLayout );
+
+ return repo;
+ }
+
+ public List getLegacyLayoutArtifactPaths()
+ {
+ List files = new ArrayList();
+
+ files.add( "invalid/jars/1.0/invalid-1.0.jar" );
+ files.add( "invalid/jars/invalid-1.0.rar" );
+ files.add( "invalid/jars/invalid.jar" );
+ files.add( "invalid/invalid-1.0.jar" );
+ files.add( "javax.sql/jars/jdbc-2.0.jar" );
+ files.add( "org.apache.maven/jars/some-ejb-1.0-client.jar" );
+ files.add( "org.apache.maven/jars/testing-1.0.jar" );
+ files.add( "org.apache.maven/jars/testing-1.0-sources.jar" );
+ files.add( "org.apache.maven/jars/testing-UNKNOWN.jar" );
+ files.add( "org.apache.maven/jars/testing-1.0.zip" );
+ files.add( "org.apache.maven/jars/testing-1.0-20050611.112233-1.jar" );
+ files.add( "org.apache.maven/jars/testing-1.0.tar.gz" );
+ files.add( "org.apache.maven.update/jars/test-not-updated-1.0.jar" );
+ files.add( "org.apache.maven.update/jars/test-updated-1.0.jar" );
+
+ return files;
+ }
+
+ public List getDefaultLayoutArtifactPaths()
+ {
+ List files = new ArrayList();
+
+ files.add( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" );
+ files.add( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar" );
+ files.add( "invalid/invalid/1.0/invalid-1.0b.jar" );
+ files.add( "invalid/invalid/1.0/invalid-2.0.jar" );
+ files.add( "invalid/invalid-1.0.jar" );
+ files.add( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar" );
+ files.add( "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1-javadoc.jar" );
+ files.add( "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar" );
+ files.add( "org/apache/maven/A/1.0/A-1.0.war" );
+ files.add( "org/apache/maven/A/1.0/A-1.0.pom" );
+ files.add( "org/apache/maven/B/2.0/B-2.0.pom" );
+ files.add( "org/apache/maven/B/1.0/B-1.0.pom" );
+ files.add( "org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar" );
+ files.add( "org/apache/maven/C/1.0/C-1.0.war" );
+ files.add( "org/apache/maven/C/1.0/C-1.0.pom" );
+ files.add( "org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.pom" );
+ files.add( "org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.jar" );
+ files.add( "org/apache/maven/update/test-updated/1.0/test-updated-1.0.pom" );
+ files.add( "org/apache/maven/update/test-updated/1.0/test-updated-1.0.jar" );
+ files.add( "org/apache/maven/discovery/1.0/discovery-1.0.pom" );
+ files.add( "org/apache/maven/testing/1.0/testing-1.0-test-sources.jar" );
+ files.add( "org/apache/maven/testing/1.0/testing-1.0.jar" );
+ files.add( "org/apache/maven/testing/1.0/testing-1.0-sources.jar" );
+ files.add( "org/apache/maven/testing/1.0/testing-1.0.zip" );
+ files.add( "org/apache/maven/testing/1.0/testing-1.0.tar.gz" );
+ files.add( "org/apache/maven/samplejar/2.0/samplejar-2.0.pom" );
+ files.add( "org/apache/maven/samplejar/2.0/samplejar-2.0.jar" );
+ files.add( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" );
+ files.add( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" );
+ files.add( "org/apache/testgroup/discovery/1.0/discovery-1.0.pom" );
+ files.add( "javax/sql/jdbc/2.0/jdbc-2.0.jar" );
+
+ return files;
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * AbstractGenericConsumerTestCase
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class AbstractGenericConsumerTestCase
+ extends AbstractConsumerTestCase
+{
+ protected ConsumerFactory consumerFactory;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ consumerFactory = (ConsumerFactory) lookup( ConsumerFactory.ROLE );
+ }
+
+ protected void tearDown()
+ throws Exception
+ {
+ if ( consumerFactory != null )
+ {
+ release( consumerFactory );
+ }
+ super.tearDown();
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * AllTests
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class AllTests
+{
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva.common.consumers" );
+ //$JUnit-BEGIN$
+ suite.addTestSuite( GenericArtifactConsumerTest.class );
+ //$JUnit-END$
+ return suite;
+ }
+
+}
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.maven.archiva.consumers.ConsumerException;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * FileProblemsTracker
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class FileProblemsTracker
+{
+ private Map problemMap = new HashMap();
+
+ public void addProblem( BaseFile file, String message )
+ {
+ String path = file.getRelativePath();
+ addProblem( path, message );
+ }
+
+ private void addProblem( String path, String message )
+ {
+ path = StringUtils.replace( path, "\\", "/" );
+ List problems = getProblems( path );
+ problems.add( message );
+ problemMap.put( path, problems );
+ }
+
+ public void addProblem( ConsumerException e )
+ {
+ if ( e.getFile() != null )
+ {
+ this.addProblem( e.getFile(), e.getMessage() );
+ }
+ else
+ {
+ this.addProblem( "|fatal|", e.getMessage() );
+ }
+ }
+
+ public boolean hasProblems( String path )
+ {
+ if ( !problemMap.containsKey( path ) )
+ {
+ // No tracking of path at all.
+ return false;
+ }
+
+ List problems = (List) problemMap.get( path );
+ if ( problems == null )
+ {
+ // found path, but no list.
+ return false;
+ }
+
+ return !problems.isEmpty();
+ }
+
+ public Set getPaths()
+ {
+ return problemMap.keySet();
+ }
+
+ public List getProblems( String path )
+ {
+ List problems = (List) problemMap.get( path );
+ if ( problems == null )
+ {
+ problems = new ArrayList();
+ }
+
+ return problems;
+ }
+
+ public int getProblemCount()
+ {
+ int count = 0;
+ for ( Iterator it = problemMap.values().iterator(); it.hasNext(); )
+ {
+ List problems = (List) it.next();
+ count += problems.size();
+ }
+
+ return count;
+ }
+
+}
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.maven.archiva.model.ArchivaRepository;
+import org.apache.maven.artifact.Artifact;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * GenericArtifactConsumerTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class GenericArtifactConsumerTest
+ extends AbstractGenericConsumerTestCase
+{
+ private MockArtifactConsumer getMockArtifactConsumer()
+ throws Exception
+ {
+ return (MockArtifactConsumer) consumerFactory.createConsumer( "mock-artifact" );
+ }
+
+ public void testScanLegacy()
+ throws Exception
+ {
+ ArchivaRepository repository = getLegacyRepository();
+ List consumers = new ArrayList();
+
+ MockArtifactConsumer mockConsumer = getMockArtifactConsumer();
+ mockConsumer.init( repository );
+
+ consumers.add( mockConsumer );
+
+ List files = getLegacyLayoutArtifactPaths();
+ for ( Iterator it = files.iterator(); it.hasNext(); )
+ {
+ String path = (String) it.next();
+ try
+ {
+ mockConsumer.processFile( new BaseFile( repository.getRepositoryURL().getPath(), path ) );
+ }
+ catch ( ConsumerException e )
+ {
+ mockConsumer.getProblemsTracker().addProblem( e );
+ }
+ }
+
+ assertNotNull( consumers );
+
+ FileProblemsTracker tracker = mockConsumer.getProblemsTracker();
+
+ assertTracker( tracker, 16 );
+
+ assertHasFailureMessage( "Path does not match a legacy repository path for an artifact",
+ "invalid/invalid-1.0.jar", tracker );
+ assertHasFailureMessage( "Path filename version is empty", "invalid/jars/invalid.jar", tracker );
+ assertHasFailureMessage( "Path does not match a legacy repository path for an artifact",
+ "invalid/jars/1.0/invalid-1.0.jar", tracker );
+
+ assertEquals( 10, mockConsumer.getArtifactMap().size() );
+ }
+
+ public void testScanDefault()
+ throws Exception
+ {
+ ArchivaRepository repository = getDefaultRepository();
+ List consumers = new ArrayList();
+
+ MockArtifactConsumer mockConsumer = getMockArtifactConsumer();
+ mockConsumer.init( repository );
+
+ consumers.add( mockConsumer );
+
+ List files = getDefaultLayoutArtifactPaths();
+ for ( Iterator it = files.iterator(); it.hasNext(); )
+ {
+ String path = (String) it.next();
+ try
+ {
+ mockConsumer.processFile( new BaseFile( repository.getRepositoryURL().getPath(), path ) );
+ }
+ catch ( ConsumerException e )
+ {
+ mockConsumer.getProblemsTracker().addProblem( e );
+ }
+ }
+
+ // Test gathered information from Mock consumer.
+
+ assertNotNull( consumers );
+
+ FileProblemsTracker tracker = mockConsumer.getProblemsTracker();
+
+ assertTracker( tracker, 21 );
+
+ assertHasFailureMessage( "Failed to create a snapshot artifact: invalid:invalid:jar:1.0:runtime",
+ "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", tracker );
+ assertHasFailureMessage( "Path is too short to build an artifact from.", "invalid/invalid-1.0.jar", tracker );
+ assertHasFailureMessage( "Built artifact version does not match path version",
+ "invalid/invalid/1.0/invalid-2.0.jar", tracker );
+
+ assertEquals( 25, mockConsumer.getArtifactMap().size() );
+
+ // Test for known include artifacts
+
+ Collection artifacts = mockConsumer.getArtifactMap().values();
+ assertHasArtifact( "org.apache.maven", "testing", "1.0", "jar", null, artifacts );
+ assertHasArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client", artifacts );
+ assertHasArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources", artifacts );
+ assertHasArtifact( "org.apache.maven", "testing", "1.0", "java-source", "test-sources", artifacts );
+ assertHasArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip", null, artifacts );
+ assertHasArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz", null, artifacts );
+ assertHasArtifact( "javax.sql", "jdbc", "2.0", "jar", null, artifacts );
+ assertHasArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1", "jar", null, artifacts );
+ assertHasArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1", "jar", "javadoc", artifacts );
+
+ // Test for known excluded files and dirs to validate exclusions.
+
+ Iterator it = mockConsumer.getArtifactMap().values().iterator();
+ while ( it.hasNext() )
+ {
+ Artifact a = (Artifact) it.next();
+ assertTrue( "Artifact " + a + " should have it's .getFile() set.", a.getFile() != null );
+ assertTrue( "Artifact " + a + " should have it's .getRepository() set.", a.getRepository() != null );
+ assertTrue( "Artifact " + a + " should have non-null repository url.", a.getRepository().getUrl() != null );
+ assertFalse( "Check not CVS", a.getFile().getPath().indexOf( "CVS" ) >= 0 );
+ assertFalse( "Check not .svn", a.getFile().getPath().indexOf( ".svn" ) >= 0 );
+ }
+ }
+
+ private void dumpProblems( FileProblemsTracker tracker )
+ {
+ int problemNum = 0;
+ System.out.println( "-- ProblemTracker dump -------------------------" );
+ for ( Iterator itPaths = tracker.getPaths().iterator(); itPaths.hasNext(); )
+ {
+ String path = (String) itPaths.next();
+ System.out.println( " [" + problemNum + "]: " + path );
+
+ int messageNum = 0;
+ for ( Iterator itProblems = tracker.getProblems( path ).iterator(); itProblems.hasNext(); )
+ {
+ String message = (String) itProblems.next();
+ System.out.println( " [" + messageNum + "]: " + message );
+ messageNum++;
+ }
+
+ problemNum++;
+ }
+ }
+
+ private void assertTracker( FileProblemsTracker tracker, int expectedProblemCount )
+ {
+ assertNotNull( "ProblemsTracker should not be null.", tracker );
+
+ int actualProblemCount = tracker.getProblemCount();
+ if ( expectedProblemCount != actualProblemCount )
+ {
+ dumpProblems( tracker );
+ fail( "Problem count (across all paths) expected:<" + expectedProblemCount + ">, actual:<"
+ + actualProblemCount + ">" );
+ }
+ }
+
+ private void assertHasFailureMessage( String message, String path, FileProblemsTracker tracker )
+ {
+ if ( !tracker.hasProblems( path ) )
+ {
+ fail( "There are no messages for expected path [" + path + "]" );
+ }
+
+ assertTrue( "Unable to find message [" + message + "] in path [" + path + "]", tracker.getProblems( path )
+ .contains( message ) );
+ }
+
+ private void assertHasArtifact( String groupId, String artifactId, String version, String type, String classifier,
+ Collection collection )
+ {
+ for ( Iterator it = collection.iterator(); it.hasNext(); )
+ {
+ Artifact artifact = (Artifact) it.next();
+ if ( StringUtils.equals( groupId, artifact.getGroupId() )
+ && StringUtils.equals( artifactId, artifact.getArtifactId() )
+ && StringUtils.equals( version, artifact.getVersion() )
+ && StringUtils.equals( type, artifact.getType() )
+ && StringUtils.equals( classifier, artifact.getClassifier() ) )
+ {
+ // Found it!
+ return;
+ }
+ }
+
+ fail( "Was unable to find artifact " + groupId + ":" + artifactId + ":" + version + ":" + type + ":"
+ + classifier );
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.maven.archiva.common.utils.PathUtil;
+import org.apache.maven.artifact.Artifact;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * MockArtifactConsumer
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.common.consumers.Consumers"
+ * role-hint="mock-artifact"
+ * instantiation-strategy="per-lookup"
+ */
+public class MockArtifactConsumer
+ extends GenericArtifactConsumer
+{
+ private Map artifactMap = new HashMap();
+
+ private FileProblemsTracker problemsTracker = new FileProblemsTracker();
+
+ public void processArtifact( Artifact artifact, BaseFile file )
+ {
+ String relpath = PathUtil.getRelative( repository.getRepositoryURL().getPath(), file );
+ artifactMap.put( relpath, artifact );
+ }
+
+ public void processFileProblem( BaseFile file, String message )
+ {
+ problemsTracker.addProblem( file, message );
+ }
+
+ public Map getArtifactMap()
+ {
+ return artifactMap;
+ }
+
+ public String getName()
+ {
+ return "Mock Artifact Consumer (Testing Only)";
+ }
+
+ public FileProblemsTracker getProblemsTracker()
+ {
+ return problemsTracker;
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.maven.archiva.consumers.GenericModelConsumer;
+import org.apache.maven.model.Model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * MockModelConsumer
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.common.consumers.Consumers"
+ * role-hint="mock-model"
+ * instantiation-strategy="per-lookup"
+ */
+public class MockModelConsumer
+ extends GenericModelConsumer
+{
+ private Map modelMap = new HashMap();
+
+ private FileProblemsTracker problemsTracker = new FileProblemsTracker();
+
+ public void processModel( Model model, BaseFile file )
+ {
+ modelMap.put( file.getRelativePath(), model );
+ }
+
+ public void processFileProblem( BaseFile file, String message )
+ {
+ problemsTracker.addProblem( file, message );
+ }
+
+ public Map getModelMap()
+ {
+ return modelMap;
+ }
+
+ public String getName()
+ {
+ return "Mock Model Consumer (Testing Only)";
+ }
+
+ public FileProblemsTracker getProblemsTracker()
+ {
+ return problemsTracker;
+ }
+
+}
\ No newline at end of file
--- /dev/null
+package org.apache.maven.archiva.consumers;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.maven.archiva.consumers.GenericRepositoryMetadataConsumer;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * MockRepositoryMetadataConsumer
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.common.consumers.Consumers"
+ * role-hint="mock-metadata"
+ * instantiation-strategy="per-lookup"
+ */
+public class MockRepositoryMetadataConsumer
+ extends GenericRepositoryMetadataConsumer
+{
+ private Map repositoryMetadataMap = new HashMap();
+
+ private FileProblemsTracker problemsTracker = new FileProblemsTracker();
+
+ public void processRepositoryMetadata( RepositoryMetadata metadata, BaseFile file )
+ {
+ repositoryMetadataMap.put( file.getRelativePath(), metadata );
+ }
+
+ public void processFileProblem( BaseFile file, String message )
+ {
+ problemsTracker.addProblem( file, message );
+ }
+
+ public Map getRepositoryMetadataMap()
+ {
+ return repositoryMetadataMap;
+ }
+
+ public String getName()
+ {
+ return "Mock RepositoryMetadata Consumer (Testing Only)";
+ }
+
+ public FileProblemsTracker getProblemsTracker()
+ {
+ return problemsTracker;
+ }
+}
\ No newline at end of file
<artifactId>archiva-converter</artifactId>
<name>Archiva Repository Converter</name>
<dependencies>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-consumer-api</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-discoverer</artifactId>
* under the License.
*/
-import org.apache.maven.archiva.common.consumers.GenericArtifactConsumer;
import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.maven.archiva.consumers.GenericArtifactConsumer;
import org.apache.maven.archiva.converter.ConversionListener;
import org.apache.maven.archiva.converter.RepositoryConversionException;
import org.apache.maven.archiva.converter.RepositoryConverter;
<artifactId>archiva-core</artifactId>
<name>Archiva Core</name>
<dependencies>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-consumer-api</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-configuration</artifactId>
* under the License.
*/
-import org.apache.maven.archiva.common.consumers.GenericArtifactConsumer;
import org.apache.maven.archiva.common.utils.BaseFile;
import org.apache.maven.archiva.reporting.database.ArtifactResultsDatabase;
import org.apache.maven.archiva.reporting.group.ReportGroup;
* under the License.
*/
-import org.apache.maven.archiva.common.consumers.GenericArtifactConsumer;
import org.apache.maven.archiva.common.utils.BaseFile;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
* under the License.
*/
-import org.apache.maven.archiva.common.consumers.GenericRepositoryMetadataConsumer;
import org.apache.maven.archiva.common.utils.BaseFile;
import org.apache.maven.archiva.reporting.database.MetadataResultsDatabase;
import org.apache.maven.archiva.reporting.group.ReportGroup;
* under the License.
*/
-import org.apache.maven.archiva.common.consumers.Consumer;
-import org.apache.maven.archiva.common.consumers.ConsumerException;
-import org.apache.maven.archiva.common.consumers.ConsumerFactory;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ConfiguredRepositoryFactory;
import org.apache.maven.archiva.configuration.RepositoryConfiguration;
+import org.apache.maven.archiva.consumers.Consumer;
+import org.apache.maven.archiva.consumers.ConsumerException;
+import org.apache.maven.archiva.consumers.ConsumerFactory;
import org.apache.maven.archiva.discoverer.Discoverer;
import org.apache.maven.archiva.discoverer.DiscovererException;
import org.apache.maven.archiva.discoverer.DiscovererStatistics;
<name>Archiva Database</name>
<dependencies>
<dependency>
- <groupId>org.apache.ibatis</groupId>
- <artifactId>ibatis-sqlmap</artifactId>
- <version>2.3.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-artifact-manager</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-project</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-repository-metadata</artifactId>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-model</artifactId>
+ <version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-ibatis</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <artifactId>plexus-jdo2</artifactId>
+ <version>1.0-alpha-8</version>
+ <exclusions>
+ <exclusion>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xerces</groupId>
+ <artifactId>xmlParserAPIs</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-utils</artifactId>
+ <groupId>jpox</groupId>
+ <artifactId>jpox</artifactId>
+ <version>1.1.7</version>
+ <scope>compile</scope>
+ <exclusions>
+ <!-- targeting JDK 1.4 we don't need this -->
+ <exclusion>
+ <groupId>javax.sql</groupId>
+ <artifactId>jdbc-stdext</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
+++ /dev/null
-package org.apache.maven.archiva.database;
-
-/*
- * 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.
- */
-
-import com.ibatis.sqlmap.client.SqlMapClient;
-
-import org.codehaus.plexus.ibatis.PlexusIbatisHelper;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-/**
- * AbstractIbatisStore
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public abstract class AbstractIbatisStore
- extends AbstractLogEnabled
- implements Initializable
-{
- /**
- * @plexus.requirement
- */
- protected PlexusIbatisHelper ibatisHelper;
-
- /**
- * @plexus.configuration default-value="create"
- */
- private String createPrefix;
-
- /**
- * @plexus.configuration default-value="drop"
- */
- private String dropPrefix;
-
- protected abstract String[] getTableNames();
-
- public void initialize()
- throws InitializationException
- {
- try
- {
- String tableNames[] = getTableNames();
- for ( int i = 0; i < tableNames.length; i++ )
- {
- String tableName = tableNames[i];
- initializeTable( tableName );
- }
- }
- catch ( ArchivaDatabaseException e )
- {
- throw new InitializationException( "Unable to initialize the database: " + e.getMessage(), e );
- }
- }
-
- protected void initializeTable( String tableName )
- throws ArchivaDatabaseException
- {
- SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
-
- try
- {
- sqlMap.startTransaction();
-
- Connection con = sqlMap.getCurrentConnection();
-
- DatabaseMetaData databaseMetaData = con.getMetaData();
-
- ResultSet rs = databaseMetaData.getTables( con.getCatalog(), null, null, null );
-
- // check if the index database exists in the database
- while ( rs.next() )
- {
- String dbTableName = rs.getString( "TABLE_NAME" );
-
- // if it does then we are already initialized
- if ( dbTableName.toLowerCase().equals( tableName.toLowerCase() ) )
- {
- return;
- }
- }
-
- // Create the tables
-
- getLogger().info( "Creating table: " + tableName );
- sqlMap.update( createPrefix + tableName, null );
-
- sqlMap.commitTransaction();
- }
- catch ( SQLException e )
- {
- getLogger().error( "Error while initializing database, showing all linked exceptions in SQLException." );
-
- while ( e != null )
- {
- getLogger().error( e.getMessage(), e );
-
- e = e.getNextException();
- }
-
- throw new ArchivaDatabaseException( "Error while setting up database.", e );
- }
- finally
- {
- try
- {
- sqlMap.endTransaction();
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- }
- }
- }
-
- protected void dropTable( String tableName )
- throws ArchivaDatabaseException
- {
- SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
-
- try
- {
- sqlMap.startTransaction();
-
- getLogger().info( "Dropping table: " + tableName );
- sqlMap.update( dropPrefix + tableName, null );
-
- sqlMap.commitTransaction();
- }
- catch ( SQLException e )
- {
- getLogger().error( "Error while dropping database, showing all linked exceptions in SQLException." );
-
- while ( e != null )
- {
- getLogger().error( e.getMessage(), e );
-
- e = e.getNextException();
- }
-
- throw new ArchivaDatabaseException( "Error while dropping database.", e );
- }
- finally
- {
- try
- {
- sqlMap.endTransaction();
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- }
- }
- }
-
-
-}
+++ /dev/null
-package org.apache.maven.archiva.database;
-
-
-/*
- * 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.
- */
-
-import com.ibatis.sqlmap.client.SqlMapClient;
-
-import org.apache.maven.archiva.database.key.MetadataKey;
-import org.apache.maven.artifact.repository.metadata.Metadata;
-import org.codehaus.plexus.ibatis.PlexusIbatisHelper;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-
-/**
- *
- * IbatisMetadataStore
- *
- * @author <a href="mailto:jmcconnell@apache.com">Jesse McConnell</a>
- * @version $Id$
- *
- */
-public class AbstractMetadataKeyDatabase
- extends AbstractLogEnabled
- implements Initializable
-{
- /**
- * @plexus.requirement
- */
- protected PlexusIbatisHelper ibatisHelper;
-
- /**
- * @plexus.configuration default-value="create"
- */
- private String createPrefix;
-
- /**
- * @plexus.configuration default-value="drop"
- */
- private String dropPrefix;
-
- public MetadataKey getMetadataKey( Metadata metadata )
- throws ArchivaDatabaseException
- {
- SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
-
- try
- {
- sqlMap.startTransaction();
-
- getLogger().info( "Getting metadata key" );
- MetadataKey newMetadataKey = (MetadataKey) sqlMap.queryForObject( "getMetadataKey", metadata );
-
- if ( newMetadataKey == null )
- {
- getLogger().info( "added new metadata" );
- sqlMap.update( "addMetadataKey", metadata );
-
- newMetadataKey = (MetadataKey) sqlMap.queryForObject( "getMetadataKey", metadata );
-
- if ( newMetadataKey == null )
- {
- throw new ArchivaDatabaseException( "unable to create new MetadataKeys" );
- }
- }
-
- return newMetadataKey;
-
- }
- catch ( SQLException e )
- {
- getLogger().error( "Error while adding metadata, showing all linked exceptions in SQLException." );
-
- while ( e != null )
- {
- getLogger().error( e.getMessage(), e );
-
- e = e.getNextException();
- }
-
- throw new ArchivaDatabaseException ( "Error while interacting with the database.", e );
- }
- finally
- {
- try
- {
- sqlMap.endTransaction();
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- }
- }
- }
-
-
- protected void initializeTable( String tableName )
- throws ArchivaDatabaseException
- {
- SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
-
- try
- {
- sqlMap.startTransaction();
-
- Connection con = sqlMap.getCurrentConnection();
-
- DatabaseMetaData databaseMetaData = con.getMetaData();
-
- ResultSet rs = databaseMetaData.getTables( con.getCatalog(), null, null, null );
-
- // check if the index database exists in the database
- while ( rs.next() )
- {
- String dbTableName = rs.getString( "TABLE_NAME" );
-
- // if it does then we are already initialized
- if ( dbTableName.toLowerCase().equals( tableName.toLowerCase() ) )
- {
- return;
- }
- }
-
- // Create the tables
-
- getLogger().info( "Creating table: " + tableName );
- sqlMap.update( createPrefix + tableName, null );
-
- sqlMap.commitTransaction();
- }
- catch ( SQLException e )
- {
- getLogger().error( "Error while initializing database, showing all linked exceptions in SQLException." );
-
- while ( e != null )
- {
- getLogger().error( e.getMessage(), e );
-
- e = e.getNextException();
- }
-
- throw new ArchivaDatabaseException( "Error while setting up database.", e );
- }
- finally
- {
- try
- {
- sqlMap.endTransaction();
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- }
- }
- }
-
- protected void dropTable( String tableName )
- throws ArchivaDatabaseException
- {
- SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
-
- try
- {
- sqlMap.startTransaction();
-
- getLogger().info( "Dropping table: " + tableName );
- sqlMap.update( dropPrefix + tableName, null );
-
- sqlMap.commitTransaction();
- }
- catch ( SQLException e )
- {
- getLogger().error( "Error while dropping database, showing all linked exceptions in SQLException." );
-
- while ( e != null )
- {
- getLogger().error( e.getMessage(), e );
-
- e = e.getNextException();
- }
-
- throw new ArchivaDatabaseException( "Error while dropping database.", e );
- }
- finally
- {
- try
- {
- sqlMap.endTransaction();
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- }
- }
-}
-
- public void initialize()
- throws InitializationException
- {
- try
- {
- initializeTable( "MetadataKeys" );
- }
- catch ( ArchivaDatabaseException ade )
- {
- throw new InitializationException( "unable to initialize metadata keys database" );
- }
- }
-
-
- protected boolean tableExists( String tableName )
- throws ArchivaDatabaseException
-{
- SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
-
- try
- {
- sqlMap.startTransaction();
-
- Connection con = sqlMap.getCurrentConnection();
-
- DatabaseMetaData databaseMetaData = con.getMetaData();
-
- ResultSet rs = databaseMetaData.getTables( con.getCatalog(), null, null, null );
-
- // check if the index database exists in the database
- while ( rs.next() )
- {
- String dbTableName = rs.getString( "TABLE_NAME" );
-
- // if it does then we are already initialized
- if ( dbTableName.toLowerCase().equals( tableName.toLowerCase() ) )
- {
- return true;
- }
- }
- return false;
- }
- catch ( SQLException e )
- {
- getLogger().error( "Error while check database, showing all linked exceptions in SQLException." );
-
- while ( e != null )
- {
- getLogger().error( e.getMessage(), e );
-
- e = e.getNextException();
- }
-
- throw new ArchivaDatabaseException( "Error while checking database.", e );
- }
- finally
- {
- try
- {
- sqlMap.endTransaction();
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- }
- }
-}
-
-}
--- /dev/null
+package org.apache.maven.archiva.database;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.model.ArchivaRepository;
+import org.apache.maven.archiva.model.RepositoryContent;
+
+import java.util.List;
+
+/**
+ * ArchivaDAO - The interface for all content within the database.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface ArchivaDAO
+{
+ /* NOTE TO ARCHIVA DEVELOPERS.
+ *
+ * Please keep this interface clean and lean.
+ * We don't want a repeat of the Continuum Store.
+ * You should have the following methods per object type ...
+ *
+ * (Required Methods)
+ *
+ * DatabaseObject .createDatabaseObject( Required Params ) ;
+ * List .queryDatabaseObject( Constraint ) throws ObjectNotFoundException, DatabaseException;
+ * DatabaseObject .saveDatabaseObject( DatabaseObject ) throws DatabaseException;
+ *
+ * (Optional Methods)
+ *
+ * DatabaseObject .getDatabaseObject( Id ) throws ObjectNotFoundException, DatabaseException;
+ * List .getDatabaseObjects() throws ObjectNotFoundException, DatabaseException;
+ * void .deleteDatabaseObject( DatabaseObject ) throws DatabaseException;
+ *
+ * This is the only list of options created in this DAO.
+ */
+
+ /* .\ Archiva Repository \.____________________________________________________________ */
+
+ public ArchivaRepository createRepository( String id, String url );
+
+ public List /*<ArchivaRepository>*/getRepositories()
+ throws ObjectNotFoundException, ArchivaDatabaseException;
+
+ public ArchivaRepository getRepository( String id )
+ throws ObjectNotFoundException, ArchivaDatabaseException;
+
+ public List queryRepository( Constraint constraint )
+ throws ObjectNotFoundException, ArchivaDatabaseException;
+
+ public ArchivaRepository saveRepository( ArchivaRepository repository )
+ throws ArchivaDatabaseException;
+
+ public void deleteRepository( ArchivaRepository repository )
+ throws ArchivaDatabaseException;
+
+ /* .\ Repository Content \.____________________________________________________________ */
+
+ public RepositoryContent createRepositoryContent( String groupId, String artifactId, String version,
+ String repositoryId );
+
+ public RepositoryContent getRepositoryContent( String groupId, String artifactId, String version,
+ String repositoryId )
+ throws ObjectNotFoundException, ArchivaDatabaseException;
+
+ public List /*<RepositoryContent>*/queryRepositoryContents( Constraint constraint )
+ throws ObjectNotFoundException, ArchivaDatabaseException;
+
+ public RepositoryContent saveRepositoryContent( RepositoryContent repoContent )
+ throws ArchivaDatabaseException;
+
+ public void deleteRepositoryContent( RepositoryContent repoContent )
+ throws ArchivaDatabaseException;
+
+ /* .\ Archiva Artifact \. _____________________________________________________________ */
+
+ public ArchivaArtifact createArtifact( RepositoryContent repoContent, String classifier, String type );
+
+ public ArchivaArtifact getArtifact( RepositoryContent repoContent, String classifier, String type )
+ throws ObjectNotFoundException, ArchivaDatabaseException;
+
+ public List /*<ArchivaArtifact>*/queryArtifacts( Constraint constraint )
+ throws ObjectNotFoundException, ArchivaDatabaseException;
+
+ public ArchivaArtifact saveArtifact( ArchivaArtifact artifact )
+ throws ArchivaDatabaseException;
+
+ public void deleteArtifact( ArchivaArtifact artifact )
+ throws ArchivaDatabaseException;
+
+}
--- /dev/null
+package org.apache.maven.archiva.database;
+
+/**
+ * Constraint
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface Constraint
+{
+ public static final String ASCENDING = "ascending";
+
+ public static final String DESCENDING = "descending";
+
+ /**
+ * Get the fetch limits on the object.
+ *
+ * @return the fetch limits on the object. (can be null) (O/RM specific)
+ */
+ public String getFetchLimits();
+
+ /**
+ * Get the SELECT WHERE (condition) value for the constraint.
+ *
+ * @return the equivalent of the SELECT WHERE (condition) value for this constraint. (can be null)
+ */
+ public String getWhereCondition();
+
+ /**
+ * Get the sort column name.
+ *
+ * @return the sort column name. (can be null)
+ */
+ public String getSortColumn();
+
+ /**
+ * Get the sort direction name.
+ *
+ * @return the sort direction name. ("ASC" or "DESC") (only valid if {@link #getSortColumn()} is specified.)
+ */
+ public String getSortDirection();
+}
--- /dev/null
+package org.apache.maven.archiva.database;
+
+/*
+ * 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.
+ */
+
+/**
+ * ObjectNotFoundException
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ObjectNotFoundException
+ extends ArchivaDatabaseException
+{
+ private Object id;
+
+ public ObjectNotFoundException( String message, Throwable cause, Object id )
+ {
+ super( message, cause );
+ this.id = id;
+ }
+
+ public ObjectNotFoundException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public ObjectNotFoundException( String message )
+ {
+ super( message );
+ }
+
+ public Object getId()
+ {
+ return id;
+ }
+}
+++ /dev/null
-package org.apache.maven.archiva.database;
-
-/*
- * 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.
- */
-
-import com.ibatis.sqlmap.client.SqlMapClient;
-
-import org.apache.maven.archiva.database.key.MetadataKey;
-import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
-
-import java.sql.SQLException;
-
-/**
- * RepositoryMetadataDatabase
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- *
- * @plexus.component role="org.apache.maven.archiva.database.RepositoryMetadataDatabase" role-hint="default"
- */
-public class RepositoryMetadataDatabase extends AbstractMetadataKeyDatabase
-{
- public void create( RepositoryMetadata metadata )
- throws ArchivaDatabaseException
- {
-
- SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
-
- try
- {
- sqlMap.startTransaction();
-
- getLogger().info( "Adding repository metadata" );
- sqlMap.update( "addRepositoryMetadata", metadata );
-
- sqlMap.commitTransaction();
- }
- catch ( SQLException e )
- {
- getLogger().error( "Error while executing statement, showing all linked exceptions in SQLException." );
-
- while ( e != null )
- {
- getLogger().error( e.getMessage(), e );
-
- e = e.getNextException();
- }
-
- throw new ArchivaDatabaseException( "Error while executing statement.", e );
- }
- finally
- {
- try
- {
- sqlMap.endTransaction();
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- }
- }
- }
-
-
- public RepositoryMetadata read( String groupId, String artifactId, String version )
- throws ArchivaDatabaseException
- {
-
- SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
-
- try
- {
- sqlMap.startTransaction();
-
- getLogger().info( "Reading repository metadata" );
- RepositoryMetadata repositoryMetadata = (RepositoryMetadata) sqlMap.queryForObject( "getRepositoryMetadata", new MetadataKey( groupId, artifactId, version ) );
-
- return repositoryMetadata;
- }
- catch ( SQLException e )
- {
- getLogger().error( "Error while executing statement, showing all linked exceptions in SQLException." );
-
- while ( e != null )
- {
- getLogger().error( e.getMessage(), e );
-
- e = e.getNextException();
- }
-
- throw new ArchivaDatabaseException( "Error while executing statement.", e );
- }
- finally
- {
- try
- {
- sqlMap.endTransaction();
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- }
- }
- }
-
- /**
- * not implemented yet
- *
- * @param metadata
- * @throws ArchivaDatabaseException
- */
- public void update( RepositoryMetadata metadata )
- throws ArchivaDatabaseException
- {
-
- SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
-
- try
- {
- sqlMap.startTransaction();
-
- getLogger().info( "Updating repository metadata" );
- sqlMap.update( "updateRepositoryMetadata", metadata );
-
- sqlMap.commitTransaction();
- }
- catch ( SQLException e )
- {
- getLogger().error( "Error while executing statement, showing all linked exceptions in SQLException." );
-
- while ( e != null )
- {
- getLogger().error( e.getMessage(), e );
-
- e = e.getNextException();
- }
-
- throw new ArchivaDatabaseException( "Error while executing statement.", e );
- }
- finally
- {
- try
- {
- sqlMap.endTransaction();
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- }
- }
- }
-
- public void delete( RepositoryMetadata metadata )
- throws ArchivaDatabaseException
- {
- // FIXME is this right? baseVersion seems wrong but I don't know enough about the metadata to say
- delete( metadata.getGroupId(), metadata.getArtifactId(), metadata.getBaseVersion() );
- }
-
- public void delete( String groupId, String artifactId, String version )
- throws ArchivaDatabaseException
- {
- SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
-
- try
- {
- sqlMap.startTransaction();
-
- getLogger().info( "Removing repository metadata" );
- sqlMap.update( "removeRepositoryMetadata", new MetadataKey( groupId, artifactId, version ) );
-
- sqlMap.commitTransaction();
- }
- catch ( SQLException e )
- {
- getLogger().error( "Error while executing statement, showing all linked exceptions in SQLException." );
-
- while ( e != null )
- {
- getLogger().error( e.getMessage(), e );
-
- e = e.getNextException();
- }
-
- throw new ArchivaDatabaseException( "Error while executing statement.", e );
- }
- finally
- {
- try
- {
- sqlMap.endTransaction();
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- }
- }
- }
-
- public void initialize()
- throws InitializationException
- {
- super.initialize();
- try
- {
- initializeTable( "RepositoryMetadata" );
- }
- catch ( ArchivaDatabaseException ade )
- {
- throw new InitializationException( "unable to initialize repository metadata table", ade );
- }
- }
-
-
-}
+++ /dev/null
-package org.apache.maven.archiva.database.artifact;
-
-/*
- * 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.
- */
-
-/**
- * ArtifactKey
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class ArtifactKey
-{
- private String groupId;
-
- private String artifactId;
-
- private String version;
-
- private String classifier;
-
- private String type;
-
- private long id;
-
- public String getArtifactId()
- {
- return artifactId;
- }
-
- public void setArtifactId( String artifactId )
- {
- this.artifactId = artifactId;
- }
-
- public String getClassifier()
- {
- return classifier;
- }
-
- public void setClassifier( String classifier )
- {
- this.classifier = classifier;
- }
-
- public String getGroupId()
- {
- return groupId;
- }
-
- public void setGroupId( String groupId )
- {
- this.groupId = groupId;
- }
-
- public long getId()
- {
- return id;
- }
-
- public void setId( long id )
- {
- this.id = id;
- }
-
- public String getType()
- {
- return type;
- }
-
- public void setType( String type )
- {
- this.type = type;
- }
-
- public String getVersion()
- {
- return version;
- }
-
- public void setVersion( String version )
- {
- this.version = version;
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.database.artifact;
-
-/*
- * 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.
- */
-
-import com.ibatis.sqlmap.client.SqlMapClient;
-
-import org.apache.maven.archiva.database.AbstractIbatisStore;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.artifact.Artifact;
-
-import java.sql.SQLException;
-
-/**
- * ArtifactPersistence
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- *
- * @plexus.component role="org.apache.maven.archiva.database.artifact.ArtifactPersistence"
- */
-public class ArtifactPersistence
- extends AbstractIbatisStore
-{
- protected String[] getTableNames()
- {
- return new String[] { "ArtifactKeys" };
- }
-
- private ArtifactKey toKey( Artifact artifact )
- {
- ArtifactKey key = new ArtifactKey();
- key.setGroupId( artifact.getGroupId() );
- key.setArtifactId( artifact.getArtifactId() );
- key.setVersion( artifact.getVersion() );
- key.setClassifier( artifact.getClassifier() );
- key.setType( artifact.getType() );
- return key;
- }
-
- public void create( Artifact artifact )
- throws ArchivaDatabaseException
- {
- SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
-
- try
- {
- sqlMap.startTransaction();
-
- getLogger().info( "Adding artifact." );
- sqlMap.update( "addArtifact", artifact );
-
- sqlMap.commitTransaction();
- }
- catch ( SQLException e )
- {
- getLogger().error( "Error while executing statement, showing all linked exceptions in SQLException." );
-
- while ( e != null )
- {
- getLogger().error( e.getMessage(), e );
-
- e = e.getNextException();
- }
-
- throw new ArchivaDatabaseException( "Error while executing statement.", e );
- }
- finally
- {
- try
- {
- sqlMap.endTransaction();
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- }
- }
- }
-
- public Artifact read( String groupId, String artifactId, String version )
- {
- return null;
- }
-
- public Artifact read( String groupId, String artifactId, String version, String type )
- {
- return null;
- }
-
- public Artifact read( String groupId, String artifactId, String version, String classifier, String type )
- {
- return null;
- }
-
- public void update( Artifact artifact )
- {
-
- }
-
- public void delete( Artifact artifact )
- {
-
- }
-
- public void delete( String groupId, String artifactId, String version )
- {
-
- }
-
- public void delete( String groupId, String artifactId, String version, String type )
- {
-
- }
-
- public void delete( String groupId, String artifactId, String version, String classifier, String type )
- {
-
- }
-
-}
--- /dev/null
+package org.apache.maven.archiva.database.constraints;
+
+import org.apache.maven.archiva.database.Constraint;
+
+/**
+ * ArchivaRepositoryByUrlConstraint
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ArchivaRepositoryByUrlConstraint
+ implements Constraint
+{
+ private String whereCondition;
+
+ public ArchivaRepositoryByUrlConstraint( String url )
+ {
+ whereCondition = "this.url == '" + url + "'";
+ }
+
+ public String getWhereCondition()
+ {
+ return whereCondition;
+ }
+
+ public String getFetchLimits()
+ {
+ return null;
+ }
+
+ public String getSortColumn()
+ {
+ return "url";
+ }
+
+ public String getSortDirection()
+ {
+ return Constraint.ASCENDING;
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.database.jdo;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
+import org.apache.maven.archiva.database.Constraint;
+import org.apache.maven.archiva.database.ObjectNotFoundException;
+import org.codehaus.plexus.jdo.JdoFactory;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+
+import java.io.PrintStream;
+import java.util.List;
+
+import javax.jdo.Extent;
+import javax.jdo.JDOException;
+import javax.jdo.JDOHelper;
+import javax.jdo.JDOObjectNotFoundException;
+import javax.jdo.JDOUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+import javax.jdo.datastore.DataStoreCache;
+import javax.jdo.listener.InstanceLifecycleEvent;
+import javax.jdo.listener.InstanceLifecycleListener;
+import javax.jdo.listener.StoreLifecycleListener;
+import javax.jdo.spi.Detachable;
+import javax.jdo.spi.PersistenceCapable;
+
+/**
+ * JdoAccess
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class JdoAccess
+ implements Initializable, InstanceLifecycleListener, StoreLifecycleListener
+{
+ /**
+ * @plexus.requirement role-hint="users"
+ */
+ private JdoFactory jdoFactory;
+
+ private PersistenceManagerFactory pmf;
+
+ public void initialize()
+ throws InitializationException
+ {
+ pmf = jdoFactory.getPersistenceManagerFactory();
+
+ pmf.addInstanceLifecycleListener( this, null );
+ }
+
+ public static void dumpObjectState( PrintStream out, Object o )
+ {
+ final String STATE = "[STATE] ";
+ final String INDENT = " ";
+
+ if ( o == null )
+ {
+ out.println( STATE + "Object is null." );
+ return;
+ }
+
+ out.println( STATE + "Object " + o.getClass().getName() );
+
+ if ( !( o instanceof PersistenceCapable ) )
+ {
+ out.println( INDENT + "is NOT PersistenceCapable (not a jdo object?)" );
+ return;
+ }
+
+ out.println( INDENT + "is PersistenceCapable." );
+ if ( o instanceof Detachable )
+ {
+ out.println( INDENT + "is Detachable" );
+ }
+
+ out.println( INDENT + "is new : " + Boolean.toString( JDOHelper.isNew( o ) ) );
+ out.println( INDENT + "is transactional : " + Boolean.toString( JDOHelper.isTransactional( o ) ) );
+ out.println( INDENT + "is deleted : " + Boolean.toString( JDOHelper.isDeleted( o ) ) );
+ out.println( INDENT + "is detached : " + Boolean.toString( JDOHelper.isDetached( o ) ) );
+ out.println( INDENT + "is dirty : " + Boolean.toString( JDOHelper.isDirty( o ) ) );
+ out.println( INDENT + "is persistent : " + Boolean.toString( JDOHelper.isPersistent( o ) ) );
+
+ out.println( INDENT + "object id : " + JDOHelper.getObjectId( o ) );
+ }
+
+ public PersistenceManager getPersistenceManager()
+ {
+ PersistenceManager pm = pmf.getPersistenceManager();
+
+ pm.getFetchPlan().setMaxFetchDepth( -1 );
+
+ return pm;
+ }
+
+ public void enableCache( Class clazz )
+ {
+ DataStoreCache cache = pmf.getDataStoreCache();
+ cache.pinAll( clazz, false ); // Pin all objects of type clazz from now on
+ }
+
+ public Object saveObject( Object object )
+ {
+ return saveObject( object, null );
+ }
+
+ public Object saveObject( Object object, String[] fetchGroups )
+ {
+ PersistenceManager pm = getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+
+ try
+ {
+ tx.begin();
+
+ if ( ( JDOHelper.getObjectId( object ) != null ) && !JDOHelper.isDetached( object ) )
+ {
+ // This is a fatal error that means we need to fix our code.
+ // Leave it as a JDOUserException, it's intentional.
+ throw new JDOUserException( "Existing object is not detached: " + object, object );
+ }
+
+ if ( fetchGroups != null )
+ {
+ for ( int i = 0; i >= fetchGroups.length; i++ )
+ {
+ pm.getFetchPlan().addGroup( fetchGroups[i] );
+ }
+ }
+
+ pm.makePersistent( object );
+
+ object = pm.detachCopy( object );
+
+ tx.commit();
+
+ return object;
+ }
+ finally
+ {
+ rollbackIfActive( tx );
+ }
+ }
+
+ public List getAllObjects( Class clazz )
+ {
+ return getAllObjects( clazz, null );
+ }
+
+ public List getAllObjects( Class clazz, Constraint constraint )
+ {
+ PersistenceManager pm = getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+
+ try
+ {
+ tx.begin();
+
+ Extent extent = pm.getExtent( clazz, true );
+
+ Query query = pm.newQuery( extent );
+
+ if ( constraint != null )
+ {
+ if ( constraint.getSortColumn() != null )
+ {
+ String ordering = constraint.getSortColumn();
+
+ if ( constraint.getSortDirection() != null )
+ {
+ ordering += " " + constraint.getSortDirection();
+ }
+
+ query.setOrdering( ordering );
+ }
+
+ if ( constraint.getFetchLimits() != null )
+ {
+ pm.getFetchPlan().addGroup( constraint.getFetchLimits() );
+ }
+
+ if ( constraint.getWhereCondition() != null )
+ {
+ query.setFilter( constraint.getWhereCondition() );
+ }
+ }
+
+ List result = (List) query.execute();
+
+ result = (List) pm.detachCopyAll( result );
+
+ tx.commit();
+
+ return result;
+ }
+ finally
+ {
+ rollbackIfActive( tx );
+ }
+ }
+
+ // public List getUserAssignmentsForRoles( Class clazz, String ordering, Collection roleNames )
+ // {
+ // PersistenceManager pm = getPersistenceManager();
+ // Transaction tx = pm.currentTransaction();
+ //
+ // try
+ // {
+ // tx.begin();
+ //
+ // Extent extent = pm.getExtent( clazz, true );
+ //
+ // Query query = pm.newQuery( extent );
+ //
+ // if ( ordering != null )
+ // {
+ // query.setOrdering( ordering );
+ // }
+ //
+ // query.declareImports( "import java.lang.String" );
+ //
+ // StringBuffer filter = new StringBuffer();
+ //
+ // Iterator i = roleNames.iterator();
+ //
+ // if ( roleNames.size() > 0 )
+ // {
+ // filter.append( "this.roleNames.contains(\"" ).append( i.next() ).append( "\")" );
+ //
+ // while ( i.hasNext() )
+ // {
+ // filter.append( " || this.roleNames.contains(\"" ).append( i.next() ).append( "\")" );
+ // }
+ //
+ // query.setFilter( filter.toString() );
+ // }
+ //
+ // List result = (List) query.execute();
+ //
+ // result = (List) pm.detachCopyAll( result );
+ //
+ // tx.commit();
+ //
+ // return result;
+ // }
+ // finally
+ // {
+ // rollbackIfActive( tx );
+ // }
+ // }
+
+ public Object getObjectById( Class clazz, Object id, String fetchGroup )
+ throws ObjectNotFoundException, ArchivaDatabaseException
+ {
+ if ( id == null )
+ {
+ throw new ObjectNotFoundException( "Unable to get object '" + clazz.getName()
+ + "' from jdo using null id." );
+ }
+
+ PersistenceManager pm = getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+
+ try
+ {
+ tx.begin();
+
+ if ( fetchGroup != null )
+ {
+ pm.getFetchPlan().addGroup( fetchGroup );
+ }
+
+ Object objectId = pm.newObjectIdInstance( clazz, id );
+
+ Object object = pm.getObjectById( objectId );
+
+ object = pm.detachCopy( object );
+
+ tx.commit();
+
+ return object;
+ }
+ catch ( JDOObjectNotFoundException e )
+ {
+ throw new ObjectNotFoundException( "Unable to find Database Object '" + id + "' of type " + clazz.getName()
+ + " using fetch-group '" + fetchGroup + "'", e, id );
+ }
+ catch ( JDOException e )
+ {
+ throw new ArchivaDatabaseException( "Error in JDO during get of Database object id '" + id + "' of type "
+ + clazz.getName() + " using fetch-group '" + fetchGroup + "'", e );
+ }
+ finally
+ {
+ rollbackIfActive( tx );
+ }
+ }
+
+ public Object getObjectById( Class clazz, String id, String fetchGroup )
+ throws ObjectNotFoundException, ArchivaDatabaseException
+ {
+ if ( StringUtils.isEmpty( id ) )
+ {
+ throw new ObjectNotFoundException( "Unable to get object '" + clazz.getName()
+ + "' from jdo using null/empty id." );
+ }
+
+ return getObjectById( clazz, (Object) id, fetchGroup );
+ }
+
+ public boolean objectExists( Object object )
+ {
+ return ( JDOHelper.getObjectId( object ) != null );
+ }
+
+ public boolean objectExistsById( Class clazz, String id )
+ throws ArchivaDatabaseException
+ {
+ try
+ {
+ Object o = getObjectById( clazz, id, null );
+ return ( o != null );
+ }
+ catch ( ObjectNotFoundException e )
+ {
+ return false;
+ }
+ }
+
+ public void removeObject( Object o )
+ throws ArchivaDatabaseException
+ {
+ if ( o == null )
+ {
+ throw new ArchivaDatabaseException( "Unable to remove null object '" + o.getClass().getName() + "'" );
+ }
+
+ PersistenceManager pm = getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+
+ try
+ {
+ tx.begin();
+
+ o = pm.getObjectById( pm.getObjectId( o ) );
+
+ pm.deletePersistent( o );
+
+ tx.commit();
+ }
+ finally
+ {
+ rollbackIfActive( tx );
+ }
+ }
+
+ public void rollbackIfActive( Transaction tx )
+ {
+ PersistenceManager pm = tx.getPersistenceManager();
+
+ try
+ {
+ if ( tx.isActive() )
+ {
+ tx.rollback();
+ }
+ }
+ finally
+ {
+ closePersistenceManager( pm );
+ }
+ }
+
+ public void closePersistenceManager( PersistenceManager pm )
+ {
+ try
+ {
+ pm.close();
+ }
+ catch ( JDOUserException e )
+ {
+ // ignore
+ }
+ }
+
+ public void postDelete( InstanceLifecycleEvent evt )
+ {
+ PersistenceCapable obj = ( (PersistenceCapable) evt.getSource() );
+
+ if ( obj == null )
+ {
+ // Do not track null objects.
+ // These events are typically a product of an internal lifecycle event.
+ return;
+ }
+ }
+
+ public void preDelete( InstanceLifecycleEvent evt )
+ {
+ // ignore
+ }
+
+ public void postStore( InstanceLifecycleEvent evt )
+ {
+ // PersistenceCapable obj = ( (PersistenceCapable) evt.getSource() );
+ }
+
+ public void preStore( InstanceLifecycleEvent evt )
+ {
+ // ignore
+ }
+
+ public void removeAll( Class aClass )
+ {
+ PersistenceManager pm = getPersistenceManager();
+ Transaction tx = pm.currentTransaction();
+
+ try
+ {
+ tx.begin();
+
+ Query query = pm.newQuery( aClass );
+ query.deletePersistentAll();
+
+ tx.commit();
+ }
+ finally
+ {
+ rollbackIfActive( tx );
+ }
+ }
+
+ public JdoFactory getJdoFactory()
+ {
+ return jdoFactory;
+ }
+
+}
--- /dev/null
+package org.apache.maven.archiva.database.jdo;
+
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
+import org.apache.maven.archiva.database.Constraint;
+import org.apache.maven.archiva.database.ObjectNotFoundException;
+import org.apache.maven.archiva.database.constraints.ArchivaRepositoryByUrlConstraint;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.model.ArchivaRepository;
+import org.apache.maven.archiva.model.RepositoryContent;
+import org.apache.maven.archiva.model.RepositoryContentKey;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+import java.util.List;
+
+/**
+ * JdoArchivaDAO
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.database.ArchivaDAO"
+ * role-hint="jdo"
+ */
+public class JdoArchivaDAO
+ extends AbstractLogEnabled
+ implements ArchivaDAO
+{
+ /**
+ * @plexus.requirement
+ */
+ private JdoAccess jdo;
+
+ /* .\ Archiva Repository \.____________________________________________________________ */
+
+ public ArchivaRepository createRepository( String id, String url )
+ {
+ ArchivaRepository repo;
+
+ try
+ {
+ repo = getRepository( id );
+ }
+ catch ( ArchivaDatabaseException e )
+ {
+ repo = new ArchivaRepository();
+ repo.setId( id );
+ repo.setUrl( url );
+ }
+
+ return repo;
+ }
+
+ public List getRepositories()
+ throws ObjectNotFoundException, ArchivaDatabaseException
+ {
+ return jdo.getAllObjects( ArchivaRepository.class );
+ }
+
+ public ArchivaRepository getRepository( String id )
+ throws ObjectNotFoundException, ArchivaDatabaseException
+ {
+ return (ArchivaRepository) jdo.getObjectById( ArchivaRepository.class, id, null );
+ }
+
+ public List queryRepository( Constraint constraint )
+ throws ObjectNotFoundException, ArchivaDatabaseException
+ {
+ return jdo.getAllObjects( ArchivaRepository.class, constraint );
+ }
+
+ public ArchivaRepository saveRepository( ArchivaRepository repository )
+ {
+ return (ArchivaRepository) jdo.saveObject( repository );
+ }
+
+ public void deleteRepository( ArchivaRepository repository )
+ throws ArchivaDatabaseException
+ {
+ jdo.removeObject( repository );
+ }
+
+ /* .\ Repository Content \.____________________________________________________________ */
+
+ public RepositoryContent createRepositoryContent( String groupId, String artifactId, String version,
+ String repositoryId )
+ {
+ RepositoryContent repoContent;
+
+ try
+ {
+ repoContent = getRepositoryContent( groupId, artifactId, version, repositoryId );
+ }
+ catch ( ArchivaDatabaseException e )
+ {
+ repoContent = new RepositoryContent( repositoryId, groupId, artifactId, version );
+ }
+
+ return repoContent;
+ }
+
+ public RepositoryContent getRepositoryContent( String groupId, String artifactId, String version,
+ String repositoryId )
+ throws ObjectNotFoundException, ArchivaDatabaseException
+ {
+ RepositoryContentKey key = new RepositoryContentKey();
+ key.groupId = groupId;
+ key.artifactId = artifactId;
+ key.version = version;
+ key.repositoryId = repositoryId;
+
+ return (RepositoryContent) jdo.getObjectById( RepositoryContent.class, key, null );
+ }
+
+ public List queryRepositoryContents( Constraint constraint )
+ throws ObjectNotFoundException, ArchivaDatabaseException
+ {
+ return jdo.getAllObjects( RepositoryContent.class, constraint );
+ }
+
+ public RepositoryContent saveRepositoryContent( RepositoryContent repoContent )
+ throws ArchivaDatabaseException
+ {
+ return (RepositoryContent) jdo.saveObject( repoContent );
+ }
+
+ public void deleteRepositoryContent( RepositoryContent repoContent )
+ throws ArchivaDatabaseException
+ {
+ jdo.removeObject( repoContent );
+ }
+
+ /* .\ Archiva Artifact \. _____________________________________________________________ */
+
+ public ArchivaArtifact createArtifact( RepositoryContent repoContent, String classifier, String type )
+ {
+ ArchivaArtifact artifact;
+
+ try
+ {
+ artifact = getArtifact( repoContent, classifier, type );
+ }
+ catch ( ArchivaDatabaseException e )
+ {
+ artifact = new ArchivaArtifact();
+ artifact.setContentKey( repoContent );
+ artifact.setClassifier( classifier );
+ artifact.setType( type );
+ }
+
+ return artifact;
+ }
+
+ public ArchivaArtifact getArtifact( RepositoryContent repoContent, String classifier, String type )
+ throws ObjectNotFoundException, ArchivaDatabaseException
+ {
+
+ return null;
+ }
+
+ public List queryArtifacts( Constraint constraint )
+ throws ObjectNotFoundException, ArchivaDatabaseException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ArchivaArtifact saveArtifact( ArchivaArtifact artifact )
+ throws ArchivaDatabaseException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void deleteArtifact( ArchivaArtifact artifact )
+ throws ArchivaDatabaseException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
+++ /dev/null
-package org.apache.maven.archiva.database.key;
-
-public class MetadataKey {
-
- private String groupId;
- private String artifactId;
- private String version;
- private int metadataKey;
-
- public MetadataKey( String groupId, String artifactId, String version )
- {
- this.groupId = groupId;
- this.artifactId = artifactId;
- this.version = version;
- }
-
- public MetadataKey() {}
-
- public String getArtifactId() {
- return artifactId;
- }
- public void setArtifactId(String artifactId) {
- this.artifactId = artifactId;
- }
- public String getGroupId() {
- return groupId;
- }
- public void setGroupId(String groupId) {
- this.groupId = groupId;
- }
- public int getMetadataKey() {
- return metadataKey;
- }
- public void setMetadataKey(int id) {
- this.metadataKey = id;
- }
- public String getVersion() {
- return version;
- }
- public void setVersion(String version) {
- this.version = version;
- }
-
-
-
-}
+++ /dev/null
-package org.apache.maven.archiva.database;
-
-/*
- * 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.
- */
-
-import org.apache.maven.archiva.database.key.MetadataKey;
-import org.apache.maven.artifact.repository.metadata.Metadata;
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.ibatis.PlexusIbatisHelper;
-
-/**
- * RepositoryMetadataDatabaseTest
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class RepositoryMetadataDatabaseTest
- extends PlexusTestCase
-{
- /**
- * @plexus.requirement
- */
- protected PlexusIbatisHelper ibatisHelper;
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
- }
-
- public void testRepositoryMetadataCreationAndDeletion() throws Exception
- {
- RepositoryMetadataDatabase db = (RepositoryMetadataDatabase) lookup( "org.apache.maven.archiva.database.RepositoryMetadataDatabase", "default" );
-
- assertNotNull( db );
- assertTrue( db.tableExists( "RepositoryMetadata" ) );
- assertTrue( db.tableExists( "MetadataKeys" ) );
-
- db.dropTable( "RepositoryMetadata" );
- db.dropTable( "MetadataKeys" );
-
- assertFalse( db.tableExists( "RepositoryMetadata" ) );
- assertFalse( db.tableExists( "MetadataKeys" ) );
- }
-
- public void testMetadataKeyRetrieval() throws Exception
- {
- RepositoryMetadataDatabase db = (RepositoryMetadataDatabase) lookup( "org.apache.maven.archiva.database.RepositoryMetadataDatabase", "default" );
-
- Metadata metadata = new Metadata();
- metadata.setArtifactId( "testArtifactId" );
- metadata.setGroupId( "testGroupId" );
- metadata.setVersion( "testVersion" );
-
- MetadataKey metadataKey = db.getMetadataKey( metadata );
-
- assertTrue( metadataKey.getMetadataKey() > 0 );
- assertEquals( metadataKey.getArtifactId(), metadata.getArtifactId() );
- assertEquals( metadataKey.getGroupId(), metadata.getGroupId() );
- assertEquals( metadataKey.getVersion(), metadata.getVersion() );
-
- db.dropTable( "RepositoryMetadata" );
- db.dropTable( "MetadataKeys" );
-
- assertFalse( db.tableExists( "RepositoryMetadata" ) );
- assertFalse( db.tableExists( "MetadataKeys" ) );
-
- }
-
-
-}
+++ /dev/null
-package org.apache.maven.archiva.database.artifact;
-
-/*
- * 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.
- */
-
-import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-
-/**
- * ArtifactPersistenceTest
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class ArtifactPersistenceTest
- extends AbstractArchivaDatabaseTestCase
-{
- private ArtifactFactory artifactFactory;
-
- private ArtifactPersistence db;
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
-
- artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
- db = (ArtifactPersistence) lookup( ArtifactPersistence.class.getName() );
- }
-
- public void testLookup()
- {
- assertNotNull( db );
- }
-
- public void testAddArtifact() throws ArchivaDatabaseException
- {
- String groupId = "org.apache.maven.archiva";
- String artifactId = "archiva-test-artifact";
- String version = "1.0";
-
- Artifact artifact = artifactFactory
- .createArtifact( groupId, artifactId, version, Artifact.SCOPE_COMPILE, "jar" );
-
- db.create( artifact );
-
- Artifact fetched = db.read( groupId, artifactId, version );
-
- assertNotNull( "Should have fetched an Artifact.", fetched );
- assertEquals( "Should have fetched the expected Artifact.", artifact, fetched );
- }
-}
<artifactId>archiva-discoverer</artifactId>
<name>Archiva Discoverer</name>
<dependencies>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-consumer-api</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-common</artifactId>
* under the License.
*/
-import org.apache.maven.archiva.common.consumers.Consumer;
+import org.apache.maven.archiva.consumers.Consumer;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.DirectoryWalker;
*/
import org.apache.commons.lang.SystemUtils;
-import org.apache.maven.archiva.common.consumers.Consumer;
import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.maven.archiva.consumers.Consumer;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.DirectoryWalkListener;
*/
package org.apache.maven.archiva.discoverer;
-import org.apache.maven.archiva.common.consumers.Consumer;
-import org.apache.maven.archiva.common.consumers.ConsumerException;
import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.maven.archiva.consumers.Consumer;
+import org.apache.maven.archiva.consumers.ConsumerException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.ArrayList;
<name>Archiva Model</name>
<dependencies>
<dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-artifact-manager</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-project</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-repository-metadata</artifactId>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-common</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-maven-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.modello</groupId>
+ <artifactId>modello-maven-plugin</artifactId>
+ <version>1.0-alpha-15-SNAPSHOT</version>
+ <configuration>
+ <version>1.0.0</version>
+ <packageWithVersion>false</packageWithVersion>
+ <model>src/main/mdo/archiva.xml</model>
+ </configuration>
+ <executions>
+ <execution>
+ <id>modello-java</id>
+ <goals>
+ <goal>java</goal>
+ <goal>jpox-metadata-class</goal>
+ <!--
+ <goal>xpp3-writer</goal>
+ <goal>xpp3-reader</goal>
+ -->
+ </goals>
+ </execution>
+ <execution>
+ <id>jpox-jdo-mapping</id>
+ <goals>
+ <goal>jpox-jdo-mapping</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${basedir}/target/classes/org/apache/maven/archiva/model/</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jpox-maven-plugin</artifactId>
+ <version>1.1.6</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>enhance</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ <configuration>
+ <instrumentation>
+ <!-- exclude generated -->
+ <excludes>
+ <exclude>org/apache/maven/archiva/reporting/model/**</exclude>
+ </excludes>
+ </instrumentation>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
--- /dev/null
+package org.apache.maven.archiva.model;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.artifact.InvalidArtifactRTException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.util.Map;
+
+/**
+ * ArchivaArtifact
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class AbstractArchivaArtifact
+{
+ private String classifier;
+
+ private RepositoryContent key;
+
+ private String type;
+
+ public AbstractArchivaArtifact( ArchivaRepository repository, String groupId, String artifactId, String version, String classifier, String type )
+ {
+ this.key = new RepositoryContent( repository, groupId, artifactId, version );
+
+ this.classifier = classifier;
+
+ this.type = type;
+
+ validateIdentity();
+ }
+
+ public String getClassifier()
+ {
+ return classifier;
+ }
+
+ public RepositoryContent getRepositoryContent()
+ {
+ return key;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public boolean hasClassifier()
+ {
+ return StringUtils.isNotEmpty( classifier );
+ }
+
+ public void setRepositoryContent( RepositoryContent key )
+ {
+ this.key = key;
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ if ( key.getGroupId() != null )
+ {
+ sb.append( key.getGroupId() );
+ sb.append( ":" );
+ }
+ appendArtifactTypeClassifierString( sb );
+ sb.append( ":" );
+ if ( key.getVersion() != null )
+ {
+ sb.append( key.getVersion() );
+ }
+
+ return sb.toString();
+ }
+
+ private void appendArtifactTypeClassifierString( StringBuffer sb )
+ {
+ sb.append( key.getArtifactId() );
+ sb.append( ":" );
+ sb.append( getType() );
+ if ( hasClassifier() )
+ {
+ sb.append( ":" );
+ sb.append( getClassifier() );
+ }
+ }
+
+ protected boolean empty( String value )
+ {
+ return value == null || value.trim().length() < 1;
+ }
+
+ protected void validateIdentity()
+ {
+ if ( empty( key.getGroupId() ) )
+ {
+ throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
+ "The groupId cannot be empty." );
+ }
+
+ if ( key.getArtifactId() == null )
+ {
+ throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
+ "The artifactId cannot be empty." );
+ }
+
+ if ( type == null )
+ {
+ throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
+ "The type cannot be empty." );
+ }
+
+ if ( key.getVersion() == null )
+ {
+ throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
+ "The version cannot be empty." );
+ }
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.model;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.common.utils.RepositoryURL;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+
+/**
+ * AbstractArchivaRepository
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class AbstractArchivaRepository
+{
+ protected ArtifactRepositoryLayout layout;
+
+ protected ArtifactRepositoryPolicy releases;
+
+ protected ArtifactRepositoryPolicy snapshots;
+
+ protected boolean blacklisted;
+
+ public AbstractArchivaRepository()
+ {
+
+ }
+
+ /**
+ * Construct a Repository.
+ *
+ * @param id the unique identifier for this repository.
+ * @param name the name for this repository.
+ * @param url the base URL for this repository (this should point to the top level URL for the entire repository)
+ * @param layout the layout technique for this repository.
+ */
+ public AbstractArchivaRepository( String id, String name, String url, ArtifactRepositoryLayout layout )
+ {
+ setId( id );
+ setName( name );
+ setUrl( url );
+ setLayout( layout );
+ }
+
+ public abstract void setUrl( String url );
+
+ public abstract String getUrl();
+
+ public abstract void setName( String name );
+
+ public abstract void setId( String id );
+
+ public boolean isBlacklisted()
+ {
+ return blacklisted;
+ }
+
+ public void setBlacklisted( boolean blacklisted )
+ {
+ this.blacklisted = blacklisted;
+ }
+
+ public ArtifactRepositoryLayout getLayout()
+ {
+ return layout;
+ }
+
+ public void setLayout( ArtifactRepositoryLayout layout )
+ {
+ this.layout = layout;
+ }
+
+ public ArtifactRepositoryPolicy getReleases()
+ {
+ return releases;
+ }
+
+ public void setReleases( ArtifactRepositoryPolicy releases )
+ {
+ this.releases = releases;
+ }
+
+ public ArtifactRepositoryPolicy getSnapshots()
+ {
+ return snapshots;
+ }
+
+ public void setSnapshots( ArtifactRepositoryPolicy snapshots )
+ {
+ this.snapshots = snapshots;
+ }
+
+ public boolean isRemote()
+ {
+ return !getRepositoryURL().getProtocol().equals( "file" );
+ }
+
+ public boolean isManaged()
+ {
+ return getRepositoryURL().getProtocol().equals( "file" );
+ }
+
+ public RepositoryURL getRepositoryURL()
+ {
+ return new RepositoryURL( getUrl() );
+ }
+}
+++ /dev/null
-package org.apache.maven.archiva.model;
-
-/*
- * 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.
- */
-
-import org.apache.maven.artifact.InvalidArtifactRTException;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.codehaus.plexus.util.StringUtils;
-
-import java.util.Map;
-
-/**
- * ArchivaArtifact
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- *
- * @plexus.component role="org.apache.maven.archiva.model.ArchivaArtifact"
- */
-public class ArchivaArtifact
- implements RepositoryContent
-{
- private Map attached;
-
- private String classifier;
-
- private RepositoryContentKey key;
-
- private String type;
-
- public ArchivaArtifact( ArtifactRepository repository, String groupId, String artifactId, String version, String classifier, String type )
- {
- this.key = new RepositoryContentKey( repository, groupId, artifactId, version );
-
- this.classifier = classifier;
-
- this.type = type;
-
- validateIdentity();
- }
-
- public void addAttached( ArchivaArtifact attachedArtifact )
- {
- attached.put( attachedArtifact.getClassifier(), attachedArtifact );
- // Naughty, Attached shouldn't have it's own attached artifacts!
- attachedArtifact.clearAttached();
- }
-
- public void clearAttached()
- {
- attached.clear();
- }
-
- public Map getAttached()
- {
- return attached;
- }
-
- public String getClassifier()
- {
- return classifier;
- }
-
- public RepositoryContentKey getRepositoryContentKey()
- {
- return key;
- }
-
- public String getType()
- {
- return type;
- }
-
- public boolean hasClassifier()
- {
- return StringUtils.isNotEmpty( classifier );
- }
-
- public void setAttached( Map attached )
- {
- this.attached = attached;
- }
-
- public void setRepositoryContentKey( RepositoryContentKey key )
- {
- this.key = key;
- }
-
- public String toString()
- {
- StringBuffer sb = new StringBuffer();
- if ( key.getGroupId() != null )
- {
- sb.append( key.getGroupId() );
- sb.append( ":" );
- }
- appendArtifactTypeClassifierString( sb );
- sb.append( ":" );
- if ( key.getVersion() != null )
- {
- sb.append( key.getVersion() );
- }
-
- return sb.toString();
- }
-
- private void appendArtifactTypeClassifierString( StringBuffer sb )
- {
- sb.append( key.getArtifactId() );
- sb.append( ":" );
- sb.append( getType() );
- if ( hasClassifier() )
- {
- sb.append( ":" );
- sb.append( getClassifier() );
- }
- }
-
- private boolean empty( String value )
- {
- return value == null || value.trim().length() < 1;
- }
-
- private void validateIdentity()
- {
- if ( empty( key.getGroupId() ) )
- {
- throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
- "The groupId cannot be empty." );
- }
-
- if ( key.getArtifactId() == null )
- {
- throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
- "The artifactId cannot be empty." );
- }
-
- if ( type == null )
- {
- throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
- "The type cannot be empty." );
- }
-
- if ( key.getVersion() == null )
- {
- throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
- "The version cannot be empty." );
- }
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.model;
-
-/*
- * 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.
- */
-
-import org.apache.maven.artifact.repository.ArtifactRepository;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * ArchivaRepositoryMetadata
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class ArchivaRepositoryMetadata
- implements RepositoryContent
-{
- private List availableVersions = new ArrayList();
-
- private RepositoryContentKey key;
-
- private String releasedVersion;
-
- public ArchivaRepositoryMetadata( ArtifactRepository repository, String groupId, String artifactId, String version )
- {
- this.key = new RepositoryContentKey( repository, groupId, artifactId, version );
- }
-
- public List getAvailableVersions()
- {
- return availableVersions;
- }
-
- public String getReleasedVersion()
- {
- return releasedVersion;
- }
-
- public RepositoryContentKey getRepositoryContentKey()
- {
- return this.key;
- }
-
- public void setAvailableVersions( List availableVersions )
- {
- this.availableVersions = availableVersions;
- }
-
- public void setReleasedVersion( String releasedVersion )
- {
- this.releasedVersion = releasedVersion;
- }
-
- public void setRepositoryContentKey( RepositoryContentKey key )
- {
- this.key = key;
- }
-
-}
+++ /dev/null
-package org.apache.maven.archiva.model;
-
-/*
- * 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.
- */
-
-/**
- * RepositoryContent
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public interface RepositoryContent
-{
- public RepositoryContentKey getRepositoryContentKey();
-
- public void setRepositoryContentKey( RepositoryContentKey key );
-}
* under the License.
*/
-import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.commons.lang.StringUtils;
+
+import java.io.Serializable;
/**
- * RepositoryContentKey - the golden key for all content within the repository.
+ * RepositoryContentKey - the jpox application key support class for all content within the repository.
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
-public class RepositoryContentKey
+public class RepositoryContentKey implements Serializable
{
- private String artifactId;
-
- private String groupId;
+ /**
+ * The Repository ID. (JPOX Requires this remain public)
+ */
+ public String repositoryId = "";
- private ArtifactRepository repository;
+ /**
+ * The Group ID. (JPOX Requires this remain public)
+ */
+ public String groupId = "";
- private String version;
+ /**
+ * The Artifact ID. (JPOX Requires this remain public)
+ */
+ public String artifactId = "";
- public RepositoryContentKey( ArtifactRepository repository, String groupId, String artifactId, String version )
- {
- this.repository = repository;
- this.groupId = groupId;
- this.artifactId = artifactId;
- this.version = version;
- }
+ /**
+ * The Version. (JPOX Requires this remain public)
+ */
+ public String version = "";
- public String getArtifactId()
+ /**
+ * Default Constructor. Required by JPOX.
+ */
+ public RepositoryContentKey()
{
- return artifactId;
- }
- public String getGroupId()
- {
- return groupId;
}
- public ArtifactRepository getRepository()
+ /**
+ * Key Based Constructor. Required by JPOX.
+ *
+ * @param key the String representing this object's values.
+ */
+ public RepositoryContentKey( String key )
{
- return repository;
+ String parts[] = StringUtils.splitPreserveAllTokens( key, ':' );
+ repositoryId = parts[0];
+ groupId = parts[1];
+ artifactId = parts[2];
+ version = parts[3];
}
- public String getVersion()
+ /**
+ * Get the String representation of this object. - Required by JPOX.
+ */
+ public String toString()
{
- return version;
+ return StringUtils.join( new String[] { repositoryId, groupId, artifactId, version } );
}
- public void setArtifactId( String artifactId )
+ /**
+ * Get the hashcode for this object's values - Required by JPOX.
+ */
+ public int hashCode()
{
- this.artifactId = artifactId;
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ( ( repositoryId == null ) ? 0 : repositoryId.hashCode() );
+ result = PRIME * result + ( ( groupId == null ) ? 0 : groupId.hashCode() );
+ result = PRIME * result + ( ( artifactId == null ) ? 0 : artifactId.hashCode() );
+ result = PRIME * result + ( ( version == null ) ? 0 : version.hashCode() );
+ return result;
}
- public void setGroupId( String groupId )
+ /**
+ * Get the equals for this object's values - Required by JPOX.
+ */
+ public boolean equals( Object obj )
{
- this.groupId = groupId;
- }
+ if ( this == obj )
+ {
+ return true;
+ }
- public void setRepository( ArtifactRepository repository )
- {
- this.repository = repository;
- }
+ if ( obj == null )
+ {
+ return false;
+ }
- public void setVersion( String version )
- {
- this.version = version;
+ if ( getClass() != obj.getClass() )
+ {
+ return false;
+ }
+
+ final RepositoryContentKey other = (RepositoryContentKey) obj;
+
+ if ( repositoryId == null )
+ {
+ if ( other.repositoryId != null )
+ {
+ return false;
+ }
+ }
+ else if ( !repositoryId.equals( other.repositoryId ) )
+ {
+ return false;
+ }
+
+ if ( groupId == null )
+ {
+ if ( other.groupId != null )
+ {
+ return false;
+ }
+ }
+ else if ( !groupId.equals( other.groupId ) )
+ {
+ return false;
+ }
+
+ if ( artifactId == null )
+ {
+ if ( other.artifactId != null )
+ {
+ return false;
+ }
+ }
+ else if ( !artifactId.equals( other.artifactId ) )
+ {
+ return false;
+ }
+
+ if ( version == null )
+ {
+ if ( other.version != null )
+ {
+ return false;
+ }
+ }
+ else if ( !version.equals( other.version ) )
+ {
+ return false;
+ }
+
+ return true;
}
}
+++ /dev/null
-package org.apache.maven.archiva.model.health;
-
-/*
- * 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.
- */
-
-import org.apache.maven.archiva.model.ArchivaArtifact;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * ArtifactHealth
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class ArtifactHealth
-{
- private ArchivaArtifact artifact;
-
- private List problems = new ArrayList();
-
- public void addProblem( HealthProblem problem )
- {
- this.problems.add( problem );
- }
-
- public ArchivaArtifact getArtifact()
- {
- return artifact;
- }
-
- public List getProblems()
- {
- return problems;
- }
-
- public void setArtifact( ArchivaArtifact artifact )
- {
- this.artifact = artifact;
- }
-
- public void setProblems( List problems )
- {
- this.problems = problems;
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.model.health;
-
-/*
- * 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.
- */
-
-/**
- * HealthProblem
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class HealthProblem
-{
- private String type;
-
- private String origin;
-
- private String message;
-
- public HealthProblem()
- {
-
- }
-
- public HealthProblem( String type, String origin, String message )
- {
- this.type = type;
- this.origin = origin;
- this.message = message;
- }
-
- public String getMessage()
- {
- return message;
- }
-
- public void setMessage( String message )
- {
- this.message = message;
- }
-
- public String getOrigin()
- {
- return origin;
- }
-
- public void setOrigin( String origin )
- {
- this.origin = origin;
- }
-
- public String getType()
- {
- return type;
- }
-
- public void setType( String type )
- {
- this.type = type;
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.model.health;
-
-/*
- * 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.
- */
-
-import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * RepositoryMetadataHealth
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class RepositoryMetadataHealth
-{
- private ArchivaRepositoryMetadata repositoryMetadata;
-
- private List problems = new ArrayList();
-
- public void addProblem( HealthProblem problem )
- {
- this.problems.add( problem );
- }
-
- public List getProblems()
- {
- return problems;
- }
-
- public void setProblems( List problems )
- {
- this.problems = problems;
- }
-
- public ArchivaRepositoryMetadata getRepositoryMetadata()
- {
- return repositoryMetadata;
- }
-
- public void setRepositoryMetadata( ArchivaRepositoryMetadata repositoryMetadata )
- {
- this.repositoryMetadata = repositoryMetadata;
- }
-}
--- /dev/null
+<?xml version="1.0" ?>
+<model jpox.table-prefix="ARCHIVA_">
+ <id>archiva-model</id>
+ <name>ArchivaModel</name>
+ <version>1.0.0</version>
+ <description>Archiva Model</description>
+ <defaults>
+ <default>
+ <key>package</key>
+ <value>org.apache.maven.archiva.model</value>
+ </default>
+ </defaults>
+
+ <classes>
+ <class stash.storable="false" rootElement="true">
+ <name>ArchivaDatabase</name>
+ <version>1.0.0+</version>
+ <fields>
+ <field>
+ <name>Repositories</name>
+ <version>1.0.0+</version>
+ <association>
+ <type>ArchivaRepository</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ </fields>
+ </class>
+ <class stash.storable="true">
+ <superClass>AbstractArchivaRepository</superClass>
+ <name>ArchivaRepository</name>
+ <version>1.0.0+</version>
+ <fields>
+ <field>
+ <name>id</name>
+ <identity>true</identity>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The unique ID for the repository.
+ </description>
+ </field>
+ <field>
+ <name>name</name>
+ <identity>false</identity>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The Name of the repository.
+ </description>
+ </field>
+ <field>
+ <name>url</name>
+ <identity>false</identity>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The URL of the repository.
+ </description>
+ </field>
+ <field>
+ <name>creationSource</name>
+ <identity>false</identity>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The Source of this repository.
+ (Example: Configuration, POM)
+ </description>
+ </field>
+ <field>
+ <name>layoutName</name>
+ <identity>false</identity>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The layout of the repository.
+ (Either 'default', or 'legacy')
+ </description>
+ </field>
+ <field>
+ <name>releasePolicy</name>
+ <identity>false</identity>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The releases policy of the repository.
+ </description>
+ </field>
+ <field>
+ <name>snapshotPolicy</name>
+ <identity>false</identity>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The snapshot policy of the repository.
+ </description>
+ </field>
+ </fields>
+ </class>
+ <class stash.storable="true"
+ jpox.use-identifiers-as-primary-key="true"
+ jpox.identity-type="application"
+ jpox.identity-class="RepositoryContentKey">
+ <name>RepositoryContent</name>
+ <version>1.0.0+</version>
+ <description>
+ Repository Content Identifier.
+ </description>
+ <fields>
+ <field jpox.primary-key="true"
+ jpox.value-strategy="off"
+ jpox.persistence-modifier="persistent">
+ <name>groupId</name>
+ <identity>true</identity>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The Group ID of the repository content.
+ </description>
+ </field>
+ <field jpox.primary-key="true"
+ jpox.value-strategy="off"
+ jpox.persistence-modifier="persistent">
+ <name>artifactId</name>
+ <identity>true</identity>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The Artifact ID of the repository content.
+ </description>
+ </field>
+ <field jpox.primary-key="true"
+ jpox.value-strategy="off"
+ jpox.persistence-modifier="persistent">
+ <name>version</name>
+ <identity>true</identity>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>false</required>
+ <description>
+ The version of the repository content.
+ </description>
+ </field>
+ <field jpox.primary-key="true"
+ jpox.value-strategy="off"
+ jpox.persistence-modifier="persistent">
+ <name>repositoryId</name>
+ <identity>true</identity>
+ <version>1.0.0+</version>
+ <required>true</required>
+ <type>String</type>
+ <description>
+ The repository associated with this content.
+ </description>
+ </field>
+ </fields>
+ <codeSegments>
+ <codeSegment>
+ <version>1.0.0+</version>
+ <code>
+ public RepositoryContent( String repositoryId, String groupId, String artifactId, String version )
+ {
+ this.setRepositoryId( repositoryId );
+ this.setGroupId( groupId );
+ this.setArtifactId( artifactId );
+ this.setVersion( version );
+ }
+
+ public RepositoryContent( ArchivaRepository repository, String groupId, String artifactId, String version )
+ {
+ this.setRepositoryId( repository.getId() );
+ this.setGroupId( groupId );
+ this.setArtifactId( artifactId );
+ this.setVersion( version );
+ }
+ </code>
+ </codeSegment>
+ </codeSegments>
+ </class>
+ <class>
+ <name>ArchivaArtifact</name>
+ <version>1.0.0+</version>
+ <fields>
+ <field>
+ <name>contentKey</name>
+ <identity>true</identity>
+ <version>1.0.0+</version>
+ <required>true</required>
+ <association>
+ <type>RepositoryContent</type>
+ <multiplicity>1</multiplicity>
+ </association>
+ <description>
+ The content key for this artifact.
+ </description>
+ </field>
+ <field>
+ <name>classifier</name>
+ <identity>false</identity>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>false</required>
+ <description>
+ The classifier for this artifact.
+ </description>
+ </field>
+ <field jpox.column="FILE_TYPE">
+ <name>type</name>
+ <identity>true</identity>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The type of artifact.
+ </description>
+ </field>
+ </fields>
+ </class>
+ <class>
+ <name>ArchivaRepositoryMetadata</name>
+ <version>1.0.0+</version>
+ <fields>
+ <field>
+ <name>contentKey</name>
+ <identity>true</identity>
+ <version>1.0.0+</version>
+ <required>true</required>
+ <association>
+ <type>RepositoryContent</type>
+ <multiplicity>1</multiplicity>
+ </association>
+ <description>
+ The content key for this repository metadata.
+ </description>
+ </field>
+ <field>
+ <name>releasedVersion</name>
+ <identity>false</identity>
+ <version>1.0.0+</version>
+ <required>false</required>
+ <type>String</type>
+ <description>
+ The released version id.
+ </description>
+ </field>
+ <field>
+ <name>availableVersions</name>
+ <identity>false</identity>
+ <version>1.0.0+</version>
+ <required>false</required>
+ <association>
+ <type>String</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ <description>
+ The list of available version ids.
+ </description>
+ </field>
+ </fields>
+ </class>
+ <class>
+ <name>HealthProblem</name>
+ <version>1.0.0+</version>
+ <fields>
+ <field jpox.column="PROBLEM_TYPE">
+ <name>type</name>
+ <identity>false</identity>
+ <version>1.0.0+</version>
+ <required>true</required>
+ <type>String</type>
+ <description>
+ The type of health problem.
+ </description>
+ </field>
+ <field jpox.column="PROBLEM_ORIGIN">
+ <name>origin</name>
+ <identity>false</identity>
+ <version>1.0.0+</version>
+ <required>true</required>
+ <type>String</type>
+ <description>
+ The origin of the health problem.
+ </description>
+ </field>
+ <field>
+ <name>message</name>
+ <identity>false</identity>
+ <version>1.0.0+</version>
+ <required>true</required>
+ <type>String</type>
+ <description>
+ The origin of the health problem.
+ </description>
+ </field>
+ </fields>
+ </class>
+ <class>
+ <name>ArchivaArtifactHealth</name>
+ <version>1.0.0+</version>
+ <fields>
+ <field>
+ <name>artifact</name>
+ <identity>true</identity>
+ <version>1.0.0+</version>
+ <required>true</required>
+ <association>
+ <type>ArchivaArtifact</type>
+ <multiplicity>1</multiplicity>
+ </association>
+ <description>
+ The Artifact to report on.
+ </description>
+ </field>
+ <field>
+ <name>problems</name>
+ <identity>false</identity>
+ <version>1.0.0+</version>
+ <required>false</required>
+ <association>
+ <type>HealthProblem</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ <description>
+ The list of problems associated with this artifact.
+ </description>
+ </field>
+ </fields>
+ </class>
+ <class>
+ <name>ArchivaRepositoryMetadataHealth</name>
+ <version>1.0.0+</version>
+ <fields>
+ <field>
+ <name>repositoryMetadata</name>
+ <identity>true</identity>
+ <version>1.0.0+</version>
+ <required>true</required>
+ <association>
+ <type>ArchivaRepositoryMetadata</type>
+ <multiplicity>1</multiplicity>
+ </association>
+ <description>
+ The ArchivaRepositoryMetadata to report on.
+ </description>
+ </field>
+ <field>
+ <name>problems</name>
+ <identity>false</identity>
+ <version>1.0.0+</version>
+ <required>false</required>
+ <association>
+ <type>HealthProblem</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ <description>
+ The list of problems associated with this repository metadata.
+ </description>
+ </field>
+ </fields>
+ </class>
+ <class>
+ <name>RepositoryContentStatistics</name>
+ <version>1.0.0+</version>
+ <fields>
+ <field>
+ <name>repositoryId</name>
+ <version>1.0.0+</version>
+ <identity>false</identity>
+ <required>true</required>
+ <type>String</type>
+ <description>
+ The repository id the statistics belong to.
+ </description>
+ </field>
+ <field>
+ <name>whenGathered</name>
+ <version>1.0.0+</version>
+ <identity>false</identity>
+ <required>true</required>
+ <type>Date</type>
+ <description>
+ The timestamp on when this set of statistics was gathered.
+ </description>
+ </field>
+ <field>
+ <name>duration</name>
+ <version>1.0.0+</version>
+ <identity>false</identity>
+ <required>true</required>
+ <type>long</type>
+ <description>
+ The duration (in milliseconds) for the gathering of the statistics.
+ </description>
+ </field>
+ <field>
+ <name>totalFileCount</name>
+ <version>1.0.0+</version>
+ <identity>false</identity>
+ <required>true</required>
+ <type>long</type>
+ <description>
+ The total number of files in the repository.
+ </description>
+ </field>
+ <field>
+ <name>newFileCount</name>
+ <version>1.0.0+</version>
+ <identity>false</identity>
+ <required>true</required>
+ <type>long</type>
+ <description>
+ The number of new files discovered.
+ </description>
+ </field>
+ </fields>
+ <codeSegments>
+ <codeSegment>
+ <version>1.0.0+</version>
+ <code>
+ private transient long startTimestamp;
+
+ public void triggerStart() {
+ startTimestamp = System.currentTimeMillis();
+ }
+
+ public void triggerFinished() {
+ long finished = System.currentTimeMillis();
+ setDuration( finished - startTimestamp );
+ setWhenGathered( new java.util.Date( finished ) );
+ }
+
+ public void increaseFileCount() {
+ this.totalFileCount++;
+ }
+
+ public void increaseNewFileCount() {
+ this.newFileCount++;
+ }
+ </code>
+ </codeSegment>
+ </codeSegments>
+ </class>
+ </classes>
+</model>
<artifactId>archiva-repository-layer</artifactId>
<name>Archiva Repository Interface Layer</name>
<dependencies>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-consumer-api</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-common</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-model</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
+++ /dev/null
-package org.apache.maven.archiva.repository;
-
-/*
- * 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.
- */
-
-import java.util.List;
-
-/**
- * DefinedRepositories - maintains the list of defined repositories.
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public interface DefinedRepositories
-{
- /**
- * Get the entire list of repositories.
- *
- * @return the list of repositories.
- */
- public List getAllRepositories();
-
- /**
- * Get the list of managed (local) repositories.
- *
- * @return the list of managed (local) repositories.
- */
- public List getManagedRepositories();
-
- /**
- * Get the list of remote repositories.
- *
- * @return the list of remote repositories.
- */
- public List getRemoteRepositories();
-
- /**
- * Add a repository.
- *
- * @param repository the repository to add.
- */
- public void addRepository( Repository repository );
-
- /**
- * Remove a repository.
- *
- * @param repository the repository to add.
- */
- public void removeRepository( Repository repository );
-
- /**
- * Get a repository using the provided repository key.
- *
- * @param repositoryKey the repository key to find the repository via.
- * @return the repository associated with the provided Repository Key, or null if not found.
- */
- public Repository getRepository( String repositoryKey );
-}
+++ /dev/null
-package org.apache.maven.archiva.repository;
-
-/*
- * 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.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
-
-/**
- * Repository
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class Repository
- implements ArtifactRepository
-{
- protected String id;
-
- protected String name;
-
- protected String source;
-
- protected RepositoryURL url;
-
- protected ArtifactRepositoryLayout layout;
-
- protected ArtifactRepositoryPolicy releases;
-
- protected ArtifactRepositoryPolicy snapshots;
-
- protected boolean blacklisted;
-
- /* .\ Constructor \.__________________________________________________ */
-
- /**
- * Construct a Repository.
- *
- * @param id the unique identifier for this repository.
- * @param name the name for this repository.
- * @param url the base URL for this repository (this should point to the top level URL for the entire repository)
- * @param layout the layout technique for this repository.
- */
- public Repository( String id, String name, String url, ArtifactRepositoryLayout layout )
- {
- this.id = id;
- this.name = name;
- this.url = new RepositoryURL( url );
- this.layout = layout;
- }
-
- /* .\ Information \.__________________________________________________ */
-
- /**
- * Get the unique ID for this repository.
- *
- * @return the unique ID for this repository.
- */
- public String getId()
- {
- return id;
- }
-
- /**
- * Get the Name of this repository.
- * This is usually the human readable name for the repository.
- *
- * @return the name of this repository.
- */
- public String getName()
- {
- return name;
- }
-
- public String getUrl()
- {
- return url.toString();
- }
-
- public void setLayout( ArtifactRepositoryLayout layout )
- {
- this.layout = layout;
- }
-
- public ArtifactRepositoryLayout getLayout()
- {
- return layout;
- }
-
- public void setSource( String source )
- {
- this.source = source;
- }
-
- public String getSource()
- {
- return source;
- }
-
- /* .\ Tasks \.________________________________________________________ */
-
- public String pathOf( Artifact artifact )
- {
- return getLayout().pathOf( artifact );
- }
-
- /* .\ State \.________________________________________________________ */
-
- public void setBlacklisted( boolean blacklisted )
- {
- this.blacklisted = blacklisted;
- }
-
- public boolean isBlacklisted()
- {
- return blacklisted;
- }
-
- public boolean isManaged()
- {
- return this.url.getProtocol().equals( "file" );
- }
-
- public boolean isRemote()
- {
- return !this.url.getProtocol().equals( "file" );
- }
-
- public void setSnapshots( ArtifactRepositoryPolicy snapshots )
- {
- this.snapshots = snapshots;
- }
-
- public ArtifactRepositoryPolicy getSnapshots()
- {
- return snapshots;
- }
-
- public void setReleases( ArtifactRepositoryPolicy releases )
- {
- this.releases = releases;
- }
-
- public ArtifactRepositoryPolicy getReleases()
- {
- return releases;
- }
-
- public boolean equals( Object other )
- {
- return ( other == this || ( ( other instanceof Repository ) && ( (Repository) other ).getId().equals( getId() ) ) );
- }
-
- public int hashCode()
- {
- return getId().hashCode();
- }
-
- /* .\ ArtifactRepository Requirements \.______________________________ */
-
- public String getBasedir()
- {
- return url.getPath();
- }
-
- public String getKey()
- {
- return getId();
- }
-
- public String getProtocol()
- {
- return url.getProtocol();
- }
-
- public boolean isUniqueVersion()
- {
- // TODO: Determine Importance
- return false;
- }
-
- public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata )
- {
- return layout.pathOfRemoteRepositoryMetadata( artifactMetadata );
- }
-
- public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
- {
- return layout.pathOfLocalRepositoryMetadata( metadata, repository );
- }
-
-}
+++ /dev/null
-package org.apache.maven.archiva.repository;
-
-/*
- * 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.
- */
-
-
-/**
- * RepositoryURL - Mutable (and protocol forgiving) URL object.
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class RepositoryURL
-{
- private String url;
-
- private String protocol;
-
- private String host;
-
- private String port;
-
- private String username;
-
- private String password;
-
- private String path;
-
- public RepositoryURL( String url )
- {
- this.url = url;
-
- // .\ Parse the URL \.____________________________________________
-
- int pos;
-
- pos = url.indexOf( "://" );
- if ( pos == ( -1 ) )
- {
- throw new IllegalArgumentException( "Invalid URL, unable to parse protocol:// from " + url );
- }
-
- protocol = url.substring( 0, pos );
-
- // attempt to find the start of the 'path'
- pos = url.indexOf( "/", protocol.length() + 3 );
-
- // no path specified - ex "http://localhost"
- if ( pos == ( -1 ) )
- {
- // set pos to end of string. (needed for 'middle section')
- pos = url.length();
- // default path
- path = "/";
- }
- else
- {
- // get actual path.
- path = url.substring( pos );
- }
-
- // get the middle section ( username : password @ hostname : port )
- String middle = url.substring( protocol.length() + 3, pos );
-
- pos = middle.indexOf( '@' );
-
- // we have an authentication section.
- if ( pos > 0 )
- {
- String authentication = middle.substring( 0, pos );
- middle = middle.substring( pos + 1 ); // lop off authentication for host:port search
-
- pos = authentication.indexOf( ':' );
-
- // we have a password.
- if ( pos > 0 )
- {
- username = authentication.substring( 0, pos );
- password = authentication.substring( pos + 1 );
- }
- else
- {
- username = authentication;
- }
- }
-
- pos = middle.indexOf( ':' );
-
- // we have a defined port
- if ( pos > 0 )
- {
- host = middle.substring( 0, pos );
- port = middle.substring( pos + 1 );
- }
- else
- {
- host = middle;
- }
- }
-
- public String toString()
- {
- return url;
- }
-
- public String getUsername()
- {
- return username;
- }
-
- public String getPassword()
- {
- return password;
- }
-
- public String getHost()
- {
- return host;
- }
-
- public String getPath()
- {
- return path;
- }
-
- public String getPort()
- {
- return port;
- }
-
- public String getProtocol()
- {
- return protocol;
- }
-
- public String getUrl()
- {
- return url;
- }
-}
* under the License.
*/
-import org.apache.maven.archiva.repository.Repository;
+import org.apache.maven.archiva.model.ArchivaRepository;
import java.util.List;
*/
public interface RepositoryConnector
{
- public Repository getSourceRepository();
+ public ArchivaRepository getSourceRepository();
- public Repository getTargetRepository();
+ public ArchivaRepository getTargetRepository();
public List getBlacklist();
--- /dev/null
+package org.apache.maven.archiva.repository.content;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.archiva.model.ArchivaArtifact;
+
+/**
+ * BidirectionalRepositoryLayout - Similar in scope to ArtifactRepositoryLayout, but does
+ * the both the Path to Artifact and Artifact to Path conversions.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface BidirectionalRepositoryLayout
+{
+ /**
+ * Given an ArchivaArtifact
+ *
+ * @param artifact
+ * @return
+ */
+ public String pathOf( ArchivaArtifact artifact );
+
+ ArchivaArtifact toArtifact( String path );
+}
* under the License.
*/
-import org.apache.maven.archiva.common.consumers.Consumer;
+import org.apache.maven.archiva.consumers.Consumer;
+import org.apache.maven.archiva.model.ArchivaRepository;
+import org.apache.maven.archiva.model.RepositoryContentStatistics;
import org.apache.maven.archiva.repository.RepositoryException;
-import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.util.DirectoryWalker;
import org.codehaus.plexus.util.FileUtils;
* @return the statistics for this scan.
* @throws RepositoryException if there was a fundamental problem with getting the discoverer started.
*/
- public ScanStatistics scan( ArtifactRepository repository, List consumers, boolean includeSnapshots )
+ public RepositoryContentStatistics scan( ArchivaRepository repository, List consumers, boolean includeSnapshots )
throws RepositoryException
{
return scan( repository, consumers, includeSnapshots, 0, null, null );
* @return the statistics for this scan.
* @throws RepositoryException if there was a fundamental problem with getting the discoverer started.
*/
- public ScanStatistics scan( ArtifactRepository repository, List consumers, boolean includeSnapshots,
+ public RepositoryContentStatistics scan( ArchivaRepository repository, List consumers, boolean includeSnapshots,
long onlyModifiedAfterTimestamp, List extraFileExclusions, List extraFileInclusions )
throws RepositoryException
{
throw new IllegalArgumentException( "Unable to operate on a null repository." );
}
- if ( !"file".equals( repository.getProtocol() ) )
+ if ( !"file".equals( repository.getRepositoryURL().getProtocol() ) )
{
throw new UnsupportedOperationException( "Only filesystem repositories are supported." );
}
- File repositoryBase = new File( repository.getBasedir() );
+ File repositoryBase = new File( repository.getRepositoryURL().getPath() );
if ( !repositoryBase.exists() )
{
*/
import org.apache.commons.lang.SystemUtils;
-import org.apache.maven.archiva.common.consumers.Consumer;
import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.maven.archiva.consumers.Consumer;
+import org.apache.maven.archiva.model.ArchivaRepository;
+import org.apache.maven.archiva.model.RepositoryContentStatistics;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.util.DirectoryWalkListener;
import org.codehaus.plexus.util.SelectorUtils;
private List consumers;
- private ArtifactRepository repository;
+ private ArchivaRepository repository;
private boolean isCaseSensitive = true;
- private ScanStatistics stats;
+ private RepositoryContentStatistics stats;
private long onlyModifiedAfterTimestamp = 0;
- public RepositoryScannerInstance( ArtifactRepository repository, List consumerList )
+ public RepositoryScannerInstance( ArchivaRepository repository, List consumerList )
{
this.repository = repository;
this.consumers = consumerList;
- stats = new ScanStatistics( repository );
+ stats = new RepositoryContentStatistics();
+ stats.setRepositoryId( repository.getId() );
+
Iterator it = this.consumers.iterator();
while ( it.hasNext() )
}
}
- public ScanStatistics getStatistics()
+ public RepositoryContentStatistics getStatistics()
{
return stats;
}
public void directoryWalkStarting( File basedir )
{
- log.info( "Walk Started: [" + this.repository.getId() + "] " + this.repository.getBasedir() );
- stats.reset();
- stats.timestampStarted = System.currentTimeMillis();
+ log.info( "Walk Started: [" + this.repository.getId() + "] " + this.repository.getRepositoryURL() );
+ stats.triggerStart();
}
public void directoryWalkStep( int percentage, File file )
{
log.debug( "Walk Step: " + percentage + ", " + file );
+
+ stats.increaseFileCount();
// Timestamp finished points to the last successful scan, not this current one.
if ( file.lastModified() < onlyModifiedAfterTimestamp )
{
// Skip file as no change has occured.
log.debug( "Skipping, No Change: " + file.getAbsolutePath() );
- stats.filesSkipped++;
return;
}
synchronized ( consumers )
{
- stats.filesIncluded++;
+ stats.increaseNewFileCount();
- BaseFile basefile = new BaseFile( repository.getBasedir(), file );
+ BaseFile basefile = new BaseFile( repository.getRepositoryURL().getPath(), file );
Iterator itConsumers = this.consumers.iterator();
while ( itConsumers.hasNext() )
try
{
log.debug( "Sending to consumer: " + consumer.getName() );
- stats.filesConsumed++;
consumer.processFile( basefile );
}
catch ( Exception e )
public void directoryWalkFinished()
{
- log.info( "Walk Finished: [" + this.repository.getId() + "] " + this.repository.getBasedir() );
- stats.timestampFinished = System.currentTimeMillis();
+ log.info( "Walk Finished: [" + this.repository.getId() + "] " + this.repository.getRepositoryURL() );
+ stats.triggerFinished();
}
private boolean wantsFile( Consumer consumer, String relativePath )
+++ /dev/null
-package org.apache.maven.archiva.repository.scanner;
-
-/*
- * 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.
- */
-
-import org.apache.commons.lang.math.NumberUtils;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.util.IOUtil;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Properties;
-
-/**
- * ScanStatistics
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class ScanStatistics
-{
- private static final String PROP_FILES_CONSUMED = "scan.consumed.files";
-
- private static final String PROP_FILES_INCLUDED = "scan.included.files";
-
- private static final String PROP_FILES_SKIPPED = "scan.skipped.files";
-
- private static final String PROP_TIMESTAMP_STARTED = "scan.started.timestamp";
-
- private static final String PROP_TIMESTAMP_FINISHED = "scan.finished.timestamp";
-
- protected long timestampStarted = 0;
-
- protected long timestampFinished = 0;
-
- protected long filesIncluded = 0;
-
- protected long filesConsumed = 0;
-
- protected long filesSkipped = 0;
-
- private ArtifactRepository repository;
-
- public ScanStatistics( ArtifactRepository repository )
- {
- this.repository = repository;
- }
-
- public void load( String filename )
- throws IOException
- {
- File repositoryBase = new File( this.repository.getBasedir() );
-
- File scanProperties = new File( repositoryBase, filename );
- FileInputStream fis = null;
- try
- {
- Properties props = new Properties();
- fis = new FileInputStream( scanProperties );
- props.load( fis );
-
- timestampFinished = NumberUtils.toLong( props.getProperty( PROP_TIMESTAMP_FINISHED ), 0 );
- timestampStarted = NumberUtils.toLong( props.getProperty( PROP_TIMESTAMP_STARTED ), 0 );
- filesIncluded = NumberUtils.toLong( props.getProperty( PROP_FILES_INCLUDED ), 0 );
- filesConsumed = NumberUtils.toLong( props.getProperty( PROP_FILES_CONSUMED ), 0 );
- filesSkipped = NumberUtils.toLong( props.getProperty( PROP_FILES_SKIPPED ), 0 );
- }
- catch ( IOException e )
- {
- reset();
- throw e;
- }
- finally
- {
- IOUtil.close( fis );
- }
- }
-
- public void save( String filename )
- throws IOException
- {
- Properties props = new Properties();
- props.setProperty( PROP_TIMESTAMP_FINISHED, String.valueOf( timestampFinished ) );
- props.setProperty( PROP_TIMESTAMP_STARTED, String.valueOf( timestampStarted ) );
- props.setProperty( PROP_FILES_INCLUDED, String.valueOf( filesIncluded ) );
- props.setProperty( PROP_FILES_CONSUMED, String.valueOf( filesConsumed ) );
- props.setProperty( PROP_FILES_SKIPPED, String.valueOf( filesSkipped ) );
-
- File repositoryBase = new File( this.repository.getBasedir() );
- File statsFile = new File( repositoryBase, filename );
-
- FileOutputStream fos = null;
- try
- {
- fos = new FileOutputStream( statsFile );
- props.store( fos, "Last Scan Information, managed by Archiva. DO NOT EDIT" );
- fos.flush();
- }
- finally
- {
- IOUtil.close( fos );
- }
- }
-
- public void reset()
- {
- timestampStarted = 0;
- timestampFinished = 0;
- filesIncluded = 0;
- filesConsumed = 0;
- filesSkipped = 0;
- }
-
- public long getElapsedMilliseconds()
- {
- return timestampFinished - timestampStarted;
- }
-
- public long getFilesConsumed()
- {
- return filesConsumed;
- }
-
- public long getFilesIncluded()
- {
- return filesIncluded;
- }
-
- public ArtifactRepository getRepository()
- {
- return repository;
- }
-
- public long getTimestampFinished()
- {
- return timestampFinished;
- }
-
- public long getTimestampStarted()
- {
- return timestampStarted;
- }
-
- public long getFilesSkipped()
- {
- return filesSkipped;
- }
-
- public void setTimestampFinished( long timestampFinished )
- {
- this.timestampFinished = timestampFinished;
- }
-
- public void setTimestampStarted( long timestampStarted )
- {
- this.timestampStarted = timestampStarted;
- }
-
- public void dump( Logger logger )
- {
- logger.info( "----------------------------------------------------" );
- logger.info( "Scan of Repository: " + repository.getId() );
- logger.info( " Started : " + toHumanTimestamp( this.getTimestampStarted() ) );
- logger.info( " Finished: " + toHumanTimestamp( this.getTimestampFinished() ) );
- // TODO: pretty print ellapsed time.
- logger.info( " Duration: " + this.getElapsedMilliseconds() + "ms" );
- logger.info( " Files : " + this.getFilesIncluded() );
- logger.info( " Consumed: " + this.getFilesConsumed() );
- logger.info( " Skipped : " + this.getFilesSkipped() );
- }
-
- private String toHumanTimestamp( long timestamp )
- {
- SimpleDateFormat dateFormat = new SimpleDateFormat();
- return dateFormat.format( new Date( timestamp ) );
- }
-}
* under the License.
*/
+import org.apache.maven.archiva.common.utils.RepositoryURL;
+
import java.net.MalformedURLException;
import junit.framework.TestCase;
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-common</artifactId>
- <version>${pom.version}</version>
+ <version>${archiva.version}</version>
</dependency>
<!--
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-common</artifactId>
- <version>${pom.version}</version>
+ <version>${archiva.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-core</artifactId>
- <version>${pom.version}</version>
+ <version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-reports-standard</artifactId>
- <version>${pom.version}</version>
+ <version>${archiva.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-model</artifactId>
+ <version>${archiva.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-database</artifactId>
+ <version>${archiva.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-consumer-api</artifactId>
+ <version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-discoverer</artifactId>
- <version>${pom.version}</version>
+ <version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-repository-layer</artifactId>
- <version>${pom.version}</version>
+ <version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-indexer</artifactId>
- <version>${pom.version}</version>
+ <version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-proxy</artifactId>
- <version>${pom.version}</version>
+ <version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-applet</artifactId>
- <version>${pom.version}</version>
+ <version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-security</artifactId>
- <version>${pom.version}</version>
+ <version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-configuration</artifactId>
- <version>${pom.version}</version>
+ <version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-converter</artifactId>
- <version>${pom.version}</version>
+ <version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-utils</artifactId>
- <version>${pom.version}</version>
+ <version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-webapp</artifactId>
- <version>${pom.version}</version>
+ <version>${archiva.version}</version>
<type>war</type>
</dependency>
<dependency>
</pluginRepository>
</pluginRepositories>
<properties>
+ <archiva.version>1.0-SNAPSHOT</archiva.version>
<maven.version>2.0.5</maven.version>
<wagon.version>1.0-beta-2</wagon.version>
<plexus-security.version>1.0-alpha-11-SNAPSHOT</plexus-security.version>