Search in sources :

Example 76 with Files

use of java.nio.file.Files in project cas by apereo.

the class ExportPropertiesCommand method exportProperties.

/**
 * Export properties.
 *
 * @param dir the directory for the configuration export
 * @throws Exception the exception
 */
@ShellMethod(key = "export-props", value = "Export CAS properties and settings from configuration metadata.")
public void exportProperties(@ShellOption(value = { "dir", "--dir" }, help = "Path to a directory where reference configuration files would be exported.", defaultValue = "./etc/cas/config") final String dir) throws Exception {
    val allProps = CasConfigurationMetadataCatalog.query(ConfigurationMetadataCatalogQuery.builder().queryType(ConfigurationMetadataCatalogQuery.QueryTypes.ALL).build());
    try (val writer = Files.newBufferedWriter(new File(dir, "all-properties.ref").toPath(), Charset.defaultCharset())) {
        allProps.properties().forEach(Unchecked.consumer(prop -> writeProperty(writer, prop)));
        writer.flush();
    }
    val casProps = CasConfigurationMetadataCatalog.query(ConfigurationMetadataCatalogQuery.builder().queryType(ConfigurationMetadataCatalogQuery.QueryTypes.CAS).build());
    try (val writer = Files.newBufferedWriter(new File(dir, "cas-properties.ref").toPath(), Charset.defaultCharset())) {
        casProps.properties().forEach(Unchecked.consumer(prop -> writeProperty(writer, prop)));
        writer.flush();
    }
    val thirdPartyProperties = CasConfigurationMetadataCatalog.query(ConfigurationMetadataCatalogQuery.builder().queryType(ConfigurationMetadataCatalogQuery.QueryTypes.THIRD_PARTY).build());
    try (val writer = Files.newBufferedWriter(new File(dir, "thirdparty-properties.ref").toPath(), Charset.defaultCharset())) {
        thirdPartyProperties.properties().forEach(Unchecked.consumer(prop -> writeProperty(writer, prop)));
        writer.flush();
    }
    LOGGER.info("Exported configuration properties to [{}]", new File(dir).getAbsolutePath());
}
Also used : lombok.val(lombok.val) ShellCommandGroup(org.springframework.shell.standard.ShellCommandGroup) Unchecked(org.jooq.lambda.Unchecked) Files(java.nio.file.Files) WordUtils(org.apache.commons.text.WordUtils) lombok.val(lombok.val) ConfigurationMetadataCatalogQuery(org.apereo.cas.metadata.ConfigurationMetadataCatalogQuery) ShellMethod(org.springframework.shell.standard.ShellMethod) StringUtils(org.apache.commons.lang3.StringUtils) ShellComponent(org.springframework.shell.standard.ShellComponent) ShellOption(org.springframework.shell.standard.ShellOption) File(java.io.File) Slf4j(lombok.extern.slf4j.Slf4j) Charset(java.nio.charset.Charset) Writer(java.io.Writer) CasConfigurationMetadataCatalog(org.apereo.cas.metadata.CasConfigurationMetadataCatalog) CasReferenceProperty(org.apereo.cas.metadata.CasReferenceProperty) File(java.io.File) ShellMethod(org.springframework.shell.standard.ShellMethod)

Example 77 with Files

use of java.nio.file.Files in project batfish by batfish.

the class Batfish method readFiles.

