Example usage for java.lang.reflect InvocationTargetException InvocationTargetException

List of usage examples for java.lang.reflect InvocationTargetException InvocationTargetException

Introduction

In this page you can find the example usage for java.lang.reflect InvocationTargetException InvocationTargetException.

Prototype

public InvocationTargetException(Throwable target) 

Source Link

Document

Constructs a InvocationTargetException with a target exception.

Usage

From source file:org.mule.tooling.devkit.wizards.NewDevkitProjectWizard.java

@Override
public boolean performFinish() {
    wasCreated = false;// www  .  j a  va  2s  .c om
    final ConnectorMavenModel mavenModel = getPopulatedModel();
    if (mavenModel.getApiType().equals(ApiType.SOAP)) {
        if (!isValidWsdl(getWsdlPath())) {
            return false;
        }
    }
    final IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {

                final IJavaProject javaProject = doFinish(mavenModel, monitor);
                downloadJavadocForAnnotations(javaProject, monitor);
                if (mavenModel.getApiType().equals(ApiType.SOAP)) {
                    MavenRunBuilder.newMavenRunBuilder().withProject(javaProject).withArg("clean")
                            .withArg("compile").withArg("-Pconnector-generator")
                            .withTaskName("Generating connector from WSDL...").build().run(monitor);

                    MavenRunBuilder.newMavenRunBuilder().withProject(javaProject).withArg("license:format")
                            .withTaskName("Adding headers...").build().run(monitor);

                    javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
                }

                boolean autoBuilding = ResourcesPlugin.getWorkspace().isAutoBuilding();
                UpdateProjectClasspathWorkspaceJob job = new UpdateProjectClasspathWorkspaceJob(javaProject);
                monitor.subTask("Downloading dependencies");
                job.runInWorkspace(monitor);
                if (!autoBuilding) {

                    ProjectSubsetBuildAction projectBuild = new ProjectSubsetBuildAction(new IShellProvider() {

                        @Override
                        public Shell getShell() {
                            return page.getShell();
                        }
                    }, IncrementalProjectBuilder.CLEAN_BUILD, new IProject[] { javaProject.getProject() });
                    projectBuild.run();

                }
                openConnectorClass(mavenModel, javaProject.getProject());
                javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
                wasCreated = true;
            } catch (CoreException e) {

                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };
    if (!runInContainer(op)) {
        return false;
    }
    return true;
}

From source file:org.openqa.jetty.xml.XmlConfiguration.java

