Rename.groovy
01 /*
02  * SPDX-License-Identifier: Apache-2.0
03  *
04  * Copyright 2019-2021 Andres Almiray.
05  *
06  * Licensed under the Apache License, Version 2.0 (the "License");
07  * you may not use this file except in compliance with the License.
08  * You may obtain a copy of the License at
09  *
10  *     https://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 package org.kordamp.gradle.plugin.yguard.tasks
19 
20 import groovy.transform.CompileDynamic
21 import groovy.transform.CompileStatic
22 import org.gradle.api.Action
23 import org.gradle.api.Project
24 import org.gradle.api.provider.Property
25 
26 import javax.inject.Inject
27 
28 /**
29  *
30  @author Andres Almiray
31  @since 0.1.0
32  */
33 @CompileStatic
34 class Rename {
35     final Property<String> logFile
36     final Property<String> mainClass
37     final Property<Boolean> conserveManifest
38     final Property<Boolean> replaceClassNameStrings
39     final Property<String> annotationClass
40     final Property<Boolean> enabled
41 
42     final Props props
43     final Keep keep
44     final List<Adjust> adjusts = []
45 
46     private final Project project
47 
48     @Inject
49     Rename(Project project) {
50         this.project = project
51         logFile = project.objects.property(String).convention('rename.xml')
52         mainClass = project.objects.property(String)
53         conserveManifest = project.objects.property(Boolean).convention(false)
54         replaceClassNameStrings = project.objects.property(Boolean).convention(false)
55         annotationClass = project.objects.property(String).convention('com.yworks.util.annotation.Obfuscation')
56         enabled = project.objects.property(Boolean).convention(true)
57 
58         props = project.objects.newInstance(Props, project)
59         keep = project.objects.newInstance(Keep, project)
60     }
61 
62     void props(Action<? extends Props> action) {
63         action.execute(props)
64     }
65 
66     void keep(Action<? extends Keep> action) {
67         action.execute(keep)
68     }
69 
70     void adjust(Action<? extends Adjust> action) {
71         Adjust adjust = project.objects.newInstance(Adjust, project)
72         action.execute(adjust)
73         adjusts.add(adjust)
74     }
75 
76     @CompileDynamic
77     List<String> validate() {
78         List<String> errors = []
79         errors.addAll(props.validate())
80         errors.addAll(keep.validate())
81         errors.addAll(adjusts*.validate())
82         errors
83     }
84 }