Search in sources :

Example 21 with Type

use of org.apache.commons.vfs2.UserAuthenticationData.Type in project pentaho-kettle by pentaho.

the class Spoon method newStep.

/**
 * Allocate new step, optionally open and rename it.
 *
 * @param id
 *          Id of the new step
 * @param name
 *          Name of the new step
 * @param description
 *          Description of the type of step
 * @param openit
 *          Open the dialog for this step?
 * @param rename
 *          Rename this step?
 *
 * @return The newly created StepMeta object.
 */
public StepMeta newStep(TransMeta transMeta, String id, String name, String description, boolean openit, boolean rename) {
    StepMeta inf = null;
    // See if we need to rename the step to avoid doubles!
    if (rename && transMeta.findStep(name) != null) {
        int i = 2;
        String newName = name + " " + i;
        while (transMeta.findStep(newName) != null) {
            i++;
            newName = name + " " + i;
        }
        name = newName;
    }
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface stepPlugin = id != null ? registry.findPluginWithId(StepPluginType.class, id) : registry.findPluginWithName(StepPluginType.class, description);
    try {
        if (stepPlugin != null) {
            StepMetaInterface info = (StepMetaInterface) registry.loadClass(stepPlugin);
            info.setDefault();
            if (openit) {
                StepDialogInterface dialog = this.getStepEntryDialog(info, transMeta, name);
                if (dialog != null) {
                    name = dialog.open();
                }
            }
            inf = new StepMeta(stepPlugin.getIds()[0], name, info);
            if (name != null) {
                // OK pressed in the dialog: we have a step-name
                String newName = name;
                StepMeta stepMeta = transMeta.findStep(newName);
                int nr = 2;
                while (stepMeta != null) {
                    newName = name + " " + nr;
                    stepMeta = transMeta.findStep(newName);
                    nr++;
                }
                if (nr > 2) {
                    inf.setName(newName);
                    MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                    // "This stepName already exists.  Spoon changed the stepName to ["+newName+"]"
                    mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.ChangeStepname.Message", newName));
                    mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.ChangeStepname.Title"));
                    mb.open();
                }
                // default location at (20,20)
                inf.setLocation(20, 20);
                transMeta.addStep(inf);
                addUndoNew(transMeta, new StepMeta[] { inf }, new int[] { transMeta.indexOfStep(inf) });
                // Also store it in the pluginHistory list...
                props.increasePluginHistory(stepPlugin.getIds()[0]);
                // stepHistoryChanged = true;
                refreshTree();
            } else {
                // Cancel pressed in dialog.
                return null;
            }
            setShellText();
        }
    } catch (KettleException e) {
        String filename = stepPlugin.getErrorHelpFile();
        if (!Utils.isEmpty(filename)) {
            // OK, in stead of a normal error message, we give back the
            // content of the error help file... (HTML)
            FileInputStream fis = null;
            try {
                StringBuilder content = new StringBuilder();
                fis = new FileInputStream(new File(filename));
                int ch = fis.read();
                while (ch >= 0) {
                    content.append((char) ch);
                    ch = fis.read();
                }
                ShowBrowserDialog sbd = new ShowBrowserDialog(// "Error help text"
                shell, BaseMessages.getString(PKG, "Spoon.Dialog.ErrorHelpText.Title"), content.toString());
                sbd.open();
            } catch (Exception ex) {
                new ErrorDialog(shell, // "Error showing help text"
                BaseMessages.getString(PKG, "Spoon.Dialog.ErrorShowingHelpText.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorShowingHelpText.Message"), ex);
            } finally {
                if (fis != null) {
                    try {
                        fis.close();
                    } catch (Exception ex) {
                        log.logError("Error closing plugin help file", ex);
                    }
                }
            }
        } else {
            new ErrorDialog(shell, // "I was unable to create a new step"
            BaseMessages.getString(PKG, "Spoon.Dialog.UnableCreateNewStep.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.UnableCreateNewStep.Message"), e);
        }
        return null;
    } catch (Throwable e) {
        if (!shell.isDisposed()) {
            new ErrorDialog(shell, // "Error creating step"
            BaseMessages.getString(PKG, "Spoon.Dialog.ErrorCreatingStep.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.UnableCreateNewStep.Message"), e);
        }
        return null;
    }
    return inf;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) StepDialogInterface(org.pentaho.di.trans.step.StepDialogInterface) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) ShowBrowserDialog(org.pentaho.di.ui.core.dialog.ShowBrowserDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) FileInputStream(java.io.FileInputStream) SWTException(org.eclipse.swt.SWTException) KettleRowException(org.pentaho.di.core.exception.KettleRowException) FileSystemException(org.apache.commons.vfs2.FileSystemException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleAuthException(org.pentaho.di.core.exception.KettleAuthException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) LifecycleException(org.pentaho.di.core.lifecycle.LifecycleException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) MalformedURLException(java.net.MalformedURLException) MessageBox(org.eclipse.swt.widgets.MessageBox) StepPluginType(org.pentaho.di.core.plugins.StepPluginType) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) LastUsedFile(org.pentaho.di.core.LastUsedFile) File(java.io.File)

