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
23 import java.io.IOException;
25 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
26 import org.codehaus.plexus.taskqueue.Task;
27 import org.sonatype.nexus.index.NexusIndexer;
28 import org.sonatype.nexus.index.context.DefaultIndexingContext;
29 import org.sonatype.nexus.index.context.IndexingContext;
30 import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException;
32 public class ArtifactIndexingTask
40 private final ManagedRepositoryConfiguration repository;
42 private final File resourceFile;
44 private final Action action;
46 private final IndexingContext context;
48 public ArtifactIndexingTask( ManagedRepositoryConfiguration repository, File resourceFile, Action action,
49 IndexingContext context )
51 this.repository = repository;
52 this.resourceFile = resourceFile;
54 this.context = context;
57 public long getMaxExecutionTime()
62 public File getResourceFile()
67 public Action getAction()
73 public String toString()
75 return "ArtifactIndexingTask [action=" + action + ", repositoryId=" + repository.getId() + ", resourceFile="
79 public ManagedRepositoryConfiguration getRepository()
84 public IndexingContext getContext()
94 result = prime * result + action.hashCode();
95 result = prime * result + repository.getId().hashCode();
96 result = prime * result + ( ( resourceFile == null ) ? 0 : resourceFile.hashCode() );
101 public boolean equals( Object obj )
107 if ( getClass() != obj.getClass() )
109 ArtifactIndexingTask other = (ArtifactIndexingTask) obj;
110 if ( !action.equals( other.action ) )
112 if ( !repository.getId().equals( other.repository.getId() ) )
114 if ( resourceFile == null )
116 if ( other.resourceFile != null )
119 else if ( !resourceFile.equals( other.resourceFile ) )
124 public static IndexingContext createContext( ManagedRepositoryConfiguration repository )
125 throws IOException, UnsupportedExistingLuceneIndexException
127 String indexDir = repository.getIndexDir();
128 File managedRepository = new File( repository.getLocation() );
130 File indexDirectory = null;
131 if ( indexDir != null && !"".equals( indexDir ) )
133 indexDirectory = new File( repository.getIndexDir() );
137 indexDirectory = new File( managedRepository, ".indexer" );
140 IndexingContext context =
141 new DefaultIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
142 null, null, NexusIndexer.FULL_INDEX, false );
143 context.setSearchable( repository.isScanned() );