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.indexer.ArchivaIndexingContext; 023import org.apache.archiva.components.taskqueue.Task; 024import org.apache.archiva.repository.ManagedRepository; 025 026import java.nio.file.Path; 027 028 029public class ArtifactIndexingTask 030 implements Task 031{ 032 public enum Action 033 { 034 ADD, 035 DELETE, 036 FINISH 037 } 038 039 private final ManagedRepository repository; 040 041 private final Path resourceFile; 042 043 private final Action action; 044 045 private final ArchivaIndexingContext context; 046 047 private boolean executeOnEntireRepo = true; 048 049 /** 050 * @since 1.4-M1 051 */ 052 private boolean onlyUpdate = false; 053 054 public ArtifactIndexingTask( ManagedRepository repository, Path resourceFile, Action action, 055 ArchivaIndexingContext context ) 056 { 057 this.repository = repository; 058 this.resourceFile = resourceFile; 059 this.action = action; 060 this.context = context; 061 } 062 063 public ArtifactIndexingTask( ManagedRepository repository, Path resourceFile, Action action, 064 ArchivaIndexingContext context, boolean executeOnEntireRepo ) 065 { 066 this( repository, resourceFile, action, context ); 067 this.executeOnEntireRepo = executeOnEntireRepo; 068 } 069 070 public ArtifactIndexingTask( ManagedRepository repository, Path resourceFile, Action action, 071 ArchivaIndexingContext context, boolean executeOnEntireRepo, boolean onlyUpdate ) 072 { 073 this( repository, resourceFile, action, context, executeOnEntireRepo ); 074 this.onlyUpdate = onlyUpdate; 075 } 076 077 public boolean isExecuteOnEntireRepo() 078 { 079 return executeOnEntireRepo; 080 } 081 082 public void setExecuteOnEntireRepo( boolean executeOnEntireRepo ) 083 { 084 this.executeOnEntireRepo( executeOnEntireRepo ); 085 } 086 087 public ArtifactIndexingTask executeOnEntireRepo( boolean executeOnEntireRepo ) 088 { 089 this.executeOnEntireRepo = executeOnEntireRepo; 090 return this; 091 } 092 093 @Override 094 public long getMaxExecutionTime() 095 { 096 return 0; 097 } 098 099 public Path getResourceFile() 100 { 101 return resourceFile; 102 } 103 104 public Action getAction() 105 { 106 return action; 107 } 108 109 public ManagedRepository getRepository() 110 { 111 return repository; 112 } 113 114 public ArchivaIndexingContext getContext() 115 { 116 return context; 117 } 118 119 public boolean isOnlyUpdate() 120 { 121 return onlyUpdate; 122 } 123 124 public void setOnlyUpdate( boolean onlyUpdate ) 125 { 126 this.onlyUpdate = onlyUpdate; 127 } 128 129 @Override 130 public int hashCode() 131 { 132 final int prime = 31; 133 int result = 1; 134 result = prime * result + action.hashCode(); 135 result = prime * result + repository.getId().hashCode(); 136 result = prime * result + ( ( resourceFile == null ) ? 0 : resourceFile.hashCode() ); 137 return result; 138 } 139 140 @Override 141 public boolean equals( Object obj ) 142 { 143 if ( this == obj ) 144 { 145 return true; 146 } 147 if ( obj == null ) 148 { 149 return false; 150 } 151 if ( getClass() != obj.getClass() ) 152 { 153 return false; 154 } 155 ArtifactIndexingTask other = (ArtifactIndexingTask) obj; 156 if ( !action.equals( other.action ) ) 157 { 158 return false; 159 } 160 if ( !repository.getId().equals( other.repository.getId() ) ) 161 { 162 return false; 163 } 164 if ( resourceFile == null ) 165 { 166 if ( other.resourceFile != null ) 167 { 168 return false; 169 } 170 } 171 else if ( !resourceFile.equals( other.resourceFile ) ) 172 { 173 return false; 174 } 175 return true; 176 } 177 178 179 @Override 180 public String toString() 181 { 182 return "ArtifactIndexingTask [action=" + action + ", repositoryId=" + repository.getId() + ", resourceFile=" 183 + resourceFile + "]"; 184 } 185 186}