Example 22 with Type

use of org.apache.commons.vfs2.UserAuthenticationData.Type in project spoofax by metaborg.

the class ConstraintMultiFileAnalyzer method analyzeSemiIncremental.

private ISpoofaxAnalyzeResults analyzeSemiIncremental(Map<String, ISpoofaxParseUnit> changed, java.util.Set<String> removed, IMultiFileScopeGraphContext context, HybridInterpreter runtime, String strategy, IProgress progress, ICancel cancel) throws AnalysisException {
    final NaBL2DebugConfig debugConfig = context.config().debug();
    final Timer totalTimer = new Timer(true);
    final AggregateTimer collectionTimer = new AggregateTimer();
    final AggregateTimer solverTimer = new AggregateTimer();
    final AggregateTimer finalizeTimer = new AggregateTimer();
    final String globalSource = "";
    final Function1<String, String> globalFresh = base -> context.unit(globalSource).fresh().fresh(base);
    for (String input : removed) {
        context.removeUnit(input);
    }
    final int n = changed.size();
    final int w = context.units().size() / 2;
    progress.setWorkRemaining(n + w + 1);
    if (debugConfig.analysis() || debugConfig.files()) {
        logger.info("Analyzing {} files in {}.", n, context.location());
    }
    final Collection<ISpoofaxAnalyzeUnit> results = Lists.newArrayList();
    final Collection<ISpoofaxAnalyzeUnitUpdate> updateResults = Lists.newArrayList();
    try {
        // initial
        InitialResult initialResult;
        final Optional<ITerm> customInitial;
        {
            if (debugConfig.collection()) {
                logger.info("Collecting initial constraints.");
            }
            if (context.initialResult().isPresent()) {
                initialResult = context.initialResult().get();
                customInitial = context.initialResult().flatMap(r -> r.getCustomResult());
            } else {
                collectionTimer.start();
                try {
                    final ITerm globalAST = Actions.sourceTerm(globalSource, B.EMPTY_TUPLE);
                    ITerm initialResultTerm = doAction(strategy, Actions.analyzeInitial(globalSource, globalAST), context, runtime).orElseThrow(() -> new AnalysisException(context, "No initial result."));
                    initialResult = InitialResult.matcher().match(initialResultTerm).orElseThrow(() -> new AnalysisException(context, "Invalid initial results."));
                    customInitial = doCustomAction(strategy, Actions.customInitial(globalSource, globalAST), context, runtime);
                    initialResult = initialResult.withCustomResult(customInitial);
                    context.setInitialResult(initialResult);
                } finally {
                    collectionTimer.stop();
                }
            }
            if (debugConfig.collection()) {
                logger.info("Initial constraints collected.");
            }
        }
        // global parameters, that form the interface for a single unit
        final java.util.Set<ITermVar> intfVars = Sets.newHashSet();
        {
            initialResult.getArgs().getParams().stream().forEach(param -> intfVars.addAll(param.getVars()));
            initialResult.getArgs().getType().ifPresent(type -> intfVars.addAll(type.getVars()));
        }
        final SemiIncrementalMultiFileSolver solver = new SemiIncrementalMultiFileSolver(context.config().debug(), callExternal(runtime));
        // global
        ISolution initialSolution;
        {
            if (context.initialSolution().isPresent()) {
                initialSolution = context.initialSolution().get();
            } else {
                try {
                    solverTimer.start();
                    final IProgress subprogress = progress.subProgress(1);
                    GraphSolution preSolution = solver.solveGraph(ImmutableBaseSolution.of(initialResult.getConfig(), initialResult.getConstraints(), PersistentUnifier.Immutable.of()), globalFresh, cancel, subprogress);
                    preSolution = solver.reportUnsolvedGraphConstraints(preSolution);
                    initialSolution = solver.solveIntra(preSolution, intfVars, null, globalFresh, cancel, subprogress);
                    if (debugConfig.resolution()) {
                        logger.info("Reduced file constraints to {}.", initialSolution.constraints().size());
                    }
                } catch (SolverException e) {
                    throw new AnalysisException(context, e);
                } finally {
                    solverTimer.stop();
                }
                context.setInitialSolution(initialSolution);
            }
        }
        final java.util.Set<Scope> intfScopes = Sets.newHashSet();
        {
            initialResult.getArgs().getParams().stream().forEach(param -> Scope.matcher().match(param, initialSolution.unifier()).ifPresent(intfScopes::add));
        }
        // units
        final Map<String, IStrategoTerm> astsByFile = Maps.newHashMap();
        final Map<String, IMessage> failures = Maps.newHashMap();
        final Multimap<String, IMessage> ambiguitiesByFile = HashMultimap.create();
        for (Map.Entry<String, ISpoofaxParseUnit> input : changed.entrySet()) {
            final String source = input.getKey();
            final ISpoofaxParseUnit parseUnit = input.getValue();
            final ITerm ast = strategoTerms.fromStratego(parseUnit.ast());
            if (debugConfig.files()) {
                logger.info("Analyzing {}.", source);
            }
            final IMultiFileScopeGraphUnit unit = context.unit(source);
            unit.clear();
            try {
                UnitResult unitResult;
                final Optional<ITerm> customUnit;
                {
                    if (debugConfig.collection()) {
                        logger.info("Collecting constraints of {}.", source);
                    }
                    try {
                        collectionTimer.start();
                        final ITerm unitResultTerm = doAction(strategy, Actions.analyzeUnit(source, ast, initialResult.getArgs()), context, runtime).orElseThrow(() -> new AnalysisException(context, "No unit result."));
                        unitResult = UnitResult.matcher().match(unitResultTerm).orElseThrow(() -> new MetaborgException("Invalid unit results."));
                        final ITerm desugaredAST = unitResult.getAST();
                        customUnit = doCustomAction(strategy, Actions.customUnit(source, desugaredAST, customInitial.orElse(B.EMPTY_TUPLE)), context, runtime);
                        unitResult = unitResult.withCustomResult(customUnit);
                        final IStrategoTerm analyzedAST = strategoTerms.toStratego(desugaredAST);
                        astsByFile.put(source, analyzedAST);
                        ambiguitiesByFile.putAll(source, analysisCommon.ambiguityMessages(parseUnit.source(), parseUnit.ast()));
                        unit.setUnitResult(unitResult);
                    } finally {
                        collectionTimer.stop();
                    }
                    if (debugConfig.collection()) {
                        logger.info("Collected {} constraints of {}.", unitResult.getConstraints().size(), source);
                    }
                }
                {
                    final ISolution unitSolution;
                    if (debugConfig.resolution()) {
                        logger.info("Reducing {} constraints of {}.", unitResult.getConstraints().size(), source);
                    }
                    try {
                        solverTimer.start();
                        final Function1<String, String> fresh = base -> context.unit(source).fresh().fresh(base);
                        final IProgress subprogress = progress.subProgress(1);
                        GraphSolution preSolution = solver.solveGraph(ImmutableBaseSolution.of(initialResult.getConfig(), unitResult.getConstraints(), initialSolution.unifier()), fresh, cancel, subprogress);
                        preSolution = solver.reportUnsolvedGraphConstraints(preSolution);
                        unitSolution = solver.solveIntra(preSolution, intfVars, intfScopes, fresh, cancel, subprogress);
                        if (debugConfig.resolution()) {
                            logger.info("Reduced file constraints to {}.", unitSolution.constraints().size());
                        }
                    } catch (SolverException e) {
                        throw new AnalysisException(context, e);
                    } finally {
                        solverTimer.stop();
                    }
                    unit.setPartialSolution(unitSolution);
                    if (debugConfig.files() || debugConfig.resolution()) {
                        logger.info("Analyzed {}: {} errors, {} warnings, {} notes, {} unsolved constraints.", source, unitSolution.messages().getErrors().size(), unitSolution.messages().getWarnings().size(), unitSolution.messages().getNotes().size(), unitSolution.constraints().size());
                    }
                }
            } catch (MetaborgException e) {
                logger.warn("Analysis of " + source + " failed.", e);
                failures.put(source, MessageFactory.newAnalysisErrorAtTop(parseUnit.source(), "File analysis failed.", e));
            }
        }
        // solve
        final ISolution solution;
        final List<Optional<ITerm>> customUnits = Lists.newArrayList();
        {
            final List<ISolution> partialSolutions = Lists.newArrayList();
            for (IMultiFileScopeGraphUnit unit : context.units()) {
                unit.partialSolution().ifPresent(partialSolutions::add);
                unit.unitResult().map(UnitResult::getCustomResult).ifPresent(customUnits::add);
            }
            if (debugConfig.resolution()) {
                logger.info("Solving {} partial solutions.", partialSolutions.size());
            }
            ISolution sol;
            try {
                solverTimer.start();
                Function1<String, String> fresh = base -> context.unit(globalSource).fresh().fresh(base);
                IMessageInfo message = ImmutableMessageInfo.of(MessageKind.ERROR, MessageContent.of(), Actions.sourceTerm(globalSource));
                sol = solver.solveInter(initialSolution, partialSolutions, message, fresh, cancel, progress.subProgress(w));
                sol = solver.reportUnsolvedConstraints(sol);
            } catch (SolverException e) {
                throw new AnalysisException(context, e);
            } finally {
                solverTimer.stop();
            }
            if (!sol.flowSpecSolution().controlFlowGraph().isEmpty()) {
                logger.debug("CFG is not empty: calling FlowSpec dataflow solver");
                sol = new FixedPoint().entryPoint(sol, getFlowSpecTransferFunctions(context.language()));
            }
            solution = sol;
            context.setSolution(solution);
            if (debugConfig.resolution()) {
                logger.info("Project constraints solved.");
            }
        }
        // final
        FinalResult finalResult;
        final Optional<ITerm> customFinal;
        final Optional<CustomSolution> customSolution;
        {
            if (debugConfig.analysis()) {
                logger.info("Finalizing project analysis.");
            }
            finalizeTimer.start();
            try {
                ITerm finalResultTerm = doAction(strategy, Actions.analyzeFinal(globalSource), context, runtime).orElseThrow(() -> new AnalysisException(context, "No final result."));
                finalResult = FinalResult.matcher().match(finalResultTerm, solution.unifier()).orElseThrow(() -> new AnalysisException(context, "Invalid final results."));
                customFinal = doCustomAction(strategy, Actions.customFinal(globalSource, customInitial.orElse(B.EMPTY_TUPLE), Optionals.filter(customUnits)), context, runtime);
                finalResult = finalResult.withCustomResult(customFinal);
                context.setFinalResult(finalResult);
                customSolution = customFinal.flatMap(cs -> CustomSolution.matcher().match(cs, solution.unifier()));
                customSolution.ifPresent(cs -> context.setCustomSolution(cs));
            } finally {
                finalizeTimer.stop();
            }
            if (debugConfig.analysis()) {
                logger.info("Project analysis finalized.");
            }
        }
        // errors
        {
            if (debugConfig.analysis()) {
                logger.info("Processing project messages.");
            }
            Messages.Transient messageBuilder = Messages.Transient.of();
            messageBuilder.addAll(Messages.unsolvedErrors(solution.constraints()));
            messageBuilder.addAll(solution.messages().getAll());
            customSolution.map(CustomSolution::getMessages).map(IMessages::getAll).ifPresent(messageBuilder::addAll);
            IMessages messages = messageBuilder.freeze();
            IRelation3.Transient<String, MessageSeverity, IMessage> messagesByFile = HashTrieRelation3.Transient.of();
            messagesByFile(failures.values(), messagesByFile, context);
            messagesByFile(messages(messages.getAll(), solution.unifier(), context, context.location()), messagesByFile, context);
            // precondition: the messagesByFile should not contain any files that do not have corresponding units
            for (IMultiFileScopeGraphUnit unit : context.units()) {
                final String source = unit.resource();
                final java.util.Set<IMessage> fileMessages = messagesByFile.get(source).stream().map(Map.Entry::getValue).collect(Collectors2.toHashSet());
                if (changed.containsKey(source)) {
                    fileMessages.addAll(ambiguitiesByFile.get(source));
                    final boolean valid = !failures.containsKey(source);
                    final boolean success = valid && messagesByFile.get(source, MessageSeverity.ERROR).isEmpty();
                    final IStrategoTerm analyzedAST = astsByFile.get(source);
                    results.add(unitService.analyzeUnit(changed.get(source), new AnalyzeContrib(valid, success, analyzedAST != null, analyzedAST, fileMessages, -1), context));
                } else {
                    try {
                        final FileObject file = context.location().resolveFile(source);
                        updateResults.add(unitService.analyzeUnitUpdate(file, new AnalyzeUpdateData(fileMessages), context));
                    } catch (IOException ex) {
                        logger.error("Could not resolve {} to update messages", source);
                    }
                }
                messagesByFile.remove(source);
            }
            if (!messagesByFile.keySet().isEmpty()) {
                logger.error("Found messages for unanalyzed files {}", messagesByFile.keySet());
            }
            if (debugConfig.analysis() || debugConfig.files() || debugConfig.resolution()) {
                logger.info("Analyzed {} files: {} errors, {} warnings, {} notes.", n, messages.getErrors().size(), messages.getWarnings().size(), messages.getNotes().size());
            }
        }
    } catch (InterruptedException e) {
        logger.debug("Analysis was interrupted.");
    } finally {
        totalTimer.stop();
    }
    final ConstraintDebugData debugData = new ConstraintDebugData(totalTimer.stop(), collectionTimer.total(), solverTimer.total(), finalizeTimer.total());
    if (debugConfig.analysis()) {
        logger.info("{}", debugData);
    }
    return new SpoofaxAnalyzeResults(results, updateResults, context, debugData);
}
Also used : UnitResult(mb.nabl2.spoofax.analysis.UnitResult) ITerm(mb.nabl2.terms.ITerm) ISpoofaxAnalyzeUnit(org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnit) IProgress(org.metaborg.util.task.IProgress) Inject(com.google.inject.Inject) IRelation3(mb.nabl2.util.collections.IRelation3) MetaborgException(org.metaborg.core.MetaborgException) HashMultimap(com.google.common.collect.HashMultimap) ICancel(org.metaborg.util.task.ICancel) Map(java.util.Map) ITermVar(mb.nabl2.terms.ITermVar) SolverException(mb.nabl2.solver.SolverException) ISolution(mb.nabl2.solver.ISolution) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) B(mb.nabl2.terms.build.TermBuild.B) GraphSolution(mb.nabl2.solver.solvers.BaseSolver.GraphSolution) ISpoofaxAnalyzer(org.metaborg.spoofax.core.analysis.ISpoofaxAnalyzer) ISpoofaxParseUnit(org.metaborg.spoofax.core.unit.ISpoofaxParseUnit) Collection(java.util.Collection) ISpoofaxTracingService(org.metaborg.spoofax.core.tracing.ISpoofaxTracingService) IMessageInfo(mb.nabl2.constraints.messages.IMessageInfo) SemiIncrementalMultiFileSolver(mb.nabl2.solver.solvers.SemiIncrementalMultiFileSolver) AnalyzeUpdateData(org.metaborg.spoofax.core.unit.AnalyzeUpdateData) Sets(com.google.common.collect.Sets) FinalResult(mb.nabl2.spoofax.analysis.FinalResult) List(java.util.List) Optionals(org.metaborg.util.optionals.Optionals) Optional(java.util.Optional) LoggerUtils(org.metaborg.util.log.LoggerUtils) Timer(org.metaborg.util.time.Timer) ImmutableBaseSolution(mb.nabl2.solver.solvers.ImmutableBaseSolution) IMultiFileScopeGraphContext(org.metaborg.spoofax.core.context.scopegraph.IMultiFileScopeGraphContext) ITermFactoryService(org.metaborg.spoofax.core.terms.ITermFactoryService) AggregateTimer(org.metaborg.util.time.AggregateTimer) Function1(org.metaborg.util.functions.Function1) AnalysisCommon(org.metaborg.spoofax.core.analysis.AnalysisCommon) ISpoofaxAnalyzeResults(org.metaborg.spoofax.core.analysis.ISpoofaxAnalyzeResults) Multimap(com.google.common.collect.Multimap) Actions(mb.nabl2.spoofax.analysis.Actions) Lists(com.google.common.collect.Lists) ISpoofaxAnalyzeUnitUpdate(org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnitUpdate) IMultiFileScopeGraphUnit(org.metaborg.spoofax.core.context.scopegraph.IMultiFileScopeGraphUnit) ISpoofaxUnitService(org.metaborg.spoofax.core.unit.ISpoofaxUnitService) HybridInterpreter(org.strategoxt.HybridInterpreter) PersistentUnifier(mb.nabl2.terms.unification.PersistentUnifier) ILogger(org.metaborg.util.log.ILogger) ImmutableMessageInfo(mb.nabl2.constraints.messages.ImmutableMessageInfo) HashTrieRelation3(mb.nabl2.util.collections.HashTrieRelation3) Messages(mb.nabl2.solver.messages.Messages) IOException(java.io.IOException) MessageKind(mb.nabl2.constraints.messages.MessageKind) Scope(mb.nabl2.scopegraph.terms.Scope) CustomSolution(mb.nabl2.spoofax.analysis.CustomSolution) IMessage(org.metaborg.core.messages.IMessage) FileObject(org.apache.commons.vfs2.FileObject) Maps(com.google.common.collect.Maps) NaBL2DebugConfig(mb.nabl2.config.NaBL2DebugConfig) MessageContent(mb.nabl2.constraints.messages.MessageContent) AnalyzeContrib(org.metaborg.spoofax.core.unit.AnalyzeContrib) IMessages(mb.nabl2.solver.messages.IMessages) SpoofaxAnalyzeResults(org.metaborg.spoofax.core.analysis.SpoofaxAnalyzeResults) Collectors2(org.metaborg.util.stream.Collectors2) FixedPoint(mb.flowspec.runtime.solver.FixedPoint) IResourceService(org.metaborg.core.resource.IResourceService) IStrategoCommon(org.metaborg.spoofax.core.stratego.IStrategoCommon) InitialResult(mb.nabl2.spoofax.analysis.InitialResult) MessageSeverity(org.metaborg.core.messages.MessageSeverity) AnalysisException(org.metaborg.core.analysis.AnalysisException) IStrategoRuntimeService(org.metaborg.spoofax.core.stratego.IStrategoRuntimeService) MessageFactory(org.metaborg.core.messages.MessageFactory) ISpoofaxAnalyzeResults(org.metaborg.spoofax.core.analysis.ISpoofaxAnalyzeResults) SpoofaxAnalyzeResults(org.metaborg.spoofax.core.analysis.SpoofaxAnalyzeResults) ITermVar(mb.nabl2.terms.ITermVar) GraphSolution(mb.nabl2.solver.solvers.BaseSolver.GraphSolution) List(java.util.List) FileObject(org.apache.commons.vfs2.FileObject) InitialResult(mb.nabl2.spoofax.analysis.InitialResult) IProgress(org.metaborg.util.task.IProgress) Optional(java.util.Optional) AnalyzeUpdateData(org.metaborg.spoofax.core.unit.AnalyzeUpdateData) FinalResult(mb.nabl2.spoofax.analysis.FinalResult) IMessage(org.metaborg.core.messages.IMessage) Function1(org.metaborg.util.functions.Function1) ISolution(mb.nabl2.solver.ISolution) IMultiFileScopeGraphUnit(org.metaborg.spoofax.core.context.scopegraph.IMultiFileScopeGraphUnit) CustomSolution(mb.nabl2.spoofax.analysis.CustomSolution) NaBL2DebugConfig(mb.nabl2.config.NaBL2DebugConfig) Map(java.util.Map) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) ISpoofaxAnalyzeUnitUpdate(org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnitUpdate) SemiIncrementalMultiFileSolver(mb.nabl2.solver.solvers.SemiIncrementalMultiFileSolver) MetaborgException(org.metaborg.core.MetaborgException) UnitResult(mb.nabl2.spoofax.analysis.UnitResult) AggregateTimer(org.metaborg.util.time.AggregateTimer) IMessageInfo(mb.nabl2.constraints.messages.IMessageInfo) AnalyzeContrib(org.metaborg.spoofax.core.unit.AnalyzeContrib) FixedPoint(mb.flowspec.runtime.solver.FixedPoint) ISpoofaxAnalyzeUnit(org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnit) ISpoofaxParseUnit(org.metaborg.spoofax.core.unit.ISpoofaxParseUnit) IMessages(mb.nabl2.solver.messages.IMessages) IOException(java.io.IOException) FixedPoint(mb.flowspec.runtime.solver.FixedPoint) Timer(org.metaborg.util.time.Timer) AggregateTimer(org.metaborg.util.time.AggregateTimer) Scope(mb.nabl2.scopegraph.terms.Scope) AnalysisException(org.metaborg.core.analysis.AnalysisException) ITerm(mb.nabl2.terms.ITerm) SolverException(mb.nabl2.solver.SolverException)

