1 package org.apache.archiva.scheduler.indexing;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.admin.model.beans.ManagedRepository;
23 import org.apache.maven.index.NexusIndexer;
24 import org.apache.maven.index.context.IndexCreator;
25 import org.apache.maven.index.context.IndexingContext;
26 import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
27 import org.codehaus.plexus.taskqueue.Task;
28 import org.slf4j.LoggerFactory;
31 import java.io.IOException;
32 import java.util.List;
34 public class ArtifactIndexingTask
44 private final ManagedRepository repository;
46 private final File resourceFile;
48 private final Action action;
50 private final IndexingContext context;
52 private boolean executeOnEntireRepo = true;
57 private boolean onlyUpdate = false;
59 public ArtifactIndexingTask( ManagedRepository repository, File resourceFile, Action action,
60 IndexingContext context )
62 this.repository = repository;
63 this.resourceFile = resourceFile;
65 this.context = context;
68 public ArtifactIndexingTask( ManagedRepository repository, File resourceFile, Action action,
69 IndexingContext context, boolean executeOnEntireRepo )
71 this( repository, resourceFile, action, context );
72 this.executeOnEntireRepo = executeOnEntireRepo;
75 public ArtifactIndexingTask( ManagedRepository repository, File resourceFile, Action action,
76 IndexingContext context, boolean executeOnEntireRepo, boolean onlyUpdate )
78 this( repository, resourceFile, action, context, executeOnEntireRepo );
79 this.onlyUpdate = onlyUpdate;
82 public boolean isExecuteOnEntireRepo()
84 return executeOnEntireRepo;
87 public void setExecuteOnEntireRepo( boolean executeOnEntireRepo )
89 this.executeOnEntireRepo = executeOnEntireRepo;
92 public long getMaxExecutionTime()
97 public File getResourceFile()
102 public Action getAction()
107 public ManagedRepository getRepository()
112 public IndexingContext getContext()
117 public boolean isOnlyUpdate()
122 public void setOnlyUpdate( boolean onlyUpdate )
124 this.onlyUpdate = onlyUpdate;
128 public int hashCode()
130 final int prime = 31;
132 result = prime * result + action.hashCode();
133 result = prime * result + repository.getId().hashCode();
134 result = prime * result + ( ( resourceFile == null ) ? 0 : resourceFile.hashCode() );
139 public boolean equals( Object obj )
149 if ( getClass() != obj.getClass() )
153 ArtifactIndexingTask other = (ArtifactIndexingTask) obj;
154 if ( !action.equals( other.action ) )
158 if ( !repository.getId().equals( other.repository.getId() ) )
162 if ( resourceFile == null )
164 if ( other.resourceFile != null )
169 else if ( !resourceFile.equals( other.resourceFile ) )
178 public String toString()
180 return "ArtifactIndexingTask [action=" + action + ", repositoryId=" + repository.getId() + ", resourceFile="
181 + resourceFile + "]";
185 * FIXME remove this static somewhere else !
188 * @param indexCreators
190 * @throws IOException
191 * @throws UnsupportedExistingLuceneIndexException
193 public static IndexingContext createContext( ManagedRepository repository, NexusIndexer indexer,
194 List<? extends IndexCreator> indexCreators )
195 throws IOException, UnsupportedExistingLuceneIndexException
197 IndexingContext context = indexer.getIndexingContexts().get( repository.getId() );
199 if ( context != null )
201 LoggerFactory.getLogger( ArtifactIndexingTask.class ).debug(
202 "skip adding repository with id {} as already exists", repository.getId() );
207 String indexDir = repository.getIndexDirectory();
208 File managedRepository = new File( repository.getLocation() );
210 File indexDirectory = null;
211 if ( indexDir != null && !"".equals( indexDir ) )
213 indexDirectory = new File( repository.getIndexDirectory() );
217 indexDirectory = new File( managedRepository, ".indexer" );
221 context = indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
222 managedRepository.toURI().toURL().toExternalForm(),
223 indexDirectory.toURI().toURL().toString(), indexCreators );
225 context.setSearchable( repository.isScanned() );