-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
364 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
src/main/java/org/embulk/gradle/runset/EmbulkRunsetExtension.java
This file was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
src/main/java/org/embulk/gradle/runset/InstallEmbulkRunSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright 2022 The Embulk project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.embulk.gradle.runset; | ||
|
||
import java.util.AbstractMap; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.IllegalDependencyNotation; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.artifacts.Configuration; | ||
import org.gradle.api.artifacts.Dependency; | ||
import org.gradle.api.model.ObjectFactory; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.tasks.InputFile; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
/** | ||
* A Gradle Task to set up an environment for running Embulk. | ||
*/ | ||
public class InstallEmbulkRunSet extends DefaultTask { | ||
public InstallEmbulkRunSet() { | ||
super(); | ||
|
||
this.project = this.getProject(); | ||
|
||
final ObjectFactory objectFactory = this.project.getObjects(); | ||
|
||
this.dependencies = new ArrayList<>(); | ||
this.targetDirectory = objectFactory.property(String.class); | ||
} | ||
|
||
@TaskAction | ||
public void exec() { | ||
} | ||
|
||
/** | ||
* Adds a Maven artifact to be installed. | ||
* | ||
* <p>It tries to simulate Gradle's dependency notations, but it is yet far from perfect. | ||
* | ||
* @see <a href="https://github.com/gradle/gradle/blob/v8.4.0/subprojects/dependency-management/src/main/java/org/gradle/api/internal/notations/DependencyNotationParser.java#L49-L86">org.gradle.api.internal.notations.DependencyNotationParser#create</a> | ||
*/ | ||
public void artifact(final Object dependencyNotation) { | ||
if (dependencyNotation instanceof CharSequence) { | ||
this.dependencies.add(this.mapFromCharSequence((CharSequence) dependencyNotation)); | ||
} else if (dependencyNotation instanceof Map) { | ||
this.dependencies.add(this.mapFromMap((Map) dependencyNotation)); | ||
} else { | ||
throw new IllegalDependencyNotation("Supplied module notation is invalid."); | ||
} | ||
} | ||
|
||
@InputFile | ||
@org.gradle.api.tasks.Optional | ||
public Property<String> getTargetDirectory() { | ||
return this.targetDirectory; | ||
} | ||
|
||
List<Configuration> buildDetachedConfigurations() { | ||
final ArrayList<Configuration> configurations = new ArrayList<>(); | ||
for (final Map.Entry<Object, Dependency> dependency : this.dependencies) { | ||
final Configuration configuration = this.project.getConfigurations().detachedConfiguration(dependency.getValue()); | ||
configurations.add(configuration); | ||
} | ||
return Collections.unmodifiableList(configurations); | ||
} | ||
|
||
// https://github.com/gradle/gradle/blob/v8.4.0/subprojects/dependency-management/src/main/java/org/gradle/api/internal/notations/DependencyStringNotationConverter.java | ||
private Map.Entry<Object, Dependency> mapFromCharSequence(final CharSequence dependencyNotation) { | ||
System.out.println(dependencyNotation); | ||
return new AbstractMap.SimpleImmutableEntry<>( | ||
dependencyNotation.toString(), | ||
this.project.getDependencies().create(dependencyNotation)); | ||
} | ||
|
||
// https://github.com/gradle/gradle/blob/v8.4.0/subprojects/core/src/main/java/org/gradle/internal/typeconversion/MapNotationConverter.java | ||
private Map.Entry<Object, Dependency> mapFromMap(final Map dependencyNotation) { | ||
System.out.println(dependencyNotation); | ||
|
||
return new AbstractMap.SimpleImmutableEntry<>( | ||
new LinkedHashMap((Map) dependencyNotation), | ||
this.project.getDependencies().create(dependencyNotation)); | ||
} | ||
|
||
private final Project project; | ||
|
||
private final ArrayList<Map.Entry<Object, Dependency>> dependencies; | ||
|
||
private final Property<String> targetDirectory; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.