Example 23 with Type

use of org.apache.commons.vfs2.UserAuthenticationData.Type in project wso2-synapse by wso2.

the class VFSTransportListener method processFile.

/**
 * Process a single file through Axis2
 * @param entry the PollTableEntry for the file (or its parent directory or archive)
 * @param file the file that contains the actual message pumped into Axis2
 * @throws AxisFault on error
 */
private void processFile(PollTableEntry entry, FileObject file) throws AxisFault {
    try {
        FileContent content = file.getContent();
        String fileName = file.getName().getBaseName();
        String filePath = file.getName().getPath();
        String fileURI = file.getName().getURI();
        metrics.incrementBytesReceived(content.getSize());
        Map<String, Object> transportHeaders = new HashMap<String, Object>();
        transportHeaders.put(VFSConstants.FILE_PATH, filePath);
        transportHeaders.put(VFSConstants.FILE_NAME, fileName);
        transportHeaders.put(VFSConstants.FILE_URI, fileURI);
        try {
            transportHeaders.put(VFSConstants.FILE_LENGTH, content.getSize());
            transportHeaders.put(VFSConstants.LAST_MODIFIED, content.getLastModifiedTime());
        } catch (FileSystemException ignore) {
        }
        MessageContext msgContext = entry.createMessageContext();
        String contentType = entry.getContentType();
        if (BaseUtils.isBlank(contentType)) {
            if (file.getName().getExtension().toLowerCase().endsWith(".xml")) {
                contentType = "text/xml";
            } else if (file.getName().getExtension().toLowerCase().endsWith(".txt")) {
                contentType = "text/plain";
            }
        } else {
            // Extract the charset encoding from the configured content type and
            // set the CHARACTER_SET_ENCODING property as e.g. SOAPBuilder relies on this.
            String charSetEnc = null;
            try {
                if (contentType != null) {
                    charSetEnc = new ContentType(contentType).getParameter("charset");
                }
            } catch (ParseException ex) {
            // ignore
            }
            msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
        }
        // if the content type was not found, but the service defined it.. use it
        if (contentType == null) {
            if (entry.getContentType() != null) {
                contentType = entry.getContentType();
            } else if (VFSUtils.getProperty(content, BaseConstants.CONTENT_TYPE) != null) {
                contentType = VFSUtils.getProperty(content, BaseConstants.CONTENT_TYPE);
            }
        }
        // does the service specify a default reply file URI ?
        String replyFileURI = entry.getReplyFileURI();
        if (replyFileURI != null) {
            msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, new VFSOutTransportInfo(replyFileURI, entry.isFileLockingEnabled()));
        }
        // Determine the message builder to use
        Builder builder;
        if (contentType == null) {
            if (log.isDebugEnabled()) {
                log.debug("No content type specified. Using SOAP builder.");
            }
            builder = new SOAPBuilder();
        } else {
            int index = contentType.indexOf(';');
            String type = index > 0 ? contentType.substring(0, index) : contentType;
            builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
            if (builder == null) {
                if (log.isDebugEnabled()) {
                    log.debug("No message builder found for type '" + type + "'. Falling back to SOAP.");
                }
                builder = new SOAPBuilder();
            }
        }
        // set the message payload to the message context
        InputStream in;
        ManagedDataSource dataSource;
        if (builder instanceof DataSourceMessageBuilder && entry.isStreaming()) {
            in = null;
            dataSource = ManagedDataSourceFactory.create(new FileObjectDataSource(file, contentType));
        } else {
            in = new AutoCloseInputStream(content.getInputStream());
            dataSource = null;
        }
        try {
            OMElement documentElement;
            if (in != null) {
                documentElement = builder.processDocument(in, contentType, msgContext);
            } else {
                documentElement = ((DataSourceMessageBuilder) builder).processDocument(dataSource, contentType, msgContext);
            }
            msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
            handleIncomingMessage(msgContext, transportHeaders, // * SOAP Action - not applicable *//
            null, contentType);
        } finally {
            if (dataSource != null) {
                dataSource.destroy();
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("Processed file : " + VFSUtils.maskURLPassword(file.toString()) + " of Content-type : " + contentType);
        }
    } catch (FileSystemException e) {
        handleException("Error reading file content or attributes : " + VFSUtils.maskURLPassword(file.toString()), e);
    } finally {
        try {
            if (file != null) {
                if (fsManager != null && file.getName() != null && file.getName().getScheme() != null && file.getName().getScheme().startsWith("file")) {
                    fsManager.closeFileSystem(file.getParent().getFileSystem());
                }
                file.close();
            }
        } catch (FileSystemException warn) {
        // ignore the warning,  since we handed over the stream close job to
        // AutocloseInputstream..
        }
    }
}
Also used : ContentType(javax.mail.internet.ContentType) HashMap(java.util.HashMap) AutoCloseInputStream(org.apache.commons.io.input.AutoCloseInputStream) InputStream(java.io.InputStream) DataSourceMessageBuilder(org.apache.axis2.format.DataSourceMessageBuilder) Builder(org.apache.axis2.builder.Builder) SOAPBuilder(org.apache.axis2.builder.SOAPBuilder) OMElement(org.apache.axiom.om.OMElement) FileContent(org.apache.commons.vfs2.FileContent) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject) SOAPBuilder(org.apache.axis2.builder.SOAPBuilder) FileObjectDataSource(org.apache.synapse.commons.vfs.FileObjectDataSource) MessageContext(org.apache.axis2.context.MessageContext) ParseException(javax.mail.internet.ParseException) VFSOutTransportInfo(org.apache.synapse.commons.vfs.VFSOutTransportInfo) AutoCloseInputStream(org.apache.commons.io.input.AutoCloseInputStream) ManagedDataSource(org.apache.axis2.format.ManagedDataSource) DataSourceMessageBuilder(org.apache.axis2.format.DataSourceMessageBuilder)

