use of com.perl5.lang.perl.idea.sdk.host.PerlHostData in project Perl5-IDEA by Camelcade.
the class PerlCoverageProfileState method getAdditionalPerlParameters.
@Override
@NotNull
public List<String> getAdditionalPerlParameters(@NotNull GenericPerlRunConfiguration perlRunConfiguration) throws ExecutionException {
CoverageHelper.resetCoverageSuit(perlRunConfiguration);
String coverageBasePath = CoverageEnabledConfiguration.getOrCreate((GenericPerlRunConfiguration) getEnvironment().getRunProfile()).getCoverageFilePath();
if (coverageBasePath != null) {
File coverageDir = new File(coverageBasePath);
coverageDir.mkdirs();
LOG.debug("Coverage directory created: ", coverageDir);
}
Sdk effectiveSdk = perlRunConfiguration.getEffectiveSdk();
PerlHostData<?, ?> hostData = PerlHostData.notNullFrom(effectiveSdk);
if (ApplicationManager.getApplication().isUnitTestMode()) {
return Collections.singletonList("-MDevel::Cover=-db," + hostData.getRemotePath(coverageBasePath) + ",-dir,.");
}
return Collections.singletonList("-MDevel::Cover=-silent,1,-db," + hostData.getRemotePath(coverageBasePath) + ",-dir,.");
}
use of com.perl5.lang.perl.idea.sdk.host.PerlHostData in project Perl5-IDEA by Camelcade.
the class PerlCoverageRunner method doLoadCoverageData.
@Nullable
private static ProjectData doLoadCoverageData(@NotNull File sessionDataFile, @NotNull PerlCoverageSuite perlCoverageSuite) {
Project project = perlCoverageSuite.getProject();
Sdk effectiveSdk;
try {
effectiveSdk = perlCoverageSuite.getConfiguration().getEffectiveSdk();
} catch (ExecutionException e) {
LOG.error(e);
return null;
}
PerlHostData<?, ?> hostData = PerlHostData.from(effectiveSdk);
if (hostData == null) {
LOG.warn("No host data for " + effectiveSdk);
return null;
}
try {
hostData.fixPermissionsRecursively(sessionDataFile.getAbsolutePath(), project);
} catch (ExecutionException e) {
LOG.warn("Error fixing permissions for " + sessionDataFile);
}
PerlCommandLine perlCommandLine = ReadAction.compute(() -> {
if (project.isDisposed()) {
LOG.debug("Project disposed");
return null;
}
VirtualFile coverFile = PerlRunUtil.findLibraryScriptWithNotification(effectiveSdk, project, COVER, COVER_LIB);
if (coverFile == null) {
LOG.warn("No `cover` script found in " + effectiveSdk);
return null;
}
PerlCommandLine commandLine = PerlRunUtil.getPerlCommandLine(project, effectiveSdk, coverFile, Collections.singletonList(PerlRunUtil.PERL_I + hostData.getRemotePath(PerlPluginUtil.getHelpersLibPath())), Collections.emptyList());
if (commandLine == null) {
LOG.warn("Unable to create a command line: " + " project: " + project + "; sdk:" + effectiveSdk + "; coverageFile: " + coverFile);
return null;
}
String remotePath = hostData.getRemotePath(sessionDataFile.getAbsolutePath());
if (StringUtil.isEmpty(remotePath)) {
LOG.warn("Unable to map remote path for: " + sessionDataFile.getAbsolutePath() + " in " + hostData);
return null;
}
commandLine.addParameters("--silent", "--nosummary", "-report", "camelcade", remotePath);
commandLine.withSdk(effectiveSdk);
commandLine.withProject(project);
return commandLine;
});
if (perlCommandLine == null) {
return null;
}
try {
LOG.info("Loading coverage by: " + perlCommandLine.getCommandLineString());
ProcessOutput output = PerlHostData.execAndGetOutput(perlCommandLine);
if (output.getExitCode() != 0) {
String errorMessage = output.getStderr();
if (StringUtil.isEmpty(errorMessage)) {
errorMessage = output.getStdout();
}
if (!StringUtil.isEmpty(errorMessage)) {
showError(project, errorMessage);
}
return null;
}
String stdout = output.getStdout();
if (StringUtil.isEmpty(stdout)) {
return null;
}
try {
PerlFileCoverageData[] filesData = new Gson().fromJson(stdout, PerlFileCoverageData[].class);
if (filesData != null) {
return parsePerlFileData(PerlHostData.notNullFrom(effectiveSdk), filesData);
}
} catch (JsonParseException e) {
LOG.warn("Error parsing JSON", e);
showError(project, e.getMessage());
}
} catch (ExecutionException e) {
LOG.warn("Error loading coverage", e);
showError(project, e.getMessage());
}
return null;
}
use of com.perl5.lang.perl.idea.sdk.host.PerlHostData in project Perl5-IDEA by Camelcade.
the class PerlSdkType method setupSdkPaths.
@Override
public void setupSdkPaths(@NotNull Sdk sdk) {
if (ApplicationManager.getApplication().isDispatchThread() && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
throw new RuntimeException("Do not call from EDT, refreshes FS");
}
String oldText = PerlRunUtil.setProgressText(PerlBundle.message("perl.progress.refreshing.inc", sdk.getName()));
LOG.info("Refreshing @INC for " + sdk);
PerlHostData<?, ?> hostData = PerlHostData.notNullFrom(sdk);
List<String> pathsToRefresh = new ArrayList<>();
// syncing data if necessary
List<String> incPaths = computeIncPaths(sdk);
List<Exception> exceptions = new ArrayList<>();
try (PerlHostFileTransfer<?> fileTransfer = hostData.getFileTransfer()) {
Consumer<File> downloader = it -> syncAndCollectException(fileTransfer, it, pathsToRefresh, exceptions, false);
Consumer<File> binStubber = it -> syncAndCollectException(fileTransfer, it, pathsToRefresh, exceptions, true);
for (String hostPath : incPaths) {
downloader.accept(new File(hostPath));
binStubber.accept(PerlRunUtil.findLibsBin(new File(hostPath)));
}
// additional bin dirs from version manager
PerlVersionManagerData.notNullFrom(sdk).getBinDirsPath().forEach(binStubber);
// sdk home path
File interpreterPath = new File(Objects.requireNonNull(PerlProjectManager.getInterpreterPath(sdk)));
binStubber.accept(interpreterPath.getParentFile());
List<VirtualFile> filesToRefresh = pathsToRefresh.stream().map(it -> VfsUtil.findFileByIoFile(new File(it), true)).filter(Objects::nonNull).collect(Collectors.toList());
if (!filesToRefresh.isEmpty()) {
PerlRunUtil.setProgressText(PerlBundle.message("perl.progress.refreshing.filesystem"));
VfsUtil.markDirtyAndRefresh(false, true, true, filesToRefresh.toArray(VirtualFile.EMPTY_ARRAY));
}
try {
fileTransfer.syncHelpers();
} catch (IOException e) {
exceptions.add(e);
}
if (!exceptions.isEmpty()) {
int copiedFiles = filesToRefresh.size();
int errorsNumber = exceptions.size();
Notifications.Bus.notify(new Notification(PerlBundle.message("perl.sync.notification.group"), PerlBundle.message("perl.sync.notification.title"), PerlBundle.message("perl.sync.notification.body", copiedFiles, copiedFiles + errorsNumber, errorsNumber, StringUtil.pluralize(PerlBundle.message("perl.sync.notification.pluralize"), errorsNumber)), NotificationType.ERROR));
exceptions.forEach(LOG::warn);
}
} catch (IOException e) {
LOG.warn("Error closing transfer for " + sdk, e);
}
// updating sdk
SdkModificator sdkModificator = sdk.getSdkModificator();
sdkModificator.removeAllRoots();
for (String hostPath : incPaths) {
String localPath = hostData.getLocalPath(hostPath);
if (localPath == null) {
continue;
}
File libDir = new File(localPath);
if (libDir.exists() && libDir.isDirectory()) {
VirtualFile virtualDir = VfsUtil.findFileByIoFile(libDir, true);
if (virtualDir != null) {
sdkModificator.addRoot(virtualDir, OrderRootType.CLASSES);
}
}
}
ApplicationManager.getApplication().invokeAndWait(sdkModificator::commitChanges);
PerlRunUtil.setProgressText(oldText);
}
use of com.perl5.lang.perl.idea.sdk.host.PerlHostData in project Perl5-IDEA by Camelcade.
the class PerlRunUtil method getPerlCommandLine.
/**
* Builds non-patched perl command line (without patching by version manager)
*
* @return new perl command line or null if sdk is missing or corrupted
*/
@Nullable
public static PerlCommandLine getPerlCommandLine(@NotNull Project project, @Nullable Sdk perlSdk, @Nullable String localScriptPath, @NotNull List<String> perlParameters, @NotNull List<String> scriptParameters) {
if (perlSdk == null) {
perlSdk = PerlProjectManager.getSdk(project);
}
if (perlSdk == null) {
LOG.error("No sdk provided or available in project " + project);
return null;
}
String interpreterPath = PerlProjectManager.getInterpreterPath(perlSdk);
if (StringUtil.isEmpty(interpreterPath)) {
LOG.warn("Empty interpreter path in " + perlSdk + " while building command line for " + localScriptPath);
return null;
}
PerlCommandLine commandLine = new PerlCommandLine(perlSdk).withProject(project);
commandLine.setExePath(interpreterPath);
PerlHostData<?, ?> hostData = PerlHostData.notNullFrom(perlSdk);
for (VirtualFile libRoot : PerlProjectManager.getInstance(project).getModulesLibraryRoots()) {
commandLine.addParameter(PERL_I + hostData.getRemotePath(libRoot.getCanonicalPath()));
}
commandLine.addParameters(perlParameters);
if (StringUtil.isNotEmpty(localScriptPath)) {
String remoteScriptPath = hostData.getRemotePath(localScriptPath);
if (remoteScriptPath != null) {
commandLine.addParameter(remoteScriptPath);
}
}
commandLine.addParameters(scriptParameters);
return commandLine;
}
use of com.perl5.lang.perl.idea.sdk.host.PerlHostData in project Perl5-IDEA by Camelcade.
the class PerlRunUtil method getBinDirectories.
/**
* @return list of perl bin directories where script from library may be located
*/
@NotNull
public static Stream<VirtualFile> getBinDirectories(@Nullable Sdk sdk) {
if (sdk == null) {
return Stream.empty();
}
ApplicationManager.getApplication().assertReadAccessAllowed();
SdkTypeId sdkType = sdk.getSdkType();
if (!(sdkType instanceof PerlSdkType)) {
throw new IllegalArgumentException("Got non-perl sdk: " + sdk);
}
List<VirtualFile> files = new ArrayList<>(ContainerUtil.map(sdk.getRootProvider().getFiles(OrderRootType.CLASSES), PerlRunUtil::findLibsBin));
PerlHostData<?, ?> hostData = PerlHostData.notNullFrom(sdk);
File localSdkBinDir = hostData.getLocalPath(new File(StringUtil.notNullize(PerlProjectManager.getInterpreterPath(sdk))).getParentFile());
if (localSdkBinDir != null) {
files.add(VfsUtil.findFileByIoFile(localSdkBinDir, false));
}
PerlVersionManagerData.notNullFrom(sdk).getBinDirsPath().forEach(it -> ObjectUtils.doIfNotNull(hostData.getLocalPath(it), localPath -> files.add(VfsUtil.findFileByIoFile(localPath, false))));
return files.stream().filter(Objects::nonNull).distinct();
}
Aggregations