Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,73 @@ private void addDirectoryEntry(List<Path> filePaths, List<String> entryNames, St
}
spIndex = entryName.indexOf("/", spIndex + 1);
}

if (entryName.startsWith("webapp/")) {
spIndex = entryName.indexOf("/", 7);
while (spIndex > 0) {
final String dir = entryName.substring(0, spIndex + 1);
if (added.add(dir)) {
filePaths.add(null);
entryNames.add(dir);
}
spIndex = entryName.indexOf("/", spIndex + 1);
}
}
}

private boolean isInWebAppDirectory(VirtualFile virtualFile) {
VirtualFile current = virtualFile;
while (current != null) {
if ("webapp".equals(current.getName())) {
return true;
}
current = current.getParent();
}
return false;
}

private String calculateWebAppEntryPath(VirtualFile virtualFile) {
List<String> pathSegments = new ArrayList<>();
VirtualFile current = virtualFile;

while (current != null && !"webapp".equals(current.getName())) {
pathSegments.add(0, current.getName());
current = current.getParent();
}

if (current == null) {
return null;
}

StringBuilder path = new StringBuilder("webapp");
for (String segment : pathSegments) {
path.append("/").append(segment);
}

return path.toString();
}

private void collectExportVirtualFile(List<Path> filePaths, List<String> jarEntryNames, VirtualFile virtualFile) {
final boolean inTestSourceContent =
ProjectRootManager.getInstance(project).getFileIndex().isInTestSourceContent(virtualFile);
if (inTestSourceContent && !exportOptionSet.contains(ExportOptions.export_test)) { // not export test source and resource files
final boolean inTestSourceContent = ProjectRootManager.getInstance(project).getFileIndex().isInTestSourceContent(virtualFile);

if (inTestSourceContent && !exportOptionSet.contains(ExportOptions.export_test)) {
return;
}

if (isInWebAppDirectory(virtualFile)) {

String entryPath = calculateWebAppEntryPath(virtualFile);
if (entryPath != null) {
collectExportFile(filePaths, jarEntryNames, "", Paths.get(virtualFile.getPath()), entryPath);
}
return;
}
// find package name
PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(virtualFile.isDirectory() ?
virtualFile : virtualFile.getParent());

PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(virtualFile.isDirectory() ? virtualFile : virtualFile.getParent());
PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
String packagePath = psiPackage == null ? "" : psiPackage.getQualifiedName().replaceAll("\\.", "/");
String fileName = virtualFile.getName();

if (CompilerManager.getInstance(project).isCompilableFileType(virtualFile.getFileType())) {
if (exportOptionSet.contains(ExportOptions.export_java)) {
collectExportFile(filePaths, jarEntryNames, packagePath, Paths.get(virtualFile.getPath()));
Expand Down Expand Up @@ -131,8 +184,7 @@ private void collectExportVirtualFile(List<Path> filePaths, List<String> jarEntr
final Path classFileBasePath = Paths.get(outPutPath).resolve(packagePath);
Set<String> offspringClassNames = new HashSet<>();
for (String localClassName : localClassNames) {
CommonUtils.findOffspringClassName(offspringClassNames,
classFileBasePath.resolve(localClassName + ".class"));
CommonUtils.findOffspringClassName(offspringClassNames, classFileBasePath.resolve(localClassName + ".class"));
}
try {
Files.walk(classFileBasePath, 1).forEach(p -> {
Expand Down Expand Up @@ -160,16 +212,23 @@ private boolean isExportClassSourceFile(String fileName) {
return fileName.endsWith(".java") || fileName.endsWith(".kt");
}

private void collectExportFile(List<Path> filePaths, List<String> jarEntryNames, String packagePath,
Path filePath) {
private void collectExportFile(List<Path> filePaths, List<String> jarEntryNames, String packagePath, Path filePath, String entryName) {
filePaths.add(filePath);
String normalPackagePath = "".equals(packagePath) ? "" : packagePath.endsWith("/") ? packagePath :
packagePath + "/";
jarEntryNames.add(normalPackagePath + filePath.getFileName());
String normalEntryName = entryName == null ? "" : entryName;
if (entryName == null) {
String normalPackagePath = "".equals(packagePath) ? "" : packagePath.endsWith("/") ? packagePath : packagePath + "/";
normalEntryName = normalPackagePath + filePath.getFileName();
}
jarEntryNames.add(normalEntryName);
}

private void collectExportFile(List<Path> filePaths, List<String> jarEntryNames, String packagePath, Path filePath) {
collectExportFile(filePaths, jarEntryNames, packagePath, filePath, null);
}

@Override
public void finished(boolean b, int error, int i1, @NotNull CompileContext compileContext) {
public void finished(boolean b, int error, int i1, @NotNull
CompileContext compileContext) {
if (error == 0) {
ApplicationManager.getApplication().runWriteAction(this::whenFinishSuccess);
} else {
Expand All @@ -187,8 +246,7 @@ private void whenFinishSuccess() {
return;
}
info(project, exportJarFullPath + " complete export successfully");
infoNotify(Constants.actionName + " status", exportJarFullPath + "<br> complete export successfully",
List.of(new CopyTextToClipboardAction(exportJarFullPath.toString()), new ShowInExplorerAction(exportJarFullPath)));
infoNotify(Constants.actionName + " status", exportJarFullPath + "<br> complete export successfully", List.of(new CopyTextToClipboardAction(exportJarFullPath.toString()), new ShowInExplorerAction(exportJarFullPath)));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,22 @@ private static boolean isValidExport(Project project, VirtualFile virtualFile, P
compilerConfiguration.isCompilableResourceFile(project, virtualFile);
}
}
else if (virtualFile.isInLocalFileSystem()) {
return isInWebAppDirectory(virtualFile);
}
return false;
}

private static boolean isInWebAppDirectory(VirtualFile virtualFile) {
VirtualFile current = virtualFile;
while (current != null) {
if ("webapp".equals(current.getName())) {
return true;
}
current = current.getParent();
}
return false;
}
/**
* lookup modules from data context
*
Expand Down