private SortedMap<Path, String> readFiles(Path directory, String description) {
    _logger.infof("\n*** READING FILES: %s ***\n", description);
    _logger.resetTimer();
    SortedMap<Path, String> fileData = new TreeMap<>();
    List<Path> filePaths;
    try (Stream<Path> paths = CommonUtil.list(directory)) {
        filePaths = paths.filter(path -> !path.getFileName().toString().startsWith(".")).sorted().collect(Collectors.toList());
    }
    AtomicInteger completed = newBatch("Reading files: " + description, filePaths.size());
    for (Path file : filePaths) {
        _logger.debugf("Reading: \"%s\"\n", file);
        String fileTextRaw = CommonUtil.readFile(file.toAbsolutePath());
        String fileText = fileTextRaw + ((fileTextRaw.length() != 0) ? "\n" : "");
        fileData.put(file, fileText);
        completed.incrementAndGet();
    }
    _logger.printElapsedTime();
    return fileData;
}
Also used : Path(java.nio.file.Path) JuniperFlattener(org.batfish.grammar.juniper.JuniperFlattener) TreeMultiSet(org.batfish.datamodel.collections.TreeMultiSet) BfConsts(org.batfish.common.BfConsts) HeaderQuestion(org.batfish.datamodel.questions.smt.HeaderQuestion) Topology(org.batfish.datamodel.Topology) Map(java.util.Map) RoutesByVrf(org.batfish.datamodel.collections.RoutesByVrf) Pair(org.batfish.common.Pair) Path(java.nio.file.Path) TopologyExtractor(org.batfish.grammar.topology.TopologyExtractor) ConfigurationFormat(org.batfish.datamodel.ConfigurationFormat) GenericConfigObject(org.batfish.datamodel.GenericConfigObject) AnswerSummary(org.batfish.datamodel.answers.AnswerSummary) ReachabilityQuerySynthesizer(org.batfish.z3.ReachabilityQuerySynthesizer) AssertionCombinedParser(org.batfish.grammar.assertion.AssertionCombinedParser) ParseEnvironmentBgpTableJob(org.batfish.job.ParseEnvironmentBgpTableJob) Serializable(java.io.Serializable) Environment(org.batfish.datamodel.pojo.Environment) AssertionExtractor(org.batfish.grammar.assertion.AssertionExtractor) Stream(java.util.stream.Stream) NamedStructureEquivalenceSets(org.batfish.datamodel.collections.NamedStructureEquivalenceSets) RoleQuestion(org.batfish.datamodel.questions.smt.RoleQuestion) BatfishCompressor(org.batfish.symbolic.abstraction.BatfishCompressor) CoordConsts(org.batfish.common.CoordConsts) AssertionContext(org.batfish.grammar.assertion.AssertionParser.AssertionContext) BatfishStackTrace(org.batfish.common.BatfishException.BatfishStackTrace) AnswerElement(org.batfish.datamodel.answers.AnswerElement) JuniperCombinedParser(org.batfish.grammar.juniper.JuniperCombinedParser) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) InitInfoAnswerElement(org.batfish.datamodel.answers.InitInfoAnswerElement) QuerySynthesizer(org.batfish.z3.QuerySynthesizer) NodJob(org.batfish.z3.NodJob) RipNeighbor(org.batfish.datamodel.RipNeighbor) SerializationUtils(org.apache.commons.lang3.SerializationUtils) HostConfiguration(org.batfish.representation.host.HostConfiguration) AclLine(org.batfish.z3.AclLine) DataPlanePlugin(org.batfish.common.plugin.DataPlanePlugin) ParseStatus(org.batfish.datamodel.answers.ParseStatus) Lists(com.google.common.collect.Lists) RunAnalysisAnswerElement(org.batfish.datamodel.answers.RunAnalysisAnswerElement) DeviceType(org.batfish.datamodel.DeviceType) AclReachabilityQuerySynthesizer(org.batfish.z3.AclReachabilityQuerySynthesizer) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Directory(org.batfish.common.Directory) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) IOException(java.io.IOException) InterfaceType(org.batfish.datamodel.InterfaceType) ReachabilitySettings(org.batfish.datamodel.questions.ReachabilitySettings) JSONArray(org.codehaus.jettison.json.JSONArray) NodeRoleSpecifier(org.batfish.datamodel.NodeRoleSpecifier) AnswerStatus(org.batfish.datamodel.answers.AnswerStatus) ExecutionException(java.util.concurrent.ExecutionException) ParseEnvironmentRoutingTableJob(org.batfish.job.ParseEnvironmentRoutingTableJob) BlacklistDstIpQuerySynthesizer(org.batfish.z3.BlacklistDstIpQuerySynthesizer) CleanBatfishException(org.batfish.common.CleanBatfishException) TreeMap(java.util.TreeMap) JSONException(org.codehaus.jettison.json.JSONException) Snapshot(org.batfish.common.Snapshot) IpsecVpn(org.batfish.datamodel.IpsecVpn) SortedSet(java.util.SortedSet) DataPlaneAnswerElement(org.batfish.datamodel.answers.DataPlaneAnswerElement) BiFunction(java.util.function.BiFunction) FlowTrace(org.batfish.datamodel.FlowTrace) BgpTableFormat(org.batfish.grammar.BgpTableFormat) FlowHistory(org.batfish.datamodel.FlowHistory) Edge(org.batfish.datamodel.Edge) ForwardingAnalysisImpl(org.batfish.datamodel.ForwardingAnalysisImpl) OspfProcess(org.batfish.datamodel.OspfProcess) Collectors.toMap(java.util.stream.Collectors.toMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PropertyChecker(org.batfish.symbolic.smt.PropertyChecker) ConvertConfigurationAnswerElement(org.batfish.datamodel.answers.ConvertConfigurationAnswerElement) NodFirstUnsatJob(org.batfish.z3.NodFirstUnsatJob) VyosFlattener(org.batfish.grammar.vyos.VyosFlattener) Vrf(org.batfish.datamodel.Vrf) ImmutableSet(com.google.common.collect.ImmutableSet) ParseVendorConfigurationJob(org.batfish.job.ParseVendorConfigurationJob) RipProcess(org.batfish.datamodel.RipProcess) StandardReachabilityQuerySynthesizer(org.batfish.z3.StandardReachabilityQuerySynthesizer) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InferRoles(org.batfish.role.InferRoles) AclLinesAnswerElement(org.batfish.datamodel.answers.AclLinesAnswerElement) ParseEnvironmentRoutingTablesAnswerElement(org.batfish.datamodel.answers.ParseEnvironmentRoutingTablesAnswerElement) NavigableMap(java.util.NavigableMap) Collectors(java.util.stream.Collectors) Settings(org.batfish.config.Settings) BatfishCombinedParser(org.batfish.grammar.BatfishCombinedParser) Entry(java.util.Map.Entry) BatfishJobExecutor(org.batfish.job.BatfishJobExecutor) Ip(org.batfish.datamodel.Ip) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) ForwardingAnalysis(org.batfish.datamodel.ForwardingAnalysis) BatfishException(org.batfish.common.BatfishException) IpAccessList(org.batfish.datamodel.IpAccessList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) TestrigSettings(org.batfish.config.Settings.TestrigSettings) BgpAdvertisementsByVrf(org.batfish.datamodel.collections.BgpAdvertisementsByVrf) ImmutableList(com.google.common.collect.ImmutableList) Version(org.batfish.common.Version) BatfishObjectMapper(org.batfish.common.util.BatfishObjectMapper) NamedStructureEquivalenceSet(org.batfish.datamodel.collections.NamedStructureEquivalenceSet) Configuration(org.batfish.datamodel.Configuration) ComputeDataPlaneResult(org.batfish.common.plugin.DataPlanePlugin.ComputeDataPlaneResult) ImmutableConfiguration(org.apache.commons.configuration2.ImmutableConfiguration) Nonnull(javax.annotation.Nonnull) ConvertConfigurationJob(org.batfish.job.ConvertConfigurationJob) Answerer(org.batfish.common.Answerer) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) NodAnswerElement(org.batfish.datamodel.answers.NodAnswerElement) NodFirstUnsatAnswerElement(org.batfish.datamodel.answers.NodFirstUnsatAnswerElement) InitStepAnswerElement(org.batfish.datamodel.answers.InitStepAnswerElement) NodSatAnswerElement(org.batfish.datamodel.answers.NodSatAnswerElement) ParseAnswerElement(org.batfish.datamodel.answers.ParseAnswerElement) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) FileVisitOption(java.nio.file.FileVisitOption) AwsConfiguration(org.batfish.representation.aws.AwsConfiguration) Cache(com.google.common.cache.Cache) HeaderLocationQuestion(org.batfish.datamodel.questions.smt.HeaderLocationQuestion) AssertionAst(org.batfish.datamodel.assertion.AssertionAst) Interface(org.batfish.datamodel.Interface) CompositeNodJob(org.batfish.z3.CompositeNodJob) DirectoryStream(java.nio.file.DirectoryStream) Flow(org.batfish.datamodel.Flow) FlattenVendorConfigurationAnswerElement(org.batfish.datamodel.answers.FlattenVendorConfigurationAnswerElement) InvalidReachabilitySettingsException(org.batfish.datamodel.questions.InvalidReachabilitySettingsException) GrammarSettings(org.batfish.grammar.GrammarSettings) IptablesVendorConfiguration(org.batfish.representation.iptables.IptablesVendorConfiguration) Verify(com.google.common.base.Verify) DataPlane(org.batfish.datamodel.DataPlane) VendorConfiguration(org.batfish.vendor.VendorConfiguration) Set(java.util.Set) EnvironmentSettings(org.batfish.config.Settings.EnvironmentSettings) IBatfish(org.batfish.common.plugin.IBatfish) Question(org.batfish.datamodel.questions.Question) Roles(org.batfish.symbolic.abstraction.Roles) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) ForwardingAction(org.batfish.datamodel.ForwardingAction) CommonUtil(org.batfish.common.util.CommonUtil) EarliestMoreGeneralReachableLineQuerySynthesizer(org.batfish.z3.EarliestMoreGeneralReachableLineQuerySynthesizer) AclReachabilityEntry(org.batfish.datamodel.answers.AclLinesAnswerElement.AclReachabilityEntry) PluginClientType(org.batfish.common.plugin.PluginClientType) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) BgpTablePlugin(org.batfish.common.plugin.BgpTablePlugin) ParseTreePrettyPrinter(org.batfish.grammar.ParseTreePrettyPrinter) ReachEdgeQuerySynthesizer(org.batfish.z3.ReachEdgeQuerySynthesizer) ValidateEnvironmentAnswerElement(org.batfish.datamodel.answers.ValidateEnvironmentAnswerElement) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) BgpAdvertisementType(org.batfish.datamodel.BgpAdvertisement.BgpAdvertisementType) Files(java.nio.file.Files) JSONObject(org.codehaus.jettison.json.JSONObject) ExternalBgpAdvertisementPlugin(org.batfish.common.plugin.ExternalBgpAdvertisementPlugin) File(java.io.File) ParseEnvironmentBgpTablesAnswerElement(org.batfish.datamodel.answers.ParseEnvironmentBgpTablesAnswerElement) Paths(java.nio.file.Paths) ActiveSpan(io.opentracing.ActiveSpan) HeaderSpace(org.batfish.datamodel.HeaderSpace) SynthesizerInputImpl(org.batfish.z3.SynthesizerInputImpl) MultiSet(org.batfish.datamodel.collections.MultiSet) NodesSpecifier(org.batfish.datamodel.questions.NodesSpecifier) Answer(org.batfish.datamodel.answers.Answer) NodSatJob(org.batfish.z3.NodSatJob) FlattenVendorConfigurationJob(org.batfish.job.FlattenVendorConfigurationJob) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PatternSyntaxException(java.util.regex.PatternSyntaxException) ImmutableMap(com.google.common.collect.ImmutableMap) Sets(com.google.common.collect.Sets) List(java.util.List) GNS3TopologyExtractor(org.batfish.grammar.topology.GNS3TopologyExtractor) Warnings(org.batfish.common.Warnings) Pattern(java.util.regex.Pattern) Synthesizer(org.batfish.z3.Synthesizer) PluginConsumer(org.batfish.common.plugin.PluginConsumer) SortedMap(java.util.SortedMap) MultipathInconsistencyQuerySynthesizer(org.batfish.z3.MultipathInconsistencyQuerySynthesizer) BatfishLogger(org.batfish.common.BatfishLogger) HashMap(java.util.HashMap) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) AbstractRoute(org.batfish.datamodel.AbstractRoute) SubRange(org.batfish.datamodel.SubRange) VyosCombinedParser(org.batfish.grammar.vyos.VyosCombinedParser) Warning(org.batfish.common.Warning) Iterator(java.util.Iterator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GlobalTracer(io.opentracing.util.GlobalTracer) GNS3TopologyCombinedParser(org.batfish.grammar.topology.GNS3TopologyCombinedParser) ParseVendorConfigurationAnswerElement(org.batfish.datamodel.answers.ParseVendorConfigurationAnswerElement) DataPlanePluginSettings(org.batfish.common.plugin.DataPlanePluginSettings) ReportAnswerElement(org.batfish.datamodel.answers.ReportAnswerElement) Collections(java.util.Collections) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TreeMap(java.util.TreeMap)

Example 78 with Files

use of java.nio.file.Files in project batfish by batfish.

the class Batfish method serializeHostConfigs.

private SortedMap<String, VendorConfiguration> serializeHostConfigs(Path testRigPath, Path outputPath, ParseVendorConfigurationAnswerElement answerElement) {
    SortedMap<Path, String> configurationData = readConfigurationFiles(testRigPath, BfConsts.RELPATH_HOST_CONFIGS_DIR);
    // read the host files
    SortedMap<String, VendorConfiguration> allHostConfigurations;
    try (ActiveSpan parseHostConfigsSpan = GlobalTracer.get().buildSpan("Parse host configs").startActive()) {
        // avoid unused warning
        assert parseHostConfigsSpan != null;
        allHostConfigurations = parseVendorConfigurations(configurationData, answerElement, ConfigurationFormat.HOST);
    }
    if (allHostConfigurations == null) {
        throw new BatfishException("Exiting due to parser errors");
    }
    _logger.infof("Testrig:%s in container:%s has total number of host configs:%d", getTestrigName(), getContainerName(), allHostConfigurations.size());
    // split into hostConfigurations and overlayConfigurations
    SortedMap<String, VendorConfiguration> overlayConfigurations = allHostConfigurations.entrySet().stream().filter(e -> ((HostConfiguration) e.getValue()).getOverlay()).collect(toMap(Entry::getKey, Entry::getValue, (v1, v2) -> v1, TreeMap::new));
    SortedMap<String, VendorConfiguration> nonOverlayHostConfigurations = allHostConfigurations.entrySet().stream().filter(e -> !((HostConfiguration) e.getValue()).getOverlay()).collect(toMap(Entry::getKey, Entry::getValue, (v1, v2) -> v1, TreeMap::new));
    // read and associate iptables files for specified hosts
    SortedMap<Path, String> iptablesData = new TreeMap<>();
    readIptableFiles(testRigPath, allHostConfigurations, iptablesData, answerElement);
    SortedMap<String, VendorConfiguration> iptablesConfigurations = parseVendorConfigurations(iptablesData, answerElement, ConfigurationFormat.IPTABLES);
    for (VendorConfiguration vc : allHostConfigurations.values()) {
        HostConfiguration hostConfig = (HostConfiguration) vc;
        if (hostConfig.getIptablesFile() != null) {
            Path path = Paths.get(testRigPath.toString(), hostConfig.getIptablesFile());
            String relativePathStr = _testrigSettings.getBasePath().relativize(path).toString();
            if (iptablesConfigurations.containsKey(relativePathStr)) {
                hostConfig.setIptablesVendorConfig((IptablesVendorConfiguration) iptablesConfigurations.get(relativePathStr));
            }
        }
    }
    // now, serialize
    _logger.info("\n*** SERIALIZING VENDOR CONFIGURATION STRUCTURES ***\n");
    _logger.resetTimer();
    CommonUtil.createDirectories(outputPath);
    Map<Path, VendorConfiguration> output = new TreeMap<>();
    nonOverlayHostConfigurations.forEach((name, vc) -> {
        Path currentOutputPath = outputPath.resolve(name);
        output.put(currentOutputPath, vc);
    });
    serializeObjects(output);
    // serialize warnings
    serializeObject(answerElement, _testrigSettings.getParseAnswerPath());
    _logger.printElapsedTime();
    return overlayConfigurations;
}
Also used : Path(java.nio.file.Path) JuniperFlattener(org.batfish.grammar.juniper.JuniperFlattener) TreeMultiSet(org.batfish.datamodel.collections.TreeMultiSet) BfConsts(org.batfish.common.BfConsts) HeaderQuestion(org.batfish.datamodel.questions.smt.HeaderQuestion) Topology(org.batfish.datamodel.Topology) Map(java.util.Map) RoutesByVrf(org.batfish.datamodel.collections.RoutesByVrf) Pair(org.batfish.common.Pair) Path(java.nio.file.Path) TopologyExtractor(org.batfish.grammar.topology.TopologyExtractor) ConfigurationFormat(org.batfish.datamodel.ConfigurationFormat) GenericConfigObject(org.batfish.datamodel.GenericConfigObject) AnswerSummary(org.batfish.datamodel.answers.AnswerSummary) ReachabilityQuerySynthesizer(org.batfish.z3.ReachabilityQuerySynthesizer) AssertionCombinedParser(org.batfish.grammar.assertion.AssertionCombinedParser) ParseEnvironmentBgpTableJob(org.batfish.job.ParseEnvironmentBgpTableJob) Serializable(java.io.Serializable) Environment(org.batfish.datamodel.pojo.Environment) AssertionExtractor(org.batfish.grammar.assertion.AssertionExtractor) Stream(java.util.stream.Stream) NamedStructureEquivalenceSets(org.batfish.datamodel.collections.NamedStructureEquivalenceSets) RoleQuestion(org.batfish.datamodel.questions.smt.RoleQuestion) BatfishCompressor(org.batfish.symbolic.abstraction.BatfishCompressor) CoordConsts(org.batfish.common.CoordConsts) AssertionContext(org.batfish.grammar.assertion.AssertionParser.AssertionContext) BatfishStackTrace(org.batfish.common.BatfishException.BatfishStackTrace) AnswerElement(org.batfish.datamodel.answers.AnswerElement) JuniperCombinedParser(org.batfish.grammar.juniper.JuniperCombinedParser) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) InitInfoAnswerElement(org.batfish.datamodel.answers.InitInfoAnswerElement) QuerySynthesizer(org.batfish.z3.QuerySynthesizer) NodJob(org.batfish.z3.NodJob) RipNeighbor(org.batfish.datamodel.RipNeighbor) SerializationUtils(org.apache.commons.lang3.SerializationUtils) HostConfiguration(org.batfish.representation.host.HostConfiguration) AclLine(org.batfish.z3.AclLine) DataPlanePlugin(org.batfish.common.plugin.DataPlanePlugin) ParseStatus(org.batfish.datamodel.answers.ParseStatus) Lists(com.google.common.collect.Lists) RunAnalysisAnswerElement(org.batfish.datamodel.answers.RunAnalysisAnswerElement) DeviceType(org.batfish.datamodel.DeviceType) AclReachabilityQuerySynthesizer(org.batfish.z3.AclReachabilityQuerySynthesizer) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Directory(org.batfish.common.Directory) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) IOException(java.io.IOException) InterfaceType(org.batfish.datamodel.InterfaceType) ReachabilitySettings(org.batfish.datamodel.questions.ReachabilitySettings) JSONArray(org.codehaus.jettison.json.JSONArray) NodeRoleSpecifier(org.batfish.datamodel.NodeRoleSpecifier) AnswerStatus(org.batfish.datamodel.answers.AnswerStatus) ExecutionException(java.util.concurrent.ExecutionException) ParseEnvironmentRoutingTableJob(org.batfish.job.ParseEnvironmentRoutingTableJob) BlacklistDstIpQuerySynthesizer(org.batfish.z3.BlacklistDstIpQuerySynthesizer) CleanBatfishException(org.batfish.common.CleanBatfishException) TreeMap(java.util.TreeMap) JSONException(org.codehaus.jettison.json.JSONException) Snapshot(org.batfish.common.Snapshot) IpsecVpn(org.batfish.datamodel.IpsecVpn) SortedSet(java.util.SortedSet) DataPlaneAnswerElement(org.batfish.datamodel.answers.DataPlaneAnswerElement) BiFunction(java.util.function.BiFunction) FlowTrace(org.batfish.datamodel.FlowTrace) BgpTableFormat(org.batfish.grammar.BgpTableFormat) FlowHistory(org.batfish.datamodel.FlowHistory) Edge(org.batfish.datamodel.Edge) ForwardingAnalysisImpl(org.batfish.datamodel.ForwardingAnalysisImpl) OspfProcess(org.batfish.datamodel.OspfProcess) Collectors.toMap(java.util.stream.Collectors.toMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PropertyChecker(org.batfish.symbolic.smt.PropertyChecker) ConvertConfigurationAnswerElement(org.batfish.datamodel.answers.ConvertConfigurationAnswerElement) NodFirstUnsatJob(org.batfish.z3.NodFirstUnsatJob) VyosFlattener(org.batfish.grammar.vyos.VyosFlattener) Vrf(org.batfish.datamodel.Vrf) ImmutableSet(com.google.common.collect.ImmutableSet) ParseVendorConfigurationJob(org.batfish.job.ParseVendorConfigurationJob) RipProcess(org.batfish.datamodel.RipProcess) StandardReachabilityQuerySynthesizer(org.batfish.z3.StandardReachabilityQuerySynthesizer) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InferRoles(org.batfish.role.InferRoles) AclLinesAnswerElement(org.batfish.datamodel.answers.AclLinesAnswerElement) ParseEnvironmentRoutingTablesAnswerElement(org.batfish.datamodel.answers.ParseEnvironmentRoutingTablesAnswerElement) NavigableMap(java.util.NavigableMap) Collectors(java.util.stream.Collectors) Settings(org.batfish.config.Settings) BatfishCombinedParser(org.batfish.grammar.BatfishCombinedParser) Entry(java.util.Map.Entry) BatfishJobExecutor(org.batfish.job.BatfishJobExecutor) Ip(org.batfish.datamodel.Ip) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) ForwardingAnalysis(org.batfish.datamodel.ForwardingAnalysis) BatfishException(org.batfish.common.BatfishException) IpAccessList(org.batfish.datamodel.IpAccessList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) TestrigSettings(org.batfish.config.Settings.TestrigSettings) BgpAdvertisementsByVrf(org.batfish.datamodel.collections.BgpAdvertisementsByVrf) ImmutableList(com.google.common.collect.ImmutableList) Version(org.batfish.common.Version) BatfishObjectMapper(org.batfish.common.util.BatfishObjectMapper) NamedStructureEquivalenceSet(org.batfish.datamodel.collections.NamedStructureEquivalenceSet) Configuration(org.batfish.datamodel.Configuration) ComputeDataPlaneResult(org.batfish.common.plugin.DataPlanePlugin.ComputeDataPlaneResult) ImmutableConfiguration(org.apache.commons.configuration2.ImmutableConfiguration) Nonnull(javax.annotation.Nonnull) ConvertConfigurationJob(org.batfish.job.ConvertConfigurationJob) Answerer(org.batfish.common.Answerer) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) NodAnswerElement(org.batfish.datamodel.answers.NodAnswerElement) NodFirstUnsatAnswerElement(org.batfish.datamodel.answers.NodFirstUnsatAnswerElement) InitStepAnswerElement(org.batfish.datamodel.answers.InitStepAnswerElement) NodSatAnswerElement(org.batfish.datamodel.answers.NodSatAnswerElement) ParseAnswerElement(org.batfish.datamodel.answers.ParseAnswerElement) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) FileVisitOption(java.nio.file.FileVisitOption) AwsConfiguration(org.batfish.representation.aws.AwsConfiguration) Cache(com.google.common.cache.Cache) HeaderLocationQuestion(org.batfish.datamodel.questions.smt.HeaderLocationQuestion) AssertionAst(org.batfish.datamodel.assertion.AssertionAst) Interface(org.batfish.datamodel.Interface) CompositeNodJob(org.batfish.z3.CompositeNodJob) DirectoryStream(java.nio.file.DirectoryStream) Flow(org.batfish.datamodel.Flow) FlattenVendorConfigurationAnswerElement(org.batfish.datamodel.answers.FlattenVendorConfigurationAnswerElement) InvalidReachabilitySettingsException(org.batfish.datamodel.questions.InvalidReachabilitySettingsException) GrammarSettings(org.batfish.grammar.GrammarSettings) IptablesVendorConfiguration(org.batfish.representation.iptables.IptablesVendorConfiguration) Verify(com.google.common.base.Verify) DataPlane(org.batfish.datamodel.DataPlane) VendorConfiguration(org.batfish.vendor.VendorConfiguration) Set(java.util.Set) EnvironmentSettings(org.batfish.config.Settings.EnvironmentSettings) IBatfish(org.batfish.common.plugin.IBatfish) Question(org.batfish.datamodel.questions.Question) Roles(org.batfish.symbolic.abstraction.Roles) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) ForwardingAction(org.batfish.datamodel.ForwardingAction) CommonUtil(org.batfish.common.util.CommonUtil) EarliestMoreGeneralReachableLineQuerySynthesizer(org.batfish.z3.EarliestMoreGeneralReachableLineQuerySynthesizer) AclReachabilityEntry(org.batfish.datamodel.answers.AclLinesAnswerElement.AclReachabilityEntry) PluginClientType(org.batfish.common.plugin.PluginClientType) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) BgpTablePlugin(org.batfish.common.plugin.BgpTablePlugin) ParseTreePrettyPrinter(org.batfish.grammar.ParseTreePrettyPrinter) ReachEdgeQuerySynthesizer(org.batfish.z3.ReachEdgeQuerySynthesizer) ValidateEnvironmentAnswerElement(org.batfish.datamodel.answers.ValidateEnvironmentAnswerElement) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) BgpAdvertisementType(org.batfish.datamodel.BgpAdvertisement.BgpAdvertisementType) Files(java.nio.file.Files) JSONObject(org.codehaus.jettison.json.JSONObject) ExternalBgpAdvertisementPlugin(org.batfish.common.plugin.ExternalBgpAdvertisementPlugin) File(java.io.File) ParseEnvironmentBgpTablesAnswerElement(org.batfish.datamodel.answers.ParseEnvironmentBgpTablesAnswerElement) Paths(java.nio.file.Paths) ActiveSpan(io.opentracing.ActiveSpan) HeaderSpace(org.batfish.datamodel.HeaderSpace) SynthesizerInputImpl(org.batfish.z3.SynthesizerInputImpl) MultiSet(org.batfish.datamodel.collections.MultiSet) NodesSpecifier(org.batfish.datamodel.questions.NodesSpecifier) Answer(org.batfish.datamodel.answers.Answer) NodSatJob(org.batfish.z3.NodSatJob) FlattenVendorConfigurationJob(org.batfish.job.FlattenVendorConfigurationJob) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PatternSyntaxException(java.util.regex.PatternSyntaxException) ImmutableMap(com.google.common.collect.ImmutableMap) Sets(com.google.common.collect.Sets) List(java.util.List) GNS3TopologyExtractor(org.batfish.grammar.topology.GNS3TopologyExtractor) Warnings(org.batfish.common.Warnings) Pattern(java.util.regex.Pattern) Synthesizer(org.batfish.z3.Synthesizer) PluginConsumer(org.batfish.common.plugin.PluginConsumer) SortedMap(java.util.SortedMap) MultipathInconsistencyQuerySynthesizer(org.batfish.z3.MultipathInconsistencyQuerySynthesizer) BatfishLogger(org.batfish.common.BatfishLogger) HashMap(java.util.HashMap) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) AbstractRoute(org.batfish.datamodel.AbstractRoute) SubRange(org.batfish.datamodel.SubRange) VyosCombinedParser(org.batfish.grammar.vyos.VyosCombinedParser) Warning(org.batfish.common.Warning) Iterator(java.util.Iterator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GlobalTracer(io.opentracing.util.GlobalTracer) GNS3TopologyCombinedParser(org.batfish.grammar.topology.GNS3TopologyCombinedParser) ParseVendorConfigurationAnswerElement(org.batfish.datamodel.answers.ParseVendorConfigurationAnswerElement) DataPlanePluginSettings(org.batfish.common.plugin.DataPlanePluginSettings) ReportAnswerElement(org.batfish.datamodel.answers.ReportAnswerElement) Collections(java.util.Collections) CleanBatfishException(org.batfish.common.CleanBatfishException) BatfishException(org.batfish.common.BatfishException) IptablesVendorConfiguration(org.batfish.representation.iptables.IptablesVendorConfiguration) VendorConfiguration(org.batfish.vendor.VendorConfiguration) ActiveSpan(io.opentracing.ActiveSpan) HostConfiguration(org.batfish.representation.host.HostConfiguration) TreeMap(java.util.TreeMap)

Example 79 with Files

use of java.nio.file.Files in project sts4 by spring-projects.

the class SpringIndexer method scanFiles.

private void scanFiles(WorkspaceFolder directory) {
    try {
        Map<Optional<IJavaProject>, List<String>> projects = Files.walk(Paths.get(new URI(directory.getUri()))).filter(path -> path.getFileName().toString().endsWith(".java")).filter(Files::isRegularFile).map(path -> path.toAbsolutePath().toString()).collect(Collectors.groupingBy((javaFile) -> projectFinder.find(new TextDocumentIdentifier(new File(javaFile).toURI().toString()))));
        projects.forEach((maybeProject, files) -> maybeProject.ifPresent(project -> scanProject(project, files.toArray(new String[0]))));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Arrays(java.util.Arrays) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) SymbolProvider(org.springframework.ide.vscode.boot.java.handlers.SymbolProvider) LoggerFactory(org.slf4j.LoggerFactory) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) FileASTRequestor(org.eclipse.jdt.core.dom.FileASTRequestor) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Location(org.eclipse.lsp4j.Location) AnnotationHierarchyAwareLookup(org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchyAwareLookup) URI(java.net.URI) Path(java.nio.file.Path) ExceptionUtil(org.springframework.ide.vscode.commons.util.ExceptionUtil) Predicate(java.util.function.Predicate) SymbolAddOnInformation(org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) EnhancedSymbolInformation(org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation) List(java.util.List) Stream(java.util.stream.Stream) ASTParser(org.eclipse.jdt.core.dom.ASTParser) WorkspaceFolder(org.eclipse.lsp4j.WorkspaceFolder) AST(org.eclipse.jdt.core.dom.AST) Optional(java.util.Optional) SimpleWorkspaceService(org.springframework.ide.vscode.commons.languageserver.util.SimpleWorkspaceService) SingleMemberAnnotation(org.eclipse.jdt.core.dom.SingleMemberAnnotation) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) SimpleLanguageServer(org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer) MarkerAnnotation(org.eclipse.jdt.core.dom.MarkerAnnotation) JavaProjectFinder(org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder) SymbolKind(org.eclipse.lsp4j.SymbolKind) BootLanguageServerParams(org.springframework.ide.vscode.boot.BootLanguageServerParams) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) ProjectObserver(org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) ImmutableList(com.google.common.collect.ImmutableList) Annotation(org.eclipse.jdt.core.dom.Annotation) AnnotationHierarchies(org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchies) UriUtil(org.springframework.ide.vscode.commons.util.UriUtil) NormalAnnotation(org.eclipse.jdt.core.dom.NormalAnnotation) IClasspath(org.springframework.ide.vscode.commons.java.IClasspath) LanguageId(org.springframework.ide.vscode.commons.util.text.LanguageId) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) Logger(org.slf4j.Logger) Files(java.nio.file.Files) JavaCore(org.eclipse.jdt.core.JavaCore) Futures(org.springframework.ide.vscode.commons.util.Futures) FileUtils(org.apache.commons.io.FileUtils) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) File(java.io.File) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) Listener(org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener) Paths(java.nio.file.Paths) Collections(java.util.Collections) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Optional(java.util.Optional) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Files(java.nio.file.Files) URI(java.net.URI) File(java.io.File)

