From: Joakim Erdfelt Date: Thu, 15 Mar 2007 16:48:40 +0000 (+0000) Subject: Partial work against jpox database refactoring. X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dd498ec7dd22d318d914b40207d8a529598b80fe;p=archiva.git Partial work against jpox database refactoring. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@518686 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/AbstractConsumer.java b/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/AbstractConsumer.java deleted file mode 100644 index 603434630..000000000 --- a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/AbstractConsumer.java +++ /dev/null @@ -1,66 +0,0 @@ -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 Joakim Erdfelt - * @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; - } -} diff --git a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/Consumer.java b/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/Consumer.java deleted file mode 100644 index fad6f2fa8..000000000 --- a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/Consumer.java +++ /dev/null @@ -1,90 +0,0 @@ -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 Joakim Erdfelt - * @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 ); -} diff --git a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/ConsumerException.java b/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/ConsumerException.java deleted file mode 100644 index 0c4c6451a..000000000 --- a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/ConsumerException.java +++ /dev/null @@ -1,52 +0,0 @@ -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 Joakim Erdfelt - * @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; - } -} diff --git a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/ConsumerFactory.java b/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/ConsumerFactory.java deleted file mode 100644 index eb08afef4..000000000 --- a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/ConsumerFactory.java +++ /dev/null @@ -1,70 +0,0 @@ -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 Joakim Erdfelt - * @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 ); - } -} diff --git a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/GenericArtifactConsumer.java b/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/GenericArtifactConsumer.java deleted file mode 100644 index c9e5437b7..000000000 --- a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/GenericArtifactConsumer.java +++ /dev/null @@ -1,130 +0,0 @@ -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 Joakim Erdfelt - * @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; - } -} diff --git a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/GenericModelConsumer.java b/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/GenericModelConsumer.java deleted file mode 100644 index efcd7af64..000000000 --- a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/GenericModelConsumer.java +++ /dev/null @@ -1,98 +0,0 @@ -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 Joakim Erdfelt - * @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; - } -} diff --git a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/GenericRepositoryMetadataConsumer.java b/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/GenericRepositoryMetadataConsumer.java deleted file mode 100644 index 1f4433c49..000000000 --- a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/consumers/GenericRepositoryMetadataConsumer.java +++ /dev/null @@ -1,231 +0,0 @@ -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 Joakim Erdfelt - * @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; - } -} diff --git a/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/RepositoryURL.java b/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/RepositoryURL.java new file mode 100644 index 000000000..5ad550e6e --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/RepositoryURL.java @@ -0,0 +1,156 @@ +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 Joakim Erdfelt + * @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; + } +} diff --git a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/AbstractArchivaCommonTestCase.java b/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/AbstractArchivaCommonTestCase.java index 11b2d1c2c..4ee9785d0 100644 --- a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/AbstractArchivaCommonTestCase.java +++ b/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/AbstractArchivaCommonTestCase.java @@ -23,12 +23,9 @@ import org.apache.maven.artifact.repository.ArtifactRepository; 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; /** @@ -40,48 +37,6 @@ 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 { diff --git a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/AllTests.java b/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/AllTests.java index 878f7fe1a..b6bde475a 100644 --- a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/AllTests.java +++ b/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/AllTests.java @@ -36,7 +36,6 @@ public class AllTests 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; diff --git a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/AbstractGenericConsumerTestCase.java b/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/AbstractGenericConsumerTestCase.java deleted file mode 100644 index 08abd6432..000000000 --- a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/AbstractGenericConsumerTestCase.java +++ /dev/null @@ -1,52 +0,0 @@ -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 Joakim Erdfelt - * @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(); - } -} diff --git a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/AllTests.java b/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/AllTests.java deleted file mode 100644 index b04c4c37c..000000000 --- a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/AllTests.java +++ /dev/null @@ -1,43 +0,0 @@ -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 Joakim Erdfelt - * @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; - } - -} diff --git a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/FileProblemsTracker.java b/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/FileProblemsTracker.java deleted file mode 100644 index 82a32f525..000000000 --- a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/FileProblemsTracker.java +++ /dev/null @@ -1,114 +0,0 @@ -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 Joakim Erdfelt - * @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; - } - -} diff --git a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/GenericArtifactConsumerTest.java b/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/GenericArtifactConsumerTest.java deleted file mode 100644 index 1ff2d1ebb..000000000 --- a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/GenericArtifactConsumerTest.java +++ /dev/null @@ -1,220 +0,0 @@ -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 Joakim Erdfelt - * @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 ); - } -} diff --git a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/MockArtifactConsumer.java b/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/MockArtifactConsumer.java deleted file mode 100644 index 94fb5ca3e..000000000 --- a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/MockArtifactConsumer.java +++ /dev/null @@ -1,71 +0,0 @@ -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 Joakim Erdfelt - * @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 diff --git a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/MockModelConsumer.java b/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/MockModelConsumer.java deleted file mode 100644 index 969f10b52..000000000 --- a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/MockModelConsumer.java +++ /dev/null @@ -1,70 +0,0 @@ -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 Joakim Erdfelt - * @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 diff --git a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/MockRepositoryMetadataConsumer.java b/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/MockRepositoryMetadataConsumer.java deleted file mode 100644 index d10331adf..000000000 --- a/archiva-jpox-database-refactor/archiva-common/src/test/java/org/apache/maven/archiva/common/consumers/MockRepositoryMetadataConsumer.java +++ /dev/null @@ -1,69 +0,0 @@ -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 Joakim Erdfelt - * @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 diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/pom.xml b/archiva-jpox-database-refactor/archiva-consumer-api/pom.xml new file mode 100755 index 000000000..b305f96c2 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/pom.xml @@ -0,0 +1,61 @@ + + + + + + org.apache.maven.archiva + archiva + 1.0-SNAPSHOT + + 4.0.0 + archiva-consumer-api + Archiva Consumer API + + + org.apache.maven.archiva + archiva-model + + + org.codehaus.plexus + plexus-utils + + + org.codehaus.plexus + plexus-container-default + + + commons-lang + commons-lang + + + commons-io + commons-io + + + + + + org.codehaus.plexus + plexus-maven-plugin + + + + diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractConsumer.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractConsumer.java new file mode 100644 index 000000000..200844a11 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractConsumer.java @@ -0,0 +1,66 @@ +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 Joakim Erdfelt + * @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; + } +} diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/Consumer.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/Consumer.java new file mode 100644 index 000000000..2ed0f1b72 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/Consumer.java @@ -0,0 +1,91 @@ +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 Joakim Erdfelt + * @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 ); +} diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerException.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerException.java new file mode 100644 index 000000000..790620b0c --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerException.java @@ -0,0 +1,52 @@ +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 Joakim Erdfelt + * @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; + } +} diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerFactory.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerFactory.java new file mode 100644 index 000000000..d95bfda0e --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerFactory.java @@ -0,0 +1,70 @@ +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 Joakim Erdfelt + * @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 ); + } +} diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/GenericArtifactConsumer.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/GenericArtifactConsumer.java new file mode 100644 index 000000000..4c6f57bdb --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/GenericArtifactConsumer.java @@ -0,0 +1,130 @@ +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 Joakim Erdfelt + * @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; + } +} diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/GenericModelConsumer.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/GenericModelConsumer.java new file mode 100644 index 000000000..4fe0c429b --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/GenericModelConsumer.java @@ -0,0 +1,98 @@ +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 Joakim Erdfelt + * @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; + } +} diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/GenericRepositoryMetadataConsumer.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/GenericRepositoryMetadataConsumer.java new file mode 100644 index 000000000..a575f156a --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/GenericRepositoryMetadataConsumer.java @@ -0,0 +1,231 @@ +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 Joakim Erdfelt + * @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; + } +} diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/AbstractConsumerTestCase.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/AbstractConsumerTestCase.java new file mode 100644 index 000000000..dc35fc44d --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/AbstractConsumerTestCase.java @@ -0,0 +1,152 @@ +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 Joakim Erdfelt + * @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; + } +} diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/AbstractGenericConsumerTestCase.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/AbstractGenericConsumerTestCase.java new file mode 100644 index 000000000..db51092e3 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/AbstractGenericConsumerTestCase.java @@ -0,0 +1,51 @@ +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 Joakim Erdfelt + * @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(); + } +} diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/AllTests.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/AllTests.java new file mode 100644 index 000000000..783fb8547 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/AllTests.java @@ -0,0 +1,43 @@ +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 Joakim Erdfelt + * @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; + } + +} diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/FileProblemsTracker.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/FileProblemsTracker.java new file mode 100644 index 000000000..35457c4b1 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/FileProblemsTracker.java @@ -0,0 +1,115 @@ +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 Joakim Erdfelt + * @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; + } + +} diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/GenericArtifactConsumerTest.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/GenericArtifactConsumerTest.java new file mode 100644 index 000000000..27111ac1e --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/GenericArtifactConsumerTest.java @@ -0,0 +1,220 @@ +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 Joakim Erdfelt + * @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 ); + } +} diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/MockArtifactConsumer.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/MockArtifactConsumer.java new file mode 100644 index 000000000..2d1ccfe3c --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/MockArtifactConsumer.java @@ -0,0 +1,71 @@ +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 Joakim Erdfelt + * @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 diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/MockModelConsumer.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/MockModelConsumer.java new file mode 100644 index 000000000..b52ec372c --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/MockModelConsumer.java @@ -0,0 +1,71 @@ +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 Joakim Erdfelt + * @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 diff --git a/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/MockRepositoryMetadataConsumer.java b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/MockRepositoryMetadataConsumer.java new file mode 100644 index 000000000..a9a63eab5 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-consumer-api/src/test/java/org/apache/maven/archiva/consumers/MockRepositoryMetadataConsumer.java @@ -0,0 +1,70 @@ +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 Joakim Erdfelt + * @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 diff --git a/archiva-jpox-database-refactor/archiva-converter/pom.xml b/archiva-jpox-database-refactor/archiva-converter/pom.xml index 49bde7bd2..a8fefa798 100644 --- a/archiva-jpox-database-refactor/archiva-converter/pom.xml +++ b/archiva-jpox-database-refactor/archiva-converter/pom.xml @@ -29,6 +29,10 @@ archiva-converter Archiva Repository Converter + + org.apache.maven.archiva + archiva-consumer-api + org.apache.maven.archiva archiva-discoverer diff --git a/archiva-jpox-database-refactor/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyConverterArtifactConsumer.java b/archiva-jpox-database-refactor/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyConverterArtifactConsumer.java index a5b758c4b..03e9d47d0 100644 --- a/archiva-jpox-database-refactor/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyConverterArtifactConsumer.java +++ b/archiva-jpox-database-refactor/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyConverterArtifactConsumer.java @@ -19,8 +19,8 @@ package org.apache.maven.archiva.converter.legacy; * 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; diff --git a/archiva-jpox-database-refactor/archiva-core/pom.xml b/archiva-jpox-database-refactor/archiva-core/pom.xml index 09daa2d48..a1cec5ad3 100644 --- a/archiva-jpox-database-refactor/archiva-core/pom.xml +++ b/archiva-jpox-database-refactor/archiva-core/pom.xml @@ -29,6 +29,10 @@ archiva-core Archiva Core + + org.apache.maven.archiva + archiva-consumer-api + org.apache.maven.archiva archiva-configuration diff --git a/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/consumers/ArtifactHealthConsumer.java b/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/consumers/ArtifactHealthConsumer.java index d20594f08..f0eb8843f 100644 --- a/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/consumers/ArtifactHealthConsumer.java +++ b/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/consumers/ArtifactHealthConsumer.java @@ -19,7 +19,6 @@ package org.apache.maven.archiva.consumers; * 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; diff --git a/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/consumers/IndexArtifactConsumer.java b/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/consumers/IndexArtifactConsumer.java index 2d7026bb1..f89bd5109 100644 --- a/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/consumers/IndexArtifactConsumer.java +++ b/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/consumers/IndexArtifactConsumer.java @@ -19,7 +19,6 @@ package org.apache.maven.archiva.consumers; * 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; diff --git a/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/consumers/RepositoryMetadataHealthConsumer.java b/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/consumers/RepositoryMetadataHealthConsumer.java index d858d32cd..0c56768b1 100644 --- a/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/consumers/RepositoryMetadataHealthConsumer.java +++ b/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/consumers/RepositoryMetadataHealthConsumer.java @@ -19,7 +19,6 @@ package org.apache.maven.archiva.consumers; * 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; diff --git a/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/executors/DataRefreshExecutor.java b/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/executors/DataRefreshExecutor.java index e95014360..0d92adf71 100644 --- a/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/executors/DataRefreshExecutor.java +++ b/archiva-jpox-database-refactor/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/executors/DataRefreshExecutor.java @@ -19,13 +19,13 @@ package org.apache.maven.archiva.scheduler.executors; * 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; diff --git a/archiva-jpox-database-refactor/archiva-database/pom.xml b/archiva-jpox-database-refactor/archiva-database/pom.xml index f978fdd2f..32ede8488 100755 --- a/archiva-jpox-database-refactor/archiva-database/pom.xml +++ b/archiva-jpox-database-refactor/archiva-database/pom.xml @@ -30,30 +30,37 @@ Archiva Database - org.apache.ibatis - ibatis-sqlmap - 2.3.0 - - - org.apache.maven - maven-artifact-manager - - - org.apache.maven - maven-project - - - org.apache.maven - maven-repository-metadata + org.apache.maven.archiva + archiva-model + 1.0-SNAPSHOT org.codehaus.plexus - plexus-ibatis - 1.0-SNAPSHOT + plexus-jdo2 + 1.0-alpha-8 + + + xerces + xercesImpl + + + xerces + xmlParserAPIs + + - org.codehaus.plexus - plexus-utils + jpox + jpox + 1.1.7 + compile + + + + javax.sql + jdbc-stdext + + org.codehaus.plexus diff --git a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/AbstractIbatisStore.java b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/AbstractIbatisStore.java deleted file mode 100644 index 0e25a028c..000000000 --- a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/AbstractIbatisStore.java +++ /dev/null @@ -1,180 +0,0 @@ -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 Joakim Erdfelt - * @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(); - } - } - } - - -} diff --git a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/AbstractMetadataKeyDatabase.java b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/AbstractMetadataKeyDatabase.java deleted file mode 100644 index dda52114a..000000000 --- a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/AbstractMetadataKeyDatabase.java +++ /dev/null @@ -1,288 +0,0 @@ -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 Jesse McConnell - * @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(); - } - } -} - -} diff --git a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java new file mode 100644 index 000000000..ef56ad1b1 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java @@ -0,0 +1,110 @@ +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 Joakim Erdfelt + * @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 /**/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 /**/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 /**/queryArtifacts( Constraint constraint ) + throws ObjectNotFoundException, ArchivaDatabaseException; + + public ArchivaArtifact saveArtifact( ArchivaArtifact artifact ) + throws ArchivaDatabaseException; + + public void deleteArtifact( ArchivaArtifact artifact ) + throws ArchivaDatabaseException; + +} diff --git a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/Constraint.java b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/Constraint.java new file mode 100644 index 000000000..eac67f913 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/Constraint.java @@ -0,0 +1,42 @@ +package org.apache.maven.archiva.database; + +/** + * Constraint + * + * @author Joakim Erdfelt + * @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(); +} diff --git a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/ObjectNotFoundException.java b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/ObjectNotFoundException.java new file mode 100644 index 000000000..e9dfc01d0 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/ObjectNotFoundException.java @@ -0,0 +1,53 @@ +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 Joakim Erdfelt + * @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; + } +} diff --git a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryMetadataDatabase.java b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryMetadataDatabase.java deleted file mode 100644 index 5434e6071..000000000 --- a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryMetadataDatabase.java +++ /dev/null @@ -1,232 +0,0 @@ -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 Joakim Erdfelt - * @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 ); - } - } - - -} diff --git a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/artifact/ArtifactKey.java b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/artifact/ArtifactKey.java deleted file mode 100644 index e1f00ab98..000000000 --- a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/artifact/ArtifactKey.java +++ /dev/null @@ -1,101 +0,0 @@ -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 Joakim Erdfelt - * @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; - } -} diff --git a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/artifact/ArtifactPersistence.java b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/artifact/ArtifactPersistence.java deleted file mode 100644 index d59cbf9cc..000000000 --- a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/artifact/ArtifactPersistence.java +++ /dev/null @@ -1,137 +0,0 @@ -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 Joakim Erdfelt - * @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 ) - { - - } - -} diff --git a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArchivaRepositoryByUrlConstraint.java b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArchivaRepositoryByUrlConstraint.java new file mode 100644 index 000000000..8abc14bec --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArchivaRepositoryByUrlConstraint.java @@ -0,0 +1,40 @@ +package org.apache.maven.archiva.database.constraints; + +import org.apache.maven.archiva.database.Constraint; + +/** + * ArchivaRepositoryByUrlConstraint + * + * @author Joakim Erdfelt + * @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; + } +} diff --git a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java new file mode 100644 index 000000000..7ab55087e --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java @@ -0,0 +1,459 @@ +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 Joakim Erdfelt + * @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; + } + +} diff --git a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java new file mode 100644 index 000000000..00af94585 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java @@ -0,0 +1,182 @@ +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 Joakim Erdfelt + * @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 + + } + +} diff --git a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/key/MetadataKey.java b/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/key/MetadataKey.java deleted file mode 100644 index b06e03b17..000000000 --- a/archiva-jpox-database-refactor/archiva-database/src/main/java/org/apache/maven/archiva/database/key/MetadataKey.java +++ /dev/null @@ -1,46 +0,0 @@ -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; - } - - - -} diff --git a/archiva-jpox-database-refactor/archiva-database/src/test/java/org/apache/maven/archiva/database/RepositoryMetadataDatabaseTest.java b/archiva-jpox-database-refactor/archiva-database/src/test/java/org/apache/maven/archiva/database/RepositoryMetadataDatabaseTest.java deleted file mode 100644 index 070e54958..000000000 --- a/archiva-jpox-database-refactor/archiva-database/src/test/java/org/apache/maven/archiva/database/RepositoryMetadataDatabaseTest.java +++ /dev/null @@ -1,87 +0,0 @@ -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 Joakim Erdfelt - * @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" ) ); - - } - - -} diff --git a/archiva-jpox-database-refactor/archiva-database/src/test/java/org/apache/maven/archiva/database/artifact/ArtifactPersistenceTest.java b/archiva-jpox-database-refactor/archiva-database/src/test/java/org/apache/maven/archiva/database/artifact/ArtifactPersistenceTest.java deleted file mode 100644 index 007e027b2..000000000 --- a/archiva-jpox-database-refactor/archiva-database/src/test/java/org/apache/maven/archiva/database/artifact/ArtifactPersistenceTest.java +++ /dev/null @@ -1,70 +0,0 @@ -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 Joakim Erdfelt - * @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 ); - } -} diff --git a/archiva-jpox-database-refactor/archiva-discoverer/pom.xml b/archiva-jpox-database-refactor/archiva-discoverer/pom.xml index 8a96e39c5..e32a38447 100755 --- a/archiva-jpox-database-refactor/archiva-discoverer/pom.xml +++ b/archiva-jpox-database-refactor/archiva-discoverer/pom.xml @@ -29,6 +29,10 @@ archiva-discoverer Archiva Discoverer + + org.apache.maven.archiva + archiva-consumer-api + org.apache.maven.archiva archiva-common diff --git a/archiva-jpox-database-refactor/archiva-discoverer/src/main/java/org/apache/maven/archiva/discoverer/DefaultDiscoverer.java b/archiva-jpox-database-refactor/archiva-discoverer/src/main/java/org/apache/maven/archiva/discoverer/DefaultDiscoverer.java index bd5e4fd44..8a6a61855 100644 --- a/archiva-jpox-database-refactor/archiva-discoverer/src/main/java/org/apache/maven/archiva/discoverer/DefaultDiscoverer.java +++ b/archiva-jpox-database-refactor/archiva-discoverer/src/main/java/org/apache/maven/archiva/discoverer/DefaultDiscoverer.java @@ -19,7 +19,7 @@ package org.apache.maven.archiva.discoverer; * 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; diff --git a/archiva-jpox-database-refactor/archiva-discoverer/src/main/java/org/apache/maven/archiva/discoverer/RepositoryScanner.java b/archiva-jpox-database-refactor/archiva-discoverer/src/main/java/org/apache/maven/archiva/discoverer/RepositoryScanner.java index 8eef2b766..9a37ac4a8 100644 --- a/archiva-jpox-database-refactor/archiva-discoverer/src/main/java/org/apache/maven/archiva/discoverer/RepositoryScanner.java +++ b/archiva-jpox-database-refactor/archiva-discoverer/src/main/java/org/apache/maven/archiva/discoverer/RepositoryScanner.java @@ -20,8 +20,8 @@ package org.apache.maven.archiva.discoverer; */ 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; diff --git a/archiva-jpox-database-refactor/archiva-discoverer/src/test/java/org/apache/maven/archiva/discoverer/MockConsumer.java b/archiva-jpox-database-refactor/archiva-discoverer/src/test/java/org/apache/maven/archiva/discoverer/MockConsumer.java index 7f081c955..e6b7b14fe 100644 --- a/archiva-jpox-database-refactor/archiva-discoverer/src/test/java/org/apache/maven/archiva/discoverer/MockConsumer.java +++ b/archiva-jpox-database-refactor/archiva-discoverer/src/test/java/org/apache/maven/archiva/discoverer/MockConsumer.java @@ -3,9 +3,9 @@ */ 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; diff --git a/archiva-jpox-database-refactor/archiva-model/pom.xml b/archiva-jpox-database-refactor/archiva-model/pom.xml index 5325f20e4..007df7295 100755 --- a/archiva-jpox-database-refactor/archiva-model/pom.xml +++ b/archiva-jpox-database-refactor/archiva-model/pom.xml @@ -30,16 +30,8 @@ Archiva Model - org.apache.maven - maven-artifact-manager - - - org.apache.maven - maven-project - - - org.apache.maven - maven-repository-metadata + org.apache.maven.archiva + archiva-common org.codehaus.plexus @@ -64,6 +56,62 @@ org.codehaus.plexus plexus-maven-plugin + + org.codehaus.modello + modello-maven-plugin + 1.0-alpha-15-SNAPSHOT + + 1.0.0 + false + src/main/mdo/archiva.xml + + + + modello-java + + java + jpox-metadata-class + + + + + jpox-jdo-mapping + + jpox-jdo-mapping + + + ${basedir}/target/classes/org/apache/maven/archiva/model/ + + + + + + org.codehaus.mojo + jpox-maven-plugin + 1.1.6 + + + + enhance + + + + + + org.codehaus.mojo + cobertura-maven-plugin + + + + + org/apache/maven/archiva/reporting/model/** + + + + diff --git a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/AbstractArchivaArtifact.java b/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/AbstractArchivaArtifact.java new file mode 100644 index 000000000..df9d773f2 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/AbstractArchivaArtifact.java @@ -0,0 +1,139 @@ +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 Joakim Erdfelt + * @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." ); + } + } +} diff --git a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/AbstractArchivaRepository.java b/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/AbstractArchivaRepository.java new file mode 100644 index 000000000..347f68d47 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/AbstractArchivaRepository.java @@ -0,0 +1,125 @@ +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 Joakim Erdfelt + * @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() ); + } +} diff --git a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/ArchivaArtifact.java b/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/ArchivaArtifact.java deleted file mode 100644 index 0e1bceb02..000000000 --- a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/ArchivaArtifact.java +++ /dev/null @@ -1,166 +0,0 @@ -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 Joakim Erdfelt - * @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." ); - } - } -} diff --git a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/ArchivaRepositoryMetadata.java b/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/ArchivaRepositoryMetadata.java deleted file mode 100644 index cfed04f40..000000000 --- a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/ArchivaRepositoryMetadata.java +++ /dev/null @@ -1,77 +0,0 @@ -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 Joakim Erdfelt - * @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; - } - -} diff --git a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/RepositoryContent.java b/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/RepositoryContent.java deleted file mode 100644 index 3a195dfcc..000000000 --- a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/RepositoryContent.java +++ /dev/null @@ -1,33 +0,0 @@ -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 Joakim Erdfelt - * @version $Id$ - */ -public interface RepositoryContent -{ - public RepositoryContentKey getRepositoryContentKey(); - - public void setRepositoryContentKey( RepositoryContentKey key ); -} diff --git a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/RepositoryContentKey.java b/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/RepositoryContentKey.java index 4880c0505..a198eaec2 100644 --- a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/RepositoryContentKey.java +++ b/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/RepositoryContentKey.java @@ -19,69 +19,152 @@ package org.apache.maven.archiva.model; * 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 Joakim Erdfelt * @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; } } diff --git a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/health/ArtifactHealth.java b/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/health/ArtifactHealth.java deleted file mode 100644 index e26435c41..000000000 --- a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/health/ArtifactHealth.java +++ /dev/null @@ -1,63 +0,0 @@ -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 Joakim Erdfelt - * @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; - } -} diff --git a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/health/HealthProblem.java b/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/health/HealthProblem.java deleted file mode 100644 index f437be21a..000000000 --- a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/health/HealthProblem.java +++ /dev/null @@ -1,77 +0,0 @@ -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 Joakim Erdfelt - * @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; - } -} diff --git a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/health/RepositoryMetadataHealth.java b/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/health/RepositoryMetadataHealth.java deleted file mode 100644 index 32e0257e1..000000000 --- a/archiva-jpox-database-refactor/archiva-model/src/main/java/org/apache/maven/archiva/model/health/RepositoryMetadataHealth.java +++ /dev/null @@ -1,63 +0,0 @@ -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 Joakim Erdfelt - * @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; - } -} diff --git a/archiva-jpox-database-refactor/archiva-model/src/main/mdo/archiva.xml b/archiva-jpox-database-refactor/archiva-model/src/main/mdo/archiva.xml new file mode 100644 index 000000000..1caa7850d --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-model/src/main/mdo/archiva.xml @@ -0,0 +1,454 @@ + + + archiva-model + ArchivaModel + 1.0.0 + Archiva Model + + + package + org.apache.maven.archiva.model + + + + + + ArchivaDatabase + 1.0.0+ + + + Repositories + 1.0.0+ + + ArchivaRepository + * + + + + + + AbstractArchivaRepository + ArchivaRepository + 1.0.0+ + + + id + true + 1.0.0+ + String + true + + The unique ID for the repository. + + + + name + false + 1.0.0+ + String + true + + The Name of the repository. + + + + url + false + 1.0.0+ + String + true + + The URL of the repository. + + + + creationSource + false + 1.0.0+ + String + true + + The Source of this repository. + (Example: Configuration, POM) + + + + layoutName + false + 1.0.0+ + String + true + + The layout of the repository. + (Either 'default', or 'legacy') + + + + releasePolicy + false + 1.0.0+ + String + true + + The releases policy of the repository. + + + + snapshotPolicy + false + 1.0.0+ + String + true + + The snapshot policy of the repository. + + + + + + RepositoryContent + 1.0.0+ + + Repository Content Identifier. + + + + groupId + true + 1.0.0+ + String + true + + The Group ID of the repository content. + + + + artifactId + true + 1.0.0+ + String + true + + The Artifact ID of the repository content. + + + + version + true + 1.0.0+ + String + false + + The version of the repository content. + + + + repositoryId + true + 1.0.0+ + true + String + + The repository associated with this content. + + + + + + 1.0.0+ + + 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 ); + } + + + + + + ArchivaArtifact + 1.0.0+ + + + contentKey + true + 1.0.0+ + true + + RepositoryContent + 1 + + + The content key for this artifact. + + + + classifier + false + 1.0.0+ + String + false + + The classifier for this artifact. + + + + type + true + 1.0.0+ + String + true + + The type of artifact. + + + + + + ArchivaRepositoryMetadata + 1.0.0+ + + + contentKey + true + 1.0.0+ + true + + RepositoryContent + 1 + + + The content key for this repository metadata. + + + + releasedVersion + false + 1.0.0+ + false + String + + The released version id. + + + + availableVersions + false + 1.0.0+ + false + + String + * + + + The list of available version ids. + + + + + + HealthProblem + 1.0.0+ + + + type + false + 1.0.0+ + true + String + + The type of health problem. + + + + origin + false + 1.0.0+ + true + String + + The origin of the health problem. + + + + message + false + 1.0.0+ + true + String + + The origin of the health problem. + + + + + + ArchivaArtifactHealth + 1.0.0+ + + + artifact + true + 1.0.0+ + true + + ArchivaArtifact + 1 + + + The Artifact to report on. + + + + problems + false + 1.0.0+ + false + + HealthProblem + * + + + The list of problems associated with this artifact. + + + + + + ArchivaRepositoryMetadataHealth + 1.0.0+ + + + repositoryMetadata + true + 1.0.0+ + true + + ArchivaRepositoryMetadata + 1 + + + The ArchivaRepositoryMetadata to report on. + + + + problems + false + 1.0.0+ + false + + HealthProblem + * + + + The list of problems associated with this repository metadata. + + + + + + RepositoryContentStatistics + 1.0.0+ + + + repositoryId + 1.0.0+ + false + true + String + + The repository id the statistics belong to. + + + + whenGathered + 1.0.0+ + false + true + Date + + The timestamp on when this set of statistics was gathered. + + + + duration + 1.0.0+ + false + true + long + + The duration (in milliseconds) for the gathering of the statistics. + + + + totalFileCount + 1.0.0+ + false + true + long + + The total number of files in the repository. + + + + newFileCount + 1.0.0+ + false + true + long + + The number of new files discovered. + + + + + + 1.0.0+ + + 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++; + } + + + + + + diff --git a/archiva-jpox-database-refactor/archiva-repository-layer/pom.xml b/archiva-jpox-database-refactor/archiva-repository-layer/pom.xml index b8488712a..b0a50cae9 100644 --- a/archiva-jpox-database-refactor/archiva-repository-layer/pom.xml +++ b/archiva-jpox-database-refactor/archiva-repository-layer/pom.xml @@ -30,10 +30,19 @@ archiva-repository-layer Archiva Repository Interface Layer + + org.apache.maven.archiva + archiva-consumer-api + org.apache.maven.archiva archiva-common + + org.apache.maven.archiva + archiva-model + 1.0-SNAPSHOT + org.codehaus.plexus plexus-utils diff --git a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/DefinedRepositories.java b/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/DefinedRepositories.java deleted file mode 100644 index d86427d26..000000000 --- a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/DefinedRepositories.java +++ /dev/null @@ -1,74 +0,0 @@ -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 Joakim Erdfelt - * @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 ); -} diff --git a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/Repository.java b/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/Repository.java deleted file mode 100644 index 920b68dc4..000000000 --- a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/Repository.java +++ /dev/null @@ -1,211 +0,0 @@ -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 Joakim Erdfelt - * @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 ); - } - -} diff --git a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/RepositoryURL.java b/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/RepositoryURL.java deleted file mode 100644 index 13ed57fc9..000000000 --- a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/RepositoryURL.java +++ /dev/null @@ -1,156 +0,0 @@ -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 Joakim Erdfelt - * @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; - } -} diff --git a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/connector/RepositoryConnector.java b/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/connector/RepositoryConnector.java index 345f33c25..3d70058fd 100644 --- a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/connector/RepositoryConnector.java +++ b/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/connector/RepositoryConnector.java @@ -19,7 +19,7 @@ package org.apache.maven.archiva.repository.connector; * under the License. */ -import org.apache.maven.archiva.repository.Repository; +import org.apache.maven.archiva.model.ArchivaRepository; import java.util.List; @@ -31,9 +31,9 @@ import java.util.List; */ public interface RepositoryConnector { - public Repository getSourceRepository(); + public ArchivaRepository getSourceRepository(); - public Repository getTargetRepository(); + public ArchivaRepository getTargetRepository(); public List getBlacklist(); diff --git a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/BidirectionalRepositoryLayout.java b/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/BidirectionalRepositoryLayout.java new file mode 100644 index 000000000..9f10e3f3f --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/BidirectionalRepositoryLayout.java @@ -0,0 +1,42 @@ +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 Joakim Erdfelt + * @version $Id$ + */ +public interface BidirectionalRepositoryLayout +{ + /** + * Given an ArchivaArtifact + * + * @param artifact + * @return + */ + public String pathOf( ArchivaArtifact artifact ); + + ArchivaArtifact toArtifact( String path ); +} diff --git a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScanner.java b/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScanner.java index bc8a62aec..fab8d1a33 100644 --- a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScanner.java +++ b/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScanner.java @@ -19,9 +19,10 @@ package org.apache.maven.archiva.repository.scanner; * 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; @@ -72,7 +73,7 @@ public class RepositoryScanner * @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 ); @@ -93,7 +94,7 @@ public class RepositoryScanner * @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 { @@ -102,12 +103,12 @@ public class RepositoryScanner 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() ) { diff --git a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java b/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java index f4bd38bf2..70554f73d 100644 --- a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java +++ b/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java @@ -20,8 +20,10 @@ package org.apache.maven.archiva.repository.scanner; */ 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; @@ -45,19 +47,21 @@ public class RepositoryScannerInstance implements DirectoryWalkListener 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() ) @@ -77,36 +81,36 @@ public class RepositoryScannerInstance implements DirectoryWalkListener } } - 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() ) @@ -118,7 +122,6 @@ public class RepositoryScannerInstance implements DirectoryWalkListener try { log.debug( "Sending to consumer: " + consumer.getName() ); - stats.filesConsumed++; consumer.processFile( basefile ); } catch ( Exception e ) @@ -141,8 +144,8 @@ public class RepositoryScannerInstance implements DirectoryWalkListener 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 ) diff --git a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/ScanStatistics.java b/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/ScanStatistics.java deleted file mode 100644 index 780b95367..000000000 --- a/archiva-jpox-database-refactor/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/ScanStatistics.java +++ /dev/null @@ -1,198 +0,0 @@ -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 Joakim Erdfelt - * @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 ) ); - } -} diff --git a/archiva-jpox-database-refactor/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/RepositoryURLTest.java b/archiva-jpox-database-refactor/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/RepositoryURLTest.java index af2efe5fc..a7aac9513 100644 --- a/archiva-jpox-database-refactor/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/RepositoryURLTest.java +++ b/archiva-jpox-database-refactor/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/RepositoryURLTest.java @@ -19,6 +19,8 @@ package org.apache.maven.archiva.repository; * under the License. */ +import org.apache.maven.archiva.common.utils.RepositoryURL; + import java.net.MalformedURLException; import junit.framework.TestCase; diff --git a/archiva-jpox-database-refactor/pom.xml b/archiva-jpox-database-refactor/pom.xml index 174fea814..a500c2f61 100644 --- a/archiva-jpox-database-refactor/pom.xml +++ b/archiva-jpox-database-refactor/pom.xml @@ -228,13 +228,13 @@ org.apache.maven.archiva archiva-common - ${pom.version} + ${archiva.version}