private Object value(Object obj, XmlParser.Node node) throws NoSuchMethodException, ClassNotFoundException,
        InvocationTargetException, IllegalAccessException {
    Object value = null;/*from  ww w  .j  a  va 2  s .co  m*/

    // Get the type
    String type = node.getAttribute("type");

    // Try a ref lookup
    String ref = node.getAttribute("ref");
    if (ref != null) {
        value = _idMap.get(ref);
    } else {
        // handle trivial case
        if (node.size() == 0) {
            if ("String".equals(type))
                return "";
            return null;
        }

        // Trim values
        int first = 0;
        int last = node.size() - 1;

        // Handle default trim type
        if (type == null || !"String".equals(type)) {
            // Skip leading white
            Object item = null;
            while (first <= last) {
                item = node.get(first);
                if (!(item instanceof String))
                    break;
                item = ((String) item).trim();
                if (((String) item).length() > 0)
                    break;
                first++;
            }

            // Skip trailing white
            while (first < last) {
                item = node.get(last);
                if (!(item instanceof String))
                    break;
                item = ((String) item).trim();
                if (((String) item).length() > 0)
                    break;
                last--;
            }

            // All white, so return null
            if (first > last)
                return null;
        }

        if (first == last)
            //  Single Item value
            value = itemValue(obj, node.get(first));
        else {
            // Get the multiple items as a single string
            StringBuffer buf = new StringBuffer();
            synchronized (buf) {
                for (int i = first; i <= last; i++) {
                    Object item = node.get(i);
                    buf.append(itemValue(obj, item));
                }
                value = buf.toString();
            }
        }
    }

    // Untyped or unknown
    if (value == null) {
        if ("String".equals(type))
            return "";
        return null;
    }

    // Try to type the object
    if (type == null) {
        if (value != null && value instanceof String)
            return ((String) value).trim();
        return value;
    }

    if ("String".equals(type) || "java.lang.String".equals(type))
        return value.toString();

    Class pClass = TypeUtil.fromName(type);
    if (pClass != null)
        return TypeUtil.valueOf(pClass, value.toString());

    if ("URL".equals(type) || "java.net.URL".equals(type)) {
        if (value instanceof URL)
            return value;
        try {
            return new URL(value.toString());
        } catch (MalformedURLException e) {
            throw new InvocationTargetException(e);
        }
    }

    if ("InetAddress".equals(type) || "java.net.InetAddress".equals(type)) {
        if (value instanceof InetAddress)
            return value;
        try {
            return InetAddress.getByName(value.toString());
        } catch (UnknownHostException e) {
            throw new InvocationTargetException(e);
        }
    }

    if ("InetAddrPort".equals(type) || "org.openqa.jetty.util.InetAddrPort".equals(type)) {
        if (value instanceof InetAddrPort)
            return value;
        try {
            return new InetAddrPort(value.toString());
        } catch (UnknownHostException e) {
            throw new InvocationTargetException(e);
        }
    }

    throw new IllegalStateException("Unknown type " + type);
}

From source file:org.ops4j.pax.exam.junit.internal.JUnit4TestMethod.java

/**
 * {@inheritDoc} Starts the test container, installs the test bundle and executes the test within the container.
 *///from   ww  w . j a  v a 2s. c om
@Override
public void invoke(Object test)
        throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Info.showLogo();

    final String fullTestName = m_name + "(" + m_testMethod.getDeclaringClass().getName() + ")";
    LOG.info("Starting test " + fullTestName);

    int executionState = NOT_STARTED;
    final TestContainerFactory containerFactory = PaxExamRuntime.getTestContainerFactory();
    TestContainer container = null;
    try {
        LOG.trace("Start test container");
        container = containerFactory.newInstance(m_options);
        container.start();
        executionState = CONTAINER_STARTED;

        LOG.trace("Install and start test bundle");
        final long bundleId = container.installBundle(m_testBundleUrl);
        executionState = PROBE_INSTALLED;
        container.setBundleStartLevel(bundleId, START_LEVEL_TEST_BUNDLE);
        container.startBundle(bundleId);
        executionState = PROBE_STARTED;

        LOG.trace("Execute test [" + m_name + "]");
        final CallableTestMethod callable = container.getService(CallableTestMethod.class);
        try {
            LOG.info("Starting test " + fullTestName);
            callable.call();
            LOG.info("Test " + fullTestName + " ended succesfully");
            executionState = SUCCESFUL;
        } catch (InstantiationException e) {
            throw new InvocationTargetException(e);
        } catch (ClassNotFoundException e) {
            throw new InvocationTargetException(e);
        }
    } finally {
        if (container != null) {
            // Leave handling of proper stop to container implementation
            try {
                container.stop();
            } catch (RuntimeException ignore) {
                if (executionState >= SUCCESFUL) {
                    // throw catched exception if the test already was successful
                    // noinspection ThrowFromFinallyBlock
                    throw ignore;
                } else {
                    // Do not throw an exception that could occur during stopping the container in case that an
                    // exception was already being thrown
                    LOG.error("Cannot stop the test container: " + ignore.getMessage());
                }
            }
        }
    }
}

From source file:org.polymap.core.data.imex.FileImportWizard.java

/**
 * //from   w w  w  .  j ava2s  .c  om
 */
