001package ball.util.ant.taskdefs; 002/*- 003 * ########################################################################## 004 * Utilities 005 * $Id: UUIDTask.Generate.html 5431 2020-02-12 19:03:17Z ball $ 006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/hcf-dev/blog/2019-07-08-fivethirtyeight-best-scrabble-string/src/main/resources/javadoc/src-html/ball/util/ant/taskdefs/UUIDTask.Generate.html $ 007 * %% 008 * Copyright (C) 2008 - 2020 Allen D. Ball 009 * %% 010 * Licensed under the Apache License, Version 2.0 (the "License"); 011 * you may not use this file except in compliance with the License. 012 * You may obtain a copy of the License at 013 * 014 * http://www.apache.org/licenses/LICENSE-2.0 015 * 016 * Unless required by applicable law or agreed to in writing, software 017 * distributed under the License is distributed on an "AS IS" BASIS, 018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 019 * See the License for the specific language governing permissions and 020 * limitations under the License. 021 * ########################################################################## 022 */ 023import ball.util.UUIDFactory; 024import java.util.UUID; 025import lombok.Getter; 026import lombok.NoArgsConstructor; 027import lombok.Setter; 028import lombok.ToString; 029import lombok.experimental.Accessors; 030import org.apache.tools.ant.BuildException; 031import org.apache.tools.ant.Task; 032import org.apache.tools.ant.util.ClasspathUtils; 033 034import static lombok.AccessLevel.PROTECTED; 035 036/** 037 * {@link.uri http://ant.apache.org/ Ant} {@link Task} to generate new 038 * unique {@link UUID}s. 039 * 040 * {@ant.task} 041 * 042 * @see Generate 043 * @see GenerateRandom 044 * @see GenerateTime 045 * 046 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball} 047 * @version $Revision: 5431 $ 048 */ 049@NoArgsConstructor(access = PROTECTED) 050public abstract class UUIDTask extends Task 051 implements AnnotatedAntTask, 052 ClasspathDelegateAntTask, 053 ConfigurableAntTask, 054 PropertySetterAntTask { 055 @Getter @Setter @Accessors(chain = true, fluent = true) 056 private ClasspathUtils.Delegate delegate = null; 057 @Getter @Setter 058 private String property = null; 059 060 @Override 061 public void init() throws BuildException { 062 super.init(); 063 ClasspathDelegateAntTask.super.init(); 064 ConfigurableAntTask.super.init(); 065 } 066 067 @Override 068 public void execute() throws BuildException { 069 super.execute(); 070 AnnotatedAntTask.super.execute(); 071 PropertySetterAntTask.super.execute(); 072 } 073 074 @Override 075 public abstract UUID getPropertyValue() throws Exception; 076 077 /** 078 * {@link.uri http://ant.apache.org/ Ant} {@link Task} to generate a 079 * {@link UUID} with {@link UUID#fromString(String)}. 080 * 081 * {@ant.task} 082 */ 083 @AntTask("uuid-from") 084 @NoArgsConstructor @ToString 085 public static class From extends UUIDTask { 086 @NotNull @Getter @Setter 087 private String string = null; 088 089 @Override 090 public UUID getPropertyValue() { 091 return UUID.fromString(getString()); 092 } 093 } 094 095 /** 096 * {@link.uri http://ant.apache.org/ Ant} {@link Task} to generate a new 097 * {@link UUID} with {@link UUIDFactory#generate()}. 098 * 099 * {@ant.task} 100 */ 101 @AntTask("uuid-generate") 102 @NoArgsConstructor @ToString 103 public static class Generate extends UUIDTask { 104 @Override 105 public UUID getPropertyValue() { 106 return UUIDFactory.getDefault().generate(); 107 } 108 } 109 110 /** 111 * {@link.uri http://ant.apache.org/ Ant} {@link Task} to generate a new 112 * {@link UUID} with {@link UUIDFactory#generateRandom()}. 113 * 114 * {@ant.task} 115 */ 116 @AntTask("uuid-generate-random") 117 @NoArgsConstructor @ToString 118 public static class GenerateRandom extends UUIDTask { 119 @Override 120 public UUID getPropertyValue() { 121 return UUIDFactory.getDefault().generateRandom(); 122 } 123 } 124 125 /** 126 * {@link.uri http://ant.apache.org/ Ant} {@link Task} to generate a new 127 * {@link UUID} with {@link UUIDFactory#generateTime()}. 128 * 129 * {@ant.task} 130 */ 131 @AntTask("uuid-generate-time") 132 @NoArgsConstructor @ToString 133 public static class GenerateTime extends UUIDTask { 134 @Override 135 public UUID getPropertyValue() { 136 return UUIDFactory.getDefault().generateTime(); 137 } 138 } 139 140 /** 141 * {@link.uri http://ant.apache.org/ Ant} {@link Task} to generate a 142 * {@code null} {@link UUID} with {@link UUIDFactory#generateNull()}. 143 * 144 * {@ant.task} 145 */ 146 @AntTask("uuid-null") 147 @NoArgsConstructor @ToString 148 public static class Null extends UUIDTask { 149 @Override 150 public UUID getPropertyValue() { 151 return UUIDFactory.getDefault().generateNull(); 152 } 153 } 154}