Skip to content

Commit 69f7d26

Browse files
committed
Skeleton implementation of modern versions of our primary elements.
1 parent 79b210a commit 69f7d26

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2016-2020 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.gradle.spotless;
17+
18+
import org.gradle.api.Project;
19+
20+
public class SpotlessExtensionModern extends SpotlessExtensionBase {
21+
public SpotlessExtensionModern(Project project) {
22+
super(project);
23+
}
24+
25+
@Override
26+
protected void createFormatTasks(String name, FormatExtension formatExtension) {
27+
// TODO level 1: implement SpotlessExtension::createFormatTasks, but using config avoidance
28+
// TODO level 2: override configure(String name, Class<T> clazz, Action<T> configure) so that it is lazy
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2016-2020 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.gradle.spotless;
17+
18+
import org.gradle.api.Plugin;
19+
import org.gradle.api.Project;
20+
import org.gradle.api.Task;
21+
import org.gradle.api.plugins.BasePlugin;
22+
23+
import com.diffplug.spotless.SpotlessCache;
24+
25+
public class SpotlessPluginModern implements Plugin<Project> {
26+
@Override
27+
public void apply(Project project) {
28+
// make sure there's a `clean` task
29+
project.getPlugins().apply(BasePlugin.class);
30+
31+
// setup the extension
32+
project.getExtensions().create(SpotlessExtension.EXTENSION, SpotlessExtensionModern.class, project);
33+
34+
// clear spotless' cache when the user does a clean
35+
Task clean = project.getTasks().getByName(BasePlugin.CLEAN_TASK_NAME);
36+
clean.doLast(unused -> {
37+
// resolution for: https://github.com/diffplug/spotless/issues/243#issuecomment-564323856
38+
// project.getRootProject() is consistent across every project, so only of one the clears will
39+
// actually happen (as desired)
40+
//
41+
// we use System.identityHashCode() to avoid a memory leak by hanging on to the reference directly
42+
SpotlessCache.clearOnce(System.identityHashCode(project.getRootProject()));
43+
});
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2016-2020 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.gradle.spotless;
17+
18+
import org.gradle.api.tasks.CacheableTask;
19+
import org.gradle.api.tasks.TaskAction;
20+
21+
@CacheableTask
22+
public class SpotlessTaskModern extends SpotlessTask {
23+
@TaskAction
24+
public void performAction() throws Exception {
25+
// TODO: implement using the InputChanges api
26+
}
27+
}

0 commit comments

Comments
 (0)