@Override
public boolean performFinish() {
    final AtomicBoolean ok_flag = new AtomicBoolean(false);

    IRunnableWithProgress task = new IRunnableWithProgress() {
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                monitor.beginTask(i18n.get("finishTaskTitle"), 3);

                IResolve service = page1.getTarget();
                SimpleFeatureType schema = (SimpleFeatureType) features.getSchema();

                // adjust type name
                SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
                ftb.init(schema);
                ftb.setName(page1.getTypeName());
                //ftb.setNamespaceURI( "" );
                final SimpleFeatureType targetSchema = ftb.buildFeatureType();
                ReTypingFeatureCollection targetFeatures = new ReTypingFeatureCollection(features,
                        targetSchema);

                //                DefaultTransaction tx = new DefaultTransaction( "import" );

                // find service and create schema
                SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
                subMonitor.beginTask("Finding Service...", 1);
                DataAccess ds = service.resolve(DataAccess.class, subMonitor);
                try {
                    ds.getSchema(targetSchema.getName()).getName();
                } catch (Exception e) {
                    ds.createSchema(targetSchema);
                }
                monitor.worked(1);

                // write the features
                monitor.subTask("Writing Features...");
                FeatureStore fs = (FeatureStore) ds.getFeatureSource(targetSchema.getName());
                fs.addFeatures(targetFeatures);
                monitor.worked(1);

                // reset service in catalog
                Thread.sleep(1000);
                subMonitor = new SubProgressMonitor(monitor, 1);
                subMonitor.beginTask("Resetting Service...", 1);
                if (service instanceof IService) {
                    ResetServiceAction.reset(Collections.singletonList((IService) service), subMonitor);
                } else if (service instanceof IResolveFolder) {
                    ResetServiceAction.reset(
                            Collections.singletonList(((IResolveFolder) service).getService(monitor)),
                            subMonitor);
                }
                monitor.worked(1);

                // create layer
                if (page1.isCreateLayer()) {
                    subMonitor = new SubProgressMonitor(monitor, 1);
                    subMonitor.beginTask("Creating Layer...", 1);

                    try {
                        IService _service = service instanceof IService ? (IService) service
                                : ((IResolveFolder) service).getService(monitor);
                        IGeoResource geores = find(_service.resources(subMonitor),
                                new Predicate<IGeoResource>() {
                                    public boolean apply(IGeoResource input) {
                                        try {
                                            return input.getInfo(new NullProgressMonitor()).getName()
                                                    .equals(targetSchema.getName().getLocalPart());
                                        } catch (IOException e) {
                                            log.warn("", e);
                                            return false;
                                        }
                                    }
                                });
                        NewLayerOperation op = new NewLayerOperation();
                        op.init(ProjectPlugin.getSelectedMap(), geores);
                        OperationSupport.instance().execute(op, false, false);
                    } catch (ExecutionException e) {
                        throw new InvocationTargetException(e.getCause());
                    }
                    monitor.worked(1);
                }
                monitor.done();
            } catch (IOException e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    try {
        getContainer().run(true, true, task);
    } catch (InvocationTargetException e) {
        features = null;
        PolymapWorkbench.handleError(DataPlugin.PLUGIN_ID, FileImportWizard.this, i18n.get("finishTaskError"),
                e.getCause());
    } catch (InterruptedException e) {
        //MessageDialog.openInformation( getShell(), "Info", i18n.get( "timeout" ) );
    }
    return true;
}

From source file:org.polymap.core.data.imex.gpx.GpxImportWizard.java

@Override
public FeatureCollection parseKml(final InputStream in) throws Exception {
    features = null;/*w  w w  .  ja v  a  2  s  .  co  m*/
    IRunnableWithProgress task = new IRunnableWithProgress() {
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask(i18n.get("parseTaskTitle"), 2);
            try {
                // transform GPX
                monitor.subTask("Transforming GPX data...");
                InputStream xslIn = DataPlugin.getDefault().getBundle()
                        .getResource("org/polymap/core/data/imex/gpx/gpx2kml.xsl").openStream();
                Source xslDoc = new StreamSource(xslIn);
                Source xmlDoc = new StreamSource(in);
                ByteArrayOutputStream kmlOut = new ByteArrayOutputStream();

                Transformer trasform = TransformerFactory.newInstance().newTransformer(xslDoc);
                trasform.transform(xmlDoc, new StreamResult(kmlOut));
                log.info("KML: " + kmlOut.toString());
                monitor.worked(1);

                // parse KML
                monitor.subTask("Parsing...");
                KMLConfiguration config = new KMLConfiguration();

                Parser parser = new Parser(config);
                SimpleFeature f = (SimpleFeature) parser.parse(new ByteArrayInputStream(kmlOut.toByteArray()));
                Collection<Feature> placemarks = (Collection<Feature>) f.getAttribute("Feature");
                //log.info( placemarks );

                features = DefaultFeatureCollections.newCollection();
                features.addAll(placemarks);
                monitor.worked(1);

                // adjust type
                FeatureType schema = features.getSchema();
                SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
                ftb.setName("Placemark");
                ftb.setNamespaceURI(schema.getName().getNamespaceURI());
                ftb.add("name", String.class);
                ftb.add("description", String.class);
                ftb.add(schema.getGeometryDescriptor().getLocalName(), MultiLineString.class,
                        CRS.decode("EPSG:4326"));

                features = new RetypingFeatureCollection(features, ftb.buildFeatureType()) {
                    private SimpleFeatureType targetSchema = getSchema();

                    protected Feature retype(Feature feature) {
                        try {
                            SimpleFeatureBuilder fb = new SimpleFeatureBuilder(targetSchema);
                            for (PropertyDescriptor prop : targetSchema.getDescriptors()) {
                                fb.set(prop.getName(), feature.getProperty(prop.getName()).getValue());
                            }
                            return fb.buildFeature(feature.getIdentifier().getID());
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                };

                //                    features = new ReTypingFeatureCollection( features, ftb.buildFeatureType() );
            } catch (Exception e) {
                log.warn("", e);
                throw new InvocationTargetException(e);
            } finally {
                IOUtils.closeQuietly(in);
            }
        }
    };

    try {
        getContainer().run(true, true, task);
    } catch (InvocationTargetException e) {
        Throwables.propagateIfPossible(e.getTargetException(), Exception.class);
    } catch (InterruptedException e) {
        throw e;
    }
    return features;
}

From source file:org.polymap.core.data.imex.kml.KmlImportWizard.java

@Override
public FeatureCollection parseKml(final InputStream in) throws Exception {
    features = null;/*  ww w  . j  a v  a2 s . c  o m*/
    IRunnableWithProgress task = new IRunnableWithProgress() {
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask(i18n.get("parseTaskTitle"), 2);
            try {
                //                    log.info( "KML: " + kmlOut.toString() );
                // parse KML
                monitor.subTask("Parsing KML...");
                KMLConfiguration config = new KMLConfiguration();

                Parser parser = new Parser(config);
                SimpleFeature f = (SimpleFeature) parser.parse(in);
                Collection<Feature> placemarks = (Collection<Feature>) f.getAttribute("Feature");
                //log.info( placemarks );

                features = DefaultFeatureCollections.newCollection();
                features.addAll(placemarks);
                monitor.worked(1);

                // adjust type
                FeatureType schema = features.getSchema();
                //                    SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
                //                    ftb.init( (SimpleFeatureType)schema );
                //                    ftb.remove( "visibility" );
                //                    ftb.remove( "open" );
                //                    ftb.remove( "Style" );
                //                    ftb.remove( "LookAt" );
                //                    ftb.setCRS( CRS.decode( "EPSG:4326" ) );
                //                    ftb.remove( schema.getGeometryDescriptor().getLocalName() );
                //                    ftb.add( schema.getGeometryDescriptor().getLocalName(), MultiLineString.class, CRS.decode( "EPSG:4326" ) );

                //                    SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
                //                    ftb.add( "name", String.class );
                //                    ftb.setCRS( CRS.decode( "EPSG:4326" ) );
                //                    ftb.add( schema.getGeometryDescriptor().getLocalName(), MultiLineString.class, CRS.decode( "EPSG:4326" ) );
                //
                //                    //features = new ReTypingFeatureCollection( features, ftb.buildFeatureType() );
                //                    features = new RetypingFeatureCollection( features, ftb.buildFeatureType() ) {
                //                        protected Feature retype( Feature feature ) {
                //                            try {
                //                                SimpleFeatureBuilder fb = new SimpleFeatureBuilder( (SimpleFeatureType)getSchema() );
                //                                for (PropertyDescriptor prop : getSchema().getDescriptors()) {
                //                                    fb.set( prop.getName(), feature.getProperty( prop.getName() ).getValue() );
                //                                }
                //                                return fb.buildFeature( feature.getIdentifier().getID() );
                //                            }
                //                            catch (Exception e) {
                //                                throw new RuntimeException( e );
                //                            }
                //                        }
                //                    };
            } catch (Exception e) {
                new InvocationTargetException(e);
            } finally {
                IOUtils.closeQuietly(in);
            }
        }
    };

    try {
        getContainer().run(true, true, task);
    } catch (InvocationTargetException e) {
        Throwables.propagateIfPossible(e.getTargetException(), Exception.class);
    } catch (InterruptedException e) {
        //MessageDialog.openInformation( getShell(), "Info", i18n.get( "timeout" ) );
    }
    return features;
}

From source file:org.review_board.ereviewboard.ui.editor.ReviewboardCompareEditorInput.java

@Override
protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

    ReviewboardRepositoryConnector connector = ReviewboardCorePlugin.getDefault().getConnector();

    ReviewboardClient client = connector.getClientManager().getClient(TasksUi.getRepositoryManager()
            .getRepository(ReviewboardCorePlugin.REPOSITORY_KIND, _taskData.getRepositoryUrl()));

    try {//from   w  w w. ja  v a 2  s .  co  m
        monitor.beginTask("Loading file contents and comments", 5);

        loadContents(monitor);
        appendComments(monitor, client);

        return super.prepareInput(monitor);

    } catch (ReviewboardException e) {
        throw new InvocationTargetException(e);
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    } catch (IOException e) {
        throw new InvocationTargetException(e);
    } finally {
        monitor.done();
    }
}