Example 24 with Type

use of org.apache.commons.vfs2.UserAuthenticationData.Type in project artisynth_core by artisynth.

the class ConsoleUserAuthenticator method requestAuthentication.

public UserAuthenticationData requestAuthentication(Type[] types) {
    UserAuthenticationData data = new UserAuthenticationData();
    System.out.println("Authentication requested...");
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    for (int i = 0; i < types.length; i++) {
        if (types[i] == UserAuthenticationData.DOMAIN) {
            System.out.print("Domain: ");
            String domain = storage.get(UserAuthenticationData.DOMAIN);
            if (domain == null) {
                try {
                    domain = in.readLine();
                // storage.put(UserAuthenticationData.DOMAIN, domain);
                } catch (IOException e) {
                    e.printStackTrace();
                    continue;
                }
            }
            data.setData(UserAuthenticationData.DOMAIN, UserAuthenticatorUtils.toChar(domain));
        } else if (types[i] == UserAuthenticationData.USERNAME) {
            System.out.print("Username: ");
            String user = storage.get(UserAuthenticationData.DOMAIN);
            if (user == null) {
                try {
                    user = in.readLine();
                // storage.put(UserAuthenticationData.USERNAME, user);
                } catch (IOException e) {
                    e.printStackTrace();
                    continue;
                }
            }
            data.setData(UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(user));
        } else if (types[i] == UserAuthenticationData.PASSWORD) {
            System.out.print("Password: ");
            String pass = storage.get(UserAuthenticationData.PASSWORD);
            if (pass == null) {
                try {
                    pass = in.readLine();
                // storage.put(UserAuthenticationData.PASSWORD, pass);
                } catch (IOException e) {
                    e.printStackTrace();
                    continue;
                }
            }
            data.setData(UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(pass));
        }
    }
    return data;
}
Also used : UserAuthenticationData(org.apache.commons.vfs2.UserAuthenticationData) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 25 with Type

