001    package org.apache.archiva.scheduler.indexing;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *  http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.archiva.admin.model.beans.ManagedRepository;
023    import org.apache.maven.index.context.IndexingContext;
024    import org.apache.archiva.redback.components.taskqueue.Task;
025    
026    import java.io.File;
027    
028    public class ArtifactIndexingTask
029        implements Task
030    {
031        public enum Action
032        {
033            ADD,
034            DELETE,
035            FINISH
036        }
037    
038        private final ManagedRepository repository;
039    
040        private final File resourceFile;
041    
042        private final Action action;
043    
044        private final IndexingContext context;
045    
046        private boolean executeOnEntireRepo = true;
047    
048        /**
049         * @since 1.4-M1
050         */
051        private boolean onlyUpdate = false;
052    
053        public ArtifactIndexingTask( ManagedRepository repository, File resourceFile, Action action,
054                                     IndexingContext context )
055        {
056            this.repository = repository;
057            this.resourceFile = resourceFile;
058            this.action = action;
059            this.context = context;
060        }
061    
062        public ArtifactIndexingTask( ManagedRepository repository, File resourceFile, Action action,
063                                     IndexingContext context, boolean executeOnEntireRepo )
064        {
065            this( repository, resourceFile, action, context );
066            this.executeOnEntireRepo = executeOnEntireRepo;
067        }
068    
069        public ArtifactIndexingTask( ManagedRepository repository, File resourceFile, Action action,
070                                     IndexingContext context, boolean executeOnEntireRepo, boolean onlyUpdate )
071        {
072            this( repository, resourceFile, action, context, executeOnEntireRepo );
073            this.onlyUpdate = onlyUpdate;
074        }
075    
076        public boolean isExecuteOnEntireRepo()
077        {
078            return executeOnEntireRepo;
079        }
080    
081        public void setExecuteOnEntireRepo( boolean executeOnEntireRepo )
082        {
083            this.executeOnEntireRepo = executeOnEntireRepo;
084        }
085    
086        public long getMaxExecutionTime()
087        {
088            return 0;
089        }
090    
091        public File getResourceFile()
092        {
093            return resourceFile;
094        }
095    
096        public Action getAction()
097        {
098            return action;
099        }
100    
101        public ManagedRepository getRepository()
102        {
103            return repository;
104        }
105    
106        public IndexingContext getContext()
107        {
108            return context;
109        }
110    
111        public boolean isOnlyUpdate()
112        {
113            return onlyUpdate;
114        }
115    
116        public void setOnlyUpdate( boolean onlyUpdate )
117        {
118            this.onlyUpdate = onlyUpdate;
119        }
120    
121        @Override
122        public int hashCode()
123        {
124            final int prime = 31;
125            int result = 1;
126            result = prime * result + action.hashCode();
127            result = prime * result + repository.getId().hashCode();
128            result = prime * result + ( ( resourceFile == null ) ? 0 : resourceFile.hashCode() );
129            return result;
130        }
131    
132        @Override
133        public boolean equals( Object obj )
134        {
135            if ( this == obj )
136            {
137                return true;
138            }
139            if ( obj == null )
140            {
141                return false;
142            }
143            if ( getClass() != obj.getClass() )
144            {
145                return false;
146            }
147            ArtifactIndexingTask other = (ArtifactIndexingTask) obj;
148            if ( !action.equals( other.action ) )
149            {
150                return false;
151            }
152            if ( !repository.getId().equals( other.repository.getId() ) )
153            {
154                return false;
155            }
156            if ( resourceFile == null )
157            {
158                if ( other.resourceFile != null )
159                {
160                    return false;
161                }
162            }
163            else if ( !resourceFile.equals( other.resourceFile ) )
164            {
165                return false;
166            }
167            return true;
168        }
169    
170    
171        @Override
172        public String toString()
173        {
174            return "ArtifactIndexingTask [action=" + action + ", repositoryId=" + repository.getId() + ", resourceFile="
175                + resourceFile + "]";
176        }
177    
178    }