From source file:org.sonar.ide.eclipse.internal.ui.wizards.ServerLocationWizardPage.java

/**
 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(Composite)
 *//*from w  ww  .  j a v  a2 s . c  o  m*/
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 2;
    layout.verticalSpacing = 9;
    Label label = new Label(container, SWT.NULL);
    label.setText(Messages.ServerLocationWizardPage_label_host);
    serverUrlText = new Text(container, SWT.BORDER | SWT.SINGLE);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    serverUrlText.setLayoutData(gd);
    serverUrlText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });

    // Sonar Server Username
    Label labelUsername = new Label(container, SWT.NULL);
    labelUsername.setText(Messages.ServerLocationWizardPage_label_username);
    serverUsernameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    serverUsernameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Sonar Server password
    Label labelPassword = new Label(container, SWT.NULL);
    labelPassword.setText(Messages.ServerLocationWizardPage_label_password);
    serverPasswordText = new Text(container, SWT.BORDER | SWT.SINGLE | SWT.PASSWORD);
    serverPasswordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Sonar test connection button
    testConnectionButton = new Button(container, SWT.PUSH);
    testConnectionButton.setText(Messages.ServerLocationWizardPage_action_test);
    testConnectionButton.setToolTipText(Messages.ServerLocationWizardPage_action_test_tooltip);
    testConnectionButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    testConnectionButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // We need those variables - in other case we would get an IllegalAccessException
            final String serverUrl = getServerUrl();
            final String username = getUsername();
            final String password = getPassword();
            try {
                getWizard().getContainer().run(true, true, new IRunnableWithProgress() {

                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        monitor.beginTask("Testing", IProgressMonitor.UNKNOWN);
                        try {
                            ConnectionTestResult result = SonarCorePlugin.getServerConnectionTester()
                                    .testSonar(serverUrl, username, password);
                            switch (result) {
                            case OK:
                                status = new Status(IStatus.OK, ISonarConstants.PLUGIN_ID,
                                        Messages.ServerLocationWizardPage_msg_connected);
                                break;
                            case AUTHENTICATION_ERROR:
                                status = new Status(IStatus.ERROR, ISonarConstants.PLUGIN_ID,
                                        Messages.ServerLocationWizardPage_msg_authentication_error);
                                break;
                            case CONNECT_ERROR:
                                status = new Status(IStatus.ERROR, ISonarConstants.PLUGIN_ID,
                                        Messages.ServerLocationWizardPage_msg_connection_error);
                                break;
                            }
                        } catch (OperationCanceledException e) {
                            throw new InterruptedException();
                        } catch (Exception e) {
                            throw new InvocationTargetException(e);
                        } finally {
                            monitor.done();
                        }
                    }
                });
            } catch (InvocationTargetException e1) {
                LoggerFactory.getLogger(getClass()).error(e1.getMessage(), e1);

                status = new Status(IStatus.ERROR, ISonarConstants.PLUGIN_ID,
                        Messages.ServerLocationWizardPage_msg_error);
            } catch (InterruptedException e1) { // NOSONAR - canceled
                status = Status.CANCEL_STATUS;
            }
            getWizard().getContainer().updateButtons();

            String message = status.getMessage();
            switch (status.getSeverity()) {
            case IStatus.OK:
                setMessage(message, IMessageProvider.INFORMATION);
                break;
            default:
                setMessage(message, IMessageProvider.ERROR);
                break;
            }
        }
    });

    initialize();
    dialogChanged();
    setControl(container);
}

