001package 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 022import org.apache.archiva.admin.model.beans.ManagedRepository; 023import org.apache.maven.index.context.IndexingContext; 024import org.apache.archiva.redback.components.taskqueue.Task; 025 026import java.io.File; 027 028public 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 @Override 087 public long getMaxExecutionTime() 088 { 089 return 0; 090 } 091 092 public File getResourceFile() 093 { 094 return resourceFile; 095 } 096 097 public Action getAction() 098 { 099 return action; 100 } 101 102 public ManagedRepository getRepository() 103 { 104 return repository; 105 } 106 107 public IndexingContext getContext() 108 { 109 return context; 110 } 111 112 public boolean isOnlyUpdate() 113 { 114 return onlyUpdate; 115 } 116 117 public void setOnlyUpdate( boolean onlyUpdate ) 118 { 119 this.onlyUpdate = onlyUpdate; 120 } 121 122 @Override 123 public int hashCode() 124 { 125 final int prime = 31; 126 int result = 1; 127 result = prime * result + action.hashCode(); 128 result = prime * result + repository.getId().hashCode(); 129 result = prime * result + ( ( resourceFile == null ) ? 0 : resourceFile.hashCode() ); 130 return result; 131 } 132 133 @Override 134 public boolean equals( Object obj ) 135 { 136 if ( this == obj ) 137 { 138 return true; 139 } 140 if ( obj == null ) 141 { 142 return false; 143 } 144 if ( getClass() != obj.getClass() ) 145 { 146 return false; 147 } 148 ArtifactIndexingTask other = (ArtifactIndexingTask) obj; 149 if ( !action.equals( other.action ) ) 150 { 151 return false; 152 } 153 if ( !repository.getId().equals( other.repository.getId() ) ) 154 { 155 return false; 156 } 157 if ( resourceFile == null ) 158 { 159 if ( other.resourceFile != null ) 160 { 161 return false; 162 } 163 } 164 else if ( !resourceFile.equals( other.resourceFile ) ) 165 { 166 return false; 167 } 168 return true; 169 } 170 171 172 @Override 173 public String toString() 174 { 175 return "ArtifactIndexingTask [action=" + action + ", repositoryId=" + repository.getId() + ", resourceFile=" 176 + resourceFile + "]"; 177 } 178 179}