Search in sources :

Example 26 with Artifact

use of com.intellij.packaging.artifacts.Artifact in project azure-tools-for-java by Microsoft.

the class SparkSubmitModel method buildArtifactObservable.

public Single<Artifact> buildArtifactObservable(@NotNull String artifactName) {
    Optional<JobStatusManager> jsmOpt = Optional.ofNullable(HDInsightUtil.getJobStatusManager(project));
    return Single.fromEmitter(em -> {
        jsmOpt.ifPresent((jsm) -> jsm.setJobRunningState(true));
        postEventAction();
        if (isLocalArtifact()) {
            em.onError(new NotSupportExecption());
            return;
        }
        final Artifact artifact = artifactHashMap.get(artifactName);
        final List<Artifact> artifacts = Collections.singletonList(artifact);
        ArtifactsWorkspaceSettings.getInstance(project).setArtifactsToBuild(artifacts);
        ApplicationManager.getApplication().invokeAndWait(() -> {
            final CompileScope scope = ArtifactCompileScope.createArtifactsScope(project, artifacts, true);
            CompilerManager.getInstance(project).make(scope, (aborted, errors, warnings, compileContext) -> {
                if (aborted || errors != 0) {
                    showCompilerErrorMessage(compileContext);
                    jsmOpt.ifPresent((jsm) -> jsm.setJobRunningState(false));
                    String errorMessage = StringUtils.join(compileContext.getMessages(CompilerMessageCategory.ERROR), "\\n");
                    postEventProperty.put("IsSubmitSucceed", "false");
                    postEventProperty.put("SubmitFailedReason", errorMessage.substring(0, 50));
                    AppInsightsClient.create(HDInsightBundle.message("SparkProjectDebugCompileFailed"), null, postEventProperty);
                    em.onError(new CompilationException(errorMessage));
                } else {
                    postEventProperty.put("IsSubmitSucceed", "true");
                    postEventProperty.put("SubmitFailedReason", "CompileSuccess");
                    AppInsightsClient.create(HDInsightBundle.message("SparkProjectDebugCompileSuccess"), null, postEventProperty);
                    HDInsightUtil.showInfoOnSubmissionMessageWindow(project, String.format("Info : Build %s successfully.", artifact.getOutputFile()));
                    em.onSuccess(artifact);
                }
            });
        }, ModalityState.defaultModalityState());
    });
}
Also used : JobStatusManager(com.microsoft.azure.hdinsight.common.JobStatusManager) ArtifactCompileScope(com.intellij.packaging.impl.compiler.ArtifactCompileScope) NotSupportExecption(com.microsoft.azure.hdinsight.sdk.common.NotSupportExecption) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 27 with Artifact

use of com.intellij.packaging.artifacts.Artifact in project azure-tools-for-java by Microsoft.

the class AzureWebDeployAction method onActionPerformed.

public void onActionPerformed(AnActionEvent e) {
    //        Module module = LangDataKeys.MODULE.getData(e.getDataContext());
    //        Module module1 = e.getData(LangDataKeys.MODULE);
    Project project = DataKeys.PROJECT.getData(e.getDataContext());
    JFrame frame = WindowManager.getInstance().getFrame(project);
    try {
        if (!AzureSignInAction.doSignIn(AuthMethodManager.getInstance(), project))
            return;
        //Project project = module.getProject();
        ModifiableArtifactModel artifactModel = ProjectStructureConfigurable.getInstance(project).getArtifactsStructureConfigurable().getModifiableArtifactModel();
        Artifact artifactToDeploy = null;
        Collection<? extends Artifact> artifacts = artifactModel.getArtifactsByType(ArtifactType.findById("war"));
        List<String> issues = new LinkedList<>();
        if (artifacts.size() == 0) {
            issues.add("A web archive (WAR) Artifact has not been configured yet. The artifact configurations are managed in the <b>Project Structure</b> dialog (<b>File | Project Structure | Artifacts</b>).");
            ArtifactValidationWindow.go(project, issues);
            return;
        } else if (artifacts.size() > 1) {
            WarSelectDialog d = WarSelectDialog.go(project, new ArrayList<>(artifacts));
            if (d == null) {
                return;
            }
            artifactToDeploy = d.getSelectedArtifact();
        } else {
            artifactToDeploy = (Artifact) artifacts.toArray()[0];
        }
        // check artifact name is valid
        String name = artifactToDeploy.getName();
        if (!name.matches("^[A-Za-z0-9]*[A-Za-z0-9]$")) {
            issues.add("The artifact name <b>'" + name + "'</b> is invalid. An artifact name may contain only the ASCII letters 'a' through 'z' (case-insensitive),\nand the digits '0' through '9'.");
        }
        boolean exists = Files.exists(Paths.get(artifactToDeploy.getOutputFilePath()));
        if (!exists) {
            issues.add("The Artifact has not been built yet. You can initiate building an artifact using <b>Build | Build Artifacts...</b> menu.");
        }
        if (issues.size() > 0) {
            ArtifactValidationWindow.go(project, issues);
            return;
        }
        WebAppDeployDialog d = WebAppDeployDialog.go(project, artifactToDeploy);
    } catch (Exception ex) {
        ex.printStackTrace();
        //LOGGER.error("actionPerformed", ex);
        ErrorWindow.show(project, ex.getMessage(), "Azure Web Deploy Action Error");
    }
}
Also used : WebAppDeployDialog(com.microsoft.azuretools.ijidea.ui.WebAppDeployDialog) WarSelectDialog(com.microsoft.azuretools.ijidea.ui.WarSelectDialog) ArrayList(java.util.ArrayList) Artifact(com.intellij.packaging.artifacts.Artifact) LinkedList(java.util.LinkedList) Project(com.intellij.openapi.project.Project) ModifiableArtifactModel(com.intellij.packaging.artifacts.ModifiableArtifactModel)