From source file:org.springframework.ide.eclipse.boot.wizard.NewSpringBootWizardModel.java

public void performFinish(IProgressMonitor mon) throws InvocationTargetException, InterruptedException {
    mon.beginTask("Importing " + baseUrl.getValue(), 4);
    updateUsageCounts();/*w  w w. java  2  s. co m*/
    preferredSelections.save(this);
    DownloadManager downloader = null;
    try {
        downloader = new DownloadManager(urlConnectionFactory).allowUIThread(allowUIThread);

        DownloadableItem zip = new DownloadableItem(newURL(downloadUrl.getValue()), downloader);
        String projectNameValue = projectName.getValue();
        CodeSet cs = CodeSet.fromZip(projectNameValue, zip, new Path("/"));

        ImportStrategy strat = getImportStrategy();
        if (strat == null) {
            strat = BuildType.GENERAL.getDefaultStrategy();
        }
        IRunnableWithProgress oper = strat
                .createOperation(ImportUtils.importConfig(new Path(location.getValue()), projectNameValue, cs));
        oper.run(SubMonitor.convert(mon, 3));

        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectNameValue);
        addToWorkingSets(project, SubMonitor.convert(mon, 1));

    } catch (IOException e) {
        throw new InvocationTargetException(e);
    } finally {
        if (downloader != null) {
            downloader.dispose();
        }
        mon.done();
    }
}