Example 80 with Files

use of java.nio.file.Files in project mycore by MyCoRe-Org.

the class MCRPathXML method getDirectoryXML.

/**
 * Sends the contents of an MCRDirectory as XML data to the client
 */
public static Document getDirectoryXML(MCRPath path, BasicFileAttributes attr) throws IOException {
    LOGGER.debug("MCRDirectoryXML: start listing of directory {}", path);
    Element root = new Element("mcr_directory");
    Document doc = new org.jdom2.Document(root);
    addString(root, "uri", path.toUri().toString(), false);
    addString(root, "ownerID", path.getOwner(), false);
    MCRPath relativePath = path.getRoot().relativize(path);
    boolean isRoot = relativePath.toString().isEmpty();
    addString(root, "name", (isRoot ? "" : relativePath.getFileName().toString()), true);
    addString(root, "path", toStringValue(relativePath), true);
    if (!isRoot) {
        addString(root, "parentPath", toStringValue(relativePath.getParent()), true);
    }
    addBasicAttributes(root, attr, path);
    Element numChildren = new Element("numChildren");
    Element here = new Element("here");
    root.addContent(numChildren);
    numChildren.addContent(here);
    Element nodes = new Element("children");
    root.addContent(nodes);
    SortedMap<MCRPath, MCRFileAttributes<?>> directories = new TreeMap<>();
    SortedMap<MCRPath, MCRFileAttributes<?>> files = new TreeMap<>();
    try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(path)) {
        LOGGER.debug(() -> "Opened DirectoryStream for " + path);
        Function<Path, MCRFileAttributes<?>> attrResolver = p -> {
            try {
                return Files.readAttributes(p, MCRFileAttributes.class);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        };
        if (dirStream instanceof SecureDirectoryStream) {
            // fast path
            LOGGER.debug(() -> "Using SecureDirectoryStream code path for " + path);
            attrResolver = p -> {
                try {
                    BasicFileAttributeView attributeView = ((SecureDirectoryStream<Path>) dirStream).getFileAttributeView(p.getFileName(), BasicFileAttributeView.class);
                    return (MCRFileAttributes<?>) attributeView.readAttributes();
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            };
        }
        for (Path child : dirStream) {
            MCRFileAttributes<?> childAttrs;
            try {
                childAttrs = attrResolver.apply(child);
            } catch (UncheckedIOException e) {
                throw e.getCause();
            }
            if (childAttrs.isDirectory()) {
                directories.put(MCRPath.toMCRPath(child), childAttrs);
            } else {
                files.put(MCRPath.toMCRPath(child), childAttrs);
            }
        }
    }
    // store current directory statistics
    addString(here, "directories", Integer.toString(directories.size()), false);
    addString(here, "files", Integer.toString(files.size()), false);
    for (Map.Entry<MCRPath, MCRFileAttributes<?>> dirEntry : directories.entrySet()) {
        Element child = new Element("child");
        child.setAttribute("type", "directory");
        addString(child, "name", dirEntry.getKey().getFileName().toString(), true);
        addString(child, "uri", dirEntry.getKey().toUri().toString(), false);
        nodes.addContent(child);
        addBasicAttributes(child, dirEntry.getValue(), dirEntry.getKey());
    }
    for (Map.Entry<MCRPath, MCRFileAttributes<?>> fileEntry : files.entrySet()) {
        Element child = new Element("child");
        child.setAttribute("type", "file");
        addString(child, "name", fileEntry.getKey().getFileName().toString(), true);
        addString(child, "uri", fileEntry.getKey().toUri().toString(), false);
        nodes.addContent(child);
        addAttributes(child, fileEntry.getValue(), fileEntry.getKey());
    }
    LOGGER.debug("MCRDirectoryXML: end listing of directory {}", path);
    return doc;
}
Also used : Path(java.nio.file.Path) MCRConstants(org.mycore.common.MCRConstants) FileTime(java.nio.file.attribute.FileTime) Function(java.util.function.Function) SEPARATOR_STRING(org.mycore.datamodel.niofs.MCRAbstractFileSystem.SEPARATOR_STRING) Document(org.jdom2.Document) DirectoryStream(java.nio.file.DirectoryStream) MCRCategLinkServiceFactory(org.mycore.datamodel.classifications2.MCRCategLinkServiceFactory) SecureDirectoryStream(java.nio.file.SecureDirectoryStream) BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) Map(java.util.Map) Path(java.nio.file.Path) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference) MCRMetadataManager(org.mycore.datamodel.metadata.MCRMetadataManager) Files(java.nio.file.Files) Collection(java.util.Collection) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) IOException(java.io.IOException) SEPARATOR(org.mycore.datamodel.niofs.MCRAbstractFileSystem.SEPARATOR) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) UncheckedIOException(java.io.UncheckedIOException) TimeUnit(java.util.concurrent.TimeUnit) Logger(org.apache.logging.log4j.Logger) TreeMap(java.util.TreeMap) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) LogManager(org.apache.logging.log4j.LogManager) SortedMap(java.util.SortedMap) Element(org.jdom2.Element) Element(org.jdom2.Element) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Document(org.jdom2.Document) TreeMap(java.util.TreeMap) SecureDirectoryStream(java.nio.file.SecureDirectoryStream) BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Aggregations

Files (java.nio.file.Files)243 IOException (java.io.IOException)210 Path (java.nio.file.Path)196 List (java.util.List)176 Collectors (java.util.stream.Collectors)154 Paths (java.nio.file.Paths)133 File (java.io.File)127 ArrayList (java.util.ArrayList)117 Map (java.util.Map)109 Set (java.util.Set)96 Collections (java.util.Collections)89 Arrays (java.util.Arrays)81 Stream (java.util.stream.Stream)77 HashMap (java.util.HashMap)74 HashSet (java.util.HashSet)58 InputStream (java.io.InputStream)55 Collection (java.util.Collection)55 Logger (org.slf4j.Logger)54 Pattern (java.util.regex.Pattern)53 Optional (java.util.Optional)51