Example 28 with Artifact

use of com.intellij.packaging.artifacts.Artifact in project azure-tools-for-java by Microsoft.

the class IDEHelperImpl method buildArtifact.

@NotNull
@Override
public ListenableFuture<String> buildArtifact(@NotNull ProjectDescriptor projectDescriptor, @NotNull ArtifactDescriptor artifactDescriptor) {
    try {
        Project project = findOpenProject(projectDescriptor);
        final Artifact artifact = findProjectArtifact(project, artifactDescriptor);
        final SettableFuture<String> future = SettableFuture.create();
        Futures.addCallback(buildArtifact(project, artifact, false), new FutureCallback<Boolean>() {

            @Override
            public void onSuccess(@Nullable Boolean succeded) {
                if (succeded != null && succeded) {
                    future.set(artifact.getOutputFilePath());
                } else {
                    future.setException(new AzureCmdException("An error occurred while building the artifact"));
                }
            }

            @Override
            public void onFailure(Throwable throwable) {
                if (throwable instanceof ExecutionException) {
                    future.setException(new AzureCmdException("An error occurred while building the artifact", throwable.getCause()));
                } else {
                    future.setException(new AzureCmdException("An error occurred while building the artifact", throwable));
                }
            }
        });
        return future;
    } catch (AzureCmdException e) {
        return Futures.immediateFailedFuture(e);
    }
}
Also used : Project(com.intellij.openapi.project.Project) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) ExecutionException(java.util.concurrent.ExecutionException) Artifact(com.intellij.packaging.artifacts.Artifact) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 29 with Artifact

use of com.intellij.packaging.artifacts.Artifact in project azure-tools-for-java by Microsoft.

the class IDEHelperImpl method buildArtifact.

private static ListenableFuture<Boolean> buildArtifact(@NotNull Project project, @NotNull final Artifact artifact, boolean rebuild) {
    final SettableFuture<Boolean> future = SettableFuture.create();
    Set<Artifact> artifacts = new LinkedHashSet<Artifact>(1);
    artifacts.add(artifact);
    CompileScope scope = ArtifactCompileScope.createArtifactsScope(project, artifacts, rebuild);
    ArtifactsWorkspaceSettings.getInstance(project).setArtifactsToBuild(artifacts);
    CompilerManager.getInstance(project).make(scope, new CompileStatusNotification() {

        @Override
        public void finished(boolean aborted, int errors, int warnings, CompileContext compileContext) {
            future.set(!aborted && errors == 0);
        }
    });
    return future;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CompileStatusNotification(com.intellij.openapi.compiler.CompileStatusNotification) ArtifactCompileScope(com.intellij.packaging.impl.compiler.ArtifactCompileScope) CompileScope(com.intellij.openapi.compiler.CompileScope) CompileContext(com.intellij.openapi.compiler.CompileContext) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 30 with Artifact

use of com.intellij.packaging.artifacts.Artifact in project azure-tools-for-java by Microsoft.

the class IDEHelperImpl method getArtifacts.

@NotNull
@Override
public List<ArtifactDescriptor> getArtifacts(@NotNull ProjectDescriptor projectDescriptor) throws AzureCmdException {
    Project project = findOpenProject(projectDescriptor);
    List<ArtifactDescriptor> artifactDescriptors = new ArrayList<ArtifactDescriptor>();
    for (Artifact artifact : ArtifactUtil.getArtifactWithOutputPaths(project)) {
        artifactDescriptors.add(new ArtifactDescriptor(artifact.getName(), artifact.getArtifactType().getId()));
    }
    return artifactDescriptors;
}
Also used : Project(com.intellij.openapi.project.Project) ArrayList(java.util.ArrayList) Artifact(com.intellij.packaging.artifacts.Artifact) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Aggregations

Artifact (com.intellij.packaging.artifacts.Artifact)52 ArrayList (java.util.ArrayList)13 Project (com.intellij.openapi.project.Project)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Module (com.intellij.openapi.module.Module)7 NotNull (org.jetbrains.annotations.NotNull)6 ArtifactManager (com.intellij.packaging.artifacts.ArtifactManager)5 File (java.io.File)5 PackagingElement (com.intellij.packaging.elements.PackagingElement)4 ArtifactCompileScope (com.intellij.packaging.impl.compiler.ArtifactCompileScope)4 ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)4 Nullable (org.jetbrains.annotations.Nullable)4 ArtifactType (com.intellij.packaging.artifacts.ArtifactType)3 PackagingElementPath (com.intellij.packaging.impl.artifacts.PackagingElementPath)3 ReadAction (com.intellij.openapi.application.ReadAction)2 Result (com.intellij.openapi.application.Result)2 Pair (com.intellij.openapi.util.Pair)2 ModifiableArtifactModel (com.intellij.packaging.artifacts.ModifiableArtifactModel)2 CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)2 PackagingElementFactory (com.intellij.packaging.elements.PackagingElementFactory)2