use of java.util.EnumSet in project buck by facebook.
the class AndroidBinary method addDexingSteps.
/**
* Create dex artifacts for all of the individual directories of compiled .class files (or
* the obfuscated jar files if proguard is used). If split dex is used, multiple dex artifacts
* will be produced.
* @param classpathEntriesToDex Full set of classpath entries that must make
* their way into the final APK structure (but not necessarily into the
* primary dex).
* @param secondaryDexDirectories The contract for updating this builder must match that
* of {@link PreDexMerge#getSecondaryDexDirectories()}.
* @param steps List of steps to add to.
* @param primaryDexPath Output path for the primary dex file.
*/
@VisibleForTesting
void addDexingSteps(Set<Path> classpathEntriesToDex, Supplier<ImmutableMap<String, HashCode>> classNamesToHashesSupplier, ImmutableSet.Builder<Path> secondaryDexDirectories, ImmutableList.Builder<Step> steps, Path primaryDexPath, Optional<SourcePath> dexReorderToolFile, Optional<SourcePath> dexReorderDataDumpFile, ImmutableMultimap<APKModule, Path> additionalDexStoreToJarPathMap, SourcePathResolver resolver) {
final Supplier<Set<Path>> primaryInputsToDex;
final Optional<Path> secondaryDexDir;
final Optional<Supplier<Multimap<Path, Path>>> secondaryOutputToInputs;
Path secondaryDexParentDir = getBinPath("__%s_secondary_dex__/");
Path additionalDexParentDir = getBinPath("__%s_additional_dex__/");
Path additionalDexAssetsDir = additionalDexParentDir.resolve("assets");
final Optional<ImmutableSet<Path>> additionalDexDirs;
if (shouldSplitDex()) {
Optional<Path> proguardFullConfigFile = Optional.empty();
Optional<Path> proguardMappingFile = Optional.empty();
if (packageType.isBuildWithObfuscation()) {
Path proguardConfigDir = getProguardTextFilesPath();
proguardFullConfigFile = Optional.of(proguardConfigDir.resolve("configuration.txt"));
proguardMappingFile = Optional.of(proguardConfigDir.resolve("mapping.txt"));
}
// DexLibLoader expects that metadata.txt and secondary jar files are under this dir
// in assets.
// Intermediate directory holding the primary split-zip jar.
Path splitZipDir = getBinPath("__%s_split_zip__");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), splitZipDir));
Path primaryJarPath = splitZipDir.resolve("primary.jar");
Path secondaryJarMetaDirParent = splitZipDir.resolve("secondary_meta");
Path secondaryJarMetaDir = secondaryJarMetaDirParent.resolve(SECONDARY_DEX_SUBDIR);
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), secondaryJarMetaDir));
Path secondaryJarMeta = secondaryJarMetaDir.resolve("metadata.txt");
// Intermediate directory holding _ONLY_ the secondary split-zip jar files. This is
// important because SmartDexingCommand will try to dx every entry in this directory. It
// does this because it's impossible to know what outputs split-zip will generate until it
// runs.
final Path secondaryZipDir = getBinPath("__%s_secondary_zip__");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), secondaryZipDir));
// Intermediate directory holding the directories holding _ONLY_ the additional split-zip
// jar files that are intended for that dex store.
final Path additionalDexStoresZipDir = getBinPath("__%s_dex_stores_zip__");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), additionalDexStoresZipDir));
for (APKModule dexStore : additionalDexStoreToJarPathMap.keySet()) {
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), additionalDexStoresZipDir.resolve(dexStore.getName())));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), secondaryJarMetaDirParent.resolve("assets").resolve(dexStore.getName())));
}
// Run the split-zip command which is responsible for dividing the large set of input
// classpaths into a more compact set of jar files such that no one jar file when dexed will
// yield a dex artifact too large for dexopt or the dx method limit to handle.
Path zipSplitReportDir = getBinPath("__%s_split_zip_report__");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), zipSplitReportDir));
SplitZipStep splitZipCommand = new SplitZipStep(getProjectFilesystem(), classpathEntriesToDex, secondaryJarMeta, primaryJarPath, secondaryZipDir, "secondary-%d.jar", secondaryJarMetaDirParent, additionalDexStoresZipDir, proguardFullConfigFile, proguardMappingFile, skipProguard, dexSplitMode, dexSplitMode.getPrimaryDexScenarioFile().map(resolver::getAbsolutePath), dexSplitMode.getPrimaryDexClassesFile().map(resolver::getAbsolutePath), dexSplitMode.getSecondaryDexHeadClassesFile().map(resolver::getAbsolutePath), dexSplitMode.getSecondaryDexTailClassesFile().map(resolver::getAbsolutePath), additionalDexStoreToJarPathMap, enhancementResult.getAPKModuleGraph(), zipSplitReportDir);
steps.add(splitZipCommand);
// smart dexing command. Smart dex will handle "cleaning" this directory properly.
if (reorderClassesIntraDex) {
secondaryDexDir = Optional.of(secondaryDexParentDir.resolve(SMART_DEX_SECONDARY_DEX_SUBDIR));
Path intraDexReorderSecondaryDexDir = secondaryDexParentDir.resolve(SECONDARY_DEX_SUBDIR);
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), secondaryDexDir.get()));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), intraDexReorderSecondaryDexDir));
} else {
secondaryDexDir = Optional.of(secondaryDexParentDir.resolve(SECONDARY_DEX_SUBDIR));
steps.add(new MkdirStep(getProjectFilesystem(), secondaryDexDir.get()));
}
if (additionalDexStoreToJarPathMap.isEmpty()) {
additionalDexDirs = Optional.empty();
} else {
ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
for (APKModule dexStore : additionalDexStoreToJarPathMap.keySet()) {
Path dexStorePath = additionalDexAssetsDir.resolve(dexStore.getName());
builder.add(dexStorePath);
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), dexStorePath));
}
additionalDexDirs = Optional.of(builder.build());
}
if (dexSplitMode.getDexStore() == DexStore.RAW) {
secondaryDexDirectories.add(secondaryDexDir.get());
} else {
secondaryDexDirectories.add(secondaryJarMetaDirParent);
secondaryDexDirectories.add(secondaryDexParentDir);
}
if (additionalDexDirs.isPresent()) {
secondaryDexDirectories.add(additionalDexParentDir);
}
// Adjust smart-dex inputs for the split-zip case.
primaryInputsToDex = Suppliers.ofInstance(ImmutableSet.of(primaryJarPath));
Supplier<Multimap<Path, Path>> secondaryOutputToInputsMap = splitZipCommand.getOutputToInputsMapSupplier(secondaryDexDir.get(), additionalDexAssetsDir);
secondaryOutputToInputs = Optional.of(secondaryOutputToInputsMap);
} else {
// Simple case where our inputs are the natural classpath directories and we don't have
// to worry about secondary jar/dex files.
primaryInputsToDex = Suppliers.ofInstance(classpathEntriesToDex);
secondaryDexDir = Optional.empty();
secondaryOutputToInputs = Optional.empty();
}
HashInputJarsToDexStep hashInputJarsToDexStep = new HashInputJarsToDexStep(getProjectFilesystem(), primaryInputsToDex, secondaryOutputToInputs, classNamesToHashesSupplier);
steps.add(hashInputJarsToDexStep);
// Stores checksum information from each invocation to intelligently decide when dx needs
// to be re-run.
Path successDir = getBinPath("__%s_smart_dex__/.success");
steps.add(new MkdirStep(getProjectFilesystem(), successDir));
// Add the smart dexing tool that is capable of avoiding the external dx invocation(s) if
// it can be shown that the inputs have not changed. It also parallelizes dx invocations
// where applicable.
//
// Note that by not specifying the number of threads this command will use it will select an
// optimal default regardless of the value of --num-threads. This decision was made with the
// assumption that --num-threads specifies the threading of build rule execution and does not
// directly apply to the internal threading/parallelization details of various build commands
// being executed. For example, aapt is internally threaded by default when preprocessing
// images.
EnumSet<DxStep.Option> dxOptions = PackageType.RELEASE.equals(packageType) ? EnumSet.of(DxStep.Option.NO_LOCALS) : EnumSet.of(DxStep.Option.NO_OPTIMIZE);
Path selectedPrimaryDexPath = primaryDexPath;
if (reorderClassesIntraDex) {
String primaryDexFileName = primaryDexPath.getFileName().toString();
String smartDexPrimaryDexFileName = "smart-dex-" + primaryDexFileName;
Path smartDexPrimaryDexPath = Paths.get(primaryDexPath.toString().replace(primaryDexFileName, smartDexPrimaryDexFileName));
selectedPrimaryDexPath = smartDexPrimaryDexPath;
}
SmartDexingStep smartDexingCommand = new SmartDexingStep(getProjectFilesystem(), selectedPrimaryDexPath, primaryInputsToDex, secondaryDexDir, secondaryOutputToInputs, hashInputJarsToDexStep, successDir, dxOptions, dxExecutorService, xzCompressionLevel, dxMaxHeapSize);
steps.add(smartDexingCommand);
if (reorderClassesIntraDex) {
IntraDexReorderStep intraDexReorderStep = new IntraDexReorderStep(getProjectFilesystem(), resolver.getAbsolutePath(dexReorderToolFile.get()), resolver.getAbsolutePath(dexReorderDataDumpFile.get()), getBuildTarget(), selectedPrimaryDexPath, primaryDexPath, secondaryOutputToInputs, SMART_DEX_SECONDARY_DEX_SUBDIR, SECONDARY_DEX_SUBDIR);
steps.add(intraDexReorderStep);
}
}
use of java.util.EnumSet in project elasticsearch by elastic.
the class RestClusterStateAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest();
clusterStateRequest.indicesOptions(IndicesOptions.fromRequest(request, clusterStateRequest.indicesOptions()));
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
final String[] indices = Strings.splitStringByCommaToArray(request.param("indices", "_all"));
boolean isAllIndicesOnly = indices.length == 1 && "_all".equals(indices[0]);
if (!isAllIndicesOnly) {
clusterStateRequest.indices(indices);
}
if (request.hasParam("metric")) {
EnumSet<ClusterState.Metric> metrics = ClusterState.Metric.parseString(request.param("metric"), true);
// do not ask for what we do not need.
clusterStateRequest.nodes(metrics.contains(ClusterState.Metric.NODES) || metrics.contains(ClusterState.Metric.MASTER_NODE));
/*
* there is no distinction in Java api between routing_table and routing_nodes, it's the same info set over the wire, one single
* flag to ask for it
*/
clusterStateRequest.routingTable(metrics.contains(ClusterState.Metric.ROUTING_TABLE) || metrics.contains(ClusterState.Metric.ROUTING_NODES));
clusterStateRequest.metaData(metrics.contains(ClusterState.Metric.METADATA));
clusterStateRequest.blocks(metrics.contains(ClusterState.Metric.BLOCKS));
clusterStateRequest.customs(metrics.contains(ClusterState.Metric.CUSTOMS));
}
settingsFilter.addFilterSettingParams(request);
return channel -> client.admin().cluster().state(clusterStateRequest, new RestBuilderListener<ClusterStateResponse>(channel) {
@Override
public RestResponse buildResponse(ClusterStateResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
builder.field(Fields.CLUSTER_NAME, response.getClusterName().value());
builder.byteSizeField(Fields.CLUSTER_STATE_SIZE_IN_BYTES, Fields.CLUSTER_STATE_SIZE, response.getTotalCompressedSize());
response.getState().toXContent(builder, request);
builder.endObject();
return new BytesRestResponse(RestStatus.OK, builder);
}
});
}
use of java.util.EnumSet in project LogisticsPipes by RS485.
the class ServerRouter method recheckAdjacent.
/**
* Rechecks the piped connection to all adjacent routers as well as discover
* new ones.
*/
private boolean recheckAdjacent() {
connectionNeedsChecking = 0;
if (LPConstants.DEBUG) {
causedBy.clear();
}
if (getPipe() != null) {
/*
if (getPipe().getDebug() != null && getPipe().getDebug().debugThisPipe) {
Info info = StackTraceUtil.addTraceInformation("(" + getPipe().getX() + ", " + getPipe().getY() + ", " + getPipe().getZ() + ")");
StackTraceUtil.printTrace();
info.end();
}
*/
getPipe().spawnParticle(Particles.LightRedParticle, 5);
}
LPTickHandler.adjChecksDone++;
boolean adjacentChanged = false;
CoreRoutedPipe thisPipe = getPipe();
if (thisPipe == null) {
return false;
}
HashMap<CoreRoutedPipe, ExitRoute> adjacent;
List<Pair<ILogisticsPowerProvider, List<IFilter>>> power;
List<Pair<ISubSystemPowerProvider, List<IFilter>>> subSystemPower;
PathFinder finder = new PathFinder(thisPipe.container, Configs.LOGISTICS_DETECTION_COUNT, Configs.LOGISTICS_DETECTION_LENGTH, localChangeListener);
power = finder.powerNodes;
subSystemPower = finder.subPowerProvider;
adjacent = finder.result;
Map<ForgeDirection, List<CoreRoutedPipe>> pipeDirections = new HashMap<>();
for (Entry<CoreRoutedPipe, ExitRoute> entry : adjacent.entrySet()) {
List<CoreRoutedPipe> list = pipeDirections.get(entry.getValue().exitOrientation);
if (list == null) {
list = new ArrayList<>();
pipeDirections.put(entry.getValue().exitOrientation, list);
}
list.add(entry.getKey());
}
pipeDirections.entrySet().stream().filter(entry -> entry.getValue().size() > Configs.MAX_UNROUTED_CONNECTIONS).forEach(entry -> entry.getValue().forEach(adjacent::remove));
listenedPipes.stream().filter(list -> !finder.listenedPipes.contains(list)).forEach(list -> list.remove(localChangeListener));
listenedPipes = finder.listenedPipes;
for (CoreRoutedPipe pipe : adjacent.keySet()) {
if (pipe.stillNeedReplace()) {
return false;
}
}
boolean[] oldSideDisconnected = sideDisconnected;
sideDisconnected = new boolean[6];
checkSecurity(adjacent);
boolean changed = false;
for (int i = 0; i < 6; i++) {
changed |= sideDisconnected[i] != oldSideDisconnected[i];
}
if (changed) {
CoreRoutedPipe pipe = getPipe();
if (pipe != null) {
pipe.getWorld().notifyBlocksOfNeighborChange(pipe.getX(), pipe.getY(), pipe.getZ(), pipe.getWorld().getBlock(pipe.getX(), pipe.getY(), pipe.getZ()));
pipe.refreshConnectionAndRender(false);
}
adjacentChanged = true;
}
if (_adjacent.size() != adjacent.size()) {
adjacentChanged = true;
}
for (CoreRoutedPipe pipe : _adjacent.keySet()) {
if (!adjacent.containsKey(pipe)) {
adjacentChanged = true;
}
}
if (_powerAdjacent != null) {
if (power == null) {
adjacentChanged = true;
} else {
for (Pair<ILogisticsPowerProvider, List<IFilter>> provider : _powerAdjacent) {
if (!power.contains(provider)) {
adjacentChanged = true;
}
}
}
}
if (power != null) {
if (_powerAdjacent == null) {
adjacentChanged = true;
} else {
for (Pair<ILogisticsPowerProvider, List<IFilter>> provider : power) {
if (!_powerAdjacent.contains(provider)) {
adjacentChanged = true;
}
}
}
}
if (_subSystemPowerAdjacent != null) {
if (subSystemPower == null) {
adjacentChanged = true;
} else {
for (Pair<ISubSystemPowerProvider, List<IFilter>> provider : _subSystemPowerAdjacent) {
if (!subSystemPower.contains(provider)) {
adjacentChanged = true;
}
}
}
}
if (subSystemPower != null) {
if (_subSystemPowerAdjacent == null) {
adjacentChanged = true;
} else {
for (Pair<ISubSystemPowerProvider, List<IFilter>> provider : subSystemPower) {
if (!_subSystemPowerAdjacent.contains(provider)) {
adjacentChanged = true;
}
}
}
}
for (Entry<CoreRoutedPipe, ExitRoute> pipe : adjacent.entrySet()) {
ExitRoute oldExit = _adjacent.get(pipe.getKey());
if (oldExit == null) {
adjacentChanged = true;
break;
}
ExitRoute newExit = pipe.getValue();
if (!newExit.equals(oldExit)) {
adjacentChanged = true;
break;
}
}
if (!oldTouchedPipes.equals(finder.touchedPipes)) {
CacheHolder.clearCache(oldTouchedPipes);
CacheHolder.clearCache(finder.touchedPipes);
oldTouchedPipes = finder.touchedPipes;
BitSet visited = new BitSet(ServerRouter.getBiggestSimpleID());
visited.set(getSimpleID());
act(visited, new floodClearCache());
}
if (adjacentChanged) {
HashMap<IRouter, ExitRoute> adjacentRouter = new HashMap<>();
EnumSet<ForgeDirection> routedexits = EnumSet.noneOf(ForgeDirection.class);
EnumMap<ForgeDirection, Integer> subpowerexits = new EnumMap<>(ForgeDirection.class);
for (Entry<CoreRoutedPipe, ExitRoute> pipe : adjacent.entrySet()) {
adjacentRouter.put(pipe.getKey().getRouter(), pipe.getValue());
if ((pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canRouteTo) || pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canRequestFrom) && !routedexits.contains(pipe.getValue().exitOrientation))) {
routedexits.add(pipe.getValue().exitOrientation);
}
if (!subpowerexits.containsKey(pipe.getValue().exitOrientation) && pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
subpowerexits.put(pipe.getValue().exitOrientation, PathFinder.messureDistanceToNextRoutedPipe(getLPPosition(), pipe.getValue().exitOrientation, pipe.getKey().getWorld()));
}
}
_adjacent = Collections.unmodifiableMap(adjacent);
_adjacentRouter_Old = _adjacentRouter;
_adjacentRouter = Collections.unmodifiableMap(adjacentRouter);
if (power != null) {
_powerAdjacent = Collections.unmodifiableList(power);
} else {
_powerAdjacent = null;
}
if (subSystemPower != null) {
_subSystemPowerAdjacent = Collections.unmodifiableList(subSystemPower);
} else {
_subSystemPowerAdjacent = null;
}
_routedExits = routedexits;
_subPowerExits = subpowerexits;
SendNewLSA();
}
return adjacentChanged;
}
use of java.util.EnumSet in project robovm by robovm.
the class ClassCastExceptionTest method testMiniEnumSetAddAll.
public void testMiniEnumSetAddAll() throws Exception {
EnumSet m = EnumSet.noneOf(E.class);
EnumSet n = EnumSet.allOf(F.class);
try {
m.addAll(n);
fail();
} catch (ClassCastException ex) {
ex.printStackTrace();
assertNotNull(ex.getMessage());
}
}
use of java.util.EnumSet in project robovm by robovm.
the class ClassCastExceptionTest method testMiniEnumSetAdd.
public void testMiniEnumSetAdd() throws Exception {
EnumSet m = EnumSet.noneOf(E.class);
try {
m.add(F.A);
fail();
} catch (ClassCastException ex) {
ex.printStackTrace();
assertNotNull(ex.getMessage());
}
}
Aggregations