From source file:org.talend.camel.designer.ui.wizards.actions.JavaCamelJobScriptsExportWSAction.java

@Override
public final void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

    this.monitor = monitor;
    String groupId = getGroupId();
    String routeName = getArtifactId();
    String routeVersion = getArtifactVersion();

    // FIXME temporary solution, should be replaced by proper handling
    // of MicroService vs. KAR build.
    boolean isCreatingMicroService = false;
    Boolean oldMS = RouteProcessingExchange.isCreatingMicroService.get();
    RouteProcessingExchange.isCreatingMicroService.set(Boolean.FALSE);

    try {//from ww w .j  a  va  2  s.  c om
        prepareJobBuild();
        Boolean isMS = RouteProcessingExchange.isCreatingMicroService.get();
        if (isMS != null) {
            isCreatingMicroService = isMS.booleanValue();
        }
    } catch (Exception e) {
        throw new InvocationTargetException(e);
    } finally {
        RouteProcessingExchange.isCreatingMicroService.set(oldMS);
        if (oldMS == null) {
            RouteProcessingExchange.resetMavenOffline();
        }
    }

    // FIXME may require some further actions to get all POMs.
    if (ProcessorUtilities.isGeneratePomOnly()) {
        return;
    }

    featuresModel = new FeaturesModel(groupId, routeName, routeVersion);
    try {
        File routeFile;
        try {
            routeFile = File.createTempFile("route", FileConstants.JAR_FILE_SUFFIX, new File(getTempDir())); // $NON-NLS-1$
            addBuildArtifact(routeObject, "jar", routeFile);
        } catch (IOException e) {
            throw new InvocationTargetException(e);
        }

        BundleModel routeModel = new BundleModel(groupId, routeName, routeVersion, routeFile);
        final ProcessItem routeProcess = (ProcessItem) routeObject.getProperty().getItem();

        if (featuresModel.addBundle(routeModel)) {

            CamelFeatureUtil.addFeatureAndBundles(routeProcess, featuresModel);
            featuresModel.setConfigName(routeObject.getLabel());
            featuresModel.setContexts(JobContextUtils.getContextsMap(routeProcess));

            exportAllReferenceJobs(routeName, routeProcess);
            final Set<String> routelets = new HashSet<>();
            exportAllReferenceRoutelets(routeName, routeProcess, routelets);

            exportRouteBundle(routeObject, routeFile, version, null, null, bundleVersion, null, routelets,
                    null);
        }

        try {

            if (destinationKar != null) {
                // FIXME should be replaced by proper handling of
                // microservice vs. KAR creation.
                String dest = destinationKar;
                int suffixNdx = dest.length() - 4;
                String suffix = "kar";
                if (isCreatingMicroService) {
                    if (dest.regionMatches(true, suffixNdx, ".kar", 0, 4)) {
                        dest = dest.substring(0, suffixNdx) + ".jar";
                        suffix = "jar";
                    } else if (dest.regionMatches(true, suffixNdx, ".zip", 0, 4)) {
                        suffix = "zip";
                    }
                } else {
                    if (dest.regionMatches(true, suffixNdx, ".zip", 0, 4)) {
                        Boolean isZip = (Boolean) manager.getExportChoice().get(ExportChoice.needMavenScript);
                        if (isZip == null || !isZip.booleanValue()) {
                            dest = dest.substring(0, suffixNdx) + ".kar";
                        }
                    }
                }
                addBuildArtifact(routeObject, suffix, new File(dest));
            }

            IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
            ITalendProcessJavaProject talendProcessJavaProject = runProcessService
                    .getTalendJobJavaProject(routeObject.getProperty());

            FilesUtils.copyFile(featuresModel.getContent(),
                    new File(talendProcessJavaProject.getBundleResourcesFolder().getLocation().toOSString()
                            + File.separator + "feature.xml"));

            // Build project and collect build artifacts
            try {
                buildJob();
            } catch (Exception ex) {
                throw new InvocationTargetException(ex);
            }

            collectBuildArtifacts();

        } catch (Exception e) {
            e.printStackTrace();
        }

        processResults(featuresModel, monitor);

    } finally {
        // remove generated files
        removeTempFiles();
    }
}