use of org.apache.commons.vfs2.UserAuthenticationData.Type in project artisynth_core by artisynth.

the class EncryptedUserAuthenticator method requestAuthentication.

public UserAuthenticationData requestAuthentication(UserAuthenticationData.Type[] types) {
    UserAuthenticationData data = new UserAuthenticationData();
    for (Type type : types) {
        if (type == UserAuthenticationData.DOMAIN) {
            data.setData(UserAuthenticationData.DOMAIN, UserAuthenticatorUtils.toChar(domain));
        } else if (type == UserAuthenticationData.USERNAME) {
            data.setData(UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(username));
        } else if (type == UserAuthenticationData.PASSWORD) {
            try {
                // unfortunately, we have to pass it in plaintext, but the original password
                // could be encrypted from the get-go using the global Cryptor
                String passwd = getCryptor().decrypt(encryptedPassword);
                char[] chars = UserAuthenticatorUtils.toChar(passwd);
                data.setData(UserAuthenticationData.PASSWORD, chars);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return data;
}
Also used : UserAuthenticationData(org.apache.commons.vfs2.UserAuthenticationData) Type(org.apache.commons.vfs2.UserAuthenticationData.Type)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)38 KettleException (org.pentaho.di.core.exception.KettleException)22 IOException (java.io.IOException)20 FileSystemException (org.apache.commons.vfs2.FileSystemException)12 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)9 KettleFileException (org.pentaho.di.core.exception.KettleFileException)8 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)8 InputStream (java.io.InputStream)7 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)6 File (java.io.File)5 InputStreamReader (java.io.InputStreamReader)5 ArrayList (java.util.ArrayList)5 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 KettleValueException (org.pentaho.di.core.exception.KettleValueException)4 RowMeta (org.pentaho.di.core.row.RowMeta)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TableItem (org.eclipse.swt.widgets.TableItem)3 MetaborgException (org.metaborg.core.MetaborgException)3