Skip to content

Commit

Permalink
Supported artifacts from Maven projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
satr authored and satr committed Mar 9, 2018
1 parent d56195c commit e57f7a8
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 21 deletions.
8 changes: 4 additions & 4 deletions sources/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>io.github.satr.idea.plugin.connector.la</id>
<name>Connector for AWS Lambda</name>
<version>1.5.RC3</version>
<version>1.5.RC4</version>
<vendor email="satr.github.io@gmail.com" url="https://satr.github.io/intellij-idea-plugin-connector-for-aws-lambda/">github.com/satr</vendor>

<description><![CDATA[
Expand All @@ -13,7 +13,8 @@

<change-notes><![CDATA[
<ul>
<li>1.5.RC3</li>
<li>1.5.RC4</li>
<li>Maven project artifacts supported.</li>
<li>Artifact list is automatically refreshed after a project or artifact build.</li>
<li>Show and update selected function configuration.</li>
<li>1.4</li>
Expand Down Expand Up @@ -49,13 +50,12 @@

<idea-version since-build="IU-171.4694"/>
<depends>com.intellij.modules.java</depends>
<depends>org.jetbrains.idea.maven</depends>
<extensions defaultExtensionNs="com.intellij">
<applicationService serviceInterface="io.github.satr.idea.plugin.connector.la.models.ConnectorSettings"
serviceImplementation="io.github.satr.idea.plugin.connector.la.models.ConnectorSettings" />
<applicationService serviceInterface="io.github.satr.idea.plugin.connector.la.ui.ConnectorPresenter"
serviceImplementation="io.github.satr.idea.plugin.connector.la.ui.ConnectorPresenterImpl" />
<applicationService serviceInterface="io.github.satr.idea.plugin.connector.la.models.ProjectModel"
serviceImplementation="io.github.satr.idea.plugin.connector.la.models.ProjectModelImpl" />
<toolWindow id="Connector for AWS Lambda" secondary="true" icon="/icons/iconConnector.png" anchor="right"
factoryClass="io.github.satr.idea.plugin.connector.la.ui.ConnectorViewFactory"/>
</extensions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,43 @@
// Copyright © 2018, github.com/satr, MIT License

import com.intellij.packaging.artifacts.Artifact;
import com.intellij.packaging.artifacts.ArtifactType;

import java.nio.file.Path;
import java.nio.file.Paths;

public class ArtifactEntity {

private final String name;
private final String outputFilePath;
private final ArtifactType artifactType;
private boolean isMavenized;

public ArtifactEntity(Artifact artifact) {
name = artifact.getName();
outputFilePath = artifact.getOutputFilePath();
artifactType = artifact.getArtifactType();
this(artifact.getName(), artifact.getOutputFilePath(), false);
}

public ArtifactEntity(String artifactName, String artifactFilePath, boolean isMavenized) {
name = artifactName;
this.outputFilePath = artifactFilePath;
this.isMavenized = isMavenized;
}

public ArtifactEntity(String artifactName, String artifactPath, String artifactPackage, boolean isMavenized) {
this(artifactName, Paths.get(artifactPath, artifactName).toAbsolutePath().toString(), isMavenized);
}

public String getName() {
return name;
}

public String getOutputFilePath() {
return outputFilePath;
}

public ArtifactType getArtifactType() {
return artifactType;
}

@Override
public String toString() {
return String.format("%s", getName(), getArtifactType().toString());
return String.format("%s%s", getName(), getTypeDescription());
}

public String getTypeDescription() {
return isMavenized ? " (Maven)" : "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.intellij.packaging.artifacts.ArtifactManager;
import com.intellij.packaging.artifacts.ArtifactType;
import io.github.satr.idea.plugin.connector.la.entities.ArtifactEntity;
import org.jetbrains.idea.maven.project.MavenProject;
import org.jetbrains.idea.maven.project.MavenProjectsManager;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -14,22 +16,42 @@
public class ProjectModelImpl implements ProjectModel {
private final String JAR_ARTIFACT_TYPE = "jar";
private final Project project;
private final MavenProjectsManager mavenProjectsManager;

public ProjectModelImpl(Project project) {
this.project = project;
mavenProjectsManager = MavenProjectsManager.getInstance(project);
}

@Override
public Collection<? extends ArtifactEntity> getJarArtifacts() {
if(project == null) {
return Collections.emptyList();
}
final ArrayList<ArtifactEntity> artifactEntries = new ArrayList<>();
addProjectArtifacts(artifactEntries);
addMavenProjectArtifacts(artifactEntries);
return artifactEntries;
}

private void addMavenProjectArtifacts(ArrayList<ArtifactEntity> artifactEntries) {
if (mavenProjectsManager == null || !mavenProjectsManager.isMavenizedProject()) {
return;
}
for(MavenProject mavenProject : mavenProjectsManager.getProjects()) {
if(!JAR_ARTIFACT_TYPE.equals(mavenProject.getPackaging())){
continue;
}
String artifactName = String.format("%s.%s", mavenProject.getFinalName(), mavenProject.getPackaging());
artifactEntries.add(new ArtifactEntity(artifactName, mavenProject.getBuildDirectory(), artifactName, true));
}
}

private void addProjectArtifacts(ArrayList<ArtifactEntity> artifactEntries) {
final ArtifactManager artifactManager = ArtifactManager.getInstance(this.project);
final Collection<? extends Artifact> jarArtifacts = artifactManager.getArtifactsByType(ArtifactType.findById(JAR_ARTIFACT_TYPE));
final ArrayList<ArtifactEntity> artifactEntries = new ArrayList<>();
for(Artifact artifact : jarArtifacts) {
artifactEntries.add(new ArtifactEntity(artifact));
}
return artifactEntries;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.ui.content.ContentFactory;
import com.intellij.util.messages.MessageBusConnection;
import io.github.satr.common.MessageHelper;
Expand All @@ -31,6 +36,20 @@
import org.apache.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.execution.MavenRunner;
import org.jetbrains.idea.maven.execution.MavenRunnerParameters;
import org.jetbrains.idea.maven.execution.MavenRunnerSettings;
import org.jetbrains.idea.maven.indices.MavenArtifactSearchResult;
import org.jetbrains.idea.maven.indices.MavenArtifactSearcher;
import org.jetbrains.idea.maven.model.MavenId;
import org.jetbrains.idea.maven.model.MavenPlugin;
import org.jetbrains.idea.maven.project.MavenProject;
import org.jetbrains.idea.maven.project.MavenProjectChanges;
import org.jetbrains.idea.maven.project.MavenProjectsManager;
import org.jetbrains.idea.maven.project.MavenProjectsTree;
import org.jetbrains.idea.maven.server.NativeMavenProjectHolder;
import org.jetbrains.idea.maven.utils.MavenArtifactUtil;

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
Expand All @@ -40,10 +59,7 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.*;

import static io.github.satr.common.StringUtil.getNotEmptyString;
import static org.apache.http.util.TextUtils.isEmpty;
Expand Down

0 comments on commit e57f7a8

Please sign in to comment.