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.maven.archiva.configuration.ManagedRepositoryConfiguration;
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 ManagedRepositoryConfiguration 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( ManagedRepositoryConfiguration repository, File resourceFile, Action action,
60 IndexingContext context )
62 this.repository = repository;
63 this.resourceFile = resourceFile;
65 this.context = context;
68 public ArtifactIndexingTask( ManagedRepositoryConfiguration repository, File resourceFile, Action action,
69 IndexingContext context, boolean executeOnEntireRepo )
71 this( repository, resourceFile, action, context );
72 this.executeOnEntireRepo = executeOnEntireRepo;
75 public ArtifactIndexingTask( ManagedRepositoryConfiguration 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 ManagedRepositoryConfiguration 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( ManagedRepositoryConfiguration repository, NexusIndexer indexer,
194 List<? extends IndexCreator> indexCreators )
195 throws IOException, UnsupportedExistingLuceneIndexException
197 String indexDir = repository.getIndexDir();
198 File managedRepository = new File( repository.getLocation() );
200 File indexDirectory = null;
201 if ( indexDir != null && !"".equals( indexDir ) )
203 indexDirectory = new File( repository.getIndexDir() );
207 indexDirectory = new File( managedRepository, ".indexer" );
210 IndexingContext context = indexer.getIndexingContexts().get( repository.getId() );
212 if ( context != null )
214 LoggerFactory.getLogger( ArtifactIndexingTask.class ).warn(
215 "skip adding repository with id {} as already exists", repository.getId() );
219 context = indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
220 managedRepository.toURI().toURL().toExternalForm(),
221 indexDirectory.toURI().toURL().toString(), indexCreators );
223 context.setSearchable( repository.isScanned() );