Skip to content

Commit

Permalink
Add merge() methods to some Java providers.
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=117375231
  • Loading branch information
cgrushko authored and lberki committed Mar 17, 2016
1 parent 3ae80a7 commit 2d9ec94
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,26 @@ public NestedSet<Artifact> getCompileTimeJavaDependencyArtifacts() {
public NestedSet<Artifact> getRunTimeJavaDependencyArtifacts() {
return runTimeJavaDepArtifacts;
}

public static JavaCompilationArgsProvider merge(Iterable<JavaCompilationArgsProvider> providers) {
JavaCompilationArgs.Builder javaCompilationArgs = JavaCompilationArgs.builder();
JavaCompilationArgs.Builder recursiveJavaCompilationArgs = JavaCompilationArgs.builder();
NestedSetBuilder<Artifact> compileTimeJavaDepArtifacts = NestedSetBuilder.stableOrder();
NestedSetBuilder<Artifact> runTimeJavaDepArtifacts = NestedSetBuilder.stableOrder();

for (JavaCompilationArgsProvider provider : providers) {
javaCompilationArgs.addTransitiveArgs(
provider.getJavaCompilationArgs(), JavaCompilationArgs.ClasspathType.BOTH);
recursiveJavaCompilationArgs.addTransitiveArgs(
provider.getRecursiveJavaCompilationArgs(), JavaCompilationArgs.ClasspathType.BOTH);
compileTimeJavaDepArtifacts.addTransitive(provider.getCompileTimeJavaDependencyArtifacts());
runTimeJavaDepArtifacts.addTransitive(provider.getRunTimeJavaDependencyArtifacts());
}

return new JavaCompilationArgsProvider(
javaCompilationArgs.build(),
recursiveJavaCompilationArgs.build(),
compileTimeJavaDepArtifacts.build(),
runTimeJavaDepArtifacts.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.rules.cpp.LinkerInput;

Expand All @@ -40,4 +41,14 @@ public JavaNativeLibraryProvider(
public NestedSet<LinkerInput> getTransitiveJavaNativeLibraries() {
return transitiveJavaNativeLibraries;
}

public static JavaNativeLibraryProvider merge(Iterable<JavaNativeLibraryProvider> deps) {
NestedSetBuilder<LinkerInput> transitiveSourceJars = NestedSetBuilder.stableOrder();

for (JavaNativeLibraryProvider wrapper : deps) {
transitiveSourceJars.addTransitive(wrapper.getTransitiveJavaNativeLibraries());
}
return new JavaNativeLibraryProvider(transitiveSourceJars.build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,13 @@ public JavaRuntimeJarProvider(ImmutableList<Artifact> runtimeJars) {
public ImmutableList<Artifact> getRuntimeJars() {
return runtimeJars;
}

public static JavaRuntimeJarProvider merge(Iterable<JavaRuntimeJarProvider> deps) {
ImmutableList.Builder<Artifact> runtimeJars = ImmutableList.builder();
for (JavaRuntimeJarProvider wrapper : deps) {
runtimeJars.addAll(wrapper.getRuntimeJars());
}
return new JavaRuntimeJarProvider(runtimeJars.build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;

/**
Expand Down Expand Up @@ -49,4 +50,16 @@ public NestedSet<Artifact> getTransitiveSourceJars() {
public ImmutableList<Artifact> getSourceJars() {
return sourceJars;
}

public static JavaSourceJarsProvider merge(Iterable<JavaSourceJarsProvider> providers) {
NestedSetBuilder<Artifact> transitiveSourceJars = NestedSetBuilder.stableOrder();
ImmutableList.Builder<Artifact> sourceJars = ImmutableList.builder();

for (JavaSourceJarsProvider provider : providers) {
transitiveSourceJars.addTransitive(provider.getTransitiveSourceJars());
sourceJars.addAll(provider.getSourceJars());
}
return new JavaSourceJarsProvider(transitiveSourceJars.build(), sourceJars.build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;

/**
Expand All @@ -33,4 +34,13 @@ public ProguardSpecProvider(NestedSet<Artifact> transitiveProguardSpecs) {
public NestedSet<Artifact> getTransitiveProguardSpecs() {
return transitiveProguardSpecs;
}

public static ProguardSpecProvider merge(Iterable<ProguardSpecProvider> providers) {
NestedSetBuilder<Artifact> specs = NestedSetBuilder.stableOrder();
for (ProguardSpecProvider wrapper : providers) {
specs.addTransitive(wrapper.getTransitiveProguardSpecs());
}
return new ProguardSpecProvider(specs.build());
}

}

0 comments on commit 2d9ec94

Please sign in to comment.