use of org.gradle.api.artifacts.Configuration in project intellij-community by JetBrains.
the class ModelBuildScriptClasspathBuilderImpl method buildAll.
@Nullable
@Override
public Object buildAll(final String modelName, final Project project) {
BuildScriptClasspathModelImpl buildScriptClasspath = cache.get(project.getPath());
if (buildScriptClasspath != null)
return buildScriptClasspath;
if (mySourceSetFinder == null)
mySourceSetFinder = new SourceSetCachedFinder(project);
buildScriptClasspath = new BuildScriptClasspathModelImpl();
final File gradleHomeDir = project.getGradle().getGradleHomeDir();
buildScriptClasspath.setGradleHomeDir(gradleHomeDir);
buildScriptClasspath.setGradleVersion(GradleVersion.current().getVersion());
boolean downloadJavadoc = false;
boolean downloadSources = true;
final IdeaPlugin ideaPlugin = project.getPlugins().findPlugin(IdeaPlugin.class);
if (ideaPlugin != null) {
final IdeaModule ideaModule = ideaPlugin.getModel().getModule();
downloadJavadoc = ideaModule.isDownloadJavadoc();
downloadSources = ideaModule.isDownloadSources();
}
Project parent = project.getParent();
if (parent != null) {
BuildScriptClasspathModelImpl parentBuildScriptClasspath = (BuildScriptClasspathModelImpl) buildAll(modelName, parent);
if (parentBuildScriptClasspath != null) {
for (ClasspathEntryModel classpathEntryModel : parentBuildScriptClasspath.getClasspath()) {
buildScriptClasspath.add(classpathEntryModel);
}
}
}
Configuration classpathConfiguration = project.getBuildscript().getConfigurations().findByName(CLASSPATH_CONFIGURATION_NAME);
if (classpathConfiguration == null)
return null;
Collection<ExternalDependency> dependencies = new DependencyResolverImpl(project, false, downloadJavadoc, downloadSources, mySourceSetFinder).resolveDependencies(classpathConfiguration);
for (ExternalDependency dependency : new DependencyTraverser(dependencies)) {
if (dependency instanceof ExternalLibraryDependency) {
final ExternalLibraryDependency libraryDep = (ExternalLibraryDependency) dependency;
buildScriptClasspath.add(new ClasspathEntryModelImpl(pathSet(libraryDep.getFile()), pathSet(libraryDep.getSource()), pathSet(libraryDep.getJavadoc())));
}
if (dependency instanceof ExternalMultiLibraryDependency) {
ExternalMultiLibraryDependency multiLibraryDependency = (ExternalMultiLibraryDependency) dependency;
buildScriptClasspath.add(new ClasspathEntryModelImpl(pathSet(multiLibraryDependency.getFiles()), pathSet(multiLibraryDependency.getSources()), pathSet(multiLibraryDependency.getJavadoc())));
}
if (dependency instanceof FileCollectionDependency) {
FileCollectionDependency fileCollectionDependency = (FileCollectionDependency) dependency;
buildScriptClasspath.add(new ClasspathEntryModelImpl(pathSet(fileCollectionDependency.getFiles()), new HashSet<String>(), new HashSet<String>()));
}
}
cache.put(project.getPath(), buildScriptClasspath);
return buildScriptClasspath;
}
use of org.gradle.api.artifacts.Configuration in project intellij-community by JetBrains.
the class ModuleExtendedModelBuilderImpl method buildAll.
@Nullable
@Override
public Object buildAll(String modelName, Project project) {
final String moduleName = project.getName();
final String moduleGroup = project.getGroup().toString();
final String moduleVersion = project.getVersion().toString();
final File buildDir = project.getBuildDir();
String javaSourceCompatibility = null;
for (Task task : project.getTasks()) {
if (task instanceof JavaCompile) {
JavaCompile javaCompile = (JavaCompile) task;
javaSourceCompatibility = javaCompile.getSourceCompatibility();
if (task.getName().equals("compileJava"))
break;
}
}
final ModuleExtendedModelImpl moduleVersionModel = new ModuleExtendedModelImpl(moduleName, moduleGroup, moduleVersion, buildDir, javaSourceCompatibility);
final List<File> artifacts = new ArrayList<File>();
for (Task task : project.getTasks()) {
if (task instanceof Jar) {
Jar jar = (Jar) task;
artifacts.add(jar.getArchivePath());
}
}
moduleVersionModel.setArtifacts(artifacts);
final Set<String> sourceDirectories = new HashSet<String>();
final Set<String> testDirectories = new HashSet<String>();
final Set<String> resourceDirectories = new HashSet<String>();
final Set<String> testResourceDirectories = new HashSet<String>();
final List<File> testClassesDirs = new ArrayList<File>();
for (Task task : project.getTasks()) {
if (task instanceof Test) {
Test test = (Test) task;
testClassesDirs.add(test.getTestClassesDir());
if (test.hasProperty(TEST_SRC_DIRS_PROPERTY)) {
Object testSrcDirs = test.property(TEST_SRC_DIRS_PROPERTY);
if (testSrcDirs instanceof Iterable) {
for (Object dir : Iterable.class.cast(testSrcDirs)) {
addFilePath(testDirectories, dir);
}
}
}
}
}
IdeaCompilerOutputImpl compilerOutput = new IdeaCompilerOutputImpl();
if (project.hasProperty(SOURCE_SETS_PROPERTY)) {
Object sourceSets = project.property(SOURCE_SETS_PROPERTY);
if (sourceSets instanceof SourceSetContainer) {
SourceSetContainer sourceSetContainer = (SourceSetContainer) sourceSets;
for (SourceSet sourceSet : sourceSetContainer) {
SourceSetOutput output = sourceSet.getOutput();
if (SourceSet.TEST_SOURCE_SET_NAME.equals(sourceSet.getName())) {
compilerOutput.setTestClassesDir(output.getClassesDir());
compilerOutput.setTestResourcesDir(output.getResourcesDir());
}
if (SourceSet.MAIN_SOURCE_SET_NAME.equals(sourceSet.getName())) {
compilerOutput.setMainClassesDir(output.getClassesDir());
compilerOutput.setMainResourcesDir(output.getResourcesDir());
}
for (File javaSrcDir : sourceSet.getAllJava().getSrcDirs()) {
boolean isTestDir = isTestDir(sourceSet, testClassesDirs);
addFilePath(isTestDir ? testDirectories : sourceDirectories, javaSrcDir);
}
for (File resourcesSrcDir : sourceSet.getResources().getSrcDirs()) {
boolean isTestDir = isTestDir(sourceSet, testClassesDirs);
addFilePath(isTestDir ? testResourceDirectories : resourceDirectories, resourcesSrcDir);
}
}
}
}
File projectDir = project.getProjectDir();
IdeaContentRootImpl contentRoot = new IdeaContentRootImpl(projectDir);
final Set<String> ideaSourceDirectories = new HashSet<String>();
final Set<String> ideaTestDirectories = new HashSet<String>();
final Set<String> ideaGeneratedDirectories = new HashSet<String>();
final Set<File> excludeDirectories = new HashSet<File>();
enrichDataFromIdeaPlugin(project, excludeDirectories, ideaSourceDirectories, ideaTestDirectories, ideaGeneratedDirectories);
if (ideaSourceDirectories.isEmpty()) {
sourceDirectories.clear();
resourceDirectories.clear();
}
if (ideaTestDirectories.isEmpty()) {
testDirectories.clear();
testResourceDirectories.clear();
}
ideaSourceDirectories.removeAll(resourceDirectories);
sourceDirectories.removeAll(ideaTestDirectories);
sourceDirectories.addAll(ideaSourceDirectories);
ideaTestDirectories.removeAll(testResourceDirectories);
testDirectories.addAll(ideaTestDirectories);
// ensure disjoint directories with different type
resourceDirectories.removeAll(sourceDirectories);
testDirectories.removeAll(sourceDirectories);
testResourceDirectories.removeAll(testDirectories);
for (String javaDir : sourceDirectories) {
contentRoot.addSourceDirectory(new IdeaSourceDirectoryImpl(new File(javaDir), ideaGeneratedDirectories.contains(javaDir)));
}
for (String testDir : testDirectories) {
contentRoot.addTestDirectory(new IdeaSourceDirectoryImpl(new File(testDir), ideaGeneratedDirectories.contains(testDir)));
}
for (String resourceDir : resourceDirectories) {
contentRoot.addResourceDirectory(new IdeaSourceDirectoryImpl(new File(resourceDir)));
}
for (String testResourceDir : testResourceDirectories) {
contentRoot.addTestResourceDirectory(new IdeaSourceDirectoryImpl(new File(testResourceDir)));
}
for (File excludeDir : excludeDirectories) {
contentRoot.addExcludeDirectory(excludeDir);
}
moduleVersionModel.setContentRoots(Collections.<ExtIdeaContentRoot>singleton(contentRoot));
moduleVersionModel.setCompilerOutput(compilerOutput);
ConfigurationContainer configurations = project.getConfigurations();
SortedMap<String, Configuration> configurationsByName = configurations.getAsMap();
Map<String, Set<File>> artifactsByConfiguration = new HashMap<String, Set<File>>();
for (Map.Entry<String, Configuration> configurationEntry : configurationsByName.entrySet()) {
Set<File> files = configurationEntry.getValue().getAllArtifacts().getFiles().getFiles();
artifactsByConfiguration.put(configurationEntry.getKey(), files);
}
moduleVersionModel.setArtifactsByConfiguration(artifactsByConfiguration);
return moduleVersionModel;
}
use of org.gradle.api.artifacts.Configuration in project meecrowave by apache.
the class MeecrowavePlugin method apply.
@Override
public void apply(final Project project) {
project.getExtensions().create(NAME, MeecrowaveExtension.class);
project.afterEvaluate(actionProject -> {
final MeecrowaveExtension extension = MeecrowaveExtension.class.cast(actionProject.getExtensions().findByName(NAME));
if (extension != null && extension.isSkipMavenCentral()) {
return;
}
actionProject.getRepositories().mavenCentral();
});
final Configuration configuration = project.getConfigurations().maybeCreate(NAME);
configuration.getIncoming().beforeResolve(resolvableDependencies -> {
String version;
try {
final String resource = "META-INF/maven/org.apache.meecrowave/meecrowave-gradle-plugin/pom.properties";
try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) {
final Properties p = new Properties();
p.load(is);
version = p.getProperty("version");
}
} catch (final IOException e) {
throw new IllegalStateException(e);
}
final DependencyHandler dependencyHandler = project.getDependencies();
final DependencySet dependencies = configuration.getDependencies();
dependencies.add(dependencyHandler.create("org.apache.meecrowave:meecrowave-core:" + version));
});
project.task(new HashMap<String, Object>() {
{
put("type", MeecrowaveTask.class);
put("group", "Embedded Application Server");
put("description", "Starts a meecrowave!");
}
}, NAME);
}
use of org.gradle.api.artifacts.Configuration in project gradle by gradle.
the class Sign method sign.
/**
* Configures the task to sign every artifact of the given configurations
*/
public void sign(Configuration... configurations) {
for (Configuration configuration : configurations) {
configuration.getAllArtifacts().all(new Action<PublishArtifact>() {
@Override
public void execute(PublishArtifact artifact) {
if (artifact instanceof Signature) {
return;
}
signArtifact(artifact);
}
});
configuration.getAllArtifacts().whenObjectRemoved(new Action<PublishArtifact>() {
@Override
public void execute(final PublishArtifact publishArtifact) {
signatures.remove(Iterables.find(signatures, new Predicate<Signature>() {
@Override
public boolean apply(Signature input) {
return input.getToSignArtifact().equals(publishArtifact);
}
}));
}
});
}
}
use of org.gradle.api.artifacts.Configuration in project gradle by gradle.
the class SigningExtension method getDefaultConfiguration.
/**
* Provides the configuration that signature artifacts are added to. Called once during construction.
*/
protected Configuration getDefaultConfiguration() {
ConfigurationContainer configurations = project.getConfigurations();
Configuration configuration = configurations.findByName(DEFAULT_CONFIGURATION_NAME);
return configuration != null ? configuration : configurations.create(DEFAULT_CONFIGURATION_NAME);
}
Aggregations