下面列出了com.google.common.collect.ImmutableList#toArray ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
ReferenceableInstance createInstance(MemRepository repo, Id id) throws RepositoryException {
Integer pos = idPosMap.get(id);
String typeName = typeNameList.get(pos);
if (!Objects.equals(typeName, hierarchicalType.getName())) {
return repo.getClassStore(typeName).createInstance(repo, id);
}
ImmutableList<String> traitNames = traitNamesStore.get(pos);
String[] tNs = traitNames.toArray(new String[]{});
try {
return (ReferenceableInstance) classType.createInstance(id, tNs);
} catch (AtlasException me) {
throw new RepositoryException(me);
}
}
private static boolean computeIsSupported(CommandEnvironment cmdEnv, Path linuxSandbox) {
ImmutableList<String> linuxSandboxArgv =
LinuxSandboxUtil.commandLineBuilder(linuxSandbox, ImmutableList.of("/bin/true")).build();
ImmutableMap<String, String> env = ImmutableMap.of();
Path execRoot = cmdEnv.getExecRoot();
File cwd = execRoot.getPathFile();
Command cmd = new Command(linuxSandboxArgv.toArray(new String[0]), env, cwd);
try (SilentCloseable c = Profiler.instance().profile("LinuxSandboxedSpawnRunner.isSupported")) {
cmd.execute(ByteStreams.nullOutputStream(), ByteStreams.nullOutputStream());
} catch (CommandException e) {
return false;
}
return true;
}
@Test
public void sharedInterfaceLibraryDoesRebuildAfterInterfaceChange() throws IOException {
ImmutableList<String> args =
ImmutableList.of(
"-c",
"cxx.shlib_interfaces=enabled",
"-c",
"cxx.independent_shlib_interfaces=" + independentInterfaces,
"-c",
"cxx.objcopy=/usr/bin/objcopy",
"-c",
"cxx.platform=" + platform,
sharedBinaryTarget.getFullyQualifiedName());
String[] argv = args.toArray(new String[0]);
workspace.runBuckBuild(argv).assertSuccess();
assertTrue(workspace.replaceFileContents("library.cpp", "foo", "bar"));
workspace.runBuckBuild(argv).assertFailure();
}
@Test
public void sharedInterfaceLibraryDoesNotAffectStaticLinking() throws IOException {
BuckBuildLog log;
// Verify that using shared library interfaces does not affect static linking.
ImmutableList<String> iArgs =
ImmutableList.of(
"-c",
"cxx.shlib_interfaces=enabled",
"-c",
"cxx.independent_shlib_interfaces=" + independentInterfaces,
"-c",
"cxx.objcopy=/usr/bin/objcopy",
"-c",
"cxx.platform=" + platform,
staticBinaryTarget.getFullyQualifiedName());
String[] iArgv = iArgs.toArray(new String[0]);
workspace.runBuckBuild(iArgv).assertSuccess();
assertTrue(workspace.replaceFileContents("library.cpp", "bar1", "bar2"));
workspace.runBuckBuild(iArgv).assertSuccess();
log = workspace.getBuildLog();
log.assertTargetBuiltLocally(staticBinaryBuiltTarget);
}
JavaFileObject build() {
ImmutableList<String> list =
ImmutableList.<String>builder()
.add("package foo.bar;", "", "import com.google.auto.value.AutoValue;")
.addAll(imports)
.add("", "@AutoValue", "public abstract class Baz {")
.addAll(annotations)
.add(
" public abstract int buh();",
"",
" public static Baz create(int buh) {",
" return new AutoValue_Baz(buh);",
" }")
.addAll(innerTypes)
.add("}")
.build();
String[] lines = list.toArray(new String[list.size()]);
return JavaFileObjects.forSourceLines("foo.bar.Baz", lines);
}
private static String[] constructFullDockerComposeExecArguments(DockerComposeExecOption dockerComposeExecOption,
String containerName, DockerComposeExecArgument dockerComposeExecArgument) {
// The "-T" option here disables pseudo-TTY allocation, which is not useful here since we are not using
// terminal features here (e.g. we are not sending ^C to kill the executed process).
// Disabling pseudo-TTY allocation means this will work on OS's that don't support TTY (i.e. Windows)
ImmutableList<String> fullArgs = new ImmutableList.Builder<String>().add("exec")
.add("-T")
.addAll(dockerComposeExecOption.options())
.add(containerName)
.addAll(dockerComposeExecArgument.arguments())
.build();
return fullArgs.toArray(new String[fullArgs.size()]);
}
private static String[] constructFullDockerComposeRunArguments(DockerComposeRunOption dockerComposeRunOption,
String containerName, DockerComposeRunArgument dockerComposeRunArgument) {
ImmutableList<String> fullArgs = new ImmutableList.Builder<String>().add("run")
.addAll(dockerComposeRunOption.options())
.add(containerName)
.addAll(dockerComposeRunArgument.arguments())
.build();
return fullArgs.toArray(new String[fullArgs.size()]);
}
@Test
public void testPriorityQueueOrdering() {
PriorityQueue<SamzaResourceRequest> pq = new PriorityQueue<>();
Instant now = Instant.now();
ImmutableList<SamzaResourceRequest> expectedOrder = ImmutableList.of(
createRequestForActive(now.minusSeconds(120)),
createRequestForActive(now),
createRequestForActive(now.plusSeconds(120)),
createRequestForActive(now.plusSeconds(240)),
createRequestForStandby(now.minusSeconds(120)),
createRequestForStandby(now),
createRequestForStandby(now.plusSeconds(120)),
createRequestForStandby(now.plusSeconds(240)));
SamzaResourceRequest[] copyExpectedOrder = new SamzaResourceRequest[expectedOrder.size()];
copyExpectedOrder = expectedOrder.toArray(copyExpectedOrder);
List<SamzaResourceRequest> shuffled = Arrays.asList(copyExpectedOrder);
Collections.shuffle(shuffled, new Random(Instant.now().toEpochMilli()));
pq.addAll(shuffled);
ArrayList priorityQueueOrder = new ArrayList();
for (int i = 0; i < expectedOrder.size(); ++i) {
priorityQueueOrder.add(pq.poll());
}
assertEquals(expectedOrder, priorityQueueOrder);
}
@Test
public void testDelayedQueueOrdering() {
ResourceRequestState.DelayedRequestQueue delayedRequestQueue = new ResourceRequestState.DelayedRequestQueue();
Instant now = Instant.now();
// Expected priority by request timestamp only, regardless of active or standby
ImmutableList<SamzaResourceRequest> expectedOrder = ImmutableList.of(
createRequestForActive(now),
createRequestForStandby(now.plusSeconds(60)),
createRequestForActive(now.plusSeconds(120)),
createRequestForStandby(now.plusSeconds(121)),
createRequestForActive(now.plusSeconds(240)),
createRequestForStandby(now.plusSeconds(241)));
SamzaResourceRequest[] copyExpectedOrder = new SamzaResourceRequest[expectedOrder.size()];
copyExpectedOrder = expectedOrder.toArray(copyExpectedOrder);
List<SamzaResourceRequest> shuffled = Arrays.asList(copyExpectedOrder);
Collections.shuffle(shuffled, new Random(Instant.now().toEpochMilli()));
delayedRequestQueue.addAll(shuffled);
ArrayList priorityQueueOrder = new ArrayList();
for (int i = 0; i < expectedOrder.size(); ++i) {
priorityQueueOrder.add(delayedRequestQueue.poll());
}
assertEquals(expectedOrder, priorityQueueOrder);
}
@Override
protected void useConfiguration(String... args) throws Exception {
ImmutableList<String> extraArgs = ImmutableList.<String>builder()
.add("--xcode_version_config=" + MockObjcSupport.XCODE_VERSION_CONFIG)
.add("--apple_crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL)
.add("--crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL)
.addAll(ImmutableList.copyOf(args))
.build();
super.useConfiguration(extraArgs.toArray(new String[extraArgs.size()]));
}
@Test
public void testCommand_Echo() throws Exception {
ImmutableList<String> commandArguments = ImmutableList.of("echo", "colorless green ideas");
Command command = new Command(commandArguments.toArray(new String[0]));
CommandResult commandResult = command.execute();
assertThat(commandResult.getTerminationStatus().success()).isTrue();
assertThat(commandResult.getStdoutStream().toString()).contains("colorless green ideas");
}
@Test
public void testCommand_Echo() throws Exception {
ImmutableList<String> commandArguments = ImmutableList.of("echo", "worker bees can leave");
Command command = new Command(commandArguments.toArray(new String[0]));
CommandResult commandResult = command.execute();
assertThat(commandResult.getTerminationStatus().success()).isTrue();
assertThat(commandResult.getStdoutStream().toString()).contains("worker bees can leave");
}
public synchronized ClassLoader getClassLoaderForClassPath(
@Nullable ClassLoader parentClassLoader, ImmutableList<URL> classPath) {
Map<ImmutableList<URL>, ClassLoader> cacheForParent = getCacheForParent(parentClassLoader);
ClassLoader classLoader = cacheForParent.get(classPath);
if (classLoader == null) {
URL[] urls = classPath.toArray(new URL[0]);
classLoader = new CachedURLClassLoader(urls, parentClassLoader);
cacheForParent.put(classPath, classLoader);
}
return classLoader;
}
/**
* Returns a newly-created {@link TokenBucket} based on the set of limits configured for this builder.
*/
public TokenBucket build() {
final ImmutableList<BandwidthLimit> limits = limitsBuilder.build();
return new TokenBucket(limits.isEmpty() ? NO_BANDWIDTH_LIMITS
: limits.toArray(NO_BANDWIDTH_LIMITS));
}
@Test
public void sharedInterfaceLibraryPreventsRebuildAfterNonLocalVarNameChange() throws IOException {
BuckBuildLog log;
// First verify that *not* using shared library interfaces causes a rebuild even after making a
// non-interface change.
ImmutableList<String> args =
ImmutableList.of(
"-c",
"cxx.shlib_interfaces=disabled",
"-c",
"cxx.objcopy=/usr/bin/objcopy",
"-c",
"cxx.platform=" + platform,
sharedBinaryTarget.getFullyQualifiedName());
String[] argv = args.toArray(new String[0]);
workspace.runBuckBuild(argv).assertSuccess();
assertTrue(workspace.replaceFileContents("library.cpp", "bar1", "bar2"));
workspace.runBuckBuild(argv).assertSuccess();
log = workspace.getBuildLog();
if (sharedLibraryTarget.isPresent()) {
log.assertTargetBuiltLocally(sharedLibraryTarget.get());
}
log.assertTargetBuiltLocally(sharedBinaryBuiltTarget);
// Now verify that using shared library interfaces does not cause a rebuild after making a
// non-interface change.
ImmutableList<String> iArgs =
ImmutableList.of(
"-c",
"cxx.shlib_interfaces=enabled",
"-c",
"cxx.independent_shlib_interfaces=" + independentInterfaces,
"-c",
"cxx.objcopy=/usr/bin/objcopy",
"-c",
"cxx.platform=" + platform,
sharedBinaryTarget.getFullyQualifiedName());
String[] iArgv = iArgs.toArray(new String[0]);
workspace.runBuckBuild(iArgv).assertSuccess();
assertTrue(workspace.replaceFileContents("library.cpp", "bar2", "bar3"));
workspace.runBuckBuild(iArgv).assertSuccess();
log = workspace.getBuildLog();
if (sharedLibraryTarget.isPresent()) {
log.assertTargetBuiltLocally(sharedLibraryTarget.get());
}
log.assertTargetHadMatchingInputRuleKey(sharedBinaryBuiltTarget);
}
@Test
public void sharedInterfaceLibraryPreventsRebuildAfterCodeChange() throws IOException {
BuckBuildLog log;
// First verify that *not* using shared library interfaces causes a rebuild even after making a
// non-interface change.
ImmutableList<String> args =
ImmutableList.of(
"-c",
"cxx.shlib_interfaces=disabled",
"-c",
"cxx.objcopy=/usr/bin/objcopy",
"-c",
"cxx.platform=" + platform,
sharedBinaryTarget.getFullyQualifiedName());
String[] argv = args.toArray(new String[0]);
workspace.runBuckBuild(argv).assertSuccess();
assertTrue(workspace.replaceFileContents("library.cpp", "bar1 = 0", "bar1 = 1"));
workspace.runBuckBuild(argv).assertSuccess();
log = workspace.getBuildLog();
if (sharedLibraryTarget.isPresent()) {
log.assertTargetBuiltLocally(sharedLibraryTarget.get());
}
log.assertTargetBuiltLocally(sharedBinaryBuiltTarget);
// Now verify that using shared library interfaces does not cause a rebuild after making a
// non-interface change.
ImmutableList<String> iArgs =
ImmutableList.of(
"-c",
"cxx.shlib_interfaces=enabled",
"-c",
"cxx.independent_shlib_interfaces=" + independentInterfaces,
"-c",
"cxx.objcopy=/usr/bin/objcopy",
"-c",
"cxx.platform=" + platform,
sharedBinaryTarget.getFullyQualifiedName());
String[] iArgv = iArgs.toArray(new String[0]);
workspace.runBuckBuild(iArgv).assertSuccess();
assertTrue(workspace.replaceFileContents("library.cpp", "bar1 = 1", "bar1 = 2"));
workspace.runBuckBuild(iArgv).assertSuccess();
log = workspace.getBuildLog();
if (sharedLibraryTarget.isPresent()) {
log.assertTargetBuiltLocally(sharedLibraryTarget.get());
}
log.assertTargetHadMatchingInputRuleKey(sharedBinaryBuiltTarget);
}
@Test
public void sharedInterfaceLibraryPreventsRebuildAfterAddedCode() throws IOException {
BuckBuildLog log;
// First verify that *not* using shared library interfaces causes a rebuild even after making a
// non-interface change.
ImmutableList<String> args =
ImmutableList.of(
"-c",
"cxx.shlib_interfaces=disabled",
"-c",
"cxx.objcopy=/usr/bin/objcopy",
"-c",
"cxx.platform=" + platform,
sharedBinaryTarget.getFullyQualifiedName());
String[] argv = args.toArray(new String[0]);
workspace.runBuckBuild(argv).assertSuccess();
assertTrue(workspace.replaceFileContents("library.cpp", "return bar1", "return bar1 += 15"));
workspace.runBuckBuild(argv).assertSuccess();
log = workspace.getBuildLog();
if (sharedLibraryTarget.isPresent()) {
log.assertTargetBuiltLocally(sharedLibraryTarget.get());
}
log.assertTargetBuiltLocally(sharedBinaryBuiltTarget);
// Revert changes.
assertTrue(workspace.replaceFileContents("library.cpp", "return bar1 += 15", "return bar1"));
// Now verify that using shared library interfaces does not cause a rebuild after making a
// non-interface change.
ImmutableList<String> iArgs =
ImmutableList.of(
"-c",
"cxx.shlib_interfaces=enabled",
"-c",
"cxx.independent_shlib_interfaces=" + independentInterfaces,
"-c",
"cxx.objcopy=/usr/bin/objcopy",
"-c",
"cxx.platform=" + platform,
sharedBinaryTarget.getFullyQualifiedName());
String[] iArgv = iArgs.toArray(new String[0]);
workspace.runBuckBuild(iArgv).assertSuccess();
assertTrue(workspace.replaceFileContents("library.cpp", "return bar1", "return bar1 += 15"));
workspace.runBuckBuild(iArgv).assertSuccess();
log = workspace.getBuildLog();
if (sharedLibraryTarget.isPresent()) {
log.assertTargetBuiltLocally(sharedLibraryTarget.get());
}
log.assertTargetHadMatchingInputRuleKey(sharedBinaryBuiltTarget);
}
@Test
public void sharedInterfaceLibraryPreventsRebuildAfterAddedUndefinedSymbol() throws IOException {
BuckBuildLog log;
String originalContents = workspace.getFileContents("library.cpp");
// First verify that *not* using shared library interfaces causes a rebuild even after making a
// non-interface change.
ImmutableList<String> args =
ImmutableList.of(
"-c",
"cxx.shlib_interfaces=disabled",
"-c",
"cxx.objcopy=/usr/bin/objcopy",
"-c",
"cxx.platform=" + platform,
sharedBinaryTarget.getFullyQualifiedName());
String[] argv = args.toArray(new String[0]);
workspace.runBuckBuild(argv).assertSuccess();
assertTrue(workspace.replaceFileContents("library.cpp", "return bar1", "return bar1 + bar2"));
workspace.runBuckBuild(argv).assertSuccess();
log = workspace.getBuildLog();
if (sharedLibraryTarget.isPresent()) {
log.assertTargetBuiltLocally(sharedLibraryTarget.get());
}
log.assertTargetBuiltLocally(sharedBinaryBuiltTarget);
// Revert changes.
workspace.writeContentsToPath(originalContents, "library.cpp");
// Now verify that using shared library interfaces does not cause a rebuild after making a
// non-interface change.
ImmutableList<String> iArgs =
ImmutableList.of(
"-c",
"cxx.shlib_interfaces=defined_only",
"-c",
"cxx.objcopy=/usr/bin/objcopy",
"-c",
"cxx.platform=" + platform,
sharedBinaryTarget.getFullyQualifiedName());
String[] iArgv = iArgs.toArray(new String[0]);
workspace.runBuckBuild(iArgv).assertSuccess();
assertTrue(workspace.replaceFileContents("library.cpp", "return bar1", "return bar1 + bar2"));
workspace.runBuckBuild(iArgv).assertSuccess();
log = workspace.getBuildLog();
if (sharedLibraryTarget.isPresent()) {
log.assertTargetBuiltLocally(sharedLibraryTarget.get());
}
log.assertTargetHadMatchingInputRuleKey(sharedBinaryBuiltTarget);
}
JavaFileObject build() {
String nullable = methodAnnotations.contains("@Nullable") ? "@Nullable " : "";
ImmutableSortedSet<String> allImports =
ImmutableSortedSet.<String>naturalOrder()
.add(GeneratedImport.importGeneratedAnnotationType())
.addAll(imports)
.build();
ImmutableList<String> list =
ImmutableList.<String>builder()
.add("package foo.bar;", "")
.addAll(allImports)
.add(
"",
"@Generated(\"" + AutoValueProcessor.class.getName() + "\")",
"final class AutoValue_Baz extends Baz {")
.addAll(fieldAnnotations)
.add(
" private final int buh;",
" AutoValue_Baz(" + nullable + "int buh) {",
" this.buh = buh;",
" }",
"")
.addAll(methodAnnotations)
.add(
" @Override public int buh() {",
" return buh;",
" }",
"",
" @Override public String toString() {",
" return \"Baz{\"",
" + \"buh=\" + buh",
" + \"}\";",
" }",
"",
" @Override public boolean equals(Object o) {",
" if (o == this) {",
" return true;",
" }",
" if (o instanceof Baz) {",
" Baz that = (Baz) o;",
" return this.buh == that.buh();",
" }",
" return false;",
" }",
"",
" @Override public int hashCode() {",
" int h$ = 1;",
" h$ *= 1000003;",
" h$ ^= buh;",
" return h$;",
" }",
"}")
.build();
String[] lines = list.toArray(new String[list.size()]);
return JavaFileObjects.forSourceLines("foo.bar.AutoValue_Baz", lines);
}